blob: 814216735819e35f4caecfe039b976d9ed6ac133 [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
Kenji Toyama1d7f6562011-04-23 19:36:49 +080066static void XGI_SetSeqRegs(unsigned short ModeNo,
Kenji Toyama1d7f6562011-04-23 19:36:49 +080067 unsigned short ModeIdIndex,
68 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020069{
Peter Huewe76a58992013-02-03 22:54:34 +010070 unsigned char SRdata, i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020071
Aaro Koskinen8104e322011-03-13 12:26:22 +020072 xgifb_reg_set(pVBInfo->P3c4, 0x00, 0x03); /* Set SR0 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020073
Peter Huewe76a58992013-02-03 22:54:34 +010074 for (i = 0; i < 4; i++) {
75 /* Get SR1,2,3,4 from file */
76 /* SR1 is with screen off 0x20 */
77 SRdata = XGI330_StandTable.SR[i];
78 xgifb_reg_set(pVBInfo->P3c4, i+1, SRdata); /* Set SR 1 2 3 4 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053079 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020080}
81
Aaro Koskinen063b9c42011-03-08 22:16:13 +020082static void XGI_SetCRTCRegs(struct xgi_hw_device_info *HwDeviceExtension,
Kenji Toyama1d7f6562011-04-23 19:36:49 +080083 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020084{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053085 unsigned char CRTCdata;
86 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020087
Peter Huewe9388ad92013-02-15 20:37:10 +010088 CRTCdata = xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053089 CRTCdata &= 0x7f;
Aaro Koskinen8104e322011-03-13 12:26:22 +020090 xgifb_reg_set(pVBInfo->P3d4, 0x11, CRTCdata); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020091
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053092 for (i = 0; i <= 0x18; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +080093 /* Get CRTC from file */
Aaro Koskinen3625c9a2012-11-04 21:14:51 +020094 CRTCdata = XGI330_StandTable.CRTC[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +020095 xgifb_reg_set(pVBInfo->P3d4, i, CRTCdata); /* Set CRTC(3d4) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053096 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020097}
98
Kenji Toyama1d7f6562011-04-23 19:36:49 +080099static void XGI_SetATTRegs(unsigned short ModeNo,
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800100 unsigned short ModeIdIndex,
101 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200102{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530103 unsigned char ARdata;
104 unsigned short i, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200105
Aaro Koskinenb3979922012-11-04 21:14:52 +0200106 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200107
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530108 for (i = 0; i <= 0x13; i++) {
Aaro Koskinen3625c9a2012-11-04 21:14:51 +0200109 ARdata = XGI330_StandTable.ATTR[i];
Miguel Gómez661a6382012-07-06 12:40:45 +0200110
111 if ((modeflag & Charx8Dot) && i == 0x13) { /* ifndef Dot9 */
112 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
113 ARdata = 0;
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300114 } else if ((pVBInfo->VBInfo &
Miguel Gómez661a6382012-07-06 12:40:45 +0200115 (SetCRT2ToTV | SetCRT2ToLCD)) &&
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300116 (pVBInfo->VBInfo & SetInSlaveMode)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530117 ARdata = 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530118 }
119 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200120
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200121 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200122 outb(i, pVBInfo->P3c0); /* set index */
123 outb(ARdata, pVBInfo->P3c0); /* set data */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530124 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200125
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200126 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200127 outb(0x14, pVBInfo->P3c0); /* set index */
128 outb(0x00, pVBInfo->P3c0); /* set data */
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200129 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200130 outb(0x20, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200131}
132
Aaro Koskinena1579612012-04-07 01:14:05 +0300133static void XGI_SetGRCRegs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200134{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530135 unsigned char GRdata;
136 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200137
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530138 for (i = 0; i <= 0x08; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800139 /* Get GR from file */
Aaro Koskinen3625c9a2012-11-04 21:14:51 +0200140 GRdata = XGI330_StandTable.GRC[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200141 xgifb_reg_set(pVBInfo->P3ce, i, GRdata); /* Set GR(3ce) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530142 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200143
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530144 if (pVBInfo->ModeType > ModeVGA) {
Peter Huewe9388ad92013-02-15 20:37:10 +0100145 GRdata = xgifb_reg_get(pVBInfo->P3ce, 0x05);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530146 GRdata &= 0xBF; /* 256 color disable */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200147 xgifb_reg_set(pVBInfo->P3ce, 0x05, GRdata);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530148 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200149}
150
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200151static void XGI_ClearExt1Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200152{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530153 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200154
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530155 for (i = 0x0A; i <= 0x0E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +0200156 xgifb_reg_set(pVBInfo->P3c4, i, 0x00); /* Clear SR0A-SR0E */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200157}
158
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200159static unsigned char XGI_SetDefaultVCLK(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200160{
161
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200162 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x20);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200163 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[0].SR2B);
164 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[0].SR2C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200165
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200166 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x10);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200167 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[1].SR2B);
168 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[1].SR2C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200169
Aaro Koskinendc505562011-03-13 12:26:26 +0200170 xgifb_reg_and(pVBInfo->P3c4, 0x31, ~0x30);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530171 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200172}
173
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200174static unsigned char XGI_AjustCRT2Rate(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530175 unsigned short ModeIdIndex,
176 unsigned short RefreshRateTableIndex, unsigned short *i,
177 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200178{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530179 unsigned short tempax, tempbx, resinfo, modeflag, infoflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200180
Aaro Koskinenb3979922012-11-04 21:14:52 +0200181 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
182 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinena39325d2012-11-04 21:14:53 +0200183 tempbx = XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530184 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200185
Aaro Koskinen0903b0d2013-05-29 23:59:03 +0300186 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
187 tempax |= SupportRAMDAC2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200188
Aaro Koskinen0903b0d2013-05-29 23:59:03 +0300189 if (pVBInfo->VBType & VB_XGI301C)
190 tempax |= SupportCRT2in301C;
191 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200192
Aaro Koskinen0903b0d2013-05-29 23:59:03 +0300193 /* 301b */
194 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300195 tempax |= SupportLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200196
Aaro Koskinen0903b0d2013-05-29 23:59:03 +0300197 if (pVBInfo->LCDResInfo != Panel_1280x1024 &&
198 pVBInfo->LCDResInfo != Panel_1280x960 &&
199 (pVBInfo->LCDInfo & LCDNonExpanding) &&
200 resinfo >= 9)
201 return 0;
202 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200203
Aaro Koskinen0903b0d2013-05-29 23:59:03 +0300204 if (pVBInfo->VBInfo & SetCRT2ToHiVision) { /* for HiTV */
205 tempax |= SupportHiVision;
206 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
207 ((resinfo == 4) ||
208 (resinfo == 3 && (pVBInfo->SetFlag & TVSimuMode)) ||
209 (resinfo > 7)))
210 return 0;
211 } else if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO | SetCRT2ToSVIDEO |
212 SetCRT2ToSCART | SetCRT2ToYPbPr525750 |
213 SetCRT2ToHiVision)) {
214 tempax |= SupportTV;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200215
Aaro Koskinen0903b0d2013-05-29 23:59:03 +0300216 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV |
217 VB_SIS302LV | VB_XGI301C))
218 tempax |= SupportTV1024;
219
220 if (!(pVBInfo->VBInfo & TVSetPAL) &&
221 (modeflag & NoSupportSimuTV) &&
222 (pVBInfo->VBInfo & SetInSlaveMode) &&
223 (!(pVBInfo->VBInfo & SetNotSimuMode)))
224 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530225 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200226
Aaro Koskinena39325d2012-11-04 21:14:53 +0200227 for (; XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID ==
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800228 tempbx; (*i)--) {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200229 infoflag = XGI330_RefIndex[RefreshRateTableIndex + (*i)].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800230 Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530231 if (infoflag & tempax)
232 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200233
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530234 if ((*i) == 0)
235 break;
236 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200237
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530238 for ((*i) = 0;; (*i)++) {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200239 infoflag = XGI330_RefIndex[RefreshRateTableIndex + (*i)].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800240 Ext_InfoFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +0200241 if (XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530242 != tempbx) {
243 return 0;
244 }
245
246 if (infoflag & tempax)
247 return 1;
248 }
249 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200250}
251
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200252static void XGI_SetSync(unsigned short RefreshRateTableIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530253 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200254{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530255 unsigned short sync, temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200256
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800257 /* di+0x00 */
Aaro Koskinena39325d2012-11-04 21:14:53 +0200258 sync = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag >> 8;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530259 sync &= 0xC0;
260 temp = 0x2F;
261 temp |= sync;
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200262 outb(temp, pVBInfo->P3c2); /* Set Misc(3c2) */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200263}
264
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200265static void XGI_SetCRT1Timing_H(struct vb_device_info *pVBInfo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530266 struct xgi_hw_device_info *HwDeviceExtension)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200267{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530268 unsigned char data, data1, pushax;
269 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200270
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800271 /* unlock cr0-7 */
Peter Huewe9388ad92013-02-15 20:37:10 +0100272 data = xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530273 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200274 xgifb_reg_set(pVBInfo->P3d4, 0x11, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200275
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200276 data = pVBInfo->TimingH.data[0];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200277 xgifb_reg_set(pVBInfo->P3d4, 0, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200278
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530279 for (i = 0x01; i <= 0x04; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200280 data = pVBInfo->TimingH.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200281 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 1), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530282 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200283
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530284 for (i = 0x05; i <= 0x06; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200285 data = pVBInfo->TimingH.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200286 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i + 6), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530287 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200288
Peter Huewe9388ad92013-02-15 20:37:10 +0100289 j = xgifb_reg_get(pVBInfo->P3c4, 0x0e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530290 j &= 0x1F;
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200291 data = pVBInfo->TimingH.data[7];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530292 data &= 0xE0;
293 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200294 xgifb_reg_set(pVBInfo->P3c4, 0x0e, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200295
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530296 if (HwDeviceExtension->jChipType >= XG20) {
Peter Huewe9388ad92013-02-15 20:37:10 +0100297 data = xgifb_reg_get(pVBInfo->P3d4, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530298 data = data - 1;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200299 xgifb_reg_set(pVBInfo->P3d4, 0x04, data);
Peter Huewe9388ad92013-02-15 20:37:10 +0100300 data = xgifb_reg_get(pVBInfo->P3d4, 0x05);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530301 data1 = data;
302 data1 &= 0xE0;
303 data &= 0x1F;
304 if (data == 0) {
305 pushax = data;
Peter Huewe9388ad92013-02-15 20:37:10 +0100306 data = xgifb_reg_get(pVBInfo->P3c4, 0x0c);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530307 data &= 0xFB;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200308 xgifb_reg_set(pVBInfo->P3c4, 0x0c, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530309 data = pushax;
310 }
311 data = data - 1;
312 data |= data1;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200313 xgifb_reg_set(pVBInfo->P3d4, 0x05, data);
Peter Huewe9388ad92013-02-15 20:37:10 +0100314 data = xgifb_reg_get(pVBInfo->P3c4, 0x0e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530315 data = data >> 5;
316 data = data + 3;
317 if (data > 7)
318 data = data - 7;
319 data = data << 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200320 xgifb_reg_and_or(pVBInfo->P3c4, 0x0e, ~0xE0, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530321 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200322}
323
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800324static void XGI_SetCRT1Timing_V(unsigned short ModeIdIndex,
325 unsigned short ModeNo,
326 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200327{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530328 unsigned char data;
329 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200330
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530331 for (i = 0x00; i <= 0x01; 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 + 6), 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 = 0x02; i <= 0x03; 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 + 0x0e), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530339 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200340
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530341 for (i = 0x04; i <= 0x05; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200342 data = pVBInfo->TimingV.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200343 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x11), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530344 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200345
Peter Huewe9388ad92013-02-15 20:37:10 +0100346 j = xgifb_reg_get(pVBInfo->P3c4, 0x0a);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530347 j &= 0xC0;
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200348 data = pVBInfo->TimingV.data[6];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530349 data &= 0x3F;
350 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200351 xgifb_reg_set(pVBInfo->P3c4, 0x0a, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200352
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200353 data = pVBInfo->TimingV.data[6];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530354 data &= 0x80;
355 data = data >> 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200356
Aaro Koskinenb3979922012-11-04 21:14:52 +0200357 i = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530358 i &= DoubleScanMode;
359 if (i)
360 data |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200361
Peter Huewe9388ad92013-02-15 20:37:10 +0100362 j = xgifb_reg_get(pVBInfo->P3d4, 0x09);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530363 j &= 0x5F;
364 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200365 xgifb_reg_set(pVBInfo->P3d4, 0x09, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200366}
367
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200368static void XGI_SetCRT1CRTC(unsigned short ModeNo, unsigned short ModeIdIndex,
369 unsigned short RefreshRateTableIndex,
370 struct vb_device_info *pVBInfo,
371 struct xgi_hw_device_info *HwDeviceExtension)
372{
373 unsigned char index, data;
374 unsigned short i;
375
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800376 /* Get index */
Aaro Koskinena39325d2012-11-04 21:14:53 +0200377 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200378 index = index & IndexMask;
379
Peter Huewe9388ad92013-02-15 20:37:10 +0100380 data = xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200381 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200382 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200383
384 for (i = 0; i < 8; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200385 pVBInfo->TimingH.data[i]
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200386 = XGI_CRT1Table[index].CR[i];
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200387
388 for (i = 0; i < 7; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200389 pVBInfo->TimingV.data[i]
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200390 = XGI_CRT1Table[index].CR[i + 8];
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200391
392 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
393
394 XGI_SetCRT1Timing_V(ModeIdIndex, ModeNo, pVBInfo);
395
396 if (pVBInfo->ModeType > 0x03)
Aaro Koskinen8104e322011-03-13 12:26:22 +0200397 xgifb_reg_set(pVBInfo->P3d4, 0x14, 0x4F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200398}
399
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200400/* --------------------------------------------------------------------- */
401/* Function : XGI_SetXG21CRTC */
402/* Input : Stand or enhance CRTC table */
403/* Output : Fill CRT Hsync/Vsync to SR2E/SR2F/SR30/SR33/SR34/SR3F */
404/* Description : Set LCD timing */
405/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200406static void XGI_SetXG21CRTC(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530407 unsigned short RefreshRateTableIndex,
408 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200409{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300410 unsigned char index, Tempax, Tempbx, Tempcx, Tempdx;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530411 unsigned short Temp1, Temp2, Temp3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200412
Aaro Koskinena39325d2012-11-04 21:14:53 +0200413 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300414 /* Tempax: CR4 HRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200415 Tempax = XGI_CRT1Table[index].CR[3];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300416 Tempcx = Tempax; /* Tempcx: HRS */
417 /* SR2E[7:0]->HRS */
418 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200419
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200420 Tempdx = XGI_CRT1Table[index].CR[5]; /* SRB */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300421 Tempdx &= 0xC0; /* Tempdx[7:6]: SRB[7:6] */
422 Temp1 = Tempdx; /* Temp1[7:6]: HRS[9:8] */
423 Temp1 <<= 2; /* Temp1[9:8]: HRS[9:8] */
424 Temp1 |= Tempax; /* Temp1[9:0]: HRS[9:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800425
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200426 Tempax = XGI_CRT1Table[index].CR[4]; /* CR5 HRE */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300427 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200428
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200429 Tempbx = XGI_CRT1Table[index].CR[6]; /* SRC */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300430 Tempbx &= 0x04; /* Tempbx[2]: HRE[5] */
431 Tempbx <<= 3; /* Tempbx[5]: HRE[5] */
432 Tempax |= Tempbx; /* Tempax[5:0]: HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200433
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300434 Temp2 = Temp1 & 0x3C0; /* Temp2[9:6]: HRS[9:6] */
435 Temp2 |= Tempax; /* Temp2[9:0]: HRE[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200436
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300437 Tempcx &= 0x3F; /* Tempcx[5:0]: HRS[5:0] */
438 if (Tempax < Tempcx) /* HRE < HRS */
439 Temp2 |= 0x40; /* Temp2 + 0x40 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200440
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300441 Temp2 &= 0xFF;
442 Tempax = (unsigned char) Temp2; /* Tempax: HRE[7:0] */
443 Tempax <<= 2; /* Tempax[7:2]: HRE[5:0] */
444 Tempdx >>= 6; /* Tempdx[7:6]->[1:0] HRS[9:8] */
445 Tempax |= Tempdx; /* HRE[5:0]HRS[9:8] */
446 /* SR2F D[7:2]->HRE, D[1:0]->HRS */
447 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
448 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200449
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300450 /* CR10 VRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200451 Tempax = XGI_CRT1Table[index].CR[10];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300452 Tempbx = Tempax; /* Tempbx: VRS */
453 Tempax &= 0x01; /* Tempax[0]: VRS[0] */
454 xgifb_reg_or(pVBInfo->P3c4, 0x33, Tempax); /* SR33[0]->VRS[0] */
455 /* CR7[2][7] VRE */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200456 Tempax = XGI_CRT1Table[index].CR[9];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300457 Tempcx = Tempbx >> 1; /* Tempcx[6:0]: VRS[7:1] */
458 Tempdx = Tempax & 0x04; /* Tempdx[2]: CR7[2] */
459 Tempdx <<= 5; /* Tempdx[7]: VRS[8] */
460 Tempcx |= Tempdx; /* Tempcx[7:0]: VRS[8:1] */
461 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempcx); /* SR34[8:1]->VRS */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200462
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300463 Temp1 = Tempdx; /* Temp1[7]: Tempdx[7] */
464 Temp1 <<= 1; /* Temp1[8]: VRS[8] */
465 Temp1 |= Tempbx; /* Temp1[8:0]: VRS[8:0] */
466 Tempax &= 0x80;
467 Temp2 = Tempax << 2; /* Temp2[9]: VRS[9] */
468 Temp1 |= Temp2; /* Temp1[9:0]: VRS[9:0] */
469 /* Tempax: SRA */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200470 Tempax = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300471 Tempax &= 0x08; /* Tempax[3]: VRS[3] */
472 Temp2 = Tempax;
473 Temp2 <<= 7; /* Temp2[10]: VRS[10] */
474 Temp1 |= Temp2; /* Temp1[10:0]: VRS[10:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200475
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300476 /* Tempax: CR11 VRE */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200477 Tempax = XGI_CRT1Table[index].CR[11];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300478 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
479 /* Tempbx: SRA */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200480 Tempbx = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300481 Tempbx &= 0x20; /* Tempbx[5]: VRE[5] */
482 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
483 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
484 Temp2 = Temp1 & 0x7E0; /* Temp2[10:5]: VRS[10:5] */
485 Temp2 |= Tempax; /* Temp2[10:5]: VRE[10:5] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200486
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300487 Temp3 = Temp1 & 0x1F; /* Temp3[4:0]: VRS[4:0] */
488 if (Tempax < Temp3) /* VRE < VRS */
489 Temp2 |= 0x20; /* VRE + 0x20 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200490
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300491 Temp2 &= 0xFF;
492 Tempax = (unsigned char) Temp2; /* Tempax: VRE[7:0] */
493 Tempax <<= 2; /* Tempax[7:0]; VRE[5:0]00 */
494 Temp1 &= 0x600; /* Temp1[10:9]: VRS[10:9] */
495 Temp1 >>= 9; /* Temp1[1:0]: VRS[10:9] */
496 Tempbx = (unsigned char) Temp1;
497 Tempax |= Tempbx; /* Tempax[7:0]: VRE[5:0]VRS[10:9] */
498 Tempax &= 0x7F;
499 /* SR3F D[7:2]->VRE D[1:0]->VRS */
500 xgifb_reg_set(pVBInfo->P3c4, 0x3F, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200501}
502
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800503static void XGI_SetXG27CRTC(unsigned short ModeNo,
504 unsigned short ModeIdIndex,
505 unsigned short RefreshRateTableIndex,
506 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200507{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300508 unsigned short index, Tempax, Tempbx, Tempcx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200509
Aaro Koskinena39325d2012-11-04 21:14:53 +0200510 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300511 /* Tempax: CR4 HRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200512 Tempax = XGI_CRT1Table[index].CR[3];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300513 Tempbx = Tempax; /* Tempbx: HRS[7:0] */
514 /* SR2E[7:0]->HRS */
515 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200516
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300517 /* SR0B */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200518 Tempax = XGI_CRT1Table[index].CR[5];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300519 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
520 Tempbx |= (Tempax << 2); /* Tempbx: HRS[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200521
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200522 Tempax = XGI_CRT1Table[index].CR[4]; /* CR5 HRE */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300523 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
524 Tempcx = Tempax; /* Tempcx: HRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200525
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200526 Tempax = XGI_CRT1Table[index].CR[6]; /* SRC */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300527 Tempax &= 0x04; /* Tempax[2]: HRE[5] */
528 Tempax <<= 3; /* Tempax[5]: HRE[5] */
529 Tempcx |= Tempax; /* Tempcx[5:0]: HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200530
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300531 Tempbx = Tempbx & 0x3C0; /* Tempbx[9:6]: HRS[9:6] */
532 Tempbx |= Tempcx; /* Tempbx: HRS[9:6]HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200533
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300534 /* Tempax: CR4 HRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200535 Tempax = XGI_CRT1Table[index].CR[3];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300536 Tempax &= 0x3F; /* Tempax: HRS[5:0] */
537 if (Tempcx <= Tempax) /* HRE[5:0] < HRS[5:0] */
538 Tempbx += 0x40; /* Tempbx= Tempbx + 0x40 : HRE[9:0]*/
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200539
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200540 Tempax = XGI_CRT1Table[index].CR[5]; /* SR0B */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300541 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
542 Tempax >>= 6; /* Tempax[1:0]: HRS[9:8]*/
543 Tempax |= ((Tempbx << 2) & 0xFF); /* Tempax[7:2]: HRE[5:0] */
544 /* SR2F [7:2][1:0]: HRE[5:0]HRS[9:8] */
545 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
546 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200547
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300548 /* CR10 VRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200549 Tempax = XGI_CRT1Table[index].CR[10];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300550 /* SR34[7:0]->VRS[7:0] */
551 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200552
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300553 Tempcx = Tempax; /* Tempcx <= VRS[7:0] */
554 /* CR7[7][2] VRS[9][8] */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200555 Tempax = XGI_CRT1Table[index].CR[9];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300556 Tempbx = Tempax; /* Tempbx <= CR07[7:0] */
557 Tempax = Tempax & 0x04; /* Tempax[2]: CR7[2]: VRS[8] */
558 Tempax >>= 2; /* Tempax[0]: VRS[8] */
559 /* SR35[0]: VRS[8] */
560 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x01, Tempax);
561 Tempcx |= (Tempax << 8); /* Tempcx <= VRS[8:0] */
562 Tempcx |= ((Tempbx & 0x80) << 2); /* Tempcx <= VRS[9:0] */
563 /* Tempax: SR0A */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200564 Tempax = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300565 Tempax &= 0x08; /* SR0A[3] VRS[10] */
566 Tempcx |= (Tempax << 7); /* Tempcx <= VRS[10:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200567
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300568 /* Tempax: CR11 VRE */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200569 Tempax = XGI_CRT1Table[index].CR[11];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300570 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
571 /* Tempbx: SR0A */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200572 Tempbx = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300573 Tempbx &= 0x20; /* Tempbx[5]: SR0A[5]: VRE[4] */
574 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
575 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
576 Tempbx = Tempcx; /* Tempbx: VRS[10:0] */
577 Tempbx &= 0x7E0; /* Tempbx[10:5]: VRS[10:5] */
578 Tempbx |= Tempax; /* Tempbx: VRS[10:5]VRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200579
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300580 if (Tempbx <= Tempcx) /* VRE <= VRS */
581 Tempbx |= 0x20; /* VRE + 0x20 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200582
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300583 /* Tempax: Tempax[7:0]; VRE[5:0]00 */
584 Tempax = (Tempbx << 2) & 0xFF;
585 /* SR3F[7:2]:VRE[5:0] */
586 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC, Tempax);
587 Tempax = Tempcx >> 8;
588 /* SR35[2:0]:VRS[10:8] */
589 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200590}
591
Aaro Koskinena2d08cf2011-11-27 23:03:08 +0200592static void XGI_SetXG27FPBits(struct vb_device_info *pVBInfo)
593{
594 unsigned char temp;
595
596 /* D[1:0] 01: 18bit, 00: dual 12, 10: single 24 */
597 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
598 temp = (temp & 3) << 6;
599 /* SR06[7]0: dual 12/1: single 24 [6] 18bit Dither <= 0 h/w recommend */
600 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0xc0, temp & 0x80);
601 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: 24bits */
602 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
603
604}
605
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300606static void xgifb_set_lcd(int chip_id,
607 struct vb_device_info *pVBInfo,
608 unsigned short RefreshRateTableIndex,
609 unsigned short ModeNo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200610{
Peter Huewee2e544c2013-02-03 04:08:46 +0100611 unsigned short temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200612
Aaro Koskinen8104e322011-03-13 12:26:22 +0200613 xgifb_reg_set(pVBInfo->P3d4, 0x2E, 0x00);
614 xgifb_reg_set(pVBInfo->P3d4, 0x2F, 0x00);
615 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x00);
616 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x00);
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300617
618 if (chip_id == XG27) {
Peter Huewee2e544c2013-02-03 04:08:46 +0100619 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
620 if ((temp & 0x03) == 0) { /* dual 12 */
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300621 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x13);
622 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x13);
623 }
624 }
625
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300626 if (chip_id == XG27) {
627 XGI_SetXG27FPBits(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530628 } else {
Peter Huewee2e544c2013-02-03 04:08:46 +0100629 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
630 if (temp & 0x01) {
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300631 /* 18 bits FP */
632 xgifb_reg_or(pVBInfo->P3c4, 0x06, 0x40);
633 xgifb_reg_or(pVBInfo->P3c4, 0x09, 0x40);
634 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530635 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200636
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +0200637 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x01); /* Negative blank polarity */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200638
Aaro Koskinendc505562011-03-13 12:26:26 +0200639 xgifb_reg_and(pVBInfo->P3c4, 0x30, ~0x20); /* Hsync polarity */
640 xgifb_reg_and(pVBInfo->P3c4, 0x35, ~0x80); /* Vsync polarity */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200641
Peter Huewee2e544c2013-02-03 04:08:46 +0100642 temp = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
643 if (temp & 0x4000)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300644 /* Hsync polarity */
645 xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20);
Peter Huewee2e544c2013-02-03 04:08:46 +0100646 if (temp & 0x8000)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300647 /* Vsync polarity */
648 xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200649}
650
651/* --------------------------------------------------------------------- */
652/* Function : XGI_UpdateXG21CRTC */
653/* Input : */
654/* Output : CRT1 CRTC */
655/* Description : Modify CRT1 Hsync/Vsync to fix LCD mode timing */
656/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800657static void XGI_UpdateXG21CRTC(unsigned short ModeNo,
658 struct vb_device_info *pVBInfo,
659 unsigned short RefreshRateTableIndex)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200660{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300661 int index = -1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200662
Aaro Koskinendc505562011-03-13 12:26:26 +0200663 xgifb_reg_and(pVBInfo->P3d4, 0x11, 0x7F); /* Unlock CR0~7 */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300664 if (ModeNo == 0x2E &&
Aaro Koskinena39325d2012-11-04 21:14:53 +0200665 (XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC ==
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300666 RES640x480x60))
667 index = 12;
Aaro Koskinena39325d2012-11-04 21:14:53 +0200668 else if (ModeNo == 0x2E && (XGI330_RefIndex[RefreshRateTableIndex].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800669 Ext_CRT1CRTC == RES640x480x72))
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300670 index = 13;
671 else if (ModeNo == 0x2F)
672 index = 14;
673 else if (ModeNo == 0x50)
674 index = 15;
675 else if (ModeNo == 0x59)
676 index = 16;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200677
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530678 if (index != -1) {
Aaro Koskinen8104e322011-03-13 12:26:22 +0200679 xgifb_reg_set(pVBInfo->P3d4, 0x02,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200680 XGI_UpdateCRT1Table[index].CR02);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200681 xgifb_reg_set(pVBInfo->P3d4, 0x03,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200682 XGI_UpdateCRT1Table[index].CR03);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200683 xgifb_reg_set(pVBInfo->P3d4, 0x15,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200684 XGI_UpdateCRT1Table[index].CR15);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200685 xgifb_reg_set(pVBInfo->P3d4, 0x16,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200686 XGI_UpdateCRT1Table[index].CR16);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530687 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200688}
689
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200690static void XGI_SetCRT1DE(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530691 unsigned short ModeNo, unsigned short ModeIdIndex,
692 unsigned short RefreshRateTableIndex,
693 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200694{
Bill Pemberton82d6eb52010-06-17 13:10:46 -0400695 unsigned short resindex, tempax, tempbx, tempcx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200696
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530697 unsigned char data;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200698
Aaro Koskinenb3979922012-11-04 21:14:52 +0200699 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200700
Aaro Koskinenb3979922012-11-04 21:14:52 +0200701 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinene8e6c752012-11-04 21:15:00 +0200702 tempax = XGI330_ModeResInfo[resindex].HTotal;
703 tempbx = XGI330_ModeResInfo[resindex].VTotal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200704
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530705 if (modeflag & HalfDCLK)
706 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200707
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300708 if (modeflag & HalfDCLK)
709 tempax = tempax << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200710
Aaro Koskinena39325d2012-11-04 21:14:53 +0200711 temp = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200712
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300713 if (temp & InterlaceMode)
714 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200715
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300716 if (modeflag & DoubleScanMode)
717 tempbx = tempbx << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200718
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530719 tempcx = 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200720
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530721 tempax /= tempcx;
722 tempax -= 1;
723 tempbx -= 1;
724 tempcx = tempax;
Peter Huewe9388ad92013-02-15 20:37:10 +0100725 temp = xgifb_reg_get(pVBInfo->P3d4, 0x11);
726 data = xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530727 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200728 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
729 xgifb_reg_set(pVBInfo->P3d4, 0x01, (unsigned short) (tempcx & 0xff));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200730 xgifb_reg_and_or(pVBInfo->P3d4, 0x0b, ~0x0c,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530731 (unsigned short) ((tempcx & 0x0ff00) >> 10));
Aaro Koskinen8104e322011-03-13 12:26:22 +0200732 xgifb_reg_set(pVBInfo->P3d4, 0x12, (unsigned short) (tempbx & 0xff));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530733 tempax = 0;
734 tempbx = tempbx >> 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200735
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530736 if (tempbx & 0x01)
737 tempax |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200738
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530739 if (tempbx & 0x02)
740 tempax |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200741
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200742 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x42, tempax);
Peter Huewe9388ad92013-02-15 20:37:10 +0100743 data = xgifb_reg_get(pVBInfo->P3d4, 0x07);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530744 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200745
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530746 if (tempbx & 0x04)
747 tempax |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200748
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200749 xgifb_reg_and_or(pVBInfo->P3d4, 0x0a, ~0x02, tempax);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200750 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200751}
752
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800753static void XGI_SetCRT1Offset(unsigned short ModeNo,
754 unsigned short ModeIdIndex,
755 unsigned short RefreshRateTableIndex,
756 struct xgi_hw_device_info *HwDeviceExtension,
757 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200758{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530759 unsigned short temp, ah, al, temp2, i, DisplayUnit;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200760
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530761 /* GetOffset */
Aaro Koskinenb3979922012-11-04 21:14:52 +0200762 temp = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeInfo;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530763 temp = temp >> 8;
Aaro Koskinen224114c2012-11-04 21:14:59 +0200764 temp = XGI330_ScreenOffset[temp];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200765
Aaro Koskinena39325d2012-11-04 21:14:53 +0200766 temp2 = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530767 temp2 &= InterlaceMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200768
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530769 if (temp2)
770 temp = temp << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200771
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530772 temp2 = pVBInfo->ModeType - ModeEGA;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200773
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530774 switch (temp2) {
775 case 0:
776 temp2 = 1;
777 break;
778 case 1:
779 temp2 = 2;
780 break;
781 case 2:
782 temp2 = 4;
783 break;
784 case 3:
785 temp2 = 4;
786 break;
787 case 4:
788 temp2 = 6;
789 break;
790 case 5:
791 temp2 = 8;
792 break;
793 default:
794 break;
795 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200796
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530797 if ((ModeNo >= 0x26) && (ModeNo <= 0x28))
798 temp = temp * temp2 + temp2 / 2;
799 else
800 temp *= temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200801
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530802 /* SetOffset */
803 DisplayUnit = temp;
804 temp2 = temp;
805 temp = temp >> 8; /* ah */
806 temp &= 0x0F;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200807 i = xgifb_reg_get(pVBInfo->P3c4, 0x0E);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530808 i &= 0xF0;
809 i |= temp;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200810 xgifb_reg_set(pVBInfo->P3c4, 0x0E, i);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200811
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530812 temp = (unsigned char) temp2;
813 temp &= 0xFF; /* al */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200814 xgifb_reg_set(pVBInfo->P3d4, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200815
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530816 /* SetDisplayUnit */
Aaro Koskinena39325d2012-11-04 21:14:53 +0200817 temp2 = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530818 temp2 &= InterlaceMode;
819 if (temp2)
820 DisplayUnit >>= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200821
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530822 DisplayUnit = DisplayUnit << 5;
823 ah = (DisplayUnit & 0xff00) >> 8;
824 al = DisplayUnit & 0x00ff;
825 if (al == 0)
826 ah += 1;
827 else
828 ah += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200829
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530830 if (HwDeviceExtension->jChipType >= XG20)
831 if ((ModeNo == 0x4A) | (ModeNo == 0x49))
832 ah -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200833
Aaro Koskinen8104e322011-03-13 12:26:22 +0200834 xgifb_reg_set(pVBInfo->P3c4, 0x10, ah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200835}
836
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200837static unsigned short XGI_GetVCLK2Ptr(unsigned short ModeNo,
838 unsigned short ModeIdIndex,
839 unsigned short RefreshRateTableIndex,
840 struct xgi_hw_device_info *HwDeviceExtension,
841 struct vb_device_info *pVBInfo)
842{
Peter Hueweef9a6b92013-02-03 04:08:43 +0100843 unsigned short VCLKIndex, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200844
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300845 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +0200846 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200847
Aaro Koskinen7ac54d02013-02-09 00:03:43 +0200848 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) { /*301b*/
849 if (pVBInfo->LCDResInfo != Panel_1024x768)
850 /* LCDXlat2VCLK */
851 VCLKIndex = VCLK108_2_315 + 5;
852 else
853 VCLKIndex = VCLK65_315 + 2; /* LCDXlat1VCLK */
854 } else if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
855 if (pVBInfo->SetFlag & RPLLDIV2XO)
856 VCLKIndex = TVCLKBASE_315_25 + HiTVVCLKDIV2;
857 else
858 VCLKIndex = TVCLKBASE_315_25 + HiTVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200859
Aaro Koskinen7ac54d02013-02-09 00:03:43 +0200860 if (pVBInfo->SetFlag & TVSimuMode) {
861 if (modeflag & Charx8Dot) {
862 VCLKIndex = TVCLKBASE_315_25 + HiTVSimuVCLK;
863 } else {
864 VCLKIndex = TVCLKBASE_315_25 + HiTVTextVCLK;
Aaro Koskinen798b4da2011-11-27 23:03:20 +0200865 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200866 }
Aaro Koskinen7ac54d02013-02-09 00:03:43 +0200867
868 /* 301lv */
869 if (pVBInfo->VBType & VB_SIS301LV) {
870 if (pVBInfo->SetFlag & RPLLDIV2XO)
871 VCLKIndex = YPbPr525iVCLK_2;
872 else
873 VCLKIndex = YPbPr525iVCLK;
874 }
875 } else if (pVBInfo->VBInfo & SetCRT2ToTV) {
876 if (pVBInfo->SetFlag & RPLLDIV2XO)
877 VCLKIndex = TVCLKBASE_315_25 + TVVCLKDIV2;
878 else
879 VCLKIndex = TVCLKBASE_315_25 + TVVCLK;
880 } else { /* for CRT2 */
881 /* di+Ext_CRTVCLK */
882 VCLKIndex = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
883 VCLKIndex &= IndexMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200884 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200885
886 return VCLKIndex;
887}
888
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800889static void XGI_SetCRT1VCLK(unsigned short ModeNo,
890 unsigned short ModeIdIndex,
891 struct xgi_hw_device_info *HwDeviceExtension,
892 unsigned short RefreshRateTableIndex,
893 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200894{
Bill Pemberton108afbf2010-06-17 13:10:47 -0400895 unsigned char index, data;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530896 unsigned short vclkindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200897
Aaro Koskinenb750f512013-05-29 23:59:05 +0300898 if ((pVBInfo->IF_DEF_LVDS == 0) &&
899 (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV |
900 VB_SIS302LV | VB_XGI301C)) &&
901 (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530902 vclkindex = XGI_GetVCLK2Ptr(ModeNo, ModeIdIndex,
903 RefreshRateTableIndex, HwDeviceExtension,
904 pVBInfo);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200905 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200906 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200907 data = XGI_VBVCLKData[vclkindex].Part4_A;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200908 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200909 data = XGI_VBVCLKData[vclkindex].Part4_B;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200910 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
911 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530912 } else {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200913 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200914 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200915 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200916 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[index].SR2B);
917 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[index].SR2C);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200918 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530919 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200920
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530921 if (HwDeviceExtension->jChipType >= XG20) {
Aaro Koskinenb3979922012-11-04 21:14:52 +0200922 if (XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag &
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800923 HalfDCLK) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200924 data = xgifb_reg_get(pVBInfo->P3c4, 0x2B);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200925 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200926 data = xgifb_reg_get(pVBInfo->P3c4, 0x2C);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530927 index = data;
928 index &= 0xE0;
929 data &= 0x1F;
930 data = data << 1;
931 data += 1;
932 data |= index;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200933 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530934 }
935 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200936}
937
Aaro Koskinene85f2032011-11-27 23:03:07 +0200938static void XGI_SetXG21FPBits(struct vb_device_info *pVBInfo)
939{
940 unsigned char temp;
941
942 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37); /* D[0] 1: 18bit */
943 temp = (temp & 1) << 6;
944 /* SR06[6] 18bit Dither */
945 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x40, temp);
946 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: dual 12bits */
947 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
948
949}
950
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200951static void XGI_SetCRT1FIFO(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530952 struct xgi_hw_device_info *HwDeviceExtension,
953 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200954{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530955 unsigned short data;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200956
Aaro Koskinen58839b02011-03-13 12:26:23 +0200957 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530958 data &= 0xfe;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200959 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data); /* diable auto-threshold */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200960
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300961 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0x34);
962 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
963 data &= 0xC0;
964 xgifb_reg_set(pVBInfo->P3c4, 0x09, data | 0x30);
965 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
966 data |= 0x01;
967 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200968
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530969 if (HwDeviceExtension->jChipType == XG21)
970 XGI_SetXG21FPBits(pVBInfo); /* Fix SR9[7:6] can't read back */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200971}
972
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200973static void XGI_SetVCLKState(struct xgi_hw_device_info *HwDeviceExtension,
974 unsigned short ModeNo, unsigned short RefreshRateTableIndex,
975 struct vb_device_info *pVBInfo)
976{
977 unsigned short data, data2 = 0;
978 short VCLK;
979
980 unsigned char index;
981
Aaro Koskinena39325d2012-11-04 21:14:53 +0200982 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300983 index &= IndexMask;
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200984 VCLK = XGI_VCLKData[index].CLOCK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200985
Aaro Koskinen58839b02011-03-13 12:26:23 +0200986 data = xgifb_reg_get(pVBInfo->P3c4, 0x32);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200987 data &= 0xf3;
988 if (VCLK >= 200)
989 data |= 0x0c; /* VCLK > 200 */
990
991 if (HwDeviceExtension->jChipType >= XG20)
992 data &= ~0x04; /* 2 pixel mode */
993
Aaro Koskinen8104e322011-03-13 12:26:22 +0200994 xgifb_reg_set(pVBInfo->P3c4, 0x32, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200995
996 if (HwDeviceExtension->jChipType < XG20) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200997 data = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200998 data &= 0xE7;
999 if (VCLK < 200)
1000 data |= 0x10;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001001 xgifb_reg_set(pVBInfo->P3c4, 0x1F, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001002 }
1003
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001004 data2 = 0x00;
1005
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001006 xgifb_reg_and_or(pVBInfo->P3c4, 0x07, 0xFC, data2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001007 if (HwDeviceExtension->jChipType >= XG27)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001008 xgifb_reg_and_or(pVBInfo->P3c4, 0x40, 0xFC, data2 & 0x03);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001009
1010}
1011
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001012static void XGI_SetCRT1ModeRegs(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301013 unsigned short ModeNo, unsigned short ModeIdIndex,
1014 unsigned short RefreshRateTableIndex,
1015 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001016{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301017 unsigned short data, data2, data3, infoflag = 0, modeflag, resindex,
1018 xres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001019
Aaro Koskinenb3979922012-11-04 21:14:52 +02001020 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02001021 infoflag = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001022
Aaro Koskinen58839b02011-03-13 12:26:23 +02001023 if (xgifb_reg_get(pVBInfo->P3d4, 0x31) & 0x01)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001024 xgifb_reg_and_or(pVBInfo->P3c4, 0x1F, 0x3F, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001025
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001026 data = infoflag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301027 data2 = 0;
Aaro Koskinen969f7f32012-04-07 01:14:03 +03001028 data2 |= 0x02;
1029 data3 = pVBInfo->ModeType - ModeVGA;
1030 data3 = data3 << 2;
1031 data2 |= data3;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301032 data &= InterlaceMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001033
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301034 if (data)
1035 data2 |= 0x20;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001036
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001037 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x3F, data2);
Aaro Koskinenb3979922012-11-04 21:14:52 +02001038 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02001039 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001040
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301041 data = 0x0000;
1042 if (infoflag & InterlaceMode) {
1043 if (xres == 1024)
1044 data = 0x0035;
1045 else if (xres == 1280)
1046 data = 0x0048;
1047 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001048
Peter Huewe5d1c2a92013-02-03 22:54:37 +01001049 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFF, data);
1050 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFC, 0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001051
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301052 if (modeflag & HalfDCLK)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001053 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xF7, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001054
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301055 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001056
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301057 if (modeflag & LineCompareOff)
1058 data2 |= 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001059
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001060 xgifb_reg_and_or(pVBInfo->P3c4, 0x0F, ~0x48, data2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301061 data = 0x60;
Aaro Koskinen969f7f32012-04-07 01:14:03 +03001062 data = data ^ 0x60;
1063 data = data ^ 0xA0;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001064 xgifb_reg_and_or(pVBInfo->P3c4, 0x21, 0x1F, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001065
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301066 XGI_SetVCLKState(HwDeviceExtension, ModeNo, RefreshRateTableIndex,
1067 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001068
Aaro Koskinen58839b02011-03-13 12:26:23 +02001069 data = xgifb_reg_get(pVBInfo->P3d4, 0x31);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001070
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301071 if (HwDeviceExtension->jChipType == XG27) {
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);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02001077 xgifb_reg_or(pVBInfo->P3d4, 0x51, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301078 } else if (HwDeviceExtension->jChipType >= XG20) {
1079 if (data & 0x40)
1080 data = 0x33;
1081 else
1082 data = 0x73;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001083 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
1084 xgifb_reg_set(pVBInfo->P3d4, 0x51, 0x02);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301085 } else {
1086 if (data & 0x40)
1087 data = 0x2c;
1088 else
1089 data = 0x6c;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001090 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301091 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001092
1093}
1094
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001095static void XGI_WriteDAC(unsigned short dl,
1096 unsigned short ah,
1097 unsigned short al,
1098 unsigned short dh,
1099 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001100{
1101 unsigned short temp, bh, bl;
1102
1103 bh = ah;
1104 bl = al;
1105
1106 if (dl != 0) {
1107 temp = bh;
1108 bh = dh;
1109 dh = temp;
1110 if (dl == 1) {
1111 temp = bl;
1112 bl = dh;
1113 dh = temp;
1114 } else {
1115 temp = bl;
1116 bl = bh;
1117 bh = temp;
1118 }
1119 }
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001120 outb((unsigned short) dh, pVBInfo->P3c9);
1121 outb((unsigned short) bh, pVBInfo->P3c9);
1122 outb((unsigned short) bl, pVBInfo->P3c9);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001123}
1124
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001125static void XGI_LoadDAC(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301126 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001127{
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001128 unsigned short data, data2, i, k, m, n, o, si, di, bx, dl, al, ah, dh;
1129 const unsigned short *table = XGINew_VGA_DAC;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001130
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001131 outb(0xFF, pVBInfo->P3c6);
1132 outb(0x00, pVBInfo->P3c8);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001133
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001134 for (i = 0; i < 16; i++) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301135 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001136
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301137 for (k = 0; k < 3; k++) {
1138 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001139
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301140 if (data & 0x01)
1141 data2 = 0x2A;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001142
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301143 if (data & 0x02)
1144 data2 += 0x15;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001145
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001146 outb(data2, pVBInfo->P3c9);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301147 data = data >> 2;
1148 }
1149 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001150
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001151 for (i = 16; i < 32; i++) {
1152 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001153
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001154 for (k = 0; k < 3; k++)
1155 outb(data, pVBInfo->P3c9);
1156 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001157
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001158 si = 32;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001159
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001160 for (m = 0; m < 9; m++) {
1161 di = si;
1162 bx = si + 0x04;
1163 dl = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001164
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001165 for (n = 0; n < 3; n++) {
1166 for (o = 0; o < 5; o++) {
1167 dh = table[si];
1168 ah = table[di];
1169 al = table[bx];
1170 si++;
1171 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301172 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001173
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001174 si -= 2;
1175
1176 for (o = 0; o < 3; o++) {
1177 dh = table[bx];
1178 ah = table[di];
1179 al = table[si];
1180 si--;
1181 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1182 }
1183
1184 dl++;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301185 }
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001186
1187 si += 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301188 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001189}
1190
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001191static void XGI_GetLVDSResInfo(unsigned short ModeNo,
1192 unsigned short ModeIdIndex,
1193 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001194{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301195 unsigned short resindex, xres, yres, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001196
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001197 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02001198 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001199
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001200 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02001201 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001202
Aaro Koskinene8e6c752012-11-04 21:15:00 +02001203 xres = XGI330_ModeResInfo[resindex].HTotal;
1204 yres = XGI330_ModeResInfo[resindex].VTotal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001205
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001206 if (modeflag & HalfDCLK)
1207 xres = xres << 1;
1208
1209 if (modeflag & DoubleScanMode)
1210 yres = yres << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001211
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301212 if (xres == 720)
1213 xres = 640;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001214
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301215 pVBInfo->VGAHDE = xres;
1216 pVBInfo->HDE = xres;
1217 pVBInfo->VGAVDE = yres;
1218 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001219}
1220
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001221static void const *XGI_GetLcdPtr(struct XGI330_LCDDataTablStruct const *table,
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001222 unsigned short ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001223 unsigned short ModeIdIndex,
1224 unsigned short RefreshRateTableIndex,
1225 struct vb_device_info *pVBInfo)
1226{
Aaro Koskinen6c27b372012-11-04 21:14:45 +02001227 unsigned short i, tempdx, tempbx, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001228
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001229 tempbx = 0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001230
Aaro Koskinenb3979922012-11-04 21:14:52 +02001231 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001232
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001233 i = 0;
1234
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001235 while (table[i].PANELID != 0xff) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001236 tempdx = pVBInfo->LCDResInfo;
1237 if (tempbx & 0x0080) { /* OEMUtil */
1238 tempbx &= (~0x0080);
1239 tempdx = pVBInfo->LCDTypeInfo;
1240 }
1241
1242 if (pVBInfo->LCDInfo & EnableScalingLCD)
1243 tempdx &= (~PanelResInfo);
1244
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001245 if (table[i].PANELID == tempdx) {
1246 tempbx = table[i].MASK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001247 tempdx = pVBInfo->LCDInfo;
1248
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001249 if (modeflag & HalfDCLK)
1250 tempdx |= SetLCDLowResolution;
1251
1252 tempbx &= tempdx;
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001253 if (tempbx == table[i].CAP)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001254 break;
1255 }
1256 i++;
1257 }
1258
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001259 return table[i].DATAPTR;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001260}
1261
Aaro Koskinen24572542012-09-11 00:15:21 +03001262static struct SiS_TVData const *XGI_GetTVPtr(unsigned short ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001263 unsigned short ModeIdIndex,
1264 unsigned short RefreshRateTableIndex,
1265 struct vb_device_info *pVBInfo)
1266{
Aaro Koskinen56d276c2012-09-11 00:15:19 +03001267 unsigned short i, tempdx, tempal, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001268
Aaro Koskinenb3979922012-11-04 21:14:52 +02001269 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02001270 tempal = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001271 tempal = tempal & 0x3f;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001272 tempdx = pVBInfo->TVInfo;
1273
1274 if (pVBInfo->VBInfo & SetInSlaveMode)
1275 tempdx = tempdx | SetTVLockMode;
1276
1277 if (modeflag & HalfDCLK)
1278 tempdx = tempdx | SetTVLowResolution;
1279
1280 i = 0;
1281
Aaro Koskinen6265ee42012-09-11 00:15:20 +03001282 while (XGI_TVDataTable[i].MASK != 0xffff) {
1283 if ((tempdx & XGI_TVDataTable[i].MASK) ==
1284 XGI_TVDataTable[i].CAP)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001285 break;
1286 i++;
1287 }
1288
Aaro Koskinen18ba8662012-09-11 00:15:22 +03001289 return &XGI_TVDataTable[i].DATAPTR[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001290}
1291
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001292static void XGI_GetLVDSData(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301293 unsigned short RefreshRateTableIndex,
1294 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001295{
Aaro Koskinen6008f872012-11-04 21:14:49 +02001296 struct SiS_LVDSData const *LCDPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001297
Aaro Koskinen6008f872012-11-04 21:14:49 +02001298 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
1299 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001300
Aaro Koskinen6008f872012-11-04 21:14:49 +02001301 LCDPtr = XGI_GetLcdPtr(XGI_EPLLCDDataPtr, ModeNo, ModeIdIndex,
1302 RefreshRateTableIndex, pVBInfo);
1303 pVBInfo->VGAHT = LCDPtr->VGAHT;
1304 pVBInfo->VGAVT = LCDPtr->VGAVT;
1305 pVBInfo->HT = LCDPtr->LCDHT;
1306 pVBInfo->VT = LCDPtr->LCDVT;
1307
1308 if (pVBInfo->LCDInfo & (SetLCDtoNonExpanding | EnableScalingLCD))
1309 return;
1310
1311 if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
1312 (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
1313 pVBInfo->HDE = 1024;
1314 pVBInfo->VDE = 768;
1315 } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
1316 (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
1317 pVBInfo->HDE = 1280;
1318 pVBInfo->VDE = 1024;
1319 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
1320 pVBInfo->HDE = 1400;
1321 pVBInfo->VDE = 1050;
1322 } else {
1323 pVBInfo->HDE = 1600;
1324 pVBInfo->VDE = 1200;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301325 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001326}
1327
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001328static void XGI_ModCRT1Regs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301329 unsigned short RefreshRateTableIndex,
1330 struct xgi_hw_device_info *HwDeviceExtension,
1331 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001332{
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001333 unsigned short i;
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001334 struct XGI_LVDSCRT1HDataStruct const *LCDPtr = NULL;
1335 struct XGI_LVDSCRT1VDataStruct const *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001336
Peter Huewea3d675c2012-02-09 21:11:47 +01001337 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001338 LCDPtr = XGI_GetLcdPtr(xgifb_epllcd_crt1_h, ModeNo, ModeIdIndex,
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +03001339 RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001340
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001341 for (i = 0; i < 8; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +02001342 pVBInfo->TimingH.data[i] = LCDPtr[0].Reg[i];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301343 }
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001344
1345 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
1346
Peter Huewea3d675c2012-02-09 21:11:47 +01001347 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001348 LCDPtr1 = XGI_GetLcdPtr(xgifb_epllcd_crt1_v, ModeNo,
1349 ModeIdIndex, RefreshRateTableIndex,
1350 pVBInfo);
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001351 for (i = 0; i < 7; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +02001352 pVBInfo->TimingV.data[i] = LCDPtr1[0].Reg[i];
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001353 }
1354
1355 XGI_SetCRT1Timing_V(ModeIdIndex, ModeNo, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001356}
1357
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001358static unsigned short XGI_GetLCDCapPtr(struct vb_device_info *pVBInfo)
1359{
1360 unsigned char tempal, tempah, tempbl, i;
1361
Aaro Koskinen58839b02011-03-13 12:26:23 +02001362 tempah = xgifb_reg_get(pVBInfo->P3d4, 0x36);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001363 tempal = tempah & 0x0F;
1364 tempah = tempah & 0xF0;
1365 i = 0;
1366 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1367
1368 while (tempbl != 0xFF) {
1369 if (tempbl & 0x80) { /* OEMUtil */
1370 tempal = tempah;
1371 tempbl = tempbl & ~(0x80);
1372 }
1373
1374 if (tempal == tempbl)
1375 break;
1376
1377 i++;
1378
1379 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1380 }
1381
1382 return i;
1383}
1384
1385static unsigned short XGI_GetLCDCapPtr1(struct vb_device_info *pVBInfo)
1386{
1387 unsigned short tempah, tempal, tempbl, i;
1388
1389 tempal = pVBInfo->LCDResInfo;
1390 tempah = pVBInfo->LCDTypeInfo;
1391
1392 i = 0;
1393 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1394
1395 while (tempbl != 0xFF) {
1396 if ((tempbl & 0x80) && (tempbl != 0x80)) {
1397 tempal = tempah;
1398 tempbl &= ~0x80;
1399 }
1400
1401 if (tempal == tempbl)
1402 break;
1403
1404 i++;
1405 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1406 }
1407
1408 if (tempbl == 0xFF) {
Peter Huewe255aabd2012-02-09 21:11:44 +01001409 pVBInfo->LCDResInfo = Panel_1024x768;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001410 pVBInfo->LCDTypeInfo = 0;
1411 i = 0;
1412 }
1413
1414 return i;
1415}
1416
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001417static void XGI_GetLCDSync(unsigned short *HSyncWidth,
1418 unsigned short *VSyncWidth,
1419 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001420{
1421 unsigned short Index;
1422
1423 Index = XGI_GetLCDCapPtr(pVBInfo);
1424 *HSyncWidth = pVBInfo->LCDCapList[Index].LCD_HSyncWidth;
1425 *VSyncWidth = pVBInfo->LCDCapList[Index].LCD_VSyncWidth;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001426}
1427
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001428static void XGI_SetLVDSRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301429 unsigned short RefreshRateTableIndex,
1430 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001431{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301432 unsigned short tempbx, tempax, tempcx, tempdx, push1, push2, modeflag;
1433 unsigned long temp, temp1, temp2, temp3, push3;
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001434 struct XGI330_LCDDataDesStruct2 const *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001435
Aaro Koskinenb3979922012-11-04 21:14:52 +02001436 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Peter Huewe826215d2013-02-05 00:29:46 +01001437 LCDPtr1 = XGI_GetLcdPtr(XGI_EPLLCDDesDataPtr, ModeNo, ModeIdIndex,
1438 RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001439
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001440 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
1441 push1 = tempbx;
1442 push2 = tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001443
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001444 /* GetLCDResInfo */
Peter Huewe255aabd2012-02-09 21:11:44 +01001445 if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
1446 (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001447 tempax = 1024;
1448 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01001449 } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
1450 (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001451 tempax = 1280;
1452 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01001453 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001454 tempax = 1400;
1455 tempbx = 1050;
1456 } else {
1457 tempax = 1600;
1458 tempbx = 1200;
1459 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001460
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001461 if (pVBInfo->LCDInfo & SetLCDtoNonExpanding) {
1462 pVBInfo->HDE = tempax;
1463 pVBInfo->VDE = tempbx;
1464 pVBInfo->VGAHDE = tempax;
1465 pVBInfo->VGAVDE = tempbx;
1466 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001467
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001468 tempax = pVBInfo->HT;
1469
Peter Huewe826215d2013-02-05 00:29:46 +01001470 tempbx = LCDPtr1->LCDHDES;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001471
1472 tempcx = pVBInfo->HDE;
1473 tempbx = tempbx & 0x0fff;
1474 tempcx += tempbx;
1475
1476 if (tempcx >= tempax)
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001477 tempcx -= tempax;
1478
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001479 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, tempbx & 0x07);
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001480
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001481 tempcx = tempcx >> 3;
1482 tempbx = tempbx >> 3;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001483
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001484 xgifb_reg_set(pVBInfo->Part1Port, 0x16,
1485 (unsigned short) (tempbx & 0xff));
1486 xgifb_reg_set(pVBInfo->Part1Port, 0x17,
1487 (unsigned short) (tempcx & 0xff));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001488
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001489 tempax = pVBInfo->HT;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001490
Peter Huewe826215d2013-02-05 00:29:46 +01001491 tempbx = LCDPtr1->LCDHRS;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001492
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001493 tempcx = push2;
1494
1495 if (pVBInfo->LCDInfo & EnableScalingLCD)
1496 tempcx = LCDPtr1->LCDHSync;
1497
1498 tempcx += tempbx;
1499
1500 if (tempcx >= tempax)
1501 tempcx -= tempax;
1502
1503 tempax = tempbx & 0x07;
1504 tempax = tempax >> 5;
1505 tempcx = tempcx >> 3;
1506 tempbx = tempbx >> 3;
1507
1508 tempcx &= 0x1f;
1509 tempax |= tempcx;
1510
1511 xgifb_reg_set(pVBInfo->Part1Port, 0x15, tempax);
1512 xgifb_reg_set(pVBInfo->Part1Port, 0x14,
1513 (unsigned short) (tempbx & 0xff));
1514
1515 tempax = pVBInfo->VT;
Peter Huewe826215d2013-02-05 00:29:46 +01001516 tempbx = LCDPtr1->LCDVDES;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001517 tempcx = pVBInfo->VDE;
1518
1519 tempbx = tempbx & 0x0fff;
1520 tempcx += tempbx;
1521 if (tempcx >= tempax)
1522 tempcx -= tempax;
1523
1524 xgifb_reg_set(pVBInfo->Part1Port, 0x1b,
1525 (unsigned short) (tempbx & 0xff));
1526 xgifb_reg_set(pVBInfo->Part1Port, 0x1c,
1527 (unsigned short) (tempcx & 0xff));
1528
1529 tempbx = (tempbx >> 8) & 0x07;
1530 tempcx = (tempcx >> 8) & 0x07;
1531
1532 xgifb_reg_set(pVBInfo->Part1Port, 0x1d,
1533 (unsigned short) ((tempcx << 3)
1534 | tempbx));
1535
1536 tempax = pVBInfo->VT;
Peter Huewe826215d2013-02-05 00:29:46 +01001537 tempbx = LCDPtr1->LCDVRS;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001538
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001539 tempcx = push1;
1540
1541 if (pVBInfo->LCDInfo & EnableScalingLCD)
1542 tempcx = LCDPtr1->LCDVSync;
1543
1544 tempcx += tempbx;
1545 if (tempcx >= tempax)
1546 tempcx -= tempax;
1547
1548 xgifb_reg_set(pVBInfo->Part1Port, 0x18,
1549 (unsigned short) (tempbx & 0xff));
1550 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, ~0x0f,
1551 (unsigned short) (tempcx & 0x0f));
1552
1553 tempax = ((tempbx >> 8) & 0x07) << 3;
1554
1555 tempbx = pVBInfo->VGAVDE;
1556 if (tempbx != pVBInfo->VDE)
1557 tempax |= 0x40;
1558
Peter Huewea3d675c2012-02-09 21:11:47 +01001559 if (pVBInfo->LCDInfo & XGI_EnableLVDSDDA)
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001560 tempax |= 0x40;
1561
1562 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1a, 0x07,
1563 tempax);
1564
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001565 tempbx = pVBInfo->VDE;
1566 tempax = pVBInfo->VGAVDE;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001567
1568 temp = tempax; /* 0430 ylshieh */
1569 temp1 = (temp << 18) / tempbx;
1570
1571 tempdx = (unsigned short) ((temp << 18) % tempbx);
1572
1573 if (tempdx != 0)
1574 temp1 += 1;
1575
1576 temp2 = temp1;
1577 push3 = temp2;
1578
1579 xgifb_reg_set(pVBInfo->Part1Port, 0x37,
1580 (unsigned short) (temp2 & 0xff));
1581 xgifb_reg_set(pVBInfo->Part1Port, 0x36,
1582 (unsigned short) ((temp2 >> 8) & 0xff));
1583
1584 tempbx = (unsigned short) (temp2 >> 16);
1585 tempax = tempbx & 0x03;
1586
1587 tempbx = pVBInfo->VGAVDE;
1588 if (tempbx == pVBInfo->VDE)
1589 tempax |= 0x04;
1590
1591 xgifb_reg_set(pVBInfo->Part1Port, 0x35, tempax);
1592
1593 if (pVBInfo->VBType & VB_XGI301C) {
1594 temp2 = push3;
1595 xgifb_reg_set(pVBInfo->Part4Port,
1596 0x3c,
1597 (unsigned short) (temp2 & 0xff));
1598 xgifb_reg_set(pVBInfo->Part4Port,
1599 0x3b,
1600 (unsigned short) ((temp2 >> 8) &
1601 0xff));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001602 tempbx = (unsigned short) (temp2 >> 16);
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001603 xgifb_reg_and_or(pVBInfo->Part4Port, 0x3a,
1604 ~0xc0,
1605 (unsigned short) ((tempbx &
1606 0xff) << 6));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001607
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001608 tempcx = pVBInfo->VGAVDE;
1609 if (tempcx == pVBInfo->VDE)
1610 xgifb_reg_and_or(pVBInfo->Part4Port,
1611 0x30, ~0x0c, 0x00);
1612 else
1613 xgifb_reg_and_or(pVBInfo->Part4Port,
1614 0x30, ~0x0c, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301615 }
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001616
1617 tempcx = pVBInfo->VGAHDE;
1618 tempbx = pVBInfo->HDE;
1619
1620 temp1 = tempcx << 16;
1621
1622 tempax = (unsigned short) (temp1 / tempbx);
1623
1624 if ((tempbx & 0xffff) == (tempcx & 0xffff))
1625 tempax = 65535;
1626
1627 temp3 = tempax;
1628 temp1 = pVBInfo->VGAHDE << 16;
1629
1630 temp1 /= temp3;
1631 temp3 = temp3 << 16;
1632 temp1 -= 1;
1633
1634 temp3 = (temp3 & 0xffff0000) + (temp1 & 0xffff);
1635
1636 tempax = (unsigned short) (temp3 & 0xff);
1637 xgifb_reg_set(pVBInfo->Part1Port, 0x1f, tempax);
1638
1639 temp1 = pVBInfo->VGAVDE << 18;
1640 temp1 = temp1 / push3;
1641 tempbx = (unsigned short) (temp1 & 0xffff);
1642
Peter Huewe255aabd2012-02-09 21:11:44 +01001643 if (pVBInfo->LCDResInfo == Panel_1024x768)
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001644 tempbx -= 1;
1645
1646 tempax = ((tempbx >> 8) & 0xff) << 3;
1647 tempax |= (unsigned short) ((temp3 >> 8) & 0x07);
1648 xgifb_reg_set(pVBInfo->Part1Port, 0x20,
1649 (unsigned short) (tempax & 0xff));
1650 xgifb_reg_set(pVBInfo->Part1Port, 0x21,
1651 (unsigned short) (tempbx & 0xff));
1652
1653 temp3 = temp3 >> 16;
1654
1655 if (modeflag & HalfDCLK)
1656 temp3 = temp3 >> 1;
1657
1658 xgifb_reg_set(pVBInfo->Part1Port, 0x22,
1659 (unsigned short) ((temp3 >> 8) & 0xff));
1660 xgifb_reg_set(pVBInfo->Part1Port, 0x23,
1661 (unsigned short) (temp3 & 0xff));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001662}
1663
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001664/* --------------------------------------------------------------------- */
1665/* Function : XGI_GETLCDVCLKPtr */
1666/* Input : */
1667/* Output : al -> VCLK Index */
1668/* Description : */
1669/* --------------------------------------------------------------------- */
1670static void XGI_GetLCDVCLKPtr(unsigned char *di_0, unsigned char *di_1,
1671 struct vb_device_info *pVBInfo)
1672{
1673 unsigned short index;
1674
Peter Huewea3d675c2012-02-09 21:11:47 +01001675 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001676 index = XGI_GetLCDCapPtr1(pVBInfo);
1677
1678 if (pVBInfo->VBInfo & SetCRT2ToLCD) { /* LCDB */
1679 *di_0 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData1;
1680 *di_1 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData2;
1681 } else { /* LCDA */
1682 *di_0 = pVBInfo->LCDCapList[index].LCDA_VCLKData1;
1683 *di_1 = pVBInfo->LCDCapList[index].LCDA_VCLKData2;
1684 }
1685 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001686}
1687
1688static unsigned char XGI_GetVCLKPtr(unsigned short RefreshRateTableIndex,
1689 unsigned short ModeNo, unsigned short ModeIdIndex,
1690 struct vb_device_info *pVBInfo)
1691{
1692
1693 unsigned short index, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001694 unsigned char tempal;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001695
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001696 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02001697 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001698
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001699 if ((pVBInfo->SetFlag & ProgrammingCRT2) &&
1700 (!(pVBInfo->LCDInfo & EnableScalingLCD))) { /* {LCDA/LCDB} */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001701 index = XGI_GetLCDCapPtr(pVBInfo);
1702 tempal = pVBInfo->LCDCapList[index].LCD_VCLK;
1703
Peter Huewea3d675c2012-02-09 21:11:47 +01001704 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001705 return tempal;
1706
1707 /* {TV} */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001708 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01001709 (VB_SIS301B |
1710 VB_SIS302B |
1711 VB_SIS301LV |
1712 VB_SIS302LV |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001713 VB_XGI301C)) {
Peter Huewe599801f2012-02-09 21:11:45 +01001714 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001715 tempal = TVCLKBASE_315 + HiTVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001716 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
Peter Hueweccc8cb22012-02-09 21:11:48 +01001717 tempal = TVCLKBASE_315 + HiTVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001718 if (pVBInfo->TVInfo & TVSimuMode) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001719 tempal = TVCLKBASE_315 + HiTVSimuVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001720 if (!(modeflag & Charx8Dot))
Miguel Gómez3bcc2462012-07-06 12:40:53 +02001721 tempal = TVCLKBASE_315 +
1722 HiTVTextVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001723
1724 }
1725 return tempal;
1726 }
1727
Peter Huewe599801f2012-02-09 21:11:45 +01001728 if (pVBInfo->TVInfo & TVSetYPbPr750p) {
Peter Huewea3d675c2012-02-09 21:11:47 +01001729 tempal = XGI_YPbPr750pVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001730 return tempal;
1731 }
1732
Peter Huewe599801f2012-02-09 21:11:45 +01001733 if (pVBInfo->TVInfo & TVSetYPbPr525p) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001734 tempal = YPbPr525pVCLK;
1735 return tempal;
1736 }
1737
1738 tempal = NTSC1024VCLK;
1739
1740 if (!(pVBInfo->TVInfo & NTSC1024x768)) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001741 tempal = TVCLKBASE_315 + TVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001742 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
Peter Hueweccc8cb22012-02-09 21:11:48 +01001743 tempal = TVCLKBASE_315 + TVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001744 }
1745
1746 if (pVBInfo->VBInfo & SetCRT2ToTV)
1747 return tempal;
1748 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001749 } /* {End of VB} */
1750
Peter Huewe516354e2013-02-15 20:37:11 +01001751 inb((pVBInfo->P3ca + 0x02));
Aaro Koskinena39325d2012-11-04 21:14:53 +02001752 tempal = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001753 return tempal;
1754}
1755
1756static void XGI_GetVCLKLen(unsigned char tempal, unsigned char *di_0,
1757 unsigned char *di_1, struct vb_device_info *pVBInfo)
1758{
Peter Huewe6896b942012-02-09 21:11:46 +01001759 if (pVBInfo->VBType & (VB_SIS301 | VB_SIS301B | VB_SIS302B
1760 | VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +02001761 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) &&
1762 (pVBInfo->SetFlag & ProgrammingCRT2)) {
Aaro Koskinene8cb03d2012-09-11 00:15:31 +03001763 *di_0 = XGI_VBVCLKData[tempal].Part4_A;
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +03001764 *di_1 = XGI_VBVCLKData[tempal].Part4_B;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001765 }
1766 } else {
1767 *di_0 = XGI_VCLKData[tempal].SR2B;
1768 *di_1 = XGI_VCLKData[tempal].SR2C;
1769 }
1770}
1771
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001772static void XGI_SetCRT2ECLK(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301773 unsigned short RefreshRateTableIndex,
1774 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001775{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301776 unsigned char di_0, di_1, tempal;
1777 int i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001778
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301779 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
1780 pVBInfo);
1781 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
1782 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001783
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301784 for (i = 0; i < 4; i++) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001785 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, ~0x30,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301786 (unsigned short) (0x10 * i));
Peter Huewea3d675c2012-02-09 21:11:47 +01001787 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301788 && (!(pVBInfo->VBInfo & SetInSlaveMode))) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001789 xgifb_reg_set(pVBInfo->P3c4, 0x2e, di_0);
1790 xgifb_reg_set(pVBInfo->P3c4, 0x2f, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301791 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001792 xgifb_reg_set(pVBInfo->P3c4, 0x2b, di_0);
1793 xgifb_reg_set(pVBInfo->P3c4, 0x2c, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301794 }
1795 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001796}
1797
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001798static void XGI_UpdateModeInfo(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301799 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001800{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301801 unsigned short tempcl, tempch, temp, tempbl, tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001802
Peter Huewe6896b942012-02-09 21:11:46 +01001803 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
1804 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301805 tempcl = 0;
1806 tempch = 0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02001807 temp = xgifb_reg_get(pVBInfo->P3c4, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001808
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301809 if (!(temp & 0x20)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001810 temp = xgifb_reg_get(pVBInfo->P3d4, 0x17);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301811 if (temp & 0x80) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001812 temp = xgifb_reg_get(pVBInfo->P3d4, 0x53);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301813 if (!(temp & 0x40))
1814 tempcl |= ActiveCRT1;
1815 }
1816 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001817
Aaro Koskinen58839b02011-03-13 12:26:23 +02001818 temp = xgifb_reg_get(pVBInfo->Part1Port, 0x2e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301819 temp &= 0x0f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001820
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301821 if (!(temp == 0x08)) {
Miguel Gómez949eb0a2012-07-06 12:40:36 +02001822 /* Check ChannelA */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001823 tempax = xgifb_reg_get(pVBInfo->Part1Port, 0x13);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301824 if (tempax & 0x04)
1825 tempcl = tempcl | ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001826
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301827 temp &= 0x05;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001828
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301829 if (!(tempcl & ActiveLCD))
1830 if (temp == 0x01)
1831 tempcl |= ActiveCRT2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001832
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301833 if (temp == 0x04)
1834 tempcl |= ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001835
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301836 if (temp == 0x05) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001837 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001838
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301839 if (!(temp & 0x08))
1840 tempch |= ActiveAVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001841
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301842 if (!(temp & 0x04))
1843 tempch |= ActiveSVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001844
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301845 if (temp & 0x02)
1846 tempch |= ActiveSCART;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001847
Peter Huewe599801f2012-02-09 21:11:45 +01001848 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301849 if (temp & 0x01)
1850 tempch |= ActiveHiTV;
1851 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001852
Peter Huewe599801f2012-02-09 21:11:45 +01001853 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001854 temp = xgifb_reg_get(
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301855 pVBInfo->Part2Port,
1856 0x4d);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001857
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301858 if (temp & 0x10)
1859 tempch |= ActiveYPbPr;
1860 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001861
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301862 if (tempch != 0)
1863 tempcl |= ActiveTV;
1864 }
1865 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001866
Aaro Koskinen58839b02011-03-13 12:26:23 +02001867 temp = xgifb_reg_get(pVBInfo->P3d4, 0x3d);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301868 if (tempcl & ActiveLCD) {
1869 if ((pVBInfo->SetFlag & ReserveTVOption)) {
1870 if (temp & ActiveTV)
1871 tempcl |= ActiveTV;
1872 }
1873 }
1874 temp = tempcl;
Peter Huewea3d675c2012-02-09 21:11:47 +01001875 tempbl = ~XGI_ModeSwitchStatus;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001876 xgifb_reg_and_or(pVBInfo->P3d4, 0x3d, tempbl, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001877
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301878 if (!(pVBInfo->SetFlag & ReserveTVOption))
Aaro Koskinen8104e322011-03-13 12:26:22 +02001879 xgifb_reg_set(pVBInfo->P3d4, 0x3e, tempch);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301880 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001881}
1882
Bill Pemberton80adad82010-06-17 13:10:51 -04001883void XGI_GetVBType(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001884{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301885 unsigned short flag, tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001886
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001887 tempbx = VB_SIS302B;
1888 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
1889 if (flag == 0x02)
1890 goto finish;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001891
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001892 tempbx = VB_SIS301;
1893 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x01);
1894 if (flag < 0xB0)
1895 goto finish;
1896
1897 tempbx = VB_SIS301B;
1898 if (flag < 0xC0)
1899 goto bigger_than_0xB0;
1900
1901 tempbx = VB_XGI301C;
1902 if (flag < 0xD0)
1903 goto bigger_than_0xB0;
1904
1905 tempbx = VB_SIS301LV;
1906 if (flag < 0xE0)
1907 goto bigger_than_0xB0;
1908
1909 tempbx = VB_SIS302LV;
1910 tempah = xgifb_reg_get(pVBInfo->Part4Port, 0x39);
1911 if (tempah != 0xFF)
1912 tempbx = VB_XGI301C;
1913
1914bigger_than_0xB0:
1915 if (tempbx & (VB_SIS301B | VB_SIS302B)) {
1916 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x23);
1917 if (!(flag & 0x02))
1918 tempbx = tempbx | VB_NoLCD;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301919 }
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001920
1921finish:
1922 pVBInfo->VBType = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001923}
1924
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02001925static void XGI_GetVBInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301926 struct xgi_hw_device_info *HwDeviceExtension,
1927 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001928{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301929 unsigned short tempax, push, tempbx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001930
Aaro Koskinenb3979922012-11-04 21:14:52 +02001931 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301932 pVBInfo->SetFlag = 0;
Peter Huewe6896b942012-02-09 21:11:46 +01001933 pVBInfo->ModeType = modeflag & ModeTypeMask;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301934 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001935
Miguel Gómezf9317352012-07-06 12:40:48 +02001936 if (!(pVBInfo->VBType & 0xFFFF))
1937 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001938
Miguel Gómezf9317352012-07-06 12:40:48 +02001939 /* Check Display Device */
1940 temp = xgifb_reg_get(pVBInfo->P3d4, 0x30);
1941 tempbx = tempbx | temp;
1942 temp = xgifb_reg_get(pVBInfo->P3d4, 0x31);
1943 push = temp;
1944 push = push << 8;
1945 tempax = temp << 8;
1946 tempbx = tempbx | tempax;
1947 temp = (SetCRT2ToDualEdge | SetCRT2ToYPbPr525750 | XGI_SetCRT2ToLCDA
1948 | SetInSlaveMode | DisableCRT2Display);
1949 temp = 0xFFFF ^ temp;
1950 tempbx &= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001951
Miguel Gómezf9317352012-07-06 12:40:48 +02001952 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001953
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001954 if (pVBInfo->VBType & (VB_SIS302B | VB_SIS301LV | VB_SIS302LV |
1955 VB_XGI301C)) {
1956 if (temp & EnableDualEdge) {
1957 tempbx |= SetCRT2ToDualEdge;
1958 if (temp & SetToLCDA)
1959 tempbx |= XGI_SetCRT2ToLCDA;
Miguel Gómezf9317352012-07-06 12:40:48 +02001960 }
1961 }
1962
Aaro Koskinena4ce0e72013-05-29 23:59:14 +03001963 if (pVBInfo->VBType & (VB_SIS301LV|VB_SIS302LV|VB_XGI301C)) {
1964 if (temp & SetYPbPr) {
1965 if (pVBInfo->IF_DEF_HiVision == 1) {
1966 /* shampoo add for new scratch */
1967 temp = xgifb_reg_get(pVBInfo->P3d4, 0x35);
1968 temp &= YPbPrMode;
1969 tempbx |= SetCRT2ToHiVision;
Miguel Gómezf9317352012-07-06 12:40:48 +02001970
Aaro Koskinena4ce0e72013-05-29 23:59:14 +03001971 if (temp != YPbPrMode1080i) {
1972 tempbx &= (~SetCRT2ToHiVision);
1973 tempbx |= SetCRT2ToYPbPr525750;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301974 }
1975 }
1976 }
Miguel Gómezf9317352012-07-06 12:40:48 +02001977 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001978
Miguel Gómezf9317352012-07-06 12:40:48 +02001979 tempax = push; /* restore CR31 */
1980
Aaro Koskinena4ce0e72013-05-29 23:59:14 +03001981 if (pVBInfo->IF_DEF_HiVision == 1)
1982 temp = 0x09FC;
1983 else
1984 temp = 0x097C;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001985
Miguel Gómezf9317352012-07-06 12:40:48 +02001986 if (!(tempbx & temp)) {
1987 tempax |= DisableCRT2Display;
1988 tempbx = 0;
1989 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001990
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03001991 if (!(pVBInfo->VBType & VB_NoLCD)) {
1992 if (tempbx & XGI_SetCRT2ToLCDA) {
1993 if (tempbx & SetSimuScanMode)
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001994 tempbx &= (~(SetCRT2ToLCD | SetCRT2ToRAMDAC |
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03001995 SwitchCRT2));
1996 else
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001997 tempbx &= (~(SetCRT2ToLCD | SetCRT2ToRAMDAC |
1998 SetCRT2ToTV | SwitchCRT2));
Miguel Gómezf9317352012-07-06 12:40:48 +02001999 }
2000 }
2001
2002 /* shampoo add */
2003 /* for driver abnormal */
2004 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode))) {
2005 if (pVBInfo->IF_DEF_CRT2Monitor == 1) {
2006 if (tempbx & SetCRT2ToRAMDAC) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002007 tempbx &= (0xFF00 | SetCRT2ToRAMDAC |
2008 SwitchCRT2 | SetSimuScanMode);
Peter Huewe599801f2012-02-09 21:11:45 +01002009 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302010 }
Miguel Gómezf9317352012-07-06 12:40:48 +02002011 } else {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002012 tempbx &= (~(SetCRT2ToRAMDAC | SetCRT2ToLCD |
Miguel Gómezf9317352012-07-06 12:40:48 +02002013 SetCRT2ToTV));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302014 }
Miguel Gómezf9317352012-07-06 12:40:48 +02002015 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002016
Miguel Gómezf9317352012-07-06 12:40:48 +02002017 if (!(pVBInfo->VBType & VB_NoLCD)) {
2018 if (tempbx & SetCRT2ToLCD) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002019 tempbx &= (0xFF00 | SetCRT2ToLCD | SwitchCRT2 |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002020 SetSimuScanMode);
Peter Huewe599801f2012-02-09 21:11:45 +01002021 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302022 }
Miguel Gómezf9317352012-07-06 12:40:48 +02002023 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002024
Miguel Gómezf9317352012-07-06 12:40:48 +02002025 if (tempbx & SetCRT2ToSCART) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002026 tempbx &= (0xFF00 | SetCRT2ToSCART | SwitchCRT2 |
Miguel Gómezf9317352012-07-06 12:40:48 +02002027 SetSimuScanMode);
2028 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
2029 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002030
Aaro Koskinena4ce0e72013-05-29 23:59:14 +03002031 if (tempbx & SetCRT2ToYPbPr525750)
2032 tempbx &= (0xFF00 | SwitchCRT2 | SetSimuScanMode);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002033
Miguel Gómezf9317352012-07-06 12:40:48 +02002034 if (pVBInfo->IF_DEF_HiVision == 1) {
2035 if (tempbx & SetCRT2ToHiVision)
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002036 tempbx &= (0xFF00 | SetCRT2ToHiVision | SwitchCRT2 |
Miguel Gómezf9317352012-07-06 12:40:48 +02002037 SetSimuScanMode);
2038 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002039
Miguel Gómezf9317352012-07-06 12:40:48 +02002040 if (tempax & DisableCRT2Display) { /* Set Display Device Info */
2041 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode)))
2042 tempbx = DisableCRT2Display;
2043 }
2044
2045 if (!(tempbx & DisableCRT2Display)) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002046 if ((!(tempbx & DriverMode)) || (!(modeflag & CRT2Mode))) {
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03002047 if (!(tempbx & XGI_SetCRT2ToLCDA))
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002048 tempbx |= (SetInSlaveMode | SetSimuScanMode);
Miguel Gómezf9317352012-07-06 12:40:48 +02002049 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002050
Miguel Gómezf9317352012-07-06 12:40:48 +02002051 /* LCD+TV can't support in slave mode
2052 * (Force LCDA+TV->LCDB) */
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002053 if ((tempbx & SetInSlaveMode) && (tempbx & XGI_SetCRT2ToLCDA)) {
2054 tempbx ^= (SetCRT2ToLCD | XGI_SetCRT2ToLCDA |
Miguel Gómezf9317352012-07-06 12:40:48 +02002055 SetCRT2ToDualEdge);
2056 pVBInfo->SetFlag |= ReserveTVOption;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302057 }
2058 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002059
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302060 pVBInfo->VBInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002061}
2062
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02002063static void XGI_GetTVInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302064 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002065{
Peter Huewe5fc699f2013-02-03 04:08:45 +01002066 unsigned short tempbx = 0, resinfo = 0, modeflag, index1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002067
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302068 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinenb3979922012-11-04 21:14:52 +02002069 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2070 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002071
Peter Huewe5fc699f2013-02-03 04:08:45 +01002072 tempbx = xgifb_reg_get(pVBInfo->P3d4, 0x35);
2073 if (tempbx & TVSetPAL) {
2074 tempbx &= (SetCHTVOverScan |
2075 TVSetPALM |
2076 TVSetPALN |
2077 TVSetPAL);
2078 if (tempbx & TVSetPALM)
2079 /* set to NTSC if PAL-M */
2080 tempbx &= ~TVSetPAL;
2081 } else
2082 tempbx &= (SetCHTVOverScan |
2083 TVSetNTSCJ |
2084 TVSetPAL);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002085
Aaro Koskinena8b35292013-02-09 00:03:45 +02002086 if (pVBInfo->VBInfo & SetCRT2ToSCART)
2087 tempbx |= TVSetPAL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002088
Aaro Koskinena4ce0e72013-05-29 23:59:14 +03002089 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
2090 index1 = xgifb_reg_get(pVBInfo->P3d4, 0x35);
2091 index1 &= YPbPrMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002092
Aaro Koskinena4ce0e72013-05-29 23:59:14 +03002093 if (index1 == YPbPrMode525i)
2094 tempbx |= TVSetYPbPr525i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002095
Aaro Koskinena4ce0e72013-05-29 23:59:14 +03002096 if (index1 == YPbPrMode525p)
2097 tempbx = tempbx | TVSetYPbPr525p;
2098 if (index1 == YPbPrMode750p)
2099 tempbx = tempbx | TVSetYPbPr750p;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302100 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002101
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302102 if (pVBInfo->IF_DEF_HiVision == 1) {
Peter Huewe599801f2012-02-09 21:11:45 +01002103 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
2104 tempbx = tempbx | TVSetHiVision | TVSetPAL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302105 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002106
Aaro Koskinena8b35292013-02-09 00:03:45 +02002107 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
2108 (!(pVBInfo->VBInfo & SetNotSimuMode)))
2109 tempbx |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002110
Aaro Koskinena8b35292013-02-09 00:03:45 +02002111 if (!(tempbx & TVSetPAL) && (modeflag > 13) && (resinfo == 8))
2112 /* NTSC 1024x768, */
2113 tempbx |= NTSC1024x768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002114
Aaro Koskinena8b35292013-02-09 00:03:45 +02002115 tempbx |= RPLLDIV2XO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002116
Aaro Koskinena8b35292013-02-09 00:03:45 +02002117 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
2118 if (pVBInfo->VBInfo & SetInSlaveMode)
2119 tempbx &= (~RPLLDIV2XO);
2120 } else if (tempbx & (TVSetYPbPr525p | TVSetYPbPr750p)) {
2121 tempbx &= (~RPLLDIV2XO);
2122 } else if (!(pVBInfo->VBType & (VB_SIS301B | VB_SIS302B |
2123 VB_SIS301LV | VB_SIS302LV |
2124 VB_XGI301C))) {
2125 if (tempbx & TVSimuMode)
2126 tempbx &= (~RPLLDIV2XO);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302127 }
2128 }
2129 pVBInfo->TVInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002130}
2131
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02002132static unsigned char XGI_GetLCDInfo(unsigned short ModeNo,
2133 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002134{
Peter Hueweef9a6b92013-02-03 04:08:43 +01002135 unsigned short temp, tempax, tempbx, resinfo = 0, LCDIdIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002136
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302137 pVBInfo->LCDResInfo = 0;
2138 pVBInfo->LCDTypeInfo = 0;
2139 pVBInfo->LCDInfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002140
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002141 /* si+Ext_ResInfo // */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002142 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinen58839b02011-03-13 12:26:23 +02002143 temp = xgifb_reg_get(pVBInfo->P3d4, 0x36); /* Get LCD Res.Info */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302144 tempbx = temp & 0x0F;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002145
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302146 if (tempbx == 0)
Peter Huewe255aabd2012-02-09 21:11:44 +01002147 tempbx = Panel_1024x768; /* default */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002148
Miguel Gómez949eb0a2012-07-06 12:40:36 +02002149 /* LCD75 */
Peter Huewe255aabd2012-02-09 21:11:44 +01002150 if ((tempbx == Panel_1024x768) || (tempbx == Panel_1280x1024)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302151 if (pVBInfo->VBInfo & DriverMode) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002152 tempax = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Peter Huewea3d675c2012-02-09 21:11:47 +01002153 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302154 tempax &= 0x0F;
2155 else
2156 tempax = tempax >> 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002157
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302158 if ((resinfo == 6) || (resinfo == 9)) {
2159 if (tempax >= 3)
2160 tempbx |= PanelRef75Hz;
2161 } else if ((resinfo == 7) || (resinfo == 8)) {
2162 if (tempax >= 4)
2163 tempbx |= PanelRef75Hz;
2164 }
2165 }
2166 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002167
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302168 pVBInfo->LCDResInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002169
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302170 /* End of LCD75 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002171
Peter Huewea3d675c2012-02-09 21:11:47 +01002172 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302173 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002174
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302175 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002176
Aaro Koskinen58839b02011-03-13 12:26:23 +02002177 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002178
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302179 temp &= (ScalingLCD | LCDNonExpanding | LCDSyncBit | SetPWDEnable);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002180
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302181 tempbx |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002182
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302183 LCDIdIndex = XGI_GetLCDCapPtr1(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002184
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302185 tempax = pVBInfo->LCDCapList[LCDIdIndex].LCD_Capability;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002186
Aaro Koskinen718e7152013-02-09 00:03:46 +02002187 if (((pVBInfo->VBType & VB_SIS302LV) ||
2188 (pVBInfo->VBType & VB_XGI301C)) && (tempax & XGI_LCDDualLink))
2189 tempbx |= SetLCDDualLink;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002190
Aaro Koskinen718e7152013-02-09 00:03:46 +02002191 if ((pVBInfo->LCDResInfo == Panel_1400x1050) &&
2192 (pVBInfo->VBInfo & SetCRT2ToLCD) && (resinfo == 9) &&
2193 (!(tempbx & EnableScalingLCD)))
2194 /*
2195 * set to center in 1280x1024 LCDB
2196 * for Panel_1400x1050
2197 */
2198 tempbx |= SetLCDtoNonExpanding;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002199
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302200 if (pVBInfo->VBInfo & SetInSlaveMode) {
2201 if (pVBInfo->VBInfo & SetNotSimuMode)
Peter Huewea3d675c2012-02-09 21:11:47 +01002202 tempbx |= XGI_LCDVESATiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302203 } else {
Peter Huewea3d675c2012-02-09 21:11:47 +01002204 tempbx |= XGI_LCDVESATiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302205 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002206
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302207 pVBInfo->LCDInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002208
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302209 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002210}
2211
Bill Pemberton108afbf2010-06-17 13:10:47 -04002212unsigned char XGI_SearchModeID(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302213 unsigned short *ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002214{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002215 for (*ModeIdIndex = 0;; (*ModeIdIndex)++) {
Aaro Koskinenb3979922012-11-04 21:14:52 +02002216 if (XGI330_EModeIDTable[*ModeIdIndex].Ext_ModeID == ModeNo)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002217 break;
Aaro Koskinenb3979922012-11-04 21:14:52 +02002218 if (XGI330_EModeIDTable[*ModeIdIndex].Ext_ModeID == 0xFF)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002219 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302220 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002221
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302222 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002223}
2224
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002225static unsigned char XG21GPIODataTransfer(unsigned char ujDate)
2226{
2227 unsigned char ujRet = 0;
2228 unsigned char i = 0;
2229
2230 for (i = 0; i < 8; i++) {
2231 ujRet = ujRet << 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002232 ujRet |= (ujDate >> i) & 1;
2233 }
2234
2235 return ujRet;
2236}
2237
2238/*----------------------------------------------------------------------------*/
2239/* output */
2240/* bl[5] : LVDS signal */
2241/* bl[1] : LVDS backlight */
2242/* bl[0] : LVDS VDD */
2243/*----------------------------------------------------------------------------*/
2244static unsigned char XGI_XG21GetPSCValue(struct vb_device_info *pVBInfo)
2245{
2246 unsigned char CR4A, temp;
2247
Aaro Koskinen58839b02011-03-13 12:26:23 +02002248 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02002249 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x23); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002250
Aaro Koskinen58839b02011-03-13 12:26:23 +02002251 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002252
2253 temp = XG21GPIODataTransfer(temp);
2254 temp &= 0x23;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002255 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002256 return temp;
2257}
2258
2259/*----------------------------------------------------------------------------*/
2260/* output */
2261/* bl[5] : LVDS signal */
2262/* bl[1] : LVDS backlight */
2263/* bl[0] : LVDS VDD */
2264/*----------------------------------------------------------------------------*/
2265static unsigned char XGI_XG27GetPSCValue(struct vb_device_info *pVBInfo)
2266{
2267 unsigned char CR4A, CRB4, temp;
2268
Aaro Koskinen58839b02011-03-13 12:26:23 +02002269 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02002270 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x0C); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002271
Aaro Koskinen58839b02011-03-13 12:26:23 +02002272 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002273
2274 temp &= 0x0C;
2275 temp >>= 2;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002276 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinen58839b02011-03-13 12:26:23 +02002277 CRB4 = xgifb_reg_get(pVBInfo->P3d4, 0xB4);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002278 temp |= ((CRB4 & 0x04) << 3);
2279 return temp;
2280}
2281
Aaro Koskinen0ebf5382011-11-27 23:03:09 +02002282/*----------------------------------------------------------------------------*/
2283/* input */
2284/* bl[5] : 1;LVDS signal on */
2285/* bl[1] : 1;LVDS backlight on */
2286/* bl[0] : 1:LVDS VDD on */
2287/* bh: 100000b : clear bit 5, to set bit5 */
2288/* 000010b : clear bit 1, to set bit1 */
2289/* 000001b : clear bit 0, to set bit0 */
2290/*----------------------------------------------------------------------------*/
2291static void XGI_XG21BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
2292 struct vb_device_info *pVBInfo)
2293{
2294 unsigned char CR4A, temp;
2295
2296 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
2297 tempbh &= 0x23;
2298 tempbl &= 0x23;
2299 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
2300
2301 if (tempbh & 0x20) {
2302 temp = (tempbl >> 4) & 0x02;
2303
2304 /* CR B4[1] */
2305 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
2306
2307 }
2308
2309 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
2310
2311 temp = XG21GPIODataTransfer(temp);
2312 temp &= ~tempbh;
2313 temp |= tempbl;
2314 xgifb_reg_set(pVBInfo->P3d4, 0x48, temp);
2315}
2316
Aaro Koskinen776115a2011-11-27 23:03:10 +02002317static void XGI_XG27BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
2318 struct vb_device_info *pVBInfo)
2319{
2320 unsigned char CR4A, temp;
2321 unsigned short tempbh0, tempbl0;
2322
2323 tempbh0 = tempbh;
2324 tempbl0 = tempbl;
2325 tempbh0 &= 0x20;
2326 tempbl0 &= 0x20;
2327 tempbh0 >>= 3;
2328 tempbl0 >>= 3;
2329
2330 if (tempbh & 0x20) {
2331 temp = (tempbl >> 4) & 0x02;
2332
2333 /* CR B4[1] */
2334 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
2335
2336 }
2337 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~tempbh0, tempbl0);
2338
2339 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
2340 tempbh &= 0x03;
2341 tempbl &= 0x03;
2342 tempbh <<= 2;
2343 tempbl <<= 2; /* GPIOC,GPIOD */
2344 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
2345 xgifb_reg_and_or(pVBInfo->P3d4, 0x48, ~tempbh, tempbl);
2346}
2347
Aaro Koskinenfab04b92011-12-06 00:10:45 +02002348static void XGI_DisplayOn(struct xgifb_video_info *xgifb_info,
2349 struct xgi_hw_device_info *pXGIHWDE,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302350 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002351{
2352
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002353 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302354 if (pXGIHWDE->jChipType == XG21) {
2355 if (pVBInfo->IF_DEF_LVDS == 1) {
2356 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002357 /* LVDS VDD on */
2358 XGI_XG21BLSignalVDD(0x01, 0x01, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002359 mdelay(xgifb_info->lvds_data.PSC_S2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302360 }
2361 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002362 /* LVDS signal on */
2363 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002364 mdelay(xgifb_info->lvds_data.PSC_S3);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002365 /* LVDS backlight on */
2366 XGI_XG21BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302367 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002368 /* DVO/DVI signal on */
2369 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302370 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002371
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302372 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002373
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302374 if (pXGIHWDE->jChipType == XG27) {
2375 if (pVBInfo->IF_DEF_LVDS == 1) {
2376 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002377 /* LVDS VDD on */
2378 XGI_XG27BLSignalVDD(0x01, 0x01, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002379 mdelay(xgifb_info->lvds_data.PSC_S2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302380 }
2381 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002382 /* LVDS signal on */
2383 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002384 mdelay(xgifb_info->lvds_data.PSC_S3);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002385 /* LVDS backlight on */
2386 XGI_XG27BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302387 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002388 /* DVO/DVI signal on */
2389 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302390 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002391
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302392 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002393}
2394
Aaro Koskinenfab04b92011-12-06 00:10:45 +02002395void XGI_DisplayOff(struct xgifb_video_info *xgifb_info,
2396 struct xgi_hw_device_info *pXGIHWDE,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302397 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002398{
2399
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302400 if (pXGIHWDE->jChipType == XG21) {
2401 if (pVBInfo->IF_DEF_LVDS == 1) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002402 /* LVDS backlight off */
2403 XGI_XG21BLSignalVDD(0x02, 0x00, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002404 mdelay(xgifb_info->lvds_data.PSC_S3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302405 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002406 /* DVO/DVI signal off */
2407 XGI_XG21BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302408 }
2409 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002410
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302411 if (pXGIHWDE->jChipType == XG27) {
2412 if ((XGI_XG27GetPSCValue(pVBInfo) & 0x2)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002413 /* LVDS backlight off */
2414 XGI_XG27BLSignalVDD(0x02, 0x00, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002415 mdelay(xgifb_info->lvds_data.PSC_S3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302416 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002417
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302418 if (pVBInfo->IF_DEF_LVDS == 0)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002419 /* DVO/DVI signal off */
2420 XGI_XG27BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302421 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002422
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002423 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x20);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002424}
2425
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002426static void XGI_WaitDisply(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002427{
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02002428 while ((inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302429 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002430
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02002431 while (!(inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302432 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002433}
2434
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002435static void XGI_AutoThreshold(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002436{
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002437 xgifb_reg_or(pVBInfo->Part1Port, 0x01, 0x40);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002438}
2439
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002440static void XGI_SaveCRT2Info(unsigned short ModeNo,
2441 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002442{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302443 unsigned short temp1, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002444
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002445 /* reserve CR34 for CRT1 Mode No */
2446 xgifb_reg_set(pVBInfo->P3d4, 0x34, ModeNo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302447 temp1 = (pVBInfo->VBInfo & SetInSlaveMode) >> 8;
2448 temp2 = ~(SetInSlaveMode >> 8);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002449 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, temp2, temp1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002450}
2451
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002452static void XGI_GetCRT2ResInfo(unsigned short ModeNo,
2453 unsigned short ModeIdIndex,
2454 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002455{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302456 unsigned short xres, yres, modeflag, resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002457
Aaro Koskinenb3979922012-11-04 21:14:52 +02002458 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02002459 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
2460 yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002461 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002462 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002463
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002464 if (modeflag & HalfDCLK)
2465 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002466
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002467 if (modeflag & DoubleScanMode)
2468 yres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002469
Miguel Gómez3339db82012-07-06 12:40:49 +02002470 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
2471 goto exit;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002472
Aaro Koskinen22006832013-02-09 00:03:47 +02002473 if (pVBInfo->LCDResInfo == Panel_1600x1200) {
2474 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
2475 if (yres == 1024)
2476 yres = 1056;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302477 }
Aaro Koskinen22006832013-02-09 00:03:47 +02002478 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002479
Aaro Koskinen22006832013-02-09 00:03:47 +02002480 if (pVBInfo->LCDResInfo == Panel_1280x1024) {
2481 if (yres == 400)
2482 yres = 405;
2483 else if (yres == 350)
2484 yres = 360;
Miguel Gómez3339db82012-07-06 12:40:49 +02002485
Aaro Koskinen22006832013-02-09 00:03:47 +02002486 if (pVBInfo->LCDInfo & XGI_LCDVESATiming) {
2487 if (yres == 360)
2488 yres = 375;
Miguel Gómez3339db82012-07-06 12:40:49 +02002489 }
Aaro Koskinen22006832013-02-09 00:03:47 +02002490 }
Miguel Gómez3339db82012-07-06 12:40:49 +02002491
Aaro Koskinen22006832013-02-09 00:03:47 +02002492 if (pVBInfo->LCDResInfo == Panel_1024x768) {
2493 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
2494 if (!(pVBInfo->LCDInfo & LCDNonExpanding)) {
2495 if (yres == 350)
2496 yres = 357;
2497 else if (yres == 400)
2498 yres = 420;
2499 else if (yres == 480)
2500 yres = 525;
Miguel Gómez3339db82012-07-06 12:40:49 +02002501 }
2502 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302503 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002504
Miguel Gómez3339db82012-07-06 12:40:49 +02002505 if (xres == 720)
2506 xres = 640;
2507
2508exit:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302509 pVBInfo->VGAHDE = xres;
2510 pVBInfo->HDE = xres;
2511 pVBInfo->VGAVDE = yres;
2512 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002513}
2514
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002515static unsigned char XGI_IsLCDDualLink(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002516{
2517
Peter Huewea3d675c2012-02-09 21:11:47 +01002518 if ((pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) &&
Dan Carpentera65fd092011-01-04 09:02:27 +03002519 (pVBInfo->LCDInfo & SetLCDDualLink)) /* shampoo0129 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302520 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002521
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302522 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002523}
2524
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002525static void XGI_GetRAMDAC2DATA(unsigned short ModeNo,
2526 unsigned short ModeIdIndex,
2527 unsigned short RefreshRateTableIndex,
2528 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002529{
2530 unsigned short tempax, tempbx, temp1, temp2, modeflag = 0, tempcx,
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002531 CRT1Index;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002532
2533 pVBInfo->RVBHCMAX = 1;
2534 pVBInfo->RVBHCFACT = 1;
Aaro Koskinenb3979922012-11-04 21:14:52 +02002535 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02002536 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002537 CRT1Index &= IndexMask;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002538 temp1 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[0];
2539 temp2 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[5];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002540 tempax = (temp1 & 0xFF) | ((temp2 & 0x03) << 8);
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002541 tempbx = (unsigned short) XGI_CRT1Table[CRT1Index].CR[8];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002542 tempcx = (unsigned short)
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002543 XGI_CRT1Table[CRT1Index].CR[14] << 8;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002544 tempcx &= 0x0100;
2545 tempcx = tempcx << 2;
2546 tempbx |= tempcx;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002547 temp1 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[9];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002548
2549 if (temp1 & 0x01)
2550 tempbx |= 0x0100;
2551
2552 if (temp1 & 0x20)
2553 tempbx |= 0x0200;
2554 tempax += 5;
2555
2556 if (modeflag & Charx8Dot)
2557 tempax *= 8;
2558 else
2559 tempax *= 9;
2560
2561 pVBInfo->VGAHT = tempax;
2562 pVBInfo->HT = tempax;
2563 tempbx++;
2564 pVBInfo->VGAVT = tempbx;
2565 pVBInfo->VT = tempbx;
2566}
2567
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002568static void XGI_GetCRT2Data(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302569 unsigned short RefreshRateTableIndex,
2570 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002571{
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02002572 unsigned short tempax = 0, tempbx = 0, modeflag, resinfo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002573
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02002574 struct SiS_LCDData const *LCDPtr = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002575
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002576 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002577 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2578 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302579 pVBInfo->NewFlickerMode = 0;
2580 pVBInfo->RVBHRS = 50;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002581
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302582 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
2583 XGI_GetRAMDAC2DATA(ModeNo, ModeIdIndex, RefreshRateTableIndex,
2584 pVBInfo);
2585 return;
2586 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002587
Peter Huewea3d675c2012-02-09 21:11:47 +01002588 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02002589 LCDPtr = XGI_GetLcdPtr(XGI_LCDDataTable, ModeNo, ModeIdIndex,
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +03002590 RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002591
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302592 pVBInfo->RVBHCMAX = LCDPtr->RVBHCMAX;
2593 pVBInfo->RVBHCFACT = LCDPtr->RVBHCFACT;
2594 pVBInfo->VGAHT = LCDPtr->VGAHT;
2595 pVBInfo->VGAVT = LCDPtr->VGAVT;
2596 pVBInfo->HT = LCDPtr->LCDHT;
2597 pVBInfo->VT = LCDPtr->LCDVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002598
Peter Huewe255aabd2012-02-09 21:11:44 +01002599 if (pVBInfo->LCDResInfo == Panel_1024x768) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302600 tempax = 1024;
2601 tempbx = 768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002602
Peter Huewea3d675c2012-02-09 21:11:47 +01002603 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302604 if (pVBInfo->VGAVDE == 357)
2605 tempbx = 527;
2606 else if (pVBInfo->VGAVDE == 420)
2607 tempbx = 620;
2608 else if (pVBInfo->VGAVDE == 525)
2609 tempbx = 775;
2610 else if (pVBInfo->VGAVDE == 600)
2611 tempbx = 775;
Peter Huewe7580d7f2013-05-18 00:19:54 +02002612 }
Peter Huewe255aabd2012-02-09 21:11:44 +01002613 } else if (pVBInfo->LCDResInfo == Panel_1024x768x75) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302614 tempax = 1024;
2615 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01002616 } else if (pVBInfo->LCDResInfo == Panel_1280x1024) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302617 tempax = 1280;
2618 if (pVBInfo->VGAVDE == 360)
2619 tempbx = 768;
2620 else if (pVBInfo->VGAVDE == 375)
2621 tempbx = 800;
2622 else if (pVBInfo->VGAVDE == 405)
2623 tempbx = 864;
2624 else
2625 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01002626 } else if (pVBInfo->LCDResInfo == Panel_1280x1024x75) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302627 tempax = 1280;
2628 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01002629 } else if (pVBInfo->LCDResInfo == Panel_1280x960) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302630 tempax = 1280;
2631 if (pVBInfo->VGAVDE == 350)
2632 tempbx = 700;
2633 else if (pVBInfo->VGAVDE == 400)
2634 tempbx = 800;
2635 else if (pVBInfo->VGAVDE == 1024)
2636 tempbx = 960;
2637 else
2638 tempbx = 960;
Peter Huewe255aabd2012-02-09 21:11:44 +01002639 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302640 tempax = 1400;
2641 tempbx = 1050;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002642
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302643 if (pVBInfo->VGAVDE == 1024) {
2644 tempax = 1280;
2645 tempbx = 1024;
2646 }
Peter Huewe255aabd2012-02-09 21:11:44 +01002647 } else if (pVBInfo->LCDResInfo == Panel_1600x1200) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302648 tempax = 1600;
2649 tempbx = 1200; /* alan 10/14/2003 */
Peter Huewea3d675c2012-02-09 21:11:47 +01002650 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302651 if (pVBInfo->VGAVDE == 350)
2652 tempbx = 875;
2653 else if (pVBInfo->VGAVDE == 400)
2654 tempbx = 1000;
2655 }
2656 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002657
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302658 if (pVBInfo->LCDInfo & LCDNonExpanding) {
2659 tempax = pVBInfo->VGAHDE;
2660 tempbx = pVBInfo->VGAVDE;
2661 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002662
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302663 pVBInfo->HDE = tempax;
2664 pVBInfo->VDE = tempbx;
2665 return;
2666 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002667
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302668 if (pVBInfo->VBInfo & (SetCRT2ToTV)) {
Aaro Koskinen24572542012-09-11 00:15:21 +03002669 struct SiS_TVData const *TVPtr;
2670
2671 TVPtr = XGI_GetTVPtr(ModeNo, ModeIdIndex, RefreshRateTableIndex,
2672 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002673
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302674 pVBInfo->RVBHCMAX = TVPtr->RVBHCMAX;
2675 pVBInfo->RVBHCFACT = TVPtr->RVBHCFACT;
2676 pVBInfo->VGAHT = TVPtr->VGAHT;
2677 pVBInfo->VGAVT = TVPtr->VGAVT;
2678 pVBInfo->HDE = TVPtr->TVHDE;
2679 pVBInfo->VDE = TVPtr->TVVDE;
2680 pVBInfo->RVBHRS = TVPtr->RVBHRS;
2681 pVBInfo->NewFlickerMode = TVPtr->FlickerMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002682
Peter Huewe599801f2012-02-09 21:11:45 +01002683 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302684 if (resinfo == 0x08)
2685 pVBInfo->NewFlickerMode = 0x40;
2686 else if (resinfo == 0x09)
2687 pVBInfo->NewFlickerMode = 0x40;
2688 else if (resinfo == 0x12)
2689 pVBInfo->NewFlickerMode = 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002690
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302691 if (pVBInfo->VGAVDE == 350)
2692 pVBInfo->TVInfo |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002693
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302694 tempax = ExtHiTVHT;
2695 tempbx = ExtHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002696
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302697 if (pVBInfo->VBInfo & SetInSlaveMode) {
2698 if (pVBInfo->TVInfo & TVSimuMode) {
2699 tempax = StHiTVHT;
2700 tempbx = StHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002701
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302702 if (!(modeflag & Charx8Dot)) {
2703 tempax = StHiTextTVHT;
2704 tempbx = StHiTextTVVT;
2705 }
2706 }
2707 }
Peter Huewe599801f2012-02-09 21:11:45 +01002708 } else if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
2709 if (pVBInfo->TVInfo & TVSetYPbPr750p) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302710 tempax = YPbPrTV750pHT; /* Ext750pTVHT */
2711 tempbx = YPbPrTV750pVT; /* Ext750pTVVT */
2712 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002713
Peter Huewe599801f2012-02-09 21:11:45 +01002714 if (pVBInfo->TVInfo & TVSetYPbPr525p) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302715 tempax = YPbPrTV525pHT; /* Ext525pTVHT */
2716 tempbx = YPbPrTV525pVT; /* Ext525pTVVT */
Peter Huewe599801f2012-02-09 21:11:45 +01002717 } else if (pVBInfo->TVInfo & TVSetYPbPr525i) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302718 tempax = YPbPrTV525iHT; /* Ext525iTVHT */
2719 tempbx = YPbPrTV525iVT; /* Ext525iTVVT */
2720 if (pVBInfo->TVInfo & NTSC1024x768)
2721 tempax = NTSC1024x768HT;
2722 }
2723 } else {
2724 tempax = PALHT;
2725 tempbx = PALVT;
Peter Huewe599801f2012-02-09 21:11:45 +01002726 if (!(pVBInfo->TVInfo & TVSetPAL)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302727 tempax = NTSCHT;
2728 tempbx = NTSCVT;
2729 if (pVBInfo->TVInfo & NTSC1024x768)
2730 tempax = NTSC1024x768HT;
2731 }
2732 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002733
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302734 pVBInfo->HT = tempax;
2735 pVBInfo->VT = tempbx;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302736 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002737}
2738
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002739static void XGI_SetCRT2VCLK(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302740 unsigned short RefreshRateTableIndex,
2741 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002742{
Bill Pemberton108afbf2010-06-17 13:10:47 -04002743 unsigned char di_0, di_1, tempal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002744
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302745 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
2746 pVBInfo);
2747 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
2748 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002749
Peter Huewe6896b942012-02-09 21:11:46 +01002750 if (pVBInfo->VBType & VB_SIS301) { /* shampoo 0129 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302751 /* 301 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002752 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, 0x10);
2753 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
2754 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302755 } else { /* 301b/302b/301lv/302lv */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002756 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
2757 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302758 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002759
Aaro Koskinen8104e322011-03-13 12:26:22 +02002760 xgifb_reg_set(pVBInfo->Part4Port, 0x00, 0x12);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002761
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302762 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02002763 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x28);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302764 else
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02002765 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002766}
2767
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002768static unsigned short XGI_GetColorDepth(unsigned short ModeNo,
2769 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002770{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002771 unsigned short ColorDepth[6] = { 1, 2, 4, 4, 6, 8 };
2772 short index;
2773 unsigned short modeflag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302774
Aaro Koskinenb3979922012-11-04 21:14:52 +02002775 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Peter Huewe6896b942012-02-09 21:11:46 +01002776 index = (modeflag & ModeTypeMask) - ModeEGA;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302777
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002778 if (index < 0)
2779 index = 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302780
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002781 return ColorDepth[index];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302782}
2783
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002784static unsigned short XGI_GetOffset(unsigned short ModeNo,
2785 unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302786 unsigned short RefreshRateTableIndex,
2787 struct xgi_hw_device_info *HwDeviceExtension,
2788 struct vb_device_info *pVBInfo)
2789{
2790 unsigned short temp, colordepth, modeinfo, index, infoflag,
2791 ColorDepth[] = { 0x01, 0x02, 0x04 };
2792
Aaro Koskinenb3979922012-11-04 21:14:52 +02002793 modeinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeInfo;
Aaro Koskinena39325d2012-11-04 21:14:53 +02002794 infoflag = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302795
2796 index = (modeinfo >> 8) & 0xFF;
2797
Aaro Koskinen224114c2012-11-04 21:14:59 +02002798 temp = XGI330_ScreenOffset[index];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302799
2800 if (infoflag & InterlaceMode)
2801 temp = temp << 1;
2802
2803 colordepth = XGI_GetColorDepth(ModeNo, ModeIdIndex, pVBInfo);
2804
2805 if ((ModeNo >= 0x7C) && (ModeNo <= 0x7E)) {
2806 temp = ModeNo - 0x7C;
2807 colordepth = ColorDepth[temp];
2808 temp = 0x6B;
2809 if (infoflag & InterlaceMode)
2810 temp = temp << 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302811 }
Peter Huewe053004b2013-02-15 20:37:12 +01002812 return temp * colordepth;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302813}
2814
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002815static void XGI_SetCRT2Offset(unsigned short ModeNo,
2816 unsigned short ModeIdIndex,
2817 unsigned short RefreshRateTableIndex,
2818 struct xgi_hw_device_info *HwDeviceExtension,
2819 struct vb_device_info *pVBInfo)
2820{
2821 unsigned short offset;
2822 unsigned char temp;
2823
2824 if (pVBInfo->VBInfo & SetInSlaveMode)
2825 return;
2826
2827 offset = XGI_GetOffset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
2828 HwDeviceExtension, pVBInfo);
2829 temp = (unsigned char) (offset & 0xFF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002830 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002831 temp = (unsigned char) ((offset & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002832 xgifb_reg_set(pVBInfo->Part1Port, 0x09, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002833 temp = (unsigned char) (((offset >> 3) & 0xFF) + 1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002834 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002835}
2836
Randy Dunlap89229672010-08-10 08:46:44 -07002837static void XGI_SetCRT2FIFO(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002838{
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002839 /* threshold high ,disable auto threshold */
2840 xgifb_reg_set(pVBInfo->Part1Port, 0x01, 0x3B);
2841 /* threshold low default 04h */
2842 xgifb_reg_and_or(pVBInfo->Part1Port, 0x02, ~(0x3F), 0x04);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002843}
2844
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002845static void XGI_PreSetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302846 struct xgi_hw_device_info *HwDeviceExtension,
2847 unsigned short RefreshRateTableIndex,
2848 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002849{
Peter Hueweef9a6b92013-02-03 04:08:43 +01002850 u8 tempcx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002851
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302852 XGI_SetCRT2Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
2853 HwDeviceExtension, pVBInfo);
2854 XGI_SetCRT2FIFO(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002855
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302856 for (tempcx = 4; tempcx < 7; tempcx++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02002857 xgifb_reg_set(pVBInfo->Part1Port, tempcx, 0x0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002858
Aaro Koskinen8104e322011-03-13 12:26:22 +02002859 xgifb_reg_set(pVBInfo->Part1Port, 0x50, 0x00);
2860 xgifb_reg_set(pVBInfo->Part1Port, 0x02, 0x44); /* temp 0206 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002861}
2862
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002863static void XGI_SetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302864 struct xgi_hw_device_info *HwDeviceExtension,
2865 unsigned short RefreshRateTableIndex,
2866 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002867{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302868 unsigned short temp = 0, tempax = 0, tempbx = 0, tempcx = 0,
Peter Hueweef9a6b92013-02-03 04:08:43 +01002869 pushbx = 0, CRT1Index, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002870
Aaro Koskinena39325d2012-11-04 21:14:53 +02002871 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002872 CRT1Index &= IndexMask;
Aaro Koskinenb3979922012-11-04 21:14:52 +02002873 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002874
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302875 /* bainy change table name */
2876 if (modeflag & HalfDCLK) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002877 /* BTVGA2HT 0x08,0x09 */
2878 temp = (pVBInfo->VGAHT / 2 - 1) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002879 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302880 temp = (((pVBInfo->VGAHT / 2 - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002881 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002882 /* BTVGA2HDEE 0x0A,0x0C */
2883 temp = (pVBInfo->VGAHDE / 2 + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002884 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302885 tempcx = ((pVBInfo->VGAHT - pVBInfo->VGAHDE) / 2) >> 2;
2886 pushbx = pVBInfo->VGAHDE / 2 + 16;
2887 tempcx = tempcx >> 1;
2888 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
2889 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002890
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302891 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002892 tempbx = XGI_CRT1Table[CRT1Index].CR[4];
2893 tempbx |= ((XGI_CRT1Table[CRT1Index].CR[14] &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002894 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302895 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002896 tempcx = XGI_CRT1Table[CRT1Index].CR[5];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302897 tempcx &= 0x1F;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002898 temp = XGI_CRT1Table[CRT1Index].CR[15];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302899 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
2900 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
2901 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002902
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302903 tempbx += 4;
2904 tempcx += 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002905
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302906 if (tempcx > (pVBInfo->VGAHT / 2))
2907 tempcx = pVBInfo->VGAHT / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002908
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302909 temp = tempbx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002910
Aaro Koskinen8104e322011-03-13 12:26:22 +02002911 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302912 } else {
2913 temp = (pVBInfo->VGAHT - 1) & 0x0FF; /* BTVGA2HT 0x08,0x09 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002914 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302915 temp = (((pVBInfo->VGAHT - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002916 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002917 /* BTVGA2HDEE 0x0A,0x0C */
2918 temp = (pVBInfo->VGAHDE + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002919 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302920 tempcx = (pVBInfo->VGAHT - pVBInfo->VGAHDE) >> 2; /* cx */
2921 pushbx = pVBInfo->VGAHDE + 16;
2922 tempcx = tempcx >> 1;
2923 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
2924 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002925
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302926 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002927 tempbx = XGI_CRT1Table[CRT1Index].CR[3];
2928 tempbx |= ((XGI_CRT1Table[CRT1Index].CR[5] &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002929 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302930 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002931 tempcx = XGI_CRT1Table[CRT1Index].CR[4];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302932 tempcx &= 0x1F;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002933 temp = XGI_CRT1Table[CRT1Index].CR[6];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302934 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
2935 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
2936 tempbx += 16;
2937 tempcx += 16;
2938 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002939
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302940 if (tempcx > pVBInfo->VGAHT)
2941 tempcx = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002942
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302943 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002944 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302945 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002946
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302947 tempax = (tempax & 0x00FF) | (tempbx & 0xFF00);
2948 tempbx = pushbx;
2949 tempbx = (tempbx & 0x00FF) | ((tempbx & 0xFF00) << 4);
2950 tempax |= (tempbx & 0xFF00);
2951 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002952 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302953 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002954 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302955 tempcx = (pVBInfo->VGAVT - 1);
2956 temp = tempcx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002957
Aaro Koskinen8104e322011-03-13 12:26:22 +02002958 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302959 tempbx = pVBInfo->VGAVDE - 1;
2960 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002961 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302962 temp = ((tempbx & 0xFF00) << 3) >> 8;
2963 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002964 xgifb_reg_set(pVBInfo->Part1Port, 0x12, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002965
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002966 /* BTVGA2VRS 0x10,0x11 */
2967 tempbx = (pVBInfo->VGAVT + pVBInfo->VGAVDE) >> 1;
2968 /* BTVGA2VRE 0x11 */
2969 tempcx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) >> 4) + tempbx + 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002970
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302971 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002972 tempbx = XGI_CRT1Table[CRT1Index].CR[10];
2973 temp = XGI_CRT1Table[CRT1Index].CR[9];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002974
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302975 if (temp & 0x04)
2976 tempbx |= 0x0100;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002977
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302978 if (temp & 0x080)
2979 tempbx |= 0x0200;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002980
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002981 temp = XGI_CRT1Table[CRT1Index].CR[14];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002982
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302983 if (temp & 0x08)
2984 tempbx |= 0x0400;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002985
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002986 temp = XGI_CRT1Table[CRT1Index].CR[11];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302987 tempcx = (tempcx & 0xFF00) | (temp & 0x00FF);
2988 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002989
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302990 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002991 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302992 temp = ((tempbx & 0xFF00) >> 8) << 4;
2993 temp = ((tempcx & 0x000F) | (temp));
Aaro Koskinen8104e322011-03-13 12:26:22 +02002994 xgifb_reg_set(pVBInfo->Part1Port, 0x11, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302995 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002996
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302997 if (modeflag & DoubleScanMode)
2998 tempax |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002999
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303000 if (modeflag & HalfDCLK)
3001 tempax |= 0x40;
3002
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003003 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2C, ~0x0C0, tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003004}
3005
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003006static unsigned short XGI_GetVGAHT2(struct vb_device_info *pVBInfo)
3007{
3008 unsigned long tempax, tempbx;
3009
3010 tempbx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) * pVBInfo->RVBHCMAX)
3011 & 0xFFFF;
3012 tempax = (pVBInfo->VT - pVBInfo->VDE) * pVBInfo->RVBHCFACT;
3013 tempax = (tempax * pVBInfo->HT) / tempbx;
3014
3015 return (unsigned short) tempax;
3016}
3017
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003018static void XGI_SetLockRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303019 struct xgi_hw_device_info *HwDeviceExtension,
3020 unsigned short RefreshRateTableIndex,
3021 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003022{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303023 unsigned short push1, push2, tempax, tempbx = 0, tempcx, temp, resinfo,
Peter Hueweef9a6b92013-02-03 04:08:43 +01003024 modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003025
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003026 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02003027 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3028 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003029
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303030 if (!(pVBInfo->VBInfo & SetInSlaveMode))
3031 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003032
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303033 temp = 0xFF; /* set MAX HT */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003034 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303035 tempcx = 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003036
Peter Huewe6896b942012-02-09 21:11:46 +01003037 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303038 modeflag |= Charx8Dot;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003039
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303040 tempax = pVBInfo->VGAHDE; /* 0x04 Horizontal Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003041
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303042 if (modeflag & HalfDCLK)
3043 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003044
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303045 tempax = (tempax / tempcx) - 1;
3046 tempbx |= ((tempax & 0x00FF) << 8);
3047 temp = tempax & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003048 xgifb_reg_set(pVBInfo->Part1Port, 0x04, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003049
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303050 temp = (tempbx & 0xFF00) >> 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003051
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303052 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Peter Huewe6896b942012-02-09 21:11:46 +01003053 if (!(pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3054 | VB_SIS302LV | VB_XGI301C)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303055 temp += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003056
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03003057 if ((pVBInfo->VBInfo & SetCRT2ToHiVision) &&
3058 !(pVBInfo->VBType & VB_SIS301LV) && (resinfo == 7))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303059 temp -= 2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303060 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003061
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003062 /* 0x05 Horizontal Display Start */
3063 xgifb_reg_set(pVBInfo->Part1Port, 0x05, temp);
3064 /* 0x06 Horizontal Blank end */
3065 xgifb_reg_set(pVBInfo->Part1Port, 0x06, 0x03);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003066
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303067 if (!(pVBInfo->VBInfo & DisableCRT2Display)) { /* 030226 bainy */
3068 if (pVBInfo->VBInfo & SetCRT2ToTV)
3069 tempax = pVBInfo->VGAHT;
3070 else
3071 tempax = XGI_GetVGAHT2(pVBInfo);
3072 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003073
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303074 if (tempax >= pVBInfo->VGAHT)
3075 tempax = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003076
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303077 if (modeflag & HalfDCLK)
3078 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003079
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303080 tempax = (tempax / tempcx) - 5;
3081 tempcx = tempax; /* 20030401 0x07 horizontal Retrace Start */
Peter Huewe599801f2012-02-09 21:11:45 +01003082 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303083 temp = (tempbx & 0x00FF) - 1;
3084 if (!(modeflag & HalfDCLK)) {
3085 temp -= 6;
3086 if (pVBInfo->TVInfo & TVSimuMode) {
3087 temp -= 4;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003088 temp -= 10;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303089 }
3090 }
3091 } else {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303092 tempbx = (tempbx & 0xFF00) >> 8;
3093 tempcx = (tempcx + tempbx) >> 1;
3094 temp = (tempcx & 0x00FF) + 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003095
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303096 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3097 temp -= 1;
3098 if (!(modeflag & HalfDCLK)) {
3099 if ((modeflag & Charx8Dot)) {
3100 temp += 4;
3101 if (pVBInfo->VGAHDE >= 800)
3102 temp -= 6;
3103 }
3104 }
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003105 } else if (!(modeflag & HalfDCLK)) {
3106 temp -= 4;
Peter Huewe255aabd2012-02-09 21:11:44 +01003107 if (pVBInfo->LCDResInfo != Panel_1280x960 &&
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003108 pVBInfo->VGAHDE >= 800) {
3109 temp -= 7;
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003110 if (pVBInfo->VGAHDE >= 1280 &&
Peter Huewe255aabd2012-02-09 21:11:44 +01003111 pVBInfo->LCDResInfo != Panel_1280x960 &&
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003112 (pVBInfo->LCDInfo & LCDNonExpanding))
3113 temp += 28;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303114 }
3115 }
3116 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003117
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003118 /* 0x07 Horizontal Retrace Start */
3119 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
3120 /* 0x08 Horizontal Retrace End */
3121 xgifb_reg_set(pVBInfo->Part1Port, 0x08, 0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003122
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303123 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3124 if (pVBInfo->TVInfo & TVSimuMode) {
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003125 if (ModeNo == 0x50) {
Peter Huewe85b38472013-05-13 23:41:49 +02003126 if (pVBInfo->TVInfo == SetNTSCTV) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003127 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303128 0x07, 0x30);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003129 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303130 0x08, 0x03);
3131 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003132 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303133 0x07, 0x2f);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003134 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303135 0x08, 0x02);
3136 }
3137 }
3138 }
3139 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003140
Aaro Koskinen8104e322011-03-13 12:26:22 +02003141 xgifb_reg_set(pVBInfo->Part1Port, 0x18, 0x03); /* 0x18 SR0B */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003142 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0xF0, 0x00);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003143 xgifb_reg_set(pVBInfo->Part1Port, 0x09, 0xFF); /* 0x09 Set Max VT */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003144
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303145 tempbx = pVBInfo->VGAVT;
3146 push1 = tempbx;
3147 tempcx = 0x121;
3148 tempbx = pVBInfo->VGAVDE; /* 0x0E Virtical Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003149
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303150 if (tempbx == 357)
3151 tempbx = 350;
3152 if (tempbx == 360)
3153 tempbx = 350;
3154 if (tempbx == 375)
3155 tempbx = 350;
3156 if (tempbx == 405)
3157 tempbx = 400;
3158 if (tempbx == 525)
3159 tempbx = 480;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003160
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303161 push2 = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003162
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303163 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
Peter Huewe255aabd2012-02-09 21:11:44 +01003164 if (pVBInfo->LCDResInfo == Panel_1024x768) {
Peter Huewea3d675c2012-02-09 21:11:47 +01003165 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303166 if (tempbx == 350)
3167 tempbx += 5;
3168 if (tempbx == 480)
3169 tempbx += 5;
3170 }
3171 }
3172 }
3173 tempbx--;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303174 tempbx--;
3175 temp = tempbx & 0x00FF;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003176 /* 0x10 vertical Blank Start */
3177 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303178 tempbx = push2;
3179 tempbx--;
3180 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003181 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003182
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303183 if (tempbx & 0x0100)
3184 tempcx |= 0x0002;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003185
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303186 tempax = 0x000B;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003187
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303188 if (modeflag & DoubleScanMode)
3189 tempax |= 0x08000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003190
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303191 if (tempbx & 0x0200)
3192 tempcx |= 0x0040;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003193
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303194 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003195 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003196
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303197 if (tempbx & 0x0400)
3198 tempcx |= 0x0600;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003199
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003200 /* 0x11 Vertival Blank End */
3201 xgifb_reg_set(pVBInfo->Part1Port, 0x11, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303202
3203 tempax = push1;
3204 tempax -= tempbx; /* 0x0C Vertical Retrace Start */
3205 tempax = tempax >> 2;
3206 push1 = tempax; /* push ax */
3207
3208 if (resinfo != 0x09) {
3209 tempax = tempax << 1;
3210 tempbx += tempax;
3211 }
3212
Peter Huewe599801f2012-02-09 21:11:45 +01003213 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Miguel Gómez470c5332012-07-06 12:40:50 +02003214 if ((pVBInfo->VBType & VB_SIS301LV) &&
3215 !(pVBInfo->TVInfo & TVSetHiVision)) {
3216 if ((pVBInfo->TVInfo & TVSimuMode) &&
3217 (pVBInfo->TVInfo & TVSetPAL)) {
3218 if (!(pVBInfo->VBType & VB_SIS301LV) ||
3219 !(pVBInfo->TVInfo &
3220 (TVSetYPbPr525p |
3221 TVSetYPbPr750p |
3222 TVSetHiVision)))
3223 tempbx += 40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303224 }
3225 } else {
3226 tempbx -= 10;
3227 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003228 } else if (pVBInfo->TVInfo & TVSimuMode) {
3229 if (pVBInfo->TVInfo & TVSetPAL) {
3230 if (pVBInfo->VBType & VB_SIS301LV) {
3231 if (!(pVBInfo->TVInfo &
3232 (TVSetYPbPr525p |
3233 TVSetYPbPr750p |
3234 TVSetHiVision)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303235 tempbx += 40;
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003236 } else {
3237 tempbx += 40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303238 }
3239 }
3240 }
3241 tempax = push1;
3242 tempax = tempax >> 2;
3243 tempax++;
3244 tempax += tempbx;
3245 push1 = tempax; /* push ax */
3246
Peter Huewe599801f2012-02-09 21:11:45 +01003247 if ((pVBInfo->TVInfo & TVSetPAL)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303248 if (tempbx <= 513) {
3249 if (tempax >= 513)
3250 tempbx = 513;
3251 }
3252 }
3253
3254 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003255 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303256 tempbx--;
3257 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003258 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303259
3260 if (tempbx & 0x0100)
3261 tempcx |= 0x0008;
3262
3263 if (tempbx & 0x0200)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003264 xgifb_reg_and_or(pVBInfo->Part1Port, 0x0B, 0x0FF, 0x20);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303265
3266 tempbx++;
3267
3268 if (tempbx & 0x0100)
3269 tempcx |= 0x0004;
3270
3271 if (tempbx & 0x0200)
3272 tempcx |= 0x0080;
3273
3274 if (tempbx & 0x0400)
3275 tempcx |= 0x0C00;
3276
3277 tempbx = push1; /* pop ax */
3278 temp = tempbx & 0x00FF;
3279 temp &= 0x0F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003280 /* 0x0D vertical Retrace End */
3281 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303282
3283 if (tempbx & 0x0010)
3284 tempcx |= 0x2000;
3285
3286 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003287 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp); /* 0x0A CR07 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303288 temp = (tempcx & 0x0FF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003289 xgifb_reg_set(pVBInfo->Part1Port, 0x17, temp); /* 0x17 SR0A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303290 tempax = modeflag;
3291 temp = (tempax & 0xFF00) >> 8;
3292
3293 temp = (temp >> 1) & 0x09;
3294
Peter Huewe6896b942012-02-09 21:11:46 +01003295 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303296 temp |= 0x01;
3297
Aaro Koskinen8104e322011-03-13 12:26:22 +02003298 xgifb_reg_set(pVBInfo->Part1Port, 0x16, temp); /* 0x16 SR01 */
3299 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, 0); /* 0x0F CR14 */
3300 xgifb_reg_set(pVBInfo->Part1Port, 0x12, 0); /* 0x12 CR17 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303301
3302 if (pVBInfo->LCDInfo & LCDRGB18Bit)
3303 temp = 0x80;
3304 else
3305 temp = 0x00;
3306
Aaro Koskinen8104e322011-03-13 12:26:22 +02003307 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, temp); /* 0x1A SR0E */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003308}
3309
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003310static void XGI_SetGroup2(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303311 unsigned short RefreshRateTableIndex,
3312 struct xgi_hw_device_info *HwDeviceExtension,
3313 struct vb_device_info *pVBInfo)
3314{
3315 unsigned short i, j, tempax, tempbx, tempcx, temp, push1, push2,
Peter Hueweef9a6b92013-02-03 04:08:43 +01003316 modeflag;
Aaro Koskinend21222d2012-09-11 00:15:29 +03003317 unsigned char const *TimingPoint;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303318
3319 unsigned long longtemp, tempeax, tempebx, temp2, tempecx;
3320
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003321 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02003322 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303323
3324 tempax = 0;
3325
3326 if (!(pVBInfo->VBInfo & SetCRT2ToAVIDEO))
3327 tempax |= 0x0800;
3328
3329 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3330 tempax |= 0x0400;
3331
3332 if (pVBInfo->VBInfo & SetCRT2ToSCART)
3333 tempax |= 0x0200;
3334
Peter Huewe599801f2012-02-09 21:11:45 +01003335 if (!(pVBInfo->TVInfo & TVSetPAL))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303336 tempax |= 0x1000;
3337
Peter Huewe599801f2012-02-09 21:11:45 +01003338 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303339 tempax |= 0x0100;
3340
Peter Huewe599801f2012-02-09 21:11:45 +01003341 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303342 tempax &= 0xfe00;
3343
3344 tempax = (tempax & 0xff00) >> 8;
3345
Aaro Koskinen8104e322011-03-13 12:26:22 +02003346 xgifb_reg_set(pVBInfo->Part2Port, 0x0, tempax);
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003347 TimingPoint = XGI330_NTSCTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303348
Peter Huewe599801f2012-02-09 21:11:45 +01003349 if (pVBInfo->TVInfo & TVSetPAL)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003350 TimingPoint = XGI330_PALTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303351
Peter Huewe599801f2012-02-09 21:11:45 +01003352 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003353 TimingPoint = XGI330_HiTVExtTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303354
3355 if (pVBInfo->VBInfo & SetInSlaveMode)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003356 TimingPoint = XGI330_HiTVSt2Timing;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303357
3358 if (pVBInfo->SetFlag & TVSimuMode)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003359 TimingPoint = XGI330_HiTVSt1Timing;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303360
3361 if (!(modeflag & Charx8Dot))
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003362 TimingPoint = XGI330_HiTVTextTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303363 }
3364
Peter Huewe599801f2012-02-09 21:11:45 +01003365 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
3366 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003367 TimingPoint = XGI330_YPbPr525iTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303368
Peter Huewe599801f2012-02-09 21:11:45 +01003369 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003370 TimingPoint = XGI330_YPbPr525pTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303371
Peter Huewe599801f2012-02-09 21:11:45 +01003372 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003373 TimingPoint = XGI330_YPbPr750pTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303374 }
3375
3376 for (i = 0x01, j = 0; i <= 0x2D; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02003377 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303378
3379 for (i = 0x39; i <= 0x45; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003380 /* di->temp2[j] */
3381 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303382
3383 if (pVBInfo->VBInfo & SetCRT2ToTV)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003384 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303385
3386 temp = pVBInfo->NewFlickerMode;
3387 temp &= 0x80;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003388 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xFF, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303389
Peter Huewe599801f2012-02-09 21:11:45 +01003390 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303391 tempax = 520;
3392 else
3393 tempax = 440;
3394
3395 if (pVBInfo->VDE <= tempax) {
3396 tempax -= pVBInfo->VDE;
3397 tempax = tempax >> 2;
3398 tempax = (tempax & 0x00FF) | ((tempax & 0x00FF) << 8);
3399 push1 = tempax;
3400 temp = (tempax & 0xFF00) >> 8;
3401 temp += (unsigned short) TimingPoint[0];
3402
Peter Huewe6896b942012-02-09 21:11:46 +01003403 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3404 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303405 if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO
3406 | SetCRT2ToSVIDEO | SetCRT2ToSCART
Peter Huewe599801f2012-02-09 21:11:45 +01003407 | SetCRT2ToYPbPr525750)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303408 tempcx = pVBInfo->VGAHDE;
3409 if (tempcx >= 1024) {
3410 temp = 0x17; /* NTSC */
Peter Huewe599801f2012-02-09 21:11:45 +01003411 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303412 temp = 0x19; /* PAL */
3413 }
3414 }
3415 }
3416
Aaro Koskinen8104e322011-03-13 12:26:22 +02003417 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303418 tempax = push1;
3419 temp = (tempax & 0xFF00) >> 8;
3420 temp += TimingPoint[1];
3421
Peter Huewe6896b942012-02-09 21:11:46 +01003422 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3423 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303424 if ((pVBInfo->VBInfo & (SetCRT2ToAVIDEO
3425 | SetCRT2ToSVIDEO | SetCRT2ToSCART
Peter Huewe599801f2012-02-09 21:11:45 +01003426 | SetCRT2ToYPbPr525750))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303427 tempcx = pVBInfo->VGAHDE;
3428 if (tempcx >= 1024) {
3429 temp = 0x1D; /* NTSC */
Peter Huewe599801f2012-02-09 21:11:45 +01003430 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303431 temp = 0x52; /* PAL */
3432 }
3433 }
3434 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02003435 xgifb_reg_set(pVBInfo->Part2Port, 0x02, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303436 }
3437
3438 /* 301b */
3439 tempcx = pVBInfo->HT;
3440
3441 if (XGI_IsLCDDualLink(pVBInfo))
3442 tempcx = tempcx >> 1;
3443
3444 tempcx -= 2;
3445 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003446 xgifb_reg_set(pVBInfo->Part2Port, 0x1B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303447
3448 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003449 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303450
3451 tempcx = pVBInfo->HT >> 1;
3452 push1 = tempcx; /* push cx */
3453 tempcx += 7;
3454
Peter Huewe599801f2012-02-09 21:11:45 +01003455 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303456 tempcx -= 4;
3457
3458 temp = tempcx & 0x00FF;
3459 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003460 xgifb_reg_and_or(pVBInfo->Part2Port, 0x22, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303461
3462 tempbx = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
3463 tempbx += tempcx;
3464 push2 = tempbx;
3465 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003466 xgifb_reg_set(pVBInfo->Part2Port, 0x24, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303467 temp = (tempbx & 0xFF00) >> 8;
3468 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003469 xgifb_reg_and_or(pVBInfo->Part2Port, 0x25, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303470
3471 tempbx = push2;
3472 tempbx = tempbx + 8;
Peter Huewe599801f2012-02-09 21:11:45 +01003473 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303474 tempbx = tempbx - 4;
3475 tempcx = tempbx;
3476 }
3477
3478 temp = (tempbx & 0x00FF) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003479 xgifb_reg_and_or(pVBInfo->Part2Port, 0x29, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303480
3481 j += 2;
3482 tempcx += (TimingPoint[j] | ((TimingPoint[j + 1]) << 8));
3483 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003484 xgifb_reg_set(pVBInfo->Part2Port, 0x27, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303485 temp = ((tempcx & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003486 xgifb_reg_and_or(pVBInfo->Part2Port, 0x28, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303487
3488 tempcx += 8;
Peter Huewe599801f2012-02-09 21:11:45 +01003489 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303490 tempcx -= 4;
3491
3492 temp = tempcx & 0xFF;
3493 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003494 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2A, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303495
3496 tempcx = push1; /* pop cx */
3497 j += 2;
3498 temp = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
3499 tempcx -= temp;
3500 temp = tempcx & 0x00FF;
3501 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003502 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2D, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303503
3504 tempcx -= 11;
3505
3506 if (!(pVBInfo->VBInfo & SetCRT2ToTV)) {
3507 tempax = XGI_GetVGAHT2(pVBInfo);
3508 tempcx = tempax - 1;
3509 }
3510 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003511 xgifb_reg_set(pVBInfo->Part2Port, 0x2E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303512
3513 tempbx = pVBInfo->VDE;
3514
3515 if (pVBInfo->VGAVDE == 360)
3516 tempbx = 746;
3517 if (pVBInfo->VGAVDE == 375)
3518 tempbx = 746;
3519 if (pVBInfo->VGAVDE == 405)
3520 tempbx = 853;
3521
3522 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003523 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01003524 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003525 if (!(pVBInfo->TVInfo &
Peter Huewe599801f2012-02-09 21:11:45 +01003526 (TVSetYPbPr525p | TVSetYPbPr750p)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303527 tempbx = tempbx >> 1;
3528 } else
3529 tempbx = tempbx >> 1;
3530 }
3531
3532 tempbx -= 2;
3533 temp = tempbx & 0x00FF;
3534
Peter Huewe599801f2012-02-09 21:11:45 +01003535 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Huewe6896b942012-02-09 21:11:46 +01003536 if (pVBInfo->VBType & VB_SIS301LV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003537 if (pVBInfo->TVInfo & TVSetHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303538 if (pVBInfo->VBInfo & SetInSlaveMode) {
3539 if (ModeNo == 0x2f)
3540 temp += 1;
3541 }
3542 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003543 } else if (pVBInfo->VBInfo & SetInSlaveMode) {
3544 if (ModeNo == 0x2f)
3545 temp += 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303546 }
3547 }
3548
Aaro Koskinen8104e322011-03-13 12:26:22 +02003549 xgifb_reg_set(pVBInfo->Part2Port, 0x2F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303550
3551 temp = (tempcx & 0xFF00) >> 8;
3552 temp |= ((tempbx & 0xFF00) >> 8) << 6;
3553
Peter Huewe599801f2012-02-09 21:11:45 +01003554 if (!(pVBInfo->VBInfo & SetCRT2ToHiVision)) {
Peter Huewe6896b942012-02-09 21:11:46 +01003555 if (pVBInfo->VBType & VB_SIS301LV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003556 if (pVBInfo->TVInfo & TVSetHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303557 temp |= 0x10;
3558
3559 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3560 temp |= 0x20;
3561 }
3562 } else {
3563 temp |= 0x10;
3564 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3565 temp |= 0x20;
3566 }
3567 }
3568
Aaro Koskinen8104e322011-03-13 12:26:22 +02003569 xgifb_reg_set(pVBInfo->Part2Port, 0x30, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303570
Peter Huewe6896b942012-02-09 21:11:46 +01003571 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3572 | VB_SIS302LV | VB_XGI301C)) { /* TV gatingno */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303573 tempbx = pVBInfo->VDE;
3574 tempcx = tempbx - 2;
3575
3576 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003577 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p
3578 | TVSetYPbPr750p)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303579 tempbx = tempbx >> 1;
3580 }
3581
Peter Huewe6896b942012-02-09 21:11:46 +01003582 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303583 temp = 0;
3584 if (tempcx & 0x0400)
3585 temp |= 0x20;
3586
3587 if (tempbx & 0x0400)
3588 temp |= 0x40;
3589
Aaro Koskinen8104e322011-03-13 12:26:22 +02003590 xgifb_reg_set(pVBInfo->Part4Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303591 }
3592
3593 temp = (((tempbx - 3) & 0x0300) >> 8) << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003594 xgifb_reg_set(pVBInfo->Part2Port, 0x46, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303595 temp = (tempbx - 3) & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003596 xgifb_reg_set(pVBInfo->Part2Port, 0x47, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303597 }
3598
3599 tempbx = tempbx & 0x00FF;
3600
3601 if (!(modeflag & HalfDCLK)) {
3602 tempcx = pVBInfo->VGAHDE;
3603 if (tempcx >= pVBInfo->HDE) {
3604 tempbx |= 0x2000;
3605 tempax &= 0x00FF;
3606 }
3607 }
3608
3609 tempcx = 0x0101;
3610
3611 if (pVBInfo->VBInfo & SetCRT2ToTV) { /*301b*/
3612 if (pVBInfo->VGAHDE >= 1024) {
3613 tempcx = 0x1920;
3614 if (pVBInfo->VGAHDE >= 1280) {
3615 tempcx = 0x1420;
3616 tempbx = tempbx & 0xDFFF;
3617 }
3618 }
3619 }
3620
3621 if (!(tempbx & 0x2000)) {
3622 if (modeflag & HalfDCLK)
3623 tempcx = (tempcx & 0xFF00) | ((tempcx & 0x00FF) << 1);
3624
3625 push1 = tempbx;
3626 tempeax = pVBInfo->VGAHDE;
3627 tempebx = (tempcx & 0xFF00) >> 8;
3628 longtemp = tempeax * tempebx;
3629 tempecx = tempcx & 0x00FF;
3630 longtemp = longtemp / tempecx;
3631
3632 /* 301b */
3633 tempecx = 8 * 1024;
3634
Peter Huewe6896b942012-02-09 21:11:46 +01003635 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3636 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303637 tempecx = tempecx * 8;
3638 }
3639
3640 longtemp = longtemp * tempecx;
3641 tempecx = pVBInfo->HDE;
3642 temp2 = longtemp % tempecx;
3643 tempeax = longtemp / tempecx;
3644 if (temp2 != 0)
3645 tempeax += 1;
3646
3647 tempax = (unsigned short) tempeax;
3648
3649 /* 301b */
Peter Huewe6896b942012-02-09 21:11:46 +01003650 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3651 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303652 tempcx = ((tempax & 0xFF00) >> 5) >> 8;
3653 }
3654 /* end 301b */
3655
3656 tempbx = push1;
3657 tempbx = (unsigned short) (((tempeax & 0x0000FF00) & 0x1F00)
3658 | (tempbx & 0x00FF));
3659 tempax = (unsigned short) (((tempeax & 0x000000FF) << 8)
3660 | (tempax & 0x00FF));
3661 temp = (tempax & 0xFF00) >> 8;
3662 } else {
3663 temp = (tempax & 0x00FF) >> 8;
3664 }
3665
Aaro Koskinen8104e322011-03-13 12:26:22 +02003666 xgifb_reg_set(pVBInfo->Part2Port, 0x44, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303667 temp = (tempbx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003668 xgifb_reg_and_or(pVBInfo->Part2Port, 0x45, ~0x03F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303669 temp = tempcx & 0x00FF;
3670
3671 if (tempbx & 0x2000)
3672 temp = 0;
3673
3674 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
3675 temp |= 0x18;
3676
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003677 xgifb_reg_and_or(pVBInfo->Part2Port, 0x46, ~0x1F, temp);
Peter Huewe599801f2012-02-09 21:11:45 +01003678 if (pVBInfo->TVInfo & TVSetPAL) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303679 tempbx = 0x0382;
3680 tempcx = 0x007e;
3681 } else {
3682 tempbx = 0x0369;
3683 tempcx = 0x0061;
3684 }
3685
3686 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003687 xgifb_reg_set(pVBInfo->Part2Port, 0x4b, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303688 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003689 xgifb_reg_set(pVBInfo->Part2Port, 0x4c, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303690
3691 temp = ((tempcx & 0xFF00) >> 8) & 0x03;
3692 temp = temp << 2;
3693 temp |= ((tempbx & 0xFF00) >> 8) & 0x03;
3694
Peter Huewe599801f2012-02-09 21:11:45 +01003695 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303696 temp |= 0x10;
3697
Peter Huewe599801f2012-02-09 21:11:45 +01003698 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303699 temp |= 0x20;
3700
Peter Huewe599801f2012-02-09 21:11:45 +01003701 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303702 temp |= 0x60;
3703 }
3704
Aaro Koskinen8104e322011-03-13 12:26:22 +02003705 xgifb_reg_set(pVBInfo->Part2Port, 0x4d, temp);
Aaro Koskinen58839b02011-03-13 12:26:23 +02003706 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x43); /* 301b change */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003707 xgifb_reg_set(pVBInfo->Part2Port, 0x43, (unsigned short) (temp - 3));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303708
Peter Huewe599801f2012-02-09 21:11:45 +01003709 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303710 if (pVBInfo->TVInfo & NTSC1024x768) {
3711 TimingPoint = XGI_NTSC1024AdjTime;
3712 for (i = 0x1c, j = 0; i <= 0x30; i++, j++) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003713 xgifb_reg_set(pVBInfo->Part2Port, i,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303714 TimingPoint[j]);
3715 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02003716 xgifb_reg_set(pVBInfo->Part2Port, 0x43, 0x72);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303717 }
3718 }
3719
Miguel Gómez949eb0a2012-07-06 12:40:36 +02003720 /* Modify for 301C PALM Support */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303721 if (pVBInfo->VBType & VB_XGI301C) {
Peter Huewe599801f2012-02-09 21:11:45 +01003722 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003723 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x08,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303724 0x08); /* PALM Mode */
3725 }
3726
Peter Huewe599801f2012-02-09 21:11:45 +01003727 if (pVBInfo->TVInfo & TVSetPALM) {
Peter Huewe9388ad92013-02-15 20:37:10 +01003728 tempax = xgifb_reg_get(pVBInfo->Part2Port, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303729 tempax--;
Aaro Koskinendc505562011-03-13 12:26:26 +02003730 xgifb_reg_and(pVBInfo->Part2Port, 0x01, tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303731
Aaro Koskinendc505562011-03-13 12:26:26 +02003732 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xEF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303733 }
3734
Peter Huewe599801f2012-02-09 21:11:45 +01003735 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303736 if (!(pVBInfo->VBInfo & SetInSlaveMode))
Aaro Koskinen8104e322011-03-13 12:26:22 +02003737 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303738 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303739}
3740
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003741static void XGI_SetLCDRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303742 struct xgi_hw_device_info *HwDeviceExtension,
3743 unsigned short RefreshRateTableIndex,
3744 struct vb_device_info *pVBInfo)
3745{
Peter Hueweef9a6b92013-02-03 04:08:43 +01003746 unsigned short pushbx, tempax, tempbx, tempcx, temp, tempah,
3747 tempbh, tempch;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303748
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02003749 struct XGI_LCDDesStruct const *LCDBDesPtr = NULL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303750
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003751 /* si+Ext_ResInfo */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303752 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
3753 return;
3754
3755 tempbx = pVBInfo->HDE; /* RHACTE=HDE-1 */
3756
3757 if (XGI_IsLCDDualLink(pVBInfo))
3758 tempbx = tempbx >> 1;
3759
3760 tempbx -= 1;
3761 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003762 xgifb_reg_set(pVBInfo->Part2Port, 0x2C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303763 temp = (tempbx & 0xFF00) >> 8;
3764 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003765 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2B, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303766 temp = 0x01;
3767
Aaro Koskinen8104e322011-03-13 12:26:22 +02003768 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303769 tempbx = pVBInfo->VDE; /* RTVACTEO=(VDE-1)&0xFF */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303770 tempbx--;
3771 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003772 xgifb_reg_set(pVBInfo->Part2Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303773 temp = ((tempbx & 0xFF00) >> 8) & 0x07;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003774 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0C, ~0x07, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303775
3776 tempcx = pVBInfo->VT - 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303777 temp = tempcx & 0x00FF; /* RVTVT=VT-1 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003778 xgifb_reg_set(pVBInfo->Part2Port, 0x19, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303779 temp = (tempcx & 0xFF00) >> 8;
3780 temp = temp << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003781 xgifb_reg_set(pVBInfo->Part2Port, 0x1A, temp);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003782 xgifb_reg_and_or(pVBInfo->Part2Port, 0x09, 0xF0, 0x00);
3783 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xF0, 0x00);
3784 xgifb_reg_and_or(pVBInfo->Part2Port, 0x17, 0xFB, 0x00);
3785 xgifb_reg_and_or(pVBInfo->Part2Port, 0x18, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303786
Justin P. Mattock558f7582012-10-02 21:17:11 -07003787 /* Customized LCDB Does not add */
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02003788 if ((pVBInfo->VBType & VB_SIS301LV) || (pVBInfo->VBType & VB_SIS302LV))
3789 LCDBDesPtr = XGI_GetLcdPtr(xgifb_lcddldes, ModeNo, ModeIdIndex,
3790 RefreshRateTableIndex, pVBInfo);
3791 else
3792 LCDBDesPtr = XGI_GetLcdPtr(XGI_LCDDesDataTable, ModeNo,
3793 ModeIdIndex, RefreshRateTableIndex,
3794 pVBInfo);
3795
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303796 tempah = pVBInfo->LCDResInfo;
3797 tempah &= PanelResInfo;
3798
Peter Huewe255aabd2012-02-09 21:11:44 +01003799 if ((tempah == Panel_1024x768) || (tempah == Panel_1024x768x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303800 tempbx = 1024;
3801 tempcx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01003802 } else if ((tempah == Panel_1280x1024) ||
3803 (tempah == Panel_1280x1024x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303804 tempbx = 1280;
3805 tempcx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01003806 } else if (tempah == Panel_1400x1050) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303807 tempbx = 1400;
3808 tempcx = 1050;
3809 } else {
3810 tempbx = 1600;
3811 tempcx = 1200;
3812 }
3813
3814 if (pVBInfo->LCDInfo & EnableScalingLCD) {
3815 tempbx = pVBInfo->HDE;
3816 tempcx = pVBInfo->VDE;
3817 }
3818
3819 pushbx = tempbx;
3820 tempax = pVBInfo->VT;
3821 pVBInfo->LCDHDES = LCDBDesPtr->LCDHDES;
3822 pVBInfo->LCDHRS = LCDBDesPtr->LCDHRS;
3823 pVBInfo->LCDVDES = LCDBDesPtr->LCDVDES;
3824 pVBInfo->LCDVRS = LCDBDesPtr->LCDVRS;
3825 tempbx = pVBInfo->LCDVDES;
3826 tempcx += tempbx;
3827
3828 if (tempcx >= tempax)
3829 tempcx -= tempax; /* lcdvdes */
3830
3831 temp = tempbx & 0x00FF; /* RVEQ1EQ=lcdvdes */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003832 xgifb_reg_set(pVBInfo->Part2Port, 0x05, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303833 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003834 xgifb_reg_set(pVBInfo->Part2Port, 0x06, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303835 tempch = ((tempcx & 0xFF00) >> 8) & 0x07;
3836 tempbh = ((tempbx & 0xFF00) >> 8) & 0x07;
3837 tempah = tempch;
3838 tempah = tempah << 3;
3839 tempah |= tempbh;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003840 xgifb_reg_set(pVBInfo->Part2Port, 0x02, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303841
3842 /* getlcdsync() */
3843 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
3844 tempcx = tempbx;
3845 tempax = pVBInfo->VT;
3846 tempbx = pVBInfo->LCDVRS;
3847
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303848 tempcx += tempbx;
3849 if (tempcx >= tempax)
3850 tempcx -= tempax;
3851
3852 temp = tempbx & 0x00FF; /* RTVACTEE=lcdvrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003853 xgifb_reg_set(pVBInfo->Part2Port, 0x04, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303854 temp = (tempbx & 0xFF00) >> 8;
3855 temp = temp << 4;
3856 temp |= (tempcx & 0x000F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003857 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303858 tempcx = pushbx;
3859 tempax = pVBInfo->HT;
3860 tempbx = pVBInfo->LCDHDES;
3861 tempbx &= 0x0FFF;
3862
3863 if (XGI_IsLCDDualLink(pVBInfo)) {
3864 tempax = tempax >> 1;
3865 tempbx = tempbx >> 1;
3866 tempcx = tempcx >> 1;
3867 }
3868
Peter Huewe6896b942012-02-09 21:11:46 +01003869 if (pVBInfo->VBType & VB_SIS302LV)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303870 tempbx += 1;
3871
3872 if (pVBInfo->VBType & VB_XGI301C) /* tap4 */
3873 tempbx += 1;
3874
3875 tempcx += tempbx;
3876
3877 if (tempcx >= tempax)
3878 tempcx -= tempax;
3879
3880 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003881 xgifb_reg_set(pVBInfo->Part2Port, 0x1F, temp); /* RHBLKE=lcdhdes */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303882 temp = ((tempbx & 0xFF00) >> 8) << 4;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003883 xgifb_reg_set(pVBInfo->Part2Port, 0x20, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303884 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003885 xgifb_reg_set(pVBInfo->Part2Port, 0x23, temp); /* RHEQPLE=lcdhdee */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303886 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003887 xgifb_reg_set(pVBInfo->Part2Port, 0x25, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303888
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303889 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
3890 tempcx = tempax;
3891 tempax = pVBInfo->HT;
3892 tempbx = pVBInfo->LCDHRS;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303893 if (XGI_IsLCDDualLink(pVBInfo)) {
3894 tempax = tempax >> 1;
3895 tempbx = tempbx >> 1;
3896 tempcx = tempcx >> 1;
3897 }
3898
Peter Huewe6896b942012-02-09 21:11:46 +01003899 if (pVBInfo->VBType & VB_SIS302LV)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303900 tempbx += 1;
3901
3902 tempcx += tempbx;
3903
3904 if (tempcx >= tempax)
3905 tempcx -= tempax;
3906
3907 temp = tempbx & 0x00FF; /* RHBURSTS=lcdhrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003908 xgifb_reg_set(pVBInfo->Part2Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303909
3910 temp = (tempbx & 0xFF00) >> 8;
3911 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003912 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303913 temp = tempcx & 0x00FF; /* RHSYEXP2S=lcdhre */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003914 xgifb_reg_set(pVBInfo->Part2Port, 0x21, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303915
Peter Huewea3d675c2012-02-09 21:11:47 +01003916 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303917 if (pVBInfo->VGAVDE == 525) {
Peter Huewe6896b942012-02-09 21:11:46 +01003918 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
3919 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303920 | VB_XGI301C)) {
3921 temp = 0xC6;
3922 } else
3923 temp = 0xC4;
3924
Aaro Koskinen8104e322011-03-13 12:26:22 +02003925 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
3926 xgifb_reg_set(pVBInfo->Part2Port, 0x30, 0xB3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303927 }
3928
3929 if (pVBInfo->VGAVDE == 420) {
Peter Huewe6896b942012-02-09 21:11:46 +01003930 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
3931 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303932 | VB_XGI301C)) {
3933 temp = 0x4F;
3934 } else
3935 temp = 0x4E;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003936 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303937 }
3938 }
3939}
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003940
3941/* --------------------------------------------------------------------- */
3942/* Function : XGI_GetTap4Ptr */
3943/* Input : */
3944/* Output : di -> Tap4 Reg. Setting Pointer */
3945/* Description : */
3946/* --------------------------------------------------------------------- */
Aaro Koskinen1cccd9e2012-11-04 21:15:06 +02003947static struct XGI301C_Tap4TimingStruct const
3948*XGI_GetTap4Ptr(unsigned short tempcx, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003949{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303950 unsigned short tempax, tempbx, i;
Aaro Koskinen1cccd9e2012-11-04 21:15:06 +02003951 struct XGI301C_Tap4TimingStruct const *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003952
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303953 if (tempcx == 0) {
3954 tempax = pVBInfo->VGAHDE;
3955 tempbx = pVBInfo->HDE;
3956 } else {
3957 tempax = pVBInfo->VGAVDE;
3958 tempbx = pVBInfo->VDE;
3959 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003960
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03003961 if (tempax <= tempbx)
3962 return &xgifb_tap4_timing[0];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303963 else
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03003964 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing; /* NTSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003965
Peter Huewe599801f2012-02-09 21:11:45 +01003966 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303967 Tap4TimingPtr = PALTap4Timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003968
Peter Huewe599801f2012-02-09 21:11:45 +01003969 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
3970 if ((pVBInfo->TVInfo & TVSetYPbPr525i) ||
3971 (pVBInfo->TVInfo & TVSetYPbPr525p))
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03003972 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing;
Peter Huewe599801f2012-02-09 21:11:45 +01003973 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303974 Tap4TimingPtr = YPbPr750pTap4Timing;
3975 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003976
Peter Huewe599801f2012-02-09 21:11:45 +01003977 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03003978 Tap4TimingPtr = xgifb_tap4_timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003979
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303980 i = 0;
3981 while (Tap4TimingPtr[i].DE != 0xFFFF) {
3982 if (Tap4TimingPtr[i].DE == tempax)
3983 break;
3984 i++;
3985 }
3986 return &Tap4TimingPtr[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003987}
3988
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003989static void XGI_SetTap4Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003990{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303991 unsigned short i, j;
Aaro Koskinen1cccd9e2012-11-04 21:15:06 +02003992 struct XGI301C_Tap4TimingStruct const *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003993
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303994 if (!(pVBInfo->VBType & VB_XGI301C))
3995 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003996
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303997 Tap4TimingPtr = XGI_GetTap4Ptr(0, pVBInfo); /* Set Horizontal Scaling */
3998 for (i = 0x80, j = 0; i <= 0xBF; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02003999 xgifb_reg_set(pVBInfo->Part2Port, i, Tap4TimingPtr->Reg[j]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004000
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004001 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
Peter Huewe599801f2012-02-09 21:11:45 +01004002 (!(pVBInfo->VBInfo & SetCRT2ToHiVision))) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004003 /* Set Vertical Scaling */
4004 Tap4TimingPtr = XGI_GetTap4Ptr(1, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304005 for (i = 0xC0, j = 0; i < 0xFF; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004006 xgifb_reg_set(pVBInfo->Part2Port,
4007 i,
4008 Tap4TimingPtr->Reg[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304009 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004010
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004011 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
Peter Huewe599801f2012-02-09 21:11:45 +01004012 (!(pVBInfo->VBInfo & SetCRT2ToHiVision)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004013 /* Enable V.Scaling */
4014 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304015 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004016 /* Enable H.Scaling */
4017 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x10);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004018}
4019
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004020static void XGI_SetGroup3(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304021 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004022{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304023 unsigned short i;
Aaro Koskinend21222d2012-09-11 00:15:29 +03004024 unsigned char const *tempdi;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304025 unsigned short modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004026
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004027 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004028 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004029
Aaro Koskinen8104e322011-03-13 12:26:22 +02004030 xgifb_reg_set(pVBInfo->Part3Port, 0x00, 0x00);
Peter Huewe599801f2012-02-09 21:11:45 +01004031 if (pVBInfo->TVInfo & TVSetPAL) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004032 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
4033 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304034 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004035 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xF5);
4036 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xB7);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304037 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004038
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304039 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
4040 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004041
Peter Huewe599801f2012-02-09 21:11:45 +01004042 if (pVBInfo->TVInfo & TVSetPALM) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004043 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
4044 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
4045 xgifb_reg_set(pVBInfo->Part3Port, 0x3D, 0xA8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304046 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004047
Peter Huewe599801f2012-02-09 21:11:45 +01004048 if ((pVBInfo->VBInfo & SetCRT2ToHiVision) || (pVBInfo->VBInfo
4049 & SetCRT2ToYPbPr525750)) {
4050 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304051 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004052
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004053 tempdi = XGI330_HiTVGroup3Data;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304054 if (pVBInfo->SetFlag & TVSimuMode) {
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004055 tempdi = XGI330_HiTVGroup3Simu;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304056 if (!(modeflag & Charx8Dot))
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004057 tempdi = XGI330_HiTVGroup3Text;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304058 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004059
Peter Huewe599801f2012-02-09 21:11:45 +01004060 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004061 tempdi = XGI330_Ren525pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004062
Peter Huewe599801f2012-02-09 21:11:45 +01004063 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004064 tempdi = XGI330_Ren750pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004065
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304066 for (i = 0; i <= 0x3E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004067 xgifb_reg_set(pVBInfo->Part3Port, i, tempdi[i]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004068
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304069 if (pVBInfo->VBType & VB_XGI301C) { /* Marcovision */
Peter Huewe599801f2012-02-09 21:11:45 +01004070 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004071 xgifb_reg_set(pVBInfo->Part3Port, 0x28, 0x3f);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304072 }
4073 }
Aaro Koskinen2351d1f2013-05-29 23:59:13 +03004074}
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304075
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004076static void XGI_SetGroup4(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304077 unsigned short RefreshRateTableIndex,
4078 struct xgi_hw_device_info *HwDeviceExtension,
4079 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004080{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304081 unsigned short tempax, tempcx, tempbx, modeflag, temp, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004082
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304083 unsigned long tempebx, tempeax, templong;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004084
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004085 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004086 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304087 temp = pVBInfo->RVBHCFACT;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004088 xgifb_reg_set(pVBInfo->Part4Port, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004089
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304090 tempbx = pVBInfo->RVBHCMAX;
4091 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004092 xgifb_reg_set(pVBInfo->Part4Port, 0x14, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304093 temp2 = ((tempbx & 0xFF00) >> 8) << 7;
4094 tempcx = pVBInfo->VGAHT - 1;
4095 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004096 xgifb_reg_set(pVBInfo->Part4Port, 0x16, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004097
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304098 temp = ((tempcx & 0xFF00) >> 8) << 3;
4099 temp2 |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004100
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304101 tempcx = pVBInfo->VGAVT - 1;
4102 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
4103 tempcx -= 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004104
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304105 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004106 xgifb_reg_set(pVBInfo->Part4Port, 0x17, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304107 temp = temp2 | ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004108 xgifb_reg_set(pVBInfo->Part4Port, 0x15, temp);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004109 xgifb_reg_or(pVBInfo->Part4Port, 0x0D, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304110 tempcx = pVBInfo->VBInfo;
4111 tempbx = pVBInfo->VGAHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004112
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304113 if (modeflag & HalfDCLK)
4114 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004115
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304116 if (XGI_IsLCDDualLink(pVBInfo))
4117 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004118
Peter Huewe599801f2012-02-09 21:11:45 +01004119 if (tempcx & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304120 temp = 0;
4121 if (tempbx <= 1024)
4122 temp = 0xA0;
4123 if (tempbx == 1280)
4124 temp = 0xC0;
4125 } else if (tempcx & SetCRT2ToTV) {
4126 temp = 0xA0;
4127 if (tempbx <= 800)
4128 temp = 0x80;
4129 } else {
4130 temp = 0x80;
4131 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4132 temp = 0;
4133 if (tempbx > 800)
4134 temp = 0x60;
4135 }
4136 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004137
Peter Huewe599801f2012-02-09 21:11:45 +01004138 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304139 temp = 0x00;
4140 if (pVBInfo->VGAHDE == 1280)
4141 temp = 0x40;
4142 if (pVBInfo->VGAHDE == 1024)
4143 temp = 0x20;
4144 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004145 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0E, ~0xEF, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004146
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304147 tempebx = pVBInfo->VDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004148
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304149 tempcx = pVBInfo->RVBHRS;
4150 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004151 xgifb_reg_set(pVBInfo->Part4Port, 0x18, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004152
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304153 tempeax = pVBInfo->VGAVDE;
4154 tempcx |= 0x04000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004155
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304156 if (tempeax <= tempebx) {
4157 tempcx = (tempcx & (~0x4000));
4158 tempeax = pVBInfo->VGAVDE;
4159 } else {
4160 tempeax -= tempebx;
4161 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004162
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304163 templong = (tempeax * 256 * 1024) % tempebx;
4164 tempeax = (tempeax * 256 * 1024) / tempebx;
4165 tempebx = tempeax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004166
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304167 if (templong != 0)
4168 tempebx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004169
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304170 temp = (unsigned short) (tempebx & 0x000000FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004171 xgifb_reg_set(pVBInfo->Part4Port, 0x1B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004172
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304173 temp = (unsigned short) ((tempebx & 0x0000FF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004174 xgifb_reg_set(pVBInfo->Part4Port, 0x1A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304175 tempbx = (unsigned short) (tempebx >> 16);
4176 temp = tempbx & 0x00FF;
4177 temp = temp << 4;
4178 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004179 xgifb_reg_set(pVBInfo->Part4Port, 0x19, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004180
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304181 /* 301b */
Peter Huewe6896b942012-02-09 21:11:46 +01004182 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4183 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304184 temp = 0x0028;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004185 xgifb_reg_set(pVBInfo->Part4Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304186 tempax = pVBInfo->VGAHDE;
4187 if (modeflag & HalfDCLK)
4188 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004189
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304190 if (XGI_IsLCDDualLink(pVBInfo))
4191 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004192
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304193 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4194 if (tempax > 800)
4195 tempax -= 800;
Aaro Koskinend3ae5762012-09-11 00:15:27 +03004196 } else if (pVBInfo->VGAHDE > 800) {
4197 if (pVBInfo->VGAHDE == 1024)
4198 tempax = (tempax * 25 / 32) - 1;
4199 else
4200 tempax = (tempax * 20 / 32) - 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304201 }
4202 tempax -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004203
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304204 temp = (tempax & 0xFF00) >> 8;
4205 temp = ((temp & 0x0003) << 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004206 xgifb_reg_set(pVBInfo->Part4Port, 0x1E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304207 temp = (tempax & 0x00FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004208 xgifb_reg_set(pVBInfo->Part4Port, 0x1D, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004209
Peter Huewe599801f2012-02-09 21:11:45 +01004210 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToHiVision)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304211 if (pVBInfo->VGAHDE > 800)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004212 xgifb_reg_or(pVBInfo->Part4Port, 0x1E, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004213
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304214 }
4215 temp = 0x0036;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004216
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304217 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4218 if (!(pVBInfo->TVInfo & (NTSC1024x768
Peter Huewe599801f2012-02-09 21:11:45 +01004219 | TVSetYPbPr525p | TVSetYPbPr750p
4220 | TVSetHiVision))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304221 temp |= 0x0001;
4222 if ((pVBInfo->VBInfo & SetInSlaveMode)
4223 && (!(pVBInfo->TVInfo
4224 & TVSimuMode)))
4225 temp &= (~0x0001);
4226 }
4227 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004228
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004229 xgifb_reg_and_or(pVBInfo->Part4Port, 0x1F, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304230 tempbx = pVBInfo->HT;
4231 if (XGI_IsLCDDualLink(pVBInfo))
4232 tempbx = tempbx >> 1;
4233 tempbx = (tempbx >> 1) - 2;
4234 temp = ((tempbx & 0x0700) >> 8) << 3;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004235 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304236 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004237 xgifb_reg_set(pVBInfo->Part4Port, 0x22, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304238 }
4239 /* end 301b */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004240
Aaro Koskinen8951dad2012-09-11 00:15:30 +03004241 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004242}
4243
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004244static void XGINew_EnableCRT2(struct vb_device_info *pVBInfo)
4245{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004246 xgifb_reg_and_or(pVBInfo->P3c4, 0x1E, 0xFF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004247}
4248
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004249static void XGI_SetGroup5(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304250 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004251{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304252 if (pVBInfo->ModeType == ModeVGA) {
4253 if (!(pVBInfo->VBInfo & (SetInSlaveMode | LoadDACFlag
Peter Huewe6896b942012-02-09 21:11:46 +01004254 | DisableCRT2Display))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304255 XGINew_EnableCRT2(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304256 }
4257 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004258}
4259
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004260static void XGI_DisableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304261 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004262{
4263
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004264 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004265}
4266
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004267static unsigned char XGI_XG21CheckLVDSMode(struct xgifb_video_info *xgifb_info,
4268 unsigned short ModeNo, unsigned short ModeIdIndex,
4269 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004270{
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004271 unsigned short xres, yres, colordepth, modeflag, resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004272
Aaro Koskinenb3979922012-11-04 21:14:52 +02004273 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02004274 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
4275 yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004276 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004277 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004278
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304279 if (!(modeflag & Charx8Dot)) {
4280 xres /= 9;
4281 xres *= 8;
4282 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004283
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004284 if ((ModeNo > 0x13) && (modeflag & HalfDCLK))
4285 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004286
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004287 if ((ModeNo > 0x13) && (modeflag & DoubleScanMode))
4288 yres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004289
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004290 if (xres > xgifb_info->lvds_data.LVDSHDE)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304291 return 0;
Bill Pembertondda08c52010-06-17 13:10:42 -04004292
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004293 if (yres > xgifb_info->lvds_data.LVDSVDE)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304294 return 0;
4295
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004296 if (xres != xgifb_info->lvds_data.LVDSHDE ||
4297 yres != xgifb_info->lvds_data.LVDSVDE) {
4298 colordepth = XGI_GetColorDepth(ModeNo, ModeIdIndex, pVBInfo);
4299 if (colordepth > 2)
4300 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304301 }
4302 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004303}
4304
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004305static void xgifb_set_lvds(struct xgifb_video_info *xgifb_info,
4306 int chip_id,
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004307 unsigned short ModeNo,
4308 unsigned short ModeIdIndex,
4309 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004310{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304311 unsigned char temp, Miscdata;
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004312 unsigned short xres, yres, modeflag, resindex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304313 unsigned short LVDSHT, LVDSHBS, LVDSHRS, LVDSHRE, LVDSHBE;
4314 unsigned short LVDSVT, LVDSVBS, LVDSVRS, LVDSVRE, LVDSVBE;
4315 unsigned short value;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004316
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004317 temp = (unsigned char) ((xgifb_info->lvds_data.LVDS_Capability &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004318 (LCDPolarity << 8)) >> 8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304319 temp &= LCDPolarity;
Peter Huewe9388ad92013-02-15 20:37:10 +01004320 Miscdata = inb(pVBInfo->P3cc);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004321
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004322 outb((Miscdata & 0x3F) | temp, pVBInfo->P3c2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004323
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004324 temp = xgifb_info->lvds_data.LVDS_Capability & LCDPolarity;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004325 /* SR35[7] FP VSync polarity */
4326 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x80, temp & 0x80);
4327 /* SR30[5] FP HSync polarity */
4328 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, ~0x20, (temp & 0x40) >> 1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004329
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004330 if (chip_id == XG27)
4331 XGI_SetXG27FPBits(pVBInfo);
4332 else
4333 XGI_SetXG21FPBits(pVBInfo);
4334
Aaro Koskinenb3979922012-11-04 21:14:52 +02004335 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02004336 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
4337 yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004338 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004339 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004340
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304341 if (!(modeflag & Charx8Dot))
4342 xres = xres * 8 / 9;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004343
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004344 LVDSHT = xgifb_info->lvds_data.LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004345
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004346 LVDSHBS = xres + (xgifb_info->lvds_data.LVDSHDE - xres) / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004347
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304348 if (LVDSHBS > LVDSHT)
4349 LVDSHBS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004350
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004351 LVDSHRS = LVDSHBS + xgifb_info->lvds_data.LVDSHFP;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304352 if (LVDSHRS > LVDSHT)
4353 LVDSHRS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004354
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004355 LVDSHRE = LVDSHRS + xgifb_info->lvds_data.LVDSHSYNC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304356 if (LVDSHRE > LVDSHT)
4357 LVDSHRE -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004358
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004359 LVDSHBE = LVDSHBS + LVDSHT - xgifb_info->lvds_data.LVDSHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004360
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004361 LVDSVT = xgifb_info->lvds_data.LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004362
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004363 LVDSVBS = yres + (xgifb_info->lvds_data.LVDSVDE - yres) / 2;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004364 if (modeflag & DoubleScanMode)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304365 LVDSVBS += yres / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004366
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304367 if (LVDSVBS > LVDSVT)
4368 LVDSVBS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004369
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004370 LVDSVRS = LVDSVBS + xgifb_info->lvds_data.LVDSVFP;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304371 if (LVDSVRS > LVDSVT)
4372 LVDSVRS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004373
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004374 LVDSVRE = LVDSVRS + xgifb_info->lvds_data.LVDSVSYNC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304375 if (LVDSVRE > LVDSVT)
4376 LVDSVRE -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004377
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004378 LVDSVBE = LVDSVBS + LVDSVT - xgifb_info->lvds_data.LVDSVDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004379
Peter Huewe9388ad92013-02-15 20:37:10 +01004380 temp = xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004381 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp & 0x7f); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004382
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304383 if (!(modeflag & Charx8Dot))
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004384 xgifb_reg_or(pVBInfo->P3c4, 0x1, 0x1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004385
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304386 /* HT SR0B[1:0] CR00 */
4387 value = (LVDSHT >> 3) - 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004388 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004389 xgifb_reg_set(pVBInfo->P3d4, 0x0, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004390
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304391 /* HBS SR0B[5:4] CR02 */
4392 value = (LVDSHBS >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004393 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x30, (value & 0x300) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004394 xgifb_reg_set(pVBInfo->P3d4, 0x2, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004395
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304396 /* HBE SR0C[1:0] CR05[7] CR03[4:0] */
4397 value = (LVDSHBE >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004398 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x03, (value & 0xC0) >> 6);
4399 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x80, (value & 0x20) << 2);
4400 xgifb_reg_and_or(pVBInfo->P3d4, 0x03, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004401
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304402 /* HRS SR0B[7:6] CR04 */
4403 value = (LVDSHRS >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004404 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0xC0, (value & 0x300) >> 2);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004405 xgifb_reg_set(pVBInfo->P3d4, 0x4, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004406
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304407 /* Panel HRS SR2F[1:0] SR2E[7:0] */
4408 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004409 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004410 xgifb_reg_set(pVBInfo->P3c4, 0x2E, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004411
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304412 /* HRE SR0C[2] CR05[4:0] */
4413 value = (LVDSHRE >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004414 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x04, (value & 0x20) >> 3);
4415 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004416
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304417 /* Panel HRE SR2F[7:2] */
4418 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004419 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0xFC, value << 2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004420
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304421 /* VT SR0A[0] CR07[5][0] CR06 */
4422 value = LVDSVT - 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004423 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x01, (value & 0x400) >> 10);
4424 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x20, (value & 0x200) >> 4);
4425 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x01, (value & 0x100) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004426 xgifb_reg_set(pVBInfo->P3d4, 0x06, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004427
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304428 /* VBS SR0A[2] CR09[5] CR07[3] CR15 */
4429 value = LVDSVBS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004430 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x04, (value & 0x400) >> 8);
4431 xgifb_reg_and_or(pVBInfo->P3d4, 0x09, ~0x20, (value & 0x200) >> 4);
4432 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x08, (value & 0x100) >> 5);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004433 xgifb_reg_set(pVBInfo->P3d4, 0x15, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004434
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304435 /* VBE SR0A[4] CR16 */
4436 value = LVDSVBE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004437 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x10, (value & 0x100) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004438 xgifb_reg_set(pVBInfo->P3d4, 0x16, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004439
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304440 /* VRS SR0A[3] CR7[7][2] CR10 */
4441 value = LVDSVRS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004442 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x08, (value & 0x400) >> 7);
4443 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x80, (value & 0x200) >> 2);
4444 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x04, (value & 0x100) >> 6);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004445 xgifb_reg_set(pVBInfo->P3d4, 0x10, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004446
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004447 if (chip_id == XG27) {
4448 /* Panel VRS SR35[2:0] SR34[7:0] */
4449 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07,
4450 (value & 0x700) >> 8);
4451 xgifb_reg_set(pVBInfo->P3c4, 0x34, value & 0xFF);
4452 } else {
4453 /* Panel VRS SR3F[1:0] SR34[7:0] SR33[0] */
4454 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0x03,
4455 (value & 0x600) >> 9);
4456 xgifb_reg_set(pVBInfo->P3c4, 0x34, (value >> 1) & 0xFF);
4457 xgifb_reg_and_or(pVBInfo->P3d4, 0x33, ~0x01, value & 0x01);
4458 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004459
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304460 /* VRE SR0A[5] CR11[3:0] */
4461 value = LVDSVRE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004462 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x20, (value & 0x10) << 1);
4463 xgifb_reg_and_or(pVBInfo->P3d4, 0x11, ~0x0F, value & 0x0F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004464
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304465 /* Panel VRE SR3F[7:2] */
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004466 if (chip_id == XG27)
4467 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
4468 (value << 2) & 0xFC);
4469 else
4470 /* SR3F[7] has to be 0, h/w bug */
4471 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
4472 (value << 2) & 0x7C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004473
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304474 for (temp = 0, value = 0; temp < 3; temp++) {
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004475
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004476 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, value);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004477 xgifb_reg_set(pVBInfo->P3c4,
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004478 0x2B, xgifb_info->lvds_data.VCLKData1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004479 xgifb_reg_set(pVBInfo->P3c4,
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004480 0x2C, xgifb_info->lvds_data.VCLKData2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304481 value += 0x10;
4482 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004483
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304484 if (!(modeflag & Charx8Dot)) {
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004485 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004486 outb(0x13, pVBInfo->P3c0); /* set index */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004487 /* set data, panning = 0, shift left 1 dot*/
4488 outb(0x00, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004489
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004490 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004491 outb(0x20, pVBInfo->P3c0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304492
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004493 inb(pVBInfo->P3da); /* reset 3da */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304494 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004495
4496}
4497
4498/* --------------------------------------------------------------------- */
4499/* Function : XGI_IsLCDON */
4500/* Input : */
Bill Pembertondda08c52010-06-17 13:10:42 -04004501/* Output : 0 : Skip PSC Control */
4502/* 1: Disable PSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004503/* Description : */
4504/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004505static unsigned char XGI_IsLCDON(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004506{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304507 unsigned short tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004508
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304509 tempax = pVBInfo->VBInfo;
4510 if (tempax & SetCRT2ToDualEdge)
4511 return 0;
Peter Huewe6896b942012-02-09 21:11:46 +01004512 else if (tempax & (DisableCRT2Display | SwitchCRT2 | SetSimuScanMode))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304513 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004514
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304515 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004516}
4517
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004518static void XGI_DisableBridge(struct xgifb_video_info *xgifb_info,
4519 struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304520 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004521{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02004522 unsigned short tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004523
Peter Huewe6896b942012-02-09 21:11:46 +01004524 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4525 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304526 tempah = 0x3F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004527 if (!(pVBInfo->VBInfo &
4528 (DisableCRT2Display | SetSimuScanMode))) {
Peter Huewea3d675c2012-02-09 21:11:47 +01004529 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Aaro Koskinen41fc5f02013-05-29 23:59:12 +03004530 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304531 tempah = 0x7F; /* Disable Channel A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304532 }
4533 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004534
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004535 /* disable part4_1f */
4536 xgifb_reg_and(pVBInfo->Part4Port, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004537
Peter Huewe6896b942012-02-09 21:11:46 +01004538 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004539 if (((pVBInfo->VBInfo &
Peter Huewe06cc47b2013-02-03 22:54:38 +01004540 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))) ||
Peter Huewe06cc47b2013-02-03 22:54:38 +01004541 (XGI_IsLCDON(pVBInfo)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004542 /* LVDS Driver power down */
4543 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304544 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004545
Aaro Koskinend1724632013-05-29 23:59:09 +03004546 if (pVBInfo->VBInfo & (DisableCRT2Display | XGI_SetCRT2ToLCDA |
4547 SetSimuScanMode))
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004548 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004549
Aaro Koskinen41fc5f02013-05-29 23:59:12 +03004550 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
4551 /* Power down */
4552 xgifb_reg_and(pVBInfo->Part1Port, 0x1e, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004553
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004554 /* disable TV as primary VGA swap */
4555 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004556
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304557 if ((pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToDualEdge)))
Aaro Koskinendc505562011-03-13 12:26:26 +02004558 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004559
Aaro Koskinenc4f9c312013-05-29 23:59:07 +03004560 if ((pVBInfo->VBInfo &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004561 (DisableCRT2Display | SetSimuScanMode)) ||
Peter Huewea3d675c2012-02-09 21:11:47 +01004562 ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) &&
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004563 (pVBInfo->VBInfo &
4564 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004565 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004566
Aaro Koskinenc4f9c312013-05-29 23:59:07 +03004567 if ((pVBInfo->VBInfo &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004568 (DisableCRT2Display | SetSimuScanMode)) ||
Peter Huewea3d675c2012-02-09 21:11:47 +01004569 (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) ||
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004570 (pVBInfo->VBInfo &
4571 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))) {
4572 /* save Part1 index 0 */
4573 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
4574 /* BTDAC = 1, avoid VB reset */
4575 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x10);
4576 /* disable CRT2 */
4577 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
4578 /* restore Part1 index 0 */
4579 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304580 }
4581 } else { /* {301} */
4582 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004583 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
4584 /* Disable CRT2 */
4585 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
4586 /* Disable TV asPrimary VGA swap */
4587 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xDF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304588 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004589
Peter Huewea3d675c2012-02-09 21:11:47 +01004590 if (pVBInfo->VBInfo & (DisableCRT2Display | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304591 | SetSimuScanMode))
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004592 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304593 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004594}
4595
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004596/* --------------------------------------------------------------------- */
4597/* Function : XGI_GetTVPtrIndex */
4598/* Input : */
4599/* Output : */
4600/* Description : bx 0 : ExtNTSC */
4601/* 1 : StNTSC */
4602/* 2 : ExtPAL */
4603/* 3 : StPAL */
4604/* 4 : ExtHiTV */
4605/* 5 : StHiTV */
4606/* 6 : Ext525i */
4607/* 7 : St525i */
4608/* 8 : Ext525p */
4609/* 9 : St525p */
4610/* A : Ext750p */
4611/* B : St750p */
4612/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004613static unsigned short XGI_GetTVPtrIndex(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004614{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304615 unsigned short tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004616
Peter Huewe599801f2012-02-09 21:11:45 +01004617 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304618 tempbx = 2;
Peter Huewe599801f2012-02-09 21:11:45 +01004619 if (pVBInfo->TVInfo & TVSetHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304620 tempbx = 4;
Peter Huewe599801f2012-02-09 21:11:45 +01004621 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304622 tempbx = 6;
Peter Huewe599801f2012-02-09 21:11:45 +01004623 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304624 tempbx = 8;
Peter Huewe599801f2012-02-09 21:11:45 +01004625 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304626 tempbx = 10;
4627 if (pVBInfo->TVInfo & TVSimuMode)
4628 tempbx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004629
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304630 return tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004631}
4632
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004633/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004634/* Function : XGI_GetTVPtrIndex2 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004635/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004636/* Output : bx 0 : NTSC */
4637/* 1 : PAL */
4638/* 2 : PALM */
4639/* 3 : PALN */
4640/* 4 : NTSC1024x768 */
4641/* 5 : PAL-M 1024x768 */
4642/* 6-7: reserved */
4643/* cl 0 : YFilter1 */
4644/* 1 : YFilter2 */
4645/* ch 0 : 301A */
4646/* 1 : 301B/302B/301LV/302LV */
4647/* Description : */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004648/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004649static void XGI_GetTVPtrIndex2(unsigned short *tempbx, unsigned char *tempcl,
4650 unsigned char *tempch, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004651{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004652 *tempbx = 0;
4653 *tempcl = 0;
4654 *tempch = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004655
Peter Huewe599801f2012-02-09 21:11:45 +01004656 if (pVBInfo->TVInfo & TVSetPAL)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004657 *tempbx = 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004658
Peter Huewe599801f2012-02-09 21:11:45 +01004659 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004660 *tempbx = 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004661
Peter Huewe599801f2012-02-09 21:11:45 +01004662 if (pVBInfo->TVInfo & TVSetPALN)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004663 *tempbx = 3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004664
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004665 if (pVBInfo->TVInfo & NTSC1024x768) {
4666 *tempbx = 4;
Peter Huewe599801f2012-02-09 21:11:45 +01004667 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004668 *tempbx = 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304669 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004670
Peter Huewe6896b942012-02-09 21:11:46 +01004671 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4672 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004673 if ((!(pVBInfo->VBInfo & SetInSlaveMode)) || (pVBInfo->TVInfo
4674 & TVSimuMode)) {
4675 *tempbx += 8;
4676 *tempcl += 1;
4677 }
4678 }
4679
Peter Huewe6896b942012-02-09 21:11:46 +01004680 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4681 | VB_SIS302LV | VB_XGI301C))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004682 (*tempch)++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004683}
4684
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004685static void XGI_SetDelayComp(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004686{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304687 unsigned char tempah, tempbl, tempbh;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004688
Peter Huewe6896b942012-02-09 21:11:46 +01004689 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4690 | VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01004691 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304692 | SetCRT2ToTV | SetCRT2ToRAMDAC)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304693 tempbh = 0;
Peter Huewe03f76fc2012-06-14 00:21:50 +02004694 tempbl = XGI301TVDelay;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004695
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304696 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
4697 tempbl = tempbl >> 4;
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004698 if (pVBInfo->VBInfo &
4699 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Peter Huewe03f76fc2012-06-14 00:21:50 +02004700 tempbh = XGI301LCDDelay;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004701
Peter Huewea3d675c2012-02-09 21:11:47 +01004702 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304703 tempbl = tempbh;
4704 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004705
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304706 tempbl &= 0x0F;
4707 tempbh &= 0xF0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02004708 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2D);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004709
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304710 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD
4711 | SetCRT2ToTV)) { /* Channel B */
4712 tempah &= 0xF0;
4713 tempah |= tempbl;
4714 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004715
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004716 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
4717 /* Channel A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304718 tempah &= 0x0F;
4719 tempah |= tempbh;
4720 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02004721 xgifb_reg_set(pVBInfo->Part1Port, 0x2D, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304722 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304723 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004724}
4725
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004726static void XGI_SetLCDCap_A(unsigned short tempcx,
4727 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004728{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304729 unsigned short temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004730
Aaro Koskinen58839b02011-03-13 12:26:23 +02004731 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004732
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304733 if (temp & LCDRGB18Bit) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004734 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004735 /* Enable Dither */
4736 (unsigned short) (0x20 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004737 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304738 } else {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004739 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304740 (unsigned short) (0x30 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004741 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304742 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004743}
4744
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004745/* --------------------------------------------------------------------- */
4746/* Function : XGI_SetLCDCap_B */
4747/* Input : cx -> LCD Capability */
4748/* Output : */
4749/* Description : */
4750/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004751static void XGI_SetLCDCap_B(unsigned short tempcx,
4752 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004753{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304754 if (tempcx & EnableLCD24bpp) /* 24bits */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004755 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304756 (unsigned short) (((tempcx & 0x00ff) >> 6)
4757 | 0x0c));
4758 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004759 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304760 (unsigned short) (((tempcx & 0x00ff) >> 6)
4761 | 0x18)); /* Enable Dither */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004762}
4763
Aaro Koskinen7f04ec32011-11-27 23:03:05 +02004764static void XGI_LongWait(struct vb_device_info *pVBInfo)
4765{
4766 unsigned short i;
4767
4768 i = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
4769
4770 if (!(i & 0xC0)) {
4771 for (i = 0; i < 0xFFFF; i++) {
4772 if (!(inb(pVBInfo->P3da) & 0x08))
4773 break;
4774 }
4775
4776 for (i = 0; i < 0xFFFF; i++) {
4777 if ((inb(pVBInfo->P3da) & 0x08))
4778 break;
4779 }
4780 }
4781}
4782
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004783static void SetSpectrum(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004784{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304785 unsigned short index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004786
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304787 index = XGI_GetLCDCapPtr(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004788
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004789 /* disable down spectrum D[4] */
4790 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x8F);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304791 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004792 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x20); /* reset spectrum */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304793 XGI_LongWait(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004794
Aaro Koskinen8104e322011-03-13 12:26:22 +02004795 xgifb_reg_set(pVBInfo->Part4Port, 0x31,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304796 pVBInfo->LCDCapList[index].Spectrum_31);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004797 xgifb_reg_set(pVBInfo->Part4Port, 0x32,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304798 pVBInfo->LCDCapList[index].Spectrum_32);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004799 xgifb_reg_set(pVBInfo->Part4Port, 0x33,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304800 pVBInfo->LCDCapList[index].Spectrum_33);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004801 xgifb_reg_set(pVBInfo->Part4Port, 0x34,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304802 pVBInfo->LCDCapList[index].Spectrum_34);
4803 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004804 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x40); /* enable spectrum */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004805}
4806
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004807static void XGI_SetLCDCap(struct vb_device_info *pVBInfo)
4808{
4809 unsigned short tempcx;
4810
4811 tempcx = pVBInfo->LCDCapList[XGI_GetLCDCapPtr(pVBInfo)].LCD_Capability;
4812
Peter Huewef951dd02013-02-05 00:29:47 +01004813 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV |
4814 VB_SIS302LV | VB_XGI301C)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004815 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01004816 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004817 /* Set 301LV Capability */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004818 xgifb_reg_set(pVBInfo->Part4Port, 0x24,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004819 (unsigned char) (tempcx & 0x1F));
4820 }
4821 /* VB Driving */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004822 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004823 ~((EnableVBCLKDRVLOW | EnablePLLSPLOW) >> 8),
4824 (unsigned short) ((tempcx & (EnableVBCLKDRVLOW
4825 | EnablePLLSPLOW)) >> 8));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004826
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004827 if (pVBInfo->VBInfo & SetCRT2ToLCD)
4828 XGI_SetLCDCap_B(tempcx, pVBInfo);
Peter Huewea3d675c2012-02-09 21:11:47 +01004829 else if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004830 XGI_SetLCDCap_A(tempcx, pVBInfo);
4831
Peter Huewe6896b942012-02-09 21:11:46 +01004832 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004833 if (tempcx & EnableSpectrum)
4834 SetSpectrum(pVBInfo);
4835 }
4836 } else {
4837 /* LVDS,CH7017 */
4838 XGI_SetLCDCap_A(tempcx, pVBInfo);
4839 }
4840}
4841
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004842/* --------------------------------------------------------------------- */
4843/* Function : XGI_SetAntiFlicker */
4844/* Input : */
4845/* Output : */
4846/* Description : Set TV Customized Param. */
4847/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004848static void XGI_SetAntiFlicker(unsigned short ModeNo,
4849 unsigned short ModeIdIndex,
4850 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004851{
Aaro Koskinen36ae0352012-04-07 01:14:08 +03004852 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004853
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304854 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004855
Peter Huewe599801f2012-02-09 21:11:45 +01004856 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304857 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004858
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304859 tempbx = XGI_GetTVPtrIndex(pVBInfo);
4860 tempbx &= 0xFE;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304861 tempah = TVAntiFlickList[tempbx];
4862 tempah = tempah << 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004863
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004864 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0x8F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004865}
4866
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004867static void XGI_SetEdgeEnhance(unsigned short ModeNo,
4868 unsigned short ModeIdIndex,
4869 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004870{
Aaro Koskinen354f49f2012-04-07 01:14:09 +03004871 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004872
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304873 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004874
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304875 tempbx = XGI_GetTVPtrIndex(pVBInfo);
4876 tempbx &= 0xFE;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304877 tempah = TVEdgeList[tempbx];
4878 tempah = tempah << 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004879
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004880 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004881}
4882
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004883static void XGI_SetPhaseIncr(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004884{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304885 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004886
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304887 unsigned char tempcl, tempch;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004888
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304889 unsigned long tempData;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004890
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304891 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
4892 tempData = TVPhaseList[tempbx];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004893
Aaro Koskinen8104e322011-03-13 12:26:22 +02004894 xgifb_reg_set(pVBInfo->Part2Port, 0x31, (unsigned short) (tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304895 & 0x000000FF));
Aaro Koskinen8104e322011-03-13 12:26:22 +02004896 xgifb_reg_set(pVBInfo->Part2Port, 0x32, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304897 & 0x0000FF00) >> 8));
Aaro Koskinen8104e322011-03-13 12:26:22 +02004898 xgifb_reg_set(pVBInfo->Part2Port, 0x33, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304899 & 0x00FF0000) >> 16));
Aaro Koskinen8104e322011-03-13 12:26:22 +02004900 xgifb_reg_set(pVBInfo->Part2Port, 0x34, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304901 & 0xFF000000) >> 24));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004902}
4903
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004904static void XGI_SetYFilter(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304905 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004906{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304907 unsigned short tempbx, index;
Aaro Koskinena68292f2012-11-04 21:15:07 +02004908 unsigned char const *filterPtr;
4909 unsigned char tempcl, tempch, tempal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004910
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304911 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004912
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304913 switch (tempbx) {
4914 case 0x00:
4915 case 0x04:
4916 filterPtr = NTSCYFilter1;
4917 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004918
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304919 case 0x01:
4920 filterPtr = PALYFilter1;
4921 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004922
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304923 case 0x02:
4924 case 0x05:
4925 case 0x0D:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304926 case 0x03:
Aaro Koskinen2555e942011-08-31 21:46:06 +03004927 filterPtr = xgifb_palmn_yfilter1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304928 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004929
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304930 case 0x08:
4931 case 0x0C:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304932 case 0x0A:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304933 case 0x0B:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304934 case 0x09:
Aaro Koskinen80f86f82011-08-31 21:46:05 +03004935 filterPtr = xgifb_yfilter2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304936 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004937
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304938 default:
4939 return;
4940 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004941
Aaro Koskinenb3979922012-11-04 21:14:52 +02004942 tempal = XGI330_EModeIDTable[ModeIdIndex].VB_ExtTVYFilterIndex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304943 if (tempcl == 0)
4944 index = tempal * 4;
4945 else
4946 index = tempal * 7;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004947
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304948 if ((tempcl == 0) && (tempch == 1)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004949 xgifb_reg_set(pVBInfo->Part2Port, 0x35, 0);
4950 xgifb_reg_set(pVBInfo->Part2Port, 0x36, 0);
4951 xgifb_reg_set(pVBInfo->Part2Port, 0x37, 0);
4952 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304953 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004954 xgifb_reg_set(pVBInfo->Part2Port, 0x35, filterPtr[index++]);
4955 xgifb_reg_set(pVBInfo->Part2Port, 0x36, filterPtr[index++]);
4956 xgifb_reg_set(pVBInfo->Part2Port, 0x37, filterPtr[index++]);
4957 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304958 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004959
Peter Huewe6896b942012-02-09 21:11:46 +01004960 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4961 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004962 xgifb_reg_set(pVBInfo->Part2Port, 0x48, filterPtr[index++]);
4963 xgifb_reg_set(pVBInfo->Part2Port, 0x49, filterPtr[index++]);
4964 xgifb_reg_set(pVBInfo->Part2Port, 0x4A, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304965 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004966}
4967
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004968/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004969/* Function : XGI_OEM310Setting */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004970/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004971/* Output : */
4972/* Description : Customized Param. for 301 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004973/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004974static void XGI_OEM310Setting(unsigned short ModeNo,
4975 unsigned short ModeIdIndex,
4976 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004977{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004978 XGI_SetDelayComp(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004979
Peter Huewea3d675c2012-02-09 21:11:47 +01004980 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004981 XGI_SetLCDCap(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004982
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004983 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004984 XGI_SetPhaseIncr(pVBInfo);
4985 XGI_SetYFilter(ModeNo, ModeIdIndex, pVBInfo);
4986 XGI_SetAntiFlicker(ModeNo, ModeIdIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004987
Peter Huewe6896b942012-02-09 21:11:46 +01004988 if (pVBInfo->VBType & VB_SIS301)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004989 XGI_SetEdgeEnhance(ModeNo, ModeIdIndex, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304990 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004991}
4992
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004993/* --------------------------------------------------------------------- */
4994/* Function : XGI_SetCRT2ModeRegs */
4995/* Input : */
4996/* Output : */
4997/* Description : Origin code for crt2group */
4998/* --------------------------------------------------------------------- */
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02004999static void XGI_SetCRT2ModeRegs(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305000 struct xgi_hw_device_info *HwDeviceExtension,
5001 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005002{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305003 unsigned short tempbl;
5004 short tempcl;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005005
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305006 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005007
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305008 tempah = 0;
5009 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005010 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305011 tempah &= ~0x10; /* BTRAMDAC */
5012 tempah |= 0x40; /* BTRAM */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005013
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305014 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
5015 | SetCRT2ToLCD)) {
5016 tempah = 0x40; /* BTDRAM */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005017 tempcl = pVBInfo->ModeType;
5018 tempcl -= ModeVGA;
5019 if (tempcl >= 0) {
5020 /* BT Color */
5021 tempah = (0x008 >> tempcl);
5022 if (tempah == 0)
5023 tempah = 1;
5024 tempah |= 0x040;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305025 }
5026 if (pVBInfo->VBInfo & SetInSlaveMode)
5027 tempah ^= 0x50; /* BTDAC */
5028 }
5029 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005030
Aaro Koskinen8104e322011-03-13 12:26:22 +02005031 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305032 tempah = 0x08;
5033 tempbl = 0xf0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005034
Miguel Gómeze123e462012-07-06 12:40:52 +02005035 if (pVBInfo->VBInfo & DisableCRT2Display)
5036 goto reg_and_or;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005037
Miguel Gómeze123e462012-07-06 12:40:52 +02005038 tempah = 0x00;
5039 tempbl = 0xff;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005040
Miguel Gómeze123e462012-07-06 12:40:52 +02005041 if (!(pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV |
5042 SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
5043 goto reg_and_or;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005044
Miguel Gómeze123e462012-07-06 12:40:52 +02005045 if ((pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) &&
5046 (!(pVBInfo->VBInfo & SetSimuScanMode))) {
5047 tempbl &= 0xf7;
5048 tempah |= 0x01;
5049 goto reg_and_or;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305050 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005051
Miguel Gómeze123e462012-07-06 12:40:52 +02005052 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
5053 tempbl &= 0xf7;
5054 tempah |= 0x01;
5055 }
5056
5057 if (!(pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD)))
5058 goto reg_and_or;
5059
5060 tempbl &= 0xf8;
5061 tempah = 0x01;
5062
5063 if (!(pVBInfo->VBInfo & SetInSlaveMode))
5064 tempah |= 0x02;
5065
5066 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
5067 tempah = tempah ^ 0x05;
5068 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
5069 tempah = tempah ^ 0x01;
5070 }
5071
5072 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
5073 tempah |= 0x08;
5074
5075reg_and_or:
5076 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl, tempah);
5077
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305078 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD
Peter Huewea3d675c2012-02-09 21:11:47 +01005079 | XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305080 tempah &= (~0x08);
5081 if ((pVBInfo->ModeType == ModeVGA) && (!(pVBInfo->VBInfo
5082 & SetInSlaveMode))) {
5083 tempah |= 0x010;
5084 }
5085 tempah |= 0x080;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005086
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305087 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305088 tempah |= 0x020;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005089 if (pVBInfo->VBInfo & DriverMode)
5090 tempah = tempah ^ 0x20;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305091 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005092
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005093 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D, ~0x0BF, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305094 tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005095
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305096 if (pVBInfo->LCDInfo & SetLCDDualLink)
5097 tempah |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005098
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305099 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305100 if (pVBInfo->TVInfo & RPLLDIV2XO)
5101 tempah |= 0x40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305102 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005103
Peter Huewe255aabd2012-02-09 21:11:44 +01005104 if ((pVBInfo->LCDResInfo == Panel_1280x1024)
5105 || (pVBInfo->LCDResInfo == Panel_1280x1024x75))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305106 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005107
Peter Huewe255aabd2012-02-09 21:11:44 +01005108 if (pVBInfo->LCDResInfo == Panel_1280x960)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305109 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005110
Aaro Koskinen8104e322011-03-13 12:26:22 +02005111 xgifb_reg_set(pVBInfo->Part4Port, 0x0C, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305112 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005113
Peter Huewe6896b942012-02-09 21:11:46 +01005114 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5115 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305116 tempah = 0;
5117 tempbl = 0xfb;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005118
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305119 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
5120 tempbl = 0xff;
Peter Huewea3d675c2012-02-09 21:11:47 +01005121 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305122 tempah |= 0x04; /* shampoo 0129 */
5123 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005124
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005125 xgifb_reg_and_or(pVBInfo->Part1Port, 0x13, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305126 tempah = 0x00;
5127 tempbl = 0xcf;
5128 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5129 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5130 tempah |= 0x30;
5131 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005132
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005133 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2c, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305134 tempah = 0;
5135 tempbl = 0x3f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005136
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305137 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5138 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5139 tempah |= 0xc0;
5140 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005141 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305142 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005143
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305144 tempah = 0;
5145 tempbl = 0x7f;
Peter Huewea3d675c2012-02-09 21:11:47 +01005146 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305147 tempbl = 0xff;
5148 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
5149 tempah |= 0x80;
5150 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005151
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005152 xgifb_reg_and_or(pVBInfo->Part4Port, 0x23, tempbl, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005153
Peter Huewe6896b942012-02-09 21:11:46 +01005154 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305155 if (pVBInfo->LCDInfo & SetLCDDualLink) {
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005156 xgifb_reg_or(pVBInfo->Part4Port, 0x27, 0x20);
5157 xgifb_reg_or(pVBInfo->Part4Port, 0x34, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305158 }
5159 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005160}
5161
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005162
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305163void XGI_UnLockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
5164 struct vb_device_info *pVBInfo)
5165{
5166
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005167 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2f, 0xFF, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005168
5169}
5170
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305171void XGI_LockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
5172 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005173{
5174
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005175 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2F, 0xFE, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005176
5177}
5178
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005179unsigned short XGI_GetRatePtrCRT2(struct xgi_hw_device_info *pXGIHWDE,
5180 unsigned short ModeNo, unsigned short ModeIdIndex,
5181 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005182{
Peter Huewef2c22602013-02-03 22:54:30 +01005183 const u8 LCDARefreshIndex[] = {
5184 0x00, 0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x00 };
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005185
Peter Hueweef9a6b92013-02-03 04:08:43 +01005186 unsigned short RefreshRateTableIndex, i, index, temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005187
Aaro Koskinen58839b02011-03-13 12:26:23 +02005188 index = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005189 index = index >> pVBInfo->SelectCRT2Rate;
5190 index &= 0x0F;
5191
5192 if (pVBInfo->LCDInfo & LCDNonExpanding)
5193 index = 0;
5194
5195 if (index > 0)
5196 index--;
5197
5198 if (pVBInfo->SetFlag & ProgrammingCRT2) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005199 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinenb0b4a8a2013-05-29 23:59:04 +03005200 temp = LCDARefreshIndex[pVBInfo->LCDResInfo & 0x07];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005201
Aaro Koskinenb0b4a8a2013-05-29 23:59:04 +03005202 if (index > temp)
5203 index = temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005204 }
5205 }
5206
Aaro Koskinenb3979922012-11-04 21:14:52 +02005207 RefreshRateTableIndex = XGI330_EModeIDTable[ModeIdIndex].REFindex;
Aaro Koskinena39325d2012-11-04 21:14:53 +02005208 ModeNo = XGI330_RefIndex[RefreshRateTableIndex].ModeID;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005209 if (pXGIHWDE->jChipType >= XG20) { /* for XG20, XG21, XG27 */
Aaro Koskinena39325d2012-11-04 21:14:53 +02005210 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 800) &&
5211 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 600)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005212 index++;
5213 }
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005214 /* do the similar adjustment like XGISearchCRT1Rate() */
Aaro Koskinena39325d2012-11-04 21:14:53 +02005215 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 1024) &&
5216 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 768)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005217 index++;
5218 }
Aaro Koskinena39325d2012-11-04 21:14:53 +02005219 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 1280) &&
5220 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 1024)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005221 index++;
5222 }
5223 }
5224
5225 i = 0;
5226 do {
Aaro Koskinena39325d2012-11-04 21:14:53 +02005227 if (XGI330_RefIndex[RefreshRateTableIndex + i].
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005228 ModeID != ModeNo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005229 break;
Aaro Koskinena39325d2012-11-04 21:14:53 +02005230 temp = XGI330_RefIndex[RefreshRateTableIndex + i].Ext_InfoFlag;
Peter Huewe6896b942012-02-09 21:11:46 +01005231 temp &= ModeTypeMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005232 if (temp < pVBInfo->ModeType)
5233 break;
5234 i++;
5235 index--;
5236
5237 } while (index != 0xFFFF);
5238 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
5239 if (pVBInfo->VBInfo & SetInSlaveMode) {
Aaro Koskinena39325d2012-11-04 21:14:53 +02005240 temp = XGI330_RefIndex[RefreshRateTableIndex + i - 1].
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005241 Ext_InfoFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005242 if (temp & InterlaceMode)
5243 i++;
5244 }
5245 }
5246 i--;
5247 if ((pVBInfo->SetFlag & ProgrammingCRT2)) {
5248 temp = XGI_AjustCRT2Rate(ModeNo, ModeIdIndex,
5249 RefreshRateTableIndex, &i, pVBInfo);
5250 }
Aaro Koskinen9a0b2952011-11-27 23:03:16 +02005251 return RefreshRateTableIndex + i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005252}
5253
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005254static void XGI_SetLCDAGroup(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305255 struct xgi_hw_device_info *HwDeviceExtension,
5256 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005257{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005258 unsigned short RefreshRateTableIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005259
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005260 pVBInfo->SetFlag |= ProgrammingCRT2;
5261 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5262 ModeIdIndex, pVBInfo);
5263 XGI_GetLVDSResInfo(ModeNo, ModeIdIndex, pVBInfo);
5264 XGI_GetLVDSData(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5265 XGI_ModCRT1Regs(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5266 HwDeviceExtension, pVBInfo);
5267 XGI_SetLVDSRegs(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5268 XGI_SetCRT2ECLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005269}
5270
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02005271static unsigned char XGI_SetCRT2Group301(unsigned short ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005272 struct xgi_hw_device_info *HwDeviceExtension,
5273 struct vb_device_info *pVBInfo)
5274{
Peter Huewea9e29e62013-02-03 04:08:44 +01005275 unsigned short ModeIdIndex, RefreshRateTableIndex;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005276
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005277 pVBInfo->SetFlag |= ProgrammingCRT2;
5278 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
5279 pVBInfo->SelectCRT2Rate = 4;
5280 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5281 ModeIdIndex, pVBInfo);
5282 XGI_SaveCRT2Info(ModeNo, pVBInfo);
5283 XGI_GetCRT2ResInfo(ModeNo, ModeIdIndex, pVBInfo);
5284 XGI_GetCRT2Data(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5285 XGI_PreSetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
5286 RefreshRateTableIndex, pVBInfo);
5287 XGI_SetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
5288 RefreshRateTableIndex, pVBInfo);
5289 XGI_SetLockRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
5290 RefreshRateTableIndex, pVBInfo);
5291 XGI_SetGroup2(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5292 HwDeviceExtension, pVBInfo);
5293 XGI_SetLCDRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
5294 RefreshRateTableIndex, pVBInfo);
5295 XGI_SetTap4Regs(pVBInfo);
5296 XGI_SetGroup3(ModeNo, ModeIdIndex, pVBInfo);
5297 XGI_SetGroup4(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5298 HwDeviceExtension, pVBInfo);
5299 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5300 XGI_SetGroup5(ModeNo, ModeIdIndex, pVBInfo);
5301 XGI_AutoThreshold(pVBInfo);
5302 return 1;
5303}
5304
5305void XGI_SenseCRT1(struct vb_device_info *pVBInfo)
5306{
5307 unsigned char CRTCData[17] = { 0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81,
5308 0x0B, 0x3E, 0xE9, 0x0B, 0xDF, 0xE7, 0x04, 0x00, 0x00,
5309 0x05, 0x00 };
5310
5311 unsigned char SR01 = 0, SR1F = 0, SR07 = 0, SR06 = 0;
5312
5313 unsigned char CR17, CR63, SR31;
5314 unsigned short temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005315
5316 int i;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005317 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005318
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005319 /* to fix XG42 single LCD sense to CRT+LCD */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005320 xgifb_reg_set(pVBInfo->P3d4, 0x57, 0x4A);
Peter Huewe9388ad92013-02-15 20:37:10 +01005321 xgifb_reg_set(pVBInfo->P3d4, 0x53, (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005322 pVBInfo->P3d4, 0x53) | 0x02));
5323
Peter Huewe9388ad92013-02-15 20:37:10 +01005324 SR31 = xgifb_reg_get(pVBInfo->P3c4, 0x31);
5325 CR63 = xgifb_reg_get(pVBInfo->P3d4, 0x63);
5326 SR01 = xgifb_reg_get(pVBInfo->P3c4, 0x01);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005327
Aaro Koskinen8104e322011-03-13 12:26:22 +02005328 xgifb_reg_set(pVBInfo->P3c4, 0x01, (unsigned char) (SR01 & 0xDF));
5329 xgifb_reg_set(pVBInfo->P3d4, 0x63, (unsigned char) (CR63 & 0xBF));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005330
Peter Huewe9388ad92013-02-15 20:37:10 +01005331 CR17 = xgifb_reg_get(pVBInfo->P3d4, 0x17);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005332 xgifb_reg_set(pVBInfo->P3d4, 0x17, (unsigned char) (CR17 | 0x80));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005333
Peter Huewe9388ad92013-02-15 20:37:10 +01005334 SR1F = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005335 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) (SR1F | 0x04));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005336
Peter Huewe9388ad92013-02-15 20:37:10 +01005337 SR07 = xgifb_reg_get(pVBInfo->P3c4, 0x07);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005338 xgifb_reg_set(pVBInfo->P3c4, 0x07, (unsigned char) (SR07 & 0xFB));
Peter Huewe9388ad92013-02-15 20:37:10 +01005339 SR06 = xgifb_reg_get(pVBInfo->P3c4, 0x06);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005340 xgifb_reg_set(pVBInfo->P3c4, 0x06, (unsigned char) (SR06 & 0xC3));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005341
Aaro Koskinen8104e322011-03-13 12:26:22 +02005342 xgifb_reg_set(pVBInfo->P3d4, 0x11, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005343
5344 for (i = 0; i < 8; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005345 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) i, CRTCData[i]);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005346
5347 for (i = 8; i < 11; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005348 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 8),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005349 CRTCData[i]);
5350
5351 for (i = 11; i < 13; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005352 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 4),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005353 CRTCData[i]);
5354
5355 for (i = 13; i < 16; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005356 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i - 3),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005357 CRTCData[i]);
5358
Aaro Koskinen8104e322011-03-13 12:26:22 +02005359 xgifb_reg_set(pVBInfo->P3c4, 0x0E, (unsigned char) (CRTCData[16]
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005360 & 0xE0));
5361
Aaro Koskinen8104e322011-03-13 12:26:22 +02005362 xgifb_reg_set(pVBInfo->P3c4, 0x31, 0x00);
5363 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x1B);
5364 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE1);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005365
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005366 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005367
Peter Huewe771f3ee2013-02-15 20:37:13 +01005368 for (i = 0; i < 256 * 3; i++) {
5369 outb(0x0F, (pVBInfo->P3c8 + 1)); /* DAC_TEST_PARMS */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005370 }
5371
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005372 mdelay(1);
5373
5374 XGI_WaitDisply(pVBInfo);
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02005375 temp = inb(pVBInfo->P3c2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005376
5377 if (temp & 0x10)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005378 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005379 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005380 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005381
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005382 /* avoid display something, set BLACK DAC if not restore DAC */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005383 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005384
Peter Huewe771f3ee2013-02-15 20:37:13 +01005385 for (i = 0; i < 256 * 3; i++) {
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005386 outb(0, (pVBInfo->P3c8 + 1));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005387 }
5388
Aaro Koskinen8104e322011-03-13 12:26:22 +02005389 xgifb_reg_set(pVBInfo->P3c4, 0x01, SR01);
5390 xgifb_reg_set(pVBInfo->P3d4, 0x63, CR63);
5391 xgifb_reg_set(pVBInfo->P3c4, 0x31, SR31);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005392
Peter Huewe9388ad92013-02-15 20:37:10 +01005393 xgifb_reg_set(pVBInfo->P3d4, 0x53, (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005394 pVBInfo->P3d4, 0x53) & 0xFD));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005395 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) SR1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005396}
5397
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005398static void XGI_EnableBridge(struct xgifb_video_info *xgifb_info,
5399 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005400 struct vb_device_info *pVBInfo)
5401{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02005402 unsigned short tempah;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005403
Peter Huewe6896b942012-02-09 21:11:46 +01005404 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5405 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinena2526d12013-05-29 23:59:10 +03005406 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
Aaro Koskinend1724632013-05-29 23:59:09 +03005407 /* Power on */
5408 xgifb_reg_set(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005409
Aaro Koskinenb8e34b32013-05-29 23:59:08 +03005410 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV |
5411 SetCRT2ToRAMDAC)) {
Aaro Koskinenc4f9c312013-05-29 23:59:07 +03005412 tempah = xgifb_reg_get(pVBInfo->P3c4, 0x32);
5413 tempah &= 0xDF;
5414 if (pVBInfo->VBInfo & SetInSlaveMode) {
5415 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC))
5416 tempah |= 0x20;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005417 }
Aaro Koskinenc4f9c312013-05-29 23:59:07 +03005418 xgifb_reg_set(pVBInfo->P3c4, 0x32, tempah);
5419 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x20);
5420
5421 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2E);
5422
5423 if (!(tempah & 0x80))
5424 xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80);
5425 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005426 }
5427
Aaro Koskinena2526d12013-05-29 23:59:10 +03005428 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005429 xgifb_reg_and_or(pVBInfo->Part2Port, 0x00, ~0xE0,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005430 0x20); /* shampoo 0129 */
Peter Huewe6896b942012-02-09 21:11:46 +01005431 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinen056b5402013-05-29 23:59:11 +03005432 if (pVBInfo->VBInfo &
5433 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
5434 /* LVDS PLL power on */
5435 xgifb_reg_and(pVBInfo->Part4Port, 0x2A,
5436 0x7F);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005437 /* LVDS Driver power on */
5438 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005439 }
5440 }
5441
5442 tempah = 0x00;
5443
5444 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5445 tempah = 0xc0;
5446
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005447 if (!(pVBInfo->VBInfo & SetSimuScanMode) &&
5448 (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) &&
5449 (pVBInfo->VBInfo & SetCRT2ToDualEdge)) {
5450 tempah = tempah & 0x40;
5451 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
5452 tempah = tempah ^ 0xC0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005453 }
5454 }
5455
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005456 /* EnablePart4_1F */
5457 xgifb_reg_or(pVBInfo->Part4Port, 0x1F, tempah);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005458
Aaro Koskinend1724632013-05-29 23:59:09 +03005459 XGI_DisableGatingCRT(HwDeviceExtension, pVBInfo);
5460 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005461 } /* 301 */
5462 else { /* LVDS */
5463 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD
Peter Huewea3d675c2012-02-09 21:11:47 +01005464 | XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005465 /* enable CRT2 */
5466 xgifb_reg_or(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005467
Peter Huewe9388ad92013-02-15 20:37:10 +01005468 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2E);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005469 if (!(tempah & 0x80))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005470 xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005471
Aaro Koskinendc505562011-03-13 12:26:26 +02005472 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005473 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005474 } /* End of VB */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005475}
5476
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005477static void XGI_SetCRT1Group(struct xgifb_video_info *xgifb_info,
5478 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005479 unsigned short ModeNo, unsigned short ModeIdIndex,
5480 struct vb_device_info *pVBInfo)
5481{
Aaro Koskinena1579612012-04-07 01:14:05 +03005482 unsigned short RefreshRateTableIndex, temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005483
Aaro Koskinena1579612012-04-07 01:14:05 +03005484 XGI_SetSeqRegs(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinen3625c9a2012-11-04 21:14:51 +02005485 outb(XGI330_StandTable.MISC, pVBInfo->P3c2);
Aaro Koskinena1579612012-04-07 01:14:05 +03005486 XGI_SetCRTCRegs(HwDeviceExtension, pVBInfo);
5487 XGI_SetATTRegs(ModeNo, ModeIdIndex, pVBInfo);
5488 XGI_SetGRCRegs(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005489 XGI_ClearExt1Regs(pVBInfo);
5490
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005491 if (HwDeviceExtension->jChipType == XG27) {
5492 if (pVBInfo->IF_DEF_LVDS == 0)
5493 XGI_SetDefaultVCLK(pVBInfo);
5494 }
5495
5496 temp = ~ProgrammingCRT2;
5497 pVBInfo->SetFlag &= temp;
5498 pVBInfo->SelectCRT2Rate = 0;
5499
Peter Huewe6896b942012-02-09 21:11:46 +01005500 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5501 | VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005502 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005503 | SetInSlaveMode)) {
5504 pVBInfo->SetFlag |= ProgrammingCRT2;
5505 }
5506 }
5507
5508 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5509 ModeIdIndex, pVBInfo);
5510 if (RefreshRateTableIndex != 0xFFFF) {
5511 XGI_SetSync(RefreshRateTableIndex, pVBInfo);
5512 XGI_SetCRT1CRTC(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5513 pVBInfo, HwDeviceExtension);
5514 XGI_SetCRT1DE(HwDeviceExtension, ModeNo, ModeIdIndex,
5515 RefreshRateTableIndex, pVBInfo);
5516 XGI_SetCRT1Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5517 HwDeviceExtension, pVBInfo);
5518 XGI_SetCRT1VCLK(ModeNo, ModeIdIndex, HwDeviceExtension,
5519 RefreshRateTableIndex, pVBInfo);
5520 }
5521
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005522 if (HwDeviceExtension->jChipType >= XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005523 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005524 if (temp & 0xA0) {
5525
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005526 if (HwDeviceExtension->jChipType == XG27)
5527 XGI_SetXG27CRTC(ModeNo, ModeIdIndex,
5528 RefreshRateTableIndex, pVBInfo);
5529 else
5530 XGI_SetXG21CRTC(ModeNo, ModeIdIndex,
5531 RefreshRateTableIndex, pVBInfo);
5532
5533 XGI_UpdateXG21CRTC(ModeNo, pVBInfo,
5534 RefreshRateTableIndex);
5535
Aaro Koskinen105d8d02011-08-31 21:46:00 +03005536 xgifb_set_lcd(HwDeviceExtension->jChipType,
5537 pVBInfo, RefreshRateTableIndex, ModeNo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005538
Aaro Koskinen64db29f2011-08-31 21:46:01 +03005539 if (pVBInfo->IF_DEF_LVDS == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005540 xgifb_set_lvds(xgifb_info,
5541 HwDeviceExtension->jChipType,
Aaro Koskinen64db29f2011-08-31 21:46:01 +03005542 ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005543 }
5544 }
5545
5546 pVBInfo->SetFlag &= (~ProgrammingCRT2);
5547 XGI_SetCRT1FIFO(ModeNo, HwDeviceExtension, pVBInfo);
5548 XGI_SetCRT1ModeRegs(HwDeviceExtension, ModeNo, ModeIdIndex,
5549 RefreshRateTableIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005550 XGI_LoadDAC(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005551}
5552
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005553unsigned char XGISetModeNew(struct xgifb_video_info *xgifb_info,
5554 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005555 unsigned short ModeNo)
5556{
5557 unsigned short ModeIdIndex;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005558 struct vb_device_info VBINF;
5559 struct vb_device_info *pVBInfo = &VBINF;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005560 pVBInfo->IF_DEF_LVDS = 0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005561
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005562 if (HwDeviceExtension->jChipType >= XG20) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005563 pVBInfo->IF_DEF_HiVision = 0;
5564 pVBInfo->IF_DEF_CRT2Monitor = 0;
5565 pVBInfo->VBType = 0; /*set VBType default 0*/
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005566 } else {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005567 pVBInfo->IF_DEF_HiVision = 1;
Aaro Koskinen06587332011-03-13 12:26:10 +02005568 pVBInfo->IF_DEF_CRT2Monitor = 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005569 }
5570
Aaro Koskinen56810a92013-01-21 02:57:47 +02005571 XGIRegInit(pVBInfo, xgifb_info->vga_base);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005572
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005573 /* for x86 Linux, XG21 LVDS */
5574 if (HwDeviceExtension->jChipType == XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005575 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005576 pVBInfo->IF_DEF_LVDS = 1;
5577 }
5578 if (HwDeviceExtension->jChipType == XG27) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005579 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0) {
5580 if (xgifb_reg_get(pVBInfo->P3d4, 0x30) & 0x20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005581 pVBInfo->IF_DEF_LVDS = 1;
5582 }
5583 }
5584
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005585 InitTo330Pointer(HwDeviceExtension->jChipType, pVBInfo);
Aaro Koskinenef497f42011-11-27 23:03:21 +02005586 if (ModeNo & 0x80)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005587 ModeNo = ModeNo & 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005588 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005589
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005590 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005591 XGI_UnLockCRT2(HwDeviceExtension, pVBInfo);
5592
5593 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
5594
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005595 if (HwDeviceExtension->jChipType < XG20) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005596 XGI_GetVBInfo(ModeNo, ModeIdIndex, HwDeviceExtension, pVBInfo);
5597 XGI_GetTVInfo(ModeNo, ModeIdIndex, pVBInfo);
5598 XGI_GetLCDInfo(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005599 XGI_DisableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005600
Peter Huewee44adfd2013-02-03 22:54:39 +01005601 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA) ||
5602 (!(pVBInfo->VBInfo & SwitchCRT2))) {
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005603 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005604 ModeIdIndex, pVBInfo);
5605
Peter Huewea3d675c2012-02-09 21:11:47 +01005606 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005607 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
5608 HwDeviceExtension, pVBInfo);
5609 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005610 }
5611
Peter Huewe6896b942012-02-09 21:11:46 +01005612 if (pVBInfo->VBInfo & (SetSimuScanMode | SwitchCRT2)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005613 switch (HwDeviceExtension->ujVBChipID) {
Peter Huewee44adfd2013-02-03 22:54:39 +01005614 case VB_CHIP_301: /* fall through */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005615 case VB_CHIP_302:
5616 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
5617 pVBInfo); /*add for CRT2 */
5618 break;
5619
5620 default:
5621 break;
5622 }
5623 }
5624
5625 XGI_SetCRT2ModeRegs(ModeNo, HwDeviceExtension, pVBInfo);
5626 XGI_OEM310Setting(ModeNo, ModeIdIndex, pVBInfo); /*0212*/
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005627 XGI_EnableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005628 } /* !XG20 */
5629 else {
5630 if (pVBInfo->IF_DEF_LVDS == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005631 if (!XGI_XG21CheckLVDSMode(xgifb_info, ModeNo,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005632 ModeIdIndex,
5633 pVBInfo))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005634 return 0;
5635
Aaro Koskinenb3979922012-11-04 21:14:52 +02005636 pVBInfo->ModeType = XGI330_EModeIDTable[ModeIdIndex].
Peter Huewe6896b942012-02-09 21:11:46 +01005637 Ext_ModeFlag & ModeTypeMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005638
5639 pVBInfo->SetFlag = 0;
Aaro Koskinen83f76a92011-08-31 21:45:58 +03005640 pVBInfo->VBInfo = DisableCRT2Display;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005641
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005642 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005643
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005644 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
5645 ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005646
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005647 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005648 }
5649
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005650 XGI_UpdateModeInfo(HwDeviceExtension, pVBInfo);
5651
Miguel Gómez3bcc2462012-07-06 12:40:53 +02005652 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005653 XGI_LockCRT2(HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005654
5655 return 1;
5656}