blob: 729203803b1b4943f476b8af0f09f85d219c63bd [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,
1204 unsigned short RefreshRateTableIndex,
1205 struct vb_device_info *pVBInfo)
1206{
Aaro Koskinen6c27b372012-11-04 21:14:45 +02001207 unsigned short i, tempdx, tempbx, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001208
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001209 tempbx = 0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001210
Aaro Koskinenb3979922012-11-04 21:14:52 +02001211 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001212
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001213 i = 0;
1214
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001215 while (table[i].PANELID != 0xff) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001216 tempdx = pVBInfo->LCDResInfo;
1217 if (tempbx & 0x0080) { /* OEMUtil */
1218 tempbx &= (~0x0080);
1219 tempdx = pVBInfo->LCDTypeInfo;
1220 }
1221
1222 if (pVBInfo->LCDInfo & EnableScalingLCD)
1223 tempdx &= (~PanelResInfo);
1224
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001225 if (table[i].PANELID == tempdx) {
1226 tempbx = table[i].MASK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001227 tempdx = pVBInfo->LCDInfo;
1228
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001229 if (modeflag & HalfDCLK)
1230 tempdx |= SetLCDLowResolution;
1231
1232 tempbx &= tempdx;
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001233 if (tempbx == table[i].CAP)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001234 break;
1235 }
1236 i++;
1237 }
1238
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001239 return table[i].DATAPTR;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001240}
1241
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001242static struct SiS_TVData const *XGI_GetTVPtr(unsigned short ModeIdIndex,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001243 unsigned short RefreshRateTableIndex,
1244 struct vb_device_info *pVBInfo)
1245{
Aaro Koskinen56d276c2012-09-11 00:15:19 +03001246 unsigned short i, tempdx, tempal, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001247
Aaro Koskinenb3979922012-11-04 21:14:52 +02001248 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02001249 tempal = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001250 tempal = tempal & 0x3f;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001251 tempdx = pVBInfo->TVInfo;
1252
1253 if (pVBInfo->VBInfo & SetInSlaveMode)
1254 tempdx = tempdx | SetTVLockMode;
1255
1256 if (modeflag & HalfDCLK)
1257 tempdx = tempdx | SetTVLowResolution;
1258
1259 i = 0;
1260
Aaro Koskinen6265ee42012-09-11 00:15:20 +03001261 while (XGI_TVDataTable[i].MASK != 0xffff) {
1262 if ((tempdx & XGI_TVDataTable[i].MASK) ==
1263 XGI_TVDataTable[i].CAP)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001264 break;
1265 i++;
1266 }
1267
Aaro Koskinen18ba8662012-09-11 00:15:22 +03001268 return &XGI_TVDataTable[i].DATAPTR[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001269}
1270
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001271static void XGI_GetLVDSData(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301272 unsigned short RefreshRateTableIndex,
1273 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001274{
Aaro Koskinen6008f872012-11-04 21:14:49 +02001275 struct SiS_LVDSData const *LCDPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001276
Aaro Koskinen6008f872012-11-04 21:14:49 +02001277 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
1278 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001279
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001280 LCDPtr = XGI_GetLcdPtr(XGI_EPLLCDDataPtr, ModeIdIndex,
Aaro Koskinen6008f872012-11-04 21:14:49 +02001281 RefreshRateTableIndex, pVBInfo);
1282 pVBInfo->VGAHT = LCDPtr->VGAHT;
1283 pVBInfo->VGAVT = LCDPtr->VGAVT;
1284 pVBInfo->HT = LCDPtr->LCDHT;
1285 pVBInfo->VT = LCDPtr->LCDVT;
1286
1287 if (pVBInfo->LCDInfo & (SetLCDtoNonExpanding | EnableScalingLCD))
1288 return;
1289
1290 if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
1291 (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
1292 pVBInfo->HDE = 1024;
1293 pVBInfo->VDE = 768;
1294 } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
1295 (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
1296 pVBInfo->HDE = 1280;
1297 pVBInfo->VDE = 1024;
1298 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
1299 pVBInfo->HDE = 1400;
1300 pVBInfo->VDE = 1050;
1301 } else {
1302 pVBInfo->HDE = 1600;
1303 pVBInfo->VDE = 1200;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301304 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001305}
1306
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001307static void XGI_ModCRT1Regs(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301308 unsigned short RefreshRateTableIndex,
1309 struct xgi_hw_device_info *HwDeviceExtension,
1310 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001311{
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001312 unsigned short i;
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001313 struct XGI_LVDSCRT1HDataStruct const *LCDPtr = NULL;
1314 struct XGI_LVDSCRT1VDataStruct const *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001315
Peter Huewea3d675c2012-02-09 21:11:47 +01001316 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001317 LCDPtr = XGI_GetLcdPtr(xgifb_epllcd_crt1_h, ModeIdIndex,
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +03001318 RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001319
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001320 for (i = 0; i < 8; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +02001321 pVBInfo->TimingH.data[i] = LCDPtr[0].Reg[i];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301322 }
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001323
1324 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
1325
Peter Huewea3d675c2012-02-09 21:11:47 +01001326 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001327 LCDPtr1 = XGI_GetLcdPtr(xgifb_epllcd_crt1_v, ModeIdIndex,
1328 RefreshRateTableIndex, pVBInfo);
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001329 for (i = 0; i < 7; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +02001330 pVBInfo->TimingV.data[i] = LCDPtr1[0].Reg[i];
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001331 }
1332
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001333 XGI_SetCRT1Timing_V(ModeIdIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001334}
1335
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001336static unsigned short XGI_GetLCDCapPtr(struct vb_device_info *pVBInfo)
1337{
1338 unsigned char tempal, tempah, tempbl, i;
1339
Aaro Koskinen58839b02011-03-13 12:26:23 +02001340 tempah = xgifb_reg_get(pVBInfo->P3d4, 0x36);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001341 tempal = tempah & 0x0F;
1342 tempah = tempah & 0xF0;
1343 i = 0;
1344 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1345
1346 while (tempbl != 0xFF) {
1347 if (tempbl & 0x80) { /* OEMUtil */
1348 tempal = tempah;
1349 tempbl = tempbl & ~(0x80);
1350 }
1351
1352 if (tempal == tempbl)
1353 break;
1354
1355 i++;
1356
1357 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1358 }
1359
1360 return i;
1361}
1362
1363static unsigned short XGI_GetLCDCapPtr1(struct vb_device_info *pVBInfo)
1364{
1365 unsigned short tempah, tempal, tempbl, i;
1366
1367 tempal = pVBInfo->LCDResInfo;
1368 tempah = pVBInfo->LCDTypeInfo;
1369
1370 i = 0;
1371 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1372
1373 while (tempbl != 0xFF) {
1374 if ((tempbl & 0x80) && (tempbl != 0x80)) {
1375 tempal = tempah;
1376 tempbl &= ~0x80;
1377 }
1378
1379 if (tempal == tempbl)
1380 break;
1381
1382 i++;
1383 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1384 }
1385
1386 if (tempbl == 0xFF) {
Peter Huewe255aabd2012-02-09 21:11:44 +01001387 pVBInfo->LCDResInfo = Panel_1024x768;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001388 pVBInfo->LCDTypeInfo = 0;
1389 i = 0;
1390 }
1391
1392 return i;
1393}
1394
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001395static void XGI_GetLCDSync(unsigned short *HSyncWidth,
1396 unsigned short *VSyncWidth,
1397 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001398{
1399 unsigned short Index;
1400
1401 Index = XGI_GetLCDCapPtr(pVBInfo);
1402 *HSyncWidth = pVBInfo->LCDCapList[Index].LCD_HSyncWidth;
1403 *VSyncWidth = pVBInfo->LCDCapList[Index].LCD_VSyncWidth;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001404}
1405
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001406static void XGI_SetLVDSRegs(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301407 unsigned short RefreshRateTableIndex,
1408 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001409{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301410 unsigned short tempbx, tempax, tempcx, tempdx, push1, push2, modeflag;
1411 unsigned long temp, temp1, temp2, temp3, push3;
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001412 struct XGI330_LCDDataDesStruct2 const *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001413
Aaro Koskinenb3979922012-11-04 21:14:52 +02001414 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001415 LCDPtr1 = XGI_GetLcdPtr(XGI_EPLLCDDesDataPtr, ModeIdIndex,
1416 RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001417
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001418 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
1419 push1 = tempbx;
1420 push2 = tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001421
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001422 /* GetLCDResInfo */
Peter Huewe255aabd2012-02-09 21:11:44 +01001423 if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
1424 (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001425 tempax = 1024;
1426 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01001427 } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
1428 (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001429 tempax = 1280;
1430 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01001431 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001432 tempax = 1400;
1433 tempbx = 1050;
1434 } else {
1435 tempax = 1600;
1436 tempbx = 1200;
1437 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001438
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001439 if (pVBInfo->LCDInfo & SetLCDtoNonExpanding) {
1440 pVBInfo->HDE = tempax;
1441 pVBInfo->VDE = tempbx;
1442 pVBInfo->VGAHDE = tempax;
1443 pVBInfo->VGAVDE = tempbx;
1444 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001445
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001446 tempax = pVBInfo->HT;
1447
Peter Huewe826215d2013-02-05 00:29:46 +01001448 tempbx = LCDPtr1->LCDHDES;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001449
1450 tempcx = pVBInfo->HDE;
1451 tempbx = tempbx & 0x0fff;
1452 tempcx += tempbx;
1453
1454 if (tempcx >= tempax)
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001455 tempcx -= tempax;
1456
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001457 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, tempbx & 0x07);
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001458
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001459 tempcx = tempcx >> 3;
1460 tempbx = tempbx >> 3;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001461
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001462 xgifb_reg_set(pVBInfo->Part1Port, 0x16,
1463 (unsigned short) (tempbx & 0xff));
1464 xgifb_reg_set(pVBInfo->Part1Port, 0x17,
1465 (unsigned short) (tempcx & 0xff));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001466
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001467 tempax = pVBInfo->HT;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001468
Peter Huewe826215d2013-02-05 00:29:46 +01001469 tempbx = LCDPtr1->LCDHRS;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001470
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001471 tempcx = push2;
1472
1473 if (pVBInfo->LCDInfo & EnableScalingLCD)
1474 tempcx = LCDPtr1->LCDHSync;
1475
1476 tempcx += tempbx;
1477
1478 if (tempcx >= tempax)
1479 tempcx -= tempax;
1480
1481 tempax = tempbx & 0x07;
1482 tempax = tempax >> 5;
1483 tempcx = tempcx >> 3;
1484 tempbx = tempbx >> 3;
1485
1486 tempcx &= 0x1f;
1487 tempax |= tempcx;
1488
1489 xgifb_reg_set(pVBInfo->Part1Port, 0x15, tempax);
1490 xgifb_reg_set(pVBInfo->Part1Port, 0x14,
1491 (unsigned short) (tempbx & 0xff));
1492
1493 tempax = pVBInfo->VT;
Peter Huewe826215d2013-02-05 00:29:46 +01001494 tempbx = LCDPtr1->LCDVDES;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001495 tempcx = pVBInfo->VDE;
1496
1497 tempbx = tempbx & 0x0fff;
1498 tempcx += tempbx;
1499 if (tempcx >= tempax)
1500 tempcx -= tempax;
1501
1502 xgifb_reg_set(pVBInfo->Part1Port, 0x1b,
1503 (unsigned short) (tempbx & 0xff));
1504 xgifb_reg_set(pVBInfo->Part1Port, 0x1c,
1505 (unsigned short) (tempcx & 0xff));
1506
1507 tempbx = (tempbx >> 8) & 0x07;
1508 tempcx = (tempcx >> 8) & 0x07;
1509
1510 xgifb_reg_set(pVBInfo->Part1Port, 0x1d,
1511 (unsigned short) ((tempcx << 3)
1512 | tempbx));
1513
1514 tempax = pVBInfo->VT;
Peter Huewe826215d2013-02-05 00:29:46 +01001515 tempbx = LCDPtr1->LCDVRS;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001516
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001517 tempcx = push1;
1518
1519 if (pVBInfo->LCDInfo & EnableScalingLCD)
1520 tempcx = LCDPtr1->LCDVSync;
1521
1522 tempcx += tempbx;
1523 if (tempcx >= tempax)
1524 tempcx -= tempax;
1525
1526 xgifb_reg_set(pVBInfo->Part1Port, 0x18,
1527 (unsigned short) (tempbx & 0xff));
1528 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, ~0x0f,
1529 (unsigned short) (tempcx & 0x0f));
1530
1531 tempax = ((tempbx >> 8) & 0x07) << 3;
1532
1533 tempbx = pVBInfo->VGAVDE;
1534 if (tempbx != pVBInfo->VDE)
1535 tempax |= 0x40;
1536
Peter Huewea3d675c2012-02-09 21:11:47 +01001537 if (pVBInfo->LCDInfo & XGI_EnableLVDSDDA)
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001538 tempax |= 0x40;
1539
1540 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1a, 0x07,
1541 tempax);
1542
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001543 tempbx = pVBInfo->VDE;
1544 tempax = pVBInfo->VGAVDE;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001545
1546 temp = tempax; /* 0430 ylshieh */
1547 temp1 = (temp << 18) / tempbx;
1548
1549 tempdx = (unsigned short) ((temp << 18) % tempbx);
1550
1551 if (tempdx != 0)
1552 temp1 += 1;
1553
1554 temp2 = temp1;
1555 push3 = temp2;
1556
1557 xgifb_reg_set(pVBInfo->Part1Port, 0x37,
1558 (unsigned short) (temp2 & 0xff));
1559 xgifb_reg_set(pVBInfo->Part1Port, 0x36,
1560 (unsigned short) ((temp2 >> 8) & 0xff));
1561
1562 tempbx = (unsigned short) (temp2 >> 16);
1563 tempax = tempbx & 0x03;
1564
1565 tempbx = pVBInfo->VGAVDE;
1566 if (tempbx == pVBInfo->VDE)
1567 tempax |= 0x04;
1568
1569 xgifb_reg_set(pVBInfo->Part1Port, 0x35, tempax);
1570
1571 if (pVBInfo->VBType & VB_XGI301C) {
1572 temp2 = push3;
1573 xgifb_reg_set(pVBInfo->Part4Port,
1574 0x3c,
1575 (unsigned short) (temp2 & 0xff));
1576 xgifb_reg_set(pVBInfo->Part4Port,
1577 0x3b,
1578 (unsigned short) ((temp2 >> 8) &
1579 0xff));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001580 tempbx = (unsigned short) (temp2 >> 16);
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001581 xgifb_reg_and_or(pVBInfo->Part4Port, 0x3a,
1582 ~0xc0,
1583 (unsigned short) ((tempbx &
1584 0xff) << 6));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001585
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001586 tempcx = pVBInfo->VGAVDE;
1587 if (tempcx == pVBInfo->VDE)
1588 xgifb_reg_and_or(pVBInfo->Part4Port,
1589 0x30, ~0x0c, 0x00);
1590 else
1591 xgifb_reg_and_or(pVBInfo->Part4Port,
1592 0x30, ~0x0c, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301593 }
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001594
1595 tempcx = pVBInfo->VGAHDE;
1596 tempbx = pVBInfo->HDE;
1597
1598 temp1 = tempcx << 16;
1599
1600 tempax = (unsigned short) (temp1 / tempbx);
1601
1602 if ((tempbx & 0xffff) == (tempcx & 0xffff))
1603 tempax = 65535;
1604
1605 temp3 = tempax;
1606 temp1 = pVBInfo->VGAHDE << 16;
1607
1608 temp1 /= temp3;
1609 temp3 = temp3 << 16;
1610 temp1 -= 1;
1611
1612 temp3 = (temp3 & 0xffff0000) + (temp1 & 0xffff);
1613
1614 tempax = (unsigned short) (temp3 & 0xff);
1615 xgifb_reg_set(pVBInfo->Part1Port, 0x1f, tempax);
1616
1617 temp1 = pVBInfo->VGAVDE << 18;
1618 temp1 = temp1 / push3;
1619 tempbx = (unsigned short) (temp1 & 0xffff);
1620
Peter Huewe255aabd2012-02-09 21:11:44 +01001621 if (pVBInfo->LCDResInfo == Panel_1024x768)
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001622 tempbx -= 1;
1623
1624 tempax = ((tempbx >> 8) & 0xff) << 3;
1625 tempax |= (unsigned short) ((temp3 >> 8) & 0x07);
1626 xgifb_reg_set(pVBInfo->Part1Port, 0x20,
1627 (unsigned short) (tempax & 0xff));
1628 xgifb_reg_set(pVBInfo->Part1Port, 0x21,
1629 (unsigned short) (tempbx & 0xff));
1630
1631 temp3 = temp3 >> 16;
1632
1633 if (modeflag & HalfDCLK)
1634 temp3 = temp3 >> 1;
1635
1636 xgifb_reg_set(pVBInfo->Part1Port, 0x22,
1637 (unsigned short) ((temp3 >> 8) & 0xff));
1638 xgifb_reg_set(pVBInfo->Part1Port, 0x23,
1639 (unsigned short) (temp3 & 0xff));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001640}
1641
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001642/* --------------------------------------------------------------------- */
1643/* Function : XGI_GETLCDVCLKPtr */
1644/* Input : */
1645/* Output : al -> VCLK Index */
1646/* Description : */
1647/* --------------------------------------------------------------------- */
1648static void XGI_GetLCDVCLKPtr(unsigned char *di_0, unsigned char *di_1,
1649 struct vb_device_info *pVBInfo)
1650{
1651 unsigned short index;
1652
Peter Huewea3d675c2012-02-09 21:11:47 +01001653 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001654 index = XGI_GetLCDCapPtr1(pVBInfo);
1655
1656 if (pVBInfo->VBInfo & SetCRT2ToLCD) { /* LCDB */
1657 *di_0 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData1;
1658 *di_1 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData2;
1659 } else { /* LCDA */
1660 *di_0 = pVBInfo->LCDCapList[index].LCDA_VCLKData1;
1661 *di_1 = pVBInfo->LCDCapList[index].LCDA_VCLKData2;
1662 }
1663 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001664}
1665
1666static unsigned char XGI_GetVCLKPtr(unsigned short RefreshRateTableIndex,
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001667 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001668{
1669
1670 unsigned short index, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001671 unsigned char tempal;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001672
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001673 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02001674 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001675
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001676 if ((pVBInfo->SetFlag & ProgrammingCRT2) &&
1677 (!(pVBInfo->LCDInfo & EnableScalingLCD))) { /* {LCDA/LCDB} */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001678 index = XGI_GetLCDCapPtr(pVBInfo);
1679 tempal = pVBInfo->LCDCapList[index].LCD_VCLK;
1680
Peter Huewea3d675c2012-02-09 21:11:47 +01001681 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001682 return tempal;
1683
1684 /* {TV} */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001685 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01001686 (VB_SIS301B |
1687 VB_SIS302B |
1688 VB_SIS301LV |
1689 VB_SIS302LV |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001690 VB_XGI301C)) {
Peter Huewe599801f2012-02-09 21:11:45 +01001691 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001692 tempal = TVCLKBASE_315 + HiTVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001693 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
Peter Hueweccc8cb22012-02-09 21:11:48 +01001694 tempal = TVCLKBASE_315 + HiTVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001695 if (pVBInfo->TVInfo & TVSimuMode) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001696 tempal = TVCLKBASE_315 + HiTVSimuVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001697 if (!(modeflag & Charx8Dot))
Miguel Gómez3bcc2462012-07-06 12:40:53 +02001698 tempal = TVCLKBASE_315 +
1699 HiTVTextVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001700
1701 }
1702 return tempal;
1703 }
1704
Peter Huewe599801f2012-02-09 21:11:45 +01001705 if (pVBInfo->TVInfo & TVSetYPbPr750p) {
Peter Huewea3d675c2012-02-09 21:11:47 +01001706 tempal = XGI_YPbPr750pVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001707 return tempal;
1708 }
1709
Peter Huewe599801f2012-02-09 21:11:45 +01001710 if (pVBInfo->TVInfo & TVSetYPbPr525p) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001711 tempal = YPbPr525pVCLK;
1712 return tempal;
1713 }
1714
1715 tempal = NTSC1024VCLK;
1716
1717 if (!(pVBInfo->TVInfo & NTSC1024x768)) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001718 tempal = TVCLKBASE_315 + TVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001719 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
Peter Hueweccc8cb22012-02-09 21:11:48 +01001720 tempal = TVCLKBASE_315 + TVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001721 }
1722
1723 if (pVBInfo->VBInfo & SetCRT2ToTV)
1724 return tempal;
1725 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001726 } /* {End of VB} */
1727
Peter Huewe516354e2013-02-15 20:37:11 +01001728 inb((pVBInfo->P3ca + 0x02));
Aaro Koskinena39325d2012-11-04 21:14:53 +02001729 tempal = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001730 return tempal;
1731}
1732
1733static void XGI_GetVCLKLen(unsigned char tempal, unsigned char *di_0,
1734 unsigned char *di_1, struct vb_device_info *pVBInfo)
1735{
Peter Huewe6896b942012-02-09 21:11:46 +01001736 if (pVBInfo->VBType & (VB_SIS301 | VB_SIS301B | VB_SIS302B
1737 | VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +02001738 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) &&
1739 (pVBInfo->SetFlag & ProgrammingCRT2)) {
Aaro Koskinene8cb03d2012-09-11 00:15:31 +03001740 *di_0 = XGI_VBVCLKData[tempal].Part4_A;
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +03001741 *di_1 = XGI_VBVCLKData[tempal].Part4_B;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001742 }
1743 } else {
1744 *di_0 = XGI_VCLKData[tempal].SR2B;
1745 *di_1 = XGI_VCLKData[tempal].SR2C;
1746 }
1747}
1748
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001749static void XGI_SetCRT2ECLK(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301750 unsigned short RefreshRateTableIndex,
1751 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001752{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301753 unsigned char di_0, di_1, tempal;
1754 int i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001755
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001756 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeIdIndex, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301757 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
1758 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001759
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301760 for (i = 0; i < 4; i++) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001761 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, ~0x30,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301762 (unsigned short) (0x10 * i));
Peter Huewea3d675c2012-02-09 21:11:47 +01001763 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301764 && (!(pVBInfo->VBInfo & SetInSlaveMode))) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001765 xgifb_reg_set(pVBInfo->P3c4, 0x2e, di_0);
1766 xgifb_reg_set(pVBInfo->P3c4, 0x2f, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301767 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001768 xgifb_reg_set(pVBInfo->P3c4, 0x2b, di_0);
1769 xgifb_reg_set(pVBInfo->P3c4, 0x2c, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301770 }
1771 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001772}
1773
Aaro Koskinenb053af12013-07-16 23:13:28 +03001774static void XGI_UpdateModeInfo(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001775{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301776 unsigned short tempcl, tempch, temp, tempbl, tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001777
Peter Huewe6896b942012-02-09 21:11:46 +01001778 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
1779 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301780 tempcl = 0;
1781 tempch = 0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02001782 temp = xgifb_reg_get(pVBInfo->P3c4, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001783
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301784 if (!(temp & 0x20)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001785 temp = xgifb_reg_get(pVBInfo->P3d4, 0x17);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301786 if (temp & 0x80) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001787 temp = xgifb_reg_get(pVBInfo->P3d4, 0x53);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301788 if (!(temp & 0x40))
1789 tempcl |= ActiveCRT1;
1790 }
1791 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001792
Aaro Koskinen58839b02011-03-13 12:26:23 +02001793 temp = xgifb_reg_get(pVBInfo->Part1Port, 0x2e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301794 temp &= 0x0f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001795
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301796 if (!(temp == 0x08)) {
Miguel Gómez949eb0a2012-07-06 12:40:36 +02001797 /* Check ChannelA */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001798 tempax = xgifb_reg_get(pVBInfo->Part1Port, 0x13);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301799 if (tempax & 0x04)
1800 tempcl = tempcl | ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001801
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301802 temp &= 0x05;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001803
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301804 if (!(tempcl & ActiveLCD))
1805 if (temp == 0x01)
1806 tempcl |= ActiveCRT2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001807
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301808 if (temp == 0x04)
1809 tempcl |= ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001810
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301811 if (temp == 0x05) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001812 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001813
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301814 if (!(temp & 0x08))
1815 tempch |= ActiveAVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001816
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301817 if (!(temp & 0x04))
1818 tempch |= ActiveSVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001819
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301820 if (temp & 0x02)
1821 tempch |= ActiveSCART;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001822
Peter Huewe599801f2012-02-09 21:11:45 +01001823 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301824 if (temp & 0x01)
1825 tempch |= ActiveHiTV;
1826 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001827
Peter Huewe599801f2012-02-09 21:11:45 +01001828 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001829 temp = xgifb_reg_get(
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301830 pVBInfo->Part2Port,
1831 0x4d);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001832
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301833 if (temp & 0x10)
1834 tempch |= ActiveYPbPr;
1835 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001836
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301837 if (tempch != 0)
1838 tempcl |= ActiveTV;
1839 }
1840 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001841
Aaro Koskinen58839b02011-03-13 12:26:23 +02001842 temp = xgifb_reg_get(pVBInfo->P3d4, 0x3d);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301843 if (tempcl & ActiveLCD) {
1844 if ((pVBInfo->SetFlag & ReserveTVOption)) {
1845 if (temp & ActiveTV)
1846 tempcl |= ActiveTV;
1847 }
1848 }
1849 temp = tempcl;
Peter Huewea3d675c2012-02-09 21:11:47 +01001850 tempbl = ~XGI_ModeSwitchStatus;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001851 xgifb_reg_and_or(pVBInfo->P3d4, 0x3d, tempbl, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001852
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301853 if (!(pVBInfo->SetFlag & ReserveTVOption))
Aaro Koskinen8104e322011-03-13 12:26:22 +02001854 xgifb_reg_set(pVBInfo->P3d4, 0x3e, tempch);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301855 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001856}
1857
Bill Pemberton80adad82010-06-17 13:10:51 -04001858void XGI_GetVBType(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001859{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301860 unsigned short flag, tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001861
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001862 tempbx = VB_SIS302B;
1863 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
1864 if (flag == 0x02)
1865 goto finish;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001866
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001867 tempbx = VB_SIS301;
1868 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x01);
1869 if (flag < 0xB0)
1870 goto finish;
1871
1872 tempbx = VB_SIS301B;
1873 if (flag < 0xC0)
1874 goto bigger_than_0xB0;
1875
1876 tempbx = VB_XGI301C;
1877 if (flag < 0xD0)
1878 goto bigger_than_0xB0;
1879
1880 tempbx = VB_SIS301LV;
1881 if (flag < 0xE0)
1882 goto bigger_than_0xB0;
1883
1884 tempbx = VB_SIS302LV;
1885 tempah = xgifb_reg_get(pVBInfo->Part4Port, 0x39);
1886 if (tempah != 0xFF)
1887 tempbx = VB_XGI301C;
1888
1889bigger_than_0xB0:
1890 if (tempbx & (VB_SIS301B | VB_SIS302B)) {
1891 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x23);
1892 if (!(flag & 0x02))
1893 tempbx = tempbx | VB_NoLCD;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301894 }
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001895
1896finish:
1897 pVBInfo->VBType = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001898}
1899
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001900static void XGI_GetVBInfo(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301901 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001902{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301903 unsigned short tempax, push, tempbx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001904
Aaro Koskinenb3979922012-11-04 21:14:52 +02001905 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301906 pVBInfo->SetFlag = 0;
Peter Huewe6896b942012-02-09 21:11:46 +01001907 pVBInfo->ModeType = modeflag & ModeTypeMask;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301908 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001909
Miguel Gómezf9317352012-07-06 12:40:48 +02001910 if (!(pVBInfo->VBType & 0xFFFF))
1911 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001912
Miguel Gómezf9317352012-07-06 12:40:48 +02001913 /* Check Display Device */
1914 temp = xgifb_reg_get(pVBInfo->P3d4, 0x30);
1915 tempbx = tempbx | temp;
1916 temp = xgifb_reg_get(pVBInfo->P3d4, 0x31);
1917 push = temp;
1918 push = push << 8;
1919 tempax = temp << 8;
1920 tempbx = tempbx | tempax;
1921 temp = (SetCRT2ToDualEdge | SetCRT2ToYPbPr525750 | XGI_SetCRT2ToLCDA
1922 | SetInSlaveMode | DisableCRT2Display);
1923 temp = 0xFFFF ^ temp;
1924 tempbx &= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001925
Miguel Gómezf9317352012-07-06 12:40:48 +02001926 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001927
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001928 if (pVBInfo->VBType & (VB_SIS302B | VB_SIS301LV | VB_SIS302LV |
1929 VB_XGI301C)) {
1930 if (temp & EnableDualEdge) {
1931 tempbx |= SetCRT2ToDualEdge;
1932 if (temp & SetToLCDA)
1933 tempbx |= XGI_SetCRT2ToLCDA;
Miguel Gómezf9317352012-07-06 12:40:48 +02001934 }
1935 }
1936
Aaro Koskinena4ce0e72013-05-29 23:59:14 +03001937 if (pVBInfo->VBType & (VB_SIS301LV|VB_SIS302LV|VB_XGI301C)) {
1938 if (temp & SetYPbPr) {
Aaro Koskinenaee0ac92013-05-29 23:59:15 +03001939 /* shampoo add for new scratch */
1940 temp = xgifb_reg_get(pVBInfo->P3d4, 0x35);
1941 temp &= YPbPrMode;
1942 tempbx |= SetCRT2ToHiVision;
Miguel Gómezf9317352012-07-06 12:40:48 +02001943
Aaro Koskinenaee0ac92013-05-29 23:59:15 +03001944 if (temp != YPbPrMode1080i) {
1945 tempbx &= (~SetCRT2ToHiVision);
1946 tempbx |= SetCRT2ToYPbPr525750;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301947 }
1948 }
Miguel Gómezf9317352012-07-06 12:40:48 +02001949 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001950
Miguel Gómezf9317352012-07-06 12:40:48 +02001951 tempax = push; /* restore CR31 */
1952
Aaro Koskinenaee0ac92013-05-29 23:59:15 +03001953 temp = 0x09FC;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001954
Miguel Gómezf9317352012-07-06 12:40:48 +02001955 if (!(tempbx & temp)) {
1956 tempax |= DisableCRT2Display;
1957 tempbx = 0;
1958 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001959
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03001960 if (!(pVBInfo->VBType & VB_NoLCD)) {
1961 if (tempbx & XGI_SetCRT2ToLCDA) {
1962 if (tempbx & SetSimuScanMode)
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001963 tempbx &= (~(SetCRT2ToLCD | SetCRT2ToRAMDAC |
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03001964 SwitchCRT2));
1965 else
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001966 tempbx &= (~(SetCRT2ToLCD | SetCRT2ToRAMDAC |
1967 SetCRT2ToTV | SwitchCRT2));
Miguel Gómezf9317352012-07-06 12:40:48 +02001968 }
1969 }
1970
1971 /* shampoo add */
1972 /* for driver abnormal */
1973 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode))) {
Aaro Koskinenee768752013-05-29 23:59:16 +03001974 if (tempbx & SetCRT2ToRAMDAC) {
1975 tempbx &= (0xFF00 | SetCRT2ToRAMDAC |
1976 SwitchCRT2 | SetSimuScanMode);
1977 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301978 }
Miguel Gómezf9317352012-07-06 12:40:48 +02001979 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001980
Miguel Gómezf9317352012-07-06 12:40:48 +02001981 if (!(pVBInfo->VBType & VB_NoLCD)) {
1982 if (tempbx & SetCRT2ToLCD) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001983 tempbx &= (0xFF00 | SetCRT2ToLCD | SwitchCRT2 |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001984 SetSimuScanMode);
Peter Huewe599801f2012-02-09 21:11:45 +01001985 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301986 }
Miguel Gómezf9317352012-07-06 12:40:48 +02001987 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001988
Miguel Gómezf9317352012-07-06 12:40:48 +02001989 if (tempbx & SetCRT2ToSCART) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001990 tempbx &= (0xFF00 | SetCRT2ToSCART | SwitchCRT2 |
Miguel Gómezf9317352012-07-06 12:40:48 +02001991 SetSimuScanMode);
1992 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
1993 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001994
Aaro Koskinena4ce0e72013-05-29 23:59:14 +03001995 if (tempbx & SetCRT2ToYPbPr525750)
1996 tempbx &= (0xFF00 | SwitchCRT2 | SetSimuScanMode);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001997
Aaro Koskinenaee0ac92013-05-29 23:59:15 +03001998 if (tempbx & SetCRT2ToHiVision)
1999 tempbx &= (0xFF00 | SetCRT2ToHiVision | SwitchCRT2 |
2000 SetSimuScanMode);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002001
Miguel Gómezf9317352012-07-06 12:40:48 +02002002 if (tempax & DisableCRT2Display) { /* Set Display Device Info */
2003 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode)))
2004 tempbx = DisableCRT2Display;
2005 }
2006
2007 if (!(tempbx & DisableCRT2Display)) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002008 if ((!(tempbx & DriverMode)) || (!(modeflag & CRT2Mode))) {
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03002009 if (!(tempbx & XGI_SetCRT2ToLCDA))
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002010 tempbx |= (SetInSlaveMode | SetSimuScanMode);
Miguel Gómezf9317352012-07-06 12:40:48 +02002011 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002012
Miguel Gómezf9317352012-07-06 12:40:48 +02002013 /* LCD+TV can't support in slave mode
2014 * (Force LCDA+TV->LCDB) */
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002015 if ((tempbx & SetInSlaveMode) && (tempbx & XGI_SetCRT2ToLCDA)) {
2016 tempbx ^= (SetCRT2ToLCD | XGI_SetCRT2ToLCDA |
Miguel Gómezf9317352012-07-06 12:40:48 +02002017 SetCRT2ToDualEdge);
2018 pVBInfo->SetFlag |= ReserveTVOption;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302019 }
2020 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002021
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302022 pVBInfo->VBInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002023}
2024
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002025static void XGI_GetTVInfo(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302026 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002027{
Peter Huewe5fc699f2013-02-03 04:08:45 +01002028 unsigned short tempbx = 0, resinfo = 0, modeflag, index1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002029
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302030 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinenb3979922012-11-04 21:14:52 +02002031 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2032 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002033
Peter Huewe5fc699f2013-02-03 04:08:45 +01002034 tempbx = xgifb_reg_get(pVBInfo->P3d4, 0x35);
2035 if (tempbx & TVSetPAL) {
2036 tempbx &= (SetCHTVOverScan |
2037 TVSetPALM |
2038 TVSetPALN |
2039 TVSetPAL);
2040 if (tempbx & TVSetPALM)
2041 /* set to NTSC if PAL-M */
2042 tempbx &= ~TVSetPAL;
2043 } else
2044 tempbx &= (SetCHTVOverScan |
2045 TVSetNTSCJ |
2046 TVSetPAL);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002047
Aaro Koskinena8b35292013-02-09 00:03:45 +02002048 if (pVBInfo->VBInfo & SetCRT2ToSCART)
2049 tempbx |= TVSetPAL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002050
Aaro Koskinena4ce0e72013-05-29 23:59:14 +03002051 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
2052 index1 = xgifb_reg_get(pVBInfo->P3d4, 0x35);
2053 index1 &= YPbPrMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002054
Aaro Koskinena4ce0e72013-05-29 23:59:14 +03002055 if (index1 == YPbPrMode525i)
2056 tempbx |= TVSetYPbPr525i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002057
Aaro Koskinena4ce0e72013-05-29 23:59:14 +03002058 if (index1 == YPbPrMode525p)
2059 tempbx = tempbx | TVSetYPbPr525p;
2060 if (index1 == YPbPrMode750p)
2061 tempbx = tempbx | TVSetYPbPr750p;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302062 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002063
Aaro Koskinenaee0ac92013-05-29 23:59:15 +03002064 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
2065 tempbx = tempbx | TVSetHiVision | TVSetPAL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002066
Aaro Koskinena8b35292013-02-09 00:03:45 +02002067 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
2068 (!(pVBInfo->VBInfo & SetNotSimuMode)))
2069 tempbx |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002070
Aaro Koskinena8b35292013-02-09 00:03:45 +02002071 if (!(tempbx & TVSetPAL) && (modeflag > 13) && (resinfo == 8))
2072 /* NTSC 1024x768, */
2073 tempbx |= NTSC1024x768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002074
Aaro Koskinena8b35292013-02-09 00:03:45 +02002075 tempbx |= RPLLDIV2XO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002076
Aaro Koskinena8b35292013-02-09 00:03:45 +02002077 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
2078 if (pVBInfo->VBInfo & SetInSlaveMode)
2079 tempbx &= (~RPLLDIV2XO);
2080 } else if (tempbx & (TVSetYPbPr525p | TVSetYPbPr750p)) {
2081 tempbx &= (~RPLLDIV2XO);
2082 } else if (!(pVBInfo->VBType & (VB_SIS301B | VB_SIS302B |
2083 VB_SIS301LV | VB_SIS302LV |
2084 VB_XGI301C))) {
2085 if (tempbx & TVSimuMode)
2086 tempbx &= (~RPLLDIV2XO);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302087 }
2088 }
2089 pVBInfo->TVInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002090}
2091
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002092static unsigned char XGI_GetLCDInfo(unsigned short ModeIdIndex,
2093 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002094{
Peter Hueweef9a6b92013-02-03 04:08:43 +01002095 unsigned short temp, tempax, tempbx, resinfo = 0, LCDIdIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002096
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302097 pVBInfo->LCDResInfo = 0;
2098 pVBInfo->LCDTypeInfo = 0;
2099 pVBInfo->LCDInfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002100
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002101 /* si+Ext_ResInfo // */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002102 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinen58839b02011-03-13 12:26:23 +02002103 temp = xgifb_reg_get(pVBInfo->P3d4, 0x36); /* Get LCD Res.Info */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302104 tempbx = temp & 0x0F;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002105
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302106 if (tempbx == 0)
Peter Huewe255aabd2012-02-09 21:11:44 +01002107 tempbx = Panel_1024x768; /* default */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002108
Miguel Gómez949eb0a2012-07-06 12:40:36 +02002109 /* LCD75 */
Peter Huewe255aabd2012-02-09 21:11:44 +01002110 if ((tempbx == Panel_1024x768) || (tempbx == Panel_1280x1024)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302111 if (pVBInfo->VBInfo & DriverMode) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002112 tempax = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Peter Huewea3d675c2012-02-09 21:11:47 +01002113 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302114 tempax &= 0x0F;
2115 else
2116 tempax = tempax >> 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002117
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302118 if ((resinfo == 6) || (resinfo == 9)) {
2119 if (tempax >= 3)
2120 tempbx |= PanelRef75Hz;
2121 } else if ((resinfo == 7) || (resinfo == 8)) {
2122 if (tempax >= 4)
2123 tempbx |= PanelRef75Hz;
2124 }
2125 }
2126 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002127
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302128 pVBInfo->LCDResInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002129
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302130 /* End of LCD75 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002131
Peter Huewea3d675c2012-02-09 21:11:47 +01002132 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302133 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002134
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302135 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002136
Aaro Koskinen58839b02011-03-13 12:26:23 +02002137 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002138
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302139 temp &= (ScalingLCD | LCDNonExpanding | LCDSyncBit | SetPWDEnable);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002140
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302141 tempbx |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002142
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302143 LCDIdIndex = XGI_GetLCDCapPtr1(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002144
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302145 tempax = pVBInfo->LCDCapList[LCDIdIndex].LCD_Capability;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002146
Aaro Koskinen718e7152013-02-09 00:03:46 +02002147 if (((pVBInfo->VBType & VB_SIS302LV) ||
2148 (pVBInfo->VBType & VB_XGI301C)) && (tempax & XGI_LCDDualLink))
2149 tempbx |= SetLCDDualLink;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002150
Aaro Koskinen718e7152013-02-09 00:03:46 +02002151 if ((pVBInfo->LCDResInfo == Panel_1400x1050) &&
2152 (pVBInfo->VBInfo & SetCRT2ToLCD) && (resinfo == 9) &&
2153 (!(tempbx & EnableScalingLCD)))
2154 /*
2155 * set to center in 1280x1024 LCDB
2156 * for Panel_1400x1050
2157 */
2158 tempbx |= SetLCDtoNonExpanding;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002159
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302160 if (pVBInfo->VBInfo & SetInSlaveMode) {
2161 if (pVBInfo->VBInfo & SetNotSimuMode)
Peter Huewea3d675c2012-02-09 21:11:47 +01002162 tempbx |= XGI_LCDVESATiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302163 } else {
Peter Huewea3d675c2012-02-09 21:11:47 +01002164 tempbx |= XGI_LCDVESATiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302165 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002166
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302167 pVBInfo->LCDInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002168
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302169 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002170}
2171
Bill Pemberton108afbf2010-06-17 13:10:47 -04002172unsigned char XGI_SearchModeID(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302173 unsigned short *ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002174{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002175 for (*ModeIdIndex = 0;; (*ModeIdIndex)++) {
Aaro Koskinenb3979922012-11-04 21:14:52 +02002176 if (XGI330_EModeIDTable[*ModeIdIndex].Ext_ModeID == ModeNo)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002177 break;
Aaro Koskinenb3979922012-11-04 21:14:52 +02002178 if (XGI330_EModeIDTable[*ModeIdIndex].Ext_ModeID == 0xFF)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002179 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302180 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002181
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302182 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002183}
2184
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002185static unsigned char XG21GPIODataTransfer(unsigned char ujDate)
2186{
2187 unsigned char ujRet = 0;
2188 unsigned char i = 0;
2189
2190 for (i = 0; i < 8; i++) {
2191 ujRet = ujRet << 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002192 ujRet |= (ujDate >> i) & 1;
2193 }
2194
2195 return ujRet;
2196}
2197
2198/*----------------------------------------------------------------------------*/
2199/* output */
2200/* bl[5] : LVDS signal */
2201/* bl[1] : LVDS backlight */
2202/* bl[0] : LVDS VDD */
2203/*----------------------------------------------------------------------------*/
2204static unsigned char XGI_XG21GetPSCValue(struct vb_device_info *pVBInfo)
2205{
2206 unsigned char CR4A, temp;
2207
Aaro Koskinen58839b02011-03-13 12:26:23 +02002208 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02002209 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x23); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002210
Aaro Koskinen58839b02011-03-13 12:26:23 +02002211 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002212
2213 temp = XG21GPIODataTransfer(temp);
2214 temp &= 0x23;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002215 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002216 return temp;
2217}
2218
2219/*----------------------------------------------------------------------------*/
2220/* output */
2221/* bl[5] : LVDS signal */
2222/* bl[1] : LVDS backlight */
2223/* bl[0] : LVDS VDD */
2224/*----------------------------------------------------------------------------*/
2225static unsigned char XGI_XG27GetPSCValue(struct vb_device_info *pVBInfo)
2226{
2227 unsigned char CR4A, CRB4, temp;
2228
Aaro Koskinen58839b02011-03-13 12:26:23 +02002229 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02002230 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x0C); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002231
Aaro Koskinen58839b02011-03-13 12:26:23 +02002232 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002233
2234 temp &= 0x0C;
2235 temp >>= 2;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002236 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinen58839b02011-03-13 12:26:23 +02002237 CRB4 = xgifb_reg_get(pVBInfo->P3d4, 0xB4);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002238 temp |= ((CRB4 & 0x04) << 3);
2239 return temp;
2240}
2241
Aaro Koskinen0ebf5382011-11-27 23:03:09 +02002242/*----------------------------------------------------------------------------*/
2243/* input */
2244/* bl[5] : 1;LVDS signal on */
2245/* bl[1] : 1;LVDS backlight on */
2246/* bl[0] : 1:LVDS VDD on */
2247/* bh: 100000b : clear bit 5, to set bit5 */
2248/* 000010b : clear bit 1, to set bit1 */
2249/* 000001b : clear bit 0, to set bit0 */
2250/*----------------------------------------------------------------------------*/
2251static void XGI_XG21BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
2252 struct vb_device_info *pVBInfo)
2253{
2254 unsigned char CR4A, temp;
2255
2256 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
2257 tempbh &= 0x23;
2258 tempbl &= 0x23;
2259 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
2260
2261 if (tempbh & 0x20) {
2262 temp = (tempbl >> 4) & 0x02;
2263
2264 /* CR B4[1] */
2265 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
2266
2267 }
2268
2269 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
2270
2271 temp = XG21GPIODataTransfer(temp);
2272 temp &= ~tempbh;
2273 temp |= tempbl;
2274 xgifb_reg_set(pVBInfo->P3d4, 0x48, temp);
2275}
2276
Aaro Koskinen776115a2011-11-27 23:03:10 +02002277static void XGI_XG27BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
2278 struct vb_device_info *pVBInfo)
2279{
2280 unsigned char CR4A, temp;
2281 unsigned short tempbh0, tempbl0;
2282
2283 tempbh0 = tempbh;
2284 tempbl0 = tempbl;
2285 tempbh0 &= 0x20;
2286 tempbl0 &= 0x20;
2287 tempbh0 >>= 3;
2288 tempbl0 >>= 3;
2289
2290 if (tempbh & 0x20) {
2291 temp = (tempbl >> 4) & 0x02;
2292
2293 /* CR B4[1] */
2294 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
2295
2296 }
2297 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~tempbh0, tempbl0);
2298
2299 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
2300 tempbh &= 0x03;
2301 tempbl &= 0x03;
2302 tempbh <<= 2;
2303 tempbl <<= 2; /* GPIOC,GPIOD */
2304 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
2305 xgifb_reg_and_or(pVBInfo->P3d4, 0x48, ~tempbh, tempbl);
2306}
2307
Aaro Koskinenfab04b92011-12-06 00:10:45 +02002308static void XGI_DisplayOn(struct xgifb_video_info *xgifb_info,
2309 struct xgi_hw_device_info *pXGIHWDE,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302310 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002311{
2312
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002313 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302314 if (pXGIHWDE->jChipType == XG21) {
2315 if (pVBInfo->IF_DEF_LVDS == 1) {
2316 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002317 /* LVDS VDD on */
2318 XGI_XG21BLSignalVDD(0x01, 0x01, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002319 mdelay(xgifb_info->lvds_data.PSC_S2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302320 }
2321 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002322 /* LVDS signal on */
2323 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002324 mdelay(xgifb_info->lvds_data.PSC_S3);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002325 /* LVDS backlight on */
2326 XGI_XG21BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302327 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002328 /* DVO/DVI signal on */
2329 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302330 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002331
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302332 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002333
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302334 if (pXGIHWDE->jChipType == XG27) {
2335 if (pVBInfo->IF_DEF_LVDS == 1) {
2336 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002337 /* LVDS VDD on */
2338 XGI_XG27BLSignalVDD(0x01, 0x01, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002339 mdelay(xgifb_info->lvds_data.PSC_S2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302340 }
2341 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002342 /* LVDS signal on */
2343 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002344 mdelay(xgifb_info->lvds_data.PSC_S3);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002345 /* LVDS backlight on */
2346 XGI_XG27BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302347 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002348 /* DVO/DVI signal on */
2349 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302350 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002351
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302352 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002353}
2354
Aaro Koskinenfab04b92011-12-06 00:10:45 +02002355void XGI_DisplayOff(struct xgifb_video_info *xgifb_info,
2356 struct xgi_hw_device_info *pXGIHWDE,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302357 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002358{
2359
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302360 if (pXGIHWDE->jChipType == XG21) {
2361 if (pVBInfo->IF_DEF_LVDS == 1) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002362 /* LVDS backlight off */
2363 XGI_XG21BLSignalVDD(0x02, 0x00, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002364 mdelay(xgifb_info->lvds_data.PSC_S3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302365 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002366 /* DVO/DVI signal off */
2367 XGI_XG21BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302368 }
2369 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002370
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302371 if (pXGIHWDE->jChipType == XG27) {
2372 if ((XGI_XG27GetPSCValue(pVBInfo) & 0x2)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002373 /* LVDS backlight off */
2374 XGI_XG27BLSignalVDD(0x02, 0x00, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002375 mdelay(xgifb_info->lvds_data.PSC_S3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302376 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002377
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302378 if (pVBInfo->IF_DEF_LVDS == 0)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002379 /* DVO/DVI signal off */
2380 XGI_XG27BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302381 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002382
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002383 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x20);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002384}
2385
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002386static void XGI_WaitDisply(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002387{
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02002388 while ((inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302389 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002390
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02002391 while (!(inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302392 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002393}
2394
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002395static void XGI_AutoThreshold(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002396{
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002397 xgifb_reg_or(pVBInfo->Part1Port, 0x01, 0x40);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002398}
2399
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002400static void XGI_SaveCRT2Info(unsigned short ModeNo,
2401 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002402{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302403 unsigned short temp1, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002404
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002405 /* reserve CR34 for CRT1 Mode No */
2406 xgifb_reg_set(pVBInfo->P3d4, 0x34, ModeNo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302407 temp1 = (pVBInfo->VBInfo & SetInSlaveMode) >> 8;
2408 temp2 = ~(SetInSlaveMode >> 8);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002409 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, temp2, temp1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002410}
2411
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002412static void XGI_GetCRT2ResInfo(unsigned short ModeIdIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002413 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002414{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302415 unsigned short xres, yres, modeflag, resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002416
Aaro Koskinenb3979922012-11-04 21:14:52 +02002417 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02002418 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
2419 yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002420 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002421 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002422
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002423 if (modeflag & HalfDCLK)
2424 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002425
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002426 if (modeflag & DoubleScanMode)
2427 yres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002428
Miguel Gómez3339db82012-07-06 12:40:49 +02002429 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
2430 goto exit;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002431
Aaro Koskinen22006832013-02-09 00:03:47 +02002432 if (pVBInfo->LCDResInfo == Panel_1600x1200) {
2433 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
2434 if (yres == 1024)
2435 yres = 1056;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302436 }
Aaro Koskinen22006832013-02-09 00:03:47 +02002437 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002438
Aaro Koskinen22006832013-02-09 00:03:47 +02002439 if (pVBInfo->LCDResInfo == Panel_1280x1024) {
2440 if (yres == 400)
2441 yres = 405;
2442 else if (yres == 350)
2443 yres = 360;
Miguel Gómez3339db82012-07-06 12:40:49 +02002444
Aaro Koskinen22006832013-02-09 00:03:47 +02002445 if (pVBInfo->LCDInfo & XGI_LCDVESATiming) {
2446 if (yres == 360)
2447 yres = 375;
Miguel Gómez3339db82012-07-06 12:40:49 +02002448 }
Aaro Koskinen22006832013-02-09 00:03:47 +02002449 }
Miguel Gómez3339db82012-07-06 12:40:49 +02002450
Aaro Koskinen22006832013-02-09 00:03:47 +02002451 if (pVBInfo->LCDResInfo == Panel_1024x768) {
2452 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
2453 if (!(pVBInfo->LCDInfo & LCDNonExpanding)) {
2454 if (yres == 350)
2455 yres = 357;
2456 else if (yres == 400)
2457 yres = 420;
2458 else if (yres == 480)
2459 yres = 525;
Miguel Gómez3339db82012-07-06 12:40:49 +02002460 }
2461 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302462 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002463
Miguel Gómez3339db82012-07-06 12:40:49 +02002464 if (xres == 720)
2465 xres = 640;
2466
2467exit:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302468 pVBInfo->VGAHDE = xres;
2469 pVBInfo->HDE = xres;
2470 pVBInfo->VGAVDE = yres;
2471 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002472}
2473
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002474static unsigned char XGI_IsLCDDualLink(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002475{
2476
Peter Huewea3d675c2012-02-09 21:11:47 +01002477 if ((pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) &&
Dan Carpentera65fd092011-01-04 09:02:27 +03002478 (pVBInfo->LCDInfo & SetLCDDualLink)) /* shampoo0129 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302479 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002480
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302481 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002482}
2483
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002484static void XGI_GetRAMDAC2DATA(unsigned short ModeIdIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002485 unsigned short RefreshRateTableIndex,
2486 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002487{
2488 unsigned short tempax, tempbx, temp1, temp2, modeflag = 0, tempcx,
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002489 CRT1Index;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002490
2491 pVBInfo->RVBHCMAX = 1;
2492 pVBInfo->RVBHCFACT = 1;
Aaro Koskinenb3979922012-11-04 21:14:52 +02002493 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02002494 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002495 CRT1Index &= IndexMask;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002496 temp1 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[0];
2497 temp2 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[5];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002498 tempax = (temp1 & 0xFF) | ((temp2 & 0x03) << 8);
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002499 tempbx = (unsigned short) XGI_CRT1Table[CRT1Index].CR[8];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002500 tempcx = (unsigned short)
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002501 XGI_CRT1Table[CRT1Index].CR[14] << 8;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002502 tempcx &= 0x0100;
2503 tempcx = tempcx << 2;
2504 tempbx |= tempcx;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002505 temp1 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[9];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002506
2507 if (temp1 & 0x01)
2508 tempbx |= 0x0100;
2509
2510 if (temp1 & 0x20)
2511 tempbx |= 0x0200;
2512 tempax += 5;
2513
2514 if (modeflag & Charx8Dot)
2515 tempax *= 8;
2516 else
2517 tempax *= 9;
2518
2519 pVBInfo->VGAHT = tempax;
2520 pVBInfo->HT = tempax;
2521 tempbx++;
2522 pVBInfo->VGAVT = tempbx;
2523 pVBInfo->VT = tempbx;
2524}
2525
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002526static void XGI_GetCRT2Data(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302527 unsigned short RefreshRateTableIndex,
2528 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002529{
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02002530 unsigned short tempax = 0, tempbx = 0, modeflag, resinfo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002531
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02002532 struct SiS_LCDData const *LCDPtr = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002533
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002534 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002535 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2536 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302537 pVBInfo->NewFlickerMode = 0;
2538 pVBInfo->RVBHRS = 50;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002539
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302540 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002541 XGI_GetRAMDAC2DATA(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302542 return;
2543 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002544
Peter Huewea3d675c2012-02-09 21:11:47 +01002545 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002546 LCDPtr = XGI_GetLcdPtr(XGI_LCDDataTable, ModeIdIndex,
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +03002547 RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002548
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302549 pVBInfo->RVBHCMAX = LCDPtr->RVBHCMAX;
2550 pVBInfo->RVBHCFACT = LCDPtr->RVBHCFACT;
2551 pVBInfo->VGAHT = LCDPtr->VGAHT;
2552 pVBInfo->VGAVT = LCDPtr->VGAVT;
2553 pVBInfo->HT = LCDPtr->LCDHT;
2554 pVBInfo->VT = LCDPtr->LCDVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002555
Peter Huewe255aabd2012-02-09 21:11:44 +01002556 if (pVBInfo->LCDResInfo == Panel_1024x768) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302557 tempax = 1024;
2558 tempbx = 768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002559
Peter Huewea3d675c2012-02-09 21:11:47 +01002560 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302561 if (pVBInfo->VGAVDE == 357)
2562 tempbx = 527;
2563 else if (pVBInfo->VGAVDE == 420)
2564 tempbx = 620;
2565 else if (pVBInfo->VGAVDE == 525)
2566 tempbx = 775;
2567 else if (pVBInfo->VGAVDE == 600)
2568 tempbx = 775;
Peter Huewe7580d7f2013-05-18 00:19:54 +02002569 }
Peter Huewe255aabd2012-02-09 21:11:44 +01002570 } else if (pVBInfo->LCDResInfo == Panel_1024x768x75) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302571 tempax = 1024;
2572 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01002573 } else if (pVBInfo->LCDResInfo == Panel_1280x1024) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302574 tempax = 1280;
2575 if (pVBInfo->VGAVDE == 360)
2576 tempbx = 768;
2577 else if (pVBInfo->VGAVDE == 375)
2578 tempbx = 800;
2579 else if (pVBInfo->VGAVDE == 405)
2580 tempbx = 864;
2581 else
2582 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01002583 } else if (pVBInfo->LCDResInfo == Panel_1280x1024x75) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302584 tempax = 1280;
2585 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01002586 } else if (pVBInfo->LCDResInfo == Panel_1280x960) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302587 tempax = 1280;
2588 if (pVBInfo->VGAVDE == 350)
2589 tempbx = 700;
2590 else if (pVBInfo->VGAVDE == 400)
2591 tempbx = 800;
2592 else if (pVBInfo->VGAVDE == 1024)
2593 tempbx = 960;
2594 else
2595 tempbx = 960;
Peter Huewe255aabd2012-02-09 21:11:44 +01002596 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302597 tempax = 1400;
2598 tempbx = 1050;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002599
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302600 if (pVBInfo->VGAVDE == 1024) {
2601 tempax = 1280;
2602 tempbx = 1024;
2603 }
Peter Huewe255aabd2012-02-09 21:11:44 +01002604 } else if (pVBInfo->LCDResInfo == Panel_1600x1200) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302605 tempax = 1600;
2606 tempbx = 1200; /* alan 10/14/2003 */
Peter Huewea3d675c2012-02-09 21:11:47 +01002607 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302608 if (pVBInfo->VGAVDE == 350)
2609 tempbx = 875;
2610 else if (pVBInfo->VGAVDE == 400)
2611 tempbx = 1000;
2612 }
2613 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002614
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302615 if (pVBInfo->LCDInfo & LCDNonExpanding) {
2616 tempax = pVBInfo->VGAHDE;
2617 tempbx = pVBInfo->VGAVDE;
2618 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002619
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302620 pVBInfo->HDE = tempax;
2621 pVBInfo->VDE = tempbx;
2622 return;
2623 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002624
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302625 if (pVBInfo->VBInfo & (SetCRT2ToTV)) {
Aaro Koskinen24572542012-09-11 00:15:21 +03002626 struct SiS_TVData const *TVPtr;
2627
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002628 TVPtr = XGI_GetTVPtr(ModeIdIndex, RefreshRateTableIndex,
Aaro Koskinen24572542012-09-11 00:15:21 +03002629 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002630
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302631 pVBInfo->RVBHCMAX = TVPtr->RVBHCMAX;
2632 pVBInfo->RVBHCFACT = TVPtr->RVBHCFACT;
2633 pVBInfo->VGAHT = TVPtr->VGAHT;
2634 pVBInfo->VGAVT = TVPtr->VGAVT;
2635 pVBInfo->HDE = TVPtr->TVHDE;
2636 pVBInfo->VDE = TVPtr->TVVDE;
2637 pVBInfo->RVBHRS = TVPtr->RVBHRS;
2638 pVBInfo->NewFlickerMode = TVPtr->FlickerMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002639
Peter Huewe599801f2012-02-09 21:11:45 +01002640 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302641 if (resinfo == 0x08)
2642 pVBInfo->NewFlickerMode = 0x40;
2643 else if (resinfo == 0x09)
2644 pVBInfo->NewFlickerMode = 0x40;
2645 else if (resinfo == 0x12)
2646 pVBInfo->NewFlickerMode = 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002647
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302648 if (pVBInfo->VGAVDE == 350)
2649 pVBInfo->TVInfo |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002650
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302651 tempax = ExtHiTVHT;
2652 tempbx = ExtHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002653
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302654 if (pVBInfo->VBInfo & SetInSlaveMode) {
2655 if (pVBInfo->TVInfo & TVSimuMode) {
2656 tempax = StHiTVHT;
2657 tempbx = StHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002658
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302659 if (!(modeflag & Charx8Dot)) {
2660 tempax = StHiTextTVHT;
2661 tempbx = StHiTextTVVT;
2662 }
2663 }
2664 }
Peter Huewe599801f2012-02-09 21:11:45 +01002665 } else if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
2666 if (pVBInfo->TVInfo & TVSetYPbPr750p) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302667 tempax = YPbPrTV750pHT; /* Ext750pTVHT */
2668 tempbx = YPbPrTV750pVT; /* Ext750pTVVT */
2669 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002670
Peter Huewe599801f2012-02-09 21:11:45 +01002671 if (pVBInfo->TVInfo & TVSetYPbPr525p) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302672 tempax = YPbPrTV525pHT; /* Ext525pTVHT */
2673 tempbx = YPbPrTV525pVT; /* Ext525pTVVT */
Peter Huewe599801f2012-02-09 21:11:45 +01002674 } else if (pVBInfo->TVInfo & TVSetYPbPr525i) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302675 tempax = YPbPrTV525iHT; /* Ext525iTVHT */
2676 tempbx = YPbPrTV525iVT; /* Ext525iTVVT */
2677 if (pVBInfo->TVInfo & NTSC1024x768)
2678 tempax = NTSC1024x768HT;
2679 }
2680 } else {
2681 tempax = PALHT;
2682 tempbx = PALVT;
Peter Huewe599801f2012-02-09 21:11:45 +01002683 if (!(pVBInfo->TVInfo & TVSetPAL)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302684 tempax = NTSCHT;
2685 tempbx = NTSCVT;
2686 if (pVBInfo->TVInfo & NTSC1024x768)
2687 tempax = NTSC1024x768HT;
2688 }
2689 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002690
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302691 pVBInfo->HT = tempax;
2692 pVBInfo->VT = tempbx;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302693 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002694}
2695
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002696static void XGI_SetCRT2VCLK(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302697 unsigned short RefreshRateTableIndex,
2698 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002699{
Bill Pemberton108afbf2010-06-17 13:10:47 -04002700 unsigned char di_0, di_1, tempal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002701
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002702 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeIdIndex, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302703 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
2704 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002705
Peter Huewe6896b942012-02-09 21:11:46 +01002706 if (pVBInfo->VBType & VB_SIS301) { /* shampoo 0129 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302707 /* 301 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002708 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, 0x10);
2709 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
2710 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302711 } else { /* 301b/302b/301lv/302lv */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002712 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
2713 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302714 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002715
Aaro Koskinen8104e322011-03-13 12:26:22 +02002716 xgifb_reg_set(pVBInfo->Part4Port, 0x00, 0x12);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002717
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302718 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02002719 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x28);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302720 else
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02002721 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002722}
2723
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002724static unsigned short XGI_GetColorDepth(unsigned short ModeIdIndex,
2725 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002726{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002727 unsigned short ColorDepth[6] = { 1, 2, 4, 4, 6, 8 };
2728 short index;
2729 unsigned short modeflag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302730
Aaro Koskinenb3979922012-11-04 21:14:52 +02002731 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Peter Huewe6896b942012-02-09 21:11:46 +01002732 index = (modeflag & ModeTypeMask) - ModeEGA;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302733
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002734 if (index < 0)
2735 index = 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302736
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002737 return ColorDepth[index];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302738}
2739
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002740static unsigned short XGI_GetOffset(unsigned short ModeNo,
2741 unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302742 unsigned short RefreshRateTableIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302743 struct vb_device_info *pVBInfo)
2744{
2745 unsigned short temp, colordepth, modeinfo, index, infoflag,
2746 ColorDepth[] = { 0x01, 0x02, 0x04 };
2747
Aaro Koskinenb3979922012-11-04 21:14:52 +02002748 modeinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeInfo;
Aaro Koskinena39325d2012-11-04 21:14:53 +02002749 infoflag = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302750
2751 index = (modeinfo >> 8) & 0xFF;
2752
Aaro Koskinen224114c2012-11-04 21:14:59 +02002753 temp = XGI330_ScreenOffset[index];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302754
2755 if (infoflag & InterlaceMode)
2756 temp = temp << 1;
2757
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002758 colordepth = XGI_GetColorDepth(ModeIdIndex, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302759
2760 if ((ModeNo >= 0x7C) && (ModeNo <= 0x7E)) {
2761 temp = ModeNo - 0x7C;
2762 colordepth = ColorDepth[temp];
2763 temp = 0x6B;
2764 if (infoflag & InterlaceMode)
2765 temp = temp << 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302766 }
Peter Huewe053004b2013-02-15 20:37:12 +01002767 return temp * colordepth;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302768}
2769
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002770static void XGI_SetCRT2Offset(unsigned short ModeNo,
2771 unsigned short ModeIdIndex,
2772 unsigned short RefreshRateTableIndex,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002773 struct vb_device_info *pVBInfo)
2774{
2775 unsigned short offset;
2776 unsigned char temp;
2777
2778 if (pVBInfo->VBInfo & SetInSlaveMode)
2779 return;
2780
2781 offset = XGI_GetOffset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
Aaro Koskinenb053af12013-07-16 23:13:28 +03002782 pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002783 temp = (unsigned char) (offset & 0xFF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002784 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002785 temp = (unsigned char) ((offset & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002786 xgifb_reg_set(pVBInfo->Part1Port, 0x09, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002787 temp = (unsigned char) (((offset >> 3) & 0xFF) + 1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002788 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002789}
2790
Randy Dunlap89229672010-08-10 08:46:44 -07002791static void XGI_SetCRT2FIFO(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002792{
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002793 /* threshold high ,disable auto threshold */
2794 xgifb_reg_set(pVBInfo->Part1Port, 0x01, 0x3B);
2795 /* threshold low default 04h */
2796 xgifb_reg_and_or(pVBInfo->Part1Port, 0x02, ~(0x3F), 0x04);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002797}
2798
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002799static void XGI_PreSetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302800 unsigned short RefreshRateTableIndex,
2801 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002802{
Peter Hueweef9a6b92013-02-03 04:08:43 +01002803 u8 tempcx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002804
Aaro Koskinenb053af12013-07-16 23:13:28 +03002805 XGI_SetCRT2Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302806 XGI_SetCRT2FIFO(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002807
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302808 for (tempcx = 4; tempcx < 7; tempcx++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02002809 xgifb_reg_set(pVBInfo->Part1Port, tempcx, 0x0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002810
Aaro Koskinen8104e322011-03-13 12:26:22 +02002811 xgifb_reg_set(pVBInfo->Part1Port, 0x50, 0x00);
2812 xgifb_reg_set(pVBInfo->Part1Port, 0x02, 0x44); /* temp 0206 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002813}
2814
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002815static void XGI_SetGroup1(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302816 unsigned short RefreshRateTableIndex,
2817 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002818{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302819 unsigned short temp = 0, tempax = 0, tempbx = 0, tempcx = 0,
Peter Hueweef9a6b92013-02-03 04:08:43 +01002820 pushbx = 0, CRT1Index, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002821
Aaro Koskinena39325d2012-11-04 21:14:53 +02002822 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002823 CRT1Index &= IndexMask;
Aaro Koskinenb3979922012-11-04 21:14:52 +02002824 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002825
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302826 /* bainy change table name */
2827 if (modeflag & HalfDCLK) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002828 /* BTVGA2HT 0x08,0x09 */
2829 temp = (pVBInfo->VGAHT / 2 - 1) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002830 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302831 temp = (((pVBInfo->VGAHT / 2 - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002832 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002833 /* BTVGA2HDEE 0x0A,0x0C */
2834 temp = (pVBInfo->VGAHDE / 2 + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002835 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302836 tempcx = ((pVBInfo->VGAHT - pVBInfo->VGAHDE) / 2) >> 2;
2837 pushbx = pVBInfo->VGAHDE / 2 + 16;
2838 tempcx = tempcx >> 1;
2839 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
2840 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002841
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302842 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002843 tempbx = XGI_CRT1Table[CRT1Index].CR[4];
2844 tempbx |= ((XGI_CRT1Table[CRT1Index].CR[14] &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002845 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302846 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002847 tempcx = XGI_CRT1Table[CRT1Index].CR[5];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302848 tempcx &= 0x1F;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002849 temp = XGI_CRT1Table[CRT1Index].CR[15];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302850 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
2851 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
2852 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002853
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302854 tempbx += 4;
2855 tempcx += 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002856
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302857 if (tempcx > (pVBInfo->VGAHT / 2))
2858 tempcx = pVBInfo->VGAHT / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002859
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302860 temp = tempbx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002861
Aaro Koskinen8104e322011-03-13 12:26:22 +02002862 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302863 } else {
2864 temp = (pVBInfo->VGAHT - 1) & 0x0FF; /* BTVGA2HT 0x08,0x09 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002865 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302866 temp = (((pVBInfo->VGAHT - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002867 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002868 /* BTVGA2HDEE 0x0A,0x0C */
2869 temp = (pVBInfo->VGAHDE + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002870 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302871 tempcx = (pVBInfo->VGAHT - pVBInfo->VGAHDE) >> 2; /* cx */
2872 pushbx = pVBInfo->VGAHDE + 16;
2873 tempcx = tempcx >> 1;
2874 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
2875 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002876
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302877 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002878 tempbx = XGI_CRT1Table[CRT1Index].CR[3];
2879 tempbx |= ((XGI_CRT1Table[CRT1Index].CR[5] &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002880 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302881 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002882 tempcx = XGI_CRT1Table[CRT1Index].CR[4];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302883 tempcx &= 0x1F;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002884 temp = XGI_CRT1Table[CRT1Index].CR[6];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302885 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
2886 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
2887 tempbx += 16;
2888 tempcx += 16;
2889 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002890
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302891 if (tempcx > pVBInfo->VGAHT)
2892 tempcx = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002893
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302894 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002895 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302896 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002897
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302898 tempax = (tempax & 0x00FF) | (tempbx & 0xFF00);
2899 tempbx = pushbx;
2900 tempbx = (tempbx & 0x00FF) | ((tempbx & 0xFF00) << 4);
2901 tempax |= (tempbx & 0xFF00);
2902 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002903 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302904 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002905 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302906 tempcx = (pVBInfo->VGAVT - 1);
2907 temp = tempcx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002908
Aaro Koskinen8104e322011-03-13 12:26:22 +02002909 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302910 tempbx = pVBInfo->VGAVDE - 1;
2911 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002912 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302913 temp = ((tempbx & 0xFF00) << 3) >> 8;
2914 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002915 xgifb_reg_set(pVBInfo->Part1Port, 0x12, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002916
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002917 /* BTVGA2VRS 0x10,0x11 */
2918 tempbx = (pVBInfo->VGAVT + pVBInfo->VGAVDE) >> 1;
2919 /* BTVGA2VRE 0x11 */
2920 tempcx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) >> 4) + tempbx + 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002921
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302922 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002923 tempbx = XGI_CRT1Table[CRT1Index].CR[10];
2924 temp = XGI_CRT1Table[CRT1Index].CR[9];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002925
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302926 if (temp & 0x04)
2927 tempbx |= 0x0100;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002928
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302929 if (temp & 0x080)
2930 tempbx |= 0x0200;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002931
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002932 temp = XGI_CRT1Table[CRT1Index].CR[14];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002933
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302934 if (temp & 0x08)
2935 tempbx |= 0x0400;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002936
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002937 temp = XGI_CRT1Table[CRT1Index].CR[11];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302938 tempcx = (tempcx & 0xFF00) | (temp & 0x00FF);
2939 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002940
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302941 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002942 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302943 temp = ((tempbx & 0xFF00) >> 8) << 4;
2944 temp = ((tempcx & 0x000F) | (temp));
Aaro Koskinen8104e322011-03-13 12:26:22 +02002945 xgifb_reg_set(pVBInfo->Part1Port, 0x11, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302946 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002947
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302948 if (modeflag & DoubleScanMode)
2949 tempax |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002950
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302951 if (modeflag & HalfDCLK)
2952 tempax |= 0x40;
2953
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002954 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2C, ~0x0C0, tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002955}
2956
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002957static unsigned short XGI_GetVGAHT2(struct vb_device_info *pVBInfo)
2958{
2959 unsigned long tempax, tempbx;
2960
2961 tempbx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) * pVBInfo->RVBHCMAX)
2962 & 0xFFFF;
2963 tempax = (pVBInfo->VT - pVBInfo->VDE) * pVBInfo->RVBHCFACT;
2964 tempax = (tempax * pVBInfo->HT) / tempbx;
2965
2966 return (unsigned short) tempax;
2967}
2968
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002969static void XGI_SetLockRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302970 unsigned short RefreshRateTableIndex,
2971 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002972{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302973 unsigned short push1, push2, tempax, tempbx = 0, tempcx, temp, resinfo,
Peter Hueweef9a6b92013-02-03 04:08:43 +01002974 modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002975
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002976 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002977 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2978 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002979
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302980 if (!(pVBInfo->VBInfo & SetInSlaveMode))
2981 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002982
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302983 temp = 0xFF; /* set MAX HT */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002984 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302985 tempcx = 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002986
Peter Huewe6896b942012-02-09 21:11:46 +01002987 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302988 modeflag |= Charx8Dot;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002989
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302990 tempax = pVBInfo->VGAHDE; /* 0x04 Horizontal Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002991
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302992 if (modeflag & HalfDCLK)
2993 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002994
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302995 tempax = (tempax / tempcx) - 1;
2996 tempbx |= ((tempax & 0x00FF) << 8);
2997 temp = tempax & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002998 xgifb_reg_set(pVBInfo->Part1Port, 0x04, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002999
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303000 temp = (tempbx & 0xFF00) >> 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003001
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303002 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Peter Huewe6896b942012-02-09 21:11:46 +01003003 if (!(pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3004 | VB_SIS302LV | VB_XGI301C)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303005 temp += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003006
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03003007 if ((pVBInfo->VBInfo & SetCRT2ToHiVision) &&
3008 !(pVBInfo->VBType & VB_SIS301LV) && (resinfo == 7))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303009 temp -= 2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303010 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003011
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003012 /* 0x05 Horizontal Display Start */
3013 xgifb_reg_set(pVBInfo->Part1Port, 0x05, temp);
3014 /* 0x06 Horizontal Blank end */
3015 xgifb_reg_set(pVBInfo->Part1Port, 0x06, 0x03);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003016
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303017 if (!(pVBInfo->VBInfo & DisableCRT2Display)) { /* 030226 bainy */
3018 if (pVBInfo->VBInfo & SetCRT2ToTV)
3019 tempax = pVBInfo->VGAHT;
3020 else
3021 tempax = XGI_GetVGAHT2(pVBInfo);
3022 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003023
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303024 if (tempax >= pVBInfo->VGAHT)
3025 tempax = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003026
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303027 if (modeflag & HalfDCLK)
3028 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003029
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303030 tempax = (tempax / tempcx) - 5;
3031 tempcx = tempax; /* 20030401 0x07 horizontal Retrace Start */
Peter Huewe599801f2012-02-09 21:11:45 +01003032 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303033 temp = (tempbx & 0x00FF) - 1;
3034 if (!(modeflag & HalfDCLK)) {
3035 temp -= 6;
3036 if (pVBInfo->TVInfo & TVSimuMode) {
3037 temp -= 4;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003038 temp -= 10;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303039 }
3040 }
3041 } else {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303042 tempbx = (tempbx & 0xFF00) >> 8;
3043 tempcx = (tempcx + tempbx) >> 1;
3044 temp = (tempcx & 0x00FF) + 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003045
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303046 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3047 temp -= 1;
3048 if (!(modeflag & HalfDCLK)) {
3049 if ((modeflag & Charx8Dot)) {
3050 temp += 4;
3051 if (pVBInfo->VGAHDE >= 800)
3052 temp -= 6;
3053 }
3054 }
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003055 } else if (!(modeflag & HalfDCLK)) {
3056 temp -= 4;
Peter Huewe255aabd2012-02-09 21:11:44 +01003057 if (pVBInfo->LCDResInfo != Panel_1280x960 &&
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003058 pVBInfo->VGAHDE >= 800) {
3059 temp -= 7;
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003060 if (pVBInfo->VGAHDE >= 1280 &&
Peter Huewe255aabd2012-02-09 21:11:44 +01003061 pVBInfo->LCDResInfo != Panel_1280x960 &&
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003062 (pVBInfo->LCDInfo & LCDNonExpanding))
3063 temp += 28;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303064 }
3065 }
3066 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003067
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003068 /* 0x07 Horizontal Retrace Start */
3069 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
3070 /* 0x08 Horizontal Retrace End */
3071 xgifb_reg_set(pVBInfo->Part1Port, 0x08, 0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003072
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303073 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3074 if (pVBInfo->TVInfo & TVSimuMode) {
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003075 if (ModeNo == 0x50) {
Peter Huewe85b38472013-05-13 23:41:49 +02003076 if (pVBInfo->TVInfo == SetNTSCTV) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003077 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303078 0x07, 0x30);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003079 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303080 0x08, 0x03);
3081 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003082 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303083 0x07, 0x2f);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003084 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303085 0x08, 0x02);
3086 }
3087 }
3088 }
3089 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003090
Aaro Koskinen8104e322011-03-13 12:26:22 +02003091 xgifb_reg_set(pVBInfo->Part1Port, 0x18, 0x03); /* 0x18 SR0B */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003092 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0xF0, 0x00);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003093 xgifb_reg_set(pVBInfo->Part1Port, 0x09, 0xFF); /* 0x09 Set Max VT */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003094
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303095 tempbx = pVBInfo->VGAVT;
3096 push1 = tempbx;
3097 tempcx = 0x121;
3098 tempbx = pVBInfo->VGAVDE; /* 0x0E Virtical Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003099
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303100 if (tempbx == 357)
3101 tempbx = 350;
3102 if (tempbx == 360)
3103 tempbx = 350;
3104 if (tempbx == 375)
3105 tempbx = 350;
3106 if (tempbx == 405)
3107 tempbx = 400;
3108 if (tempbx == 525)
3109 tempbx = 480;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003110
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303111 push2 = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003112
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303113 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
Peter Huewe255aabd2012-02-09 21:11:44 +01003114 if (pVBInfo->LCDResInfo == Panel_1024x768) {
Peter Huewea3d675c2012-02-09 21:11:47 +01003115 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303116 if (tempbx == 350)
3117 tempbx += 5;
3118 if (tempbx == 480)
3119 tempbx += 5;
3120 }
3121 }
3122 }
3123 tempbx--;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303124 tempbx--;
3125 temp = tempbx & 0x00FF;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003126 /* 0x10 vertical Blank Start */
3127 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303128 tempbx = push2;
3129 tempbx--;
3130 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003131 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003132
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303133 if (tempbx & 0x0100)
3134 tempcx |= 0x0002;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003135
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303136 tempax = 0x000B;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003137
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303138 if (modeflag & DoubleScanMode)
3139 tempax |= 0x08000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003140
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303141 if (tempbx & 0x0200)
3142 tempcx |= 0x0040;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003143
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303144 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003145 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003146
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303147 if (tempbx & 0x0400)
3148 tempcx |= 0x0600;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003149
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003150 /* 0x11 Vertival Blank End */
3151 xgifb_reg_set(pVBInfo->Part1Port, 0x11, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303152
3153 tempax = push1;
3154 tempax -= tempbx; /* 0x0C Vertical Retrace Start */
3155 tempax = tempax >> 2;
3156 push1 = tempax; /* push ax */
3157
3158 if (resinfo != 0x09) {
3159 tempax = tempax << 1;
3160 tempbx += tempax;
3161 }
3162
Peter Huewe599801f2012-02-09 21:11:45 +01003163 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Miguel Gómez470c5332012-07-06 12:40:50 +02003164 if ((pVBInfo->VBType & VB_SIS301LV) &&
3165 !(pVBInfo->TVInfo & TVSetHiVision)) {
3166 if ((pVBInfo->TVInfo & TVSimuMode) &&
3167 (pVBInfo->TVInfo & TVSetPAL)) {
3168 if (!(pVBInfo->VBType & VB_SIS301LV) ||
3169 !(pVBInfo->TVInfo &
3170 (TVSetYPbPr525p |
3171 TVSetYPbPr750p |
3172 TVSetHiVision)))
3173 tempbx += 40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303174 }
3175 } else {
3176 tempbx -= 10;
3177 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003178 } else if (pVBInfo->TVInfo & TVSimuMode) {
3179 if (pVBInfo->TVInfo & TVSetPAL) {
3180 if (pVBInfo->VBType & VB_SIS301LV) {
3181 if (!(pVBInfo->TVInfo &
3182 (TVSetYPbPr525p |
3183 TVSetYPbPr750p |
3184 TVSetHiVision)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303185 tempbx += 40;
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003186 } else {
3187 tempbx += 40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303188 }
3189 }
3190 }
3191 tempax = push1;
3192 tempax = tempax >> 2;
3193 tempax++;
3194 tempax += tempbx;
3195 push1 = tempax; /* push ax */
3196
Peter Huewe599801f2012-02-09 21:11:45 +01003197 if ((pVBInfo->TVInfo & TVSetPAL)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303198 if (tempbx <= 513) {
3199 if (tempax >= 513)
3200 tempbx = 513;
3201 }
3202 }
3203
3204 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003205 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303206 tempbx--;
3207 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003208 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303209
3210 if (tempbx & 0x0100)
3211 tempcx |= 0x0008;
3212
3213 if (tempbx & 0x0200)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003214 xgifb_reg_and_or(pVBInfo->Part1Port, 0x0B, 0x0FF, 0x20);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303215
3216 tempbx++;
3217
3218 if (tempbx & 0x0100)
3219 tempcx |= 0x0004;
3220
3221 if (tempbx & 0x0200)
3222 tempcx |= 0x0080;
3223
3224 if (tempbx & 0x0400)
3225 tempcx |= 0x0C00;
3226
3227 tempbx = push1; /* pop ax */
3228 temp = tempbx & 0x00FF;
3229 temp &= 0x0F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003230 /* 0x0D vertical Retrace End */
3231 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303232
3233 if (tempbx & 0x0010)
3234 tempcx |= 0x2000;
3235
3236 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003237 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp); /* 0x0A CR07 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303238 temp = (tempcx & 0x0FF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003239 xgifb_reg_set(pVBInfo->Part1Port, 0x17, temp); /* 0x17 SR0A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303240 tempax = modeflag;
3241 temp = (tempax & 0xFF00) >> 8;
3242
3243 temp = (temp >> 1) & 0x09;
3244
Peter Huewe6896b942012-02-09 21:11:46 +01003245 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303246 temp |= 0x01;
3247
Aaro Koskinen8104e322011-03-13 12:26:22 +02003248 xgifb_reg_set(pVBInfo->Part1Port, 0x16, temp); /* 0x16 SR01 */
3249 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, 0); /* 0x0F CR14 */
3250 xgifb_reg_set(pVBInfo->Part1Port, 0x12, 0); /* 0x12 CR17 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303251
3252 if (pVBInfo->LCDInfo & LCDRGB18Bit)
3253 temp = 0x80;
3254 else
3255 temp = 0x00;
3256
Aaro Koskinen8104e322011-03-13 12:26:22 +02003257 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, temp); /* 0x1A SR0E */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003258}
3259
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003260static void XGI_SetGroup2(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303261 unsigned short RefreshRateTableIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303262 struct vb_device_info *pVBInfo)
3263{
3264 unsigned short i, j, tempax, tempbx, tempcx, temp, push1, push2,
Peter Hueweef9a6b92013-02-03 04:08:43 +01003265 modeflag;
Aaro Koskinend21222d2012-09-11 00:15:29 +03003266 unsigned char const *TimingPoint;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303267
3268 unsigned long longtemp, tempeax, tempebx, temp2, tempecx;
3269
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003270 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02003271 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303272
3273 tempax = 0;
3274
3275 if (!(pVBInfo->VBInfo & SetCRT2ToAVIDEO))
3276 tempax |= 0x0800;
3277
3278 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3279 tempax |= 0x0400;
3280
3281 if (pVBInfo->VBInfo & SetCRT2ToSCART)
3282 tempax |= 0x0200;
3283
Peter Huewe599801f2012-02-09 21:11:45 +01003284 if (!(pVBInfo->TVInfo & TVSetPAL))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303285 tempax |= 0x1000;
3286
Peter Huewe599801f2012-02-09 21:11:45 +01003287 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303288 tempax |= 0x0100;
3289
Peter Huewe599801f2012-02-09 21:11:45 +01003290 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303291 tempax &= 0xfe00;
3292
3293 tempax = (tempax & 0xff00) >> 8;
3294
Aaro Koskinen8104e322011-03-13 12:26:22 +02003295 xgifb_reg_set(pVBInfo->Part2Port, 0x0, tempax);
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003296 TimingPoint = XGI330_NTSCTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303297
Peter Huewe599801f2012-02-09 21:11:45 +01003298 if (pVBInfo->TVInfo & TVSetPAL)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003299 TimingPoint = XGI330_PALTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303300
Peter Huewe599801f2012-02-09 21:11:45 +01003301 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003302 TimingPoint = XGI330_HiTVExtTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303303
3304 if (pVBInfo->VBInfo & SetInSlaveMode)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003305 TimingPoint = XGI330_HiTVSt2Timing;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303306
3307 if (pVBInfo->SetFlag & TVSimuMode)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003308 TimingPoint = XGI330_HiTVSt1Timing;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303309
3310 if (!(modeflag & Charx8Dot))
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003311 TimingPoint = XGI330_HiTVTextTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303312 }
3313
Peter Huewe599801f2012-02-09 21:11:45 +01003314 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
3315 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003316 TimingPoint = XGI330_YPbPr525iTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303317
Peter Huewe599801f2012-02-09 21:11:45 +01003318 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003319 TimingPoint = XGI330_YPbPr525pTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303320
Peter Huewe599801f2012-02-09 21:11:45 +01003321 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003322 TimingPoint = XGI330_YPbPr750pTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303323 }
3324
3325 for (i = 0x01, j = 0; i <= 0x2D; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02003326 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303327
3328 for (i = 0x39; i <= 0x45; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003329 /* di->temp2[j] */
3330 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303331
3332 if (pVBInfo->VBInfo & SetCRT2ToTV)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003333 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303334
3335 temp = pVBInfo->NewFlickerMode;
3336 temp &= 0x80;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003337 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xFF, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303338
Peter Huewe599801f2012-02-09 21:11:45 +01003339 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303340 tempax = 520;
3341 else
3342 tempax = 440;
3343
3344 if (pVBInfo->VDE <= tempax) {
3345 tempax -= pVBInfo->VDE;
3346 tempax = tempax >> 2;
3347 tempax = (tempax & 0x00FF) | ((tempax & 0x00FF) << 8);
3348 push1 = tempax;
3349 temp = (tempax & 0xFF00) >> 8;
3350 temp += (unsigned short) TimingPoint[0];
3351
Peter Huewe6896b942012-02-09 21:11:46 +01003352 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3353 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303354 if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO
3355 | SetCRT2ToSVIDEO | SetCRT2ToSCART
Peter Huewe599801f2012-02-09 21:11:45 +01003356 | SetCRT2ToYPbPr525750)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303357 tempcx = pVBInfo->VGAHDE;
3358 if (tempcx >= 1024) {
3359 temp = 0x17; /* NTSC */
Peter Huewe599801f2012-02-09 21:11:45 +01003360 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303361 temp = 0x19; /* PAL */
3362 }
3363 }
3364 }
3365
Aaro Koskinen8104e322011-03-13 12:26:22 +02003366 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303367 tempax = push1;
3368 temp = (tempax & 0xFF00) >> 8;
3369 temp += TimingPoint[1];
3370
Peter Huewe6896b942012-02-09 21:11:46 +01003371 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3372 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303373 if ((pVBInfo->VBInfo & (SetCRT2ToAVIDEO
3374 | SetCRT2ToSVIDEO | SetCRT2ToSCART
Peter Huewe599801f2012-02-09 21:11:45 +01003375 | SetCRT2ToYPbPr525750))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303376 tempcx = pVBInfo->VGAHDE;
3377 if (tempcx >= 1024) {
3378 temp = 0x1D; /* NTSC */
Peter Huewe599801f2012-02-09 21:11:45 +01003379 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303380 temp = 0x52; /* PAL */
3381 }
3382 }
3383 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02003384 xgifb_reg_set(pVBInfo->Part2Port, 0x02, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303385 }
3386
3387 /* 301b */
3388 tempcx = pVBInfo->HT;
3389
3390 if (XGI_IsLCDDualLink(pVBInfo))
3391 tempcx = tempcx >> 1;
3392
3393 tempcx -= 2;
3394 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003395 xgifb_reg_set(pVBInfo->Part2Port, 0x1B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303396
3397 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003398 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303399
3400 tempcx = pVBInfo->HT >> 1;
3401 push1 = tempcx; /* push cx */
3402 tempcx += 7;
3403
Peter Huewe599801f2012-02-09 21:11:45 +01003404 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303405 tempcx -= 4;
3406
3407 temp = tempcx & 0x00FF;
3408 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003409 xgifb_reg_and_or(pVBInfo->Part2Port, 0x22, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303410
3411 tempbx = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
3412 tempbx += tempcx;
3413 push2 = tempbx;
3414 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003415 xgifb_reg_set(pVBInfo->Part2Port, 0x24, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303416 temp = (tempbx & 0xFF00) >> 8;
3417 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003418 xgifb_reg_and_or(pVBInfo->Part2Port, 0x25, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303419
3420 tempbx = push2;
3421 tempbx = tempbx + 8;
Peter Huewe599801f2012-02-09 21:11:45 +01003422 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303423 tempbx = tempbx - 4;
3424 tempcx = tempbx;
3425 }
3426
3427 temp = (tempbx & 0x00FF) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003428 xgifb_reg_and_or(pVBInfo->Part2Port, 0x29, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303429
3430 j += 2;
3431 tempcx += (TimingPoint[j] | ((TimingPoint[j + 1]) << 8));
3432 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003433 xgifb_reg_set(pVBInfo->Part2Port, 0x27, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303434 temp = ((tempcx & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003435 xgifb_reg_and_or(pVBInfo->Part2Port, 0x28, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303436
3437 tempcx += 8;
Peter Huewe599801f2012-02-09 21:11:45 +01003438 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303439 tempcx -= 4;
3440
3441 temp = tempcx & 0xFF;
3442 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003443 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2A, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303444
3445 tempcx = push1; /* pop cx */
3446 j += 2;
3447 temp = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
3448 tempcx -= temp;
3449 temp = tempcx & 0x00FF;
3450 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003451 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2D, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303452
3453 tempcx -= 11;
3454
3455 if (!(pVBInfo->VBInfo & SetCRT2ToTV)) {
3456 tempax = XGI_GetVGAHT2(pVBInfo);
3457 tempcx = tempax - 1;
3458 }
3459 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003460 xgifb_reg_set(pVBInfo->Part2Port, 0x2E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303461
3462 tempbx = pVBInfo->VDE;
3463
3464 if (pVBInfo->VGAVDE == 360)
3465 tempbx = 746;
3466 if (pVBInfo->VGAVDE == 375)
3467 tempbx = 746;
3468 if (pVBInfo->VGAVDE == 405)
3469 tempbx = 853;
3470
3471 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003472 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01003473 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003474 if (!(pVBInfo->TVInfo &
Peter Huewe599801f2012-02-09 21:11:45 +01003475 (TVSetYPbPr525p | TVSetYPbPr750p)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303476 tempbx = tempbx >> 1;
3477 } else
3478 tempbx = tempbx >> 1;
3479 }
3480
3481 tempbx -= 2;
3482 temp = tempbx & 0x00FF;
3483
Peter Huewe599801f2012-02-09 21:11:45 +01003484 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Huewe6896b942012-02-09 21:11:46 +01003485 if (pVBInfo->VBType & VB_SIS301LV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003486 if (pVBInfo->TVInfo & TVSetHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303487 if (pVBInfo->VBInfo & SetInSlaveMode) {
3488 if (ModeNo == 0x2f)
3489 temp += 1;
3490 }
3491 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003492 } else if (pVBInfo->VBInfo & SetInSlaveMode) {
3493 if (ModeNo == 0x2f)
3494 temp += 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303495 }
3496 }
3497
Aaro Koskinen8104e322011-03-13 12:26:22 +02003498 xgifb_reg_set(pVBInfo->Part2Port, 0x2F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303499
3500 temp = (tempcx & 0xFF00) >> 8;
3501 temp |= ((tempbx & 0xFF00) >> 8) << 6;
3502
Peter Huewe599801f2012-02-09 21:11:45 +01003503 if (!(pVBInfo->VBInfo & SetCRT2ToHiVision)) {
Peter Huewe6896b942012-02-09 21:11:46 +01003504 if (pVBInfo->VBType & VB_SIS301LV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003505 if (pVBInfo->TVInfo & TVSetHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303506 temp |= 0x10;
3507
3508 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3509 temp |= 0x20;
3510 }
3511 } else {
3512 temp |= 0x10;
3513 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3514 temp |= 0x20;
3515 }
3516 }
3517
Aaro Koskinen8104e322011-03-13 12:26:22 +02003518 xgifb_reg_set(pVBInfo->Part2Port, 0x30, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303519
Peter Huewe6896b942012-02-09 21:11:46 +01003520 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3521 | VB_SIS302LV | VB_XGI301C)) { /* TV gatingno */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303522 tempbx = pVBInfo->VDE;
3523 tempcx = tempbx - 2;
3524
3525 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003526 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p
3527 | TVSetYPbPr750p)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303528 tempbx = tempbx >> 1;
3529 }
3530
Peter Huewe6896b942012-02-09 21:11:46 +01003531 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303532 temp = 0;
3533 if (tempcx & 0x0400)
3534 temp |= 0x20;
3535
3536 if (tempbx & 0x0400)
3537 temp |= 0x40;
3538
Aaro Koskinen8104e322011-03-13 12:26:22 +02003539 xgifb_reg_set(pVBInfo->Part4Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303540 }
3541
3542 temp = (((tempbx - 3) & 0x0300) >> 8) << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003543 xgifb_reg_set(pVBInfo->Part2Port, 0x46, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303544 temp = (tempbx - 3) & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003545 xgifb_reg_set(pVBInfo->Part2Port, 0x47, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303546 }
3547
3548 tempbx = tempbx & 0x00FF;
3549
3550 if (!(modeflag & HalfDCLK)) {
3551 tempcx = pVBInfo->VGAHDE;
3552 if (tempcx >= pVBInfo->HDE) {
3553 tempbx |= 0x2000;
3554 tempax &= 0x00FF;
3555 }
3556 }
3557
3558 tempcx = 0x0101;
3559
3560 if (pVBInfo->VBInfo & SetCRT2ToTV) { /*301b*/
3561 if (pVBInfo->VGAHDE >= 1024) {
3562 tempcx = 0x1920;
3563 if (pVBInfo->VGAHDE >= 1280) {
3564 tempcx = 0x1420;
3565 tempbx = tempbx & 0xDFFF;
3566 }
3567 }
3568 }
3569
3570 if (!(tempbx & 0x2000)) {
3571 if (modeflag & HalfDCLK)
3572 tempcx = (tempcx & 0xFF00) | ((tempcx & 0x00FF) << 1);
3573
3574 push1 = tempbx;
3575 tempeax = pVBInfo->VGAHDE;
3576 tempebx = (tempcx & 0xFF00) >> 8;
3577 longtemp = tempeax * tempebx;
3578 tempecx = tempcx & 0x00FF;
3579 longtemp = longtemp / tempecx;
3580
3581 /* 301b */
3582 tempecx = 8 * 1024;
3583
Peter Huewe6896b942012-02-09 21:11:46 +01003584 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3585 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303586 tempecx = tempecx * 8;
3587 }
3588
3589 longtemp = longtemp * tempecx;
3590 tempecx = pVBInfo->HDE;
3591 temp2 = longtemp % tempecx;
3592 tempeax = longtemp / tempecx;
3593 if (temp2 != 0)
3594 tempeax += 1;
3595
3596 tempax = (unsigned short) tempeax;
3597
3598 /* 301b */
Peter Huewe6896b942012-02-09 21:11:46 +01003599 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3600 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303601 tempcx = ((tempax & 0xFF00) >> 5) >> 8;
3602 }
3603 /* end 301b */
3604
3605 tempbx = push1;
3606 tempbx = (unsigned short) (((tempeax & 0x0000FF00) & 0x1F00)
3607 | (tempbx & 0x00FF));
3608 tempax = (unsigned short) (((tempeax & 0x000000FF) << 8)
3609 | (tempax & 0x00FF));
3610 temp = (tempax & 0xFF00) >> 8;
3611 } else {
3612 temp = (tempax & 0x00FF) >> 8;
3613 }
3614
Aaro Koskinen8104e322011-03-13 12:26:22 +02003615 xgifb_reg_set(pVBInfo->Part2Port, 0x44, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303616 temp = (tempbx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003617 xgifb_reg_and_or(pVBInfo->Part2Port, 0x45, ~0x03F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303618 temp = tempcx & 0x00FF;
3619
3620 if (tempbx & 0x2000)
3621 temp = 0;
3622
3623 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
3624 temp |= 0x18;
3625
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003626 xgifb_reg_and_or(pVBInfo->Part2Port, 0x46, ~0x1F, temp);
Peter Huewe599801f2012-02-09 21:11:45 +01003627 if (pVBInfo->TVInfo & TVSetPAL) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303628 tempbx = 0x0382;
3629 tempcx = 0x007e;
3630 } else {
3631 tempbx = 0x0369;
3632 tempcx = 0x0061;
3633 }
3634
3635 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003636 xgifb_reg_set(pVBInfo->Part2Port, 0x4b, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303637 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003638 xgifb_reg_set(pVBInfo->Part2Port, 0x4c, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303639
3640 temp = ((tempcx & 0xFF00) >> 8) & 0x03;
3641 temp = temp << 2;
3642 temp |= ((tempbx & 0xFF00) >> 8) & 0x03;
3643
Peter Huewe599801f2012-02-09 21:11:45 +01003644 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303645 temp |= 0x10;
3646
Peter Huewe599801f2012-02-09 21:11:45 +01003647 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303648 temp |= 0x20;
3649
Peter Huewe599801f2012-02-09 21:11:45 +01003650 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303651 temp |= 0x60;
3652 }
3653
Aaro Koskinen8104e322011-03-13 12:26:22 +02003654 xgifb_reg_set(pVBInfo->Part2Port, 0x4d, temp);
Aaro Koskinen58839b02011-03-13 12:26:23 +02003655 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x43); /* 301b change */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003656 xgifb_reg_set(pVBInfo->Part2Port, 0x43, (unsigned short) (temp - 3));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303657
Peter Huewe599801f2012-02-09 21:11:45 +01003658 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303659 if (pVBInfo->TVInfo & NTSC1024x768) {
3660 TimingPoint = XGI_NTSC1024AdjTime;
3661 for (i = 0x1c, j = 0; i <= 0x30; i++, j++) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003662 xgifb_reg_set(pVBInfo->Part2Port, i,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303663 TimingPoint[j]);
3664 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02003665 xgifb_reg_set(pVBInfo->Part2Port, 0x43, 0x72);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303666 }
3667 }
3668
Miguel Gómez949eb0a2012-07-06 12:40:36 +02003669 /* Modify for 301C PALM Support */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303670 if (pVBInfo->VBType & VB_XGI301C) {
Peter Huewe599801f2012-02-09 21:11:45 +01003671 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003672 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x08,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303673 0x08); /* PALM Mode */
3674 }
3675
Peter Huewe599801f2012-02-09 21:11:45 +01003676 if (pVBInfo->TVInfo & TVSetPALM) {
Peter Huewe9388ad92013-02-15 20:37:10 +01003677 tempax = xgifb_reg_get(pVBInfo->Part2Port, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303678 tempax--;
Aaro Koskinendc505562011-03-13 12:26:26 +02003679 xgifb_reg_and(pVBInfo->Part2Port, 0x01, tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303680
Aaro Koskinendc505562011-03-13 12:26:26 +02003681 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xEF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303682 }
3683
Peter Huewe599801f2012-02-09 21:11:45 +01003684 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303685 if (!(pVBInfo->VBInfo & SetInSlaveMode))
Aaro Koskinen8104e322011-03-13 12:26:22 +02003686 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303687 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303688}
3689
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03003690static void XGI_SetLCDRegs(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303691 unsigned short RefreshRateTableIndex,
3692 struct vb_device_info *pVBInfo)
3693{
Peter Hueweef9a6b92013-02-03 04:08:43 +01003694 unsigned short pushbx, tempax, tempbx, tempcx, temp, tempah,
3695 tempbh, tempch;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303696
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02003697 struct XGI_LCDDesStruct const *LCDBDesPtr = NULL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303698
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003699 /* si+Ext_ResInfo */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303700 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
3701 return;
3702
3703 tempbx = pVBInfo->HDE; /* RHACTE=HDE-1 */
3704
3705 if (XGI_IsLCDDualLink(pVBInfo))
3706 tempbx = tempbx >> 1;
3707
3708 tempbx -= 1;
3709 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003710 xgifb_reg_set(pVBInfo->Part2Port, 0x2C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303711 temp = (tempbx & 0xFF00) >> 8;
3712 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003713 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2B, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303714 temp = 0x01;
3715
Aaro Koskinen8104e322011-03-13 12:26:22 +02003716 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303717 tempbx = pVBInfo->VDE; /* RTVACTEO=(VDE-1)&0xFF */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303718 tempbx--;
3719 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003720 xgifb_reg_set(pVBInfo->Part2Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303721 temp = ((tempbx & 0xFF00) >> 8) & 0x07;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003722 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0C, ~0x07, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303723
3724 tempcx = pVBInfo->VT - 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303725 temp = tempcx & 0x00FF; /* RVTVT=VT-1 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003726 xgifb_reg_set(pVBInfo->Part2Port, 0x19, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303727 temp = (tempcx & 0xFF00) >> 8;
3728 temp = temp << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003729 xgifb_reg_set(pVBInfo->Part2Port, 0x1A, temp);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003730 xgifb_reg_and_or(pVBInfo->Part2Port, 0x09, 0xF0, 0x00);
3731 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xF0, 0x00);
3732 xgifb_reg_and_or(pVBInfo->Part2Port, 0x17, 0xFB, 0x00);
3733 xgifb_reg_and_or(pVBInfo->Part2Port, 0x18, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303734
Justin P. Mattock558f7582012-10-02 21:17:11 -07003735 /* Customized LCDB Does not add */
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02003736 if ((pVBInfo->VBType & VB_SIS301LV) || (pVBInfo->VBType & VB_SIS302LV))
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03003737 LCDBDesPtr = XGI_GetLcdPtr(xgifb_lcddldes, ModeIdIndex,
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02003738 RefreshRateTableIndex, pVBInfo);
3739 else
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03003740 LCDBDesPtr = XGI_GetLcdPtr(XGI_LCDDesDataTable, ModeIdIndex,
3741 RefreshRateTableIndex, pVBInfo);
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02003742
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303743 tempah = pVBInfo->LCDResInfo;
3744 tempah &= PanelResInfo;
3745
Peter Huewe255aabd2012-02-09 21:11:44 +01003746 if ((tempah == Panel_1024x768) || (tempah == Panel_1024x768x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303747 tempbx = 1024;
3748 tempcx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01003749 } else if ((tempah == Panel_1280x1024) ||
3750 (tempah == Panel_1280x1024x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303751 tempbx = 1280;
3752 tempcx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01003753 } else if (tempah == Panel_1400x1050) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303754 tempbx = 1400;
3755 tempcx = 1050;
3756 } else {
3757 tempbx = 1600;
3758 tempcx = 1200;
3759 }
3760
3761 if (pVBInfo->LCDInfo & EnableScalingLCD) {
3762 tempbx = pVBInfo->HDE;
3763 tempcx = pVBInfo->VDE;
3764 }
3765
3766 pushbx = tempbx;
3767 tempax = pVBInfo->VT;
3768 pVBInfo->LCDHDES = LCDBDesPtr->LCDHDES;
3769 pVBInfo->LCDHRS = LCDBDesPtr->LCDHRS;
3770 pVBInfo->LCDVDES = LCDBDesPtr->LCDVDES;
3771 pVBInfo->LCDVRS = LCDBDesPtr->LCDVRS;
3772 tempbx = pVBInfo->LCDVDES;
3773 tempcx += tempbx;
3774
3775 if (tempcx >= tempax)
3776 tempcx -= tempax; /* lcdvdes */
3777
3778 temp = tempbx & 0x00FF; /* RVEQ1EQ=lcdvdes */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003779 xgifb_reg_set(pVBInfo->Part2Port, 0x05, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303780 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003781 xgifb_reg_set(pVBInfo->Part2Port, 0x06, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303782 tempch = ((tempcx & 0xFF00) >> 8) & 0x07;
3783 tempbh = ((tempbx & 0xFF00) >> 8) & 0x07;
3784 tempah = tempch;
3785 tempah = tempah << 3;
3786 tempah |= tempbh;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003787 xgifb_reg_set(pVBInfo->Part2Port, 0x02, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303788
3789 /* getlcdsync() */
3790 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
3791 tempcx = tempbx;
3792 tempax = pVBInfo->VT;
3793 tempbx = pVBInfo->LCDVRS;
3794
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303795 tempcx += tempbx;
3796 if (tempcx >= tempax)
3797 tempcx -= tempax;
3798
3799 temp = tempbx & 0x00FF; /* RTVACTEE=lcdvrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003800 xgifb_reg_set(pVBInfo->Part2Port, 0x04, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303801 temp = (tempbx & 0xFF00) >> 8;
3802 temp = temp << 4;
3803 temp |= (tempcx & 0x000F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003804 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303805 tempcx = pushbx;
3806 tempax = pVBInfo->HT;
3807 tempbx = pVBInfo->LCDHDES;
3808 tempbx &= 0x0FFF;
3809
3810 if (XGI_IsLCDDualLink(pVBInfo)) {
3811 tempax = tempax >> 1;
3812 tempbx = tempbx >> 1;
3813 tempcx = tempcx >> 1;
3814 }
3815
Peter Huewe6896b942012-02-09 21:11:46 +01003816 if (pVBInfo->VBType & VB_SIS302LV)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303817 tempbx += 1;
3818
3819 if (pVBInfo->VBType & VB_XGI301C) /* tap4 */
3820 tempbx += 1;
3821
3822 tempcx += tempbx;
3823
3824 if (tempcx >= tempax)
3825 tempcx -= tempax;
3826
3827 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003828 xgifb_reg_set(pVBInfo->Part2Port, 0x1F, temp); /* RHBLKE=lcdhdes */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303829 temp = ((tempbx & 0xFF00) >> 8) << 4;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003830 xgifb_reg_set(pVBInfo->Part2Port, 0x20, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303831 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003832 xgifb_reg_set(pVBInfo->Part2Port, 0x23, temp); /* RHEQPLE=lcdhdee */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303833 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003834 xgifb_reg_set(pVBInfo->Part2Port, 0x25, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303835
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303836 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
3837 tempcx = tempax;
3838 tempax = pVBInfo->HT;
3839 tempbx = pVBInfo->LCDHRS;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303840 if (XGI_IsLCDDualLink(pVBInfo)) {
3841 tempax = tempax >> 1;
3842 tempbx = tempbx >> 1;
3843 tempcx = tempcx >> 1;
3844 }
3845
Peter Huewe6896b942012-02-09 21:11:46 +01003846 if (pVBInfo->VBType & VB_SIS302LV)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303847 tempbx += 1;
3848
3849 tempcx += tempbx;
3850
3851 if (tempcx >= tempax)
3852 tempcx -= tempax;
3853
3854 temp = tempbx & 0x00FF; /* RHBURSTS=lcdhrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003855 xgifb_reg_set(pVBInfo->Part2Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303856
3857 temp = (tempbx & 0xFF00) >> 8;
3858 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003859 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303860 temp = tempcx & 0x00FF; /* RHSYEXP2S=lcdhre */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003861 xgifb_reg_set(pVBInfo->Part2Port, 0x21, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303862
Peter Huewea3d675c2012-02-09 21:11:47 +01003863 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303864 if (pVBInfo->VGAVDE == 525) {
Peter Huewe6896b942012-02-09 21:11:46 +01003865 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
3866 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303867 | VB_XGI301C)) {
3868 temp = 0xC6;
3869 } else
3870 temp = 0xC4;
3871
Aaro Koskinen8104e322011-03-13 12:26:22 +02003872 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
3873 xgifb_reg_set(pVBInfo->Part2Port, 0x30, 0xB3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303874 }
3875
3876 if (pVBInfo->VGAVDE == 420) {
Peter Huewe6896b942012-02-09 21:11:46 +01003877 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
3878 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303879 | VB_XGI301C)) {
3880 temp = 0x4F;
3881 } else
3882 temp = 0x4E;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003883 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303884 }
3885 }
3886}
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003887
3888/* --------------------------------------------------------------------- */
3889/* Function : XGI_GetTap4Ptr */
3890/* Input : */
3891/* Output : di -> Tap4 Reg. Setting Pointer */
3892/* Description : */
3893/* --------------------------------------------------------------------- */
Aaro Koskinen1cccd9e2012-11-04 21:15:06 +02003894static struct XGI301C_Tap4TimingStruct const
3895*XGI_GetTap4Ptr(unsigned short tempcx, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003896{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303897 unsigned short tempax, tempbx, i;
Aaro Koskinen1cccd9e2012-11-04 21:15:06 +02003898 struct XGI301C_Tap4TimingStruct const *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003899
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303900 if (tempcx == 0) {
3901 tempax = pVBInfo->VGAHDE;
3902 tempbx = pVBInfo->HDE;
3903 } else {
3904 tempax = pVBInfo->VGAVDE;
3905 tempbx = pVBInfo->VDE;
3906 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003907
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03003908 if (tempax <= tempbx)
3909 return &xgifb_tap4_timing[0];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303910 else
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03003911 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing; /* NTSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003912
Peter Huewe599801f2012-02-09 21:11:45 +01003913 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303914 Tap4TimingPtr = PALTap4Timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003915
Peter Huewe599801f2012-02-09 21:11:45 +01003916 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
3917 if ((pVBInfo->TVInfo & TVSetYPbPr525i) ||
3918 (pVBInfo->TVInfo & TVSetYPbPr525p))
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03003919 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing;
Peter Huewe599801f2012-02-09 21:11:45 +01003920 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303921 Tap4TimingPtr = YPbPr750pTap4Timing;
3922 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003923
Peter Huewe599801f2012-02-09 21:11:45 +01003924 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03003925 Tap4TimingPtr = xgifb_tap4_timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003926
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303927 i = 0;
3928 while (Tap4TimingPtr[i].DE != 0xFFFF) {
3929 if (Tap4TimingPtr[i].DE == tempax)
3930 break;
3931 i++;
3932 }
3933 return &Tap4TimingPtr[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003934}
3935
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003936static void XGI_SetTap4Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003937{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303938 unsigned short i, j;
Aaro Koskinen1cccd9e2012-11-04 21:15:06 +02003939 struct XGI301C_Tap4TimingStruct const *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003940
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303941 if (!(pVBInfo->VBType & VB_XGI301C))
3942 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003943
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303944 Tap4TimingPtr = XGI_GetTap4Ptr(0, pVBInfo); /* Set Horizontal Scaling */
3945 for (i = 0x80, j = 0; i <= 0xBF; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02003946 xgifb_reg_set(pVBInfo->Part2Port, i, Tap4TimingPtr->Reg[j]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003947
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003948 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
Peter Huewe599801f2012-02-09 21:11:45 +01003949 (!(pVBInfo->VBInfo & SetCRT2ToHiVision))) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003950 /* Set Vertical Scaling */
3951 Tap4TimingPtr = XGI_GetTap4Ptr(1, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303952 for (i = 0xC0, j = 0; i < 0xFF; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003953 xgifb_reg_set(pVBInfo->Part2Port,
3954 i,
3955 Tap4TimingPtr->Reg[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303956 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003957
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003958 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
Peter Huewe599801f2012-02-09 21:11:45 +01003959 (!(pVBInfo->VBInfo & SetCRT2ToHiVision)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003960 /* Enable V.Scaling */
3961 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303962 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003963 /* Enable H.Scaling */
3964 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x10);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003965}
3966
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03003967static void XGI_SetGroup3(unsigned short ModeIdIndex,
3968 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003969{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303970 unsigned short i;
Aaro Koskinend21222d2012-09-11 00:15:29 +03003971 unsigned char const *tempdi;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303972 unsigned short modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003973
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003974 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02003975 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003976
Aaro Koskinen8104e322011-03-13 12:26:22 +02003977 xgifb_reg_set(pVBInfo->Part3Port, 0x00, 0x00);
Peter Huewe599801f2012-02-09 21:11:45 +01003978 if (pVBInfo->TVInfo & TVSetPAL) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003979 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
3980 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303981 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003982 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xF5);
3983 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xB7);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303984 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003985
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303986 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
3987 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003988
Peter Huewe599801f2012-02-09 21:11:45 +01003989 if (pVBInfo->TVInfo & TVSetPALM) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003990 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
3991 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
3992 xgifb_reg_set(pVBInfo->Part3Port, 0x3D, 0xA8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303993 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003994
Peter Huewe599801f2012-02-09 21:11:45 +01003995 if ((pVBInfo->VBInfo & SetCRT2ToHiVision) || (pVBInfo->VBInfo
3996 & SetCRT2ToYPbPr525750)) {
3997 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303998 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003999
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004000 tempdi = XGI330_HiTVGroup3Data;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304001 if (pVBInfo->SetFlag & TVSimuMode) {
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004002 tempdi = XGI330_HiTVGroup3Simu;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304003 if (!(modeflag & Charx8Dot))
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004004 tempdi = XGI330_HiTVGroup3Text;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304005 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004006
Peter Huewe599801f2012-02-09 21:11:45 +01004007 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004008 tempdi = XGI330_Ren525pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004009
Peter Huewe599801f2012-02-09 21:11:45 +01004010 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004011 tempdi = XGI330_Ren750pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004012
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304013 for (i = 0; i <= 0x3E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004014 xgifb_reg_set(pVBInfo->Part3Port, i, tempdi[i]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004015
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304016 if (pVBInfo->VBType & VB_XGI301C) { /* Marcovision */
Peter Huewe599801f2012-02-09 21:11:45 +01004017 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004018 xgifb_reg_set(pVBInfo->Part3Port, 0x28, 0x3f);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304019 }
4020 }
Aaro Koskinen2351d1f2013-05-29 23:59:13 +03004021}
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304022
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03004023static void XGI_SetGroup4(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304024 unsigned short RefreshRateTableIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304025 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004026{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304027 unsigned short tempax, tempcx, tempbx, modeflag, temp, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004028
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304029 unsigned long tempebx, tempeax, templong;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004030
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004031 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004032 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304033 temp = pVBInfo->RVBHCFACT;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004034 xgifb_reg_set(pVBInfo->Part4Port, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004035
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304036 tempbx = pVBInfo->RVBHCMAX;
4037 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004038 xgifb_reg_set(pVBInfo->Part4Port, 0x14, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304039 temp2 = ((tempbx & 0xFF00) >> 8) << 7;
4040 tempcx = pVBInfo->VGAHT - 1;
4041 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004042 xgifb_reg_set(pVBInfo->Part4Port, 0x16, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004043
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304044 temp = ((tempcx & 0xFF00) >> 8) << 3;
4045 temp2 |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004046
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304047 tempcx = pVBInfo->VGAVT - 1;
4048 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
4049 tempcx -= 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004050
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304051 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004052 xgifb_reg_set(pVBInfo->Part4Port, 0x17, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304053 temp = temp2 | ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004054 xgifb_reg_set(pVBInfo->Part4Port, 0x15, temp);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004055 xgifb_reg_or(pVBInfo->Part4Port, 0x0D, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304056 tempcx = pVBInfo->VBInfo;
4057 tempbx = pVBInfo->VGAHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004058
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304059 if (modeflag & HalfDCLK)
4060 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004061
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304062 if (XGI_IsLCDDualLink(pVBInfo))
4063 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004064
Peter Huewe599801f2012-02-09 21:11:45 +01004065 if (tempcx & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304066 temp = 0;
4067 if (tempbx <= 1024)
4068 temp = 0xA0;
4069 if (tempbx == 1280)
4070 temp = 0xC0;
4071 } else if (tempcx & SetCRT2ToTV) {
4072 temp = 0xA0;
4073 if (tempbx <= 800)
4074 temp = 0x80;
4075 } else {
4076 temp = 0x80;
4077 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4078 temp = 0;
4079 if (tempbx > 800)
4080 temp = 0x60;
4081 }
4082 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004083
Peter Huewe599801f2012-02-09 21:11:45 +01004084 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304085 temp = 0x00;
4086 if (pVBInfo->VGAHDE == 1280)
4087 temp = 0x40;
4088 if (pVBInfo->VGAHDE == 1024)
4089 temp = 0x20;
4090 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004091 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0E, ~0xEF, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004092
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304093 tempebx = pVBInfo->VDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004094
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304095 tempcx = pVBInfo->RVBHRS;
4096 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004097 xgifb_reg_set(pVBInfo->Part4Port, 0x18, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004098
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304099 tempeax = pVBInfo->VGAVDE;
4100 tempcx |= 0x04000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004101
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304102 if (tempeax <= tempebx) {
4103 tempcx = (tempcx & (~0x4000));
4104 tempeax = pVBInfo->VGAVDE;
4105 } else {
4106 tempeax -= tempebx;
4107 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004108
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304109 templong = (tempeax * 256 * 1024) % tempebx;
4110 tempeax = (tempeax * 256 * 1024) / tempebx;
4111 tempebx = tempeax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004112
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304113 if (templong != 0)
4114 tempebx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004115
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304116 temp = (unsigned short) (tempebx & 0x000000FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004117 xgifb_reg_set(pVBInfo->Part4Port, 0x1B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004118
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304119 temp = (unsigned short) ((tempebx & 0x0000FF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004120 xgifb_reg_set(pVBInfo->Part4Port, 0x1A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304121 tempbx = (unsigned short) (tempebx >> 16);
4122 temp = tempbx & 0x00FF;
4123 temp = temp << 4;
4124 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004125 xgifb_reg_set(pVBInfo->Part4Port, 0x19, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004126
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304127 /* 301b */
Peter Huewe6896b942012-02-09 21:11:46 +01004128 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4129 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304130 temp = 0x0028;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004131 xgifb_reg_set(pVBInfo->Part4Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304132 tempax = pVBInfo->VGAHDE;
4133 if (modeflag & HalfDCLK)
4134 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004135
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304136 if (XGI_IsLCDDualLink(pVBInfo))
4137 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004138
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304139 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4140 if (tempax > 800)
4141 tempax -= 800;
Aaro Koskinend3ae5762012-09-11 00:15:27 +03004142 } else if (pVBInfo->VGAHDE > 800) {
4143 if (pVBInfo->VGAHDE == 1024)
4144 tempax = (tempax * 25 / 32) - 1;
4145 else
4146 tempax = (tempax * 20 / 32) - 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304147 }
4148 tempax -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004149
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304150 temp = (tempax & 0xFF00) >> 8;
4151 temp = ((temp & 0x0003) << 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004152 xgifb_reg_set(pVBInfo->Part4Port, 0x1E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304153 temp = (tempax & 0x00FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004154 xgifb_reg_set(pVBInfo->Part4Port, 0x1D, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004155
Peter Huewe599801f2012-02-09 21:11:45 +01004156 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToHiVision)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304157 if (pVBInfo->VGAHDE > 800)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004158 xgifb_reg_or(pVBInfo->Part4Port, 0x1E, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004159
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304160 }
4161 temp = 0x0036;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004162
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304163 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4164 if (!(pVBInfo->TVInfo & (NTSC1024x768
Peter Huewe599801f2012-02-09 21:11:45 +01004165 | TVSetYPbPr525p | TVSetYPbPr750p
4166 | TVSetHiVision))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304167 temp |= 0x0001;
4168 if ((pVBInfo->VBInfo & SetInSlaveMode)
4169 && (!(pVBInfo->TVInfo
4170 & TVSimuMode)))
4171 temp &= (~0x0001);
4172 }
4173 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004174
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004175 xgifb_reg_and_or(pVBInfo->Part4Port, 0x1F, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304176 tempbx = pVBInfo->HT;
4177 if (XGI_IsLCDDualLink(pVBInfo))
4178 tempbx = tempbx >> 1;
4179 tempbx = (tempbx >> 1) - 2;
4180 temp = ((tempbx & 0x0700) >> 8) << 3;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004181 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304182 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004183 xgifb_reg_set(pVBInfo->Part4Port, 0x22, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304184 }
4185 /* end 301b */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004186
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03004187 XGI_SetCRT2VCLK(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004188}
4189
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004190static void XGINew_EnableCRT2(struct vb_device_info *pVBInfo)
4191{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004192 xgifb_reg_and_or(pVBInfo->P3c4, 0x1E, 0xFF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004193}
4194
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03004195static void XGI_SetGroup5(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004196{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304197 if (pVBInfo->ModeType == ModeVGA) {
4198 if (!(pVBInfo->VBInfo & (SetInSlaveMode | LoadDACFlag
Peter Huewe6896b942012-02-09 21:11:46 +01004199 | DisableCRT2Display))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304200 XGINew_EnableCRT2(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304201 }
4202 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004203}
4204
Aaro Koskinenb053af12013-07-16 23:13:28 +03004205static void XGI_DisableGatingCRT(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004206{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004207 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004208}
4209
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004210static unsigned char XGI_XG21CheckLVDSMode(struct xgifb_video_info *xgifb_info,
4211 unsigned short ModeNo, unsigned short ModeIdIndex,
4212 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004213{
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004214 unsigned short xres, yres, colordepth, modeflag, resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004215
Aaro Koskinenb3979922012-11-04 21:14:52 +02004216 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02004217 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
4218 yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004219 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004220 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004221
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304222 if (!(modeflag & Charx8Dot)) {
4223 xres /= 9;
4224 xres *= 8;
4225 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004226
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004227 if ((ModeNo > 0x13) && (modeflag & HalfDCLK))
4228 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004229
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004230 if ((ModeNo > 0x13) && (modeflag & DoubleScanMode))
4231 yres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004232
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004233 if (xres > xgifb_info->lvds_data.LVDSHDE)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304234 return 0;
Bill Pembertondda08c52010-06-17 13:10:42 -04004235
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004236 if (yres > xgifb_info->lvds_data.LVDSVDE)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304237 return 0;
4238
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004239 if (xres != xgifb_info->lvds_data.LVDSHDE ||
4240 yres != xgifb_info->lvds_data.LVDSVDE) {
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03004241 colordepth = XGI_GetColorDepth(ModeIdIndex, pVBInfo);
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004242 if (colordepth > 2)
4243 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304244 }
4245 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004246}
4247
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004248static void xgifb_set_lvds(struct xgifb_video_info *xgifb_info,
4249 int chip_id,
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004250 unsigned short ModeIdIndex,
4251 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004252{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304253 unsigned char temp, Miscdata;
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004254 unsigned short xres, yres, modeflag, resindex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304255 unsigned short LVDSHT, LVDSHBS, LVDSHRS, LVDSHRE, LVDSHBE;
4256 unsigned short LVDSVT, LVDSVBS, LVDSVRS, LVDSVRE, LVDSVBE;
4257 unsigned short value;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004258
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004259 temp = (unsigned char) ((xgifb_info->lvds_data.LVDS_Capability &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004260 (LCDPolarity << 8)) >> 8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304261 temp &= LCDPolarity;
Peter Huewe9388ad92013-02-15 20:37:10 +01004262 Miscdata = inb(pVBInfo->P3cc);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004263
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004264 outb((Miscdata & 0x3F) | temp, pVBInfo->P3c2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004265
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004266 temp = xgifb_info->lvds_data.LVDS_Capability & LCDPolarity;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004267 /* SR35[7] FP VSync polarity */
4268 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x80, temp & 0x80);
4269 /* SR30[5] FP HSync polarity */
4270 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, ~0x20, (temp & 0x40) >> 1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004271
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004272 if (chip_id == XG27)
4273 XGI_SetXG27FPBits(pVBInfo);
4274 else
4275 XGI_SetXG21FPBits(pVBInfo);
4276
Aaro Koskinenb3979922012-11-04 21:14:52 +02004277 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02004278 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
4279 yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004280 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004281 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004282
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304283 if (!(modeflag & Charx8Dot))
4284 xres = xres * 8 / 9;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004285
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004286 LVDSHT = xgifb_info->lvds_data.LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004287
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004288 LVDSHBS = xres + (xgifb_info->lvds_data.LVDSHDE - xres) / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004289
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304290 if (LVDSHBS > LVDSHT)
4291 LVDSHBS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004292
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004293 LVDSHRS = LVDSHBS + xgifb_info->lvds_data.LVDSHFP;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304294 if (LVDSHRS > LVDSHT)
4295 LVDSHRS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004296
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004297 LVDSHRE = LVDSHRS + xgifb_info->lvds_data.LVDSHSYNC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304298 if (LVDSHRE > LVDSHT)
4299 LVDSHRE -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004300
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004301 LVDSHBE = LVDSHBS + LVDSHT - xgifb_info->lvds_data.LVDSHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004302
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004303 LVDSVT = xgifb_info->lvds_data.LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004304
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004305 LVDSVBS = yres + (xgifb_info->lvds_data.LVDSVDE - yres) / 2;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004306 if (modeflag & DoubleScanMode)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304307 LVDSVBS += yres / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004308
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304309 if (LVDSVBS > LVDSVT)
4310 LVDSVBS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004311
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004312 LVDSVRS = LVDSVBS + xgifb_info->lvds_data.LVDSVFP;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304313 if (LVDSVRS > LVDSVT)
4314 LVDSVRS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004315
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004316 LVDSVRE = LVDSVRS + xgifb_info->lvds_data.LVDSVSYNC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304317 if (LVDSVRE > LVDSVT)
4318 LVDSVRE -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004319
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004320 LVDSVBE = LVDSVBS + LVDSVT - xgifb_info->lvds_data.LVDSVDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004321
Peter Huewe9388ad92013-02-15 20:37:10 +01004322 temp = xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004323 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp & 0x7f); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004324
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304325 if (!(modeflag & Charx8Dot))
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004326 xgifb_reg_or(pVBInfo->P3c4, 0x1, 0x1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004327
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304328 /* HT SR0B[1:0] CR00 */
4329 value = (LVDSHT >> 3) - 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004330 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004331 xgifb_reg_set(pVBInfo->P3d4, 0x0, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004332
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304333 /* HBS SR0B[5:4] CR02 */
4334 value = (LVDSHBS >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004335 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x30, (value & 0x300) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004336 xgifb_reg_set(pVBInfo->P3d4, 0x2, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004337
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304338 /* HBE SR0C[1:0] CR05[7] CR03[4:0] */
4339 value = (LVDSHBE >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004340 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x03, (value & 0xC0) >> 6);
4341 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x80, (value & 0x20) << 2);
4342 xgifb_reg_and_or(pVBInfo->P3d4, 0x03, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004343
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304344 /* HRS SR0B[7:6] CR04 */
4345 value = (LVDSHRS >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004346 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0xC0, (value & 0x300) >> 2);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004347 xgifb_reg_set(pVBInfo->P3d4, 0x4, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004348
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304349 /* Panel HRS SR2F[1:0] SR2E[7:0] */
4350 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004351 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004352 xgifb_reg_set(pVBInfo->P3c4, 0x2E, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004353
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304354 /* HRE SR0C[2] CR05[4:0] */
4355 value = (LVDSHRE >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004356 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x04, (value & 0x20) >> 3);
4357 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004358
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304359 /* Panel HRE SR2F[7:2] */
4360 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004361 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0xFC, value << 2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004362
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304363 /* VT SR0A[0] CR07[5][0] CR06 */
4364 value = LVDSVT - 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004365 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x01, (value & 0x400) >> 10);
4366 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x20, (value & 0x200) >> 4);
4367 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x01, (value & 0x100) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004368 xgifb_reg_set(pVBInfo->P3d4, 0x06, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004369
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304370 /* VBS SR0A[2] CR09[5] CR07[3] CR15 */
4371 value = LVDSVBS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004372 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x04, (value & 0x400) >> 8);
4373 xgifb_reg_and_or(pVBInfo->P3d4, 0x09, ~0x20, (value & 0x200) >> 4);
4374 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x08, (value & 0x100) >> 5);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004375 xgifb_reg_set(pVBInfo->P3d4, 0x15, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004376
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304377 /* VBE SR0A[4] CR16 */
4378 value = LVDSVBE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004379 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x10, (value & 0x100) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004380 xgifb_reg_set(pVBInfo->P3d4, 0x16, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004381
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304382 /* VRS SR0A[3] CR7[7][2] CR10 */
4383 value = LVDSVRS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004384 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x08, (value & 0x400) >> 7);
4385 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x80, (value & 0x200) >> 2);
4386 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x04, (value & 0x100) >> 6);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004387 xgifb_reg_set(pVBInfo->P3d4, 0x10, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004388
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004389 if (chip_id == XG27) {
4390 /* Panel VRS SR35[2:0] SR34[7:0] */
4391 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07,
4392 (value & 0x700) >> 8);
4393 xgifb_reg_set(pVBInfo->P3c4, 0x34, value & 0xFF);
4394 } else {
4395 /* Panel VRS SR3F[1:0] SR34[7:0] SR33[0] */
4396 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0x03,
4397 (value & 0x600) >> 9);
4398 xgifb_reg_set(pVBInfo->P3c4, 0x34, (value >> 1) & 0xFF);
4399 xgifb_reg_and_or(pVBInfo->P3d4, 0x33, ~0x01, value & 0x01);
4400 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004401
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304402 /* VRE SR0A[5] CR11[3:0] */
4403 value = LVDSVRE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004404 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x20, (value & 0x10) << 1);
4405 xgifb_reg_and_or(pVBInfo->P3d4, 0x11, ~0x0F, value & 0x0F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004406
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304407 /* Panel VRE SR3F[7:2] */
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004408 if (chip_id == XG27)
4409 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
4410 (value << 2) & 0xFC);
4411 else
4412 /* SR3F[7] has to be 0, h/w bug */
4413 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
4414 (value << 2) & 0x7C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004415
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304416 for (temp = 0, value = 0; temp < 3; temp++) {
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004417
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004418 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, value);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004419 xgifb_reg_set(pVBInfo->P3c4,
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004420 0x2B, xgifb_info->lvds_data.VCLKData1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004421 xgifb_reg_set(pVBInfo->P3c4,
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004422 0x2C, xgifb_info->lvds_data.VCLKData2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304423 value += 0x10;
4424 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004425
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304426 if (!(modeflag & Charx8Dot)) {
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004427 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004428 outb(0x13, pVBInfo->P3c0); /* set index */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004429 /* set data, panning = 0, shift left 1 dot*/
4430 outb(0x00, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004431
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004432 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004433 outb(0x20, pVBInfo->P3c0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304434
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004435 inb(pVBInfo->P3da); /* reset 3da */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304436 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004437
4438}
4439
4440/* --------------------------------------------------------------------- */
4441/* Function : XGI_IsLCDON */
4442/* Input : */
Bill Pembertondda08c52010-06-17 13:10:42 -04004443/* Output : 0 : Skip PSC Control */
4444/* 1: Disable PSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004445/* Description : */
4446/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004447static unsigned char XGI_IsLCDON(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004448{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304449 unsigned short tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004450
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304451 tempax = pVBInfo->VBInfo;
4452 if (tempax & SetCRT2ToDualEdge)
4453 return 0;
Peter Huewe6896b942012-02-09 21:11:46 +01004454 else if (tempax & (DisableCRT2Display | SwitchCRT2 | SetSimuScanMode))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304455 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004456
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304457 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004458}
4459
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004460static void XGI_DisableBridge(struct xgifb_video_info *xgifb_info,
4461 struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304462 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004463{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02004464 unsigned short tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004465
Peter Huewe6896b942012-02-09 21:11:46 +01004466 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4467 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304468 tempah = 0x3F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004469 if (!(pVBInfo->VBInfo &
4470 (DisableCRT2Display | SetSimuScanMode))) {
Peter Huewea3d675c2012-02-09 21:11:47 +01004471 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Aaro Koskinen41fc5f02013-05-29 23:59:12 +03004472 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304473 tempah = 0x7F; /* Disable Channel A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304474 }
4475 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004476
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004477 /* disable part4_1f */
4478 xgifb_reg_and(pVBInfo->Part4Port, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004479
Peter Huewe6896b942012-02-09 21:11:46 +01004480 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004481 if (((pVBInfo->VBInfo &
Peter Huewe06cc47b2013-02-03 22:54:38 +01004482 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))) ||
Peter Huewe06cc47b2013-02-03 22:54:38 +01004483 (XGI_IsLCDON(pVBInfo)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004484 /* LVDS Driver power down */
4485 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304486 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004487
Aaro Koskinend1724632013-05-29 23:59:09 +03004488 if (pVBInfo->VBInfo & (DisableCRT2Display | XGI_SetCRT2ToLCDA |
4489 SetSimuScanMode))
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004490 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004491
Aaro Koskinen41fc5f02013-05-29 23:59:12 +03004492 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
4493 /* Power down */
4494 xgifb_reg_and(pVBInfo->Part1Port, 0x1e, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004495
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004496 /* disable TV as primary VGA swap */
4497 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004498
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304499 if ((pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToDualEdge)))
Aaro Koskinendc505562011-03-13 12:26:26 +02004500 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004501
Aaro Koskinenc4f9c312013-05-29 23:59:07 +03004502 if ((pVBInfo->VBInfo &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004503 (DisableCRT2Display | SetSimuScanMode)) ||
Peter Huewea3d675c2012-02-09 21:11:47 +01004504 ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) &&
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004505 (pVBInfo->VBInfo &
4506 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004507 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004508
Aaro Koskinenc4f9c312013-05-29 23:59:07 +03004509 if ((pVBInfo->VBInfo &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004510 (DisableCRT2Display | SetSimuScanMode)) ||
Peter Huewea3d675c2012-02-09 21:11:47 +01004511 (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) ||
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004512 (pVBInfo->VBInfo &
4513 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))) {
4514 /* save Part1 index 0 */
4515 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
4516 /* BTDAC = 1, avoid VB reset */
4517 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x10);
4518 /* disable CRT2 */
4519 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
4520 /* restore Part1 index 0 */
4521 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304522 }
4523 } else { /* {301} */
4524 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004525 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
4526 /* Disable CRT2 */
4527 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
4528 /* Disable TV asPrimary VGA swap */
4529 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xDF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304530 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004531
Peter Huewea3d675c2012-02-09 21:11:47 +01004532 if (pVBInfo->VBInfo & (DisableCRT2Display | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304533 | SetSimuScanMode))
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004534 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304535 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004536}
4537
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004538/* --------------------------------------------------------------------- */
4539/* Function : XGI_GetTVPtrIndex */
4540/* Input : */
4541/* Output : */
4542/* Description : bx 0 : ExtNTSC */
4543/* 1 : StNTSC */
4544/* 2 : ExtPAL */
4545/* 3 : StPAL */
4546/* 4 : ExtHiTV */
4547/* 5 : StHiTV */
4548/* 6 : Ext525i */
4549/* 7 : St525i */
4550/* 8 : Ext525p */
4551/* 9 : St525p */
4552/* A : Ext750p */
4553/* B : St750p */
4554/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004555static unsigned short XGI_GetTVPtrIndex(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004556{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304557 unsigned short tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004558
Peter Huewe599801f2012-02-09 21:11:45 +01004559 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304560 tempbx = 2;
Peter Huewe599801f2012-02-09 21:11:45 +01004561 if (pVBInfo->TVInfo & TVSetHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304562 tempbx = 4;
Peter Huewe599801f2012-02-09 21:11:45 +01004563 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304564 tempbx = 6;
Peter Huewe599801f2012-02-09 21:11:45 +01004565 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304566 tempbx = 8;
Peter Huewe599801f2012-02-09 21:11:45 +01004567 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304568 tempbx = 10;
4569 if (pVBInfo->TVInfo & TVSimuMode)
4570 tempbx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004571
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304572 return tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004573}
4574
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004575/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004576/* Function : XGI_GetTVPtrIndex2 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004577/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004578/* Output : bx 0 : NTSC */
4579/* 1 : PAL */
4580/* 2 : PALM */
4581/* 3 : PALN */
4582/* 4 : NTSC1024x768 */
4583/* 5 : PAL-M 1024x768 */
4584/* 6-7: reserved */
4585/* cl 0 : YFilter1 */
4586/* 1 : YFilter2 */
4587/* ch 0 : 301A */
4588/* 1 : 301B/302B/301LV/302LV */
4589/* Description : */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004590/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004591static void XGI_GetTVPtrIndex2(unsigned short *tempbx, unsigned char *tempcl,
4592 unsigned char *tempch, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004593{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004594 *tempbx = 0;
4595 *tempcl = 0;
4596 *tempch = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004597
Peter Huewe599801f2012-02-09 21:11:45 +01004598 if (pVBInfo->TVInfo & TVSetPAL)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004599 *tempbx = 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004600
Peter Huewe599801f2012-02-09 21:11:45 +01004601 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004602 *tempbx = 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004603
Peter Huewe599801f2012-02-09 21:11:45 +01004604 if (pVBInfo->TVInfo & TVSetPALN)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004605 *tempbx = 3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004606
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004607 if (pVBInfo->TVInfo & NTSC1024x768) {
4608 *tempbx = 4;
Peter Huewe599801f2012-02-09 21:11:45 +01004609 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004610 *tempbx = 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304611 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004612
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 if ((!(pVBInfo->VBInfo & SetInSlaveMode)) || (pVBInfo->TVInfo
4616 & TVSimuMode)) {
4617 *tempbx += 8;
4618 *tempcl += 1;
4619 }
4620 }
4621
Peter Huewe6896b942012-02-09 21:11:46 +01004622 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4623 | VB_SIS302LV | VB_XGI301C))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004624 (*tempch)++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004625}
4626
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004627static void XGI_SetDelayComp(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004628{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304629 unsigned char tempah, tempbl, tempbh;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004630
Peter Huewe6896b942012-02-09 21:11:46 +01004631 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4632 | VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01004633 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304634 | SetCRT2ToTV | SetCRT2ToRAMDAC)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304635 tempbh = 0;
Peter Huewe03f76fc2012-06-14 00:21:50 +02004636 tempbl = XGI301TVDelay;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004637
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304638 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
4639 tempbl = tempbl >> 4;
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004640 if (pVBInfo->VBInfo &
4641 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Peter Huewe03f76fc2012-06-14 00:21:50 +02004642 tempbh = XGI301LCDDelay;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004643
Peter Huewea3d675c2012-02-09 21:11:47 +01004644 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304645 tempbl = tempbh;
4646 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004647
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304648 tempbl &= 0x0F;
4649 tempbh &= 0xF0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02004650 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2D);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004651
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304652 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD
4653 | SetCRT2ToTV)) { /* Channel B */
4654 tempah &= 0xF0;
4655 tempah |= tempbl;
4656 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004657
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004658 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
4659 /* Channel A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304660 tempah &= 0x0F;
4661 tempah |= tempbh;
4662 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02004663 xgifb_reg_set(pVBInfo->Part1Port, 0x2D, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304664 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304665 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004666}
4667
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004668static void XGI_SetLCDCap_A(unsigned short tempcx,
4669 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004670{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304671 unsigned short temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004672
Aaro Koskinen58839b02011-03-13 12:26:23 +02004673 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004674
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304675 if (temp & LCDRGB18Bit) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004676 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004677 /* Enable Dither */
4678 (unsigned short) (0x20 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004679 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304680 } else {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004681 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304682 (unsigned short) (0x30 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004683 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304684 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004685}
4686
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004687/* --------------------------------------------------------------------- */
4688/* Function : XGI_SetLCDCap_B */
4689/* Input : cx -> LCD Capability */
4690/* Output : */
4691/* Description : */
4692/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004693static void XGI_SetLCDCap_B(unsigned short tempcx,
4694 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004695{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304696 if (tempcx & EnableLCD24bpp) /* 24bits */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004697 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304698 (unsigned short) (((tempcx & 0x00ff) >> 6)
4699 | 0x0c));
4700 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004701 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304702 (unsigned short) (((tempcx & 0x00ff) >> 6)
4703 | 0x18)); /* Enable Dither */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004704}
4705
Aaro Koskinen7f04ec32011-11-27 23:03:05 +02004706static void XGI_LongWait(struct vb_device_info *pVBInfo)
4707{
4708 unsigned short i;
4709
4710 i = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
4711
4712 if (!(i & 0xC0)) {
4713 for (i = 0; i < 0xFFFF; i++) {
4714 if (!(inb(pVBInfo->P3da) & 0x08))
4715 break;
4716 }
4717
4718 for (i = 0; i < 0xFFFF; i++) {
4719 if ((inb(pVBInfo->P3da) & 0x08))
4720 break;
4721 }
4722 }
4723}
4724
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004725static void SetSpectrum(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004726{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304727 unsigned short index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004728
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304729 index = XGI_GetLCDCapPtr(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004730
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004731 /* disable down spectrum D[4] */
4732 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x8F);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304733 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004734 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x20); /* reset spectrum */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304735 XGI_LongWait(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004736
Aaro Koskinen8104e322011-03-13 12:26:22 +02004737 xgifb_reg_set(pVBInfo->Part4Port, 0x31,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304738 pVBInfo->LCDCapList[index].Spectrum_31);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004739 xgifb_reg_set(pVBInfo->Part4Port, 0x32,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304740 pVBInfo->LCDCapList[index].Spectrum_32);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004741 xgifb_reg_set(pVBInfo->Part4Port, 0x33,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304742 pVBInfo->LCDCapList[index].Spectrum_33);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004743 xgifb_reg_set(pVBInfo->Part4Port, 0x34,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304744 pVBInfo->LCDCapList[index].Spectrum_34);
4745 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004746 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x40); /* enable spectrum */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004747}
4748
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004749static void XGI_SetLCDCap(struct vb_device_info *pVBInfo)
4750{
4751 unsigned short tempcx;
4752
4753 tempcx = pVBInfo->LCDCapList[XGI_GetLCDCapPtr(pVBInfo)].LCD_Capability;
4754
Peter Huewef951dd02013-02-05 00:29:47 +01004755 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV |
4756 VB_SIS302LV | VB_XGI301C)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004757 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01004758 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004759 /* Set 301LV Capability */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004760 xgifb_reg_set(pVBInfo->Part4Port, 0x24,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004761 (unsigned char) (tempcx & 0x1F));
4762 }
4763 /* VB Driving */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004764 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004765 ~((EnableVBCLKDRVLOW | EnablePLLSPLOW) >> 8),
4766 (unsigned short) ((tempcx & (EnableVBCLKDRVLOW
4767 | EnablePLLSPLOW)) >> 8));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004768
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004769 if (pVBInfo->VBInfo & SetCRT2ToLCD)
4770 XGI_SetLCDCap_B(tempcx, pVBInfo);
Peter Huewea3d675c2012-02-09 21:11:47 +01004771 else if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004772 XGI_SetLCDCap_A(tempcx, pVBInfo);
4773
Peter Huewe6896b942012-02-09 21:11:46 +01004774 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004775 if (tempcx & EnableSpectrum)
4776 SetSpectrum(pVBInfo);
4777 }
4778 } else {
4779 /* LVDS,CH7017 */
4780 XGI_SetLCDCap_A(tempcx, pVBInfo);
4781 }
4782}
4783
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004784/* --------------------------------------------------------------------- */
4785/* Function : XGI_SetAntiFlicker */
4786/* Input : */
4787/* Output : */
4788/* Description : Set TV Customized Param. */
4789/* --------------------------------------------------------------------- */
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03004790static void XGI_SetAntiFlicker(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004791{
Aaro Koskinen36ae0352012-04-07 01:14:08 +03004792 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004793
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304794 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004795
Peter Huewe599801f2012-02-09 21:11:45 +01004796 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304797 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004798
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304799 tempbx = XGI_GetTVPtrIndex(pVBInfo);
4800 tempbx &= 0xFE;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304801 tempah = TVAntiFlickList[tempbx];
4802 tempah = tempah << 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004803
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004804 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0x8F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004805}
4806
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03004807static void XGI_SetEdgeEnhance(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004808{
Aaro Koskinen354f49f2012-04-07 01:14:09 +03004809 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004810
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304811 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004812
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304813 tempbx = XGI_GetTVPtrIndex(pVBInfo);
4814 tempbx &= 0xFE;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304815 tempah = TVEdgeList[tempbx];
4816 tempah = tempah << 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004817
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004818 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004819}
4820
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004821static void XGI_SetPhaseIncr(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004822{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304823 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004824
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304825 unsigned char tempcl, tempch;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004826
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304827 unsigned long tempData;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004828
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304829 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
4830 tempData = TVPhaseList[tempbx];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004831
Aaro Koskinen8104e322011-03-13 12:26:22 +02004832 xgifb_reg_set(pVBInfo->Part2Port, 0x31, (unsigned short) (tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304833 & 0x000000FF));
Aaro Koskinen8104e322011-03-13 12:26:22 +02004834 xgifb_reg_set(pVBInfo->Part2Port, 0x32, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304835 & 0x0000FF00) >> 8));
Aaro Koskinen8104e322011-03-13 12:26:22 +02004836 xgifb_reg_set(pVBInfo->Part2Port, 0x33, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304837 & 0x00FF0000) >> 16));
Aaro Koskinen8104e322011-03-13 12:26:22 +02004838 xgifb_reg_set(pVBInfo->Part2Port, 0x34, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304839 & 0xFF000000) >> 24));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004840}
4841
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03004842static void XGI_SetYFilter(unsigned short ModeIdIndex,
4843 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004844{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304845 unsigned short tempbx, index;
Aaro Koskinena68292f2012-11-04 21:15:07 +02004846 unsigned char const *filterPtr;
4847 unsigned char tempcl, tempch, tempal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004848
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304849 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004850
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304851 switch (tempbx) {
4852 case 0x00:
4853 case 0x04:
4854 filterPtr = NTSCYFilter1;
4855 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004856
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304857 case 0x01:
4858 filterPtr = PALYFilter1;
4859 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004860
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304861 case 0x02:
4862 case 0x05:
4863 case 0x0D:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304864 case 0x03:
Aaro Koskinen2555e942011-08-31 21:46:06 +03004865 filterPtr = xgifb_palmn_yfilter1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304866 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004867
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304868 case 0x08:
4869 case 0x0C:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304870 case 0x0A:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304871 case 0x0B:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304872 case 0x09:
Aaro Koskinen80f86f82011-08-31 21:46:05 +03004873 filterPtr = xgifb_yfilter2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304874 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004875
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304876 default:
4877 return;
4878 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004879
Aaro Koskinenb3979922012-11-04 21:14:52 +02004880 tempal = XGI330_EModeIDTable[ModeIdIndex].VB_ExtTVYFilterIndex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304881 if (tempcl == 0)
4882 index = tempal * 4;
4883 else
4884 index = tempal * 7;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004885
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304886 if ((tempcl == 0) && (tempch == 1)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004887 xgifb_reg_set(pVBInfo->Part2Port, 0x35, 0);
4888 xgifb_reg_set(pVBInfo->Part2Port, 0x36, 0);
4889 xgifb_reg_set(pVBInfo->Part2Port, 0x37, 0);
4890 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304891 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004892 xgifb_reg_set(pVBInfo->Part2Port, 0x35, filterPtr[index++]);
4893 xgifb_reg_set(pVBInfo->Part2Port, 0x36, filterPtr[index++]);
4894 xgifb_reg_set(pVBInfo->Part2Port, 0x37, filterPtr[index++]);
4895 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304896 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004897
Peter Huewe6896b942012-02-09 21:11:46 +01004898 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4899 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004900 xgifb_reg_set(pVBInfo->Part2Port, 0x48, filterPtr[index++]);
4901 xgifb_reg_set(pVBInfo->Part2Port, 0x49, filterPtr[index++]);
4902 xgifb_reg_set(pVBInfo->Part2Port, 0x4A, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304903 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004904}
4905
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004906/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004907/* Function : XGI_OEM310Setting */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004908/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004909/* Output : */
4910/* Description : Customized Param. for 301 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004911/* --------------------------------------------------------------------- */
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03004912static void XGI_OEM310Setting(unsigned short ModeIdIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004913 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004914{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004915 XGI_SetDelayComp(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004916
Peter Huewea3d675c2012-02-09 21:11:47 +01004917 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004918 XGI_SetLCDCap(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004919
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004920 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004921 XGI_SetPhaseIncr(pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03004922 XGI_SetYFilter(ModeIdIndex, pVBInfo);
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03004923 XGI_SetAntiFlicker(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004924
Peter Huewe6896b942012-02-09 21:11:46 +01004925 if (pVBInfo->VBType & VB_SIS301)
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03004926 XGI_SetEdgeEnhance(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304927 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004928}
4929
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004930/* --------------------------------------------------------------------- */
4931/* Function : XGI_SetCRT2ModeRegs */
4932/* Input : */
4933/* Output : */
4934/* Description : Origin code for crt2group */
4935/* --------------------------------------------------------------------- */
Aaro Koskinenb053af12013-07-16 23:13:28 +03004936static void XGI_SetCRT2ModeRegs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004937{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304938 unsigned short tempbl;
4939 short tempcl;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004940
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304941 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004942
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304943 tempah = 0;
4944 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02004945 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304946 tempah &= ~0x10; /* BTRAMDAC */
4947 tempah |= 0x40; /* BTRAM */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004948
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304949 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
4950 | SetCRT2ToLCD)) {
4951 tempah = 0x40; /* BTDRAM */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004952 tempcl = pVBInfo->ModeType;
4953 tempcl -= ModeVGA;
4954 if (tempcl >= 0) {
4955 /* BT Color */
4956 tempah = (0x008 >> tempcl);
4957 if (tempah == 0)
4958 tempah = 1;
4959 tempah |= 0x040;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304960 }
4961 if (pVBInfo->VBInfo & SetInSlaveMode)
4962 tempah ^= 0x50; /* BTDAC */
4963 }
4964 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004965
Aaro Koskinen8104e322011-03-13 12:26:22 +02004966 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304967 tempah = 0x08;
4968 tempbl = 0xf0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004969
Miguel Gómeze123e462012-07-06 12:40:52 +02004970 if (pVBInfo->VBInfo & DisableCRT2Display)
4971 goto reg_and_or;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004972
Miguel Gómeze123e462012-07-06 12:40:52 +02004973 tempah = 0x00;
4974 tempbl = 0xff;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004975
Miguel Gómeze123e462012-07-06 12:40:52 +02004976 if (!(pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV |
4977 SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
4978 goto reg_and_or;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004979
Miguel Gómeze123e462012-07-06 12:40:52 +02004980 if ((pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) &&
4981 (!(pVBInfo->VBInfo & SetSimuScanMode))) {
4982 tempbl &= 0xf7;
4983 tempah |= 0x01;
4984 goto reg_and_or;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304985 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004986
Miguel Gómeze123e462012-07-06 12:40:52 +02004987 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
4988 tempbl &= 0xf7;
4989 tempah |= 0x01;
4990 }
4991
4992 if (!(pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD)))
4993 goto reg_and_or;
4994
4995 tempbl &= 0xf8;
4996 tempah = 0x01;
4997
4998 if (!(pVBInfo->VBInfo & SetInSlaveMode))
4999 tempah |= 0x02;
5000
5001 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
5002 tempah = tempah ^ 0x05;
5003 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
5004 tempah = tempah ^ 0x01;
5005 }
5006
5007 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
5008 tempah |= 0x08;
5009
5010reg_and_or:
5011 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl, tempah);
5012
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305013 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD
Peter Huewea3d675c2012-02-09 21:11:47 +01005014 | XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305015 tempah &= (~0x08);
5016 if ((pVBInfo->ModeType == ModeVGA) && (!(pVBInfo->VBInfo
5017 & SetInSlaveMode))) {
5018 tempah |= 0x010;
5019 }
5020 tempah |= 0x080;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005021
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305022 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305023 tempah |= 0x020;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005024 if (pVBInfo->VBInfo & DriverMode)
5025 tempah = tempah ^ 0x20;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305026 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005027
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005028 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D, ~0x0BF, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305029 tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005030
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305031 if (pVBInfo->LCDInfo & SetLCDDualLink)
5032 tempah |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005033
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305034 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305035 if (pVBInfo->TVInfo & RPLLDIV2XO)
5036 tempah |= 0x40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305037 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005038
Peter Huewe255aabd2012-02-09 21:11:44 +01005039 if ((pVBInfo->LCDResInfo == Panel_1280x1024)
5040 || (pVBInfo->LCDResInfo == Panel_1280x1024x75))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305041 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005042
Peter Huewe255aabd2012-02-09 21:11:44 +01005043 if (pVBInfo->LCDResInfo == Panel_1280x960)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305044 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005045
Aaro Koskinen8104e322011-03-13 12:26:22 +02005046 xgifb_reg_set(pVBInfo->Part4Port, 0x0C, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305047 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005048
Peter Huewe6896b942012-02-09 21:11:46 +01005049 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5050 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305051 tempah = 0;
5052 tempbl = 0xfb;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005053
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305054 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
5055 tempbl = 0xff;
Peter Huewea3d675c2012-02-09 21:11:47 +01005056 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305057 tempah |= 0x04; /* shampoo 0129 */
5058 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005059
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005060 xgifb_reg_and_or(pVBInfo->Part1Port, 0x13, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305061 tempah = 0x00;
5062 tempbl = 0xcf;
5063 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5064 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5065 tempah |= 0x30;
5066 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005067
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005068 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2c, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305069 tempah = 0;
5070 tempbl = 0x3f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005071
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305072 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5073 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5074 tempah |= 0xc0;
5075 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005076 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305077 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005078
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305079 tempah = 0;
5080 tempbl = 0x7f;
Peter Huewea3d675c2012-02-09 21:11:47 +01005081 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305082 tempbl = 0xff;
5083 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
5084 tempah |= 0x80;
5085 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005086
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005087 xgifb_reg_and_or(pVBInfo->Part4Port, 0x23, tempbl, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005088
Peter Huewe6896b942012-02-09 21:11:46 +01005089 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305090 if (pVBInfo->LCDInfo & SetLCDDualLink) {
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005091 xgifb_reg_or(pVBInfo->Part4Port, 0x27, 0x20);
5092 xgifb_reg_or(pVBInfo->Part4Port, 0x34, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305093 }
5094 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005095}
5096
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005097
Aaro Koskinenb053af12013-07-16 23:13:28 +03005098void XGI_UnLockCRT2(struct vb_device_info *pVBInfo)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305099{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005100 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2f, 0xFF, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005101}
5102
Aaro Koskinenb053af12013-07-16 23:13:28 +03005103void XGI_LockCRT2(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005104{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005105 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2F, 0xFE, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005106}
5107
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005108unsigned short XGI_GetRatePtrCRT2(struct xgi_hw_device_info *pXGIHWDE,
5109 unsigned short ModeNo, unsigned short ModeIdIndex,
5110 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005111{
Peter Huewef2c22602013-02-03 22:54:30 +01005112 const u8 LCDARefreshIndex[] = {
5113 0x00, 0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x00 };
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005114
Peter Hueweef9a6b92013-02-03 04:08:43 +01005115 unsigned short RefreshRateTableIndex, i, index, temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005116
Aaro Koskinen58839b02011-03-13 12:26:23 +02005117 index = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005118 index = index >> pVBInfo->SelectCRT2Rate;
5119 index &= 0x0F;
5120
5121 if (pVBInfo->LCDInfo & LCDNonExpanding)
5122 index = 0;
5123
5124 if (index > 0)
5125 index--;
5126
5127 if (pVBInfo->SetFlag & ProgrammingCRT2) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005128 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinenb0b4a8a2013-05-29 23:59:04 +03005129 temp = LCDARefreshIndex[pVBInfo->LCDResInfo & 0x07];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005130
Aaro Koskinenb0b4a8a2013-05-29 23:59:04 +03005131 if (index > temp)
5132 index = temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005133 }
5134 }
5135
Aaro Koskinenb3979922012-11-04 21:14:52 +02005136 RefreshRateTableIndex = XGI330_EModeIDTable[ModeIdIndex].REFindex;
Aaro Koskinena39325d2012-11-04 21:14:53 +02005137 ModeNo = XGI330_RefIndex[RefreshRateTableIndex].ModeID;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005138 if (pXGIHWDE->jChipType >= XG20) { /* for XG20, XG21, XG27 */
Aaro Koskinena39325d2012-11-04 21:14:53 +02005139 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 800) &&
5140 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 600)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005141 index++;
5142 }
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005143 /* do the similar adjustment like XGISearchCRT1Rate() */
Aaro Koskinena39325d2012-11-04 21:14:53 +02005144 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 1024) &&
5145 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 768)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005146 index++;
5147 }
Aaro Koskinena39325d2012-11-04 21:14:53 +02005148 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 1280) &&
5149 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 1024)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005150 index++;
5151 }
5152 }
5153
5154 i = 0;
5155 do {
Aaro Koskinena39325d2012-11-04 21:14:53 +02005156 if (XGI330_RefIndex[RefreshRateTableIndex + i].
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005157 ModeID != ModeNo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005158 break;
Aaro Koskinena39325d2012-11-04 21:14:53 +02005159 temp = XGI330_RefIndex[RefreshRateTableIndex + i].Ext_InfoFlag;
Peter Huewe6896b942012-02-09 21:11:46 +01005160 temp &= ModeTypeMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005161 if (temp < pVBInfo->ModeType)
5162 break;
5163 i++;
5164 index--;
5165
5166 } while (index != 0xFFFF);
5167 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
5168 if (pVBInfo->VBInfo & SetInSlaveMode) {
Aaro Koskinena39325d2012-11-04 21:14:53 +02005169 temp = XGI330_RefIndex[RefreshRateTableIndex + i - 1].
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005170 Ext_InfoFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005171 if (temp & InterlaceMode)
5172 i++;
5173 }
5174 }
5175 i--;
5176 if ((pVBInfo->SetFlag & ProgrammingCRT2)) {
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005177 temp = XGI_AjustCRT2Rate(ModeIdIndex, RefreshRateTableIndex,
5178 &i, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005179 }
Aaro Koskinen9a0b2952011-11-27 23:03:16 +02005180 return RefreshRateTableIndex + i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005181}
5182
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005183static void XGI_SetLCDAGroup(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305184 struct xgi_hw_device_info *HwDeviceExtension,
5185 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005186{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005187 unsigned short RefreshRateTableIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005188
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005189 pVBInfo->SetFlag |= ProgrammingCRT2;
5190 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5191 ModeIdIndex, pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005192 XGI_GetLVDSResInfo(ModeIdIndex, pVBInfo);
5193 XGI_GetLVDSData(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5194 XGI_ModCRT1Regs(ModeIdIndex, RefreshRateTableIndex, HwDeviceExtension,
5195 pVBInfo);
5196 XGI_SetLVDSRegs(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5197 XGI_SetCRT2ECLK(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005198}
5199
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02005200static unsigned char XGI_SetCRT2Group301(unsigned short ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005201 struct xgi_hw_device_info *HwDeviceExtension,
5202 struct vb_device_info *pVBInfo)
5203{
Peter Huewea9e29e62013-02-03 04:08:44 +01005204 unsigned short ModeIdIndex, RefreshRateTableIndex;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005205
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005206 pVBInfo->SetFlag |= ProgrammingCRT2;
5207 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
5208 pVBInfo->SelectCRT2Rate = 4;
5209 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5210 ModeIdIndex, pVBInfo);
5211 XGI_SaveCRT2Info(ModeNo, pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005212 XGI_GetCRT2ResInfo(ModeIdIndex, pVBInfo);
5213 XGI_GetCRT2Data(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
Aaro Koskinenb053af12013-07-16 23:13:28 +03005214 XGI_PreSetGroup1(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5215 XGI_SetGroup1(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5216 XGI_SetLockRegs(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5217 XGI_SetGroup2(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5218 XGI_SetLCDRegs(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005219 XGI_SetTap4Regs(pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005220 XGI_SetGroup3(ModeIdIndex, pVBInfo);
Aaro Koskinenb053af12013-07-16 23:13:28 +03005221 XGI_SetGroup4(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005222 XGI_SetCRT2VCLK(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03005223 XGI_SetGroup5(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005224 XGI_AutoThreshold(pVBInfo);
5225 return 1;
5226}
5227
5228void XGI_SenseCRT1(struct vb_device_info *pVBInfo)
5229{
5230 unsigned char CRTCData[17] = { 0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81,
5231 0x0B, 0x3E, 0xE9, 0x0B, 0xDF, 0xE7, 0x04, 0x00, 0x00,
5232 0x05, 0x00 };
5233
5234 unsigned char SR01 = 0, SR1F = 0, SR07 = 0, SR06 = 0;
5235
5236 unsigned char CR17, CR63, SR31;
5237 unsigned short temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005238
5239 int i;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005240 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005241
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005242 /* to fix XG42 single LCD sense to CRT+LCD */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005243 xgifb_reg_set(pVBInfo->P3d4, 0x57, 0x4A);
Peter Huewe9388ad92013-02-15 20:37:10 +01005244 xgifb_reg_set(pVBInfo->P3d4, 0x53, (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005245 pVBInfo->P3d4, 0x53) | 0x02));
5246
Peter Huewe9388ad92013-02-15 20:37:10 +01005247 SR31 = xgifb_reg_get(pVBInfo->P3c4, 0x31);
5248 CR63 = xgifb_reg_get(pVBInfo->P3d4, 0x63);
5249 SR01 = xgifb_reg_get(pVBInfo->P3c4, 0x01);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005250
Aaro Koskinen8104e322011-03-13 12:26:22 +02005251 xgifb_reg_set(pVBInfo->P3c4, 0x01, (unsigned char) (SR01 & 0xDF));
5252 xgifb_reg_set(pVBInfo->P3d4, 0x63, (unsigned char) (CR63 & 0xBF));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005253
Peter Huewe9388ad92013-02-15 20:37:10 +01005254 CR17 = xgifb_reg_get(pVBInfo->P3d4, 0x17);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005255 xgifb_reg_set(pVBInfo->P3d4, 0x17, (unsigned char) (CR17 | 0x80));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005256
Peter Huewe9388ad92013-02-15 20:37:10 +01005257 SR1F = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005258 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) (SR1F | 0x04));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005259
Peter Huewe9388ad92013-02-15 20:37:10 +01005260 SR07 = xgifb_reg_get(pVBInfo->P3c4, 0x07);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005261 xgifb_reg_set(pVBInfo->P3c4, 0x07, (unsigned char) (SR07 & 0xFB));
Peter Huewe9388ad92013-02-15 20:37:10 +01005262 SR06 = xgifb_reg_get(pVBInfo->P3c4, 0x06);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005263 xgifb_reg_set(pVBInfo->P3c4, 0x06, (unsigned char) (SR06 & 0xC3));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005264
Aaro Koskinen8104e322011-03-13 12:26:22 +02005265 xgifb_reg_set(pVBInfo->P3d4, 0x11, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005266
5267 for (i = 0; i < 8; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005268 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) i, CRTCData[i]);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005269
5270 for (i = 8; i < 11; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005271 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 8),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005272 CRTCData[i]);
5273
5274 for (i = 11; i < 13; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005275 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 4),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005276 CRTCData[i]);
5277
5278 for (i = 13; i < 16; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005279 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i - 3),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005280 CRTCData[i]);
5281
Aaro Koskinen8104e322011-03-13 12:26:22 +02005282 xgifb_reg_set(pVBInfo->P3c4, 0x0E, (unsigned char) (CRTCData[16]
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005283 & 0xE0));
5284
Aaro Koskinen8104e322011-03-13 12:26:22 +02005285 xgifb_reg_set(pVBInfo->P3c4, 0x31, 0x00);
5286 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x1B);
5287 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE1);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005288
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005289 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005290
Peter Huewe771f3ee2013-02-15 20:37:13 +01005291 for (i = 0; i < 256 * 3; i++) {
5292 outb(0x0F, (pVBInfo->P3c8 + 1)); /* DAC_TEST_PARMS */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005293 }
5294
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005295 mdelay(1);
5296
5297 XGI_WaitDisply(pVBInfo);
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02005298 temp = inb(pVBInfo->P3c2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005299
5300 if (temp & 0x10)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005301 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005302 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005303 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005304
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005305 /* avoid display something, set BLACK DAC if not restore DAC */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005306 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005307
Peter Huewe771f3ee2013-02-15 20:37:13 +01005308 for (i = 0; i < 256 * 3; i++) {
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005309 outb(0, (pVBInfo->P3c8 + 1));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005310 }
5311
Aaro Koskinen8104e322011-03-13 12:26:22 +02005312 xgifb_reg_set(pVBInfo->P3c4, 0x01, SR01);
5313 xgifb_reg_set(pVBInfo->P3d4, 0x63, CR63);
5314 xgifb_reg_set(pVBInfo->P3c4, 0x31, SR31);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005315
Peter Huewe9388ad92013-02-15 20:37:10 +01005316 xgifb_reg_set(pVBInfo->P3d4, 0x53, (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005317 pVBInfo->P3d4, 0x53) & 0xFD));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005318 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) SR1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005319}
5320
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005321static void XGI_EnableBridge(struct xgifb_video_info *xgifb_info,
5322 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005323 struct vb_device_info *pVBInfo)
5324{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02005325 unsigned short tempah;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005326
Peter Huewe6896b942012-02-09 21:11:46 +01005327 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5328 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinena2526d12013-05-29 23:59:10 +03005329 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
Aaro Koskinend1724632013-05-29 23:59:09 +03005330 /* Power on */
5331 xgifb_reg_set(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005332
Aaro Koskinenb8e34b32013-05-29 23:59:08 +03005333 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV |
5334 SetCRT2ToRAMDAC)) {
Aaro Koskinenc4f9c312013-05-29 23:59:07 +03005335 tempah = xgifb_reg_get(pVBInfo->P3c4, 0x32);
5336 tempah &= 0xDF;
5337 if (pVBInfo->VBInfo & SetInSlaveMode) {
5338 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC))
5339 tempah |= 0x20;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005340 }
Aaro Koskinenc4f9c312013-05-29 23:59:07 +03005341 xgifb_reg_set(pVBInfo->P3c4, 0x32, tempah);
5342 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x20);
5343
5344 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2E);
5345
5346 if (!(tempah & 0x80))
5347 xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80);
5348 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005349 }
5350
Aaro Koskinena2526d12013-05-29 23:59:10 +03005351 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005352 xgifb_reg_and_or(pVBInfo->Part2Port, 0x00, ~0xE0,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005353 0x20); /* shampoo 0129 */
Peter Huewe6896b942012-02-09 21:11:46 +01005354 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinen056b5402013-05-29 23:59:11 +03005355 if (pVBInfo->VBInfo &
5356 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
5357 /* LVDS PLL power on */
5358 xgifb_reg_and(pVBInfo->Part4Port, 0x2A,
5359 0x7F);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005360 /* LVDS Driver power on */
5361 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005362 }
5363 }
5364
5365 tempah = 0x00;
5366
5367 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5368 tempah = 0xc0;
5369
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005370 if (!(pVBInfo->VBInfo & SetSimuScanMode) &&
5371 (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) &&
5372 (pVBInfo->VBInfo & SetCRT2ToDualEdge)) {
5373 tempah = tempah & 0x40;
5374 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
5375 tempah = tempah ^ 0xC0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005376 }
5377 }
5378
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005379 /* EnablePart4_1F */
5380 xgifb_reg_or(pVBInfo->Part4Port, 0x1F, tempah);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005381
Aaro Koskinenb053af12013-07-16 23:13:28 +03005382 XGI_DisableGatingCRT(pVBInfo);
Aaro Koskinend1724632013-05-29 23:59:09 +03005383 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005384 } /* 301 */
5385 else { /* LVDS */
5386 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD
Peter Huewea3d675c2012-02-09 21:11:47 +01005387 | XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005388 /* enable CRT2 */
5389 xgifb_reg_or(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005390
Peter Huewe9388ad92013-02-15 20:37:10 +01005391 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2E);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005392 if (!(tempah & 0x80))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005393 xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005394
Aaro Koskinendc505562011-03-13 12:26:26 +02005395 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005396 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005397 } /* End of VB */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005398}
5399
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005400static void XGI_SetCRT1Group(struct xgifb_video_info *xgifb_info,
5401 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005402 unsigned short ModeNo, unsigned short ModeIdIndex,
5403 struct vb_device_info *pVBInfo)
5404{
Aaro Koskinena1579612012-04-07 01:14:05 +03005405 unsigned short RefreshRateTableIndex, temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005406
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03005407 XGI_SetSeqRegs(pVBInfo);
Aaro Koskinen3625c9a2012-11-04 21:14:51 +02005408 outb(XGI330_StandTable.MISC, pVBInfo->P3c2);
Aaro Koskinenb053af12013-07-16 23:13:28 +03005409 XGI_SetCRTCRegs(pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005410 XGI_SetATTRegs(ModeIdIndex, pVBInfo);
Aaro Koskinena1579612012-04-07 01:14:05 +03005411 XGI_SetGRCRegs(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005412 XGI_ClearExt1Regs(pVBInfo);
5413
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005414 if (HwDeviceExtension->jChipType == XG27) {
5415 if (pVBInfo->IF_DEF_LVDS == 0)
5416 XGI_SetDefaultVCLK(pVBInfo);
5417 }
5418
5419 temp = ~ProgrammingCRT2;
5420 pVBInfo->SetFlag &= temp;
5421 pVBInfo->SelectCRT2Rate = 0;
5422
Peter Huewe6896b942012-02-09 21:11:46 +01005423 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5424 | VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005425 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005426 | SetInSlaveMode)) {
5427 pVBInfo->SetFlag |= ProgrammingCRT2;
5428 }
5429 }
5430
5431 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5432 ModeIdIndex, pVBInfo);
5433 if (RefreshRateTableIndex != 0xFFFF) {
5434 XGI_SetSync(RefreshRateTableIndex, pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005435 XGI_SetCRT1CRTC(ModeIdIndex, RefreshRateTableIndex,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005436 pVBInfo, HwDeviceExtension);
Aaro Koskinenb053af12013-07-16 23:13:28 +03005437 XGI_SetCRT1DE(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005438 XGI_SetCRT1Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5439 HwDeviceExtension, pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005440 XGI_SetCRT1VCLK(ModeIdIndex, HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005441 RefreshRateTableIndex, pVBInfo);
5442 }
5443
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005444 if (HwDeviceExtension->jChipType >= XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005445 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005446 if (temp & 0xA0) {
5447
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005448 if (HwDeviceExtension->jChipType == XG27)
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03005449 XGI_SetXG27CRTC(RefreshRateTableIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005450 else
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03005451 XGI_SetXG21CRTC(RefreshRateTableIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005452
5453 XGI_UpdateXG21CRTC(ModeNo, pVBInfo,
5454 RefreshRateTableIndex);
5455
Aaro Koskinen105d8d02011-08-31 21:46:00 +03005456 xgifb_set_lcd(HwDeviceExtension->jChipType,
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005457 pVBInfo, RefreshRateTableIndex);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005458
Aaro Koskinen64db29f2011-08-31 21:46:01 +03005459 if (pVBInfo->IF_DEF_LVDS == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005460 xgifb_set_lvds(xgifb_info,
5461 HwDeviceExtension->jChipType,
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005462 ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005463 }
5464 }
5465
5466 pVBInfo->SetFlag &= (~ProgrammingCRT2);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005467 XGI_SetCRT1FIFO(HwDeviceExtension, pVBInfo);
5468 XGI_SetCRT1ModeRegs(HwDeviceExtension, ModeIdIndex,
5469 RefreshRateTableIndex, pVBInfo);
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03005470 XGI_LoadDAC(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005471}
5472
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005473unsigned char XGISetModeNew(struct xgifb_video_info *xgifb_info,
5474 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005475 unsigned short ModeNo)
5476{
5477 unsigned short ModeIdIndex;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005478 struct vb_device_info VBINF;
5479 struct vb_device_info *pVBInfo = &VBINF;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005480 pVBInfo->IF_DEF_LVDS = 0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005481
Aaro Koskinenee768752013-05-29 23:59:16 +03005482 if (HwDeviceExtension->jChipType >= XG20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005483 pVBInfo->VBType = 0; /*set VBType default 0*/
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005484
Aaro Koskinen56810a92013-01-21 02:57:47 +02005485 XGIRegInit(pVBInfo, xgifb_info->vga_base);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005486
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005487 /* for x86 Linux, XG21 LVDS */
5488 if (HwDeviceExtension->jChipType == XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005489 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005490 pVBInfo->IF_DEF_LVDS = 1;
5491 }
5492 if (HwDeviceExtension->jChipType == XG27) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005493 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0) {
5494 if (xgifb_reg_get(pVBInfo->P3d4, 0x30) & 0x20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005495 pVBInfo->IF_DEF_LVDS = 1;
5496 }
5497 }
5498
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005499 InitTo330Pointer(HwDeviceExtension->jChipType, pVBInfo);
Aaro Koskinenef497f42011-11-27 23:03:21 +02005500 if (ModeNo & 0x80)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005501 ModeNo = ModeNo & 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005502 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005503
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005504 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinenb053af12013-07-16 23:13:28 +03005505 XGI_UnLockCRT2(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005506
5507 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
5508
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005509 if (HwDeviceExtension->jChipType < XG20) {
Aaro Koskinenb053af12013-07-16 23:13:28 +03005510 XGI_GetVBInfo(ModeIdIndex, pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005511 XGI_GetTVInfo(ModeIdIndex, pVBInfo);
5512 XGI_GetLCDInfo(ModeIdIndex, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005513 XGI_DisableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005514
Peter Huewee44adfd2013-02-03 22:54:39 +01005515 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA) ||
5516 (!(pVBInfo->VBInfo & SwitchCRT2))) {
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005517 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005518 ModeIdIndex, pVBInfo);
5519
Peter Huewea3d675c2012-02-09 21:11:47 +01005520 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005521 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
5522 HwDeviceExtension, pVBInfo);
5523 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005524 }
5525
Peter Huewe6896b942012-02-09 21:11:46 +01005526 if (pVBInfo->VBInfo & (SetSimuScanMode | SwitchCRT2)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005527 switch (HwDeviceExtension->ujVBChipID) {
Peter Huewee44adfd2013-02-03 22:54:39 +01005528 case VB_CHIP_301: /* fall through */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005529 case VB_CHIP_302:
5530 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
5531 pVBInfo); /*add for CRT2 */
5532 break;
5533
5534 default:
5535 break;
5536 }
5537 }
5538
Aaro Koskinenb053af12013-07-16 23:13:28 +03005539 XGI_SetCRT2ModeRegs(pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005540 XGI_OEM310Setting(ModeIdIndex, pVBInfo); /*0212*/
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005541 XGI_EnableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005542 } /* !XG20 */
5543 else {
5544 if (pVBInfo->IF_DEF_LVDS == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005545 if (!XGI_XG21CheckLVDSMode(xgifb_info, ModeNo,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005546 ModeIdIndex,
5547 pVBInfo))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005548 return 0;
5549
Aaro Koskinenb3979922012-11-04 21:14:52 +02005550 pVBInfo->ModeType = XGI330_EModeIDTable[ModeIdIndex].
Peter Huewe6896b942012-02-09 21:11:46 +01005551 Ext_ModeFlag & ModeTypeMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005552
5553 pVBInfo->SetFlag = 0;
Aaro Koskinen83f76a92011-08-31 21:45:58 +03005554 pVBInfo->VBInfo = DisableCRT2Display;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005555
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005556 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005557
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005558 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
5559 ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005560
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005561 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005562 }
5563
Aaro Koskinenb053af12013-07-16 23:13:28 +03005564 XGI_UpdateModeInfo(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005565
Miguel Gómez3bcc2462012-07-06 12:40:53 +02005566 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinenb053af12013-07-16 23:13:28 +03005567 XGI_LockCRT2(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005568
5569 return 1;
5570}