blob: 36be17bfa5a86d16f3e5057eab6384596612fe9b [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 Koskinen063b9c42011-03-08 22:16:13 +020080static void XGI_SetCRTCRegs(struct xgi_hw_device_info *HwDeviceExtension,
Kenji Toyama1d7f6562011-04-23 19:36:49 +080081 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020082{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053083 unsigned char CRTCdata;
84 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020085
Peter Huewe9388ad92013-02-15 20:37:10 +010086 CRTCdata = xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053087 CRTCdata &= 0x7f;
Aaro Koskinen8104e322011-03-13 12:26:22 +020088 xgifb_reg_set(pVBInfo->P3d4, 0x11, CRTCdata); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020089
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053090 for (i = 0; i <= 0x18; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +080091 /* Get CRTC from file */
Aaro Koskinen3625c9a2012-11-04 21:14:51 +020092 CRTCdata = XGI330_StandTable.CRTC[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +020093 xgifb_reg_set(pVBInfo->P3d4, i, CRTCdata); /* Set CRTC(3d4) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053094 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020095}
96
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +030097static void XGI_SetATTRegs(unsigned short ModeIdIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +080098 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020099{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530100 unsigned char ARdata;
101 unsigned short i, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200102
Aaro Koskinenb3979922012-11-04 21:14:52 +0200103 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200104
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530105 for (i = 0; i <= 0x13; i++) {
Aaro Koskinen3625c9a2012-11-04 21:14:51 +0200106 ARdata = XGI330_StandTable.ATTR[i];
Miguel Gómez661a6382012-07-06 12:40:45 +0200107
108 if ((modeflag & Charx8Dot) && i == 0x13) { /* ifndef Dot9 */
109 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
110 ARdata = 0;
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300111 } else if ((pVBInfo->VBInfo &
Miguel Gómez661a6382012-07-06 12:40:45 +0200112 (SetCRT2ToTV | SetCRT2ToLCD)) &&
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300113 (pVBInfo->VBInfo & SetInSlaveMode)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530114 ARdata = 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530115 }
116 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200117
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200118 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200119 outb(i, pVBInfo->P3c0); /* set index */
120 outb(ARdata, pVBInfo->P3c0); /* set data */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530121 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200122
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200123 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200124 outb(0x14, pVBInfo->P3c0); /* set index */
125 outb(0x00, pVBInfo->P3c0); /* set data */
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200126 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200127 outb(0x20, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200128}
129
Aaro Koskinena1579612012-04-07 01:14:05 +0300130static void XGI_SetGRCRegs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200131{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530132 unsigned char GRdata;
133 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200134
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530135 for (i = 0; i <= 0x08; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800136 /* Get GR from file */
Aaro Koskinen3625c9a2012-11-04 21:14:51 +0200137 GRdata = XGI330_StandTable.GRC[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200138 xgifb_reg_set(pVBInfo->P3ce, i, GRdata); /* Set GR(3ce) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530139 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200140
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530141 if (pVBInfo->ModeType > ModeVGA) {
Peter Huewe9388ad92013-02-15 20:37:10 +0100142 GRdata = xgifb_reg_get(pVBInfo->P3ce, 0x05);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530143 GRdata &= 0xBF; /* 256 color disable */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200144 xgifb_reg_set(pVBInfo->P3ce, 0x05, GRdata);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530145 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200146}
147
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200148static void XGI_ClearExt1Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200149{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530150 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200151
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530152 for (i = 0x0A; i <= 0x0E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +0200153 xgifb_reg_set(pVBInfo->P3c4, i, 0x00); /* Clear SR0A-SR0E */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200154}
155
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200156static unsigned char XGI_SetDefaultVCLK(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200157{
158
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200159 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x20);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200160 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[0].SR2B);
161 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[0].SR2C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200162
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200163 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x10);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200164 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[1].SR2B);
165 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[1].SR2C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200166
Aaro Koskinendc505562011-03-13 12:26:26 +0200167 xgifb_reg_and(pVBInfo->P3c4, 0x31, ~0x30);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530168 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200169}
170
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +0300171static unsigned char XGI_AjustCRT2Rate(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530172 unsigned short RefreshRateTableIndex, unsigned short *i,
173 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200174{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530175 unsigned short tempax, tempbx, resinfo, modeflag, infoflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200176
Aaro Koskinenb3979922012-11-04 21:14:52 +0200177 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
178 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinena39325d2012-11-04 21:14:53 +0200179 tempbx = XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530180 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200181
Aaro Koskinen0903b0d2013-05-29 23:59:03 +0300182 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
183 tempax |= SupportRAMDAC2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200184
Aaro Koskinen0903b0d2013-05-29 23:59:03 +0300185 if (pVBInfo->VBType & VB_XGI301C)
186 tempax |= SupportCRT2in301C;
187 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200188
Aaro Koskinen0903b0d2013-05-29 23:59:03 +0300189 /* 301b */
190 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300191 tempax |= SupportLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200192
Aaro Koskinen0903b0d2013-05-29 23:59:03 +0300193 if (pVBInfo->LCDResInfo != Panel_1280x1024 &&
194 pVBInfo->LCDResInfo != Panel_1280x960 &&
195 (pVBInfo->LCDInfo & LCDNonExpanding) &&
196 resinfo >= 9)
197 return 0;
198 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200199
Aaro Koskinen0903b0d2013-05-29 23:59:03 +0300200 if (pVBInfo->VBInfo & SetCRT2ToHiVision) { /* for HiTV */
201 tempax |= SupportHiVision;
202 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
203 ((resinfo == 4) ||
204 (resinfo == 3 && (pVBInfo->SetFlag & TVSimuMode)) ||
205 (resinfo > 7)))
206 return 0;
207 } else if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO | SetCRT2ToSVIDEO |
208 SetCRT2ToSCART | SetCRT2ToYPbPr525750 |
209 SetCRT2ToHiVision)) {
210 tempax |= SupportTV;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200211
Aaro Koskinen0903b0d2013-05-29 23:59:03 +0300212 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV |
213 VB_SIS302LV | VB_XGI301C))
214 tempax |= SupportTV1024;
215
216 if (!(pVBInfo->VBInfo & TVSetPAL) &&
217 (modeflag & NoSupportSimuTV) &&
218 (pVBInfo->VBInfo & SetInSlaveMode) &&
219 (!(pVBInfo->VBInfo & SetNotSimuMode)))
220 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530221 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200222
Aaro Koskinena39325d2012-11-04 21:14:53 +0200223 for (; XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID ==
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800224 tempbx; (*i)--) {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200225 infoflag = XGI330_RefIndex[RefreshRateTableIndex + (*i)].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800226 Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530227 if (infoflag & tempax)
228 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200229
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530230 if ((*i) == 0)
231 break;
232 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200233
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530234 for ((*i) = 0;; (*i)++) {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200235 infoflag = XGI330_RefIndex[RefreshRateTableIndex + (*i)].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800236 Ext_InfoFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +0200237 if (XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530238 != tempbx) {
239 return 0;
240 }
241
242 if (infoflag & tempax)
243 return 1;
244 }
245 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200246}
247
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200248static void XGI_SetSync(unsigned short RefreshRateTableIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530249 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200250{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530251 unsigned short sync, temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200252
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800253 /* di+0x00 */
Aaro Koskinena39325d2012-11-04 21:14:53 +0200254 sync = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag >> 8;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530255 sync &= 0xC0;
256 temp = 0x2F;
257 temp |= sync;
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200258 outb(temp, pVBInfo->P3c2); /* Set Misc(3c2) */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200259}
260
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200261static void XGI_SetCRT1Timing_H(struct vb_device_info *pVBInfo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530262 struct xgi_hw_device_info *HwDeviceExtension)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200263{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530264 unsigned char data, data1, pushax;
265 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200266
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800267 /* unlock cr0-7 */
Peter Huewe9388ad92013-02-15 20:37:10 +0100268 data = xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530269 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200270 xgifb_reg_set(pVBInfo->P3d4, 0x11, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200271
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200272 data = pVBInfo->TimingH.data[0];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200273 xgifb_reg_set(pVBInfo->P3d4, 0, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200274
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530275 for (i = 0x01; i <= 0x04; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200276 data = pVBInfo->TimingH.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200277 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 1), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530278 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200279
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530280 for (i = 0x05; i <= 0x06; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200281 data = pVBInfo->TimingH.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200282 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i + 6), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530283 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200284
Peter Huewe9388ad92013-02-15 20:37:10 +0100285 j = xgifb_reg_get(pVBInfo->P3c4, 0x0e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530286 j &= 0x1F;
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200287 data = pVBInfo->TimingH.data[7];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530288 data &= 0xE0;
289 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200290 xgifb_reg_set(pVBInfo->P3c4, 0x0e, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200291
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530292 if (HwDeviceExtension->jChipType >= XG20) {
Peter Huewe9388ad92013-02-15 20:37:10 +0100293 data = xgifb_reg_get(pVBInfo->P3d4, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530294 data = data - 1;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200295 xgifb_reg_set(pVBInfo->P3d4, 0x04, data);
Peter Huewe9388ad92013-02-15 20:37:10 +0100296 data = xgifb_reg_get(pVBInfo->P3d4, 0x05);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530297 data1 = data;
298 data1 &= 0xE0;
299 data &= 0x1F;
300 if (data == 0) {
301 pushax = data;
Peter Huewe9388ad92013-02-15 20:37:10 +0100302 data = xgifb_reg_get(pVBInfo->P3c4, 0x0c);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530303 data &= 0xFB;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200304 xgifb_reg_set(pVBInfo->P3c4, 0x0c, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530305 data = pushax;
306 }
307 data = data - 1;
308 data |= data1;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200309 xgifb_reg_set(pVBInfo->P3d4, 0x05, data);
Peter Huewe9388ad92013-02-15 20:37:10 +0100310 data = xgifb_reg_get(pVBInfo->P3c4, 0x0e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530311 data = data >> 5;
312 data = data + 3;
313 if (data > 7)
314 data = data - 7;
315 data = data << 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200316 xgifb_reg_and_or(pVBInfo->P3c4, 0x0e, ~0xE0, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530317 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200318}
319
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800320static void XGI_SetCRT1Timing_V(unsigned short ModeIdIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800321 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200322{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530323 unsigned char data;
324 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200325
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530326 for (i = 0x00; i <= 0x01; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200327 data = pVBInfo->TimingV.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200328 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 6), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530329 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200330
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530331 for (i = 0x02; i <= 0x03; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200332 data = pVBInfo->TimingV.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200333 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x0e), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530334 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200335
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530336 for (i = 0x04; i <= 0x05; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200337 data = pVBInfo->TimingV.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200338 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x11), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530339 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200340
Peter Huewe9388ad92013-02-15 20:37:10 +0100341 j = xgifb_reg_get(pVBInfo->P3c4, 0x0a);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530342 j &= 0xC0;
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200343 data = pVBInfo->TimingV.data[6];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530344 data &= 0x3F;
345 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200346 xgifb_reg_set(pVBInfo->P3c4, 0x0a, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200347
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200348 data = pVBInfo->TimingV.data[6];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530349 data &= 0x80;
350 data = data >> 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200351
Aaro Koskinenb3979922012-11-04 21:14:52 +0200352 i = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530353 i &= DoubleScanMode;
354 if (i)
355 data |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200356
Peter Huewe9388ad92013-02-15 20:37:10 +0100357 j = xgifb_reg_get(pVBInfo->P3d4, 0x09);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530358 j &= 0x5F;
359 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200360 xgifb_reg_set(pVBInfo->P3d4, 0x09, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200361}
362
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +0300363static void XGI_SetCRT1CRTC(unsigned short ModeIdIndex,
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200364 unsigned short RefreshRateTableIndex,
365 struct vb_device_info *pVBInfo,
366 struct xgi_hw_device_info *HwDeviceExtension)
367{
368 unsigned char index, data;
369 unsigned short i;
370
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800371 /* Get index */
Aaro Koskinena39325d2012-11-04 21:14:53 +0200372 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200373 index = index & IndexMask;
374
Peter Huewe9388ad92013-02-15 20:37:10 +0100375 data = xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200376 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200377 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200378
379 for (i = 0; i < 8; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200380 pVBInfo->TimingH.data[i]
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200381 = XGI_CRT1Table[index].CR[i];
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200382
383 for (i = 0; i < 7; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200384 pVBInfo->TimingV.data[i]
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200385 = XGI_CRT1Table[index].CR[i + 8];
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200386
387 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
388
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +0300389 XGI_SetCRT1Timing_V(ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200390
391 if (pVBInfo->ModeType > 0x03)
Aaro Koskinen8104e322011-03-13 12:26:22 +0200392 xgifb_reg_set(pVBInfo->P3d4, 0x14, 0x4F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200393}
394
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200395/* --------------------------------------------------------------------- */
396/* Function : XGI_SetXG21CRTC */
397/* Input : Stand or enhance CRTC table */
398/* Output : Fill CRT Hsync/Vsync to SR2E/SR2F/SR30/SR33/SR34/SR3F */
399/* Description : Set LCD timing */
400/* --------------------------------------------------------------------- */
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +0300401static void XGI_SetXG21CRTC(unsigned short RefreshRateTableIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530402 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200403{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300404 unsigned char index, Tempax, Tempbx, Tempcx, Tempdx;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530405 unsigned short Temp1, Temp2, Temp3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200406
Aaro Koskinena39325d2012-11-04 21:14:53 +0200407 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300408 /* Tempax: CR4 HRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200409 Tempax = XGI_CRT1Table[index].CR[3];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300410 Tempcx = Tempax; /* Tempcx: HRS */
411 /* SR2E[7:0]->HRS */
412 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200413
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200414 Tempdx = XGI_CRT1Table[index].CR[5]; /* SRB */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300415 Tempdx &= 0xC0; /* Tempdx[7:6]: SRB[7:6] */
416 Temp1 = Tempdx; /* Temp1[7:6]: HRS[9:8] */
417 Temp1 <<= 2; /* Temp1[9:8]: HRS[9:8] */
418 Temp1 |= Tempax; /* Temp1[9:0]: HRS[9:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800419
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200420 Tempax = XGI_CRT1Table[index].CR[4]; /* CR5 HRE */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300421 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200422
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200423 Tempbx = XGI_CRT1Table[index].CR[6]; /* SRC */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300424 Tempbx &= 0x04; /* Tempbx[2]: HRE[5] */
425 Tempbx <<= 3; /* Tempbx[5]: HRE[5] */
426 Tempax |= Tempbx; /* Tempax[5:0]: HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200427
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300428 Temp2 = Temp1 & 0x3C0; /* Temp2[9:6]: HRS[9:6] */
429 Temp2 |= Tempax; /* Temp2[9:0]: HRE[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200430
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300431 Tempcx &= 0x3F; /* Tempcx[5:0]: HRS[5:0] */
432 if (Tempax < Tempcx) /* HRE < HRS */
433 Temp2 |= 0x40; /* Temp2 + 0x40 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200434
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300435 Temp2 &= 0xFF;
436 Tempax = (unsigned char) Temp2; /* Tempax: HRE[7:0] */
437 Tempax <<= 2; /* Tempax[7:2]: HRE[5:0] */
438 Tempdx >>= 6; /* Tempdx[7:6]->[1:0] HRS[9:8] */
439 Tempax |= Tempdx; /* HRE[5:0]HRS[9:8] */
440 /* SR2F D[7:2]->HRE, D[1:0]->HRS */
441 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
442 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200443
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300444 /* CR10 VRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200445 Tempax = XGI_CRT1Table[index].CR[10];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300446 Tempbx = Tempax; /* Tempbx: VRS */
447 Tempax &= 0x01; /* Tempax[0]: VRS[0] */
448 xgifb_reg_or(pVBInfo->P3c4, 0x33, Tempax); /* SR33[0]->VRS[0] */
449 /* CR7[2][7] VRE */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200450 Tempax = XGI_CRT1Table[index].CR[9];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300451 Tempcx = Tempbx >> 1; /* Tempcx[6:0]: VRS[7:1] */
452 Tempdx = Tempax & 0x04; /* Tempdx[2]: CR7[2] */
453 Tempdx <<= 5; /* Tempdx[7]: VRS[8] */
454 Tempcx |= Tempdx; /* Tempcx[7:0]: VRS[8:1] */
455 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempcx); /* SR34[8:1]->VRS */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200456
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300457 Temp1 = Tempdx; /* Temp1[7]: Tempdx[7] */
458 Temp1 <<= 1; /* Temp1[8]: VRS[8] */
459 Temp1 |= Tempbx; /* Temp1[8:0]: VRS[8:0] */
460 Tempax &= 0x80;
461 Temp2 = Tempax << 2; /* Temp2[9]: VRS[9] */
462 Temp1 |= Temp2; /* Temp1[9:0]: VRS[9:0] */
463 /* Tempax: SRA */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200464 Tempax = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300465 Tempax &= 0x08; /* Tempax[3]: VRS[3] */
466 Temp2 = Tempax;
467 Temp2 <<= 7; /* Temp2[10]: VRS[10] */
468 Temp1 |= Temp2; /* Temp1[10:0]: VRS[10:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200469
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300470 /* Tempax: CR11 VRE */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200471 Tempax = XGI_CRT1Table[index].CR[11];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300472 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
473 /* Tempbx: SRA */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200474 Tempbx = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300475 Tempbx &= 0x20; /* Tempbx[5]: VRE[5] */
476 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
477 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
478 Temp2 = Temp1 & 0x7E0; /* Temp2[10:5]: VRS[10:5] */
479 Temp2 |= Tempax; /* Temp2[10:5]: VRE[10:5] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200480
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300481 Temp3 = Temp1 & 0x1F; /* Temp3[4:0]: VRS[4:0] */
482 if (Tempax < Temp3) /* VRE < VRS */
483 Temp2 |= 0x20; /* VRE + 0x20 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200484
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300485 Temp2 &= 0xFF;
486 Tempax = (unsigned char) Temp2; /* Tempax: VRE[7:0] */
487 Tempax <<= 2; /* Tempax[7:0]; VRE[5:0]00 */
488 Temp1 &= 0x600; /* Temp1[10:9]: VRS[10:9] */
489 Temp1 >>= 9; /* Temp1[1:0]: VRS[10:9] */
490 Tempbx = (unsigned char) Temp1;
491 Tempax |= Tempbx; /* Tempax[7:0]: VRE[5:0]VRS[10:9] */
492 Tempax &= 0x7F;
493 /* SR3F D[7:2]->VRE D[1:0]->VRS */
494 xgifb_reg_set(pVBInfo->P3c4, 0x3F, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200495}
496
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +0300497static void XGI_SetXG27CRTC(unsigned short RefreshRateTableIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800498 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200499{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300500 unsigned short index, Tempax, Tempbx, Tempcx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200501
Aaro Koskinena39325d2012-11-04 21:14:53 +0200502 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300503 /* Tempax: CR4 HRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200504 Tempax = XGI_CRT1Table[index].CR[3];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300505 Tempbx = Tempax; /* Tempbx: HRS[7:0] */
506 /* SR2E[7:0]->HRS */
507 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200508
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300509 /* SR0B */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200510 Tempax = XGI_CRT1Table[index].CR[5];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300511 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
512 Tempbx |= (Tempax << 2); /* Tempbx: HRS[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200513
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200514 Tempax = XGI_CRT1Table[index].CR[4]; /* CR5 HRE */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300515 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
516 Tempcx = Tempax; /* Tempcx: HRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200517
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200518 Tempax = XGI_CRT1Table[index].CR[6]; /* SRC */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300519 Tempax &= 0x04; /* Tempax[2]: HRE[5] */
520 Tempax <<= 3; /* Tempax[5]: HRE[5] */
521 Tempcx |= Tempax; /* Tempcx[5:0]: HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200522
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300523 Tempbx = Tempbx & 0x3C0; /* Tempbx[9:6]: HRS[9:6] */
524 Tempbx |= Tempcx; /* Tempbx: HRS[9:6]HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200525
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300526 /* Tempax: CR4 HRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200527 Tempax = XGI_CRT1Table[index].CR[3];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300528 Tempax &= 0x3F; /* Tempax: HRS[5:0] */
529 if (Tempcx <= Tempax) /* HRE[5:0] < HRS[5:0] */
530 Tempbx += 0x40; /* Tempbx= Tempbx + 0x40 : HRE[9:0]*/
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200531
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200532 Tempax = XGI_CRT1Table[index].CR[5]; /* SR0B */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300533 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
534 Tempax >>= 6; /* Tempax[1:0]: HRS[9:8]*/
535 Tempax |= ((Tempbx << 2) & 0xFF); /* Tempax[7:2]: HRE[5:0] */
536 /* SR2F [7:2][1:0]: HRE[5:0]HRS[9:8] */
537 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
538 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200539
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300540 /* CR10 VRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200541 Tempax = XGI_CRT1Table[index].CR[10];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300542 /* SR34[7:0]->VRS[7:0] */
543 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200544
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300545 Tempcx = Tempax; /* Tempcx <= VRS[7:0] */
546 /* CR7[7][2] VRS[9][8] */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200547 Tempax = XGI_CRT1Table[index].CR[9];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300548 Tempbx = Tempax; /* Tempbx <= CR07[7:0] */
549 Tempax = Tempax & 0x04; /* Tempax[2]: CR7[2]: VRS[8] */
550 Tempax >>= 2; /* Tempax[0]: VRS[8] */
551 /* SR35[0]: VRS[8] */
552 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x01, Tempax);
553 Tempcx |= (Tempax << 8); /* Tempcx <= VRS[8:0] */
554 Tempcx |= ((Tempbx & 0x80) << 2); /* Tempcx <= VRS[9:0] */
555 /* Tempax: SR0A */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200556 Tempax = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300557 Tempax &= 0x08; /* SR0A[3] VRS[10] */
558 Tempcx |= (Tempax << 7); /* Tempcx <= VRS[10:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200559
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300560 /* Tempax: CR11 VRE */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200561 Tempax = XGI_CRT1Table[index].CR[11];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300562 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
563 /* Tempbx: SR0A */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200564 Tempbx = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300565 Tempbx &= 0x20; /* Tempbx[5]: SR0A[5]: VRE[4] */
566 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
567 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
568 Tempbx = Tempcx; /* Tempbx: VRS[10:0] */
569 Tempbx &= 0x7E0; /* Tempbx[10:5]: VRS[10:5] */
570 Tempbx |= Tempax; /* Tempbx: VRS[10:5]VRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200571
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300572 if (Tempbx <= Tempcx) /* VRE <= VRS */
573 Tempbx |= 0x20; /* VRE + 0x20 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200574
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300575 /* Tempax: Tempax[7:0]; VRE[5:0]00 */
576 Tempax = (Tempbx << 2) & 0xFF;
577 /* SR3F[7:2]:VRE[5:0] */
578 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC, Tempax);
579 Tempax = Tempcx >> 8;
580 /* SR35[2:0]:VRS[10:8] */
581 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200582}
583
Aaro Koskinena2d08cf2011-11-27 23:03:08 +0200584static void XGI_SetXG27FPBits(struct vb_device_info *pVBInfo)
585{
586 unsigned char temp;
587
588 /* D[1:0] 01: 18bit, 00: dual 12, 10: single 24 */
589 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
590 temp = (temp & 3) << 6;
591 /* SR06[7]0: dual 12/1: single 24 [6] 18bit Dither <= 0 h/w recommend */
592 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0xc0, temp & 0x80);
593 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: 24bits */
594 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
595
596}
597
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300598static void xgifb_set_lcd(int chip_id,
599 struct vb_device_info *pVBInfo,
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +0300600 unsigned short RefreshRateTableIndex)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200601{
Peter Huewee2e544c2013-02-03 04:08:46 +0100602 unsigned short temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200603
Aaro Koskinen8104e322011-03-13 12:26:22 +0200604 xgifb_reg_set(pVBInfo->P3d4, 0x2E, 0x00);
605 xgifb_reg_set(pVBInfo->P3d4, 0x2F, 0x00);
606 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x00);
607 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x00);
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300608
609 if (chip_id == XG27) {
Peter Huewee2e544c2013-02-03 04:08:46 +0100610 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
611 if ((temp & 0x03) == 0) { /* dual 12 */
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300612 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x13);
613 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x13);
614 }
615 }
616
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300617 if (chip_id == XG27) {
618 XGI_SetXG27FPBits(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530619 } else {
Peter Huewee2e544c2013-02-03 04:08:46 +0100620 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
621 if (temp & 0x01) {
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300622 /* 18 bits FP */
623 xgifb_reg_or(pVBInfo->P3c4, 0x06, 0x40);
624 xgifb_reg_or(pVBInfo->P3c4, 0x09, 0x40);
625 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530626 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200627
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +0200628 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x01); /* Negative blank polarity */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200629
Aaro Koskinendc505562011-03-13 12:26:26 +0200630 xgifb_reg_and(pVBInfo->P3c4, 0x30, ~0x20); /* Hsync polarity */
631 xgifb_reg_and(pVBInfo->P3c4, 0x35, ~0x80); /* Vsync polarity */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200632
Peter Huewee2e544c2013-02-03 04:08:46 +0100633 temp = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
634 if (temp & 0x4000)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300635 /* Hsync polarity */
636 xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20);
Peter Huewee2e544c2013-02-03 04:08:46 +0100637 if (temp & 0x8000)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300638 /* Vsync polarity */
639 xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200640}
641
642/* --------------------------------------------------------------------- */
643/* Function : XGI_UpdateXG21CRTC */
644/* Input : */
645/* Output : CRT1 CRTC */
646/* Description : Modify CRT1 Hsync/Vsync to fix LCD mode timing */
647/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800648static void XGI_UpdateXG21CRTC(unsigned short ModeNo,
649 struct vb_device_info *pVBInfo,
650 unsigned short RefreshRateTableIndex)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200651{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300652 int index = -1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200653
Aaro Koskinendc505562011-03-13 12:26:26 +0200654 xgifb_reg_and(pVBInfo->P3d4, 0x11, 0x7F); /* Unlock CR0~7 */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300655 if (ModeNo == 0x2E &&
Aaro Koskinena39325d2012-11-04 21:14:53 +0200656 (XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC ==
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300657 RES640x480x60))
658 index = 12;
Aaro Koskinena39325d2012-11-04 21:14:53 +0200659 else if (ModeNo == 0x2E && (XGI330_RefIndex[RefreshRateTableIndex].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800660 Ext_CRT1CRTC == RES640x480x72))
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300661 index = 13;
662 else if (ModeNo == 0x2F)
663 index = 14;
664 else if (ModeNo == 0x50)
665 index = 15;
666 else if (ModeNo == 0x59)
667 index = 16;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200668
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530669 if (index != -1) {
Aaro Koskinen8104e322011-03-13 12:26:22 +0200670 xgifb_reg_set(pVBInfo->P3d4, 0x02,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200671 XGI_UpdateCRT1Table[index].CR02);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200672 xgifb_reg_set(pVBInfo->P3d4, 0x03,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200673 XGI_UpdateCRT1Table[index].CR03);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200674 xgifb_reg_set(pVBInfo->P3d4, 0x15,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200675 XGI_UpdateCRT1Table[index].CR15);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200676 xgifb_reg_set(pVBInfo->P3d4, 0x16,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200677 XGI_UpdateCRT1Table[index].CR16);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530678 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200679}
680
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200681static void XGI_SetCRT1DE(struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +0300682 unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530683 unsigned short RefreshRateTableIndex,
684 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200685{
Bill Pemberton82d6eb52010-06-17 13:10:46 -0400686 unsigned short resindex, tempax, tempbx, tempcx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200687
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530688 unsigned char data;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200689
Aaro Koskinenb3979922012-11-04 21:14:52 +0200690 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200691
Aaro Koskinenb3979922012-11-04 21:14:52 +0200692 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinene8e6c752012-11-04 21:15:00 +0200693 tempax = XGI330_ModeResInfo[resindex].HTotal;
694 tempbx = XGI330_ModeResInfo[resindex].VTotal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200695
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530696 if (modeflag & HalfDCLK)
697 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200698
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300699 if (modeflag & HalfDCLK)
700 tempax = tempax << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200701
Aaro Koskinena39325d2012-11-04 21:14:53 +0200702 temp = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200703
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300704 if (temp & InterlaceMode)
705 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200706
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300707 if (modeflag & DoubleScanMode)
708 tempbx = tempbx << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200709
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530710 tempcx = 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200711
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530712 tempax /= tempcx;
713 tempax -= 1;
714 tempbx -= 1;
715 tempcx = tempax;
Peter Huewe9388ad92013-02-15 20:37:10 +0100716 temp = xgifb_reg_get(pVBInfo->P3d4, 0x11);
717 data = xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530718 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200719 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
720 xgifb_reg_set(pVBInfo->P3d4, 0x01, (unsigned short) (tempcx & 0xff));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200721 xgifb_reg_and_or(pVBInfo->P3d4, 0x0b, ~0x0c,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530722 (unsigned short) ((tempcx & 0x0ff00) >> 10));
Aaro Koskinen8104e322011-03-13 12:26:22 +0200723 xgifb_reg_set(pVBInfo->P3d4, 0x12, (unsigned short) (tempbx & 0xff));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530724 tempax = 0;
725 tempbx = tempbx >> 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200726
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530727 if (tempbx & 0x01)
728 tempax |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200729
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530730 if (tempbx & 0x02)
731 tempax |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200732
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200733 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x42, tempax);
Peter Huewe9388ad92013-02-15 20:37:10 +0100734 data = xgifb_reg_get(pVBInfo->P3d4, 0x07);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530735 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200736
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530737 if (tempbx & 0x04)
738 tempax |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200739
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200740 xgifb_reg_and_or(pVBInfo->P3d4, 0x0a, ~0x02, tempax);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200741 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200742}
743
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800744static void XGI_SetCRT1Offset(unsigned short ModeNo,
745 unsigned short ModeIdIndex,
746 unsigned short RefreshRateTableIndex,
747 struct xgi_hw_device_info *HwDeviceExtension,
748 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200749{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530750 unsigned short temp, ah, al, temp2, i, DisplayUnit;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200751
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530752 /* GetOffset */
Aaro Koskinenb3979922012-11-04 21:14:52 +0200753 temp = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeInfo;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530754 temp = temp >> 8;
Aaro Koskinen224114c2012-11-04 21:14:59 +0200755 temp = XGI330_ScreenOffset[temp];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200756
Aaro Koskinena39325d2012-11-04 21:14:53 +0200757 temp2 = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530758 temp2 &= InterlaceMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200759
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530760 if (temp2)
761 temp = temp << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200762
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530763 temp2 = pVBInfo->ModeType - ModeEGA;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200764
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530765 switch (temp2) {
766 case 0:
767 temp2 = 1;
768 break;
769 case 1:
770 temp2 = 2;
771 break;
772 case 2:
773 temp2 = 4;
774 break;
775 case 3:
776 temp2 = 4;
777 break;
778 case 4:
779 temp2 = 6;
780 break;
781 case 5:
782 temp2 = 8;
783 break;
784 default:
785 break;
786 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200787
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530788 if ((ModeNo >= 0x26) && (ModeNo <= 0x28))
789 temp = temp * temp2 + temp2 / 2;
790 else
791 temp *= temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200792
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530793 /* SetOffset */
794 DisplayUnit = temp;
795 temp2 = temp;
796 temp = temp >> 8; /* ah */
797 temp &= 0x0F;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200798 i = xgifb_reg_get(pVBInfo->P3c4, 0x0E);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530799 i &= 0xF0;
800 i |= temp;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200801 xgifb_reg_set(pVBInfo->P3c4, 0x0E, i);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200802
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530803 temp = (unsigned char) temp2;
804 temp &= 0xFF; /* al */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200805 xgifb_reg_set(pVBInfo->P3d4, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200806
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530807 /* SetDisplayUnit */
Aaro Koskinena39325d2012-11-04 21:14:53 +0200808 temp2 = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530809 temp2 &= InterlaceMode;
810 if (temp2)
811 DisplayUnit >>= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200812
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530813 DisplayUnit = DisplayUnit << 5;
814 ah = (DisplayUnit & 0xff00) >> 8;
815 al = DisplayUnit & 0x00ff;
816 if (al == 0)
817 ah += 1;
818 else
819 ah += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200820
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530821 if (HwDeviceExtension->jChipType >= XG20)
822 if ((ModeNo == 0x4A) | (ModeNo == 0x49))
823 ah -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200824
Aaro Koskinen8104e322011-03-13 12:26:22 +0200825 xgifb_reg_set(pVBInfo->P3c4, 0x10, ah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200826}
827
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +0300828static unsigned short XGI_GetVCLK2Ptr(unsigned short ModeIdIndex,
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200829 unsigned short RefreshRateTableIndex,
830 struct xgi_hw_device_info *HwDeviceExtension,
831 struct vb_device_info *pVBInfo)
832{
Peter Hueweef9a6b92013-02-03 04:08:43 +0100833 unsigned short VCLKIndex, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200834
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300835 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +0200836 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200837
Aaro Koskinen7ac54d02013-02-09 00:03:43 +0200838 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) { /*301b*/
839 if (pVBInfo->LCDResInfo != Panel_1024x768)
840 /* LCDXlat2VCLK */
841 VCLKIndex = VCLK108_2_315 + 5;
842 else
843 VCLKIndex = VCLK65_315 + 2; /* LCDXlat1VCLK */
844 } else if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
845 if (pVBInfo->SetFlag & RPLLDIV2XO)
846 VCLKIndex = TVCLKBASE_315_25 + HiTVVCLKDIV2;
847 else
848 VCLKIndex = TVCLKBASE_315_25 + HiTVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200849
Aaro Koskinen7ac54d02013-02-09 00:03:43 +0200850 if (pVBInfo->SetFlag & TVSimuMode) {
851 if (modeflag & Charx8Dot) {
852 VCLKIndex = TVCLKBASE_315_25 + HiTVSimuVCLK;
853 } else {
854 VCLKIndex = TVCLKBASE_315_25 + HiTVTextVCLK;
Aaro Koskinen798b4da2011-11-27 23:03:20 +0200855 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200856 }
Aaro Koskinen7ac54d02013-02-09 00:03:43 +0200857
858 /* 301lv */
859 if (pVBInfo->VBType & VB_SIS301LV) {
860 if (pVBInfo->SetFlag & RPLLDIV2XO)
861 VCLKIndex = YPbPr525iVCLK_2;
862 else
863 VCLKIndex = YPbPr525iVCLK;
864 }
865 } else if (pVBInfo->VBInfo & SetCRT2ToTV) {
866 if (pVBInfo->SetFlag & RPLLDIV2XO)
867 VCLKIndex = TVCLKBASE_315_25 + TVVCLKDIV2;
868 else
869 VCLKIndex = TVCLKBASE_315_25 + TVVCLK;
870 } else { /* for CRT2 */
871 /* di+Ext_CRTVCLK */
872 VCLKIndex = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
873 VCLKIndex &= IndexMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200874 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200875
876 return VCLKIndex;
877}
878
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +0300879static void XGI_SetCRT1VCLK(unsigned short ModeIdIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800880 struct xgi_hw_device_info *HwDeviceExtension,
881 unsigned short RefreshRateTableIndex,
882 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200883{
Bill Pemberton108afbf2010-06-17 13:10:47 -0400884 unsigned char index, data;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530885 unsigned short vclkindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200886
Aaro Koskinenb750f512013-05-29 23:59:05 +0300887 if ((pVBInfo->IF_DEF_LVDS == 0) &&
888 (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV |
889 VB_SIS302LV | VB_XGI301C)) &&
890 (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) {
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +0300891 vclkindex = XGI_GetVCLK2Ptr(ModeIdIndex, RefreshRateTableIndex,
892 HwDeviceExtension, pVBInfo);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200893 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200894 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200895 data = XGI_VBVCLKData[vclkindex].Part4_A;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200896 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200897 data = XGI_VBVCLKData[vclkindex].Part4_B;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200898 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
899 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530900 } else {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200901 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200902 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200903 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200904 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[index].SR2B);
905 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[index].SR2C);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200906 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530907 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200908
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530909 if (HwDeviceExtension->jChipType >= XG20) {
Aaro Koskinenb3979922012-11-04 21:14:52 +0200910 if (XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag &
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800911 HalfDCLK) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200912 data = xgifb_reg_get(pVBInfo->P3c4, 0x2B);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200913 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200914 data = xgifb_reg_get(pVBInfo->P3c4, 0x2C);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530915 index = data;
916 index &= 0xE0;
917 data &= 0x1F;
918 data = data << 1;
919 data += 1;
920 data |= index;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200921 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530922 }
923 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200924}
925
Aaro Koskinene85f2032011-11-27 23:03:07 +0200926static void XGI_SetXG21FPBits(struct vb_device_info *pVBInfo)
927{
928 unsigned char temp;
929
930 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37); /* D[0] 1: 18bit */
931 temp = (temp & 1) << 6;
932 /* SR06[6] 18bit Dither */
933 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x40, temp);
934 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: dual 12bits */
935 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
936
937}
938
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +0300939static void XGI_SetCRT1FIFO(struct xgi_hw_device_info *HwDeviceExtension,
940 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200941{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530942 unsigned short data;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200943
Aaro Koskinen58839b02011-03-13 12:26:23 +0200944 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530945 data &= 0xfe;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200946 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data); /* diable auto-threshold */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200947
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300948 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0x34);
949 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
950 data &= 0xC0;
951 xgifb_reg_set(pVBInfo->P3c4, 0x09, data | 0x30);
952 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
953 data |= 0x01;
954 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200955
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530956 if (HwDeviceExtension->jChipType == XG21)
957 XGI_SetXG21FPBits(pVBInfo); /* Fix SR9[7:6] can't read back */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200958}
959
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200960static void XGI_SetVCLKState(struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +0300961 unsigned short RefreshRateTableIndex,
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200962 struct vb_device_info *pVBInfo)
963{
964 unsigned short data, data2 = 0;
965 short VCLK;
966
967 unsigned char index;
968
Aaro Koskinena39325d2012-11-04 21:14:53 +0200969 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300970 index &= IndexMask;
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200971 VCLK = XGI_VCLKData[index].CLOCK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200972
Aaro Koskinen58839b02011-03-13 12:26:23 +0200973 data = xgifb_reg_get(pVBInfo->P3c4, 0x32);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200974 data &= 0xf3;
975 if (VCLK >= 200)
976 data |= 0x0c; /* VCLK > 200 */
977
978 if (HwDeviceExtension->jChipType >= XG20)
979 data &= ~0x04; /* 2 pixel mode */
980
Aaro Koskinen8104e322011-03-13 12:26:22 +0200981 xgifb_reg_set(pVBInfo->P3c4, 0x32, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200982
983 if (HwDeviceExtension->jChipType < XG20) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200984 data = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200985 data &= 0xE7;
986 if (VCLK < 200)
987 data |= 0x10;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200988 xgifb_reg_set(pVBInfo->P3c4, 0x1F, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200989 }
990
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200991 data2 = 0x00;
992
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200993 xgifb_reg_and_or(pVBInfo->P3c4, 0x07, 0xFC, data2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200994 if (HwDeviceExtension->jChipType >= XG27)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200995 xgifb_reg_and_or(pVBInfo->P3c4, 0x40, 0xFC, data2 & 0x03);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200996
997}
998
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200999static void XGI_SetCRT1ModeRegs(struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001000 unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301001 unsigned short RefreshRateTableIndex,
1002 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001003{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301004 unsigned short data, data2, data3, infoflag = 0, modeflag, resindex,
1005 xres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001006
Aaro Koskinenb3979922012-11-04 21:14:52 +02001007 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02001008 infoflag = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001009
Aaro Koskinen58839b02011-03-13 12:26:23 +02001010 if (xgifb_reg_get(pVBInfo->P3d4, 0x31) & 0x01)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001011 xgifb_reg_and_or(pVBInfo->P3c4, 0x1F, 0x3F, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001012
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001013 data = infoflag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301014 data2 = 0;
Aaro Koskinen969f7f32012-04-07 01:14:03 +03001015 data2 |= 0x02;
1016 data3 = pVBInfo->ModeType - ModeVGA;
1017 data3 = data3 << 2;
1018 data2 |= data3;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301019 data &= InterlaceMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001020
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301021 if (data)
1022 data2 |= 0x20;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001023
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001024 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x3F, data2);
Aaro Koskinenb3979922012-11-04 21:14:52 +02001025 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02001026 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001027
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301028 data = 0x0000;
1029 if (infoflag & InterlaceMode) {
1030 if (xres == 1024)
1031 data = 0x0035;
1032 else if (xres == 1280)
1033 data = 0x0048;
1034 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001035
Peter Huewe5d1c2a92013-02-03 22:54:37 +01001036 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFF, data);
1037 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFC, 0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001038
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301039 if (modeflag & HalfDCLK)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001040 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xF7, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001041
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301042 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001043
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301044 if (modeflag & LineCompareOff)
1045 data2 |= 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001046
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001047 xgifb_reg_and_or(pVBInfo->P3c4, 0x0F, ~0x48, data2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301048 data = 0x60;
Aaro Koskinen969f7f32012-04-07 01:14:03 +03001049 data = data ^ 0x60;
1050 data = data ^ 0xA0;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001051 xgifb_reg_and_or(pVBInfo->P3c4, 0x21, 0x1F, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001052
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001053 XGI_SetVCLKState(HwDeviceExtension, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001054
Aaro Koskinen58839b02011-03-13 12:26:23 +02001055 data = xgifb_reg_get(pVBInfo->P3d4, 0x31);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001056
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301057 if (HwDeviceExtension->jChipType == XG27) {
1058 if (data & 0x40)
1059 data = 0x2c;
1060 else
1061 data = 0x6c;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001062 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02001063 xgifb_reg_or(pVBInfo->P3d4, 0x51, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301064 } else if (HwDeviceExtension->jChipType >= XG20) {
1065 if (data & 0x40)
1066 data = 0x33;
1067 else
1068 data = 0x73;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001069 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
1070 xgifb_reg_set(pVBInfo->P3d4, 0x51, 0x02);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301071 } else {
1072 if (data & 0x40)
1073 data = 0x2c;
1074 else
1075 data = 0x6c;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001076 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301077 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001078
1079}
1080
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001081static void XGI_WriteDAC(unsigned short dl,
1082 unsigned short ah,
1083 unsigned short al,
1084 unsigned short dh,
1085 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001086{
1087 unsigned short temp, bh, bl;
1088
1089 bh = ah;
1090 bl = al;
1091
1092 if (dl != 0) {
1093 temp = bh;
1094 bh = dh;
1095 dh = temp;
1096 if (dl == 1) {
1097 temp = bl;
1098 bl = dh;
1099 dh = temp;
1100 } else {
1101 temp = bl;
1102 bl = bh;
1103 bh = temp;
1104 }
1105 }
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001106 outb((unsigned short) dh, pVBInfo->P3c9);
1107 outb((unsigned short) bh, pVBInfo->P3c9);
1108 outb((unsigned short) bl, pVBInfo->P3c9);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001109}
1110
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03001111static void XGI_LoadDAC(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001112{
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001113 unsigned short data, data2, i, k, m, n, o, si, di, bx, dl, al, ah, dh;
1114 const unsigned short *table = XGINew_VGA_DAC;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001115
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001116 outb(0xFF, pVBInfo->P3c6);
1117 outb(0x00, pVBInfo->P3c8);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001118
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001119 for (i = 0; i < 16; i++) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301120 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001121
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301122 for (k = 0; k < 3; k++) {
1123 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001124
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301125 if (data & 0x01)
1126 data2 = 0x2A;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001127
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301128 if (data & 0x02)
1129 data2 += 0x15;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001130
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001131 outb(data2, pVBInfo->P3c9);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301132 data = data >> 2;
1133 }
1134 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001135
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001136 for (i = 16; i < 32; i++) {
1137 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001138
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001139 for (k = 0; k < 3; k++)
1140 outb(data, pVBInfo->P3c9);
1141 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001142
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001143 si = 32;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001144
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001145 for (m = 0; m < 9; m++) {
1146 di = si;
1147 bx = si + 0x04;
1148 dl = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001149
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001150 for (n = 0; n < 3; n++) {
1151 for (o = 0; o < 5; o++) {
1152 dh = table[si];
1153 ah = table[di];
1154 al = table[bx];
1155 si++;
1156 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301157 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001158
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001159 si -= 2;
1160
1161 for (o = 0; o < 3; o++) {
1162 dh = table[bx];
1163 ah = table[di];
1164 al = table[si];
1165 si--;
1166 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1167 }
1168
1169 dl++;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301170 }
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001171
1172 si += 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301173 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001174}
1175
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001176static void XGI_GetLVDSResInfo(unsigned short ModeIdIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001177 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001178{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301179 unsigned short resindex, xres, yres, modeflag;
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 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001183
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001184 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02001185 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001186
Aaro Koskinene8e6c752012-11-04 21:15:00 +02001187 xres = XGI330_ModeResInfo[resindex].HTotal;
1188 yres = XGI330_ModeResInfo[resindex].VTotal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001189
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001190 if (modeflag & HalfDCLK)
1191 xres = xres << 1;
1192
1193 if (modeflag & DoubleScanMode)
1194 yres = yres << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001195
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301196 if (xres == 720)
1197 xres = 640;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001198
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301199 pVBInfo->VGAHDE = xres;
1200 pVBInfo->HDE = xres;
1201 pVBInfo->VGAVDE = yres;
1202 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001203}
1204
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001205static void const *XGI_GetLcdPtr(struct XGI330_LCDDataTablStruct const *table,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001206 unsigned short ModeIdIndex,
1207 unsigned short RefreshRateTableIndex,
1208 struct vb_device_info *pVBInfo)
1209{
Aaro Koskinen6c27b372012-11-04 21:14:45 +02001210 unsigned short i, tempdx, tempbx, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001211
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001212 tempbx = 0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001213
Aaro Koskinenb3979922012-11-04 21:14:52 +02001214 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001215
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001216 i = 0;
1217
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001218 while (table[i].PANELID != 0xff) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001219 tempdx = pVBInfo->LCDResInfo;
1220 if (tempbx & 0x0080) { /* OEMUtil */
1221 tempbx &= (~0x0080);
1222 tempdx = pVBInfo->LCDTypeInfo;
1223 }
1224
1225 if (pVBInfo->LCDInfo & EnableScalingLCD)
1226 tempdx &= (~PanelResInfo);
1227
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001228 if (table[i].PANELID == tempdx) {
1229 tempbx = table[i].MASK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001230 tempdx = pVBInfo->LCDInfo;
1231
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001232 if (modeflag & HalfDCLK)
1233 tempdx |= SetLCDLowResolution;
1234
1235 tempbx &= tempdx;
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001236 if (tempbx == table[i].CAP)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001237 break;
1238 }
1239 i++;
1240 }
1241
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001242 return table[i].DATAPTR;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001243}
1244
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001245static struct SiS_TVData const *XGI_GetTVPtr(unsigned short ModeIdIndex,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001246 unsigned short RefreshRateTableIndex,
1247 struct vb_device_info *pVBInfo)
1248{
Aaro Koskinen56d276c2012-09-11 00:15:19 +03001249 unsigned short i, tempdx, tempal, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001250
Aaro Koskinenb3979922012-11-04 21:14:52 +02001251 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02001252 tempal = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001253 tempal = tempal & 0x3f;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001254 tempdx = pVBInfo->TVInfo;
1255
1256 if (pVBInfo->VBInfo & SetInSlaveMode)
1257 tempdx = tempdx | SetTVLockMode;
1258
1259 if (modeflag & HalfDCLK)
1260 tempdx = tempdx | SetTVLowResolution;
1261
1262 i = 0;
1263
Aaro Koskinen6265ee42012-09-11 00:15:20 +03001264 while (XGI_TVDataTable[i].MASK != 0xffff) {
1265 if ((tempdx & XGI_TVDataTable[i].MASK) ==
1266 XGI_TVDataTable[i].CAP)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001267 break;
1268 i++;
1269 }
1270
Aaro Koskinen18ba8662012-09-11 00:15:22 +03001271 return &XGI_TVDataTable[i].DATAPTR[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001272}
1273
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001274static void XGI_GetLVDSData(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301275 unsigned short RefreshRateTableIndex,
1276 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001277{
Aaro Koskinen6008f872012-11-04 21:14:49 +02001278 struct SiS_LVDSData const *LCDPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001279
Aaro Koskinen6008f872012-11-04 21:14:49 +02001280 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
1281 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001282
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001283 LCDPtr = XGI_GetLcdPtr(XGI_EPLLCDDataPtr, ModeIdIndex,
Aaro Koskinen6008f872012-11-04 21:14:49 +02001284 RefreshRateTableIndex, pVBInfo);
1285 pVBInfo->VGAHT = LCDPtr->VGAHT;
1286 pVBInfo->VGAVT = LCDPtr->VGAVT;
1287 pVBInfo->HT = LCDPtr->LCDHT;
1288 pVBInfo->VT = LCDPtr->LCDVT;
1289
1290 if (pVBInfo->LCDInfo & (SetLCDtoNonExpanding | EnableScalingLCD))
1291 return;
1292
1293 if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
1294 (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
1295 pVBInfo->HDE = 1024;
1296 pVBInfo->VDE = 768;
1297 } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
1298 (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
1299 pVBInfo->HDE = 1280;
1300 pVBInfo->VDE = 1024;
1301 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
1302 pVBInfo->HDE = 1400;
1303 pVBInfo->VDE = 1050;
1304 } else {
1305 pVBInfo->HDE = 1600;
1306 pVBInfo->VDE = 1200;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301307 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001308}
1309
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001310static void XGI_ModCRT1Regs(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301311 unsigned short RefreshRateTableIndex,
1312 struct xgi_hw_device_info *HwDeviceExtension,
1313 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001314{
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001315 unsigned short i;
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001316 struct XGI_LVDSCRT1HDataStruct const *LCDPtr = NULL;
1317 struct XGI_LVDSCRT1VDataStruct const *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001318
Peter Huewea3d675c2012-02-09 21:11:47 +01001319 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001320 LCDPtr = XGI_GetLcdPtr(xgifb_epllcd_crt1_h, ModeIdIndex,
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +03001321 RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001322
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001323 for (i = 0; i < 8; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +02001324 pVBInfo->TimingH.data[i] = LCDPtr[0].Reg[i];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301325 }
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001326
1327 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
1328
Peter Huewea3d675c2012-02-09 21:11:47 +01001329 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001330 LCDPtr1 = XGI_GetLcdPtr(xgifb_epllcd_crt1_v, ModeIdIndex,
1331 RefreshRateTableIndex, pVBInfo);
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001332 for (i = 0; i < 7; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +02001333 pVBInfo->TimingV.data[i] = LCDPtr1[0].Reg[i];
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001334 }
1335
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001336 XGI_SetCRT1Timing_V(ModeIdIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001337}
1338
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001339static unsigned short XGI_GetLCDCapPtr(struct vb_device_info *pVBInfo)
1340{
1341 unsigned char tempal, tempah, tempbl, i;
1342
Aaro Koskinen58839b02011-03-13 12:26:23 +02001343 tempah = xgifb_reg_get(pVBInfo->P3d4, 0x36);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001344 tempal = tempah & 0x0F;
1345 tempah = tempah & 0xF0;
1346 i = 0;
1347 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1348
1349 while (tempbl != 0xFF) {
1350 if (tempbl & 0x80) { /* OEMUtil */
1351 tempal = tempah;
1352 tempbl = tempbl & ~(0x80);
1353 }
1354
1355 if (tempal == tempbl)
1356 break;
1357
1358 i++;
1359
1360 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1361 }
1362
1363 return i;
1364}
1365
1366static unsigned short XGI_GetLCDCapPtr1(struct vb_device_info *pVBInfo)
1367{
1368 unsigned short tempah, tempal, tempbl, i;
1369
1370 tempal = pVBInfo->LCDResInfo;
1371 tempah = pVBInfo->LCDTypeInfo;
1372
1373 i = 0;
1374 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1375
1376 while (tempbl != 0xFF) {
1377 if ((tempbl & 0x80) && (tempbl != 0x80)) {
1378 tempal = tempah;
1379 tempbl &= ~0x80;
1380 }
1381
1382 if (tempal == tempbl)
1383 break;
1384
1385 i++;
1386 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1387 }
1388
1389 if (tempbl == 0xFF) {
Peter Huewe255aabd2012-02-09 21:11:44 +01001390 pVBInfo->LCDResInfo = Panel_1024x768;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001391 pVBInfo->LCDTypeInfo = 0;
1392 i = 0;
1393 }
1394
1395 return i;
1396}
1397
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001398static void XGI_GetLCDSync(unsigned short *HSyncWidth,
1399 unsigned short *VSyncWidth,
1400 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001401{
1402 unsigned short Index;
1403
1404 Index = XGI_GetLCDCapPtr(pVBInfo);
1405 *HSyncWidth = pVBInfo->LCDCapList[Index].LCD_HSyncWidth;
1406 *VSyncWidth = pVBInfo->LCDCapList[Index].LCD_VSyncWidth;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001407}
1408
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001409static void XGI_SetLVDSRegs(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301410 unsigned short RefreshRateTableIndex,
1411 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001412{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301413 unsigned short tempbx, tempax, tempcx, tempdx, push1, push2, modeflag;
1414 unsigned long temp, temp1, temp2, temp3, push3;
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001415 struct XGI330_LCDDataDesStruct2 const *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001416
Aaro Koskinenb3979922012-11-04 21:14:52 +02001417 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001418 LCDPtr1 = XGI_GetLcdPtr(XGI_EPLLCDDesDataPtr, ModeIdIndex,
1419 RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001420
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001421 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
1422 push1 = tempbx;
1423 push2 = tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001424
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001425 /* GetLCDResInfo */
Peter Huewe255aabd2012-02-09 21:11:44 +01001426 if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
1427 (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001428 tempax = 1024;
1429 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01001430 } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
1431 (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001432 tempax = 1280;
1433 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01001434 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001435 tempax = 1400;
1436 tempbx = 1050;
1437 } else {
1438 tempax = 1600;
1439 tempbx = 1200;
1440 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001441
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001442 if (pVBInfo->LCDInfo & SetLCDtoNonExpanding) {
1443 pVBInfo->HDE = tempax;
1444 pVBInfo->VDE = tempbx;
1445 pVBInfo->VGAHDE = tempax;
1446 pVBInfo->VGAVDE = tempbx;
1447 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001448
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001449 tempax = pVBInfo->HT;
1450
Peter Huewe826215d2013-02-05 00:29:46 +01001451 tempbx = LCDPtr1->LCDHDES;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001452
1453 tempcx = pVBInfo->HDE;
1454 tempbx = tempbx & 0x0fff;
1455 tempcx += tempbx;
1456
1457 if (tempcx >= tempax)
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001458 tempcx -= tempax;
1459
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001460 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, tempbx & 0x07);
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001461
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001462 tempcx = tempcx >> 3;
1463 tempbx = tempbx >> 3;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001464
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001465 xgifb_reg_set(pVBInfo->Part1Port, 0x16,
1466 (unsigned short) (tempbx & 0xff));
1467 xgifb_reg_set(pVBInfo->Part1Port, 0x17,
1468 (unsigned short) (tempcx & 0xff));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001469
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001470 tempax = pVBInfo->HT;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001471
Peter Huewe826215d2013-02-05 00:29:46 +01001472 tempbx = LCDPtr1->LCDHRS;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001473
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001474 tempcx = push2;
1475
1476 if (pVBInfo->LCDInfo & EnableScalingLCD)
1477 tempcx = LCDPtr1->LCDHSync;
1478
1479 tempcx += tempbx;
1480
1481 if (tempcx >= tempax)
1482 tempcx -= tempax;
1483
1484 tempax = tempbx & 0x07;
1485 tempax = tempax >> 5;
1486 tempcx = tempcx >> 3;
1487 tempbx = tempbx >> 3;
1488
1489 tempcx &= 0x1f;
1490 tempax |= tempcx;
1491
1492 xgifb_reg_set(pVBInfo->Part1Port, 0x15, tempax);
1493 xgifb_reg_set(pVBInfo->Part1Port, 0x14,
1494 (unsigned short) (tempbx & 0xff));
1495
1496 tempax = pVBInfo->VT;
Peter Huewe826215d2013-02-05 00:29:46 +01001497 tempbx = LCDPtr1->LCDVDES;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001498 tempcx = pVBInfo->VDE;
1499
1500 tempbx = tempbx & 0x0fff;
1501 tempcx += tempbx;
1502 if (tempcx >= tempax)
1503 tempcx -= tempax;
1504
1505 xgifb_reg_set(pVBInfo->Part1Port, 0x1b,
1506 (unsigned short) (tempbx & 0xff));
1507 xgifb_reg_set(pVBInfo->Part1Port, 0x1c,
1508 (unsigned short) (tempcx & 0xff));
1509
1510 tempbx = (tempbx >> 8) & 0x07;
1511 tempcx = (tempcx >> 8) & 0x07;
1512
1513 xgifb_reg_set(pVBInfo->Part1Port, 0x1d,
1514 (unsigned short) ((tempcx << 3)
1515 | tempbx));
1516
1517 tempax = pVBInfo->VT;
Peter Huewe826215d2013-02-05 00:29:46 +01001518 tempbx = LCDPtr1->LCDVRS;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001519
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001520 tempcx = push1;
1521
1522 if (pVBInfo->LCDInfo & EnableScalingLCD)
1523 tempcx = LCDPtr1->LCDVSync;
1524
1525 tempcx += tempbx;
1526 if (tempcx >= tempax)
1527 tempcx -= tempax;
1528
1529 xgifb_reg_set(pVBInfo->Part1Port, 0x18,
1530 (unsigned short) (tempbx & 0xff));
1531 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, ~0x0f,
1532 (unsigned short) (tempcx & 0x0f));
1533
1534 tempax = ((tempbx >> 8) & 0x07) << 3;
1535
1536 tempbx = pVBInfo->VGAVDE;
1537 if (tempbx != pVBInfo->VDE)
1538 tempax |= 0x40;
1539
Peter Huewea3d675c2012-02-09 21:11:47 +01001540 if (pVBInfo->LCDInfo & XGI_EnableLVDSDDA)
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001541 tempax |= 0x40;
1542
1543 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1a, 0x07,
1544 tempax);
1545
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001546 tempbx = pVBInfo->VDE;
1547 tempax = pVBInfo->VGAVDE;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001548
1549 temp = tempax; /* 0430 ylshieh */
1550 temp1 = (temp << 18) / tempbx;
1551
1552 tempdx = (unsigned short) ((temp << 18) % tempbx);
1553
1554 if (tempdx != 0)
1555 temp1 += 1;
1556
1557 temp2 = temp1;
1558 push3 = temp2;
1559
1560 xgifb_reg_set(pVBInfo->Part1Port, 0x37,
1561 (unsigned short) (temp2 & 0xff));
1562 xgifb_reg_set(pVBInfo->Part1Port, 0x36,
1563 (unsigned short) ((temp2 >> 8) & 0xff));
1564
1565 tempbx = (unsigned short) (temp2 >> 16);
1566 tempax = tempbx & 0x03;
1567
1568 tempbx = pVBInfo->VGAVDE;
1569 if (tempbx == pVBInfo->VDE)
1570 tempax |= 0x04;
1571
1572 xgifb_reg_set(pVBInfo->Part1Port, 0x35, tempax);
1573
1574 if (pVBInfo->VBType & VB_XGI301C) {
1575 temp2 = push3;
1576 xgifb_reg_set(pVBInfo->Part4Port,
1577 0x3c,
1578 (unsigned short) (temp2 & 0xff));
1579 xgifb_reg_set(pVBInfo->Part4Port,
1580 0x3b,
1581 (unsigned short) ((temp2 >> 8) &
1582 0xff));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001583 tempbx = (unsigned short) (temp2 >> 16);
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001584 xgifb_reg_and_or(pVBInfo->Part4Port, 0x3a,
1585 ~0xc0,
1586 (unsigned short) ((tempbx &
1587 0xff) << 6));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001588
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001589 tempcx = pVBInfo->VGAVDE;
1590 if (tempcx == pVBInfo->VDE)
1591 xgifb_reg_and_or(pVBInfo->Part4Port,
1592 0x30, ~0x0c, 0x00);
1593 else
1594 xgifb_reg_and_or(pVBInfo->Part4Port,
1595 0x30, ~0x0c, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301596 }
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001597
1598 tempcx = pVBInfo->VGAHDE;
1599 tempbx = pVBInfo->HDE;
1600
1601 temp1 = tempcx << 16;
1602
1603 tempax = (unsigned short) (temp1 / tempbx);
1604
1605 if ((tempbx & 0xffff) == (tempcx & 0xffff))
1606 tempax = 65535;
1607
1608 temp3 = tempax;
1609 temp1 = pVBInfo->VGAHDE << 16;
1610
1611 temp1 /= temp3;
1612 temp3 = temp3 << 16;
1613 temp1 -= 1;
1614
1615 temp3 = (temp3 & 0xffff0000) + (temp1 & 0xffff);
1616
1617 tempax = (unsigned short) (temp3 & 0xff);
1618 xgifb_reg_set(pVBInfo->Part1Port, 0x1f, tempax);
1619
1620 temp1 = pVBInfo->VGAVDE << 18;
1621 temp1 = temp1 / push3;
1622 tempbx = (unsigned short) (temp1 & 0xffff);
1623
Peter Huewe255aabd2012-02-09 21:11:44 +01001624 if (pVBInfo->LCDResInfo == Panel_1024x768)
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001625 tempbx -= 1;
1626
1627 tempax = ((tempbx >> 8) & 0xff) << 3;
1628 tempax |= (unsigned short) ((temp3 >> 8) & 0x07);
1629 xgifb_reg_set(pVBInfo->Part1Port, 0x20,
1630 (unsigned short) (tempax & 0xff));
1631 xgifb_reg_set(pVBInfo->Part1Port, 0x21,
1632 (unsigned short) (tempbx & 0xff));
1633
1634 temp3 = temp3 >> 16;
1635
1636 if (modeflag & HalfDCLK)
1637 temp3 = temp3 >> 1;
1638
1639 xgifb_reg_set(pVBInfo->Part1Port, 0x22,
1640 (unsigned short) ((temp3 >> 8) & 0xff));
1641 xgifb_reg_set(pVBInfo->Part1Port, 0x23,
1642 (unsigned short) (temp3 & 0xff));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001643}
1644
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001645/* --------------------------------------------------------------------- */
1646/* Function : XGI_GETLCDVCLKPtr */
1647/* Input : */
1648/* Output : al -> VCLK Index */
1649/* Description : */
1650/* --------------------------------------------------------------------- */
1651static void XGI_GetLCDVCLKPtr(unsigned char *di_0, unsigned char *di_1,
1652 struct vb_device_info *pVBInfo)
1653{
1654 unsigned short index;
1655
Peter Huewea3d675c2012-02-09 21:11:47 +01001656 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001657 index = XGI_GetLCDCapPtr1(pVBInfo);
1658
1659 if (pVBInfo->VBInfo & SetCRT2ToLCD) { /* LCDB */
1660 *di_0 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData1;
1661 *di_1 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData2;
1662 } else { /* LCDA */
1663 *di_0 = pVBInfo->LCDCapList[index].LCDA_VCLKData1;
1664 *di_1 = pVBInfo->LCDCapList[index].LCDA_VCLKData2;
1665 }
1666 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001667}
1668
1669static unsigned char XGI_GetVCLKPtr(unsigned short RefreshRateTableIndex,
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001670 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001671{
1672
1673 unsigned short index, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001674 unsigned char tempal;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001675
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001676 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02001677 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001678
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001679 if ((pVBInfo->SetFlag & ProgrammingCRT2) &&
1680 (!(pVBInfo->LCDInfo & EnableScalingLCD))) { /* {LCDA/LCDB} */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001681 index = XGI_GetLCDCapPtr(pVBInfo);
1682 tempal = pVBInfo->LCDCapList[index].LCD_VCLK;
1683
Peter Huewea3d675c2012-02-09 21:11:47 +01001684 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001685 return tempal;
1686
1687 /* {TV} */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001688 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01001689 (VB_SIS301B |
1690 VB_SIS302B |
1691 VB_SIS301LV |
1692 VB_SIS302LV |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001693 VB_XGI301C)) {
Peter Huewe599801f2012-02-09 21:11:45 +01001694 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001695 tempal = TVCLKBASE_315 + HiTVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001696 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
Peter Hueweccc8cb22012-02-09 21:11:48 +01001697 tempal = TVCLKBASE_315 + HiTVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001698 if (pVBInfo->TVInfo & TVSimuMode) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001699 tempal = TVCLKBASE_315 + HiTVSimuVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001700 if (!(modeflag & Charx8Dot))
Miguel Gómez3bcc2462012-07-06 12:40:53 +02001701 tempal = TVCLKBASE_315 +
1702 HiTVTextVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001703
1704 }
1705 return tempal;
1706 }
1707
Peter Huewe599801f2012-02-09 21:11:45 +01001708 if (pVBInfo->TVInfo & TVSetYPbPr750p) {
Peter Huewea3d675c2012-02-09 21:11:47 +01001709 tempal = XGI_YPbPr750pVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001710 return tempal;
1711 }
1712
Peter Huewe599801f2012-02-09 21:11:45 +01001713 if (pVBInfo->TVInfo & TVSetYPbPr525p) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001714 tempal = YPbPr525pVCLK;
1715 return tempal;
1716 }
1717
1718 tempal = NTSC1024VCLK;
1719
1720 if (!(pVBInfo->TVInfo & NTSC1024x768)) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001721 tempal = TVCLKBASE_315 + TVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001722 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
Peter Hueweccc8cb22012-02-09 21:11:48 +01001723 tempal = TVCLKBASE_315 + TVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001724 }
1725
1726 if (pVBInfo->VBInfo & SetCRT2ToTV)
1727 return tempal;
1728 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001729 } /* {End of VB} */
1730
Peter Huewe516354e2013-02-15 20:37:11 +01001731 inb((pVBInfo->P3ca + 0x02));
Aaro Koskinena39325d2012-11-04 21:14:53 +02001732 tempal = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001733 return tempal;
1734}
1735
1736static void XGI_GetVCLKLen(unsigned char tempal, unsigned char *di_0,
1737 unsigned char *di_1, struct vb_device_info *pVBInfo)
1738{
Peter Huewe6896b942012-02-09 21:11:46 +01001739 if (pVBInfo->VBType & (VB_SIS301 | VB_SIS301B | VB_SIS302B
1740 | VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +02001741 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) &&
1742 (pVBInfo->SetFlag & ProgrammingCRT2)) {
Aaro Koskinene8cb03d2012-09-11 00:15:31 +03001743 *di_0 = XGI_VBVCLKData[tempal].Part4_A;
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +03001744 *di_1 = XGI_VBVCLKData[tempal].Part4_B;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001745 }
1746 } else {
1747 *di_0 = XGI_VCLKData[tempal].SR2B;
1748 *di_1 = XGI_VCLKData[tempal].SR2C;
1749 }
1750}
1751
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001752static void XGI_SetCRT2ECLK(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301753 unsigned short RefreshRateTableIndex,
1754 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001755{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301756 unsigned char di_0, di_1, tempal;
1757 int i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001758
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001759 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeIdIndex, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301760 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
1761 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001762
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301763 for (i = 0; i < 4; i++) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001764 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, ~0x30,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301765 (unsigned short) (0x10 * i));
Peter Huewea3d675c2012-02-09 21:11:47 +01001766 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301767 && (!(pVBInfo->VBInfo & SetInSlaveMode))) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001768 xgifb_reg_set(pVBInfo->P3c4, 0x2e, di_0);
1769 xgifb_reg_set(pVBInfo->P3c4, 0x2f, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301770 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001771 xgifb_reg_set(pVBInfo->P3c4, 0x2b, di_0);
1772 xgifb_reg_set(pVBInfo->P3c4, 0x2c, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301773 }
1774 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001775}
1776
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001777static void XGI_UpdateModeInfo(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301778 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001779{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301780 unsigned short tempcl, tempch, temp, tempbl, tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001781
Peter Huewe6896b942012-02-09 21:11:46 +01001782 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
1783 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301784 tempcl = 0;
1785 tempch = 0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02001786 temp = xgifb_reg_get(pVBInfo->P3c4, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001787
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301788 if (!(temp & 0x20)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001789 temp = xgifb_reg_get(pVBInfo->P3d4, 0x17);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301790 if (temp & 0x80) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001791 temp = xgifb_reg_get(pVBInfo->P3d4, 0x53);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301792 if (!(temp & 0x40))
1793 tempcl |= ActiveCRT1;
1794 }
1795 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001796
Aaro Koskinen58839b02011-03-13 12:26:23 +02001797 temp = xgifb_reg_get(pVBInfo->Part1Port, 0x2e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301798 temp &= 0x0f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001799
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301800 if (!(temp == 0x08)) {
Miguel Gómez949eb0a2012-07-06 12:40:36 +02001801 /* Check ChannelA */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001802 tempax = xgifb_reg_get(pVBInfo->Part1Port, 0x13);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301803 if (tempax & 0x04)
1804 tempcl = tempcl | ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001805
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301806 temp &= 0x05;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001807
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301808 if (!(tempcl & ActiveLCD))
1809 if (temp == 0x01)
1810 tempcl |= ActiveCRT2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001811
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301812 if (temp == 0x04)
1813 tempcl |= ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001814
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301815 if (temp == 0x05) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001816 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001817
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301818 if (!(temp & 0x08))
1819 tempch |= ActiveAVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001820
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301821 if (!(temp & 0x04))
1822 tempch |= ActiveSVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001823
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301824 if (temp & 0x02)
1825 tempch |= ActiveSCART;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001826
Peter Huewe599801f2012-02-09 21:11:45 +01001827 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301828 if (temp & 0x01)
1829 tempch |= ActiveHiTV;
1830 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001831
Peter Huewe599801f2012-02-09 21:11:45 +01001832 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001833 temp = xgifb_reg_get(
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301834 pVBInfo->Part2Port,
1835 0x4d);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001836
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301837 if (temp & 0x10)
1838 tempch |= ActiveYPbPr;
1839 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001840
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301841 if (tempch != 0)
1842 tempcl |= ActiveTV;
1843 }
1844 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001845
Aaro Koskinen58839b02011-03-13 12:26:23 +02001846 temp = xgifb_reg_get(pVBInfo->P3d4, 0x3d);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301847 if (tempcl & ActiveLCD) {
1848 if ((pVBInfo->SetFlag & ReserveTVOption)) {
1849 if (temp & ActiveTV)
1850 tempcl |= ActiveTV;
1851 }
1852 }
1853 temp = tempcl;
Peter Huewea3d675c2012-02-09 21:11:47 +01001854 tempbl = ~XGI_ModeSwitchStatus;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001855 xgifb_reg_and_or(pVBInfo->P3d4, 0x3d, tempbl, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001856
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301857 if (!(pVBInfo->SetFlag & ReserveTVOption))
Aaro Koskinen8104e322011-03-13 12:26:22 +02001858 xgifb_reg_set(pVBInfo->P3d4, 0x3e, tempch);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301859 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001860}
1861
Bill Pemberton80adad82010-06-17 13:10:51 -04001862void XGI_GetVBType(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001863{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301864 unsigned short flag, tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001865
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001866 tempbx = VB_SIS302B;
1867 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
1868 if (flag == 0x02)
1869 goto finish;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001870
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001871 tempbx = VB_SIS301;
1872 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x01);
1873 if (flag < 0xB0)
1874 goto finish;
1875
1876 tempbx = VB_SIS301B;
1877 if (flag < 0xC0)
1878 goto bigger_than_0xB0;
1879
1880 tempbx = VB_XGI301C;
1881 if (flag < 0xD0)
1882 goto bigger_than_0xB0;
1883
1884 tempbx = VB_SIS301LV;
1885 if (flag < 0xE0)
1886 goto bigger_than_0xB0;
1887
1888 tempbx = VB_SIS302LV;
1889 tempah = xgifb_reg_get(pVBInfo->Part4Port, 0x39);
1890 if (tempah != 0xFF)
1891 tempbx = VB_XGI301C;
1892
1893bigger_than_0xB0:
1894 if (tempbx & (VB_SIS301B | VB_SIS302B)) {
1895 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x23);
1896 if (!(flag & 0x02))
1897 tempbx = tempbx | VB_NoLCD;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301898 }
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001899
1900finish:
1901 pVBInfo->VBType = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001902}
1903
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001904static void XGI_GetVBInfo(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301905 struct xgi_hw_device_info *HwDeviceExtension,
1906 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001907{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301908 unsigned short tempax, push, tempbx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001909
Aaro Koskinenb3979922012-11-04 21:14:52 +02001910 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301911 pVBInfo->SetFlag = 0;
Peter Huewe6896b942012-02-09 21:11:46 +01001912 pVBInfo->ModeType = modeflag & ModeTypeMask;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301913 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001914
Miguel Gómezf9317352012-07-06 12:40:48 +02001915 if (!(pVBInfo->VBType & 0xFFFF))
1916 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001917
Miguel Gómezf9317352012-07-06 12:40:48 +02001918 /* Check Display Device */
1919 temp = xgifb_reg_get(pVBInfo->P3d4, 0x30);
1920 tempbx = tempbx | temp;
1921 temp = xgifb_reg_get(pVBInfo->P3d4, 0x31);
1922 push = temp;
1923 push = push << 8;
1924 tempax = temp << 8;
1925 tempbx = tempbx | tempax;
1926 temp = (SetCRT2ToDualEdge | SetCRT2ToYPbPr525750 | XGI_SetCRT2ToLCDA
1927 | SetInSlaveMode | DisableCRT2Display);
1928 temp = 0xFFFF ^ temp;
1929 tempbx &= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001930
Miguel Gómezf9317352012-07-06 12:40:48 +02001931 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001932
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001933 if (pVBInfo->VBType & (VB_SIS302B | VB_SIS301LV | VB_SIS302LV |
1934 VB_XGI301C)) {
1935 if (temp & EnableDualEdge) {
1936 tempbx |= SetCRT2ToDualEdge;
1937 if (temp & SetToLCDA)
1938 tempbx |= XGI_SetCRT2ToLCDA;
Miguel Gómezf9317352012-07-06 12:40:48 +02001939 }
1940 }
1941
Aaro Koskinena4ce0e72013-05-29 23:59:14 +03001942 if (pVBInfo->VBType & (VB_SIS301LV|VB_SIS302LV|VB_XGI301C)) {
1943 if (temp & SetYPbPr) {
Aaro Koskinenaee0ac92013-05-29 23:59:15 +03001944 /* shampoo add for new scratch */
1945 temp = xgifb_reg_get(pVBInfo->P3d4, 0x35);
1946 temp &= YPbPrMode;
1947 tempbx |= SetCRT2ToHiVision;
Miguel Gómezf9317352012-07-06 12:40:48 +02001948
Aaro Koskinenaee0ac92013-05-29 23:59:15 +03001949 if (temp != YPbPrMode1080i) {
1950 tempbx &= (~SetCRT2ToHiVision);
1951 tempbx |= SetCRT2ToYPbPr525750;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301952 }
1953 }
Miguel Gómezf9317352012-07-06 12:40:48 +02001954 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001955
Miguel Gómezf9317352012-07-06 12:40:48 +02001956 tempax = push; /* restore CR31 */
1957
Aaro Koskinenaee0ac92013-05-29 23:59:15 +03001958 temp = 0x09FC;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001959
Miguel Gómezf9317352012-07-06 12:40:48 +02001960 if (!(tempbx & temp)) {
1961 tempax |= DisableCRT2Display;
1962 tempbx = 0;
1963 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001964
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03001965 if (!(pVBInfo->VBType & VB_NoLCD)) {
1966 if (tempbx & XGI_SetCRT2ToLCDA) {
1967 if (tempbx & SetSimuScanMode)
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001968 tempbx &= (~(SetCRT2ToLCD | SetCRT2ToRAMDAC |
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03001969 SwitchCRT2));
1970 else
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001971 tempbx &= (~(SetCRT2ToLCD | SetCRT2ToRAMDAC |
1972 SetCRT2ToTV | SwitchCRT2));
Miguel Gómezf9317352012-07-06 12:40:48 +02001973 }
1974 }
1975
1976 /* shampoo add */
1977 /* for driver abnormal */
1978 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode))) {
Aaro Koskinenee768752013-05-29 23:59:16 +03001979 if (tempbx & SetCRT2ToRAMDAC) {
1980 tempbx &= (0xFF00 | SetCRT2ToRAMDAC |
1981 SwitchCRT2 | SetSimuScanMode);
1982 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301983 }
Miguel Gómezf9317352012-07-06 12:40:48 +02001984 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001985
Miguel Gómezf9317352012-07-06 12:40:48 +02001986 if (!(pVBInfo->VBType & VB_NoLCD)) {
1987 if (tempbx & SetCRT2ToLCD) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001988 tempbx &= (0xFF00 | SetCRT2ToLCD | SwitchCRT2 |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001989 SetSimuScanMode);
Peter Huewe599801f2012-02-09 21:11:45 +01001990 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301991 }
Miguel Gómezf9317352012-07-06 12:40:48 +02001992 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001993
Miguel Gómezf9317352012-07-06 12:40:48 +02001994 if (tempbx & SetCRT2ToSCART) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001995 tempbx &= (0xFF00 | SetCRT2ToSCART | SwitchCRT2 |
Miguel Gómezf9317352012-07-06 12:40:48 +02001996 SetSimuScanMode);
1997 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
1998 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001999
Aaro Koskinena4ce0e72013-05-29 23:59:14 +03002000 if (tempbx & SetCRT2ToYPbPr525750)
2001 tempbx &= (0xFF00 | SwitchCRT2 | SetSimuScanMode);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002002
Aaro Koskinenaee0ac92013-05-29 23:59:15 +03002003 if (tempbx & SetCRT2ToHiVision)
2004 tempbx &= (0xFF00 | SetCRT2ToHiVision | SwitchCRT2 |
2005 SetSimuScanMode);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002006
Miguel Gómezf9317352012-07-06 12:40:48 +02002007 if (tempax & DisableCRT2Display) { /* Set Display Device Info */
2008 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode)))
2009 tempbx = DisableCRT2Display;
2010 }
2011
2012 if (!(tempbx & DisableCRT2Display)) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002013 if ((!(tempbx & DriverMode)) || (!(modeflag & CRT2Mode))) {
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03002014 if (!(tempbx & XGI_SetCRT2ToLCDA))
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002015 tempbx |= (SetInSlaveMode | SetSimuScanMode);
Miguel Gómezf9317352012-07-06 12:40:48 +02002016 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002017
Miguel Gómezf9317352012-07-06 12:40:48 +02002018 /* LCD+TV can't support in slave mode
2019 * (Force LCDA+TV->LCDB) */
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002020 if ((tempbx & SetInSlaveMode) && (tempbx & XGI_SetCRT2ToLCDA)) {
2021 tempbx ^= (SetCRT2ToLCD | XGI_SetCRT2ToLCDA |
Miguel Gómezf9317352012-07-06 12:40:48 +02002022 SetCRT2ToDualEdge);
2023 pVBInfo->SetFlag |= ReserveTVOption;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302024 }
2025 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002026
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302027 pVBInfo->VBInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002028}
2029
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002030static void XGI_GetTVInfo(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302031 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002032{
Peter Huewe5fc699f2013-02-03 04:08:45 +01002033 unsigned short tempbx = 0, resinfo = 0, modeflag, index1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002034
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302035 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinenb3979922012-11-04 21:14:52 +02002036 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2037 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002038
Peter Huewe5fc699f2013-02-03 04:08:45 +01002039 tempbx = xgifb_reg_get(pVBInfo->P3d4, 0x35);
2040 if (tempbx & TVSetPAL) {
2041 tempbx &= (SetCHTVOverScan |
2042 TVSetPALM |
2043 TVSetPALN |
2044 TVSetPAL);
2045 if (tempbx & TVSetPALM)
2046 /* set to NTSC if PAL-M */
2047 tempbx &= ~TVSetPAL;
2048 } else
2049 tempbx &= (SetCHTVOverScan |
2050 TVSetNTSCJ |
2051 TVSetPAL);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002052
Aaro Koskinena8b35292013-02-09 00:03:45 +02002053 if (pVBInfo->VBInfo & SetCRT2ToSCART)
2054 tempbx |= TVSetPAL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002055
Aaro Koskinena4ce0e72013-05-29 23:59:14 +03002056 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
2057 index1 = xgifb_reg_get(pVBInfo->P3d4, 0x35);
2058 index1 &= YPbPrMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002059
Aaro Koskinena4ce0e72013-05-29 23:59:14 +03002060 if (index1 == YPbPrMode525i)
2061 tempbx |= TVSetYPbPr525i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002062
Aaro Koskinena4ce0e72013-05-29 23:59:14 +03002063 if (index1 == YPbPrMode525p)
2064 tempbx = tempbx | TVSetYPbPr525p;
2065 if (index1 == YPbPrMode750p)
2066 tempbx = tempbx | TVSetYPbPr750p;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302067 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002068
Aaro Koskinenaee0ac92013-05-29 23:59:15 +03002069 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
2070 tempbx = tempbx | TVSetHiVision | TVSetPAL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002071
Aaro Koskinena8b35292013-02-09 00:03:45 +02002072 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
2073 (!(pVBInfo->VBInfo & SetNotSimuMode)))
2074 tempbx |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002075
Aaro Koskinena8b35292013-02-09 00:03:45 +02002076 if (!(tempbx & TVSetPAL) && (modeflag > 13) && (resinfo == 8))
2077 /* NTSC 1024x768, */
2078 tempbx |= NTSC1024x768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002079
Aaro Koskinena8b35292013-02-09 00:03:45 +02002080 tempbx |= RPLLDIV2XO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002081
Aaro Koskinena8b35292013-02-09 00:03:45 +02002082 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
2083 if (pVBInfo->VBInfo & SetInSlaveMode)
2084 tempbx &= (~RPLLDIV2XO);
2085 } else if (tempbx & (TVSetYPbPr525p | TVSetYPbPr750p)) {
2086 tempbx &= (~RPLLDIV2XO);
2087 } else if (!(pVBInfo->VBType & (VB_SIS301B | VB_SIS302B |
2088 VB_SIS301LV | VB_SIS302LV |
2089 VB_XGI301C))) {
2090 if (tempbx & TVSimuMode)
2091 tempbx &= (~RPLLDIV2XO);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302092 }
2093 }
2094 pVBInfo->TVInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002095}
2096
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002097static unsigned char XGI_GetLCDInfo(unsigned short ModeIdIndex,
2098 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002099{
Peter Hueweef9a6b92013-02-03 04:08:43 +01002100 unsigned short temp, tempax, tempbx, resinfo = 0, LCDIdIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002101
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302102 pVBInfo->LCDResInfo = 0;
2103 pVBInfo->LCDTypeInfo = 0;
2104 pVBInfo->LCDInfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002105
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002106 /* si+Ext_ResInfo // */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002107 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinen58839b02011-03-13 12:26:23 +02002108 temp = xgifb_reg_get(pVBInfo->P3d4, 0x36); /* Get LCD Res.Info */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302109 tempbx = temp & 0x0F;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002110
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302111 if (tempbx == 0)
Peter Huewe255aabd2012-02-09 21:11:44 +01002112 tempbx = Panel_1024x768; /* default */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002113
Miguel Gómez949eb0a2012-07-06 12:40:36 +02002114 /* LCD75 */
Peter Huewe255aabd2012-02-09 21:11:44 +01002115 if ((tempbx == Panel_1024x768) || (tempbx == Panel_1280x1024)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302116 if (pVBInfo->VBInfo & DriverMode) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002117 tempax = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Peter Huewea3d675c2012-02-09 21:11:47 +01002118 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302119 tempax &= 0x0F;
2120 else
2121 tempax = tempax >> 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002122
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302123 if ((resinfo == 6) || (resinfo == 9)) {
2124 if (tempax >= 3)
2125 tempbx |= PanelRef75Hz;
2126 } else if ((resinfo == 7) || (resinfo == 8)) {
2127 if (tempax >= 4)
2128 tempbx |= PanelRef75Hz;
2129 }
2130 }
2131 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002132
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302133 pVBInfo->LCDResInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002134
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302135 /* End of LCD75 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002136
Peter Huewea3d675c2012-02-09 21:11:47 +01002137 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302138 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002139
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302140 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002141
Aaro Koskinen58839b02011-03-13 12:26:23 +02002142 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002143
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302144 temp &= (ScalingLCD | LCDNonExpanding | LCDSyncBit | SetPWDEnable);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002145
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302146 tempbx |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002147
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302148 LCDIdIndex = XGI_GetLCDCapPtr1(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002149
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302150 tempax = pVBInfo->LCDCapList[LCDIdIndex].LCD_Capability;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002151
Aaro Koskinen718e7152013-02-09 00:03:46 +02002152 if (((pVBInfo->VBType & VB_SIS302LV) ||
2153 (pVBInfo->VBType & VB_XGI301C)) && (tempax & XGI_LCDDualLink))
2154 tempbx |= SetLCDDualLink;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002155
Aaro Koskinen718e7152013-02-09 00:03:46 +02002156 if ((pVBInfo->LCDResInfo == Panel_1400x1050) &&
2157 (pVBInfo->VBInfo & SetCRT2ToLCD) && (resinfo == 9) &&
2158 (!(tempbx & EnableScalingLCD)))
2159 /*
2160 * set to center in 1280x1024 LCDB
2161 * for Panel_1400x1050
2162 */
2163 tempbx |= SetLCDtoNonExpanding;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002164
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302165 if (pVBInfo->VBInfo & SetInSlaveMode) {
2166 if (pVBInfo->VBInfo & SetNotSimuMode)
Peter Huewea3d675c2012-02-09 21:11:47 +01002167 tempbx |= XGI_LCDVESATiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302168 } else {
Peter Huewea3d675c2012-02-09 21:11:47 +01002169 tempbx |= XGI_LCDVESATiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302170 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002171
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302172 pVBInfo->LCDInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002173
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302174 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002175}
2176
Bill Pemberton108afbf2010-06-17 13:10:47 -04002177unsigned char XGI_SearchModeID(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302178 unsigned short *ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002179{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002180 for (*ModeIdIndex = 0;; (*ModeIdIndex)++) {
Aaro Koskinenb3979922012-11-04 21:14:52 +02002181 if (XGI330_EModeIDTable[*ModeIdIndex].Ext_ModeID == ModeNo)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002182 break;
Aaro Koskinenb3979922012-11-04 21:14:52 +02002183 if (XGI330_EModeIDTable[*ModeIdIndex].Ext_ModeID == 0xFF)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002184 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302185 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002186
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302187 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002188}
2189
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002190static unsigned char XG21GPIODataTransfer(unsigned char ujDate)
2191{
2192 unsigned char ujRet = 0;
2193 unsigned char i = 0;
2194
2195 for (i = 0; i < 8; i++) {
2196 ujRet = ujRet << 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002197 ujRet |= (ujDate >> i) & 1;
2198 }
2199
2200 return ujRet;
2201}
2202
2203/*----------------------------------------------------------------------------*/
2204/* output */
2205/* bl[5] : LVDS signal */
2206/* bl[1] : LVDS backlight */
2207/* bl[0] : LVDS VDD */
2208/*----------------------------------------------------------------------------*/
2209static unsigned char XGI_XG21GetPSCValue(struct vb_device_info *pVBInfo)
2210{
2211 unsigned char CR4A, temp;
2212
Aaro Koskinen58839b02011-03-13 12:26:23 +02002213 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02002214 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x23); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002215
Aaro Koskinen58839b02011-03-13 12:26:23 +02002216 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002217
2218 temp = XG21GPIODataTransfer(temp);
2219 temp &= 0x23;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002220 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002221 return temp;
2222}
2223
2224/*----------------------------------------------------------------------------*/
2225/* output */
2226/* bl[5] : LVDS signal */
2227/* bl[1] : LVDS backlight */
2228/* bl[0] : LVDS VDD */
2229/*----------------------------------------------------------------------------*/
2230static unsigned char XGI_XG27GetPSCValue(struct vb_device_info *pVBInfo)
2231{
2232 unsigned char CR4A, CRB4, temp;
2233
Aaro Koskinen58839b02011-03-13 12:26:23 +02002234 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02002235 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x0C); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002236
Aaro Koskinen58839b02011-03-13 12:26:23 +02002237 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002238
2239 temp &= 0x0C;
2240 temp >>= 2;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002241 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinen58839b02011-03-13 12:26:23 +02002242 CRB4 = xgifb_reg_get(pVBInfo->P3d4, 0xB4);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002243 temp |= ((CRB4 & 0x04) << 3);
2244 return temp;
2245}
2246
Aaro Koskinen0ebf5382011-11-27 23:03:09 +02002247/*----------------------------------------------------------------------------*/
2248/* input */
2249/* bl[5] : 1;LVDS signal on */
2250/* bl[1] : 1;LVDS backlight on */
2251/* bl[0] : 1:LVDS VDD on */
2252/* bh: 100000b : clear bit 5, to set bit5 */
2253/* 000010b : clear bit 1, to set bit1 */
2254/* 000001b : clear bit 0, to set bit0 */
2255/*----------------------------------------------------------------------------*/
2256static void XGI_XG21BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
2257 struct vb_device_info *pVBInfo)
2258{
2259 unsigned char CR4A, temp;
2260
2261 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
2262 tempbh &= 0x23;
2263 tempbl &= 0x23;
2264 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
2265
2266 if (tempbh & 0x20) {
2267 temp = (tempbl >> 4) & 0x02;
2268
2269 /* CR B4[1] */
2270 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
2271
2272 }
2273
2274 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
2275
2276 temp = XG21GPIODataTransfer(temp);
2277 temp &= ~tempbh;
2278 temp |= tempbl;
2279 xgifb_reg_set(pVBInfo->P3d4, 0x48, temp);
2280}
2281
Aaro Koskinen776115a2011-11-27 23:03:10 +02002282static void XGI_XG27BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
2283 struct vb_device_info *pVBInfo)
2284{
2285 unsigned char CR4A, temp;
2286 unsigned short tempbh0, tempbl0;
2287
2288 tempbh0 = tempbh;
2289 tempbl0 = tempbl;
2290 tempbh0 &= 0x20;
2291 tempbl0 &= 0x20;
2292 tempbh0 >>= 3;
2293 tempbl0 >>= 3;
2294
2295 if (tempbh & 0x20) {
2296 temp = (tempbl >> 4) & 0x02;
2297
2298 /* CR B4[1] */
2299 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
2300
2301 }
2302 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~tempbh0, tempbl0);
2303
2304 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
2305 tempbh &= 0x03;
2306 tempbl &= 0x03;
2307 tempbh <<= 2;
2308 tempbl <<= 2; /* GPIOC,GPIOD */
2309 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
2310 xgifb_reg_and_or(pVBInfo->P3d4, 0x48, ~tempbh, tempbl);
2311}
2312
Aaro Koskinenfab04b92011-12-06 00:10:45 +02002313static void XGI_DisplayOn(struct xgifb_video_info *xgifb_info,
2314 struct xgi_hw_device_info *pXGIHWDE,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302315 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002316{
2317
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002318 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302319 if (pXGIHWDE->jChipType == XG21) {
2320 if (pVBInfo->IF_DEF_LVDS == 1) {
2321 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002322 /* LVDS VDD on */
2323 XGI_XG21BLSignalVDD(0x01, 0x01, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002324 mdelay(xgifb_info->lvds_data.PSC_S2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302325 }
2326 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002327 /* LVDS signal on */
2328 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002329 mdelay(xgifb_info->lvds_data.PSC_S3);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002330 /* LVDS backlight on */
2331 XGI_XG21BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302332 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002333 /* DVO/DVI signal on */
2334 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302335 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002336
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302337 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002338
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302339 if (pXGIHWDE->jChipType == XG27) {
2340 if (pVBInfo->IF_DEF_LVDS == 1) {
2341 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002342 /* LVDS VDD on */
2343 XGI_XG27BLSignalVDD(0x01, 0x01, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002344 mdelay(xgifb_info->lvds_data.PSC_S2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302345 }
2346 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002347 /* LVDS signal on */
2348 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002349 mdelay(xgifb_info->lvds_data.PSC_S3);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002350 /* LVDS backlight on */
2351 XGI_XG27BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302352 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002353 /* DVO/DVI signal on */
2354 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302355 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002356
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302357 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002358}
2359
Aaro Koskinenfab04b92011-12-06 00:10:45 +02002360void XGI_DisplayOff(struct xgifb_video_info *xgifb_info,
2361 struct xgi_hw_device_info *pXGIHWDE,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302362 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002363{
2364
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302365 if (pXGIHWDE->jChipType == XG21) {
2366 if (pVBInfo->IF_DEF_LVDS == 1) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002367 /* LVDS backlight off */
2368 XGI_XG21BLSignalVDD(0x02, 0x00, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002369 mdelay(xgifb_info->lvds_data.PSC_S3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302370 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002371 /* DVO/DVI signal off */
2372 XGI_XG21BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302373 }
2374 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002375
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302376 if (pXGIHWDE->jChipType == XG27) {
2377 if ((XGI_XG27GetPSCValue(pVBInfo) & 0x2)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002378 /* LVDS backlight off */
2379 XGI_XG27BLSignalVDD(0x02, 0x00, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002380 mdelay(xgifb_info->lvds_data.PSC_S3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302381 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002382
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302383 if (pVBInfo->IF_DEF_LVDS == 0)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002384 /* DVO/DVI signal off */
2385 XGI_XG27BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302386 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002387
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002388 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x20);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002389}
2390
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002391static void XGI_WaitDisply(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002392{
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02002393 while ((inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302394 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002395
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02002396 while (!(inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302397 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002398}
2399
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002400static void XGI_AutoThreshold(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002401{
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002402 xgifb_reg_or(pVBInfo->Part1Port, 0x01, 0x40);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002403}
2404
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002405static void XGI_SaveCRT2Info(unsigned short ModeNo,
2406 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002407{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302408 unsigned short temp1, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002409
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002410 /* reserve CR34 for CRT1 Mode No */
2411 xgifb_reg_set(pVBInfo->P3d4, 0x34, ModeNo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302412 temp1 = (pVBInfo->VBInfo & SetInSlaveMode) >> 8;
2413 temp2 = ~(SetInSlaveMode >> 8);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002414 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, temp2, temp1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002415}
2416
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002417static void XGI_GetCRT2ResInfo(unsigned short ModeIdIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002418 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002419{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302420 unsigned short xres, yres, modeflag, resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002421
Aaro Koskinenb3979922012-11-04 21:14:52 +02002422 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02002423 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
2424 yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002425 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002426 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002427
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002428 if (modeflag & HalfDCLK)
2429 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002430
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002431 if (modeflag & DoubleScanMode)
2432 yres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002433
Miguel Gómez3339db82012-07-06 12:40:49 +02002434 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
2435 goto exit;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002436
Aaro Koskinen22006832013-02-09 00:03:47 +02002437 if (pVBInfo->LCDResInfo == Panel_1600x1200) {
2438 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
2439 if (yres == 1024)
2440 yres = 1056;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302441 }
Aaro Koskinen22006832013-02-09 00:03:47 +02002442 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002443
Aaro Koskinen22006832013-02-09 00:03:47 +02002444 if (pVBInfo->LCDResInfo == Panel_1280x1024) {
2445 if (yres == 400)
2446 yres = 405;
2447 else if (yres == 350)
2448 yres = 360;
Miguel Gómez3339db82012-07-06 12:40:49 +02002449
Aaro Koskinen22006832013-02-09 00:03:47 +02002450 if (pVBInfo->LCDInfo & XGI_LCDVESATiming) {
2451 if (yres == 360)
2452 yres = 375;
Miguel Gómez3339db82012-07-06 12:40:49 +02002453 }
Aaro Koskinen22006832013-02-09 00:03:47 +02002454 }
Miguel Gómez3339db82012-07-06 12:40:49 +02002455
Aaro Koskinen22006832013-02-09 00:03:47 +02002456 if (pVBInfo->LCDResInfo == Panel_1024x768) {
2457 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
2458 if (!(pVBInfo->LCDInfo & LCDNonExpanding)) {
2459 if (yres == 350)
2460 yres = 357;
2461 else if (yres == 400)
2462 yres = 420;
2463 else if (yres == 480)
2464 yres = 525;
Miguel Gómez3339db82012-07-06 12:40:49 +02002465 }
2466 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302467 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002468
Miguel Gómez3339db82012-07-06 12:40:49 +02002469 if (xres == 720)
2470 xres = 640;
2471
2472exit:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302473 pVBInfo->VGAHDE = xres;
2474 pVBInfo->HDE = xres;
2475 pVBInfo->VGAVDE = yres;
2476 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002477}
2478
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002479static unsigned char XGI_IsLCDDualLink(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002480{
2481
Peter Huewea3d675c2012-02-09 21:11:47 +01002482 if ((pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) &&
Dan Carpentera65fd092011-01-04 09:02:27 +03002483 (pVBInfo->LCDInfo & SetLCDDualLink)) /* shampoo0129 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302484 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002485
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302486 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002487}
2488
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002489static void XGI_GetRAMDAC2DATA(unsigned short ModeIdIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002490 unsigned short RefreshRateTableIndex,
2491 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002492{
2493 unsigned short tempax, tempbx, temp1, temp2, modeflag = 0, tempcx,
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002494 CRT1Index;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002495
2496 pVBInfo->RVBHCMAX = 1;
2497 pVBInfo->RVBHCFACT = 1;
Aaro Koskinenb3979922012-11-04 21:14:52 +02002498 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02002499 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002500 CRT1Index &= IndexMask;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002501 temp1 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[0];
2502 temp2 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[5];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002503 tempax = (temp1 & 0xFF) | ((temp2 & 0x03) << 8);
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002504 tempbx = (unsigned short) XGI_CRT1Table[CRT1Index].CR[8];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002505 tempcx = (unsigned short)
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002506 XGI_CRT1Table[CRT1Index].CR[14] << 8;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002507 tempcx &= 0x0100;
2508 tempcx = tempcx << 2;
2509 tempbx |= tempcx;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002510 temp1 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[9];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002511
2512 if (temp1 & 0x01)
2513 tempbx |= 0x0100;
2514
2515 if (temp1 & 0x20)
2516 tempbx |= 0x0200;
2517 tempax += 5;
2518
2519 if (modeflag & Charx8Dot)
2520 tempax *= 8;
2521 else
2522 tempax *= 9;
2523
2524 pVBInfo->VGAHT = tempax;
2525 pVBInfo->HT = tempax;
2526 tempbx++;
2527 pVBInfo->VGAVT = tempbx;
2528 pVBInfo->VT = tempbx;
2529}
2530
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002531static void XGI_GetCRT2Data(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302532 unsigned short RefreshRateTableIndex,
2533 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002534{
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02002535 unsigned short tempax = 0, tempbx = 0, modeflag, resinfo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002536
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02002537 struct SiS_LCDData const *LCDPtr = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002538
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002539 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002540 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2541 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302542 pVBInfo->NewFlickerMode = 0;
2543 pVBInfo->RVBHRS = 50;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002544
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302545 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002546 XGI_GetRAMDAC2DATA(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302547 return;
2548 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002549
Peter Huewea3d675c2012-02-09 21:11:47 +01002550 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002551 LCDPtr = XGI_GetLcdPtr(XGI_LCDDataTable, ModeIdIndex,
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +03002552 RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002553
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302554 pVBInfo->RVBHCMAX = LCDPtr->RVBHCMAX;
2555 pVBInfo->RVBHCFACT = LCDPtr->RVBHCFACT;
2556 pVBInfo->VGAHT = LCDPtr->VGAHT;
2557 pVBInfo->VGAVT = LCDPtr->VGAVT;
2558 pVBInfo->HT = LCDPtr->LCDHT;
2559 pVBInfo->VT = LCDPtr->LCDVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002560
Peter Huewe255aabd2012-02-09 21:11:44 +01002561 if (pVBInfo->LCDResInfo == Panel_1024x768) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302562 tempax = 1024;
2563 tempbx = 768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002564
Peter Huewea3d675c2012-02-09 21:11:47 +01002565 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302566 if (pVBInfo->VGAVDE == 357)
2567 tempbx = 527;
2568 else if (pVBInfo->VGAVDE == 420)
2569 tempbx = 620;
2570 else if (pVBInfo->VGAVDE == 525)
2571 tempbx = 775;
2572 else if (pVBInfo->VGAVDE == 600)
2573 tempbx = 775;
Peter Huewe7580d7f2013-05-18 00:19:54 +02002574 }
Peter Huewe255aabd2012-02-09 21:11:44 +01002575 } else if (pVBInfo->LCDResInfo == Panel_1024x768x75) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302576 tempax = 1024;
2577 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01002578 } else if (pVBInfo->LCDResInfo == Panel_1280x1024) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302579 tempax = 1280;
2580 if (pVBInfo->VGAVDE == 360)
2581 tempbx = 768;
2582 else if (pVBInfo->VGAVDE == 375)
2583 tempbx = 800;
2584 else if (pVBInfo->VGAVDE == 405)
2585 tempbx = 864;
2586 else
2587 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01002588 } else if (pVBInfo->LCDResInfo == Panel_1280x1024x75) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302589 tempax = 1280;
2590 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01002591 } else if (pVBInfo->LCDResInfo == Panel_1280x960) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302592 tempax = 1280;
2593 if (pVBInfo->VGAVDE == 350)
2594 tempbx = 700;
2595 else if (pVBInfo->VGAVDE == 400)
2596 tempbx = 800;
2597 else if (pVBInfo->VGAVDE == 1024)
2598 tempbx = 960;
2599 else
2600 tempbx = 960;
Peter Huewe255aabd2012-02-09 21:11:44 +01002601 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302602 tempax = 1400;
2603 tempbx = 1050;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002604
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302605 if (pVBInfo->VGAVDE == 1024) {
2606 tempax = 1280;
2607 tempbx = 1024;
2608 }
Peter Huewe255aabd2012-02-09 21:11:44 +01002609 } else if (pVBInfo->LCDResInfo == Panel_1600x1200) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302610 tempax = 1600;
2611 tempbx = 1200; /* alan 10/14/2003 */
Peter Huewea3d675c2012-02-09 21:11:47 +01002612 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302613 if (pVBInfo->VGAVDE == 350)
2614 tempbx = 875;
2615 else if (pVBInfo->VGAVDE == 400)
2616 tempbx = 1000;
2617 }
2618 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002619
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302620 if (pVBInfo->LCDInfo & LCDNonExpanding) {
2621 tempax = pVBInfo->VGAHDE;
2622 tempbx = pVBInfo->VGAVDE;
2623 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002624
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302625 pVBInfo->HDE = tempax;
2626 pVBInfo->VDE = tempbx;
2627 return;
2628 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002629
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302630 if (pVBInfo->VBInfo & (SetCRT2ToTV)) {
Aaro Koskinen24572542012-09-11 00:15:21 +03002631 struct SiS_TVData const *TVPtr;
2632
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002633 TVPtr = XGI_GetTVPtr(ModeIdIndex, RefreshRateTableIndex,
Aaro Koskinen24572542012-09-11 00:15:21 +03002634 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002635
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302636 pVBInfo->RVBHCMAX = TVPtr->RVBHCMAX;
2637 pVBInfo->RVBHCFACT = TVPtr->RVBHCFACT;
2638 pVBInfo->VGAHT = TVPtr->VGAHT;
2639 pVBInfo->VGAVT = TVPtr->VGAVT;
2640 pVBInfo->HDE = TVPtr->TVHDE;
2641 pVBInfo->VDE = TVPtr->TVVDE;
2642 pVBInfo->RVBHRS = TVPtr->RVBHRS;
2643 pVBInfo->NewFlickerMode = TVPtr->FlickerMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002644
Peter Huewe599801f2012-02-09 21:11:45 +01002645 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302646 if (resinfo == 0x08)
2647 pVBInfo->NewFlickerMode = 0x40;
2648 else if (resinfo == 0x09)
2649 pVBInfo->NewFlickerMode = 0x40;
2650 else if (resinfo == 0x12)
2651 pVBInfo->NewFlickerMode = 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002652
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302653 if (pVBInfo->VGAVDE == 350)
2654 pVBInfo->TVInfo |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002655
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302656 tempax = ExtHiTVHT;
2657 tempbx = ExtHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002658
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302659 if (pVBInfo->VBInfo & SetInSlaveMode) {
2660 if (pVBInfo->TVInfo & TVSimuMode) {
2661 tempax = StHiTVHT;
2662 tempbx = StHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002663
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302664 if (!(modeflag & Charx8Dot)) {
2665 tempax = StHiTextTVHT;
2666 tempbx = StHiTextTVVT;
2667 }
2668 }
2669 }
Peter Huewe599801f2012-02-09 21:11:45 +01002670 } else if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
2671 if (pVBInfo->TVInfo & TVSetYPbPr750p) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302672 tempax = YPbPrTV750pHT; /* Ext750pTVHT */
2673 tempbx = YPbPrTV750pVT; /* Ext750pTVVT */
2674 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002675
Peter Huewe599801f2012-02-09 21:11:45 +01002676 if (pVBInfo->TVInfo & TVSetYPbPr525p) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302677 tempax = YPbPrTV525pHT; /* Ext525pTVHT */
2678 tempbx = YPbPrTV525pVT; /* Ext525pTVVT */
Peter Huewe599801f2012-02-09 21:11:45 +01002679 } else if (pVBInfo->TVInfo & TVSetYPbPr525i) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302680 tempax = YPbPrTV525iHT; /* Ext525iTVHT */
2681 tempbx = YPbPrTV525iVT; /* Ext525iTVVT */
2682 if (pVBInfo->TVInfo & NTSC1024x768)
2683 tempax = NTSC1024x768HT;
2684 }
2685 } else {
2686 tempax = PALHT;
2687 tempbx = PALVT;
Peter Huewe599801f2012-02-09 21:11:45 +01002688 if (!(pVBInfo->TVInfo & TVSetPAL)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302689 tempax = NTSCHT;
2690 tempbx = NTSCVT;
2691 if (pVBInfo->TVInfo & NTSC1024x768)
2692 tempax = NTSC1024x768HT;
2693 }
2694 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002695
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302696 pVBInfo->HT = tempax;
2697 pVBInfo->VT = tempbx;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302698 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002699}
2700
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002701static void XGI_SetCRT2VCLK(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302702 unsigned short RefreshRateTableIndex,
2703 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002704{
Bill Pemberton108afbf2010-06-17 13:10:47 -04002705 unsigned char di_0, di_1, tempal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002706
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002707 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeIdIndex, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302708 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
2709 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002710
Peter Huewe6896b942012-02-09 21:11:46 +01002711 if (pVBInfo->VBType & VB_SIS301) { /* shampoo 0129 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302712 /* 301 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002713 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, 0x10);
2714 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
2715 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302716 } else { /* 301b/302b/301lv/302lv */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002717 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
2718 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302719 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002720
Aaro Koskinen8104e322011-03-13 12:26:22 +02002721 xgifb_reg_set(pVBInfo->Part4Port, 0x00, 0x12);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002722
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302723 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02002724 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x28);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302725 else
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02002726 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002727}
2728
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002729static unsigned short XGI_GetColorDepth(unsigned short ModeIdIndex,
2730 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002731{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002732 unsigned short ColorDepth[6] = { 1, 2, 4, 4, 6, 8 };
2733 short index;
2734 unsigned short modeflag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302735
Aaro Koskinenb3979922012-11-04 21:14:52 +02002736 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Peter Huewe6896b942012-02-09 21:11:46 +01002737 index = (modeflag & ModeTypeMask) - ModeEGA;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302738
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002739 if (index < 0)
2740 index = 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302741
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002742 return ColorDepth[index];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302743}
2744
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002745static unsigned short XGI_GetOffset(unsigned short ModeNo,
2746 unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302747 unsigned short RefreshRateTableIndex,
2748 struct xgi_hw_device_info *HwDeviceExtension,
2749 struct vb_device_info *pVBInfo)
2750{
2751 unsigned short temp, colordepth, modeinfo, index, infoflag,
2752 ColorDepth[] = { 0x01, 0x02, 0x04 };
2753
Aaro Koskinenb3979922012-11-04 21:14:52 +02002754 modeinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeInfo;
Aaro Koskinena39325d2012-11-04 21:14:53 +02002755 infoflag = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302756
2757 index = (modeinfo >> 8) & 0xFF;
2758
Aaro Koskinen224114c2012-11-04 21:14:59 +02002759 temp = XGI330_ScreenOffset[index];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302760
2761 if (infoflag & InterlaceMode)
2762 temp = temp << 1;
2763
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002764 colordepth = XGI_GetColorDepth(ModeIdIndex, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302765
2766 if ((ModeNo >= 0x7C) && (ModeNo <= 0x7E)) {
2767 temp = ModeNo - 0x7C;
2768 colordepth = ColorDepth[temp];
2769 temp = 0x6B;
2770 if (infoflag & InterlaceMode)
2771 temp = temp << 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302772 }
Peter Huewe053004b2013-02-15 20:37:12 +01002773 return temp * colordepth;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302774}
2775
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002776static void XGI_SetCRT2Offset(unsigned short ModeNo,
2777 unsigned short ModeIdIndex,
2778 unsigned short RefreshRateTableIndex,
2779 struct xgi_hw_device_info *HwDeviceExtension,
2780 struct vb_device_info *pVBInfo)
2781{
2782 unsigned short offset;
2783 unsigned char temp;
2784
2785 if (pVBInfo->VBInfo & SetInSlaveMode)
2786 return;
2787
2788 offset = XGI_GetOffset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
2789 HwDeviceExtension, pVBInfo);
2790 temp = (unsigned char) (offset & 0xFF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002791 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002792 temp = (unsigned char) ((offset & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002793 xgifb_reg_set(pVBInfo->Part1Port, 0x09, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002794 temp = (unsigned char) (((offset >> 3) & 0xFF) + 1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002795 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002796}
2797
Randy Dunlap89229672010-08-10 08:46:44 -07002798static void XGI_SetCRT2FIFO(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002799{
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002800 /* threshold high ,disable auto threshold */
2801 xgifb_reg_set(pVBInfo->Part1Port, 0x01, 0x3B);
2802 /* threshold low default 04h */
2803 xgifb_reg_and_or(pVBInfo->Part1Port, 0x02, ~(0x3F), 0x04);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002804}
2805
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002806static void XGI_PreSetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302807 struct xgi_hw_device_info *HwDeviceExtension,
2808 unsigned short RefreshRateTableIndex,
2809 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002810{
Peter Hueweef9a6b92013-02-03 04:08:43 +01002811 u8 tempcx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002812
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302813 XGI_SetCRT2Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
2814 HwDeviceExtension, pVBInfo);
2815 XGI_SetCRT2FIFO(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002816
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302817 for (tempcx = 4; tempcx < 7; tempcx++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02002818 xgifb_reg_set(pVBInfo->Part1Port, tempcx, 0x0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002819
Aaro Koskinen8104e322011-03-13 12:26:22 +02002820 xgifb_reg_set(pVBInfo->Part1Port, 0x50, 0x00);
2821 xgifb_reg_set(pVBInfo->Part1Port, 0x02, 0x44); /* temp 0206 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002822}
2823
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002824static void XGI_SetGroup1(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302825 struct xgi_hw_device_info *HwDeviceExtension,
2826 unsigned short RefreshRateTableIndex,
2827 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002828{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302829 unsigned short temp = 0, tempax = 0, tempbx = 0, tempcx = 0,
Peter Hueweef9a6b92013-02-03 04:08:43 +01002830 pushbx = 0, CRT1Index, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002831
Aaro Koskinena39325d2012-11-04 21:14:53 +02002832 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002833 CRT1Index &= IndexMask;
Aaro Koskinenb3979922012-11-04 21:14:52 +02002834 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002835
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302836 /* bainy change table name */
2837 if (modeflag & HalfDCLK) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002838 /* BTVGA2HT 0x08,0x09 */
2839 temp = (pVBInfo->VGAHT / 2 - 1) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002840 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302841 temp = (((pVBInfo->VGAHT / 2 - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002842 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002843 /* BTVGA2HDEE 0x0A,0x0C */
2844 temp = (pVBInfo->VGAHDE / 2 + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002845 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302846 tempcx = ((pVBInfo->VGAHT - pVBInfo->VGAHDE) / 2) >> 2;
2847 pushbx = pVBInfo->VGAHDE / 2 + 16;
2848 tempcx = tempcx >> 1;
2849 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
2850 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002851
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302852 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002853 tempbx = XGI_CRT1Table[CRT1Index].CR[4];
2854 tempbx |= ((XGI_CRT1Table[CRT1Index].CR[14] &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002855 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302856 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002857 tempcx = XGI_CRT1Table[CRT1Index].CR[5];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302858 tempcx &= 0x1F;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002859 temp = XGI_CRT1Table[CRT1Index].CR[15];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302860 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
2861 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
2862 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002863
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302864 tempbx += 4;
2865 tempcx += 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002866
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302867 if (tempcx > (pVBInfo->VGAHT / 2))
2868 tempcx = pVBInfo->VGAHT / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002869
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302870 temp = tempbx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002871
Aaro Koskinen8104e322011-03-13 12:26:22 +02002872 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302873 } else {
2874 temp = (pVBInfo->VGAHT - 1) & 0x0FF; /* BTVGA2HT 0x08,0x09 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002875 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302876 temp = (((pVBInfo->VGAHT - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002877 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002878 /* BTVGA2HDEE 0x0A,0x0C */
2879 temp = (pVBInfo->VGAHDE + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002880 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302881 tempcx = (pVBInfo->VGAHT - pVBInfo->VGAHDE) >> 2; /* cx */
2882 pushbx = pVBInfo->VGAHDE + 16;
2883 tempcx = tempcx >> 1;
2884 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
2885 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002886
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302887 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002888 tempbx = XGI_CRT1Table[CRT1Index].CR[3];
2889 tempbx |= ((XGI_CRT1Table[CRT1Index].CR[5] &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002890 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302891 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002892 tempcx = XGI_CRT1Table[CRT1Index].CR[4];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302893 tempcx &= 0x1F;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002894 temp = XGI_CRT1Table[CRT1Index].CR[6];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302895 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
2896 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
2897 tempbx += 16;
2898 tempcx += 16;
2899 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002900
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302901 if (tempcx > pVBInfo->VGAHT)
2902 tempcx = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002903
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302904 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002905 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302906 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002907
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302908 tempax = (tempax & 0x00FF) | (tempbx & 0xFF00);
2909 tempbx = pushbx;
2910 tempbx = (tempbx & 0x00FF) | ((tempbx & 0xFF00) << 4);
2911 tempax |= (tempbx & 0xFF00);
2912 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002913 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302914 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002915 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302916 tempcx = (pVBInfo->VGAVT - 1);
2917 temp = tempcx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002918
Aaro Koskinen8104e322011-03-13 12:26:22 +02002919 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302920 tempbx = pVBInfo->VGAVDE - 1;
2921 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002922 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302923 temp = ((tempbx & 0xFF00) << 3) >> 8;
2924 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002925 xgifb_reg_set(pVBInfo->Part1Port, 0x12, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002926
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002927 /* BTVGA2VRS 0x10,0x11 */
2928 tempbx = (pVBInfo->VGAVT + pVBInfo->VGAVDE) >> 1;
2929 /* BTVGA2VRE 0x11 */
2930 tempcx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) >> 4) + tempbx + 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002931
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302932 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002933 tempbx = XGI_CRT1Table[CRT1Index].CR[10];
2934 temp = XGI_CRT1Table[CRT1Index].CR[9];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002935
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302936 if (temp & 0x04)
2937 tempbx |= 0x0100;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002938
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302939 if (temp & 0x080)
2940 tempbx |= 0x0200;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002941
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002942 temp = XGI_CRT1Table[CRT1Index].CR[14];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002943
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302944 if (temp & 0x08)
2945 tempbx |= 0x0400;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002946
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002947 temp = XGI_CRT1Table[CRT1Index].CR[11];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302948 tempcx = (tempcx & 0xFF00) | (temp & 0x00FF);
2949 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002950
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302951 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002952 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302953 temp = ((tempbx & 0xFF00) >> 8) << 4;
2954 temp = ((tempcx & 0x000F) | (temp));
Aaro Koskinen8104e322011-03-13 12:26:22 +02002955 xgifb_reg_set(pVBInfo->Part1Port, 0x11, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302956 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002957
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302958 if (modeflag & DoubleScanMode)
2959 tempax |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002960
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302961 if (modeflag & HalfDCLK)
2962 tempax |= 0x40;
2963
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002964 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2C, ~0x0C0, tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002965}
2966
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002967static unsigned short XGI_GetVGAHT2(struct vb_device_info *pVBInfo)
2968{
2969 unsigned long tempax, tempbx;
2970
2971 tempbx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) * pVBInfo->RVBHCMAX)
2972 & 0xFFFF;
2973 tempax = (pVBInfo->VT - pVBInfo->VDE) * pVBInfo->RVBHCFACT;
2974 tempax = (tempax * pVBInfo->HT) / tempbx;
2975
2976 return (unsigned short) tempax;
2977}
2978
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002979static void XGI_SetLockRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302980 struct xgi_hw_device_info *HwDeviceExtension,
2981 unsigned short RefreshRateTableIndex,
2982 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002983{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302984 unsigned short push1, push2, tempax, tempbx = 0, tempcx, temp, resinfo,
Peter Hueweef9a6b92013-02-03 04:08:43 +01002985 modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002986
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002987 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002988 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2989 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002990
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302991 if (!(pVBInfo->VBInfo & SetInSlaveMode))
2992 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002993
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302994 temp = 0xFF; /* set MAX HT */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002995 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302996 tempcx = 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002997
Peter Huewe6896b942012-02-09 21:11:46 +01002998 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302999 modeflag |= Charx8Dot;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003000
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303001 tempax = pVBInfo->VGAHDE; /* 0x04 Horizontal Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003002
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303003 if (modeflag & HalfDCLK)
3004 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003005
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303006 tempax = (tempax / tempcx) - 1;
3007 tempbx |= ((tempax & 0x00FF) << 8);
3008 temp = tempax & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003009 xgifb_reg_set(pVBInfo->Part1Port, 0x04, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003010
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303011 temp = (tempbx & 0xFF00) >> 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003012
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303013 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Peter Huewe6896b942012-02-09 21:11:46 +01003014 if (!(pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3015 | VB_SIS302LV | VB_XGI301C)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303016 temp += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003017
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03003018 if ((pVBInfo->VBInfo & SetCRT2ToHiVision) &&
3019 !(pVBInfo->VBType & VB_SIS301LV) && (resinfo == 7))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303020 temp -= 2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303021 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003022
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003023 /* 0x05 Horizontal Display Start */
3024 xgifb_reg_set(pVBInfo->Part1Port, 0x05, temp);
3025 /* 0x06 Horizontal Blank end */
3026 xgifb_reg_set(pVBInfo->Part1Port, 0x06, 0x03);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003027
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303028 if (!(pVBInfo->VBInfo & DisableCRT2Display)) { /* 030226 bainy */
3029 if (pVBInfo->VBInfo & SetCRT2ToTV)
3030 tempax = pVBInfo->VGAHT;
3031 else
3032 tempax = XGI_GetVGAHT2(pVBInfo);
3033 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003034
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303035 if (tempax >= pVBInfo->VGAHT)
3036 tempax = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003037
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303038 if (modeflag & HalfDCLK)
3039 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003040
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303041 tempax = (tempax / tempcx) - 5;
3042 tempcx = tempax; /* 20030401 0x07 horizontal Retrace Start */
Peter Huewe599801f2012-02-09 21:11:45 +01003043 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303044 temp = (tempbx & 0x00FF) - 1;
3045 if (!(modeflag & HalfDCLK)) {
3046 temp -= 6;
3047 if (pVBInfo->TVInfo & TVSimuMode) {
3048 temp -= 4;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003049 temp -= 10;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303050 }
3051 }
3052 } else {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303053 tempbx = (tempbx & 0xFF00) >> 8;
3054 tempcx = (tempcx + tempbx) >> 1;
3055 temp = (tempcx & 0x00FF) + 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003056
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303057 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3058 temp -= 1;
3059 if (!(modeflag & HalfDCLK)) {
3060 if ((modeflag & Charx8Dot)) {
3061 temp += 4;
3062 if (pVBInfo->VGAHDE >= 800)
3063 temp -= 6;
3064 }
3065 }
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003066 } else if (!(modeflag & HalfDCLK)) {
3067 temp -= 4;
Peter Huewe255aabd2012-02-09 21:11:44 +01003068 if (pVBInfo->LCDResInfo != Panel_1280x960 &&
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003069 pVBInfo->VGAHDE >= 800) {
3070 temp -= 7;
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003071 if (pVBInfo->VGAHDE >= 1280 &&
Peter Huewe255aabd2012-02-09 21:11:44 +01003072 pVBInfo->LCDResInfo != Panel_1280x960 &&
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003073 (pVBInfo->LCDInfo & LCDNonExpanding))
3074 temp += 28;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303075 }
3076 }
3077 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003078
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003079 /* 0x07 Horizontal Retrace Start */
3080 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
3081 /* 0x08 Horizontal Retrace End */
3082 xgifb_reg_set(pVBInfo->Part1Port, 0x08, 0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003083
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303084 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3085 if (pVBInfo->TVInfo & TVSimuMode) {
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003086 if (ModeNo == 0x50) {
Peter Huewe85b38472013-05-13 23:41:49 +02003087 if (pVBInfo->TVInfo == SetNTSCTV) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003088 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303089 0x07, 0x30);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003090 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303091 0x08, 0x03);
3092 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003093 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303094 0x07, 0x2f);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003095 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303096 0x08, 0x02);
3097 }
3098 }
3099 }
3100 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003101
Aaro Koskinen8104e322011-03-13 12:26:22 +02003102 xgifb_reg_set(pVBInfo->Part1Port, 0x18, 0x03); /* 0x18 SR0B */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003103 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0xF0, 0x00);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003104 xgifb_reg_set(pVBInfo->Part1Port, 0x09, 0xFF); /* 0x09 Set Max VT */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003105
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303106 tempbx = pVBInfo->VGAVT;
3107 push1 = tempbx;
3108 tempcx = 0x121;
3109 tempbx = pVBInfo->VGAVDE; /* 0x0E Virtical Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003110
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303111 if (tempbx == 357)
3112 tempbx = 350;
3113 if (tempbx == 360)
3114 tempbx = 350;
3115 if (tempbx == 375)
3116 tempbx = 350;
3117 if (tempbx == 405)
3118 tempbx = 400;
3119 if (tempbx == 525)
3120 tempbx = 480;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003121
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303122 push2 = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003123
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303124 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
Peter Huewe255aabd2012-02-09 21:11:44 +01003125 if (pVBInfo->LCDResInfo == Panel_1024x768) {
Peter Huewea3d675c2012-02-09 21:11:47 +01003126 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303127 if (tempbx == 350)
3128 tempbx += 5;
3129 if (tempbx == 480)
3130 tempbx += 5;
3131 }
3132 }
3133 }
3134 tempbx--;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303135 tempbx--;
3136 temp = tempbx & 0x00FF;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003137 /* 0x10 vertical Blank Start */
3138 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303139 tempbx = push2;
3140 tempbx--;
3141 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003142 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003143
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303144 if (tempbx & 0x0100)
3145 tempcx |= 0x0002;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003146
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303147 tempax = 0x000B;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003148
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303149 if (modeflag & DoubleScanMode)
3150 tempax |= 0x08000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003151
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303152 if (tempbx & 0x0200)
3153 tempcx |= 0x0040;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003154
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303155 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003156 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003157
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303158 if (tempbx & 0x0400)
3159 tempcx |= 0x0600;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003160
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003161 /* 0x11 Vertival Blank End */
3162 xgifb_reg_set(pVBInfo->Part1Port, 0x11, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303163
3164 tempax = push1;
3165 tempax -= tempbx; /* 0x0C Vertical Retrace Start */
3166 tempax = tempax >> 2;
3167 push1 = tempax; /* push ax */
3168
3169 if (resinfo != 0x09) {
3170 tempax = tempax << 1;
3171 tempbx += tempax;
3172 }
3173
Peter Huewe599801f2012-02-09 21:11:45 +01003174 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Miguel Gómez470c5332012-07-06 12:40:50 +02003175 if ((pVBInfo->VBType & VB_SIS301LV) &&
3176 !(pVBInfo->TVInfo & TVSetHiVision)) {
3177 if ((pVBInfo->TVInfo & TVSimuMode) &&
3178 (pVBInfo->TVInfo & TVSetPAL)) {
3179 if (!(pVBInfo->VBType & VB_SIS301LV) ||
3180 !(pVBInfo->TVInfo &
3181 (TVSetYPbPr525p |
3182 TVSetYPbPr750p |
3183 TVSetHiVision)))
3184 tempbx += 40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303185 }
3186 } else {
3187 tempbx -= 10;
3188 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003189 } else if (pVBInfo->TVInfo & TVSimuMode) {
3190 if (pVBInfo->TVInfo & TVSetPAL) {
3191 if (pVBInfo->VBType & VB_SIS301LV) {
3192 if (!(pVBInfo->TVInfo &
3193 (TVSetYPbPr525p |
3194 TVSetYPbPr750p |
3195 TVSetHiVision)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303196 tempbx += 40;
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003197 } else {
3198 tempbx += 40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303199 }
3200 }
3201 }
3202 tempax = push1;
3203 tempax = tempax >> 2;
3204 tempax++;
3205 tempax += tempbx;
3206 push1 = tempax; /* push ax */
3207
Peter Huewe599801f2012-02-09 21:11:45 +01003208 if ((pVBInfo->TVInfo & TVSetPAL)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303209 if (tempbx <= 513) {
3210 if (tempax >= 513)
3211 tempbx = 513;
3212 }
3213 }
3214
3215 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003216 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303217 tempbx--;
3218 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003219 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303220
3221 if (tempbx & 0x0100)
3222 tempcx |= 0x0008;
3223
3224 if (tempbx & 0x0200)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003225 xgifb_reg_and_or(pVBInfo->Part1Port, 0x0B, 0x0FF, 0x20);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303226
3227 tempbx++;
3228
3229 if (tempbx & 0x0100)
3230 tempcx |= 0x0004;
3231
3232 if (tempbx & 0x0200)
3233 tempcx |= 0x0080;
3234
3235 if (tempbx & 0x0400)
3236 tempcx |= 0x0C00;
3237
3238 tempbx = push1; /* pop ax */
3239 temp = tempbx & 0x00FF;
3240 temp &= 0x0F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003241 /* 0x0D vertical Retrace End */
3242 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303243
3244 if (tempbx & 0x0010)
3245 tempcx |= 0x2000;
3246
3247 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003248 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp); /* 0x0A CR07 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303249 temp = (tempcx & 0x0FF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003250 xgifb_reg_set(pVBInfo->Part1Port, 0x17, temp); /* 0x17 SR0A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303251 tempax = modeflag;
3252 temp = (tempax & 0xFF00) >> 8;
3253
3254 temp = (temp >> 1) & 0x09;
3255
Peter Huewe6896b942012-02-09 21:11:46 +01003256 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303257 temp |= 0x01;
3258
Aaro Koskinen8104e322011-03-13 12:26:22 +02003259 xgifb_reg_set(pVBInfo->Part1Port, 0x16, temp); /* 0x16 SR01 */
3260 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, 0); /* 0x0F CR14 */
3261 xgifb_reg_set(pVBInfo->Part1Port, 0x12, 0); /* 0x12 CR17 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303262
3263 if (pVBInfo->LCDInfo & LCDRGB18Bit)
3264 temp = 0x80;
3265 else
3266 temp = 0x00;
3267
Aaro Koskinen8104e322011-03-13 12:26:22 +02003268 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, temp); /* 0x1A SR0E */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003269}
3270
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003271static void XGI_SetGroup2(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303272 unsigned short RefreshRateTableIndex,
3273 struct xgi_hw_device_info *HwDeviceExtension,
3274 struct vb_device_info *pVBInfo)
3275{
3276 unsigned short i, j, tempax, tempbx, tempcx, temp, push1, push2,
Peter Hueweef9a6b92013-02-03 04:08:43 +01003277 modeflag;
Aaro Koskinend21222d2012-09-11 00:15:29 +03003278 unsigned char const *TimingPoint;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303279
3280 unsigned long longtemp, tempeax, tempebx, temp2, tempecx;
3281
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003282 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02003283 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303284
3285 tempax = 0;
3286
3287 if (!(pVBInfo->VBInfo & SetCRT2ToAVIDEO))
3288 tempax |= 0x0800;
3289
3290 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3291 tempax |= 0x0400;
3292
3293 if (pVBInfo->VBInfo & SetCRT2ToSCART)
3294 tempax |= 0x0200;
3295
Peter Huewe599801f2012-02-09 21:11:45 +01003296 if (!(pVBInfo->TVInfo & TVSetPAL))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303297 tempax |= 0x1000;
3298
Peter Huewe599801f2012-02-09 21:11:45 +01003299 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303300 tempax |= 0x0100;
3301
Peter Huewe599801f2012-02-09 21:11:45 +01003302 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303303 tempax &= 0xfe00;
3304
3305 tempax = (tempax & 0xff00) >> 8;
3306
Aaro Koskinen8104e322011-03-13 12:26:22 +02003307 xgifb_reg_set(pVBInfo->Part2Port, 0x0, tempax);
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003308 TimingPoint = XGI330_NTSCTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303309
Peter Huewe599801f2012-02-09 21:11:45 +01003310 if (pVBInfo->TVInfo & TVSetPAL)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003311 TimingPoint = XGI330_PALTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303312
Peter Huewe599801f2012-02-09 21:11:45 +01003313 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003314 TimingPoint = XGI330_HiTVExtTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303315
3316 if (pVBInfo->VBInfo & SetInSlaveMode)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003317 TimingPoint = XGI330_HiTVSt2Timing;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303318
3319 if (pVBInfo->SetFlag & TVSimuMode)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003320 TimingPoint = XGI330_HiTVSt1Timing;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303321
3322 if (!(modeflag & Charx8Dot))
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003323 TimingPoint = XGI330_HiTVTextTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303324 }
3325
Peter Huewe599801f2012-02-09 21:11:45 +01003326 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
3327 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003328 TimingPoint = XGI330_YPbPr525iTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303329
Peter Huewe599801f2012-02-09 21:11:45 +01003330 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003331 TimingPoint = XGI330_YPbPr525pTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303332
Peter Huewe599801f2012-02-09 21:11:45 +01003333 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003334 TimingPoint = XGI330_YPbPr750pTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303335 }
3336
3337 for (i = 0x01, j = 0; i <= 0x2D; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02003338 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303339
3340 for (i = 0x39; i <= 0x45; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003341 /* di->temp2[j] */
3342 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303343
3344 if (pVBInfo->VBInfo & SetCRT2ToTV)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003345 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303346
3347 temp = pVBInfo->NewFlickerMode;
3348 temp &= 0x80;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003349 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xFF, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303350
Peter Huewe599801f2012-02-09 21:11:45 +01003351 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303352 tempax = 520;
3353 else
3354 tempax = 440;
3355
3356 if (pVBInfo->VDE <= tempax) {
3357 tempax -= pVBInfo->VDE;
3358 tempax = tempax >> 2;
3359 tempax = (tempax & 0x00FF) | ((tempax & 0x00FF) << 8);
3360 push1 = tempax;
3361 temp = (tempax & 0xFF00) >> 8;
3362 temp += (unsigned short) TimingPoint[0];
3363
Peter Huewe6896b942012-02-09 21:11:46 +01003364 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3365 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303366 if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO
3367 | SetCRT2ToSVIDEO | SetCRT2ToSCART
Peter Huewe599801f2012-02-09 21:11:45 +01003368 | SetCRT2ToYPbPr525750)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303369 tempcx = pVBInfo->VGAHDE;
3370 if (tempcx >= 1024) {
3371 temp = 0x17; /* NTSC */
Peter Huewe599801f2012-02-09 21:11:45 +01003372 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303373 temp = 0x19; /* PAL */
3374 }
3375 }
3376 }
3377
Aaro Koskinen8104e322011-03-13 12:26:22 +02003378 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303379 tempax = push1;
3380 temp = (tempax & 0xFF00) >> 8;
3381 temp += TimingPoint[1];
3382
Peter Huewe6896b942012-02-09 21:11:46 +01003383 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3384 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303385 if ((pVBInfo->VBInfo & (SetCRT2ToAVIDEO
3386 | SetCRT2ToSVIDEO | SetCRT2ToSCART
Peter Huewe599801f2012-02-09 21:11:45 +01003387 | SetCRT2ToYPbPr525750))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303388 tempcx = pVBInfo->VGAHDE;
3389 if (tempcx >= 1024) {
3390 temp = 0x1D; /* NTSC */
Peter Huewe599801f2012-02-09 21:11:45 +01003391 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303392 temp = 0x52; /* PAL */
3393 }
3394 }
3395 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02003396 xgifb_reg_set(pVBInfo->Part2Port, 0x02, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303397 }
3398
3399 /* 301b */
3400 tempcx = pVBInfo->HT;
3401
3402 if (XGI_IsLCDDualLink(pVBInfo))
3403 tempcx = tempcx >> 1;
3404
3405 tempcx -= 2;
3406 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003407 xgifb_reg_set(pVBInfo->Part2Port, 0x1B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303408
3409 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003410 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303411
3412 tempcx = pVBInfo->HT >> 1;
3413 push1 = tempcx; /* push cx */
3414 tempcx += 7;
3415
Peter Huewe599801f2012-02-09 21:11:45 +01003416 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303417 tempcx -= 4;
3418
3419 temp = tempcx & 0x00FF;
3420 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003421 xgifb_reg_and_or(pVBInfo->Part2Port, 0x22, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303422
3423 tempbx = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
3424 tempbx += tempcx;
3425 push2 = tempbx;
3426 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003427 xgifb_reg_set(pVBInfo->Part2Port, 0x24, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303428 temp = (tempbx & 0xFF00) >> 8;
3429 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003430 xgifb_reg_and_or(pVBInfo->Part2Port, 0x25, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303431
3432 tempbx = push2;
3433 tempbx = tempbx + 8;
Peter Huewe599801f2012-02-09 21:11:45 +01003434 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303435 tempbx = tempbx - 4;
3436 tempcx = tempbx;
3437 }
3438
3439 temp = (tempbx & 0x00FF) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003440 xgifb_reg_and_or(pVBInfo->Part2Port, 0x29, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303441
3442 j += 2;
3443 tempcx += (TimingPoint[j] | ((TimingPoint[j + 1]) << 8));
3444 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003445 xgifb_reg_set(pVBInfo->Part2Port, 0x27, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303446 temp = ((tempcx & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003447 xgifb_reg_and_or(pVBInfo->Part2Port, 0x28, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303448
3449 tempcx += 8;
Peter Huewe599801f2012-02-09 21:11:45 +01003450 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303451 tempcx -= 4;
3452
3453 temp = tempcx & 0xFF;
3454 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003455 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2A, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303456
3457 tempcx = push1; /* pop cx */
3458 j += 2;
3459 temp = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
3460 tempcx -= temp;
3461 temp = tempcx & 0x00FF;
3462 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003463 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2D, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303464
3465 tempcx -= 11;
3466
3467 if (!(pVBInfo->VBInfo & SetCRT2ToTV)) {
3468 tempax = XGI_GetVGAHT2(pVBInfo);
3469 tempcx = tempax - 1;
3470 }
3471 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003472 xgifb_reg_set(pVBInfo->Part2Port, 0x2E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303473
3474 tempbx = pVBInfo->VDE;
3475
3476 if (pVBInfo->VGAVDE == 360)
3477 tempbx = 746;
3478 if (pVBInfo->VGAVDE == 375)
3479 tempbx = 746;
3480 if (pVBInfo->VGAVDE == 405)
3481 tempbx = 853;
3482
3483 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003484 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01003485 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003486 if (!(pVBInfo->TVInfo &
Peter Huewe599801f2012-02-09 21:11:45 +01003487 (TVSetYPbPr525p | TVSetYPbPr750p)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303488 tempbx = tempbx >> 1;
3489 } else
3490 tempbx = tempbx >> 1;
3491 }
3492
3493 tempbx -= 2;
3494 temp = tempbx & 0x00FF;
3495
Peter Huewe599801f2012-02-09 21:11:45 +01003496 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Huewe6896b942012-02-09 21:11:46 +01003497 if (pVBInfo->VBType & VB_SIS301LV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003498 if (pVBInfo->TVInfo & TVSetHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303499 if (pVBInfo->VBInfo & SetInSlaveMode) {
3500 if (ModeNo == 0x2f)
3501 temp += 1;
3502 }
3503 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003504 } else if (pVBInfo->VBInfo & SetInSlaveMode) {
3505 if (ModeNo == 0x2f)
3506 temp += 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303507 }
3508 }
3509
Aaro Koskinen8104e322011-03-13 12:26:22 +02003510 xgifb_reg_set(pVBInfo->Part2Port, 0x2F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303511
3512 temp = (tempcx & 0xFF00) >> 8;
3513 temp |= ((tempbx & 0xFF00) >> 8) << 6;
3514
Peter Huewe599801f2012-02-09 21:11:45 +01003515 if (!(pVBInfo->VBInfo & SetCRT2ToHiVision)) {
Peter Huewe6896b942012-02-09 21:11:46 +01003516 if (pVBInfo->VBType & VB_SIS301LV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003517 if (pVBInfo->TVInfo & TVSetHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303518 temp |= 0x10;
3519
3520 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3521 temp |= 0x20;
3522 }
3523 } else {
3524 temp |= 0x10;
3525 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3526 temp |= 0x20;
3527 }
3528 }
3529
Aaro Koskinen8104e322011-03-13 12:26:22 +02003530 xgifb_reg_set(pVBInfo->Part2Port, 0x30, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303531
Peter Huewe6896b942012-02-09 21:11:46 +01003532 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3533 | VB_SIS302LV | VB_XGI301C)) { /* TV gatingno */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303534 tempbx = pVBInfo->VDE;
3535 tempcx = tempbx - 2;
3536
3537 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003538 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p
3539 | TVSetYPbPr750p)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303540 tempbx = tempbx >> 1;
3541 }
3542
Peter Huewe6896b942012-02-09 21:11:46 +01003543 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303544 temp = 0;
3545 if (tempcx & 0x0400)
3546 temp |= 0x20;
3547
3548 if (tempbx & 0x0400)
3549 temp |= 0x40;
3550
Aaro Koskinen8104e322011-03-13 12:26:22 +02003551 xgifb_reg_set(pVBInfo->Part4Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303552 }
3553
3554 temp = (((tempbx - 3) & 0x0300) >> 8) << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003555 xgifb_reg_set(pVBInfo->Part2Port, 0x46, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303556 temp = (tempbx - 3) & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003557 xgifb_reg_set(pVBInfo->Part2Port, 0x47, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303558 }
3559
3560 tempbx = tempbx & 0x00FF;
3561
3562 if (!(modeflag & HalfDCLK)) {
3563 tempcx = pVBInfo->VGAHDE;
3564 if (tempcx >= pVBInfo->HDE) {
3565 tempbx |= 0x2000;
3566 tempax &= 0x00FF;
3567 }
3568 }
3569
3570 tempcx = 0x0101;
3571
3572 if (pVBInfo->VBInfo & SetCRT2ToTV) { /*301b*/
3573 if (pVBInfo->VGAHDE >= 1024) {
3574 tempcx = 0x1920;
3575 if (pVBInfo->VGAHDE >= 1280) {
3576 tempcx = 0x1420;
3577 tempbx = tempbx & 0xDFFF;
3578 }
3579 }
3580 }
3581
3582 if (!(tempbx & 0x2000)) {
3583 if (modeflag & HalfDCLK)
3584 tempcx = (tempcx & 0xFF00) | ((tempcx & 0x00FF) << 1);
3585
3586 push1 = tempbx;
3587 tempeax = pVBInfo->VGAHDE;
3588 tempebx = (tempcx & 0xFF00) >> 8;
3589 longtemp = tempeax * tempebx;
3590 tempecx = tempcx & 0x00FF;
3591 longtemp = longtemp / tempecx;
3592
3593 /* 301b */
3594 tempecx = 8 * 1024;
3595
Peter Huewe6896b942012-02-09 21:11:46 +01003596 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3597 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303598 tempecx = tempecx * 8;
3599 }
3600
3601 longtemp = longtemp * tempecx;
3602 tempecx = pVBInfo->HDE;
3603 temp2 = longtemp % tempecx;
3604 tempeax = longtemp / tempecx;
3605 if (temp2 != 0)
3606 tempeax += 1;
3607
3608 tempax = (unsigned short) tempeax;
3609
3610 /* 301b */
Peter Huewe6896b942012-02-09 21:11:46 +01003611 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3612 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303613 tempcx = ((tempax & 0xFF00) >> 5) >> 8;
3614 }
3615 /* end 301b */
3616
3617 tempbx = push1;
3618 tempbx = (unsigned short) (((tempeax & 0x0000FF00) & 0x1F00)
3619 | (tempbx & 0x00FF));
3620 tempax = (unsigned short) (((tempeax & 0x000000FF) << 8)
3621 | (tempax & 0x00FF));
3622 temp = (tempax & 0xFF00) >> 8;
3623 } else {
3624 temp = (tempax & 0x00FF) >> 8;
3625 }
3626
Aaro Koskinen8104e322011-03-13 12:26:22 +02003627 xgifb_reg_set(pVBInfo->Part2Port, 0x44, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303628 temp = (tempbx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003629 xgifb_reg_and_or(pVBInfo->Part2Port, 0x45, ~0x03F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303630 temp = tempcx & 0x00FF;
3631
3632 if (tempbx & 0x2000)
3633 temp = 0;
3634
3635 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
3636 temp |= 0x18;
3637
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003638 xgifb_reg_and_or(pVBInfo->Part2Port, 0x46, ~0x1F, temp);
Peter Huewe599801f2012-02-09 21:11:45 +01003639 if (pVBInfo->TVInfo & TVSetPAL) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303640 tempbx = 0x0382;
3641 tempcx = 0x007e;
3642 } else {
3643 tempbx = 0x0369;
3644 tempcx = 0x0061;
3645 }
3646
3647 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003648 xgifb_reg_set(pVBInfo->Part2Port, 0x4b, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303649 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003650 xgifb_reg_set(pVBInfo->Part2Port, 0x4c, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303651
3652 temp = ((tempcx & 0xFF00) >> 8) & 0x03;
3653 temp = temp << 2;
3654 temp |= ((tempbx & 0xFF00) >> 8) & 0x03;
3655
Peter Huewe599801f2012-02-09 21:11:45 +01003656 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303657 temp |= 0x10;
3658
Peter Huewe599801f2012-02-09 21:11:45 +01003659 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303660 temp |= 0x20;
3661
Peter Huewe599801f2012-02-09 21:11:45 +01003662 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303663 temp |= 0x60;
3664 }
3665
Aaro Koskinen8104e322011-03-13 12:26:22 +02003666 xgifb_reg_set(pVBInfo->Part2Port, 0x4d, temp);
Aaro Koskinen58839b02011-03-13 12:26:23 +02003667 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x43); /* 301b change */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003668 xgifb_reg_set(pVBInfo->Part2Port, 0x43, (unsigned short) (temp - 3));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303669
Peter Huewe599801f2012-02-09 21:11:45 +01003670 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303671 if (pVBInfo->TVInfo & NTSC1024x768) {
3672 TimingPoint = XGI_NTSC1024AdjTime;
3673 for (i = 0x1c, j = 0; i <= 0x30; i++, j++) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003674 xgifb_reg_set(pVBInfo->Part2Port, i,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303675 TimingPoint[j]);
3676 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02003677 xgifb_reg_set(pVBInfo->Part2Port, 0x43, 0x72);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303678 }
3679 }
3680
Miguel Gómez949eb0a2012-07-06 12:40:36 +02003681 /* Modify for 301C PALM Support */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303682 if (pVBInfo->VBType & VB_XGI301C) {
Peter Huewe599801f2012-02-09 21:11:45 +01003683 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003684 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x08,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303685 0x08); /* PALM Mode */
3686 }
3687
Peter Huewe599801f2012-02-09 21:11:45 +01003688 if (pVBInfo->TVInfo & TVSetPALM) {
Peter Huewe9388ad92013-02-15 20:37:10 +01003689 tempax = xgifb_reg_get(pVBInfo->Part2Port, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303690 tempax--;
Aaro Koskinendc505562011-03-13 12:26:26 +02003691 xgifb_reg_and(pVBInfo->Part2Port, 0x01, tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303692
Aaro Koskinendc505562011-03-13 12:26:26 +02003693 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xEF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303694 }
3695
Peter Huewe599801f2012-02-09 21:11:45 +01003696 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303697 if (!(pVBInfo->VBInfo & SetInSlaveMode))
Aaro Koskinen8104e322011-03-13 12:26:22 +02003698 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303699 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303700}
3701
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03003702static void XGI_SetLCDRegs(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303703 struct xgi_hw_device_info *HwDeviceExtension,
3704 unsigned short RefreshRateTableIndex,
3705 struct vb_device_info *pVBInfo)
3706{
Peter Hueweef9a6b92013-02-03 04:08:43 +01003707 unsigned short pushbx, tempax, tempbx, tempcx, temp, tempah,
3708 tempbh, tempch;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303709
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02003710 struct XGI_LCDDesStruct const *LCDBDesPtr = NULL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303711
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003712 /* si+Ext_ResInfo */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303713 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
3714 return;
3715
3716 tempbx = pVBInfo->HDE; /* RHACTE=HDE-1 */
3717
3718 if (XGI_IsLCDDualLink(pVBInfo))
3719 tempbx = tempbx >> 1;
3720
3721 tempbx -= 1;
3722 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003723 xgifb_reg_set(pVBInfo->Part2Port, 0x2C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303724 temp = (tempbx & 0xFF00) >> 8;
3725 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003726 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2B, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303727 temp = 0x01;
3728
Aaro Koskinen8104e322011-03-13 12:26:22 +02003729 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303730 tempbx = pVBInfo->VDE; /* RTVACTEO=(VDE-1)&0xFF */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303731 tempbx--;
3732 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003733 xgifb_reg_set(pVBInfo->Part2Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303734 temp = ((tempbx & 0xFF00) >> 8) & 0x07;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003735 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0C, ~0x07, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303736
3737 tempcx = pVBInfo->VT - 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303738 temp = tempcx & 0x00FF; /* RVTVT=VT-1 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003739 xgifb_reg_set(pVBInfo->Part2Port, 0x19, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303740 temp = (tempcx & 0xFF00) >> 8;
3741 temp = temp << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003742 xgifb_reg_set(pVBInfo->Part2Port, 0x1A, temp);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003743 xgifb_reg_and_or(pVBInfo->Part2Port, 0x09, 0xF0, 0x00);
3744 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xF0, 0x00);
3745 xgifb_reg_and_or(pVBInfo->Part2Port, 0x17, 0xFB, 0x00);
3746 xgifb_reg_and_or(pVBInfo->Part2Port, 0x18, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303747
Justin P. Mattock558f7582012-10-02 21:17:11 -07003748 /* Customized LCDB Does not add */
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02003749 if ((pVBInfo->VBType & VB_SIS301LV) || (pVBInfo->VBType & VB_SIS302LV))
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03003750 LCDBDesPtr = XGI_GetLcdPtr(xgifb_lcddldes, ModeIdIndex,
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02003751 RefreshRateTableIndex, pVBInfo);
3752 else
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03003753 LCDBDesPtr = XGI_GetLcdPtr(XGI_LCDDesDataTable, ModeIdIndex,
3754 RefreshRateTableIndex, pVBInfo);
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02003755
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303756 tempah = pVBInfo->LCDResInfo;
3757 tempah &= PanelResInfo;
3758
Peter Huewe255aabd2012-02-09 21:11:44 +01003759 if ((tempah == Panel_1024x768) || (tempah == Panel_1024x768x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303760 tempbx = 1024;
3761 tempcx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01003762 } else if ((tempah == Panel_1280x1024) ||
3763 (tempah == Panel_1280x1024x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303764 tempbx = 1280;
3765 tempcx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01003766 } else if (tempah == Panel_1400x1050) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303767 tempbx = 1400;
3768 tempcx = 1050;
3769 } else {
3770 tempbx = 1600;
3771 tempcx = 1200;
3772 }
3773
3774 if (pVBInfo->LCDInfo & EnableScalingLCD) {
3775 tempbx = pVBInfo->HDE;
3776 tempcx = pVBInfo->VDE;
3777 }
3778
3779 pushbx = tempbx;
3780 tempax = pVBInfo->VT;
3781 pVBInfo->LCDHDES = LCDBDesPtr->LCDHDES;
3782 pVBInfo->LCDHRS = LCDBDesPtr->LCDHRS;
3783 pVBInfo->LCDVDES = LCDBDesPtr->LCDVDES;
3784 pVBInfo->LCDVRS = LCDBDesPtr->LCDVRS;
3785 tempbx = pVBInfo->LCDVDES;
3786 tempcx += tempbx;
3787
3788 if (tempcx >= tempax)
3789 tempcx -= tempax; /* lcdvdes */
3790
3791 temp = tempbx & 0x00FF; /* RVEQ1EQ=lcdvdes */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003792 xgifb_reg_set(pVBInfo->Part2Port, 0x05, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303793 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003794 xgifb_reg_set(pVBInfo->Part2Port, 0x06, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303795 tempch = ((tempcx & 0xFF00) >> 8) & 0x07;
3796 tempbh = ((tempbx & 0xFF00) >> 8) & 0x07;
3797 tempah = tempch;
3798 tempah = tempah << 3;
3799 tempah |= tempbh;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003800 xgifb_reg_set(pVBInfo->Part2Port, 0x02, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303801
3802 /* getlcdsync() */
3803 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
3804 tempcx = tempbx;
3805 tempax = pVBInfo->VT;
3806 tempbx = pVBInfo->LCDVRS;
3807
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303808 tempcx += tempbx;
3809 if (tempcx >= tempax)
3810 tempcx -= tempax;
3811
3812 temp = tempbx & 0x00FF; /* RTVACTEE=lcdvrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003813 xgifb_reg_set(pVBInfo->Part2Port, 0x04, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303814 temp = (tempbx & 0xFF00) >> 8;
3815 temp = temp << 4;
3816 temp |= (tempcx & 0x000F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003817 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303818 tempcx = pushbx;
3819 tempax = pVBInfo->HT;
3820 tempbx = pVBInfo->LCDHDES;
3821 tempbx &= 0x0FFF;
3822
3823 if (XGI_IsLCDDualLink(pVBInfo)) {
3824 tempax = tempax >> 1;
3825 tempbx = tempbx >> 1;
3826 tempcx = tempcx >> 1;
3827 }
3828
Peter Huewe6896b942012-02-09 21:11:46 +01003829 if (pVBInfo->VBType & VB_SIS302LV)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303830 tempbx += 1;
3831
3832 if (pVBInfo->VBType & VB_XGI301C) /* tap4 */
3833 tempbx += 1;
3834
3835 tempcx += tempbx;
3836
3837 if (tempcx >= tempax)
3838 tempcx -= tempax;
3839
3840 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003841 xgifb_reg_set(pVBInfo->Part2Port, 0x1F, temp); /* RHBLKE=lcdhdes */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303842 temp = ((tempbx & 0xFF00) >> 8) << 4;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003843 xgifb_reg_set(pVBInfo->Part2Port, 0x20, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303844 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003845 xgifb_reg_set(pVBInfo->Part2Port, 0x23, temp); /* RHEQPLE=lcdhdee */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303846 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003847 xgifb_reg_set(pVBInfo->Part2Port, 0x25, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303848
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303849 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
3850 tempcx = tempax;
3851 tempax = pVBInfo->HT;
3852 tempbx = pVBInfo->LCDHRS;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303853 if (XGI_IsLCDDualLink(pVBInfo)) {
3854 tempax = tempax >> 1;
3855 tempbx = tempbx >> 1;
3856 tempcx = tempcx >> 1;
3857 }
3858
Peter Huewe6896b942012-02-09 21:11:46 +01003859 if (pVBInfo->VBType & VB_SIS302LV)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303860 tempbx += 1;
3861
3862 tempcx += tempbx;
3863
3864 if (tempcx >= tempax)
3865 tempcx -= tempax;
3866
3867 temp = tempbx & 0x00FF; /* RHBURSTS=lcdhrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003868 xgifb_reg_set(pVBInfo->Part2Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303869
3870 temp = (tempbx & 0xFF00) >> 8;
3871 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003872 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303873 temp = tempcx & 0x00FF; /* RHSYEXP2S=lcdhre */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003874 xgifb_reg_set(pVBInfo->Part2Port, 0x21, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303875
Peter Huewea3d675c2012-02-09 21:11:47 +01003876 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303877 if (pVBInfo->VGAVDE == 525) {
Peter Huewe6896b942012-02-09 21:11:46 +01003878 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
3879 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303880 | VB_XGI301C)) {
3881 temp = 0xC6;
3882 } else
3883 temp = 0xC4;
3884
Aaro Koskinen8104e322011-03-13 12:26:22 +02003885 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
3886 xgifb_reg_set(pVBInfo->Part2Port, 0x30, 0xB3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303887 }
3888
3889 if (pVBInfo->VGAVDE == 420) {
Peter Huewe6896b942012-02-09 21:11:46 +01003890 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
3891 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303892 | VB_XGI301C)) {
3893 temp = 0x4F;
3894 } else
3895 temp = 0x4E;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003896 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303897 }
3898 }
3899}
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003900
3901/* --------------------------------------------------------------------- */
3902/* Function : XGI_GetTap4Ptr */
3903/* Input : */
3904/* Output : di -> Tap4 Reg. Setting Pointer */
3905/* Description : */
3906/* --------------------------------------------------------------------- */
Aaro Koskinen1cccd9e2012-11-04 21:15:06 +02003907static struct XGI301C_Tap4TimingStruct const
3908*XGI_GetTap4Ptr(unsigned short tempcx, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003909{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303910 unsigned short tempax, tempbx, i;
Aaro Koskinen1cccd9e2012-11-04 21:15:06 +02003911 struct XGI301C_Tap4TimingStruct const *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003912
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303913 if (tempcx == 0) {
3914 tempax = pVBInfo->VGAHDE;
3915 tempbx = pVBInfo->HDE;
3916 } else {
3917 tempax = pVBInfo->VGAVDE;
3918 tempbx = pVBInfo->VDE;
3919 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003920
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03003921 if (tempax <= tempbx)
3922 return &xgifb_tap4_timing[0];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303923 else
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03003924 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing; /* NTSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003925
Peter Huewe599801f2012-02-09 21:11:45 +01003926 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303927 Tap4TimingPtr = PALTap4Timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003928
Peter Huewe599801f2012-02-09 21:11:45 +01003929 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
3930 if ((pVBInfo->TVInfo & TVSetYPbPr525i) ||
3931 (pVBInfo->TVInfo & TVSetYPbPr525p))
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03003932 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing;
Peter Huewe599801f2012-02-09 21:11:45 +01003933 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303934 Tap4TimingPtr = YPbPr750pTap4Timing;
3935 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003936
Peter Huewe599801f2012-02-09 21:11:45 +01003937 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03003938 Tap4TimingPtr = xgifb_tap4_timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003939
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303940 i = 0;
3941 while (Tap4TimingPtr[i].DE != 0xFFFF) {
3942 if (Tap4TimingPtr[i].DE == tempax)
3943 break;
3944 i++;
3945 }
3946 return &Tap4TimingPtr[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003947}
3948
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003949static void XGI_SetTap4Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003950{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303951 unsigned short i, j;
Aaro Koskinen1cccd9e2012-11-04 21:15:06 +02003952 struct XGI301C_Tap4TimingStruct const *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003953
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303954 if (!(pVBInfo->VBType & VB_XGI301C))
3955 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003956
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303957 Tap4TimingPtr = XGI_GetTap4Ptr(0, pVBInfo); /* Set Horizontal Scaling */
3958 for (i = 0x80, j = 0; i <= 0xBF; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02003959 xgifb_reg_set(pVBInfo->Part2Port, i, Tap4TimingPtr->Reg[j]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003960
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003961 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
Peter Huewe599801f2012-02-09 21:11:45 +01003962 (!(pVBInfo->VBInfo & SetCRT2ToHiVision))) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003963 /* Set Vertical Scaling */
3964 Tap4TimingPtr = XGI_GetTap4Ptr(1, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303965 for (i = 0xC0, j = 0; i < 0xFF; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003966 xgifb_reg_set(pVBInfo->Part2Port,
3967 i,
3968 Tap4TimingPtr->Reg[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303969 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003970
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003971 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
Peter Huewe599801f2012-02-09 21:11:45 +01003972 (!(pVBInfo->VBInfo & SetCRT2ToHiVision)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003973 /* Enable V.Scaling */
3974 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303975 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003976 /* Enable H.Scaling */
3977 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x10);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003978}
3979
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03003980static void XGI_SetGroup3(unsigned short ModeIdIndex,
3981 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003982{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303983 unsigned short i;
Aaro Koskinend21222d2012-09-11 00:15:29 +03003984 unsigned char const *tempdi;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303985 unsigned short modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003986
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003987 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02003988 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003989
Aaro Koskinen8104e322011-03-13 12:26:22 +02003990 xgifb_reg_set(pVBInfo->Part3Port, 0x00, 0x00);
Peter Huewe599801f2012-02-09 21:11:45 +01003991 if (pVBInfo->TVInfo & TVSetPAL) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003992 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
3993 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303994 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003995 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xF5);
3996 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xB7);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303997 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003998
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303999 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
4000 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004001
Peter Huewe599801f2012-02-09 21:11:45 +01004002 if (pVBInfo->TVInfo & TVSetPALM) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004003 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
4004 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
4005 xgifb_reg_set(pVBInfo->Part3Port, 0x3D, 0xA8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304006 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004007
Peter Huewe599801f2012-02-09 21:11:45 +01004008 if ((pVBInfo->VBInfo & SetCRT2ToHiVision) || (pVBInfo->VBInfo
4009 & SetCRT2ToYPbPr525750)) {
4010 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304011 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004012
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004013 tempdi = XGI330_HiTVGroup3Data;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304014 if (pVBInfo->SetFlag & TVSimuMode) {
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004015 tempdi = XGI330_HiTVGroup3Simu;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304016 if (!(modeflag & Charx8Dot))
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004017 tempdi = XGI330_HiTVGroup3Text;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304018 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004019
Peter Huewe599801f2012-02-09 21:11:45 +01004020 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004021 tempdi = XGI330_Ren525pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004022
Peter Huewe599801f2012-02-09 21:11:45 +01004023 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004024 tempdi = XGI330_Ren750pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004025
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304026 for (i = 0; i <= 0x3E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004027 xgifb_reg_set(pVBInfo->Part3Port, i, tempdi[i]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004028
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304029 if (pVBInfo->VBType & VB_XGI301C) { /* Marcovision */
Peter Huewe599801f2012-02-09 21:11:45 +01004030 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004031 xgifb_reg_set(pVBInfo->Part3Port, 0x28, 0x3f);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304032 }
4033 }
Aaro Koskinen2351d1f2013-05-29 23:59:13 +03004034}
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304035
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03004036static void XGI_SetGroup4(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304037 unsigned short RefreshRateTableIndex,
4038 struct xgi_hw_device_info *HwDeviceExtension,
4039 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004040{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304041 unsigned short tempax, tempcx, tempbx, modeflag, temp, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004042
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304043 unsigned long tempebx, tempeax, templong;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004044
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004045 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004046 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304047 temp = pVBInfo->RVBHCFACT;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004048 xgifb_reg_set(pVBInfo->Part4Port, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004049
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304050 tempbx = pVBInfo->RVBHCMAX;
4051 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004052 xgifb_reg_set(pVBInfo->Part4Port, 0x14, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304053 temp2 = ((tempbx & 0xFF00) >> 8) << 7;
4054 tempcx = pVBInfo->VGAHT - 1;
4055 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004056 xgifb_reg_set(pVBInfo->Part4Port, 0x16, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004057
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304058 temp = ((tempcx & 0xFF00) >> 8) << 3;
4059 temp2 |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004060
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304061 tempcx = pVBInfo->VGAVT - 1;
4062 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
4063 tempcx -= 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004064
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304065 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004066 xgifb_reg_set(pVBInfo->Part4Port, 0x17, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304067 temp = temp2 | ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004068 xgifb_reg_set(pVBInfo->Part4Port, 0x15, temp);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004069 xgifb_reg_or(pVBInfo->Part4Port, 0x0D, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304070 tempcx = pVBInfo->VBInfo;
4071 tempbx = pVBInfo->VGAHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004072
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304073 if (modeflag & HalfDCLK)
4074 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004075
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304076 if (XGI_IsLCDDualLink(pVBInfo))
4077 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004078
Peter Huewe599801f2012-02-09 21:11:45 +01004079 if (tempcx & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304080 temp = 0;
4081 if (tempbx <= 1024)
4082 temp = 0xA0;
4083 if (tempbx == 1280)
4084 temp = 0xC0;
4085 } else if (tempcx & SetCRT2ToTV) {
4086 temp = 0xA0;
4087 if (tempbx <= 800)
4088 temp = 0x80;
4089 } else {
4090 temp = 0x80;
4091 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4092 temp = 0;
4093 if (tempbx > 800)
4094 temp = 0x60;
4095 }
4096 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004097
Peter Huewe599801f2012-02-09 21:11:45 +01004098 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304099 temp = 0x00;
4100 if (pVBInfo->VGAHDE == 1280)
4101 temp = 0x40;
4102 if (pVBInfo->VGAHDE == 1024)
4103 temp = 0x20;
4104 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004105 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0E, ~0xEF, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004106
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304107 tempebx = pVBInfo->VDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004108
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304109 tempcx = pVBInfo->RVBHRS;
4110 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004111 xgifb_reg_set(pVBInfo->Part4Port, 0x18, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004112
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304113 tempeax = pVBInfo->VGAVDE;
4114 tempcx |= 0x04000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004115
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304116 if (tempeax <= tempebx) {
4117 tempcx = (tempcx & (~0x4000));
4118 tempeax = pVBInfo->VGAVDE;
4119 } else {
4120 tempeax -= tempebx;
4121 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004122
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304123 templong = (tempeax * 256 * 1024) % tempebx;
4124 tempeax = (tempeax * 256 * 1024) / tempebx;
4125 tempebx = tempeax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004126
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304127 if (templong != 0)
4128 tempebx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004129
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304130 temp = (unsigned short) (tempebx & 0x000000FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004131 xgifb_reg_set(pVBInfo->Part4Port, 0x1B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004132
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304133 temp = (unsigned short) ((tempebx & 0x0000FF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004134 xgifb_reg_set(pVBInfo->Part4Port, 0x1A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304135 tempbx = (unsigned short) (tempebx >> 16);
4136 temp = tempbx & 0x00FF;
4137 temp = temp << 4;
4138 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004139 xgifb_reg_set(pVBInfo->Part4Port, 0x19, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004140
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304141 /* 301b */
Peter Huewe6896b942012-02-09 21:11:46 +01004142 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4143 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304144 temp = 0x0028;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004145 xgifb_reg_set(pVBInfo->Part4Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304146 tempax = pVBInfo->VGAHDE;
4147 if (modeflag & HalfDCLK)
4148 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004149
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304150 if (XGI_IsLCDDualLink(pVBInfo))
4151 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004152
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304153 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4154 if (tempax > 800)
4155 tempax -= 800;
Aaro Koskinend3ae5762012-09-11 00:15:27 +03004156 } else if (pVBInfo->VGAHDE > 800) {
4157 if (pVBInfo->VGAHDE == 1024)
4158 tempax = (tempax * 25 / 32) - 1;
4159 else
4160 tempax = (tempax * 20 / 32) - 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304161 }
4162 tempax -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004163
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304164 temp = (tempax & 0xFF00) >> 8;
4165 temp = ((temp & 0x0003) << 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004166 xgifb_reg_set(pVBInfo->Part4Port, 0x1E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304167 temp = (tempax & 0x00FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004168 xgifb_reg_set(pVBInfo->Part4Port, 0x1D, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004169
Peter Huewe599801f2012-02-09 21:11:45 +01004170 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToHiVision)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304171 if (pVBInfo->VGAHDE > 800)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004172 xgifb_reg_or(pVBInfo->Part4Port, 0x1E, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004173
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304174 }
4175 temp = 0x0036;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004176
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304177 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4178 if (!(pVBInfo->TVInfo & (NTSC1024x768
Peter Huewe599801f2012-02-09 21:11:45 +01004179 | TVSetYPbPr525p | TVSetYPbPr750p
4180 | TVSetHiVision))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304181 temp |= 0x0001;
4182 if ((pVBInfo->VBInfo & SetInSlaveMode)
4183 && (!(pVBInfo->TVInfo
4184 & TVSimuMode)))
4185 temp &= (~0x0001);
4186 }
4187 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004188
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004189 xgifb_reg_and_or(pVBInfo->Part4Port, 0x1F, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304190 tempbx = pVBInfo->HT;
4191 if (XGI_IsLCDDualLink(pVBInfo))
4192 tempbx = tempbx >> 1;
4193 tempbx = (tempbx >> 1) - 2;
4194 temp = ((tempbx & 0x0700) >> 8) << 3;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004195 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304196 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004197 xgifb_reg_set(pVBInfo->Part4Port, 0x22, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304198 }
4199 /* end 301b */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004200
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03004201 XGI_SetCRT2VCLK(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004202}
4203
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004204static void XGINew_EnableCRT2(struct vb_device_info *pVBInfo)
4205{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004206 xgifb_reg_and_or(pVBInfo->P3c4, 0x1E, 0xFF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004207}
4208
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03004209static void XGI_SetGroup5(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004210{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304211 if (pVBInfo->ModeType == ModeVGA) {
4212 if (!(pVBInfo->VBInfo & (SetInSlaveMode | LoadDACFlag
Peter Huewe6896b942012-02-09 21:11:46 +01004213 | DisableCRT2Display))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304214 XGINew_EnableCRT2(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304215 }
4216 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004217}
4218
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004219static void XGI_DisableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304220 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004221{
4222
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004223 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004224}
4225
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004226static unsigned char XGI_XG21CheckLVDSMode(struct xgifb_video_info *xgifb_info,
4227 unsigned short ModeNo, unsigned short ModeIdIndex,
4228 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004229{
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004230 unsigned short xres, yres, colordepth, modeflag, resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004231
Aaro Koskinenb3979922012-11-04 21:14:52 +02004232 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02004233 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
4234 yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004235 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004236 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004237
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304238 if (!(modeflag & Charx8Dot)) {
4239 xres /= 9;
4240 xres *= 8;
4241 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004242
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004243 if ((ModeNo > 0x13) && (modeflag & HalfDCLK))
4244 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004245
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004246 if ((ModeNo > 0x13) && (modeflag & DoubleScanMode))
4247 yres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004248
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004249 if (xres > xgifb_info->lvds_data.LVDSHDE)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304250 return 0;
Bill Pembertondda08c52010-06-17 13:10:42 -04004251
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004252 if (yres > xgifb_info->lvds_data.LVDSVDE)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304253 return 0;
4254
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004255 if (xres != xgifb_info->lvds_data.LVDSHDE ||
4256 yres != xgifb_info->lvds_data.LVDSVDE) {
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03004257 colordepth = XGI_GetColorDepth(ModeIdIndex, pVBInfo);
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004258 if (colordepth > 2)
4259 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304260 }
4261 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004262}
4263
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004264static void xgifb_set_lvds(struct xgifb_video_info *xgifb_info,
4265 int chip_id,
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004266 unsigned short ModeIdIndex,
4267 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004268{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304269 unsigned char temp, Miscdata;
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004270 unsigned short xres, yres, modeflag, resindex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304271 unsigned short LVDSHT, LVDSHBS, LVDSHRS, LVDSHRE, LVDSHBE;
4272 unsigned short LVDSVT, LVDSVBS, LVDSVRS, LVDSVRE, LVDSVBE;
4273 unsigned short value;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004274
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004275 temp = (unsigned char) ((xgifb_info->lvds_data.LVDS_Capability &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004276 (LCDPolarity << 8)) >> 8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304277 temp &= LCDPolarity;
Peter Huewe9388ad92013-02-15 20:37:10 +01004278 Miscdata = inb(pVBInfo->P3cc);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004279
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004280 outb((Miscdata & 0x3F) | temp, pVBInfo->P3c2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004281
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004282 temp = xgifb_info->lvds_data.LVDS_Capability & LCDPolarity;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004283 /* SR35[7] FP VSync polarity */
4284 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x80, temp & 0x80);
4285 /* SR30[5] FP HSync polarity */
4286 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, ~0x20, (temp & 0x40) >> 1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004287
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004288 if (chip_id == XG27)
4289 XGI_SetXG27FPBits(pVBInfo);
4290 else
4291 XGI_SetXG21FPBits(pVBInfo);
4292
Aaro Koskinenb3979922012-11-04 21:14:52 +02004293 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02004294 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
4295 yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004296 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004297 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004298
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304299 if (!(modeflag & Charx8Dot))
4300 xres = xres * 8 / 9;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004301
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004302 LVDSHT = xgifb_info->lvds_data.LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004303
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004304 LVDSHBS = xres + (xgifb_info->lvds_data.LVDSHDE - xres) / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004305
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304306 if (LVDSHBS > LVDSHT)
4307 LVDSHBS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004308
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004309 LVDSHRS = LVDSHBS + xgifb_info->lvds_data.LVDSHFP;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304310 if (LVDSHRS > LVDSHT)
4311 LVDSHRS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004312
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004313 LVDSHRE = LVDSHRS + xgifb_info->lvds_data.LVDSHSYNC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304314 if (LVDSHRE > LVDSHT)
4315 LVDSHRE -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004316
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004317 LVDSHBE = LVDSHBS + LVDSHT - xgifb_info->lvds_data.LVDSHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004318
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004319 LVDSVT = xgifb_info->lvds_data.LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004320
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004321 LVDSVBS = yres + (xgifb_info->lvds_data.LVDSVDE - yres) / 2;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004322 if (modeflag & DoubleScanMode)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304323 LVDSVBS += yres / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004324
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304325 if (LVDSVBS > LVDSVT)
4326 LVDSVBS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004327
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004328 LVDSVRS = LVDSVBS + xgifb_info->lvds_data.LVDSVFP;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304329 if (LVDSVRS > LVDSVT)
4330 LVDSVRS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004331
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004332 LVDSVRE = LVDSVRS + xgifb_info->lvds_data.LVDSVSYNC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304333 if (LVDSVRE > LVDSVT)
4334 LVDSVRE -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004335
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004336 LVDSVBE = LVDSVBS + LVDSVT - xgifb_info->lvds_data.LVDSVDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004337
Peter Huewe9388ad92013-02-15 20:37:10 +01004338 temp = xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004339 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp & 0x7f); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004340
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304341 if (!(modeflag & Charx8Dot))
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004342 xgifb_reg_or(pVBInfo->P3c4, 0x1, 0x1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004343
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304344 /* HT SR0B[1:0] CR00 */
4345 value = (LVDSHT >> 3) - 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004346 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004347 xgifb_reg_set(pVBInfo->P3d4, 0x0, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004348
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304349 /* HBS SR0B[5:4] CR02 */
4350 value = (LVDSHBS >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004351 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x30, (value & 0x300) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004352 xgifb_reg_set(pVBInfo->P3d4, 0x2, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004353
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304354 /* HBE SR0C[1:0] CR05[7] CR03[4:0] */
4355 value = (LVDSHBE >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004356 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x03, (value & 0xC0) >> 6);
4357 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x80, (value & 0x20) << 2);
4358 xgifb_reg_and_or(pVBInfo->P3d4, 0x03, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004359
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304360 /* HRS SR0B[7:6] CR04 */
4361 value = (LVDSHRS >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004362 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0xC0, (value & 0x300) >> 2);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004363 xgifb_reg_set(pVBInfo->P3d4, 0x4, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004364
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304365 /* Panel HRS SR2F[1:0] SR2E[7:0] */
4366 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004367 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004368 xgifb_reg_set(pVBInfo->P3c4, 0x2E, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004369
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304370 /* HRE SR0C[2] CR05[4:0] */
4371 value = (LVDSHRE >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004372 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x04, (value & 0x20) >> 3);
4373 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004374
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304375 /* Panel HRE SR2F[7:2] */
4376 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004377 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0xFC, value << 2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004378
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304379 /* VT SR0A[0] CR07[5][0] CR06 */
4380 value = LVDSVT - 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004381 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x01, (value & 0x400) >> 10);
4382 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x20, (value & 0x200) >> 4);
4383 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x01, (value & 0x100) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004384 xgifb_reg_set(pVBInfo->P3d4, 0x06, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004385
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304386 /* VBS SR0A[2] CR09[5] CR07[3] CR15 */
4387 value = LVDSVBS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004388 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x04, (value & 0x400) >> 8);
4389 xgifb_reg_and_or(pVBInfo->P3d4, 0x09, ~0x20, (value & 0x200) >> 4);
4390 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x08, (value & 0x100) >> 5);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004391 xgifb_reg_set(pVBInfo->P3d4, 0x15, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004392
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304393 /* VBE SR0A[4] CR16 */
4394 value = LVDSVBE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004395 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x10, (value & 0x100) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004396 xgifb_reg_set(pVBInfo->P3d4, 0x16, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004397
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304398 /* VRS SR0A[3] CR7[7][2] CR10 */
4399 value = LVDSVRS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004400 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x08, (value & 0x400) >> 7);
4401 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x80, (value & 0x200) >> 2);
4402 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x04, (value & 0x100) >> 6);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004403 xgifb_reg_set(pVBInfo->P3d4, 0x10, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004404
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004405 if (chip_id == XG27) {
4406 /* Panel VRS SR35[2:0] SR34[7:0] */
4407 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07,
4408 (value & 0x700) >> 8);
4409 xgifb_reg_set(pVBInfo->P3c4, 0x34, value & 0xFF);
4410 } else {
4411 /* Panel VRS SR3F[1:0] SR34[7:0] SR33[0] */
4412 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0x03,
4413 (value & 0x600) >> 9);
4414 xgifb_reg_set(pVBInfo->P3c4, 0x34, (value >> 1) & 0xFF);
4415 xgifb_reg_and_or(pVBInfo->P3d4, 0x33, ~0x01, value & 0x01);
4416 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004417
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304418 /* VRE SR0A[5] CR11[3:0] */
4419 value = LVDSVRE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004420 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x20, (value & 0x10) << 1);
4421 xgifb_reg_and_or(pVBInfo->P3d4, 0x11, ~0x0F, value & 0x0F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004422
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304423 /* Panel VRE SR3F[7:2] */
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004424 if (chip_id == XG27)
4425 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
4426 (value << 2) & 0xFC);
4427 else
4428 /* SR3F[7] has to be 0, h/w bug */
4429 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
4430 (value << 2) & 0x7C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004431
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304432 for (temp = 0, value = 0; temp < 3; temp++) {
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004433
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004434 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, value);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004435 xgifb_reg_set(pVBInfo->P3c4,
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004436 0x2B, xgifb_info->lvds_data.VCLKData1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004437 xgifb_reg_set(pVBInfo->P3c4,
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004438 0x2C, xgifb_info->lvds_data.VCLKData2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304439 value += 0x10;
4440 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004441
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304442 if (!(modeflag & Charx8Dot)) {
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004443 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004444 outb(0x13, pVBInfo->P3c0); /* set index */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004445 /* set data, panning = 0, shift left 1 dot*/
4446 outb(0x00, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004447
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004448 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004449 outb(0x20, pVBInfo->P3c0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304450
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004451 inb(pVBInfo->P3da); /* reset 3da */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304452 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004453
4454}
4455
4456/* --------------------------------------------------------------------- */
4457/* Function : XGI_IsLCDON */
4458/* Input : */
Bill Pembertondda08c52010-06-17 13:10:42 -04004459/* Output : 0 : Skip PSC Control */
4460/* 1: Disable PSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004461/* Description : */
4462/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004463static unsigned char XGI_IsLCDON(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004464{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304465 unsigned short tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004466
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304467 tempax = pVBInfo->VBInfo;
4468 if (tempax & SetCRT2ToDualEdge)
4469 return 0;
Peter Huewe6896b942012-02-09 21:11:46 +01004470 else if (tempax & (DisableCRT2Display | SwitchCRT2 | SetSimuScanMode))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304471 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004472
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304473 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004474}
4475
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004476static void XGI_DisableBridge(struct xgifb_video_info *xgifb_info,
4477 struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304478 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004479{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02004480 unsigned short tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004481
Peter Huewe6896b942012-02-09 21:11:46 +01004482 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4483 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304484 tempah = 0x3F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004485 if (!(pVBInfo->VBInfo &
4486 (DisableCRT2Display | SetSimuScanMode))) {
Peter Huewea3d675c2012-02-09 21:11:47 +01004487 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Aaro Koskinen41fc5f02013-05-29 23:59:12 +03004488 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304489 tempah = 0x7F; /* Disable Channel A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304490 }
4491 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004492
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004493 /* disable part4_1f */
4494 xgifb_reg_and(pVBInfo->Part4Port, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004495
Peter Huewe6896b942012-02-09 21:11:46 +01004496 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004497 if (((pVBInfo->VBInfo &
Peter Huewe06cc47b2013-02-03 22:54:38 +01004498 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))) ||
Peter Huewe06cc47b2013-02-03 22:54:38 +01004499 (XGI_IsLCDON(pVBInfo)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004500 /* LVDS Driver power down */
4501 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304502 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004503
Aaro Koskinend1724632013-05-29 23:59:09 +03004504 if (pVBInfo->VBInfo & (DisableCRT2Display | XGI_SetCRT2ToLCDA |
4505 SetSimuScanMode))
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004506 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004507
Aaro Koskinen41fc5f02013-05-29 23:59:12 +03004508 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
4509 /* Power down */
4510 xgifb_reg_and(pVBInfo->Part1Port, 0x1e, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004511
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004512 /* disable TV as primary VGA swap */
4513 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004514
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304515 if ((pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToDualEdge)))
Aaro Koskinendc505562011-03-13 12:26:26 +02004516 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004517
Aaro Koskinenc4f9c312013-05-29 23:59:07 +03004518 if ((pVBInfo->VBInfo &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004519 (DisableCRT2Display | SetSimuScanMode)) ||
Peter Huewea3d675c2012-02-09 21:11:47 +01004520 ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) &&
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004521 (pVBInfo->VBInfo &
4522 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004523 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004524
Aaro Koskinenc4f9c312013-05-29 23:59:07 +03004525 if ((pVBInfo->VBInfo &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004526 (DisableCRT2Display | SetSimuScanMode)) ||
Peter Huewea3d675c2012-02-09 21:11:47 +01004527 (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) ||
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004528 (pVBInfo->VBInfo &
4529 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))) {
4530 /* save Part1 index 0 */
4531 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
4532 /* BTDAC = 1, avoid VB reset */
4533 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x10);
4534 /* disable CRT2 */
4535 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
4536 /* restore Part1 index 0 */
4537 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304538 }
4539 } else { /* {301} */
4540 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004541 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
4542 /* Disable CRT2 */
4543 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
4544 /* Disable TV asPrimary VGA swap */
4545 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xDF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304546 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004547
Peter Huewea3d675c2012-02-09 21:11:47 +01004548 if (pVBInfo->VBInfo & (DisableCRT2Display | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304549 | SetSimuScanMode))
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004550 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304551 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004552}
4553
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004554/* --------------------------------------------------------------------- */
4555/* Function : XGI_GetTVPtrIndex */
4556/* Input : */
4557/* Output : */
4558/* Description : bx 0 : ExtNTSC */
4559/* 1 : StNTSC */
4560/* 2 : ExtPAL */
4561/* 3 : StPAL */
4562/* 4 : ExtHiTV */
4563/* 5 : StHiTV */
4564/* 6 : Ext525i */
4565/* 7 : St525i */
4566/* 8 : Ext525p */
4567/* 9 : St525p */
4568/* A : Ext750p */
4569/* B : St750p */
4570/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004571static unsigned short XGI_GetTVPtrIndex(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004572{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304573 unsigned short tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004574
Peter Huewe599801f2012-02-09 21:11:45 +01004575 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304576 tempbx = 2;
Peter Huewe599801f2012-02-09 21:11:45 +01004577 if (pVBInfo->TVInfo & TVSetHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304578 tempbx = 4;
Peter Huewe599801f2012-02-09 21:11:45 +01004579 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304580 tempbx = 6;
Peter Huewe599801f2012-02-09 21:11:45 +01004581 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304582 tempbx = 8;
Peter Huewe599801f2012-02-09 21:11:45 +01004583 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304584 tempbx = 10;
4585 if (pVBInfo->TVInfo & TVSimuMode)
4586 tempbx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004587
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304588 return tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004589}
4590
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004591/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004592/* Function : XGI_GetTVPtrIndex2 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004593/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004594/* Output : bx 0 : NTSC */
4595/* 1 : PAL */
4596/* 2 : PALM */
4597/* 3 : PALN */
4598/* 4 : NTSC1024x768 */
4599/* 5 : PAL-M 1024x768 */
4600/* 6-7: reserved */
4601/* cl 0 : YFilter1 */
4602/* 1 : YFilter2 */
4603/* ch 0 : 301A */
4604/* 1 : 301B/302B/301LV/302LV */
4605/* Description : */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004606/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004607static void XGI_GetTVPtrIndex2(unsigned short *tempbx, unsigned char *tempcl,
4608 unsigned char *tempch, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004609{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004610 *tempbx = 0;
4611 *tempcl = 0;
4612 *tempch = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004613
Peter Huewe599801f2012-02-09 21:11:45 +01004614 if (pVBInfo->TVInfo & TVSetPAL)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004615 *tempbx = 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004616
Peter Huewe599801f2012-02-09 21:11:45 +01004617 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004618 *tempbx = 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004619
Peter Huewe599801f2012-02-09 21:11:45 +01004620 if (pVBInfo->TVInfo & TVSetPALN)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004621 *tempbx = 3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004622
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004623 if (pVBInfo->TVInfo & NTSC1024x768) {
4624 *tempbx = 4;
Peter Huewe599801f2012-02-09 21:11:45 +01004625 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004626 *tempbx = 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304627 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004628
Peter Huewe6896b942012-02-09 21:11:46 +01004629 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4630 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004631 if ((!(pVBInfo->VBInfo & SetInSlaveMode)) || (pVBInfo->TVInfo
4632 & TVSimuMode)) {
4633 *tempbx += 8;
4634 *tempcl += 1;
4635 }
4636 }
4637
Peter Huewe6896b942012-02-09 21:11:46 +01004638 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4639 | VB_SIS302LV | VB_XGI301C))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004640 (*tempch)++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004641}
4642
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004643static void XGI_SetDelayComp(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004644{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304645 unsigned char tempah, tempbl, tempbh;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004646
Peter Huewe6896b942012-02-09 21:11:46 +01004647 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4648 | VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01004649 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304650 | SetCRT2ToTV | SetCRT2ToRAMDAC)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304651 tempbh = 0;
Peter Huewe03f76fc2012-06-14 00:21:50 +02004652 tempbl = XGI301TVDelay;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004653
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304654 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
4655 tempbl = tempbl >> 4;
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004656 if (pVBInfo->VBInfo &
4657 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Peter Huewe03f76fc2012-06-14 00:21:50 +02004658 tempbh = XGI301LCDDelay;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004659
Peter Huewea3d675c2012-02-09 21:11:47 +01004660 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304661 tempbl = tempbh;
4662 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004663
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304664 tempbl &= 0x0F;
4665 tempbh &= 0xF0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02004666 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2D);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004667
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304668 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD
4669 | SetCRT2ToTV)) { /* Channel B */
4670 tempah &= 0xF0;
4671 tempah |= tempbl;
4672 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004673
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004674 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
4675 /* Channel A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304676 tempah &= 0x0F;
4677 tempah |= tempbh;
4678 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02004679 xgifb_reg_set(pVBInfo->Part1Port, 0x2D, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304680 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304681 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004682}
4683
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004684static void XGI_SetLCDCap_A(unsigned short tempcx,
4685 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004686{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304687 unsigned short temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004688
Aaro Koskinen58839b02011-03-13 12:26:23 +02004689 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004690
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304691 if (temp & LCDRGB18Bit) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004692 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004693 /* Enable Dither */
4694 (unsigned short) (0x20 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004695 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304696 } else {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004697 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304698 (unsigned short) (0x30 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004699 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304700 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004701}
4702
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004703/* --------------------------------------------------------------------- */
4704/* Function : XGI_SetLCDCap_B */
4705/* Input : cx -> LCD Capability */
4706/* Output : */
4707/* Description : */
4708/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004709static void XGI_SetLCDCap_B(unsigned short tempcx,
4710 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004711{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304712 if (tempcx & EnableLCD24bpp) /* 24bits */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004713 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304714 (unsigned short) (((tempcx & 0x00ff) >> 6)
4715 | 0x0c));
4716 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004717 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304718 (unsigned short) (((tempcx & 0x00ff) >> 6)
4719 | 0x18)); /* Enable Dither */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004720}
4721
Aaro Koskinen7f04ec32011-11-27 23:03:05 +02004722static void XGI_LongWait(struct vb_device_info *pVBInfo)
4723{
4724 unsigned short i;
4725
4726 i = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
4727
4728 if (!(i & 0xC0)) {
4729 for (i = 0; i < 0xFFFF; i++) {
4730 if (!(inb(pVBInfo->P3da) & 0x08))
4731 break;
4732 }
4733
4734 for (i = 0; i < 0xFFFF; i++) {
4735 if ((inb(pVBInfo->P3da) & 0x08))
4736 break;
4737 }
4738 }
4739}
4740
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004741static void SetSpectrum(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004742{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304743 unsigned short index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004744
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304745 index = XGI_GetLCDCapPtr(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004746
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004747 /* disable down spectrum D[4] */
4748 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x8F);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304749 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004750 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x20); /* reset spectrum */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304751 XGI_LongWait(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004752
Aaro Koskinen8104e322011-03-13 12:26:22 +02004753 xgifb_reg_set(pVBInfo->Part4Port, 0x31,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304754 pVBInfo->LCDCapList[index].Spectrum_31);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004755 xgifb_reg_set(pVBInfo->Part4Port, 0x32,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304756 pVBInfo->LCDCapList[index].Spectrum_32);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004757 xgifb_reg_set(pVBInfo->Part4Port, 0x33,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304758 pVBInfo->LCDCapList[index].Spectrum_33);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004759 xgifb_reg_set(pVBInfo->Part4Port, 0x34,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304760 pVBInfo->LCDCapList[index].Spectrum_34);
4761 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004762 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x40); /* enable spectrum */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004763}
4764
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004765static void XGI_SetLCDCap(struct vb_device_info *pVBInfo)
4766{
4767 unsigned short tempcx;
4768
4769 tempcx = pVBInfo->LCDCapList[XGI_GetLCDCapPtr(pVBInfo)].LCD_Capability;
4770
Peter Huewef951dd02013-02-05 00:29:47 +01004771 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV |
4772 VB_SIS302LV | VB_XGI301C)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004773 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01004774 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004775 /* Set 301LV Capability */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004776 xgifb_reg_set(pVBInfo->Part4Port, 0x24,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004777 (unsigned char) (tempcx & 0x1F));
4778 }
4779 /* VB Driving */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004780 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004781 ~((EnableVBCLKDRVLOW | EnablePLLSPLOW) >> 8),
4782 (unsigned short) ((tempcx & (EnableVBCLKDRVLOW
4783 | EnablePLLSPLOW)) >> 8));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004784
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004785 if (pVBInfo->VBInfo & SetCRT2ToLCD)
4786 XGI_SetLCDCap_B(tempcx, pVBInfo);
Peter Huewea3d675c2012-02-09 21:11:47 +01004787 else if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004788 XGI_SetLCDCap_A(tempcx, pVBInfo);
4789
Peter Huewe6896b942012-02-09 21:11:46 +01004790 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004791 if (tempcx & EnableSpectrum)
4792 SetSpectrum(pVBInfo);
4793 }
4794 } else {
4795 /* LVDS,CH7017 */
4796 XGI_SetLCDCap_A(tempcx, pVBInfo);
4797 }
4798}
4799
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004800/* --------------------------------------------------------------------- */
4801/* Function : XGI_SetAntiFlicker */
4802/* Input : */
4803/* Output : */
4804/* Description : Set TV Customized Param. */
4805/* --------------------------------------------------------------------- */
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03004806static void XGI_SetAntiFlicker(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004807{
Aaro Koskinen36ae0352012-04-07 01:14:08 +03004808 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004809
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304810 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004811
Peter Huewe599801f2012-02-09 21:11:45 +01004812 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304813 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004814
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304815 tempbx = XGI_GetTVPtrIndex(pVBInfo);
4816 tempbx &= 0xFE;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304817 tempah = TVAntiFlickList[tempbx];
4818 tempah = tempah << 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004819
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004820 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0x8F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004821}
4822
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03004823static void XGI_SetEdgeEnhance(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004824{
Aaro Koskinen354f49f2012-04-07 01:14:09 +03004825 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004826
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304827 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004828
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304829 tempbx = XGI_GetTVPtrIndex(pVBInfo);
4830 tempbx &= 0xFE;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304831 tempah = TVEdgeList[tempbx];
4832 tempah = tempah << 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004833
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004834 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004835}
4836
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004837static void XGI_SetPhaseIncr(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004838{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304839 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004840
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304841 unsigned char tempcl, tempch;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004842
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304843 unsigned long tempData;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004844
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304845 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
4846 tempData = TVPhaseList[tempbx];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004847
Aaro Koskinen8104e322011-03-13 12:26:22 +02004848 xgifb_reg_set(pVBInfo->Part2Port, 0x31, (unsigned short) (tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304849 & 0x000000FF));
Aaro Koskinen8104e322011-03-13 12:26:22 +02004850 xgifb_reg_set(pVBInfo->Part2Port, 0x32, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304851 & 0x0000FF00) >> 8));
Aaro Koskinen8104e322011-03-13 12:26:22 +02004852 xgifb_reg_set(pVBInfo->Part2Port, 0x33, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304853 & 0x00FF0000) >> 16));
Aaro Koskinen8104e322011-03-13 12:26:22 +02004854 xgifb_reg_set(pVBInfo->Part2Port, 0x34, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304855 & 0xFF000000) >> 24));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004856}
4857
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03004858static void XGI_SetYFilter(unsigned short ModeIdIndex,
4859 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004860{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304861 unsigned short tempbx, index;
Aaro Koskinena68292f2012-11-04 21:15:07 +02004862 unsigned char const *filterPtr;
4863 unsigned char tempcl, tempch, tempal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004864
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304865 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004866
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304867 switch (tempbx) {
4868 case 0x00:
4869 case 0x04:
4870 filterPtr = NTSCYFilter1;
4871 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004872
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304873 case 0x01:
4874 filterPtr = PALYFilter1;
4875 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004876
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304877 case 0x02:
4878 case 0x05:
4879 case 0x0D:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304880 case 0x03:
Aaro Koskinen2555e942011-08-31 21:46:06 +03004881 filterPtr = xgifb_palmn_yfilter1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304882 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004883
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304884 case 0x08:
4885 case 0x0C:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304886 case 0x0A:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304887 case 0x0B:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304888 case 0x09:
Aaro Koskinen80f86f82011-08-31 21:46:05 +03004889 filterPtr = xgifb_yfilter2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304890 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004891
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304892 default:
4893 return;
4894 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004895
Aaro Koskinenb3979922012-11-04 21:14:52 +02004896 tempal = XGI330_EModeIDTable[ModeIdIndex].VB_ExtTVYFilterIndex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304897 if (tempcl == 0)
4898 index = tempal * 4;
4899 else
4900 index = tempal * 7;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004901
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304902 if ((tempcl == 0) && (tempch == 1)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004903 xgifb_reg_set(pVBInfo->Part2Port, 0x35, 0);
4904 xgifb_reg_set(pVBInfo->Part2Port, 0x36, 0);
4905 xgifb_reg_set(pVBInfo->Part2Port, 0x37, 0);
4906 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304907 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004908 xgifb_reg_set(pVBInfo->Part2Port, 0x35, filterPtr[index++]);
4909 xgifb_reg_set(pVBInfo->Part2Port, 0x36, filterPtr[index++]);
4910 xgifb_reg_set(pVBInfo->Part2Port, 0x37, filterPtr[index++]);
4911 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304912 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004913
Peter Huewe6896b942012-02-09 21:11:46 +01004914 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4915 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004916 xgifb_reg_set(pVBInfo->Part2Port, 0x48, filterPtr[index++]);
4917 xgifb_reg_set(pVBInfo->Part2Port, 0x49, filterPtr[index++]);
4918 xgifb_reg_set(pVBInfo->Part2Port, 0x4A, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304919 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004920}
4921
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004922/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004923/* Function : XGI_OEM310Setting */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004924/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004925/* Output : */
4926/* Description : Customized Param. for 301 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004927/* --------------------------------------------------------------------- */
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03004928static void XGI_OEM310Setting(unsigned short ModeIdIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004929 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004930{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004931 XGI_SetDelayComp(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004932
Peter Huewea3d675c2012-02-09 21:11:47 +01004933 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004934 XGI_SetLCDCap(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004935
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004936 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004937 XGI_SetPhaseIncr(pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03004938 XGI_SetYFilter(ModeIdIndex, pVBInfo);
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03004939 XGI_SetAntiFlicker(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004940
Peter Huewe6896b942012-02-09 21:11:46 +01004941 if (pVBInfo->VBType & VB_SIS301)
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03004942 XGI_SetEdgeEnhance(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304943 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004944}
4945
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004946/* --------------------------------------------------------------------- */
4947/* Function : XGI_SetCRT2ModeRegs */
4948/* Input : */
4949/* Output : */
4950/* Description : Origin code for crt2group */
4951/* --------------------------------------------------------------------- */
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03004952static void XGI_SetCRT2ModeRegs(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304953 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004954{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304955 unsigned short tempbl;
4956 short tempcl;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004957
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304958 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004959
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304960 tempah = 0;
4961 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02004962 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304963 tempah &= ~0x10; /* BTRAMDAC */
4964 tempah |= 0x40; /* BTRAM */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004965
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304966 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
4967 | SetCRT2ToLCD)) {
4968 tempah = 0x40; /* BTDRAM */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004969 tempcl = pVBInfo->ModeType;
4970 tempcl -= ModeVGA;
4971 if (tempcl >= 0) {
4972 /* BT Color */
4973 tempah = (0x008 >> tempcl);
4974 if (tempah == 0)
4975 tempah = 1;
4976 tempah |= 0x040;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304977 }
4978 if (pVBInfo->VBInfo & SetInSlaveMode)
4979 tempah ^= 0x50; /* BTDAC */
4980 }
4981 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004982
Aaro Koskinen8104e322011-03-13 12:26:22 +02004983 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304984 tempah = 0x08;
4985 tempbl = 0xf0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004986
Miguel Gómeze123e462012-07-06 12:40:52 +02004987 if (pVBInfo->VBInfo & DisableCRT2Display)
4988 goto reg_and_or;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004989
Miguel Gómeze123e462012-07-06 12:40:52 +02004990 tempah = 0x00;
4991 tempbl = 0xff;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004992
Miguel Gómeze123e462012-07-06 12:40:52 +02004993 if (!(pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV |
4994 SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
4995 goto reg_and_or;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004996
Miguel Gómeze123e462012-07-06 12:40:52 +02004997 if ((pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) &&
4998 (!(pVBInfo->VBInfo & SetSimuScanMode))) {
4999 tempbl &= 0xf7;
5000 tempah |= 0x01;
5001 goto reg_and_or;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305002 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005003
Miguel Gómeze123e462012-07-06 12:40:52 +02005004 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
5005 tempbl &= 0xf7;
5006 tempah |= 0x01;
5007 }
5008
5009 if (!(pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD)))
5010 goto reg_and_or;
5011
5012 tempbl &= 0xf8;
5013 tempah = 0x01;
5014
5015 if (!(pVBInfo->VBInfo & SetInSlaveMode))
5016 tempah |= 0x02;
5017
5018 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
5019 tempah = tempah ^ 0x05;
5020 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
5021 tempah = tempah ^ 0x01;
5022 }
5023
5024 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
5025 tempah |= 0x08;
5026
5027reg_and_or:
5028 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl, tempah);
5029
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305030 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD
Peter Huewea3d675c2012-02-09 21:11:47 +01005031 | XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305032 tempah &= (~0x08);
5033 if ((pVBInfo->ModeType == ModeVGA) && (!(pVBInfo->VBInfo
5034 & SetInSlaveMode))) {
5035 tempah |= 0x010;
5036 }
5037 tempah |= 0x080;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005038
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305039 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305040 tempah |= 0x020;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005041 if (pVBInfo->VBInfo & DriverMode)
5042 tempah = tempah ^ 0x20;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305043 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005044
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005045 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D, ~0x0BF, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305046 tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005047
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305048 if (pVBInfo->LCDInfo & SetLCDDualLink)
5049 tempah |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005050
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305051 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305052 if (pVBInfo->TVInfo & RPLLDIV2XO)
5053 tempah |= 0x40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305054 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005055
Peter Huewe255aabd2012-02-09 21:11:44 +01005056 if ((pVBInfo->LCDResInfo == Panel_1280x1024)
5057 || (pVBInfo->LCDResInfo == Panel_1280x1024x75))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305058 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005059
Peter Huewe255aabd2012-02-09 21:11:44 +01005060 if (pVBInfo->LCDResInfo == Panel_1280x960)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305061 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005062
Aaro Koskinen8104e322011-03-13 12:26:22 +02005063 xgifb_reg_set(pVBInfo->Part4Port, 0x0C, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305064 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005065
Peter Huewe6896b942012-02-09 21:11:46 +01005066 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5067 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305068 tempah = 0;
5069 tempbl = 0xfb;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005070
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305071 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
5072 tempbl = 0xff;
Peter Huewea3d675c2012-02-09 21:11:47 +01005073 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305074 tempah |= 0x04; /* shampoo 0129 */
5075 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005076
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005077 xgifb_reg_and_or(pVBInfo->Part1Port, 0x13, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305078 tempah = 0x00;
5079 tempbl = 0xcf;
5080 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5081 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5082 tempah |= 0x30;
5083 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005084
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005085 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2c, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305086 tempah = 0;
5087 tempbl = 0x3f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005088
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305089 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5090 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5091 tempah |= 0xc0;
5092 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005093 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305094 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005095
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305096 tempah = 0;
5097 tempbl = 0x7f;
Peter Huewea3d675c2012-02-09 21:11:47 +01005098 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305099 tempbl = 0xff;
5100 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
5101 tempah |= 0x80;
5102 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005103
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005104 xgifb_reg_and_or(pVBInfo->Part4Port, 0x23, tempbl, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005105
Peter Huewe6896b942012-02-09 21:11:46 +01005106 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305107 if (pVBInfo->LCDInfo & SetLCDDualLink) {
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005108 xgifb_reg_or(pVBInfo->Part4Port, 0x27, 0x20);
5109 xgifb_reg_or(pVBInfo->Part4Port, 0x34, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305110 }
5111 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005112}
5113
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005114
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305115void XGI_UnLockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
5116 struct vb_device_info *pVBInfo)
5117{
5118
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005119 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2f, 0xFF, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005120
5121}
5122
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305123void XGI_LockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
5124 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005125{
5126
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005127 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2F, 0xFE, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005128
5129}
5130
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005131unsigned short XGI_GetRatePtrCRT2(struct xgi_hw_device_info *pXGIHWDE,
5132 unsigned short ModeNo, unsigned short ModeIdIndex,
5133 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005134{
Peter Huewef2c22602013-02-03 22:54:30 +01005135 const u8 LCDARefreshIndex[] = {
5136 0x00, 0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x00 };
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005137
Peter Hueweef9a6b92013-02-03 04:08:43 +01005138 unsigned short RefreshRateTableIndex, i, index, temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005139
Aaro Koskinen58839b02011-03-13 12:26:23 +02005140 index = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005141 index = index >> pVBInfo->SelectCRT2Rate;
5142 index &= 0x0F;
5143
5144 if (pVBInfo->LCDInfo & LCDNonExpanding)
5145 index = 0;
5146
5147 if (index > 0)
5148 index--;
5149
5150 if (pVBInfo->SetFlag & ProgrammingCRT2) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005151 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinenb0b4a8a2013-05-29 23:59:04 +03005152 temp = LCDARefreshIndex[pVBInfo->LCDResInfo & 0x07];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005153
Aaro Koskinenb0b4a8a2013-05-29 23:59:04 +03005154 if (index > temp)
5155 index = temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005156 }
5157 }
5158
Aaro Koskinenb3979922012-11-04 21:14:52 +02005159 RefreshRateTableIndex = XGI330_EModeIDTable[ModeIdIndex].REFindex;
Aaro Koskinena39325d2012-11-04 21:14:53 +02005160 ModeNo = XGI330_RefIndex[RefreshRateTableIndex].ModeID;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005161 if (pXGIHWDE->jChipType >= XG20) { /* for XG20, XG21, XG27 */
Aaro Koskinena39325d2012-11-04 21:14:53 +02005162 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 800) &&
5163 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 600)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005164 index++;
5165 }
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005166 /* do the similar adjustment like XGISearchCRT1Rate() */
Aaro Koskinena39325d2012-11-04 21:14:53 +02005167 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 1024) &&
5168 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 768)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005169 index++;
5170 }
Aaro Koskinena39325d2012-11-04 21:14:53 +02005171 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 1280) &&
5172 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 1024)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005173 index++;
5174 }
5175 }
5176
5177 i = 0;
5178 do {
Aaro Koskinena39325d2012-11-04 21:14:53 +02005179 if (XGI330_RefIndex[RefreshRateTableIndex + i].
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005180 ModeID != ModeNo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005181 break;
Aaro Koskinena39325d2012-11-04 21:14:53 +02005182 temp = XGI330_RefIndex[RefreshRateTableIndex + i].Ext_InfoFlag;
Peter Huewe6896b942012-02-09 21:11:46 +01005183 temp &= ModeTypeMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005184 if (temp < pVBInfo->ModeType)
5185 break;
5186 i++;
5187 index--;
5188
5189 } while (index != 0xFFFF);
5190 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
5191 if (pVBInfo->VBInfo & SetInSlaveMode) {
Aaro Koskinena39325d2012-11-04 21:14:53 +02005192 temp = XGI330_RefIndex[RefreshRateTableIndex + i - 1].
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005193 Ext_InfoFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005194 if (temp & InterlaceMode)
5195 i++;
5196 }
5197 }
5198 i--;
5199 if ((pVBInfo->SetFlag & ProgrammingCRT2)) {
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005200 temp = XGI_AjustCRT2Rate(ModeIdIndex, RefreshRateTableIndex,
5201 &i, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005202 }
Aaro Koskinen9a0b2952011-11-27 23:03:16 +02005203 return RefreshRateTableIndex + i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005204}
5205
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005206static void XGI_SetLCDAGroup(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305207 struct xgi_hw_device_info *HwDeviceExtension,
5208 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005209{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005210 unsigned short RefreshRateTableIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005211
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005212 pVBInfo->SetFlag |= ProgrammingCRT2;
5213 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5214 ModeIdIndex, pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005215 XGI_GetLVDSResInfo(ModeIdIndex, pVBInfo);
5216 XGI_GetLVDSData(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5217 XGI_ModCRT1Regs(ModeIdIndex, RefreshRateTableIndex, HwDeviceExtension,
5218 pVBInfo);
5219 XGI_SetLVDSRegs(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5220 XGI_SetCRT2ECLK(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005221}
5222
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02005223static unsigned char XGI_SetCRT2Group301(unsigned short ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005224 struct xgi_hw_device_info *HwDeviceExtension,
5225 struct vb_device_info *pVBInfo)
5226{
Peter Huewea9e29e62013-02-03 04:08:44 +01005227 unsigned short ModeIdIndex, RefreshRateTableIndex;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005228
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005229 pVBInfo->SetFlag |= ProgrammingCRT2;
5230 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
5231 pVBInfo->SelectCRT2Rate = 4;
5232 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5233 ModeIdIndex, pVBInfo);
5234 XGI_SaveCRT2Info(ModeNo, pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005235 XGI_GetCRT2ResInfo(ModeIdIndex, pVBInfo);
5236 XGI_GetCRT2Data(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005237 XGI_PreSetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
5238 RefreshRateTableIndex, pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005239 XGI_SetGroup1(ModeIdIndex, HwDeviceExtension, RefreshRateTableIndex,
5240 pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005241 XGI_SetLockRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
5242 RefreshRateTableIndex, pVBInfo);
5243 XGI_SetGroup2(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5244 HwDeviceExtension, pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005245 XGI_SetLCDRegs(ModeIdIndex, HwDeviceExtension, RefreshRateTableIndex,
5246 pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005247 XGI_SetTap4Regs(pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005248 XGI_SetGroup3(ModeIdIndex, pVBInfo);
5249 XGI_SetGroup4(ModeIdIndex, RefreshRateTableIndex, HwDeviceExtension,
5250 pVBInfo);
5251 XGI_SetCRT2VCLK(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03005252 XGI_SetGroup5(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005253 XGI_AutoThreshold(pVBInfo);
5254 return 1;
5255}
5256
5257void XGI_SenseCRT1(struct vb_device_info *pVBInfo)
5258{
5259 unsigned char CRTCData[17] = { 0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81,
5260 0x0B, 0x3E, 0xE9, 0x0B, 0xDF, 0xE7, 0x04, 0x00, 0x00,
5261 0x05, 0x00 };
5262
5263 unsigned char SR01 = 0, SR1F = 0, SR07 = 0, SR06 = 0;
5264
5265 unsigned char CR17, CR63, SR31;
5266 unsigned short temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005267
5268 int i;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005269 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005270
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005271 /* to fix XG42 single LCD sense to CRT+LCD */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005272 xgifb_reg_set(pVBInfo->P3d4, 0x57, 0x4A);
Peter Huewe9388ad92013-02-15 20:37:10 +01005273 xgifb_reg_set(pVBInfo->P3d4, 0x53, (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005274 pVBInfo->P3d4, 0x53) | 0x02));
5275
Peter Huewe9388ad92013-02-15 20:37:10 +01005276 SR31 = xgifb_reg_get(pVBInfo->P3c4, 0x31);
5277 CR63 = xgifb_reg_get(pVBInfo->P3d4, 0x63);
5278 SR01 = xgifb_reg_get(pVBInfo->P3c4, 0x01);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005279
Aaro Koskinen8104e322011-03-13 12:26:22 +02005280 xgifb_reg_set(pVBInfo->P3c4, 0x01, (unsigned char) (SR01 & 0xDF));
5281 xgifb_reg_set(pVBInfo->P3d4, 0x63, (unsigned char) (CR63 & 0xBF));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005282
Peter Huewe9388ad92013-02-15 20:37:10 +01005283 CR17 = xgifb_reg_get(pVBInfo->P3d4, 0x17);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005284 xgifb_reg_set(pVBInfo->P3d4, 0x17, (unsigned char) (CR17 | 0x80));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005285
Peter Huewe9388ad92013-02-15 20:37:10 +01005286 SR1F = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005287 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) (SR1F | 0x04));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005288
Peter Huewe9388ad92013-02-15 20:37:10 +01005289 SR07 = xgifb_reg_get(pVBInfo->P3c4, 0x07);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005290 xgifb_reg_set(pVBInfo->P3c4, 0x07, (unsigned char) (SR07 & 0xFB));
Peter Huewe9388ad92013-02-15 20:37:10 +01005291 SR06 = xgifb_reg_get(pVBInfo->P3c4, 0x06);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005292 xgifb_reg_set(pVBInfo->P3c4, 0x06, (unsigned char) (SR06 & 0xC3));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005293
Aaro Koskinen8104e322011-03-13 12:26:22 +02005294 xgifb_reg_set(pVBInfo->P3d4, 0x11, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005295
5296 for (i = 0; i < 8; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005297 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) i, CRTCData[i]);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005298
5299 for (i = 8; i < 11; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005300 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 8),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005301 CRTCData[i]);
5302
5303 for (i = 11; i < 13; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005304 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 4),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005305 CRTCData[i]);
5306
5307 for (i = 13; i < 16; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005308 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i - 3),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005309 CRTCData[i]);
5310
Aaro Koskinen8104e322011-03-13 12:26:22 +02005311 xgifb_reg_set(pVBInfo->P3c4, 0x0E, (unsigned char) (CRTCData[16]
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005312 & 0xE0));
5313
Aaro Koskinen8104e322011-03-13 12:26:22 +02005314 xgifb_reg_set(pVBInfo->P3c4, 0x31, 0x00);
5315 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x1B);
5316 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE1);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005317
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005318 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005319
Peter Huewe771f3ee2013-02-15 20:37:13 +01005320 for (i = 0; i < 256 * 3; i++) {
5321 outb(0x0F, (pVBInfo->P3c8 + 1)); /* DAC_TEST_PARMS */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005322 }
5323
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005324 mdelay(1);
5325
5326 XGI_WaitDisply(pVBInfo);
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02005327 temp = inb(pVBInfo->P3c2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005328
5329 if (temp & 0x10)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005330 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005331 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005332 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005333
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005334 /* avoid display something, set BLACK DAC if not restore DAC */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005335 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005336
Peter Huewe771f3ee2013-02-15 20:37:13 +01005337 for (i = 0; i < 256 * 3; i++) {
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005338 outb(0, (pVBInfo->P3c8 + 1));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005339 }
5340
Aaro Koskinen8104e322011-03-13 12:26:22 +02005341 xgifb_reg_set(pVBInfo->P3c4, 0x01, SR01);
5342 xgifb_reg_set(pVBInfo->P3d4, 0x63, CR63);
5343 xgifb_reg_set(pVBInfo->P3c4, 0x31, SR31);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005344
Peter Huewe9388ad92013-02-15 20:37:10 +01005345 xgifb_reg_set(pVBInfo->P3d4, 0x53, (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005346 pVBInfo->P3d4, 0x53) & 0xFD));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005347 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) SR1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005348}
5349
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005350static void XGI_EnableBridge(struct xgifb_video_info *xgifb_info,
5351 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005352 struct vb_device_info *pVBInfo)
5353{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02005354 unsigned short tempah;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005355
Peter Huewe6896b942012-02-09 21:11:46 +01005356 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5357 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinena2526d12013-05-29 23:59:10 +03005358 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
Aaro Koskinend1724632013-05-29 23:59:09 +03005359 /* Power on */
5360 xgifb_reg_set(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005361
Aaro Koskinenb8e34b32013-05-29 23:59:08 +03005362 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV |
5363 SetCRT2ToRAMDAC)) {
Aaro Koskinenc4f9c312013-05-29 23:59:07 +03005364 tempah = xgifb_reg_get(pVBInfo->P3c4, 0x32);
5365 tempah &= 0xDF;
5366 if (pVBInfo->VBInfo & SetInSlaveMode) {
5367 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC))
5368 tempah |= 0x20;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005369 }
Aaro Koskinenc4f9c312013-05-29 23:59:07 +03005370 xgifb_reg_set(pVBInfo->P3c4, 0x32, tempah);
5371 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x20);
5372
5373 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2E);
5374
5375 if (!(tempah & 0x80))
5376 xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80);
5377 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005378 }
5379
Aaro Koskinena2526d12013-05-29 23:59:10 +03005380 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005381 xgifb_reg_and_or(pVBInfo->Part2Port, 0x00, ~0xE0,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005382 0x20); /* shampoo 0129 */
Peter Huewe6896b942012-02-09 21:11:46 +01005383 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinen056b5402013-05-29 23:59:11 +03005384 if (pVBInfo->VBInfo &
5385 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
5386 /* LVDS PLL power on */
5387 xgifb_reg_and(pVBInfo->Part4Port, 0x2A,
5388 0x7F);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005389 /* LVDS Driver power on */
5390 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005391 }
5392 }
5393
5394 tempah = 0x00;
5395
5396 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5397 tempah = 0xc0;
5398
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005399 if (!(pVBInfo->VBInfo & SetSimuScanMode) &&
5400 (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) &&
5401 (pVBInfo->VBInfo & SetCRT2ToDualEdge)) {
5402 tempah = tempah & 0x40;
5403 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
5404 tempah = tempah ^ 0xC0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005405 }
5406 }
5407
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005408 /* EnablePart4_1F */
5409 xgifb_reg_or(pVBInfo->Part4Port, 0x1F, tempah);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005410
Aaro Koskinend1724632013-05-29 23:59:09 +03005411 XGI_DisableGatingCRT(HwDeviceExtension, pVBInfo);
5412 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005413 } /* 301 */
5414 else { /* LVDS */
5415 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD
Peter Huewea3d675c2012-02-09 21:11:47 +01005416 | XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005417 /* enable CRT2 */
5418 xgifb_reg_or(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005419
Peter Huewe9388ad92013-02-15 20:37:10 +01005420 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2E);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005421 if (!(tempah & 0x80))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005422 xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005423
Aaro Koskinendc505562011-03-13 12:26:26 +02005424 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005425 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005426 } /* End of VB */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005427}
5428
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005429static void XGI_SetCRT1Group(struct xgifb_video_info *xgifb_info,
5430 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005431 unsigned short ModeNo, unsigned short ModeIdIndex,
5432 struct vb_device_info *pVBInfo)
5433{
Aaro Koskinena1579612012-04-07 01:14:05 +03005434 unsigned short RefreshRateTableIndex, temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005435
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03005436 XGI_SetSeqRegs(pVBInfo);
Aaro Koskinen3625c9a2012-11-04 21:14:51 +02005437 outb(XGI330_StandTable.MISC, pVBInfo->P3c2);
Aaro Koskinena1579612012-04-07 01:14:05 +03005438 XGI_SetCRTCRegs(HwDeviceExtension, pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005439 XGI_SetATTRegs(ModeIdIndex, pVBInfo);
Aaro Koskinena1579612012-04-07 01:14:05 +03005440 XGI_SetGRCRegs(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005441 XGI_ClearExt1Regs(pVBInfo);
5442
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005443 if (HwDeviceExtension->jChipType == XG27) {
5444 if (pVBInfo->IF_DEF_LVDS == 0)
5445 XGI_SetDefaultVCLK(pVBInfo);
5446 }
5447
5448 temp = ~ProgrammingCRT2;
5449 pVBInfo->SetFlag &= temp;
5450 pVBInfo->SelectCRT2Rate = 0;
5451
Peter Huewe6896b942012-02-09 21:11:46 +01005452 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5453 | VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005454 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005455 | SetInSlaveMode)) {
5456 pVBInfo->SetFlag |= ProgrammingCRT2;
5457 }
5458 }
5459
5460 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5461 ModeIdIndex, pVBInfo);
5462 if (RefreshRateTableIndex != 0xFFFF) {
5463 XGI_SetSync(RefreshRateTableIndex, pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005464 XGI_SetCRT1CRTC(ModeIdIndex, RefreshRateTableIndex,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005465 pVBInfo, HwDeviceExtension);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005466 XGI_SetCRT1DE(HwDeviceExtension, ModeIdIndex,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005467 RefreshRateTableIndex, pVBInfo);
5468 XGI_SetCRT1Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5469 HwDeviceExtension, pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005470 XGI_SetCRT1VCLK(ModeIdIndex, HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005471 RefreshRateTableIndex, pVBInfo);
5472 }
5473
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005474 if (HwDeviceExtension->jChipType >= XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005475 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005476 if (temp & 0xA0) {
5477
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005478 if (HwDeviceExtension->jChipType == XG27)
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03005479 XGI_SetXG27CRTC(RefreshRateTableIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005480 else
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03005481 XGI_SetXG21CRTC(RefreshRateTableIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005482
5483 XGI_UpdateXG21CRTC(ModeNo, pVBInfo,
5484 RefreshRateTableIndex);
5485
Aaro Koskinen105d8d02011-08-31 21:46:00 +03005486 xgifb_set_lcd(HwDeviceExtension->jChipType,
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005487 pVBInfo, RefreshRateTableIndex);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005488
Aaro Koskinen64db29f2011-08-31 21:46:01 +03005489 if (pVBInfo->IF_DEF_LVDS == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005490 xgifb_set_lvds(xgifb_info,
5491 HwDeviceExtension->jChipType,
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005492 ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005493 }
5494 }
5495
5496 pVBInfo->SetFlag &= (~ProgrammingCRT2);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005497 XGI_SetCRT1FIFO(HwDeviceExtension, pVBInfo);
5498 XGI_SetCRT1ModeRegs(HwDeviceExtension, ModeIdIndex,
5499 RefreshRateTableIndex, pVBInfo);
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03005500 XGI_LoadDAC(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005501}
5502
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005503unsigned char XGISetModeNew(struct xgifb_video_info *xgifb_info,
5504 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005505 unsigned short ModeNo)
5506{
5507 unsigned short ModeIdIndex;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005508 struct vb_device_info VBINF;
5509 struct vb_device_info *pVBInfo = &VBINF;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005510 pVBInfo->IF_DEF_LVDS = 0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005511
Aaro Koskinenee768752013-05-29 23:59:16 +03005512 if (HwDeviceExtension->jChipType >= XG20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005513 pVBInfo->VBType = 0; /*set VBType default 0*/
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005514
Aaro Koskinen56810a92013-01-21 02:57:47 +02005515 XGIRegInit(pVBInfo, xgifb_info->vga_base);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005516
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005517 /* for x86 Linux, XG21 LVDS */
5518 if (HwDeviceExtension->jChipType == XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005519 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005520 pVBInfo->IF_DEF_LVDS = 1;
5521 }
5522 if (HwDeviceExtension->jChipType == XG27) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005523 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0) {
5524 if (xgifb_reg_get(pVBInfo->P3d4, 0x30) & 0x20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005525 pVBInfo->IF_DEF_LVDS = 1;
5526 }
5527 }
5528
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005529 InitTo330Pointer(HwDeviceExtension->jChipType, pVBInfo);
Aaro Koskinenef497f42011-11-27 23:03:21 +02005530 if (ModeNo & 0x80)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005531 ModeNo = ModeNo & 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005532 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005533
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005534 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005535 XGI_UnLockCRT2(HwDeviceExtension, pVBInfo);
5536
5537 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
5538
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005539 if (HwDeviceExtension->jChipType < XG20) {
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005540 XGI_GetVBInfo(ModeIdIndex, HwDeviceExtension, pVBInfo);
5541 XGI_GetTVInfo(ModeIdIndex, pVBInfo);
5542 XGI_GetLCDInfo(ModeIdIndex, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005543 XGI_DisableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005544
Peter Huewee44adfd2013-02-03 22:54:39 +01005545 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA) ||
5546 (!(pVBInfo->VBInfo & SwitchCRT2))) {
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005547 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005548 ModeIdIndex, pVBInfo);
5549
Peter Huewea3d675c2012-02-09 21:11:47 +01005550 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005551 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
5552 HwDeviceExtension, pVBInfo);
5553 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005554 }
5555
Peter Huewe6896b942012-02-09 21:11:46 +01005556 if (pVBInfo->VBInfo & (SetSimuScanMode | SwitchCRT2)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005557 switch (HwDeviceExtension->ujVBChipID) {
Peter Huewee44adfd2013-02-03 22:54:39 +01005558 case VB_CHIP_301: /* fall through */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005559 case VB_CHIP_302:
5560 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
5561 pVBInfo); /*add for CRT2 */
5562 break;
5563
5564 default:
5565 break;
5566 }
5567 }
5568
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005569 XGI_SetCRT2ModeRegs(HwDeviceExtension, pVBInfo);
5570 XGI_OEM310Setting(ModeIdIndex, pVBInfo); /*0212*/
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005571 XGI_EnableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005572 } /* !XG20 */
5573 else {
5574 if (pVBInfo->IF_DEF_LVDS == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005575 if (!XGI_XG21CheckLVDSMode(xgifb_info, ModeNo,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005576 ModeIdIndex,
5577 pVBInfo))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005578 return 0;
5579
Aaro Koskinenb3979922012-11-04 21:14:52 +02005580 pVBInfo->ModeType = XGI330_EModeIDTable[ModeIdIndex].
Peter Huewe6896b942012-02-09 21:11:46 +01005581 Ext_ModeFlag & ModeTypeMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005582
5583 pVBInfo->SetFlag = 0;
Aaro Koskinen83f76a92011-08-31 21:45:58 +03005584 pVBInfo->VBInfo = DisableCRT2Display;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005585
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005586 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005587
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005588 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
5589 ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005590
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005591 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005592 }
5593
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005594 XGI_UpdateModeInfo(HwDeviceExtension, pVBInfo);
5595
Miguel Gómez3bcc2462012-07-06 12:40:53 +02005596 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005597 XGI_LockCRT2(HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005598
5599 return 1;
5600}