blob: 3adec3f184621153fa0cae6fce7ea08a7f087175 [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
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053038 /* 310 customization related */
Peter Huewe6896b942012-02-09 21:11:46 +010039 if ((pVBInfo->VBType & VB_SIS301LV) || (pVBInfo->VBType & VB_SIS302LV))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053040 pVBInfo->LCDCapList = XGI_LCDDLCapList;
41 else
42 pVBInfo->LCDCapList = XGI_LCDCapList;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020043
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053044 if (ChipType >= XG20)
Peter Huewe6d12dae2012-06-14 00:21:52 +020045 pVBInfo->XGINew_CR97 = 0x10;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020046
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053047 if (ChipType == XG27) {
Dmitry Eremin-Solenikov64903112012-03-19 21:50:09 +040048 unsigned char temp;
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +030049 pVBInfo->MCLKData = XGI27New_MCLKData;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053050 pVBInfo->CR40 = XGI27_cr41;
Peter Huewe6d12dae2012-06-14 00:21:52 +020051 pVBInfo->XGINew_CR97 = 0xc1;
Aaro Koskinen597d96b2013-03-27 23:53:15 +020052 pVBInfo->SR18 = XG27_SR18;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020053
Dmitry Eremin-Solenikov64903112012-03-19 21:50:09 +040054 /*Z11m DDR*/
55 temp = xgifb_reg_get(pVBInfo->P3c4, 0x3B);
56 /* SR3B[7][3]MAA15 MAA11 (Power on Trapping) */
57 if (((temp & 0x88) == 0x80) || ((temp & 0x88) == 0x08))
Peter Huewe6d12dae2012-06-14 00:21:52 +020058 pVBInfo->XGINew_CR97 = 0x80;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053059 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020060
61}
62
Kenji Toyama1d7f6562011-04-23 19:36:49 +080063static void XGI_SetSeqRegs(unsigned short ModeNo,
Kenji Toyama1d7f6562011-04-23 19:36:49 +080064 unsigned short ModeIdIndex,
65 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020066{
Peter Huewe76a58992013-02-03 22:54:34 +010067 unsigned char SRdata, i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020068
Aaro Koskinen8104e322011-03-13 12:26:22 +020069 xgifb_reg_set(pVBInfo->P3c4, 0x00, 0x03); /* Set SR0 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020070
Peter Huewe76a58992013-02-03 22:54:34 +010071 for (i = 0; i < 4; i++) {
72 /* Get SR1,2,3,4 from file */
73 /* SR1 is with screen off 0x20 */
74 SRdata = XGI330_StandTable.SR[i];
75 xgifb_reg_set(pVBInfo->P3c4, i+1, SRdata); /* Set SR 1 2 3 4 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053076 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020077}
78
Aaro Koskinen063b9c42011-03-08 22:16:13 +020079static void XGI_SetCRTCRegs(struct xgi_hw_device_info *HwDeviceExtension,
Kenji Toyama1d7f6562011-04-23 19:36:49 +080080 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020081{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053082 unsigned char CRTCdata;
83 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020084
Peter Huewe9388ad92013-02-15 20:37:10 +010085 CRTCdata = xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053086 CRTCdata &= 0x7f;
Aaro Koskinen8104e322011-03-13 12:26:22 +020087 xgifb_reg_set(pVBInfo->P3d4, 0x11, CRTCdata); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020088
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053089 for (i = 0; i <= 0x18; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +080090 /* Get CRTC from file */
Aaro Koskinen3625c9a2012-11-04 21:14:51 +020091 CRTCdata = XGI330_StandTable.CRTC[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +020092 xgifb_reg_set(pVBInfo->P3d4, i, CRTCdata); /* Set CRTC(3d4) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053093 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020094}
95
Kenji Toyama1d7f6562011-04-23 19:36:49 +080096static void XGI_SetATTRegs(unsigned short ModeNo,
Kenji Toyama1d7f6562011-04-23 19:36:49 +080097 unsigned short ModeIdIndex,
98 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020099{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530100 unsigned char ARdata;
101 unsigned short i, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200102
Aaro Koskinenb3979922012-11-04 21:14:52 +0200103 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200104
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530105 for (i = 0; i <= 0x13; i++) {
Aaro Koskinen3625c9a2012-11-04 21:14:51 +0200106 ARdata = XGI330_StandTable.ATTR[i];
Miguel Gómez661a6382012-07-06 12:40:45 +0200107
108 if ((modeflag & Charx8Dot) && i == 0x13) { /* ifndef Dot9 */
109 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
110 ARdata = 0;
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300111 } else if ((pVBInfo->VBInfo &
Miguel Gómez661a6382012-07-06 12:40:45 +0200112 (SetCRT2ToTV | SetCRT2ToLCD)) &&
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300113 (pVBInfo->VBInfo & SetInSlaveMode)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530114 ARdata = 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530115 }
116 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200117
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200118 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200119 outb(i, pVBInfo->P3c0); /* set index */
120 outb(ARdata, pVBInfo->P3c0); /* set data */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530121 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200122
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200123 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200124 outb(0x14, pVBInfo->P3c0); /* set index */
125 outb(0x00, pVBInfo->P3c0); /* set data */
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200126 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200127 outb(0x20, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200128}
129
Aaro Koskinena1579612012-04-07 01:14:05 +0300130static void XGI_SetGRCRegs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200131{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530132 unsigned char GRdata;
133 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200134
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530135 for (i = 0; i <= 0x08; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800136 /* Get GR from file */
Aaro Koskinen3625c9a2012-11-04 21:14:51 +0200137 GRdata = XGI330_StandTable.GRC[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200138 xgifb_reg_set(pVBInfo->P3ce, i, GRdata); /* Set GR(3ce) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530139 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200140
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530141 if (pVBInfo->ModeType > ModeVGA) {
Peter Huewe9388ad92013-02-15 20:37:10 +0100142 GRdata = xgifb_reg_get(pVBInfo->P3ce, 0x05);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530143 GRdata &= 0xBF; /* 256 color disable */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200144 xgifb_reg_set(pVBInfo->P3ce, 0x05, GRdata);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530145 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200146}
147
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200148static void XGI_ClearExt1Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200149{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530150 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200151
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530152 for (i = 0x0A; i <= 0x0E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +0200153 xgifb_reg_set(pVBInfo->P3c4, i, 0x00); /* Clear SR0A-SR0E */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200154}
155
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200156static unsigned char XGI_SetDefaultVCLK(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200157{
158
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200159 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x20);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200160 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[0].SR2B);
161 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[0].SR2C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200162
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200163 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x10);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200164 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[1].SR2B);
165 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[1].SR2C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200166
Aaro Koskinendc505562011-03-13 12:26:26 +0200167 xgifb_reg_and(pVBInfo->P3c4, 0x31, ~0x30);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530168 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200169}
170
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200171static unsigned char XGI_AjustCRT2Rate(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530172 unsigned short ModeIdIndex,
173 unsigned short RefreshRateTableIndex, unsigned short *i,
174 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200175{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530176 unsigned short tempax, tempbx, resinfo, modeflag, infoflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200177
Aaro Koskinenb3979922012-11-04 21:14:52 +0200178 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
179 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinena39325d2012-11-04 21:14:53 +0200180 tempbx = XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530181 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200182
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530183 if (pVBInfo->IF_DEF_LVDS == 0) {
184 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
185 tempax |= SupportRAMDAC2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200186
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530187 if (pVBInfo->VBType & VB_XGI301C)
188 tempax |= SupportCRT2in301C;
189 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200190
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800191 /* 301b */
Peter Huewea3d675c2012-02-09 21:11:47 +0100192 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530193 tempax |= SupportLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200194
Miguel Gómez3b175622012-07-06 12:40:46 +0200195 if (pVBInfo->LCDResInfo != Panel_1280x1024 &&
196 pVBInfo->LCDResInfo != Panel_1280x960 &&
197 (pVBInfo->LCDInfo & LCDNonExpanding) &&
198 resinfo >= 9)
199 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530200 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200201
Peter Huewe599801f2012-02-09 21:11:45 +0100202 if (pVBInfo->VBInfo & SetCRT2ToHiVision) { /* for HiTV */
Aaro Koskinen31fb40f2012-09-11 00:15:15 +0300203 tempax |= SupportHiVision;
204 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
205 ((resinfo == 4) ||
206 (resinfo == 3 &&
207 (pVBInfo->SetFlag & TVSimuMode)) ||
208 (resinfo > 7)))
Miguel Gómez3b175622012-07-06 12:40:46 +0200209 return 0;
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300210 } else if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO |
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800211 SetCRT2ToSVIDEO |
212 SetCRT2ToSCART |
Peter Huewe599801f2012-02-09 21:11:45 +0100213 SetCRT2ToYPbPr525750 |
214 SetCRT2ToHiVision)) {
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300215 tempax |= SupportTV;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200216
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300217 if (pVBInfo->VBType & (VB_SIS301B |
218 VB_SIS302B |
219 VB_SIS301LV |
220 VB_SIS302LV |
221 VB_XGI301C))
222 tempax |= SupportTV1024;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200223
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300224 if (!(pVBInfo->VBInfo & TVSetPAL) &&
225 (modeflag & NoSupportSimuTV) &&
226 (pVBInfo->VBInfo & SetInSlaveMode) &&
227 (!(pVBInfo->VBInfo & SetNotSimuMode)))
228 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530229 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300230 } else if (pVBInfo->VBInfo & SetCRT2ToLCD) { /* for LVDS */
231 tempax |= SupportLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200232
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300233 if (resinfo > 0x08)
234 return 0; /* 1024x768 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200235
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300236 if (pVBInfo->LCDResInfo < Panel_1024x768) {
237 if (resinfo > 0x07)
238 return 0; /* 800x600 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200239
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300240 if (resinfo == 0x04)
241 return 0; /* 512x384 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530242 }
243 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200244
Aaro Koskinena39325d2012-11-04 21:14:53 +0200245 for (; XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID ==
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800246 tempbx; (*i)--) {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200247 infoflag = XGI330_RefIndex[RefreshRateTableIndex + (*i)].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800248 Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530249 if (infoflag & tempax)
250 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200251
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530252 if ((*i) == 0)
253 break;
254 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200255
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530256 for ((*i) = 0;; (*i)++) {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200257 infoflag = XGI330_RefIndex[RefreshRateTableIndex + (*i)].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800258 Ext_InfoFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +0200259 if (XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530260 != tempbx) {
261 return 0;
262 }
263
264 if (infoflag & tempax)
265 return 1;
266 }
267 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200268}
269
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200270static void XGI_SetSync(unsigned short RefreshRateTableIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530271 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200272{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530273 unsigned short sync, temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200274
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800275 /* di+0x00 */
Aaro Koskinena39325d2012-11-04 21:14:53 +0200276 sync = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag >> 8;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530277 sync &= 0xC0;
278 temp = 0x2F;
279 temp |= sync;
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200280 outb(temp, pVBInfo->P3c2); /* Set Misc(3c2) */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200281}
282
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200283static void XGI_SetCRT1Timing_H(struct vb_device_info *pVBInfo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530284 struct xgi_hw_device_info *HwDeviceExtension)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200285{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530286 unsigned char data, data1, pushax;
287 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200288
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800289 /* unlock cr0-7 */
Peter Huewe9388ad92013-02-15 20:37:10 +0100290 data = xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530291 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200292 xgifb_reg_set(pVBInfo->P3d4, 0x11, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200293
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200294 data = pVBInfo->TimingH.data[0];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200295 xgifb_reg_set(pVBInfo->P3d4, 0, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200296
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530297 for (i = 0x01; i <= 0x04; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200298 data = pVBInfo->TimingH.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200299 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 1), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530300 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200301
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530302 for (i = 0x05; i <= 0x06; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200303 data = pVBInfo->TimingH.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200304 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i + 6), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530305 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200306
Peter Huewe9388ad92013-02-15 20:37:10 +0100307 j = xgifb_reg_get(pVBInfo->P3c4, 0x0e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530308 j &= 0x1F;
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200309 data = pVBInfo->TimingH.data[7];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530310 data &= 0xE0;
311 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200312 xgifb_reg_set(pVBInfo->P3c4, 0x0e, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200313
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530314 if (HwDeviceExtension->jChipType >= XG20) {
Peter Huewe9388ad92013-02-15 20:37:10 +0100315 data = xgifb_reg_get(pVBInfo->P3d4, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530316 data = data - 1;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200317 xgifb_reg_set(pVBInfo->P3d4, 0x04, data);
Peter Huewe9388ad92013-02-15 20:37:10 +0100318 data = xgifb_reg_get(pVBInfo->P3d4, 0x05);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530319 data1 = data;
320 data1 &= 0xE0;
321 data &= 0x1F;
322 if (data == 0) {
323 pushax = data;
Peter Huewe9388ad92013-02-15 20:37:10 +0100324 data = xgifb_reg_get(pVBInfo->P3c4, 0x0c);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530325 data &= 0xFB;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200326 xgifb_reg_set(pVBInfo->P3c4, 0x0c, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530327 data = pushax;
328 }
329 data = data - 1;
330 data |= data1;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200331 xgifb_reg_set(pVBInfo->P3d4, 0x05, data);
Peter Huewe9388ad92013-02-15 20:37:10 +0100332 data = xgifb_reg_get(pVBInfo->P3c4, 0x0e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530333 data = data >> 5;
334 data = data + 3;
335 if (data > 7)
336 data = data - 7;
337 data = data << 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200338 xgifb_reg_and_or(pVBInfo->P3c4, 0x0e, ~0xE0, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530339 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200340}
341
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800342static void XGI_SetCRT1Timing_V(unsigned short ModeIdIndex,
343 unsigned short ModeNo,
344 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200345{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530346 unsigned char data;
347 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200348
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530349 for (i = 0x00; i <= 0x01; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200350 data = pVBInfo->TimingV.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200351 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 6), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530352 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200353
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530354 for (i = 0x02; i <= 0x03; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200355 data = pVBInfo->TimingV.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200356 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x0e), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530357 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200358
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530359 for (i = 0x04; i <= 0x05; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200360 data = pVBInfo->TimingV.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200361 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x11), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530362 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200363
Peter Huewe9388ad92013-02-15 20:37:10 +0100364 j = xgifb_reg_get(pVBInfo->P3c4, 0x0a);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530365 j &= 0xC0;
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200366 data = pVBInfo->TimingV.data[6];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530367 data &= 0x3F;
368 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200369 xgifb_reg_set(pVBInfo->P3c4, 0x0a, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200370
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200371 data = pVBInfo->TimingV.data[6];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530372 data &= 0x80;
373 data = data >> 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200374
Aaro Koskinenb3979922012-11-04 21:14:52 +0200375 i = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530376 i &= DoubleScanMode;
377 if (i)
378 data |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200379
Peter Huewe9388ad92013-02-15 20:37:10 +0100380 j = xgifb_reg_get(pVBInfo->P3d4, 0x09);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530381 j &= 0x5F;
382 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200383 xgifb_reg_set(pVBInfo->P3d4, 0x09, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200384}
385
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200386static void XGI_SetCRT1CRTC(unsigned short ModeNo, unsigned short ModeIdIndex,
387 unsigned short RefreshRateTableIndex,
388 struct vb_device_info *pVBInfo,
389 struct xgi_hw_device_info *HwDeviceExtension)
390{
391 unsigned char index, data;
392 unsigned short i;
393
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800394 /* Get index */
Aaro Koskinena39325d2012-11-04 21:14:53 +0200395 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200396 index = index & IndexMask;
397
Peter Huewe9388ad92013-02-15 20:37:10 +0100398 data = xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200399 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200400 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200401
402 for (i = 0; i < 8; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200403 pVBInfo->TimingH.data[i]
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200404 = XGI_CRT1Table[index].CR[i];
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200405
406 for (i = 0; i < 7; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200407 pVBInfo->TimingV.data[i]
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200408 = XGI_CRT1Table[index].CR[i + 8];
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200409
410 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
411
412 XGI_SetCRT1Timing_V(ModeIdIndex, ModeNo, pVBInfo);
413
414 if (pVBInfo->ModeType > 0x03)
Aaro Koskinen8104e322011-03-13 12:26:22 +0200415 xgifb_reg_set(pVBInfo->P3d4, 0x14, 0x4F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200416}
417
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200418/* --------------------------------------------------------------------- */
419/* Function : XGI_SetXG21CRTC */
420/* Input : Stand or enhance CRTC table */
421/* Output : Fill CRT Hsync/Vsync to SR2E/SR2F/SR30/SR33/SR34/SR3F */
422/* Description : Set LCD timing */
423/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200424static void XGI_SetXG21CRTC(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530425 unsigned short RefreshRateTableIndex,
426 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200427{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300428 unsigned char index, Tempax, Tempbx, Tempcx, Tempdx;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530429 unsigned short Temp1, Temp2, Temp3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200430
Aaro Koskinena39325d2012-11-04 21:14:53 +0200431 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300432 /* Tempax: CR4 HRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200433 Tempax = XGI_CRT1Table[index].CR[3];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300434 Tempcx = Tempax; /* Tempcx: HRS */
435 /* SR2E[7:0]->HRS */
436 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200437
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200438 Tempdx = XGI_CRT1Table[index].CR[5]; /* SRB */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300439 Tempdx &= 0xC0; /* Tempdx[7:6]: SRB[7:6] */
440 Temp1 = Tempdx; /* Temp1[7:6]: HRS[9:8] */
441 Temp1 <<= 2; /* Temp1[9:8]: HRS[9:8] */
442 Temp1 |= Tempax; /* Temp1[9:0]: HRS[9:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800443
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200444 Tempax = XGI_CRT1Table[index].CR[4]; /* CR5 HRE */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300445 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200446
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200447 Tempbx = XGI_CRT1Table[index].CR[6]; /* SRC */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300448 Tempbx &= 0x04; /* Tempbx[2]: HRE[5] */
449 Tempbx <<= 3; /* Tempbx[5]: HRE[5] */
450 Tempax |= Tempbx; /* Tempax[5:0]: HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200451
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300452 Temp2 = Temp1 & 0x3C0; /* Temp2[9:6]: HRS[9:6] */
453 Temp2 |= Tempax; /* Temp2[9:0]: HRE[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200454
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300455 Tempcx &= 0x3F; /* Tempcx[5:0]: HRS[5:0] */
456 if (Tempax < Tempcx) /* HRE < HRS */
457 Temp2 |= 0x40; /* Temp2 + 0x40 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200458
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300459 Temp2 &= 0xFF;
460 Tempax = (unsigned char) Temp2; /* Tempax: HRE[7:0] */
461 Tempax <<= 2; /* Tempax[7:2]: HRE[5:0] */
462 Tempdx >>= 6; /* Tempdx[7:6]->[1:0] HRS[9:8] */
463 Tempax |= Tempdx; /* HRE[5:0]HRS[9:8] */
464 /* SR2F D[7:2]->HRE, D[1:0]->HRS */
465 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
466 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200467
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300468 /* CR10 VRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200469 Tempax = XGI_CRT1Table[index].CR[10];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300470 Tempbx = Tempax; /* Tempbx: VRS */
471 Tempax &= 0x01; /* Tempax[0]: VRS[0] */
472 xgifb_reg_or(pVBInfo->P3c4, 0x33, Tempax); /* SR33[0]->VRS[0] */
473 /* CR7[2][7] VRE */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200474 Tempax = XGI_CRT1Table[index].CR[9];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300475 Tempcx = Tempbx >> 1; /* Tempcx[6:0]: VRS[7:1] */
476 Tempdx = Tempax & 0x04; /* Tempdx[2]: CR7[2] */
477 Tempdx <<= 5; /* Tempdx[7]: VRS[8] */
478 Tempcx |= Tempdx; /* Tempcx[7:0]: VRS[8:1] */
479 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempcx); /* SR34[8:1]->VRS */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200480
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300481 Temp1 = Tempdx; /* Temp1[7]: Tempdx[7] */
482 Temp1 <<= 1; /* Temp1[8]: VRS[8] */
483 Temp1 |= Tempbx; /* Temp1[8:0]: VRS[8:0] */
484 Tempax &= 0x80;
485 Temp2 = Tempax << 2; /* Temp2[9]: VRS[9] */
486 Temp1 |= Temp2; /* Temp1[9:0]: VRS[9:0] */
487 /* Tempax: SRA */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200488 Tempax = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300489 Tempax &= 0x08; /* Tempax[3]: VRS[3] */
490 Temp2 = Tempax;
491 Temp2 <<= 7; /* Temp2[10]: VRS[10] */
492 Temp1 |= Temp2; /* Temp1[10:0]: VRS[10:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200493
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300494 /* Tempax: CR11 VRE */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200495 Tempax = XGI_CRT1Table[index].CR[11];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300496 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
497 /* Tempbx: SRA */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200498 Tempbx = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300499 Tempbx &= 0x20; /* Tempbx[5]: VRE[5] */
500 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
501 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
502 Temp2 = Temp1 & 0x7E0; /* Temp2[10:5]: VRS[10:5] */
503 Temp2 |= Tempax; /* Temp2[10:5]: VRE[10:5] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200504
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300505 Temp3 = Temp1 & 0x1F; /* Temp3[4:0]: VRS[4:0] */
506 if (Tempax < Temp3) /* VRE < VRS */
507 Temp2 |= 0x20; /* VRE + 0x20 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200508
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300509 Temp2 &= 0xFF;
510 Tempax = (unsigned char) Temp2; /* Tempax: VRE[7:0] */
511 Tempax <<= 2; /* Tempax[7:0]; VRE[5:0]00 */
512 Temp1 &= 0x600; /* Temp1[10:9]: VRS[10:9] */
513 Temp1 >>= 9; /* Temp1[1:0]: VRS[10:9] */
514 Tempbx = (unsigned char) Temp1;
515 Tempax |= Tempbx; /* Tempax[7:0]: VRE[5:0]VRS[10:9] */
516 Tempax &= 0x7F;
517 /* SR3F D[7:2]->VRE D[1:0]->VRS */
518 xgifb_reg_set(pVBInfo->P3c4, 0x3F, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200519}
520
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800521static void XGI_SetXG27CRTC(unsigned short ModeNo,
522 unsigned short ModeIdIndex,
523 unsigned short RefreshRateTableIndex,
524 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200525{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300526 unsigned short index, Tempax, Tempbx, Tempcx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200527
Aaro Koskinena39325d2012-11-04 21:14:53 +0200528 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300529 /* Tempax: CR4 HRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200530 Tempax = XGI_CRT1Table[index].CR[3];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300531 Tempbx = Tempax; /* Tempbx: HRS[7:0] */
532 /* SR2E[7:0]->HRS */
533 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200534
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300535 /* SR0B */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200536 Tempax = XGI_CRT1Table[index].CR[5];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300537 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
538 Tempbx |= (Tempax << 2); /* Tempbx: HRS[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200539
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200540 Tempax = XGI_CRT1Table[index].CR[4]; /* CR5 HRE */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300541 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
542 Tempcx = Tempax; /* Tempcx: HRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200543
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200544 Tempax = XGI_CRT1Table[index].CR[6]; /* SRC */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300545 Tempax &= 0x04; /* Tempax[2]: HRE[5] */
546 Tempax <<= 3; /* Tempax[5]: HRE[5] */
547 Tempcx |= Tempax; /* Tempcx[5:0]: HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200548
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300549 Tempbx = Tempbx & 0x3C0; /* Tempbx[9:6]: HRS[9:6] */
550 Tempbx |= Tempcx; /* Tempbx: HRS[9:6]HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200551
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300552 /* Tempax: CR4 HRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200553 Tempax = XGI_CRT1Table[index].CR[3];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300554 Tempax &= 0x3F; /* Tempax: HRS[5:0] */
555 if (Tempcx <= Tempax) /* HRE[5:0] < HRS[5:0] */
556 Tempbx += 0x40; /* Tempbx= Tempbx + 0x40 : HRE[9:0]*/
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200557
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200558 Tempax = XGI_CRT1Table[index].CR[5]; /* SR0B */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300559 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
560 Tempax >>= 6; /* Tempax[1:0]: HRS[9:8]*/
561 Tempax |= ((Tempbx << 2) & 0xFF); /* Tempax[7:2]: HRE[5:0] */
562 /* SR2F [7:2][1:0]: HRE[5:0]HRS[9:8] */
563 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
564 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200565
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300566 /* CR10 VRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200567 Tempax = XGI_CRT1Table[index].CR[10];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300568 /* SR34[7:0]->VRS[7:0] */
569 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200570
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300571 Tempcx = Tempax; /* Tempcx <= VRS[7:0] */
572 /* CR7[7][2] VRS[9][8] */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200573 Tempax = XGI_CRT1Table[index].CR[9];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300574 Tempbx = Tempax; /* Tempbx <= CR07[7:0] */
575 Tempax = Tempax & 0x04; /* Tempax[2]: CR7[2]: VRS[8] */
576 Tempax >>= 2; /* Tempax[0]: VRS[8] */
577 /* SR35[0]: VRS[8] */
578 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x01, Tempax);
579 Tempcx |= (Tempax << 8); /* Tempcx <= VRS[8:0] */
580 Tempcx |= ((Tempbx & 0x80) << 2); /* Tempcx <= VRS[9:0] */
581 /* Tempax: SR0A */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200582 Tempax = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300583 Tempax &= 0x08; /* SR0A[3] VRS[10] */
584 Tempcx |= (Tempax << 7); /* Tempcx <= VRS[10:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200585
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300586 /* Tempax: CR11 VRE */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200587 Tempax = XGI_CRT1Table[index].CR[11];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300588 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
589 /* Tempbx: SR0A */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200590 Tempbx = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300591 Tempbx &= 0x20; /* Tempbx[5]: SR0A[5]: VRE[4] */
592 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
593 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
594 Tempbx = Tempcx; /* Tempbx: VRS[10:0] */
595 Tempbx &= 0x7E0; /* Tempbx[10:5]: VRS[10:5] */
596 Tempbx |= Tempax; /* Tempbx: VRS[10:5]VRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200597
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300598 if (Tempbx <= Tempcx) /* VRE <= VRS */
599 Tempbx |= 0x20; /* VRE + 0x20 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200600
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300601 /* Tempax: Tempax[7:0]; VRE[5:0]00 */
602 Tempax = (Tempbx << 2) & 0xFF;
603 /* SR3F[7:2]:VRE[5:0] */
604 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC, Tempax);
605 Tempax = Tempcx >> 8;
606 /* SR35[2:0]:VRS[10:8] */
607 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200608}
609
Aaro Koskinena2d08cf2011-11-27 23:03:08 +0200610static void XGI_SetXG27FPBits(struct vb_device_info *pVBInfo)
611{
612 unsigned char temp;
613
614 /* D[1:0] 01: 18bit, 00: dual 12, 10: single 24 */
615 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
616 temp = (temp & 3) << 6;
617 /* SR06[7]0: dual 12/1: single 24 [6] 18bit Dither <= 0 h/w recommend */
618 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0xc0, temp & 0x80);
619 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: 24bits */
620 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
621
622}
623
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300624static void xgifb_set_lcd(int chip_id,
625 struct vb_device_info *pVBInfo,
626 unsigned short RefreshRateTableIndex,
627 unsigned short ModeNo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200628{
Peter Huewee2e544c2013-02-03 04:08:46 +0100629 unsigned short temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200630
Aaro Koskinen8104e322011-03-13 12:26:22 +0200631 xgifb_reg_set(pVBInfo->P3d4, 0x2E, 0x00);
632 xgifb_reg_set(pVBInfo->P3d4, 0x2F, 0x00);
633 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x00);
634 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x00);
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300635
636 if (chip_id == XG27) {
Peter Huewee2e544c2013-02-03 04:08:46 +0100637 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
638 if ((temp & 0x03) == 0) { /* dual 12 */
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300639 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x13);
640 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x13);
641 }
642 }
643
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300644 if (chip_id == XG27) {
645 XGI_SetXG27FPBits(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530646 } else {
Peter Huewee2e544c2013-02-03 04:08:46 +0100647 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
648 if (temp & 0x01) {
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300649 /* 18 bits FP */
650 xgifb_reg_or(pVBInfo->P3c4, 0x06, 0x40);
651 xgifb_reg_or(pVBInfo->P3c4, 0x09, 0x40);
652 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530653 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200654
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +0200655 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x01); /* Negative blank polarity */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200656
Aaro Koskinendc505562011-03-13 12:26:26 +0200657 xgifb_reg_and(pVBInfo->P3c4, 0x30, ~0x20); /* Hsync polarity */
658 xgifb_reg_and(pVBInfo->P3c4, 0x35, ~0x80); /* Vsync polarity */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200659
Peter Huewee2e544c2013-02-03 04:08:46 +0100660 temp = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
661 if (temp & 0x4000)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300662 /* Hsync polarity */
663 xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20);
Peter Huewee2e544c2013-02-03 04:08:46 +0100664 if (temp & 0x8000)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300665 /* Vsync polarity */
666 xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200667}
668
669/* --------------------------------------------------------------------- */
670/* Function : XGI_UpdateXG21CRTC */
671/* Input : */
672/* Output : CRT1 CRTC */
673/* Description : Modify CRT1 Hsync/Vsync to fix LCD mode timing */
674/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800675static void XGI_UpdateXG21CRTC(unsigned short ModeNo,
676 struct vb_device_info *pVBInfo,
677 unsigned short RefreshRateTableIndex)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200678{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300679 int index = -1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200680
Aaro Koskinendc505562011-03-13 12:26:26 +0200681 xgifb_reg_and(pVBInfo->P3d4, 0x11, 0x7F); /* Unlock CR0~7 */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300682 if (ModeNo == 0x2E &&
Aaro Koskinena39325d2012-11-04 21:14:53 +0200683 (XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC ==
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300684 RES640x480x60))
685 index = 12;
Aaro Koskinena39325d2012-11-04 21:14:53 +0200686 else if (ModeNo == 0x2E && (XGI330_RefIndex[RefreshRateTableIndex].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800687 Ext_CRT1CRTC == RES640x480x72))
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300688 index = 13;
689 else if (ModeNo == 0x2F)
690 index = 14;
691 else if (ModeNo == 0x50)
692 index = 15;
693 else if (ModeNo == 0x59)
694 index = 16;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200695
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530696 if (index != -1) {
Aaro Koskinen8104e322011-03-13 12:26:22 +0200697 xgifb_reg_set(pVBInfo->P3d4, 0x02,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200698 XGI_UpdateCRT1Table[index].CR02);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200699 xgifb_reg_set(pVBInfo->P3d4, 0x03,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200700 XGI_UpdateCRT1Table[index].CR03);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200701 xgifb_reg_set(pVBInfo->P3d4, 0x15,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200702 XGI_UpdateCRT1Table[index].CR15);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200703 xgifb_reg_set(pVBInfo->P3d4, 0x16,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200704 XGI_UpdateCRT1Table[index].CR16);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530705 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200706}
707
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200708static void XGI_SetCRT1DE(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530709 unsigned short ModeNo, unsigned short ModeIdIndex,
710 unsigned short RefreshRateTableIndex,
711 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200712{
Bill Pemberton82d6eb52010-06-17 13:10:46 -0400713 unsigned short resindex, tempax, tempbx, tempcx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200714
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530715 unsigned char data;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200716
Aaro Koskinenb3979922012-11-04 21:14:52 +0200717 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200718
Aaro Koskinenb3979922012-11-04 21:14:52 +0200719 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinene8e6c752012-11-04 21:15:00 +0200720 tempax = XGI330_ModeResInfo[resindex].HTotal;
721 tempbx = XGI330_ModeResInfo[resindex].VTotal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200722
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530723 if (modeflag & HalfDCLK)
724 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200725
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300726 if (modeflag & HalfDCLK)
727 tempax = tempax << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200728
Aaro Koskinena39325d2012-11-04 21:14:53 +0200729 temp = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200730
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300731 if (temp & InterlaceMode)
732 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200733
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300734 if (modeflag & DoubleScanMode)
735 tempbx = tempbx << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200736
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530737 tempcx = 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200738
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530739 tempax /= tempcx;
740 tempax -= 1;
741 tempbx -= 1;
742 tempcx = tempax;
Peter Huewe9388ad92013-02-15 20:37:10 +0100743 temp = xgifb_reg_get(pVBInfo->P3d4, 0x11);
744 data = xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530745 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200746 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
747 xgifb_reg_set(pVBInfo->P3d4, 0x01, (unsigned short) (tempcx & 0xff));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200748 xgifb_reg_and_or(pVBInfo->P3d4, 0x0b, ~0x0c,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530749 (unsigned short) ((tempcx & 0x0ff00) >> 10));
Aaro Koskinen8104e322011-03-13 12:26:22 +0200750 xgifb_reg_set(pVBInfo->P3d4, 0x12, (unsigned short) (tempbx & 0xff));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530751 tempax = 0;
752 tempbx = tempbx >> 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200753
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530754 if (tempbx & 0x01)
755 tempax |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200756
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530757 if (tempbx & 0x02)
758 tempax |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200759
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200760 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x42, tempax);
Peter Huewe9388ad92013-02-15 20:37:10 +0100761 data = xgifb_reg_get(pVBInfo->P3d4, 0x07);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530762 data &= 0xFF;
763 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200764
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530765 if (tempbx & 0x04)
766 tempax |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200767
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200768 xgifb_reg_and_or(pVBInfo->P3d4, 0x0a, ~0x02, tempax);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200769 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200770}
771
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800772static void XGI_SetCRT1Offset(unsigned short ModeNo,
773 unsigned short ModeIdIndex,
774 unsigned short RefreshRateTableIndex,
775 struct xgi_hw_device_info *HwDeviceExtension,
776 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200777{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530778 unsigned short temp, ah, al, temp2, i, DisplayUnit;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200779
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530780 /* GetOffset */
Aaro Koskinenb3979922012-11-04 21:14:52 +0200781 temp = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeInfo;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530782 temp = temp >> 8;
Aaro Koskinen224114c2012-11-04 21:14:59 +0200783 temp = XGI330_ScreenOffset[temp];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200784
Aaro Koskinena39325d2012-11-04 21:14:53 +0200785 temp2 = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530786 temp2 &= InterlaceMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200787
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530788 if (temp2)
789 temp = temp << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200790
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530791 temp2 = pVBInfo->ModeType - ModeEGA;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200792
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530793 switch (temp2) {
794 case 0:
795 temp2 = 1;
796 break;
797 case 1:
798 temp2 = 2;
799 break;
800 case 2:
801 temp2 = 4;
802 break;
803 case 3:
804 temp2 = 4;
805 break;
806 case 4:
807 temp2 = 6;
808 break;
809 case 5:
810 temp2 = 8;
811 break;
812 default:
813 break;
814 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200815
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530816 if ((ModeNo >= 0x26) && (ModeNo <= 0x28))
817 temp = temp * temp2 + temp2 / 2;
818 else
819 temp *= temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200820
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530821 /* SetOffset */
822 DisplayUnit = temp;
823 temp2 = temp;
824 temp = temp >> 8; /* ah */
825 temp &= 0x0F;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200826 i = xgifb_reg_get(pVBInfo->P3c4, 0x0E);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530827 i &= 0xF0;
828 i |= temp;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200829 xgifb_reg_set(pVBInfo->P3c4, 0x0E, i);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200830
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530831 temp = (unsigned char) temp2;
832 temp &= 0xFF; /* al */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200833 xgifb_reg_set(pVBInfo->P3d4, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200834
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530835 /* SetDisplayUnit */
Aaro Koskinena39325d2012-11-04 21:14:53 +0200836 temp2 = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530837 temp2 &= InterlaceMode;
838 if (temp2)
839 DisplayUnit >>= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200840
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530841 DisplayUnit = DisplayUnit << 5;
842 ah = (DisplayUnit & 0xff00) >> 8;
843 al = DisplayUnit & 0x00ff;
844 if (al == 0)
845 ah += 1;
846 else
847 ah += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200848
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530849 if (HwDeviceExtension->jChipType >= XG20)
850 if ((ModeNo == 0x4A) | (ModeNo == 0x49))
851 ah -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200852
Aaro Koskinen8104e322011-03-13 12:26:22 +0200853 xgifb_reg_set(pVBInfo->P3c4, 0x10, ah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200854}
855
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200856static unsigned short XGI_GetVCLK2Ptr(unsigned short ModeNo,
857 unsigned short ModeIdIndex,
858 unsigned short RefreshRateTableIndex,
859 struct xgi_hw_device_info *HwDeviceExtension,
860 struct vb_device_info *pVBInfo)
861{
Peter Hueweef9a6b92013-02-03 04:08:43 +0100862 unsigned short VCLKIndex, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200863
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300864 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +0200865 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200866
Aaro Koskinen7ac54d02013-02-09 00:03:43 +0200867 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) { /*301b*/
868 if (pVBInfo->LCDResInfo != Panel_1024x768)
869 /* LCDXlat2VCLK */
870 VCLKIndex = VCLK108_2_315 + 5;
871 else
872 VCLKIndex = VCLK65_315 + 2; /* LCDXlat1VCLK */
873 } else if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
874 if (pVBInfo->SetFlag & RPLLDIV2XO)
875 VCLKIndex = TVCLKBASE_315_25 + HiTVVCLKDIV2;
876 else
877 VCLKIndex = TVCLKBASE_315_25 + HiTVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200878
Aaro Koskinen7ac54d02013-02-09 00:03:43 +0200879 if (pVBInfo->SetFlag & TVSimuMode) {
880 if (modeflag & Charx8Dot) {
881 VCLKIndex = TVCLKBASE_315_25 + HiTVSimuVCLK;
882 } else {
883 VCLKIndex = TVCLKBASE_315_25 + HiTVTextVCLK;
Aaro Koskinen798b4da2011-11-27 23:03:20 +0200884 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200885 }
Aaro Koskinen7ac54d02013-02-09 00:03:43 +0200886
887 /* 301lv */
888 if (pVBInfo->VBType & VB_SIS301LV) {
889 if (pVBInfo->SetFlag & RPLLDIV2XO)
890 VCLKIndex = YPbPr525iVCLK_2;
891 else
892 VCLKIndex = YPbPr525iVCLK;
893 }
894 } else if (pVBInfo->VBInfo & SetCRT2ToTV) {
895 if (pVBInfo->SetFlag & RPLLDIV2XO)
896 VCLKIndex = TVCLKBASE_315_25 + TVVCLKDIV2;
897 else
898 VCLKIndex = TVCLKBASE_315_25 + TVVCLK;
899 } else { /* for CRT2 */
900 /* di+Ext_CRTVCLK */
901 VCLKIndex = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
902 VCLKIndex &= IndexMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200903 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200904
905 return VCLKIndex;
906}
907
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800908static void XGI_SetCRT1VCLK(unsigned short ModeNo,
909 unsigned short ModeIdIndex,
910 struct xgi_hw_device_info *HwDeviceExtension,
911 unsigned short RefreshRateTableIndex,
912 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200913{
Bill Pemberton108afbf2010-06-17 13:10:47 -0400914 unsigned char index, data;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530915 unsigned short vclkindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200916
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530917 if (pVBInfo->IF_DEF_LVDS == 1) {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200918 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200919 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200920 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200921 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[index].SR2B);
922 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[index].SR2C);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200923 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Peter Huewe6896b942012-02-09 21:11:46 +0100924 } else if ((pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
925 | VB_SIS302LV | VB_XGI301C)) && (pVBInfo->VBInfo
Peter Huewea3d675c2012-02-09 21:11:47 +0100926 & XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530927 vclkindex = XGI_GetVCLK2Ptr(ModeNo, ModeIdIndex,
928 RefreshRateTableIndex, HwDeviceExtension,
929 pVBInfo);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200930 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200931 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200932 data = XGI_VBVCLKData[vclkindex].Part4_A;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200933 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200934 data = XGI_VBVCLKData[vclkindex].Part4_B;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200935 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
936 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530937 } else {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200938 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200939 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200940 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200941 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[index].SR2B);
942 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[index].SR2C);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200943 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530944 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200945
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530946 if (HwDeviceExtension->jChipType >= XG20) {
Aaro Koskinenb3979922012-11-04 21:14:52 +0200947 if (XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag &
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800948 HalfDCLK) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200949 data = xgifb_reg_get(pVBInfo->P3c4, 0x2B);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200950 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200951 data = xgifb_reg_get(pVBInfo->P3c4, 0x2C);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530952 index = data;
953 index &= 0xE0;
954 data &= 0x1F;
955 data = data << 1;
956 data += 1;
957 data |= index;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200958 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530959 }
960 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200961}
962
Aaro Koskinene85f2032011-11-27 23:03:07 +0200963static void XGI_SetXG21FPBits(struct vb_device_info *pVBInfo)
964{
965 unsigned char temp;
966
967 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37); /* D[0] 1: 18bit */
968 temp = (temp & 1) << 6;
969 /* SR06[6] 18bit Dither */
970 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x40, temp);
971 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: dual 12bits */
972 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
973
974}
975
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200976static void XGI_SetCRT1FIFO(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530977 struct xgi_hw_device_info *HwDeviceExtension,
978 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200979{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530980 unsigned short data;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200981
Aaro Koskinen58839b02011-03-13 12:26:23 +0200982 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530983 data &= 0xfe;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200984 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data); /* diable auto-threshold */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200985
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300986 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0x34);
987 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
988 data &= 0xC0;
989 xgifb_reg_set(pVBInfo->P3c4, 0x09, data | 0x30);
990 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
991 data |= 0x01;
992 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200993
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530994 if (HwDeviceExtension->jChipType == XG21)
995 XGI_SetXG21FPBits(pVBInfo); /* Fix SR9[7:6] can't read back */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200996}
997
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200998static void XGI_SetVCLKState(struct xgi_hw_device_info *HwDeviceExtension,
999 unsigned short ModeNo, unsigned short RefreshRateTableIndex,
1000 struct vb_device_info *pVBInfo)
1001{
1002 unsigned short data, data2 = 0;
1003 short VCLK;
1004
1005 unsigned char index;
1006
Aaro Koskinena39325d2012-11-04 21:14:53 +02001007 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001008 index &= IndexMask;
Aaro Koskinenacfe0932012-11-04 21:14:58 +02001009 VCLK = XGI_VCLKData[index].CLOCK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001010
Aaro Koskinen58839b02011-03-13 12:26:23 +02001011 data = xgifb_reg_get(pVBInfo->P3c4, 0x32);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001012 data &= 0xf3;
1013 if (VCLK >= 200)
1014 data |= 0x0c; /* VCLK > 200 */
1015
1016 if (HwDeviceExtension->jChipType >= XG20)
1017 data &= ~0x04; /* 2 pixel mode */
1018
Aaro Koskinen8104e322011-03-13 12:26:22 +02001019 xgifb_reg_set(pVBInfo->P3c4, 0x32, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001020
1021 if (HwDeviceExtension->jChipType < XG20) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001022 data = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001023 data &= 0xE7;
1024 if (VCLK < 200)
1025 data |= 0x10;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001026 xgifb_reg_set(pVBInfo->P3c4, 0x1F, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001027 }
1028
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001029 data2 = 0x00;
1030
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001031 xgifb_reg_and_or(pVBInfo->P3c4, 0x07, 0xFC, data2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001032 if (HwDeviceExtension->jChipType >= XG27)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001033 xgifb_reg_and_or(pVBInfo->P3c4, 0x40, 0xFC, data2 & 0x03);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001034
1035}
1036
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001037static void XGI_SetCRT1ModeRegs(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301038 unsigned short ModeNo, unsigned short ModeIdIndex,
1039 unsigned short RefreshRateTableIndex,
1040 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001041{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301042 unsigned short data, data2, data3, infoflag = 0, modeflag, resindex,
1043 xres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001044
Aaro Koskinenb3979922012-11-04 21:14:52 +02001045 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02001046 infoflag = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001047
Aaro Koskinen58839b02011-03-13 12:26:23 +02001048 if (xgifb_reg_get(pVBInfo->P3d4, 0x31) & 0x01)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001049 xgifb_reg_and_or(pVBInfo->P3c4, 0x1F, 0x3F, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001050
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001051 data = infoflag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301052 data2 = 0;
Aaro Koskinen969f7f32012-04-07 01:14:03 +03001053 data2 |= 0x02;
1054 data3 = pVBInfo->ModeType - ModeVGA;
1055 data3 = data3 << 2;
1056 data2 |= data3;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301057 data &= InterlaceMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001058
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301059 if (data)
1060 data2 |= 0x20;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001061
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001062 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x3F, data2);
Aaro Koskinenb3979922012-11-04 21:14:52 +02001063 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02001064 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001065
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301066 data = 0x0000;
1067 if (infoflag & InterlaceMode) {
1068 if (xres == 1024)
1069 data = 0x0035;
1070 else if (xres == 1280)
1071 data = 0x0048;
1072 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001073
Peter Huewe5d1c2a92013-02-03 22:54:37 +01001074 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFF, data);
1075 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFC, 0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001076
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301077 if (modeflag & HalfDCLK)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001078 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xF7, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001079
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301080 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001081
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301082 if (modeflag & LineCompareOff)
1083 data2 |= 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001084
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001085 xgifb_reg_and_or(pVBInfo->P3c4, 0x0F, ~0x48, data2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301086 data = 0x60;
Aaro Koskinen969f7f32012-04-07 01:14:03 +03001087 data = data ^ 0x60;
1088 data = data ^ 0xA0;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001089 xgifb_reg_and_or(pVBInfo->P3c4, 0x21, 0x1F, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001090
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301091 XGI_SetVCLKState(HwDeviceExtension, ModeNo, RefreshRateTableIndex,
1092 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001093
Aaro Koskinen58839b02011-03-13 12:26:23 +02001094 data = xgifb_reg_get(pVBInfo->P3d4, 0x31);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001095
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301096 if (HwDeviceExtension->jChipType == XG27) {
1097 if (data & 0x40)
1098 data = 0x2c;
1099 else
1100 data = 0x6c;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001101 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02001102 xgifb_reg_or(pVBInfo->P3d4, 0x51, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301103 } else if (HwDeviceExtension->jChipType >= XG20) {
1104 if (data & 0x40)
1105 data = 0x33;
1106 else
1107 data = 0x73;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001108 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
1109 xgifb_reg_set(pVBInfo->P3d4, 0x51, 0x02);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301110 } else {
1111 if (data & 0x40)
1112 data = 0x2c;
1113 else
1114 data = 0x6c;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001115 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301116 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001117
1118}
1119
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001120static void XGI_WriteDAC(unsigned short dl,
1121 unsigned short ah,
1122 unsigned short al,
1123 unsigned short dh,
1124 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001125{
1126 unsigned short temp, bh, bl;
1127
1128 bh = ah;
1129 bl = al;
1130
1131 if (dl != 0) {
1132 temp = bh;
1133 bh = dh;
1134 dh = temp;
1135 if (dl == 1) {
1136 temp = bl;
1137 bl = dh;
1138 dh = temp;
1139 } else {
1140 temp = bl;
1141 bl = bh;
1142 bh = temp;
1143 }
1144 }
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001145 outb((unsigned short) dh, pVBInfo->P3c9);
1146 outb((unsigned short) bh, pVBInfo->P3c9);
1147 outb((unsigned short) bl, pVBInfo->P3c9);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001148}
1149
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001150static void XGI_LoadDAC(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301151 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001152{
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001153 unsigned short data, data2, i, k, m, n, o, si, di, bx, dl, al, ah, dh;
1154 const unsigned short *table = XGINew_VGA_DAC;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001155
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001156 outb(0xFF, pVBInfo->P3c6);
1157 outb(0x00, pVBInfo->P3c8);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001158
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001159 for (i = 0; i < 16; i++) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301160 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001161
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301162 for (k = 0; k < 3; k++) {
1163 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001164
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301165 if (data & 0x01)
1166 data2 = 0x2A;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001167
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301168 if (data & 0x02)
1169 data2 += 0x15;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001170
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001171 outb(data2, pVBInfo->P3c9);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301172 data = data >> 2;
1173 }
1174 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001175
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001176 for (i = 16; i < 32; i++) {
1177 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001178
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001179 for (k = 0; k < 3; k++)
1180 outb(data, pVBInfo->P3c9);
1181 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001182
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001183 si = 32;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001184
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001185 for (m = 0; m < 9; m++) {
1186 di = si;
1187 bx = si + 0x04;
1188 dl = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001189
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001190 for (n = 0; n < 3; n++) {
1191 for (o = 0; o < 5; o++) {
1192 dh = table[si];
1193 ah = table[di];
1194 al = table[bx];
1195 si++;
1196 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301197 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001198
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001199 si -= 2;
1200
1201 for (o = 0; o < 3; o++) {
1202 dh = table[bx];
1203 ah = table[di];
1204 al = table[si];
1205 si--;
1206 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1207 }
1208
1209 dl++;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301210 }
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001211
1212 si += 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301213 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001214}
1215
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001216static void XGI_GetLVDSResInfo(unsigned short ModeNo,
1217 unsigned short ModeIdIndex,
1218 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001219{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301220 unsigned short resindex, xres, yres, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001221
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001222 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02001223 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001224
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001225 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02001226 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001227
Aaro Koskinene8e6c752012-11-04 21:15:00 +02001228 xres = XGI330_ModeResInfo[resindex].HTotal;
1229 yres = XGI330_ModeResInfo[resindex].VTotal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001230
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001231 if (modeflag & HalfDCLK)
1232 xres = xres << 1;
1233
1234 if (modeflag & DoubleScanMode)
1235 yres = yres << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001236
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301237 if (xres == 720)
1238 xres = 640;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001239
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301240 pVBInfo->VGAHDE = xres;
1241 pVBInfo->HDE = xres;
1242 pVBInfo->VGAVDE = yres;
1243 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001244}
1245
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001246static void const *XGI_GetLcdPtr(struct XGI330_LCDDataTablStruct const *table,
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001247 unsigned short ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001248 unsigned short ModeIdIndex,
1249 unsigned short RefreshRateTableIndex,
1250 struct vb_device_info *pVBInfo)
1251{
Aaro Koskinen6c27b372012-11-04 21:14:45 +02001252 unsigned short i, tempdx, tempbx, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001253
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001254 tempbx = 0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001255
Aaro Koskinenb3979922012-11-04 21:14:52 +02001256 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001257
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001258 i = 0;
1259
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001260 while (table[i].PANELID != 0xff) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001261 tempdx = pVBInfo->LCDResInfo;
1262 if (tempbx & 0x0080) { /* OEMUtil */
1263 tempbx &= (~0x0080);
1264 tempdx = pVBInfo->LCDTypeInfo;
1265 }
1266
1267 if (pVBInfo->LCDInfo & EnableScalingLCD)
1268 tempdx &= (~PanelResInfo);
1269
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001270 if (table[i].PANELID == tempdx) {
1271 tempbx = table[i].MASK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001272 tempdx = pVBInfo->LCDInfo;
1273
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001274 if (modeflag & HalfDCLK)
1275 tempdx |= SetLCDLowResolution;
1276
1277 tempbx &= tempdx;
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001278 if (tempbx == table[i].CAP)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001279 break;
1280 }
1281 i++;
1282 }
1283
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001284 return table[i].DATAPTR;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001285}
1286
Aaro Koskinen24572542012-09-11 00:15:21 +03001287static struct SiS_TVData const *XGI_GetTVPtr(unsigned short ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001288 unsigned short ModeIdIndex,
1289 unsigned short RefreshRateTableIndex,
1290 struct vb_device_info *pVBInfo)
1291{
Aaro Koskinen56d276c2012-09-11 00:15:19 +03001292 unsigned short i, tempdx, tempal, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001293
Aaro Koskinenb3979922012-11-04 21:14:52 +02001294 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02001295 tempal = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001296 tempal = tempal & 0x3f;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001297 tempdx = pVBInfo->TVInfo;
1298
1299 if (pVBInfo->VBInfo & SetInSlaveMode)
1300 tempdx = tempdx | SetTVLockMode;
1301
1302 if (modeflag & HalfDCLK)
1303 tempdx = tempdx | SetTVLowResolution;
1304
1305 i = 0;
1306
Aaro Koskinen6265ee42012-09-11 00:15:20 +03001307 while (XGI_TVDataTable[i].MASK != 0xffff) {
1308 if ((tempdx & XGI_TVDataTable[i].MASK) ==
1309 XGI_TVDataTable[i].CAP)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001310 break;
1311 i++;
1312 }
1313
Aaro Koskinen18ba8662012-09-11 00:15:22 +03001314 return &XGI_TVDataTable[i].DATAPTR[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001315}
1316
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001317static void XGI_GetLVDSData(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301318 unsigned short RefreshRateTableIndex,
1319 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001320{
Aaro Koskinen6008f872012-11-04 21:14:49 +02001321 struct SiS_LVDSData const *LCDPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001322
Aaro Koskinen6008f872012-11-04 21:14:49 +02001323 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
1324 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001325
Aaro Koskinen6008f872012-11-04 21:14:49 +02001326 LCDPtr = XGI_GetLcdPtr(XGI_EPLLCDDataPtr, ModeNo, ModeIdIndex,
1327 RefreshRateTableIndex, pVBInfo);
1328 pVBInfo->VGAHT = LCDPtr->VGAHT;
1329 pVBInfo->VGAVT = LCDPtr->VGAVT;
1330 pVBInfo->HT = LCDPtr->LCDHT;
1331 pVBInfo->VT = LCDPtr->LCDVT;
1332
1333 if (pVBInfo->LCDInfo & (SetLCDtoNonExpanding | EnableScalingLCD))
1334 return;
1335
1336 if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
1337 (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
1338 pVBInfo->HDE = 1024;
1339 pVBInfo->VDE = 768;
1340 } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
1341 (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
1342 pVBInfo->HDE = 1280;
1343 pVBInfo->VDE = 1024;
1344 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
1345 pVBInfo->HDE = 1400;
1346 pVBInfo->VDE = 1050;
1347 } else {
1348 pVBInfo->HDE = 1600;
1349 pVBInfo->VDE = 1200;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301350 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001351}
1352
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001353static void XGI_ModCRT1Regs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301354 unsigned short RefreshRateTableIndex,
1355 struct xgi_hw_device_info *HwDeviceExtension,
1356 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001357{
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001358 unsigned short i;
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001359 struct XGI_LVDSCRT1HDataStruct const *LCDPtr = NULL;
1360 struct XGI_LVDSCRT1VDataStruct const *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001361
Peter Huewea3d675c2012-02-09 21:11:47 +01001362 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001363 LCDPtr = XGI_GetLcdPtr(xgifb_epllcd_crt1_h, ModeNo, ModeIdIndex,
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +03001364 RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001365
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001366 for (i = 0; i < 8; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +02001367 pVBInfo->TimingH.data[i] = LCDPtr[0].Reg[i];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301368 }
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001369
1370 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
1371
Peter Huewea3d675c2012-02-09 21:11:47 +01001372 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001373 LCDPtr1 = XGI_GetLcdPtr(xgifb_epllcd_crt1_v, ModeNo,
1374 ModeIdIndex, RefreshRateTableIndex,
1375 pVBInfo);
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001376 for (i = 0; i < 7; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +02001377 pVBInfo->TimingV.data[i] = LCDPtr1[0].Reg[i];
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001378 }
1379
1380 XGI_SetCRT1Timing_V(ModeIdIndex, ModeNo, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001381}
1382
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001383static unsigned short XGI_GetLCDCapPtr(struct vb_device_info *pVBInfo)
1384{
1385 unsigned char tempal, tempah, tempbl, i;
1386
Aaro Koskinen58839b02011-03-13 12:26:23 +02001387 tempah = xgifb_reg_get(pVBInfo->P3d4, 0x36);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001388 tempal = tempah & 0x0F;
1389 tempah = tempah & 0xF0;
1390 i = 0;
1391 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1392
1393 while (tempbl != 0xFF) {
1394 if (tempbl & 0x80) { /* OEMUtil */
1395 tempal = tempah;
1396 tempbl = tempbl & ~(0x80);
1397 }
1398
1399 if (tempal == tempbl)
1400 break;
1401
1402 i++;
1403
1404 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1405 }
1406
1407 return i;
1408}
1409
1410static unsigned short XGI_GetLCDCapPtr1(struct vb_device_info *pVBInfo)
1411{
1412 unsigned short tempah, tempal, tempbl, i;
1413
1414 tempal = pVBInfo->LCDResInfo;
1415 tempah = pVBInfo->LCDTypeInfo;
1416
1417 i = 0;
1418 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1419
1420 while (tempbl != 0xFF) {
1421 if ((tempbl & 0x80) && (tempbl != 0x80)) {
1422 tempal = tempah;
1423 tempbl &= ~0x80;
1424 }
1425
1426 if (tempal == tempbl)
1427 break;
1428
1429 i++;
1430 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1431 }
1432
1433 if (tempbl == 0xFF) {
Peter Huewe255aabd2012-02-09 21:11:44 +01001434 pVBInfo->LCDResInfo = Panel_1024x768;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001435 pVBInfo->LCDTypeInfo = 0;
1436 i = 0;
1437 }
1438
1439 return i;
1440}
1441
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001442static void XGI_GetLCDSync(unsigned short *HSyncWidth,
1443 unsigned short *VSyncWidth,
1444 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001445{
1446 unsigned short Index;
1447
1448 Index = XGI_GetLCDCapPtr(pVBInfo);
1449 *HSyncWidth = pVBInfo->LCDCapList[Index].LCD_HSyncWidth;
1450 *VSyncWidth = pVBInfo->LCDCapList[Index].LCD_VSyncWidth;
1451
1452 return;
1453}
1454
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001455static void XGI_SetLVDSRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301456 unsigned short RefreshRateTableIndex,
1457 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001458{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301459 unsigned short tempbx, tempax, tempcx, tempdx, push1, push2, modeflag;
1460 unsigned long temp, temp1, temp2, temp3, push3;
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001461 struct XGI330_LCDDataDesStruct2 const *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001462
Aaro Koskinenb3979922012-11-04 21:14:52 +02001463 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Peter Huewe826215d2013-02-05 00:29:46 +01001464 LCDPtr1 = XGI_GetLcdPtr(XGI_EPLLCDDesDataPtr, ModeNo, ModeIdIndex,
1465 RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001466
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001467 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
1468 push1 = tempbx;
1469 push2 = tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001470
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001471 /* GetLCDResInfo */
Peter Huewe255aabd2012-02-09 21:11:44 +01001472 if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
1473 (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001474 tempax = 1024;
1475 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01001476 } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
1477 (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001478 tempax = 1280;
1479 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01001480 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001481 tempax = 1400;
1482 tempbx = 1050;
1483 } else {
1484 tempax = 1600;
1485 tempbx = 1200;
1486 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001487
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001488 if (pVBInfo->LCDInfo & SetLCDtoNonExpanding) {
1489 pVBInfo->HDE = tempax;
1490 pVBInfo->VDE = tempbx;
1491 pVBInfo->VGAHDE = tempax;
1492 pVBInfo->VGAVDE = tempbx;
1493 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001494
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001495 tempax = pVBInfo->HT;
1496
Peter Huewe826215d2013-02-05 00:29:46 +01001497 tempbx = LCDPtr1->LCDHDES;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001498
1499 tempcx = pVBInfo->HDE;
1500 tempbx = tempbx & 0x0fff;
1501 tempcx += tempbx;
1502
1503 if (tempcx >= tempax)
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001504 tempcx -= tempax;
1505
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001506 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, tempbx & 0x07);
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001507
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001508 tempcx = tempcx >> 3;
1509 tempbx = tempbx >> 3;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001510
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001511 xgifb_reg_set(pVBInfo->Part1Port, 0x16,
1512 (unsigned short) (tempbx & 0xff));
1513 xgifb_reg_set(pVBInfo->Part1Port, 0x17,
1514 (unsigned short) (tempcx & 0xff));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001515
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001516 tempax = pVBInfo->HT;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001517
Peter Huewe826215d2013-02-05 00:29:46 +01001518 tempbx = LCDPtr1->LCDHRS;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001519
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001520 tempcx = push2;
1521
1522 if (pVBInfo->LCDInfo & EnableScalingLCD)
1523 tempcx = LCDPtr1->LCDHSync;
1524
1525 tempcx += tempbx;
1526
1527 if (tempcx >= tempax)
1528 tempcx -= tempax;
1529
1530 tempax = tempbx & 0x07;
1531 tempax = tempax >> 5;
1532 tempcx = tempcx >> 3;
1533 tempbx = tempbx >> 3;
1534
1535 tempcx &= 0x1f;
1536 tempax |= tempcx;
1537
1538 xgifb_reg_set(pVBInfo->Part1Port, 0x15, tempax);
1539 xgifb_reg_set(pVBInfo->Part1Port, 0x14,
1540 (unsigned short) (tempbx & 0xff));
1541
1542 tempax = pVBInfo->VT;
Peter Huewe826215d2013-02-05 00:29:46 +01001543 tempbx = LCDPtr1->LCDVDES;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001544 tempcx = pVBInfo->VDE;
1545
1546 tempbx = tempbx & 0x0fff;
1547 tempcx += tempbx;
1548 if (tempcx >= tempax)
1549 tempcx -= tempax;
1550
1551 xgifb_reg_set(pVBInfo->Part1Port, 0x1b,
1552 (unsigned short) (tempbx & 0xff));
1553 xgifb_reg_set(pVBInfo->Part1Port, 0x1c,
1554 (unsigned short) (tempcx & 0xff));
1555
1556 tempbx = (tempbx >> 8) & 0x07;
1557 tempcx = (tempcx >> 8) & 0x07;
1558
1559 xgifb_reg_set(pVBInfo->Part1Port, 0x1d,
1560 (unsigned short) ((tempcx << 3)
1561 | tempbx));
1562
1563 tempax = pVBInfo->VT;
Peter Huewe826215d2013-02-05 00:29:46 +01001564 tempbx = LCDPtr1->LCDVRS;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001565
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001566 tempcx = push1;
1567
1568 if (pVBInfo->LCDInfo & EnableScalingLCD)
1569 tempcx = LCDPtr1->LCDVSync;
1570
1571 tempcx += tempbx;
1572 if (tempcx >= tempax)
1573 tempcx -= tempax;
1574
1575 xgifb_reg_set(pVBInfo->Part1Port, 0x18,
1576 (unsigned short) (tempbx & 0xff));
1577 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, ~0x0f,
1578 (unsigned short) (tempcx & 0x0f));
1579
1580 tempax = ((tempbx >> 8) & 0x07) << 3;
1581
1582 tempbx = pVBInfo->VGAVDE;
1583 if (tempbx != pVBInfo->VDE)
1584 tempax |= 0x40;
1585
Peter Huewea3d675c2012-02-09 21:11:47 +01001586 if (pVBInfo->LCDInfo & XGI_EnableLVDSDDA)
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001587 tempax |= 0x40;
1588
1589 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1a, 0x07,
1590 tempax);
1591
1592 tempcx = pVBInfo->VGAVT;
1593 tempbx = pVBInfo->VDE;
1594 tempax = pVBInfo->VGAVDE;
1595 tempcx -= tempax;
1596
1597 temp = tempax; /* 0430 ylshieh */
1598 temp1 = (temp << 18) / tempbx;
1599
1600 tempdx = (unsigned short) ((temp << 18) % tempbx);
1601
1602 if (tempdx != 0)
1603 temp1 += 1;
1604
1605 temp2 = temp1;
1606 push3 = temp2;
1607
1608 xgifb_reg_set(pVBInfo->Part1Port, 0x37,
1609 (unsigned short) (temp2 & 0xff));
1610 xgifb_reg_set(pVBInfo->Part1Port, 0x36,
1611 (unsigned short) ((temp2 >> 8) & 0xff));
1612
1613 tempbx = (unsigned short) (temp2 >> 16);
1614 tempax = tempbx & 0x03;
1615
1616 tempbx = pVBInfo->VGAVDE;
1617 if (tempbx == pVBInfo->VDE)
1618 tempax |= 0x04;
1619
1620 xgifb_reg_set(pVBInfo->Part1Port, 0x35, tempax);
1621
1622 if (pVBInfo->VBType & VB_XGI301C) {
1623 temp2 = push3;
1624 xgifb_reg_set(pVBInfo->Part4Port,
1625 0x3c,
1626 (unsigned short) (temp2 & 0xff));
1627 xgifb_reg_set(pVBInfo->Part4Port,
1628 0x3b,
1629 (unsigned short) ((temp2 >> 8) &
1630 0xff));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001631 tempbx = (unsigned short) (temp2 >> 16);
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001632 xgifb_reg_and_or(pVBInfo->Part4Port, 0x3a,
1633 ~0xc0,
1634 (unsigned short) ((tempbx &
1635 0xff) << 6));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001636
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001637 tempcx = pVBInfo->VGAVDE;
1638 if (tempcx == pVBInfo->VDE)
1639 xgifb_reg_and_or(pVBInfo->Part4Port,
1640 0x30, ~0x0c, 0x00);
1641 else
1642 xgifb_reg_and_or(pVBInfo->Part4Port,
1643 0x30, ~0x0c, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301644 }
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001645
1646 tempcx = pVBInfo->VGAHDE;
1647 tempbx = pVBInfo->HDE;
1648
1649 temp1 = tempcx << 16;
1650
1651 tempax = (unsigned short) (temp1 / tempbx);
1652
1653 if ((tempbx & 0xffff) == (tempcx & 0xffff))
1654 tempax = 65535;
1655
1656 temp3 = tempax;
1657 temp1 = pVBInfo->VGAHDE << 16;
1658
1659 temp1 /= temp3;
1660 temp3 = temp3 << 16;
1661 temp1 -= 1;
1662
1663 temp3 = (temp3 & 0xffff0000) + (temp1 & 0xffff);
1664
1665 tempax = (unsigned short) (temp3 & 0xff);
1666 xgifb_reg_set(pVBInfo->Part1Port, 0x1f, tempax);
1667
1668 temp1 = pVBInfo->VGAVDE << 18;
1669 temp1 = temp1 / push3;
1670 tempbx = (unsigned short) (temp1 & 0xffff);
1671
Peter Huewe255aabd2012-02-09 21:11:44 +01001672 if (pVBInfo->LCDResInfo == Panel_1024x768)
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001673 tempbx -= 1;
1674
1675 tempax = ((tempbx >> 8) & 0xff) << 3;
1676 tempax |= (unsigned short) ((temp3 >> 8) & 0x07);
1677 xgifb_reg_set(pVBInfo->Part1Port, 0x20,
1678 (unsigned short) (tempax & 0xff));
1679 xgifb_reg_set(pVBInfo->Part1Port, 0x21,
1680 (unsigned short) (tempbx & 0xff));
1681
1682 temp3 = temp3 >> 16;
1683
1684 if (modeflag & HalfDCLK)
1685 temp3 = temp3 >> 1;
1686
1687 xgifb_reg_set(pVBInfo->Part1Port, 0x22,
1688 (unsigned short) ((temp3 >> 8) & 0xff));
1689 xgifb_reg_set(pVBInfo->Part1Port, 0x23,
1690 (unsigned short) (temp3 & 0xff));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001691}
1692
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001693/* --------------------------------------------------------------------- */
1694/* Function : XGI_GETLCDVCLKPtr */
1695/* Input : */
1696/* Output : al -> VCLK Index */
1697/* Description : */
1698/* --------------------------------------------------------------------- */
1699static void XGI_GetLCDVCLKPtr(unsigned char *di_0, unsigned char *di_1,
1700 struct vb_device_info *pVBInfo)
1701{
1702 unsigned short index;
1703
Peter Huewea3d675c2012-02-09 21:11:47 +01001704 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001705 index = XGI_GetLCDCapPtr1(pVBInfo);
1706
1707 if (pVBInfo->VBInfo & SetCRT2ToLCD) { /* LCDB */
1708 *di_0 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData1;
1709 *di_1 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData2;
1710 } else { /* LCDA */
1711 *di_0 = pVBInfo->LCDCapList[index].LCDA_VCLKData1;
1712 *di_1 = pVBInfo->LCDCapList[index].LCDA_VCLKData2;
1713 }
1714 }
1715 return;
1716}
1717
1718static unsigned char XGI_GetVCLKPtr(unsigned short RefreshRateTableIndex,
1719 unsigned short ModeNo, unsigned short ModeIdIndex,
1720 struct vb_device_info *pVBInfo)
1721{
1722
1723 unsigned short index, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001724 unsigned char tempal;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001725
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001726 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02001727 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001728
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001729 if ((pVBInfo->SetFlag & ProgrammingCRT2) &&
1730 (!(pVBInfo->LCDInfo & EnableScalingLCD))) { /* {LCDA/LCDB} */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001731 index = XGI_GetLCDCapPtr(pVBInfo);
1732 tempal = pVBInfo->LCDCapList[index].LCD_VCLK;
1733
Peter Huewea3d675c2012-02-09 21:11:47 +01001734 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001735 return tempal;
1736
1737 /* {TV} */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001738 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01001739 (VB_SIS301B |
1740 VB_SIS302B |
1741 VB_SIS301LV |
1742 VB_SIS302LV |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001743 VB_XGI301C)) {
Peter Huewe599801f2012-02-09 21:11:45 +01001744 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001745 tempal = TVCLKBASE_315 + HiTVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001746 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
Peter Hueweccc8cb22012-02-09 21:11:48 +01001747 tempal = TVCLKBASE_315 + HiTVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001748 if (pVBInfo->TVInfo & TVSimuMode) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001749 tempal = TVCLKBASE_315 + HiTVSimuVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001750 if (!(modeflag & Charx8Dot))
Miguel Gómez3bcc2462012-07-06 12:40:53 +02001751 tempal = TVCLKBASE_315 +
1752 HiTVTextVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001753
1754 }
1755 return tempal;
1756 }
1757
Peter Huewe599801f2012-02-09 21:11:45 +01001758 if (pVBInfo->TVInfo & TVSetYPbPr750p) {
Peter Huewea3d675c2012-02-09 21:11:47 +01001759 tempal = XGI_YPbPr750pVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001760 return tempal;
1761 }
1762
Peter Huewe599801f2012-02-09 21:11:45 +01001763 if (pVBInfo->TVInfo & TVSetYPbPr525p) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001764 tempal = YPbPr525pVCLK;
1765 return tempal;
1766 }
1767
1768 tempal = NTSC1024VCLK;
1769
1770 if (!(pVBInfo->TVInfo & NTSC1024x768)) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001771 tempal = TVCLKBASE_315 + TVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001772 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
Peter Hueweccc8cb22012-02-09 21:11:48 +01001773 tempal = TVCLKBASE_315 + TVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001774 }
1775
1776 if (pVBInfo->VBInfo & SetCRT2ToTV)
1777 return tempal;
1778 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001779 } /* {End of VB} */
1780
Peter Huewe516354e2013-02-15 20:37:11 +01001781 inb((pVBInfo->P3ca + 0x02));
Aaro Koskinena39325d2012-11-04 21:14:53 +02001782 tempal = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001783 return tempal;
1784}
1785
1786static void XGI_GetVCLKLen(unsigned char tempal, unsigned char *di_0,
1787 unsigned char *di_1, struct vb_device_info *pVBInfo)
1788{
Peter Huewe6896b942012-02-09 21:11:46 +01001789 if (pVBInfo->VBType & (VB_SIS301 | VB_SIS301B | VB_SIS302B
1790 | VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +02001791 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) &&
1792 (pVBInfo->SetFlag & ProgrammingCRT2)) {
Aaro Koskinene8cb03d2012-09-11 00:15:31 +03001793 *di_0 = XGI_VBVCLKData[tempal].Part4_A;
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +03001794 *di_1 = XGI_VBVCLKData[tempal].Part4_B;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001795 }
1796 } else {
1797 *di_0 = XGI_VCLKData[tempal].SR2B;
1798 *di_1 = XGI_VCLKData[tempal].SR2C;
1799 }
1800}
1801
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001802static void XGI_SetCRT2ECLK(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301803 unsigned short RefreshRateTableIndex,
1804 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001805{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301806 unsigned char di_0, di_1, tempal;
1807 int i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001808
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301809 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
1810 pVBInfo);
1811 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
1812 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001813
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301814 for (i = 0; i < 4; i++) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001815 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, ~0x30,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301816 (unsigned short) (0x10 * i));
Peter Huewea3d675c2012-02-09 21:11:47 +01001817 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301818 && (!(pVBInfo->VBInfo & SetInSlaveMode))) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001819 xgifb_reg_set(pVBInfo->P3c4, 0x2e, di_0);
1820 xgifb_reg_set(pVBInfo->P3c4, 0x2f, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301821 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001822 xgifb_reg_set(pVBInfo->P3c4, 0x2b, di_0);
1823 xgifb_reg_set(pVBInfo->P3c4, 0x2c, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301824 }
1825 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001826}
1827
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001828static void XGI_UpdateModeInfo(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301829 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001830{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301831 unsigned short tempcl, tempch, temp, tempbl, tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001832
Peter Huewe6896b942012-02-09 21:11:46 +01001833 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
1834 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301835 tempcl = 0;
1836 tempch = 0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02001837 temp = xgifb_reg_get(pVBInfo->P3c4, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001838
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301839 if (!(temp & 0x20)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001840 temp = xgifb_reg_get(pVBInfo->P3d4, 0x17);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301841 if (temp & 0x80) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001842 temp = xgifb_reg_get(pVBInfo->P3d4, 0x53);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301843 if (!(temp & 0x40))
1844 tempcl |= ActiveCRT1;
1845 }
1846 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001847
Aaro Koskinen58839b02011-03-13 12:26:23 +02001848 temp = xgifb_reg_get(pVBInfo->Part1Port, 0x2e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301849 temp &= 0x0f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001850
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301851 if (!(temp == 0x08)) {
Miguel Gómez949eb0a2012-07-06 12:40:36 +02001852 /* Check ChannelA */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001853 tempax = xgifb_reg_get(pVBInfo->Part1Port, 0x13);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301854 if (tempax & 0x04)
1855 tempcl = tempcl | ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001856
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301857 temp &= 0x05;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001858
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301859 if (!(tempcl & ActiveLCD))
1860 if (temp == 0x01)
1861 tempcl |= ActiveCRT2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001862
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301863 if (temp == 0x04)
1864 tempcl |= ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001865
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301866 if (temp == 0x05) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001867 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001868
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301869 if (!(temp & 0x08))
1870 tempch |= ActiveAVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001871
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301872 if (!(temp & 0x04))
1873 tempch |= ActiveSVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001874
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301875 if (temp & 0x02)
1876 tempch |= ActiveSCART;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001877
Peter Huewe599801f2012-02-09 21:11:45 +01001878 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301879 if (temp & 0x01)
1880 tempch |= ActiveHiTV;
1881 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001882
Peter Huewe599801f2012-02-09 21:11:45 +01001883 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001884 temp = xgifb_reg_get(
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301885 pVBInfo->Part2Port,
1886 0x4d);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001887
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301888 if (temp & 0x10)
1889 tempch |= ActiveYPbPr;
1890 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001891
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301892 if (tempch != 0)
1893 tempcl |= ActiveTV;
1894 }
1895 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001896
Aaro Koskinen58839b02011-03-13 12:26:23 +02001897 temp = xgifb_reg_get(pVBInfo->P3d4, 0x3d);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301898 if (tempcl & ActiveLCD) {
1899 if ((pVBInfo->SetFlag & ReserveTVOption)) {
1900 if (temp & ActiveTV)
1901 tempcl |= ActiveTV;
1902 }
1903 }
1904 temp = tempcl;
Peter Huewea3d675c2012-02-09 21:11:47 +01001905 tempbl = ~XGI_ModeSwitchStatus;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001906 xgifb_reg_and_or(pVBInfo->P3d4, 0x3d, tempbl, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001907
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301908 if (!(pVBInfo->SetFlag & ReserveTVOption))
Aaro Koskinen8104e322011-03-13 12:26:22 +02001909 xgifb_reg_set(pVBInfo->P3d4, 0x3e, tempch);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301910 } else {
1911 return;
1912 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001913}
1914
Bill Pemberton80adad82010-06-17 13:10:51 -04001915void XGI_GetVBType(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001916{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301917 unsigned short flag, tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001918
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001919 if (pVBInfo->IF_DEF_LVDS != 0)
1920 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001921
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001922 tempbx = VB_SIS302B;
1923 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
1924 if (flag == 0x02)
1925 goto finish;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001926
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001927 tempbx = VB_SIS301;
1928 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x01);
1929 if (flag < 0xB0)
1930 goto finish;
1931
1932 tempbx = VB_SIS301B;
1933 if (flag < 0xC0)
1934 goto bigger_than_0xB0;
1935
1936 tempbx = VB_XGI301C;
1937 if (flag < 0xD0)
1938 goto bigger_than_0xB0;
1939
1940 tempbx = VB_SIS301LV;
1941 if (flag < 0xE0)
1942 goto bigger_than_0xB0;
1943
1944 tempbx = VB_SIS302LV;
1945 tempah = xgifb_reg_get(pVBInfo->Part4Port, 0x39);
1946 if (tempah != 0xFF)
1947 tempbx = VB_XGI301C;
1948
1949bigger_than_0xB0:
1950 if (tempbx & (VB_SIS301B | VB_SIS302B)) {
1951 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x23);
1952 if (!(flag & 0x02))
1953 tempbx = tempbx | VB_NoLCD;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301954 }
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001955
1956finish:
1957 pVBInfo->VBType = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001958}
1959
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02001960static void XGI_GetVBInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301961 struct xgi_hw_device_info *HwDeviceExtension,
1962 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001963{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301964 unsigned short tempax, push, tempbx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001965
Aaro Koskinenb3979922012-11-04 21:14:52 +02001966 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301967 pVBInfo->SetFlag = 0;
Peter Huewe6896b942012-02-09 21:11:46 +01001968 pVBInfo->ModeType = modeflag & ModeTypeMask;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301969 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001970
Miguel Gómezf9317352012-07-06 12:40:48 +02001971 if (!(pVBInfo->VBType & 0xFFFF))
1972 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001973
Miguel Gómezf9317352012-07-06 12:40:48 +02001974 /* Check Display Device */
1975 temp = xgifb_reg_get(pVBInfo->P3d4, 0x30);
1976 tempbx = tempbx | temp;
1977 temp = xgifb_reg_get(pVBInfo->P3d4, 0x31);
1978 push = temp;
1979 push = push << 8;
1980 tempax = temp << 8;
1981 tempbx = tempbx | tempax;
1982 temp = (SetCRT2ToDualEdge | SetCRT2ToYPbPr525750 | XGI_SetCRT2ToLCDA
1983 | SetInSlaveMode | DisableCRT2Display);
1984 temp = 0xFFFF ^ temp;
1985 tempbx &= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001986
Miguel Gómezf9317352012-07-06 12:40:48 +02001987 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001988
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001989 if (pVBInfo->VBType & (VB_SIS302B | VB_SIS301LV | VB_SIS302LV |
1990 VB_XGI301C)) {
1991 if (temp & EnableDualEdge) {
1992 tempbx |= SetCRT2ToDualEdge;
1993 if (temp & SetToLCDA)
1994 tempbx |= XGI_SetCRT2ToLCDA;
Miguel Gómezf9317352012-07-06 12:40:48 +02001995 }
1996 }
1997
1998 if (pVBInfo->IF_DEF_YPbPr == 1) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001999 if (pVBInfo->VBType & (VB_SIS301LV|VB_SIS302LV|VB_XGI301C)) {
Miguel Gómezf9317352012-07-06 12:40:48 +02002000 if (temp & SetYPbPr) {
2001 if (pVBInfo->IF_DEF_HiVision == 1) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002002 /* shampoo add for new scratch */
2003 temp = xgifb_reg_get(pVBInfo->P3d4,
2004 0x35);
Miguel Gómezf9317352012-07-06 12:40:48 +02002005 temp &= YPbPrMode;
2006 tempbx |= SetCRT2ToHiVision;
2007
2008 if (temp != YPbPrMode1080i) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002009 tempbx &= (~SetCRT2ToHiVision);
2010 tempbx |= SetCRT2ToYPbPr525750;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302011 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302012 }
2013 }
2014 }
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 tempax = push; /* restore CR31 */
2018
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002019 if (pVBInfo->IF_DEF_YPbPr == 1) {
2020 if (pVBInfo->IF_DEF_HiVision == 1)
2021 temp = 0x09FC;
2022 else
2023 temp = 0x097C;
2024 } else if (pVBInfo->IF_DEF_HiVision == 1) {
2025 temp = 0x01FC;
2026 } else {
2027 temp = 0x017C;
Miguel Gómezf9317352012-07-06 12:40:48 +02002028 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002029
Miguel Gómezf9317352012-07-06 12:40:48 +02002030 if (!(tempbx & temp)) {
2031 tempax |= DisableCRT2Display;
2032 tempbx = 0;
2033 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002034
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03002035 if (!(pVBInfo->VBType & VB_NoLCD)) {
2036 if (tempbx & XGI_SetCRT2ToLCDA) {
2037 if (tempbx & SetSimuScanMode)
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002038 tempbx &= (~(SetCRT2ToLCD | SetCRT2ToRAMDAC |
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03002039 SwitchCRT2));
2040 else
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002041 tempbx &= (~(SetCRT2ToLCD | SetCRT2ToRAMDAC |
2042 SetCRT2ToTV | SwitchCRT2));
Miguel Gómezf9317352012-07-06 12:40:48 +02002043 }
2044 }
2045
2046 /* shampoo add */
2047 /* for driver abnormal */
2048 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode))) {
2049 if (pVBInfo->IF_DEF_CRT2Monitor == 1) {
2050 if (tempbx & SetCRT2ToRAMDAC) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002051 tempbx &= (0xFF00 | SetCRT2ToRAMDAC |
2052 SwitchCRT2 | SetSimuScanMode);
Peter Huewe599801f2012-02-09 21:11:45 +01002053 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302054 }
Miguel Gómezf9317352012-07-06 12:40:48 +02002055 } else {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002056 tempbx &= (~(SetCRT2ToRAMDAC | SetCRT2ToLCD |
Miguel Gómezf9317352012-07-06 12:40:48 +02002057 SetCRT2ToTV));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302058 }
Miguel Gómezf9317352012-07-06 12:40:48 +02002059 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002060
Miguel Gómezf9317352012-07-06 12:40:48 +02002061 if (!(pVBInfo->VBType & VB_NoLCD)) {
2062 if (tempbx & SetCRT2ToLCD) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002063 tempbx &= (0xFF00 | SetCRT2ToLCD | SwitchCRT2 |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002064 SetSimuScanMode);
Peter Huewe599801f2012-02-09 21:11:45 +01002065 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302066 }
Miguel Gómezf9317352012-07-06 12:40:48 +02002067 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002068
Miguel Gómezf9317352012-07-06 12:40:48 +02002069 if (tempbx & SetCRT2ToSCART) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002070 tempbx &= (0xFF00 | SetCRT2ToSCART | SwitchCRT2 |
Miguel Gómezf9317352012-07-06 12:40:48 +02002071 SetSimuScanMode);
2072 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
2073 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002074
Miguel Gómezf9317352012-07-06 12:40:48 +02002075 if (pVBInfo->IF_DEF_YPbPr == 1) {
2076 if (tempbx & SetCRT2ToYPbPr525750)
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002077 tempbx &= (0xFF00 | SwitchCRT2 | SetSimuScanMode);
Miguel Gómezf9317352012-07-06 12:40:48 +02002078 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002079
Miguel Gómezf9317352012-07-06 12:40:48 +02002080 if (pVBInfo->IF_DEF_HiVision == 1) {
2081 if (tempbx & SetCRT2ToHiVision)
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002082 tempbx &= (0xFF00 | SetCRT2ToHiVision | SwitchCRT2 |
Miguel Gómezf9317352012-07-06 12:40:48 +02002083 SetSimuScanMode);
2084 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002085
Miguel Gómezf9317352012-07-06 12:40:48 +02002086 if (tempax & DisableCRT2Display) { /* Set Display Device Info */
2087 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode)))
2088 tempbx = DisableCRT2Display;
2089 }
2090
2091 if (!(tempbx & DisableCRT2Display)) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002092 if ((!(tempbx & DriverMode)) || (!(modeflag & CRT2Mode))) {
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03002093 if (!(tempbx & XGI_SetCRT2ToLCDA))
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002094 tempbx |= (SetInSlaveMode | SetSimuScanMode);
Miguel Gómezf9317352012-07-06 12:40:48 +02002095 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002096
Miguel Gómezf9317352012-07-06 12:40:48 +02002097 /* LCD+TV can't support in slave mode
2098 * (Force LCDA+TV->LCDB) */
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002099 if ((tempbx & SetInSlaveMode) && (tempbx & XGI_SetCRT2ToLCDA)) {
2100 tempbx ^= (SetCRT2ToLCD | XGI_SetCRT2ToLCDA |
Miguel Gómezf9317352012-07-06 12:40:48 +02002101 SetCRT2ToDualEdge);
2102 pVBInfo->SetFlag |= ReserveTVOption;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302103 }
2104 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002105
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302106 pVBInfo->VBInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002107}
2108
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02002109static void XGI_GetTVInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302110 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002111{
Peter Huewe5fc699f2013-02-03 04:08:45 +01002112 unsigned short tempbx = 0, resinfo = 0, modeflag, index1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002113
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302114 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinenb3979922012-11-04 21:14:52 +02002115 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2116 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002117
Peter Huewe5fc699f2013-02-03 04:08:45 +01002118 tempbx = xgifb_reg_get(pVBInfo->P3d4, 0x35);
2119 if (tempbx & TVSetPAL) {
2120 tempbx &= (SetCHTVOverScan |
2121 TVSetPALM |
2122 TVSetPALN |
2123 TVSetPAL);
2124 if (tempbx & TVSetPALM)
2125 /* set to NTSC if PAL-M */
2126 tempbx &= ~TVSetPAL;
2127 } else
2128 tempbx &= (SetCHTVOverScan |
2129 TVSetNTSCJ |
2130 TVSetPAL);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002131
Aaro Koskinena8b35292013-02-09 00:03:45 +02002132 if (pVBInfo->VBInfo & SetCRT2ToSCART)
2133 tempbx |= TVSetPAL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002134
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302135 if (pVBInfo->IF_DEF_YPbPr == 1) {
Peter Huewe599801f2012-02-09 21:11:45 +01002136 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002137 index1 = xgifb_reg_get(pVBInfo->P3d4, 0x35);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302138 index1 &= YPbPrMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002139
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302140 if (index1 == YPbPrMode525i)
Peter Huewe599801f2012-02-09 21:11:45 +01002141 tempbx |= TVSetYPbPr525i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002142
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302143 if (index1 == YPbPrMode525p)
Peter Huewe599801f2012-02-09 21:11:45 +01002144 tempbx = tempbx | TVSetYPbPr525p;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302145 if (index1 == YPbPrMode750p)
Peter Huewe599801f2012-02-09 21:11:45 +01002146 tempbx = tempbx | TVSetYPbPr750p;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302147 }
2148 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002149
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302150 if (pVBInfo->IF_DEF_HiVision == 1) {
Peter Huewe599801f2012-02-09 21:11:45 +01002151 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
2152 tempbx = tempbx | TVSetHiVision | TVSetPAL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302153 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002154
Aaro Koskinena8b35292013-02-09 00:03:45 +02002155 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
2156 (!(pVBInfo->VBInfo & SetNotSimuMode)))
2157 tempbx |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002158
Aaro Koskinena8b35292013-02-09 00:03:45 +02002159 if (!(tempbx & TVSetPAL) && (modeflag > 13) && (resinfo == 8))
2160 /* NTSC 1024x768, */
2161 tempbx |= NTSC1024x768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002162
Aaro Koskinena8b35292013-02-09 00:03:45 +02002163 tempbx |= RPLLDIV2XO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002164
Aaro Koskinena8b35292013-02-09 00:03:45 +02002165 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
2166 if (pVBInfo->VBInfo & SetInSlaveMode)
2167 tempbx &= (~RPLLDIV2XO);
2168 } else if (tempbx & (TVSetYPbPr525p | TVSetYPbPr750p)) {
2169 tempbx &= (~RPLLDIV2XO);
2170 } else if (!(pVBInfo->VBType & (VB_SIS301B | VB_SIS302B |
2171 VB_SIS301LV | VB_SIS302LV |
2172 VB_XGI301C))) {
2173 if (tempbx & TVSimuMode)
2174 tempbx &= (~RPLLDIV2XO);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302175 }
2176 }
2177 pVBInfo->TVInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002178}
2179
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02002180static unsigned char XGI_GetLCDInfo(unsigned short ModeNo,
2181 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002182{
Peter Hueweef9a6b92013-02-03 04:08:43 +01002183 unsigned short temp, tempax, tempbx, resinfo = 0, LCDIdIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002184
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302185 pVBInfo->LCDResInfo = 0;
2186 pVBInfo->LCDTypeInfo = 0;
2187 pVBInfo->LCDInfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002188
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002189 /* si+Ext_ResInfo // */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002190 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinen58839b02011-03-13 12:26:23 +02002191 temp = xgifb_reg_get(pVBInfo->P3d4, 0x36); /* Get LCD Res.Info */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302192 tempbx = temp & 0x0F;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002193
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302194 if (tempbx == 0)
Peter Huewe255aabd2012-02-09 21:11:44 +01002195 tempbx = Panel_1024x768; /* default */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002196
Miguel Gómez949eb0a2012-07-06 12:40:36 +02002197 /* LCD75 */
Peter Huewe255aabd2012-02-09 21:11:44 +01002198 if ((tempbx == Panel_1024x768) || (tempbx == Panel_1280x1024)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302199 if (pVBInfo->VBInfo & DriverMode) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002200 tempax = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Peter Huewea3d675c2012-02-09 21:11:47 +01002201 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302202 tempax &= 0x0F;
2203 else
2204 tempax = tempax >> 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002205
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302206 if ((resinfo == 6) || (resinfo == 9)) {
2207 if (tempax >= 3)
2208 tempbx |= PanelRef75Hz;
2209 } else if ((resinfo == 7) || (resinfo == 8)) {
2210 if (tempax >= 4)
2211 tempbx |= PanelRef75Hz;
2212 }
2213 }
2214 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002215
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302216 pVBInfo->LCDResInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002217
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302218 /* End of LCD75 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002219
Peter Huewea3d675c2012-02-09 21:11:47 +01002220 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302221 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002222
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302223 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002224
Aaro Koskinen58839b02011-03-13 12:26:23 +02002225 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002226
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302227 temp &= (ScalingLCD | LCDNonExpanding | LCDSyncBit | SetPWDEnable);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002228
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302229 tempbx |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002230
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302231 LCDIdIndex = XGI_GetLCDCapPtr1(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002232
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302233 tempax = pVBInfo->LCDCapList[LCDIdIndex].LCD_Capability;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002234
Aaro Koskinen718e7152013-02-09 00:03:46 +02002235 if (((pVBInfo->VBType & VB_SIS302LV) ||
2236 (pVBInfo->VBType & VB_XGI301C)) && (tempax & XGI_LCDDualLink))
2237 tempbx |= SetLCDDualLink;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002238
Aaro Koskinen718e7152013-02-09 00:03:46 +02002239 if ((pVBInfo->LCDResInfo == Panel_1400x1050) &&
2240 (pVBInfo->VBInfo & SetCRT2ToLCD) && (resinfo == 9) &&
2241 (!(tempbx & EnableScalingLCD)))
2242 /*
2243 * set to center in 1280x1024 LCDB
2244 * for Panel_1400x1050
2245 */
2246 tempbx |= SetLCDtoNonExpanding;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002247
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302248 if (pVBInfo->VBInfo & SetInSlaveMode) {
2249 if (pVBInfo->VBInfo & SetNotSimuMode)
Peter Huewea3d675c2012-02-09 21:11:47 +01002250 tempbx |= XGI_LCDVESATiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302251 } else {
Peter Huewea3d675c2012-02-09 21:11:47 +01002252 tempbx |= XGI_LCDVESATiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302253 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002254
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302255 pVBInfo->LCDInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002256
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302257 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002258}
2259
Bill Pemberton108afbf2010-06-17 13:10:47 -04002260unsigned char XGI_SearchModeID(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302261 unsigned short *ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002262{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002263 for (*ModeIdIndex = 0;; (*ModeIdIndex)++) {
Aaro Koskinenb3979922012-11-04 21:14:52 +02002264 if (XGI330_EModeIDTable[*ModeIdIndex].Ext_ModeID == ModeNo)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002265 break;
Aaro Koskinenb3979922012-11-04 21:14:52 +02002266 if (XGI330_EModeIDTable[*ModeIdIndex].Ext_ModeID == 0xFF)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002267 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302268 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002269
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302270 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002271}
2272
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002273static unsigned char XG21GPIODataTransfer(unsigned char ujDate)
2274{
2275 unsigned char ujRet = 0;
2276 unsigned char i = 0;
2277
2278 for (i = 0; i < 8; i++) {
2279 ujRet = ujRet << 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002280 ujRet |= (ujDate >> i) & 1;
2281 }
2282
2283 return ujRet;
2284}
2285
2286/*----------------------------------------------------------------------------*/
2287/* output */
2288/* bl[5] : LVDS signal */
2289/* bl[1] : LVDS backlight */
2290/* bl[0] : LVDS VDD */
2291/*----------------------------------------------------------------------------*/
2292static unsigned char XGI_XG21GetPSCValue(struct vb_device_info *pVBInfo)
2293{
2294 unsigned char CR4A, temp;
2295
Aaro Koskinen58839b02011-03-13 12:26:23 +02002296 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02002297 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x23); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002298
Aaro Koskinen58839b02011-03-13 12:26:23 +02002299 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002300
2301 temp = XG21GPIODataTransfer(temp);
2302 temp &= 0x23;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002303 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002304 return temp;
2305}
2306
2307/*----------------------------------------------------------------------------*/
2308/* output */
2309/* bl[5] : LVDS signal */
2310/* bl[1] : LVDS backlight */
2311/* bl[0] : LVDS VDD */
2312/*----------------------------------------------------------------------------*/
2313static unsigned char XGI_XG27GetPSCValue(struct vb_device_info *pVBInfo)
2314{
2315 unsigned char CR4A, CRB4, temp;
2316
Aaro Koskinen58839b02011-03-13 12:26:23 +02002317 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02002318 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x0C); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002319
Aaro Koskinen58839b02011-03-13 12:26:23 +02002320 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002321
2322 temp &= 0x0C;
2323 temp >>= 2;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002324 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinen58839b02011-03-13 12:26:23 +02002325 CRB4 = xgifb_reg_get(pVBInfo->P3d4, 0xB4);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002326 temp |= ((CRB4 & 0x04) << 3);
2327 return temp;
2328}
2329
Aaro Koskinen0ebf5382011-11-27 23:03:09 +02002330/*----------------------------------------------------------------------------*/
2331/* input */
2332/* bl[5] : 1;LVDS signal on */
2333/* bl[1] : 1;LVDS backlight on */
2334/* bl[0] : 1:LVDS VDD on */
2335/* bh: 100000b : clear bit 5, to set bit5 */
2336/* 000010b : clear bit 1, to set bit1 */
2337/* 000001b : clear bit 0, to set bit0 */
2338/*----------------------------------------------------------------------------*/
2339static void XGI_XG21BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
2340 struct vb_device_info *pVBInfo)
2341{
2342 unsigned char CR4A, temp;
2343
2344 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
2345 tempbh &= 0x23;
2346 tempbl &= 0x23;
2347 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
2348
2349 if (tempbh & 0x20) {
2350 temp = (tempbl >> 4) & 0x02;
2351
2352 /* CR B4[1] */
2353 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
2354
2355 }
2356
2357 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
2358
2359 temp = XG21GPIODataTransfer(temp);
2360 temp &= ~tempbh;
2361 temp |= tempbl;
2362 xgifb_reg_set(pVBInfo->P3d4, 0x48, temp);
2363}
2364
Aaro Koskinen776115a2011-11-27 23:03:10 +02002365static void XGI_XG27BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
2366 struct vb_device_info *pVBInfo)
2367{
2368 unsigned char CR4A, temp;
2369 unsigned short tempbh0, tempbl0;
2370
2371 tempbh0 = tempbh;
2372 tempbl0 = tempbl;
2373 tempbh0 &= 0x20;
2374 tempbl0 &= 0x20;
2375 tempbh0 >>= 3;
2376 tempbl0 >>= 3;
2377
2378 if (tempbh & 0x20) {
2379 temp = (tempbl >> 4) & 0x02;
2380
2381 /* CR B4[1] */
2382 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
2383
2384 }
2385 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~tempbh0, tempbl0);
2386
2387 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
2388 tempbh &= 0x03;
2389 tempbl &= 0x03;
2390 tempbh <<= 2;
2391 tempbl <<= 2; /* GPIOC,GPIOD */
2392 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
2393 xgifb_reg_and_or(pVBInfo->P3d4, 0x48, ~tempbh, tempbl);
2394}
2395
Aaro Koskinenfab04b92011-12-06 00:10:45 +02002396static void XGI_DisplayOn(struct xgifb_video_info *xgifb_info,
2397 struct xgi_hw_device_info *pXGIHWDE,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302398 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002399{
2400
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002401 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302402 if (pXGIHWDE->jChipType == XG21) {
2403 if (pVBInfo->IF_DEF_LVDS == 1) {
2404 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002405 /* LVDS VDD on */
2406 XGI_XG21BLSignalVDD(0x01, 0x01, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002407 mdelay(xgifb_info->lvds_data.PSC_S2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302408 }
2409 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002410 /* LVDS signal on */
2411 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002412 mdelay(xgifb_info->lvds_data.PSC_S3);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002413 /* LVDS backlight on */
2414 XGI_XG21BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302415 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002416 /* DVO/DVI signal on */
2417 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302418 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002419
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302420 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002421
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302422 if (pXGIHWDE->jChipType == XG27) {
2423 if (pVBInfo->IF_DEF_LVDS == 1) {
2424 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002425 /* LVDS VDD on */
2426 XGI_XG27BLSignalVDD(0x01, 0x01, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002427 mdelay(xgifb_info->lvds_data.PSC_S2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302428 }
2429 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002430 /* LVDS signal on */
2431 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002432 mdelay(xgifb_info->lvds_data.PSC_S3);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002433 /* LVDS backlight on */
2434 XGI_XG27BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302435 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002436 /* DVO/DVI signal on */
2437 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302438 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002439
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302440 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002441}
2442
Aaro Koskinenfab04b92011-12-06 00:10:45 +02002443void XGI_DisplayOff(struct xgifb_video_info *xgifb_info,
2444 struct xgi_hw_device_info *pXGIHWDE,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302445 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002446{
2447
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302448 if (pXGIHWDE->jChipType == XG21) {
2449 if (pVBInfo->IF_DEF_LVDS == 1) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002450 /* LVDS backlight off */
2451 XGI_XG21BLSignalVDD(0x02, 0x00, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002452 mdelay(xgifb_info->lvds_data.PSC_S3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302453 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002454 /* DVO/DVI signal off */
2455 XGI_XG21BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302456 }
2457 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002458
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302459 if (pXGIHWDE->jChipType == XG27) {
2460 if ((XGI_XG27GetPSCValue(pVBInfo) & 0x2)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002461 /* LVDS backlight off */
2462 XGI_XG27BLSignalVDD(0x02, 0x00, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002463 mdelay(xgifb_info->lvds_data.PSC_S3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302464 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002465
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302466 if (pVBInfo->IF_DEF_LVDS == 0)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002467 /* DVO/DVI signal off */
2468 XGI_XG27BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302469 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002470
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002471 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x20);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002472}
2473
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002474static void XGI_WaitDisply(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002475{
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02002476 while ((inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302477 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002478
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02002479 while (!(inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302480 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002481}
2482
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002483static void XGI_AutoThreshold(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002484{
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002485 xgifb_reg_or(pVBInfo->Part1Port, 0x01, 0x40);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002486}
2487
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002488static void XGI_SaveCRT2Info(unsigned short ModeNo,
2489 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002490{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302491 unsigned short temp1, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002492
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002493 /* reserve CR34 for CRT1 Mode No */
2494 xgifb_reg_set(pVBInfo->P3d4, 0x34, ModeNo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302495 temp1 = (pVBInfo->VBInfo & SetInSlaveMode) >> 8;
2496 temp2 = ~(SetInSlaveMode >> 8);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002497 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, temp2, temp1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002498}
2499
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002500static void XGI_GetCRT2ResInfo(unsigned short ModeNo,
2501 unsigned short ModeIdIndex,
2502 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002503{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302504 unsigned short xres, yres, modeflag, resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002505
Aaro Koskinenb3979922012-11-04 21:14:52 +02002506 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02002507 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
2508 yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002509 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002510 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002511
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002512 if (modeflag & HalfDCLK)
2513 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002514
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002515 if (modeflag & DoubleScanMode)
2516 yres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002517
Miguel Gómez3339db82012-07-06 12:40:49 +02002518 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
2519 goto exit;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002520
Aaro Koskinen22006832013-02-09 00:03:47 +02002521 if (pVBInfo->LCDResInfo == Panel_1600x1200) {
2522 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
2523 if (yres == 1024)
2524 yres = 1056;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302525 }
Aaro Koskinen22006832013-02-09 00:03:47 +02002526 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002527
Aaro Koskinen22006832013-02-09 00:03:47 +02002528 if (pVBInfo->LCDResInfo == Panel_1280x1024) {
2529 if (yres == 400)
2530 yres = 405;
2531 else if (yres == 350)
2532 yres = 360;
Miguel Gómez3339db82012-07-06 12:40:49 +02002533
Aaro Koskinen22006832013-02-09 00:03:47 +02002534 if (pVBInfo->LCDInfo & XGI_LCDVESATiming) {
2535 if (yres == 360)
2536 yres = 375;
Miguel Gómez3339db82012-07-06 12:40:49 +02002537 }
Aaro Koskinen22006832013-02-09 00:03:47 +02002538 }
Miguel Gómez3339db82012-07-06 12:40:49 +02002539
Aaro Koskinen22006832013-02-09 00:03:47 +02002540 if (pVBInfo->LCDResInfo == Panel_1024x768) {
2541 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
2542 if (!(pVBInfo->LCDInfo & LCDNonExpanding)) {
2543 if (yres == 350)
2544 yres = 357;
2545 else if (yres == 400)
2546 yres = 420;
2547 else if (yres == 480)
2548 yres = 525;
Miguel Gómez3339db82012-07-06 12:40:49 +02002549 }
2550 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302551 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002552
Miguel Gómez3339db82012-07-06 12:40:49 +02002553 if (xres == 720)
2554 xres = 640;
2555
2556exit:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302557 pVBInfo->VGAHDE = xres;
2558 pVBInfo->HDE = xres;
2559 pVBInfo->VGAVDE = yres;
2560 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002561}
2562
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002563static unsigned char XGI_IsLCDDualLink(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002564{
2565
Peter Huewea3d675c2012-02-09 21:11:47 +01002566 if ((pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) &&
Dan Carpentera65fd092011-01-04 09:02:27 +03002567 (pVBInfo->LCDInfo & SetLCDDualLink)) /* shampoo0129 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302568 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002569
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302570 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002571}
2572
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002573static void XGI_GetRAMDAC2DATA(unsigned short ModeNo,
2574 unsigned short ModeIdIndex,
2575 unsigned short RefreshRateTableIndex,
2576 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002577{
2578 unsigned short tempax, tempbx, temp1, temp2, modeflag = 0, tempcx,
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002579 CRT1Index;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002580
2581 pVBInfo->RVBHCMAX = 1;
2582 pVBInfo->RVBHCFACT = 1;
Aaro Koskinenb3979922012-11-04 21:14:52 +02002583 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02002584 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002585 CRT1Index &= IndexMask;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002586 temp1 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[0];
2587 temp2 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[5];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002588 tempax = (temp1 & 0xFF) | ((temp2 & 0x03) << 8);
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002589 tempbx = (unsigned short) XGI_CRT1Table[CRT1Index].CR[8];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002590 tempcx = (unsigned short)
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002591 XGI_CRT1Table[CRT1Index].CR[14] << 8;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002592 tempcx &= 0x0100;
2593 tempcx = tempcx << 2;
2594 tempbx |= tempcx;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002595 temp1 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[9];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002596
2597 if (temp1 & 0x01)
2598 tempbx |= 0x0100;
2599
2600 if (temp1 & 0x20)
2601 tempbx |= 0x0200;
2602 tempax += 5;
2603
2604 if (modeflag & Charx8Dot)
2605 tempax *= 8;
2606 else
2607 tempax *= 9;
2608
2609 pVBInfo->VGAHT = tempax;
2610 pVBInfo->HT = tempax;
2611 tempbx++;
2612 pVBInfo->VGAVT = tempbx;
2613 pVBInfo->VT = tempbx;
2614}
2615
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002616static void XGI_GetCRT2Data(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302617 unsigned short RefreshRateTableIndex,
2618 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002619{
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02002620 unsigned short tempax = 0, tempbx = 0, modeflag, resinfo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002621
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02002622 struct SiS_LCDData const *LCDPtr = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002623
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002624 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002625 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2626 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302627 pVBInfo->NewFlickerMode = 0;
2628 pVBInfo->RVBHRS = 50;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002629
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302630 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
2631 XGI_GetRAMDAC2DATA(ModeNo, ModeIdIndex, RefreshRateTableIndex,
2632 pVBInfo);
2633 return;
2634 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002635
Peter Huewea3d675c2012-02-09 21:11:47 +01002636 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02002637 LCDPtr = XGI_GetLcdPtr(XGI_LCDDataTable, ModeNo, ModeIdIndex,
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +03002638 RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002639
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302640 pVBInfo->RVBHCMAX = LCDPtr->RVBHCMAX;
2641 pVBInfo->RVBHCFACT = LCDPtr->RVBHCFACT;
2642 pVBInfo->VGAHT = LCDPtr->VGAHT;
2643 pVBInfo->VGAVT = LCDPtr->VGAVT;
2644 pVBInfo->HT = LCDPtr->LCDHT;
2645 pVBInfo->VT = LCDPtr->LCDVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002646
Peter Huewe255aabd2012-02-09 21:11:44 +01002647 if (pVBInfo->LCDResInfo == Panel_1024x768) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302648 tempax = 1024;
2649 tempbx = 768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002650
Peter Huewea3d675c2012-02-09 21:11:47 +01002651 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302652 if (pVBInfo->VGAVDE == 357)
2653 tempbx = 527;
2654 else if (pVBInfo->VGAVDE == 420)
2655 tempbx = 620;
2656 else if (pVBInfo->VGAVDE == 525)
2657 tempbx = 775;
2658 else if (pVBInfo->VGAVDE == 600)
2659 tempbx = 775;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302660 else
2661 tempbx = 768;
2662 } else
2663 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01002664 } else if (pVBInfo->LCDResInfo == Panel_1024x768x75) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302665 tempax = 1024;
2666 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01002667 } else if (pVBInfo->LCDResInfo == Panel_1280x1024) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302668 tempax = 1280;
2669 if (pVBInfo->VGAVDE == 360)
2670 tempbx = 768;
2671 else if (pVBInfo->VGAVDE == 375)
2672 tempbx = 800;
2673 else if (pVBInfo->VGAVDE == 405)
2674 tempbx = 864;
2675 else
2676 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01002677 } else if (pVBInfo->LCDResInfo == Panel_1280x1024x75) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302678 tempax = 1280;
2679 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01002680 } else if (pVBInfo->LCDResInfo == Panel_1280x960) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302681 tempax = 1280;
2682 if (pVBInfo->VGAVDE == 350)
2683 tempbx = 700;
2684 else if (pVBInfo->VGAVDE == 400)
2685 tempbx = 800;
2686 else if (pVBInfo->VGAVDE == 1024)
2687 tempbx = 960;
2688 else
2689 tempbx = 960;
Peter Huewe255aabd2012-02-09 21:11:44 +01002690 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302691 tempax = 1400;
2692 tempbx = 1050;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002693
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302694 if (pVBInfo->VGAVDE == 1024) {
2695 tempax = 1280;
2696 tempbx = 1024;
2697 }
Peter Huewe255aabd2012-02-09 21:11:44 +01002698 } else if (pVBInfo->LCDResInfo == Panel_1600x1200) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302699 tempax = 1600;
2700 tempbx = 1200; /* alan 10/14/2003 */
Peter Huewea3d675c2012-02-09 21:11:47 +01002701 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302702 if (pVBInfo->VGAVDE == 350)
2703 tempbx = 875;
2704 else if (pVBInfo->VGAVDE == 400)
2705 tempbx = 1000;
2706 }
2707 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002708
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302709 if (pVBInfo->LCDInfo & LCDNonExpanding) {
2710 tempax = pVBInfo->VGAHDE;
2711 tempbx = pVBInfo->VGAVDE;
2712 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002713
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302714 pVBInfo->HDE = tempax;
2715 pVBInfo->VDE = tempbx;
2716 return;
2717 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002718
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302719 if (pVBInfo->VBInfo & (SetCRT2ToTV)) {
Aaro Koskinen24572542012-09-11 00:15:21 +03002720 struct SiS_TVData const *TVPtr;
2721
2722 TVPtr = XGI_GetTVPtr(ModeNo, ModeIdIndex, RefreshRateTableIndex,
2723 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002724
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302725 pVBInfo->RVBHCMAX = TVPtr->RVBHCMAX;
2726 pVBInfo->RVBHCFACT = TVPtr->RVBHCFACT;
2727 pVBInfo->VGAHT = TVPtr->VGAHT;
2728 pVBInfo->VGAVT = TVPtr->VGAVT;
2729 pVBInfo->HDE = TVPtr->TVHDE;
2730 pVBInfo->VDE = TVPtr->TVVDE;
2731 pVBInfo->RVBHRS = TVPtr->RVBHRS;
2732 pVBInfo->NewFlickerMode = TVPtr->FlickerMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002733
Peter Huewe599801f2012-02-09 21:11:45 +01002734 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302735 if (resinfo == 0x08)
2736 pVBInfo->NewFlickerMode = 0x40;
2737 else if (resinfo == 0x09)
2738 pVBInfo->NewFlickerMode = 0x40;
2739 else if (resinfo == 0x12)
2740 pVBInfo->NewFlickerMode = 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002741
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302742 if (pVBInfo->VGAVDE == 350)
2743 pVBInfo->TVInfo |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002744
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302745 tempax = ExtHiTVHT;
2746 tempbx = ExtHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002747
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302748 if (pVBInfo->VBInfo & SetInSlaveMode) {
2749 if (pVBInfo->TVInfo & TVSimuMode) {
2750 tempax = StHiTVHT;
2751 tempbx = StHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002752
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302753 if (!(modeflag & Charx8Dot)) {
2754 tempax = StHiTextTVHT;
2755 tempbx = StHiTextTVVT;
2756 }
2757 }
2758 }
Peter Huewe599801f2012-02-09 21:11:45 +01002759 } else if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
2760 if (pVBInfo->TVInfo & TVSetYPbPr750p) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302761 tempax = YPbPrTV750pHT; /* Ext750pTVHT */
2762 tempbx = YPbPrTV750pVT; /* Ext750pTVVT */
2763 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002764
Peter Huewe599801f2012-02-09 21:11:45 +01002765 if (pVBInfo->TVInfo & TVSetYPbPr525p) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302766 tempax = YPbPrTV525pHT; /* Ext525pTVHT */
2767 tempbx = YPbPrTV525pVT; /* Ext525pTVVT */
Peter Huewe599801f2012-02-09 21:11:45 +01002768 } else if (pVBInfo->TVInfo & TVSetYPbPr525i) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302769 tempax = YPbPrTV525iHT; /* Ext525iTVHT */
2770 tempbx = YPbPrTV525iVT; /* Ext525iTVVT */
2771 if (pVBInfo->TVInfo & NTSC1024x768)
2772 tempax = NTSC1024x768HT;
2773 }
2774 } else {
2775 tempax = PALHT;
2776 tempbx = PALVT;
Peter Huewe599801f2012-02-09 21:11:45 +01002777 if (!(pVBInfo->TVInfo & TVSetPAL)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302778 tempax = NTSCHT;
2779 tempbx = NTSCVT;
2780 if (pVBInfo->TVInfo & NTSC1024x768)
2781 tempax = NTSC1024x768HT;
2782 }
2783 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002784
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302785 pVBInfo->HT = tempax;
2786 pVBInfo->VT = tempbx;
2787 return;
2788 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002789}
2790
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002791static void XGI_SetCRT2VCLK(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302792 unsigned short RefreshRateTableIndex,
2793 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002794{
Bill Pemberton108afbf2010-06-17 13:10:47 -04002795 unsigned char di_0, di_1, tempal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002796
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302797 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
2798 pVBInfo);
2799 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
2800 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002801
Peter Huewe6896b942012-02-09 21:11:46 +01002802 if (pVBInfo->VBType & VB_SIS301) { /* shampoo 0129 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302803 /* 301 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002804 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, 0x10);
2805 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
2806 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302807 } else { /* 301b/302b/301lv/302lv */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002808 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
2809 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302810 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002811
Aaro Koskinen8104e322011-03-13 12:26:22 +02002812 xgifb_reg_set(pVBInfo->Part4Port, 0x00, 0x12);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002813
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302814 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02002815 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x28);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302816 else
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02002817 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002818}
2819
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002820static unsigned short XGI_GetColorDepth(unsigned short ModeNo,
2821 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002822{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002823 unsigned short ColorDepth[6] = { 1, 2, 4, 4, 6, 8 };
2824 short index;
2825 unsigned short modeflag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302826
Aaro Koskinenb3979922012-11-04 21:14:52 +02002827 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Peter Huewe6896b942012-02-09 21:11:46 +01002828 index = (modeflag & ModeTypeMask) - ModeEGA;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302829
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002830 if (index < 0)
2831 index = 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302832
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002833 return ColorDepth[index];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302834}
2835
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002836static unsigned short XGI_GetOffset(unsigned short ModeNo,
2837 unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302838 unsigned short RefreshRateTableIndex,
2839 struct xgi_hw_device_info *HwDeviceExtension,
2840 struct vb_device_info *pVBInfo)
2841{
2842 unsigned short temp, colordepth, modeinfo, index, infoflag,
2843 ColorDepth[] = { 0x01, 0x02, 0x04 };
2844
Aaro Koskinenb3979922012-11-04 21:14:52 +02002845 modeinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeInfo;
Aaro Koskinena39325d2012-11-04 21:14:53 +02002846 infoflag = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302847
2848 index = (modeinfo >> 8) & 0xFF;
2849
Aaro Koskinen224114c2012-11-04 21:14:59 +02002850 temp = XGI330_ScreenOffset[index];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302851
2852 if (infoflag & InterlaceMode)
2853 temp = temp << 1;
2854
2855 colordepth = XGI_GetColorDepth(ModeNo, ModeIdIndex, pVBInfo);
2856
2857 if ((ModeNo >= 0x7C) && (ModeNo <= 0x7E)) {
2858 temp = ModeNo - 0x7C;
2859 colordepth = ColorDepth[temp];
2860 temp = 0x6B;
2861 if (infoflag & InterlaceMode)
2862 temp = temp << 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302863 }
Peter Huewe053004b2013-02-15 20:37:12 +01002864 return temp * colordepth;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302865}
2866
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002867static void XGI_SetCRT2Offset(unsigned short ModeNo,
2868 unsigned short ModeIdIndex,
2869 unsigned short RefreshRateTableIndex,
2870 struct xgi_hw_device_info *HwDeviceExtension,
2871 struct vb_device_info *pVBInfo)
2872{
2873 unsigned short offset;
2874 unsigned char temp;
2875
2876 if (pVBInfo->VBInfo & SetInSlaveMode)
2877 return;
2878
2879 offset = XGI_GetOffset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
2880 HwDeviceExtension, pVBInfo);
2881 temp = (unsigned char) (offset & 0xFF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002882 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002883 temp = (unsigned char) ((offset & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002884 xgifb_reg_set(pVBInfo->Part1Port, 0x09, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002885 temp = (unsigned char) (((offset >> 3) & 0xFF) + 1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002886 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002887}
2888
Randy Dunlap89229672010-08-10 08:46:44 -07002889static void XGI_SetCRT2FIFO(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002890{
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002891 /* threshold high ,disable auto threshold */
2892 xgifb_reg_set(pVBInfo->Part1Port, 0x01, 0x3B);
2893 /* threshold low default 04h */
2894 xgifb_reg_and_or(pVBInfo->Part1Port, 0x02, ~(0x3F), 0x04);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002895}
2896
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002897static void XGI_PreSetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302898 struct xgi_hw_device_info *HwDeviceExtension,
2899 unsigned short RefreshRateTableIndex,
2900 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002901{
Peter Hueweef9a6b92013-02-03 04:08:43 +01002902 u8 tempcx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002903
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302904 XGI_SetCRT2Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
2905 HwDeviceExtension, pVBInfo);
2906 XGI_SetCRT2FIFO(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002907
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302908 for (tempcx = 4; tempcx < 7; tempcx++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02002909 xgifb_reg_set(pVBInfo->Part1Port, tempcx, 0x0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002910
Aaro Koskinen8104e322011-03-13 12:26:22 +02002911 xgifb_reg_set(pVBInfo->Part1Port, 0x50, 0x00);
2912 xgifb_reg_set(pVBInfo->Part1Port, 0x02, 0x44); /* temp 0206 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002913}
2914
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002915static void XGI_SetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302916 struct xgi_hw_device_info *HwDeviceExtension,
2917 unsigned short RefreshRateTableIndex,
2918 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002919{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302920 unsigned short temp = 0, tempax = 0, tempbx = 0, tempcx = 0,
Peter Hueweef9a6b92013-02-03 04:08:43 +01002921 pushbx = 0, CRT1Index, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002922
Aaro Koskinena39325d2012-11-04 21:14:53 +02002923 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002924 CRT1Index &= IndexMask;
Aaro Koskinenb3979922012-11-04 21:14:52 +02002925 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002926
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302927 /* bainy change table name */
2928 if (modeflag & HalfDCLK) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002929 /* BTVGA2HT 0x08,0x09 */
2930 temp = (pVBInfo->VGAHT / 2 - 1) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002931 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302932 temp = (((pVBInfo->VGAHT / 2 - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002933 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002934 /* BTVGA2HDEE 0x0A,0x0C */
2935 temp = (pVBInfo->VGAHDE / 2 + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002936 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302937 tempcx = ((pVBInfo->VGAHT - pVBInfo->VGAHDE) / 2) >> 2;
2938 pushbx = pVBInfo->VGAHDE / 2 + 16;
2939 tempcx = tempcx >> 1;
2940 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
2941 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002942
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302943 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002944 tempbx = XGI_CRT1Table[CRT1Index].CR[4];
2945 tempbx |= ((XGI_CRT1Table[CRT1Index].CR[14] &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002946 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302947 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002948 tempcx = XGI_CRT1Table[CRT1Index].CR[5];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302949 tempcx &= 0x1F;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002950 temp = XGI_CRT1Table[CRT1Index].CR[15];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302951 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
2952 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
2953 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002954
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302955 tempbx += 4;
2956 tempcx += 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002957
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302958 if (tempcx > (pVBInfo->VGAHT / 2))
2959 tempcx = pVBInfo->VGAHT / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002960
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302961 temp = tempbx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002962
Aaro Koskinen8104e322011-03-13 12:26:22 +02002963 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302964 } else {
2965 temp = (pVBInfo->VGAHT - 1) & 0x0FF; /* BTVGA2HT 0x08,0x09 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002966 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302967 temp = (((pVBInfo->VGAHT - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002968 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002969 /* BTVGA2HDEE 0x0A,0x0C */
2970 temp = (pVBInfo->VGAHDE + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002971 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302972 tempcx = (pVBInfo->VGAHT - pVBInfo->VGAHDE) >> 2; /* cx */
2973 pushbx = pVBInfo->VGAHDE + 16;
2974 tempcx = tempcx >> 1;
2975 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
2976 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002977
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302978 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002979 tempbx = XGI_CRT1Table[CRT1Index].CR[3];
2980 tempbx |= ((XGI_CRT1Table[CRT1Index].CR[5] &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002981 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302982 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002983 tempcx = XGI_CRT1Table[CRT1Index].CR[4];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302984 tempcx &= 0x1F;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002985 temp = XGI_CRT1Table[CRT1Index].CR[6];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302986 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
2987 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
2988 tempbx += 16;
2989 tempcx += 16;
2990 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002991
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302992 if (tempcx > pVBInfo->VGAHT)
2993 tempcx = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002994
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302995 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002996 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302997 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002998
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302999 tempax = (tempax & 0x00FF) | (tempbx & 0xFF00);
3000 tempbx = pushbx;
3001 tempbx = (tempbx & 0x00FF) | ((tempbx & 0xFF00) << 4);
3002 tempax |= (tempbx & 0xFF00);
3003 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003004 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303005 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003006 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303007 tempcx = (pVBInfo->VGAVT - 1);
3008 temp = tempcx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003009
Aaro Koskinen8104e322011-03-13 12:26:22 +02003010 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303011 tempbx = pVBInfo->VGAVDE - 1;
3012 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003013 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303014 temp = ((tempbx & 0xFF00) << 3) >> 8;
3015 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003016 xgifb_reg_set(pVBInfo->Part1Port, 0x12, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003017
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303018 tempax = pVBInfo->VGAVDE;
3019 tempbx = pVBInfo->VGAVDE;
3020 tempcx = pVBInfo->VGAVT;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003021 /* BTVGA2VRS 0x10,0x11 */
3022 tempbx = (pVBInfo->VGAVT + pVBInfo->VGAVDE) >> 1;
3023 /* BTVGA2VRE 0x11 */
3024 tempcx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) >> 4) + tempbx + 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003025
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303026 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003027 tempbx = XGI_CRT1Table[CRT1Index].CR[10];
3028 temp = XGI_CRT1Table[CRT1Index].CR[9];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003029
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303030 if (temp & 0x04)
3031 tempbx |= 0x0100;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003032
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303033 if (temp & 0x080)
3034 tempbx |= 0x0200;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003035
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003036 temp = XGI_CRT1Table[CRT1Index].CR[14];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003037
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303038 if (temp & 0x08)
3039 tempbx |= 0x0400;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003040
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003041 temp = XGI_CRT1Table[CRT1Index].CR[11];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303042 tempcx = (tempcx & 0xFF00) | (temp & 0x00FF);
3043 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003044
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303045 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003046 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303047 temp = ((tempbx & 0xFF00) >> 8) << 4;
3048 temp = ((tempcx & 0x000F) | (temp));
Aaro Koskinen8104e322011-03-13 12:26:22 +02003049 xgifb_reg_set(pVBInfo->Part1Port, 0x11, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303050 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003051
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303052 if (modeflag & DoubleScanMode)
3053 tempax |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003054
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303055 if (modeflag & HalfDCLK)
3056 tempax |= 0x40;
3057
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003058 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2C, ~0x0C0, tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003059}
3060
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003061static unsigned short XGI_GetVGAHT2(struct vb_device_info *pVBInfo)
3062{
3063 unsigned long tempax, tempbx;
3064
3065 tempbx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) * pVBInfo->RVBHCMAX)
3066 & 0xFFFF;
3067 tempax = (pVBInfo->VT - pVBInfo->VDE) * pVBInfo->RVBHCFACT;
3068 tempax = (tempax * pVBInfo->HT) / tempbx;
3069
3070 return (unsigned short) tempax;
3071}
3072
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003073static void XGI_SetLockRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303074 struct xgi_hw_device_info *HwDeviceExtension,
3075 unsigned short RefreshRateTableIndex,
3076 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003077{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303078 unsigned short push1, push2, tempax, tempbx = 0, tempcx, temp, resinfo,
Peter Hueweef9a6b92013-02-03 04:08:43 +01003079 modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003080
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003081 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02003082 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3083 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003084
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303085 if (!(pVBInfo->VBInfo & SetInSlaveMode))
3086 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003087
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303088 temp = 0xFF; /* set MAX HT */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003089 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303090 tempcx = 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003091
Peter Huewe6896b942012-02-09 21:11:46 +01003092 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303093 modeflag |= Charx8Dot;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003094
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303095 tempax = pVBInfo->VGAHDE; /* 0x04 Horizontal Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003096
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303097 if (modeflag & HalfDCLK)
3098 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003099
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303100 tempax = (tempax / tempcx) - 1;
3101 tempbx |= ((tempax & 0x00FF) << 8);
3102 temp = tempax & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003103 xgifb_reg_set(pVBInfo->Part1Port, 0x04, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003104
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303105 temp = (tempbx & 0xFF00) >> 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003106
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303107 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Peter Huewe6896b942012-02-09 21:11:46 +01003108 if (!(pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3109 | VB_SIS302LV | VB_XGI301C)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303110 temp += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003111
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03003112 if ((pVBInfo->VBInfo & SetCRT2ToHiVision) &&
3113 !(pVBInfo->VBType & VB_SIS301LV) && (resinfo == 7))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303114 temp -= 2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303115 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003116
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003117 /* 0x05 Horizontal Display Start */
3118 xgifb_reg_set(pVBInfo->Part1Port, 0x05, temp);
3119 /* 0x06 Horizontal Blank end */
3120 xgifb_reg_set(pVBInfo->Part1Port, 0x06, 0x03);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003121
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303122 if (!(pVBInfo->VBInfo & DisableCRT2Display)) { /* 030226 bainy */
3123 if (pVBInfo->VBInfo & SetCRT2ToTV)
3124 tempax = pVBInfo->VGAHT;
3125 else
3126 tempax = XGI_GetVGAHT2(pVBInfo);
3127 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003128
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303129 if (tempax >= pVBInfo->VGAHT)
3130 tempax = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003131
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303132 if (modeflag & HalfDCLK)
3133 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003134
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303135 tempax = (tempax / tempcx) - 5;
3136 tempcx = tempax; /* 20030401 0x07 horizontal Retrace Start */
Peter Huewe599801f2012-02-09 21:11:45 +01003137 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303138 temp = (tempbx & 0x00FF) - 1;
3139 if (!(modeflag & HalfDCLK)) {
3140 temp -= 6;
3141 if (pVBInfo->TVInfo & TVSimuMode) {
3142 temp -= 4;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003143 temp -= 10;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303144 }
3145 }
3146 } else {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303147 tempbx = (tempbx & 0xFF00) >> 8;
3148 tempcx = (tempcx + tempbx) >> 1;
3149 temp = (tempcx & 0x00FF) + 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003150
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303151 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3152 temp -= 1;
3153 if (!(modeflag & HalfDCLK)) {
3154 if ((modeflag & Charx8Dot)) {
3155 temp += 4;
3156 if (pVBInfo->VGAHDE >= 800)
3157 temp -= 6;
3158 }
3159 }
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003160 } else if (!(modeflag & HalfDCLK)) {
3161 temp -= 4;
Peter Huewe255aabd2012-02-09 21:11:44 +01003162 if (pVBInfo->LCDResInfo != Panel_1280x960 &&
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003163 pVBInfo->VGAHDE >= 800) {
3164 temp -= 7;
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003165 if (pVBInfo->VGAHDE >= 1280 &&
Peter Huewe255aabd2012-02-09 21:11:44 +01003166 pVBInfo->LCDResInfo != Panel_1280x960 &&
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003167 (pVBInfo->LCDInfo & LCDNonExpanding))
3168 temp += 28;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303169 }
3170 }
3171 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003172
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003173 /* 0x07 Horizontal Retrace Start */
3174 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
3175 /* 0x08 Horizontal Retrace End */
3176 xgifb_reg_set(pVBInfo->Part1Port, 0x08, 0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003177
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303178 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3179 if (pVBInfo->TVInfo & TVSimuMode) {
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003180 if (ModeNo == 0x50) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303181 if (pVBInfo->TVInfo & SetNTSCTV) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003182 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303183 0x07, 0x30);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003184 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303185 0x08, 0x03);
3186 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003187 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303188 0x07, 0x2f);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003189 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303190 0x08, 0x02);
3191 }
3192 }
3193 }
3194 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003195
Aaro Koskinen8104e322011-03-13 12:26:22 +02003196 xgifb_reg_set(pVBInfo->Part1Port, 0x18, 0x03); /* 0x18 SR0B */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003197 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0xF0, 0x00);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003198 xgifb_reg_set(pVBInfo->Part1Port, 0x09, 0xFF); /* 0x09 Set Max VT */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003199
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303200 tempbx = pVBInfo->VGAVT;
3201 push1 = tempbx;
3202 tempcx = 0x121;
3203 tempbx = pVBInfo->VGAVDE; /* 0x0E Virtical Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003204
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303205 if (tempbx == 357)
3206 tempbx = 350;
3207 if (tempbx == 360)
3208 tempbx = 350;
3209 if (tempbx == 375)
3210 tempbx = 350;
3211 if (tempbx == 405)
3212 tempbx = 400;
3213 if (tempbx == 525)
3214 tempbx = 480;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003215
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303216 push2 = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003217
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303218 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
Peter Huewe255aabd2012-02-09 21:11:44 +01003219 if (pVBInfo->LCDResInfo == Panel_1024x768) {
Peter Huewea3d675c2012-02-09 21:11:47 +01003220 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303221 if (tempbx == 350)
3222 tempbx += 5;
3223 if (tempbx == 480)
3224 tempbx += 5;
3225 }
3226 }
3227 }
3228 tempbx--;
3229 temp = tempbx & 0x00FF;
3230 tempbx--;
3231 temp = tempbx & 0x00FF;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003232 /* 0x10 vertical Blank Start */
3233 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303234 tempbx = push2;
3235 tempbx--;
3236 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003237 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003238
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303239 if (tempbx & 0x0100)
3240 tempcx |= 0x0002;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003241
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303242 tempax = 0x000B;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003243
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303244 if (modeflag & DoubleScanMode)
3245 tempax |= 0x08000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003246
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303247 if (tempbx & 0x0200)
3248 tempcx |= 0x0040;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003249
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303250 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003251 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003252
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303253 if (tempbx & 0x0400)
3254 tempcx |= 0x0600;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003255
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003256 /* 0x11 Vertival Blank End */
3257 xgifb_reg_set(pVBInfo->Part1Port, 0x11, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303258
3259 tempax = push1;
3260 tempax -= tempbx; /* 0x0C Vertical Retrace Start */
3261 tempax = tempax >> 2;
3262 push1 = tempax; /* push ax */
3263
3264 if (resinfo != 0x09) {
3265 tempax = tempax << 1;
3266 tempbx += tempax;
3267 }
3268
Peter Huewe599801f2012-02-09 21:11:45 +01003269 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Miguel Gómez470c5332012-07-06 12:40:50 +02003270 if ((pVBInfo->VBType & VB_SIS301LV) &&
3271 !(pVBInfo->TVInfo & TVSetHiVision)) {
3272 if ((pVBInfo->TVInfo & TVSimuMode) &&
3273 (pVBInfo->TVInfo & TVSetPAL)) {
3274 if (!(pVBInfo->VBType & VB_SIS301LV) ||
3275 !(pVBInfo->TVInfo &
3276 (TVSetYPbPr525p |
3277 TVSetYPbPr750p |
3278 TVSetHiVision)))
3279 tempbx += 40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303280 }
3281 } else {
3282 tempbx -= 10;
3283 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003284 } else if (pVBInfo->TVInfo & TVSimuMode) {
3285 if (pVBInfo->TVInfo & TVSetPAL) {
3286 if (pVBInfo->VBType & VB_SIS301LV) {
3287 if (!(pVBInfo->TVInfo &
3288 (TVSetYPbPr525p |
3289 TVSetYPbPr750p |
3290 TVSetHiVision)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303291 tempbx += 40;
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003292 } else {
3293 tempbx += 40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303294 }
3295 }
3296 }
3297 tempax = push1;
3298 tempax = tempax >> 2;
3299 tempax++;
3300 tempax += tempbx;
3301 push1 = tempax; /* push ax */
3302
Peter Huewe599801f2012-02-09 21:11:45 +01003303 if ((pVBInfo->TVInfo & TVSetPAL)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303304 if (tempbx <= 513) {
3305 if (tempax >= 513)
3306 tempbx = 513;
3307 }
3308 }
3309
3310 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003311 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303312 tempbx--;
3313 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003314 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303315
3316 if (tempbx & 0x0100)
3317 tempcx |= 0x0008;
3318
3319 if (tempbx & 0x0200)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003320 xgifb_reg_and_or(pVBInfo->Part1Port, 0x0B, 0x0FF, 0x20);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303321
3322 tempbx++;
3323
3324 if (tempbx & 0x0100)
3325 tempcx |= 0x0004;
3326
3327 if (tempbx & 0x0200)
3328 tempcx |= 0x0080;
3329
3330 if (tempbx & 0x0400)
3331 tempcx |= 0x0C00;
3332
3333 tempbx = push1; /* pop ax */
3334 temp = tempbx & 0x00FF;
3335 temp &= 0x0F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003336 /* 0x0D vertical Retrace End */
3337 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303338
3339 if (tempbx & 0x0010)
3340 tempcx |= 0x2000;
3341
3342 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003343 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp); /* 0x0A CR07 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303344 temp = (tempcx & 0x0FF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003345 xgifb_reg_set(pVBInfo->Part1Port, 0x17, temp); /* 0x17 SR0A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303346 tempax = modeflag;
3347 temp = (tempax & 0xFF00) >> 8;
3348
3349 temp = (temp >> 1) & 0x09;
3350
Peter Huewe6896b942012-02-09 21:11:46 +01003351 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303352 temp |= 0x01;
3353
Aaro Koskinen8104e322011-03-13 12:26:22 +02003354 xgifb_reg_set(pVBInfo->Part1Port, 0x16, temp); /* 0x16 SR01 */
3355 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, 0); /* 0x0F CR14 */
3356 xgifb_reg_set(pVBInfo->Part1Port, 0x12, 0); /* 0x12 CR17 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303357
3358 if (pVBInfo->LCDInfo & LCDRGB18Bit)
3359 temp = 0x80;
3360 else
3361 temp = 0x00;
3362
Aaro Koskinen8104e322011-03-13 12:26:22 +02003363 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, temp); /* 0x1A SR0E */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303364
3365 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003366}
3367
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003368static void XGI_SetGroup2(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303369 unsigned short RefreshRateTableIndex,
3370 struct xgi_hw_device_info *HwDeviceExtension,
3371 struct vb_device_info *pVBInfo)
3372{
3373 unsigned short i, j, tempax, tempbx, tempcx, temp, push1, push2,
Peter Hueweef9a6b92013-02-03 04:08:43 +01003374 modeflag;
Aaro Koskinend21222d2012-09-11 00:15:29 +03003375 unsigned char const *TimingPoint;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303376
3377 unsigned long longtemp, tempeax, tempebx, temp2, tempecx;
3378
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003379 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02003380 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303381
3382 tempax = 0;
3383
3384 if (!(pVBInfo->VBInfo & SetCRT2ToAVIDEO))
3385 tempax |= 0x0800;
3386
3387 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3388 tempax |= 0x0400;
3389
3390 if (pVBInfo->VBInfo & SetCRT2ToSCART)
3391 tempax |= 0x0200;
3392
Peter Huewe599801f2012-02-09 21:11:45 +01003393 if (!(pVBInfo->TVInfo & TVSetPAL))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303394 tempax |= 0x1000;
3395
Peter Huewe599801f2012-02-09 21:11:45 +01003396 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303397 tempax |= 0x0100;
3398
Peter Huewe599801f2012-02-09 21:11:45 +01003399 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303400 tempax &= 0xfe00;
3401
3402 tempax = (tempax & 0xff00) >> 8;
3403
Aaro Koskinen8104e322011-03-13 12:26:22 +02003404 xgifb_reg_set(pVBInfo->Part2Port, 0x0, tempax);
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003405 TimingPoint = XGI330_NTSCTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303406
Peter Huewe599801f2012-02-09 21:11:45 +01003407 if (pVBInfo->TVInfo & TVSetPAL)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003408 TimingPoint = XGI330_PALTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303409
Peter Huewe599801f2012-02-09 21:11:45 +01003410 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003411 TimingPoint = XGI330_HiTVExtTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303412
3413 if (pVBInfo->VBInfo & SetInSlaveMode)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003414 TimingPoint = XGI330_HiTVSt2Timing;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303415
3416 if (pVBInfo->SetFlag & TVSimuMode)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003417 TimingPoint = XGI330_HiTVSt1Timing;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303418
3419 if (!(modeflag & Charx8Dot))
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003420 TimingPoint = XGI330_HiTVTextTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303421 }
3422
Peter Huewe599801f2012-02-09 21:11:45 +01003423 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
3424 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003425 TimingPoint = XGI330_YPbPr525iTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303426
Peter Huewe599801f2012-02-09 21:11:45 +01003427 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003428 TimingPoint = XGI330_YPbPr525pTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303429
Peter Huewe599801f2012-02-09 21:11:45 +01003430 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003431 TimingPoint = XGI330_YPbPr750pTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303432 }
3433
3434 for (i = 0x01, j = 0; i <= 0x2D; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02003435 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303436
3437 for (i = 0x39; i <= 0x45; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003438 /* di->temp2[j] */
3439 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303440
3441 if (pVBInfo->VBInfo & SetCRT2ToTV)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003442 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303443
3444 temp = pVBInfo->NewFlickerMode;
3445 temp &= 0x80;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003446 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xFF, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303447
Peter Huewe599801f2012-02-09 21:11:45 +01003448 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303449 tempax = 950;
3450
Peter Huewe599801f2012-02-09 21:11:45 +01003451 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303452 tempax = 520;
3453 else
3454 tempax = 440;
3455
3456 if (pVBInfo->VDE <= tempax) {
3457 tempax -= pVBInfo->VDE;
3458 tempax = tempax >> 2;
3459 tempax = (tempax & 0x00FF) | ((tempax & 0x00FF) << 8);
3460 push1 = tempax;
3461 temp = (tempax & 0xFF00) >> 8;
3462 temp += (unsigned short) TimingPoint[0];
3463
Peter Huewe6896b942012-02-09 21:11:46 +01003464 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3465 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303466 if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO
3467 | SetCRT2ToSVIDEO | SetCRT2ToSCART
Peter Huewe599801f2012-02-09 21:11:45 +01003468 | SetCRT2ToYPbPr525750)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303469 tempcx = pVBInfo->VGAHDE;
3470 if (tempcx >= 1024) {
3471 temp = 0x17; /* NTSC */
Peter Huewe599801f2012-02-09 21:11:45 +01003472 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303473 temp = 0x19; /* PAL */
3474 }
3475 }
3476 }
3477
Aaro Koskinen8104e322011-03-13 12:26:22 +02003478 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303479 tempax = push1;
3480 temp = (tempax & 0xFF00) >> 8;
3481 temp += TimingPoint[1];
3482
Peter Huewe6896b942012-02-09 21:11:46 +01003483 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3484 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303485 if ((pVBInfo->VBInfo & (SetCRT2ToAVIDEO
3486 | SetCRT2ToSVIDEO | SetCRT2ToSCART
Peter Huewe599801f2012-02-09 21:11:45 +01003487 | SetCRT2ToYPbPr525750))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303488 tempcx = pVBInfo->VGAHDE;
3489 if (tempcx >= 1024) {
3490 temp = 0x1D; /* NTSC */
Peter Huewe599801f2012-02-09 21:11:45 +01003491 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303492 temp = 0x52; /* PAL */
3493 }
3494 }
3495 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02003496 xgifb_reg_set(pVBInfo->Part2Port, 0x02, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303497 }
3498
3499 /* 301b */
3500 tempcx = pVBInfo->HT;
3501
3502 if (XGI_IsLCDDualLink(pVBInfo))
3503 tempcx = tempcx >> 1;
3504
3505 tempcx -= 2;
3506 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003507 xgifb_reg_set(pVBInfo->Part2Port, 0x1B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303508
3509 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003510 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303511
3512 tempcx = pVBInfo->HT >> 1;
3513 push1 = tempcx; /* push cx */
3514 tempcx += 7;
3515
Peter Huewe599801f2012-02-09 21:11:45 +01003516 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303517 tempcx -= 4;
3518
3519 temp = tempcx & 0x00FF;
3520 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003521 xgifb_reg_and_or(pVBInfo->Part2Port, 0x22, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303522
3523 tempbx = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
3524 tempbx += tempcx;
3525 push2 = tempbx;
3526 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003527 xgifb_reg_set(pVBInfo->Part2Port, 0x24, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303528 temp = (tempbx & 0xFF00) >> 8;
3529 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003530 xgifb_reg_and_or(pVBInfo->Part2Port, 0x25, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303531
3532 tempbx = push2;
3533 tempbx = tempbx + 8;
Peter Huewe599801f2012-02-09 21:11:45 +01003534 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303535 tempbx = tempbx - 4;
3536 tempcx = tempbx;
3537 }
3538
3539 temp = (tempbx & 0x00FF) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003540 xgifb_reg_and_or(pVBInfo->Part2Port, 0x29, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303541
3542 j += 2;
3543 tempcx += (TimingPoint[j] | ((TimingPoint[j + 1]) << 8));
3544 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003545 xgifb_reg_set(pVBInfo->Part2Port, 0x27, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303546 temp = ((tempcx & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003547 xgifb_reg_and_or(pVBInfo->Part2Port, 0x28, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303548
3549 tempcx += 8;
Peter Huewe599801f2012-02-09 21:11:45 +01003550 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303551 tempcx -= 4;
3552
3553 temp = tempcx & 0xFF;
3554 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003555 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2A, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303556
3557 tempcx = push1; /* pop cx */
3558 j += 2;
3559 temp = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
3560 tempcx -= temp;
3561 temp = tempcx & 0x00FF;
3562 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003563 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2D, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303564
3565 tempcx -= 11;
3566
3567 if (!(pVBInfo->VBInfo & SetCRT2ToTV)) {
3568 tempax = XGI_GetVGAHT2(pVBInfo);
3569 tempcx = tempax - 1;
3570 }
3571 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003572 xgifb_reg_set(pVBInfo->Part2Port, 0x2E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303573
3574 tempbx = pVBInfo->VDE;
3575
3576 if (pVBInfo->VGAVDE == 360)
3577 tempbx = 746;
3578 if (pVBInfo->VGAVDE == 375)
3579 tempbx = 746;
3580 if (pVBInfo->VGAVDE == 405)
3581 tempbx = 853;
3582
3583 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003584 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01003585 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003586 if (!(pVBInfo->TVInfo &
Peter Huewe599801f2012-02-09 21:11:45 +01003587 (TVSetYPbPr525p | TVSetYPbPr750p)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303588 tempbx = tempbx >> 1;
3589 } else
3590 tempbx = tempbx >> 1;
3591 }
3592
3593 tempbx -= 2;
3594 temp = tempbx & 0x00FF;
3595
Peter Huewe599801f2012-02-09 21:11:45 +01003596 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Huewe6896b942012-02-09 21:11:46 +01003597 if (pVBInfo->VBType & VB_SIS301LV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003598 if (pVBInfo->TVInfo & TVSetHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303599 if (pVBInfo->VBInfo & SetInSlaveMode) {
3600 if (ModeNo == 0x2f)
3601 temp += 1;
3602 }
3603 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003604 } else if (pVBInfo->VBInfo & SetInSlaveMode) {
3605 if (ModeNo == 0x2f)
3606 temp += 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303607 }
3608 }
3609
Aaro Koskinen8104e322011-03-13 12:26:22 +02003610 xgifb_reg_set(pVBInfo->Part2Port, 0x2F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303611
3612 temp = (tempcx & 0xFF00) >> 8;
3613 temp |= ((tempbx & 0xFF00) >> 8) << 6;
3614
Peter Huewe599801f2012-02-09 21:11:45 +01003615 if (!(pVBInfo->VBInfo & SetCRT2ToHiVision)) {
Peter Huewe6896b942012-02-09 21:11:46 +01003616 if (pVBInfo->VBType & VB_SIS301LV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003617 if (pVBInfo->TVInfo & TVSetHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303618 temp |= 0x10;
3619
3620 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3621 temp |= 0x20;
3622 }
3623 } else {
3624 temp |= 0x10;
3625 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3626 temp |= 0x20;
3627 }
3628 }
3629
Aaro Koskinen8104e322011-03-13 12:26:22 +02003630 xgifb_reg_set(pVBInfo->Part2Port, 0x30, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303631
Peter Huewe6896b942012-02-09 21:11:46 +01003632 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3633 | VB_SIS302LV | VB_XGI301C)) { /* TV gatingno */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303634 tempbx = pVBInfo->VDE;
3635 tempcx = tempbx - 2;
3636
3637 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003638 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p
3639 | TVSetYPbPr750p)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303640 tempbx = tempbx >> 1;
3641 }
3642
Peter Huewe6896b942012-02-09 21:11:46 +01003643 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303644 temp = 0;
3645 if (tempcx & 0x0400)
3646 temp |= 0x20;
3647
3648 if (tempbx & 0x0400)
3649 temp |= 0x40;
3650
Aaro Koskinen8104e322011-03-13 12:26:22 +02003651 xgifb_reg_set(pVBInfo->Part4Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303652 }
3653
3654 temp = (((tempbx - 3) & 0x0300) >> 8) << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003655 xgifb_reg_set(pVBInfo->Part2Port, 0x46, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303656 temp = (tempbx - 3) & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003657 xgifb_reg_set(pVBInfo->Part2Port, 0x47, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303658 }
3659
3660 tempbx = tempbx & 0x00FF;
3661
3662 if (!(modeflag & HalfDCLK)) {
3663 tempcx = pVBInfo->VGAHDE;
3664 if (tempcx >= pVBInfo->HDE) {
3665 tempbx |= 0x2000;
3666 tempax &= 0x00FF;
3667 }
3668 }
3669
3670 tempcx = 0x0101;
3671
3672 if (pVBInfo->VBInfo & SetCRT2ToTV) { /*301b*/
3673 if (pVBInfo->VGAHDE >= 1024) {
3674 tempcx = 0x1920;
3675 if (pVBInfo->VGAHDE >= 1280) {
3676 tempcx = 0x1420;
3677 tempbx = tempbx & 0xDFFF;
3678 }
3679 }
3680 }
3681
3682 if (!(tempbx & 0x2000)) {
3683 if (modeflag & HalfDCLK)
3684 tempcx = (tempcx & 0xFF00) | ((tempcx & 0x00FF) << 1);
3685
3686 push1 = tempbx;
3687 tempeax = pVBInfo->VGAHDE;
3688 tempebx = (tempcx & 0xFF00) >> 8;
3689 longtemp = tempeax * tempebx;
3690 tempecx = tempcx & 0x00FF;
3691 longtemp = longtemp / tempecx;
3692
3693 /* 301b */
3694 tempecx = 8 * 1024;
3695
Peter Huewe6896b942012-02-09 21:11:46 +01003696 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3697 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303698 tempecx = tempecx * 8;
3699 }
3700
3701 longtemp = longtemp * tempecx;
3702 tempecx = pVBInfo->HDE;
3703 temp2 = longtemp % tempecx;
3704 tempeax = longtemp / tempecx;
3705 if (temp2 != 0)
3706 tempeax += 1;
3707
3708 tempax = (unsigned short) tempeax;
3709
3710 /* 301b */
Peter Huewe6896b942012-02-09 21:11:46 +01003711 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3712 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303713 tempcx = ((tempax & 0xFF00) >> 5) >> 8;
3714 }
3715 /* end 301b */
3716
3717 tempbx = push1;
3718 tempbx = (unsigned short) (((tempeax & 0x0000FF00) & 0x1F00)
3719 | (tempbx & 0x00FF));
3720 tempax = (unsigned short) (((tempeax & 0x000000FF) << 8)
3721 | (tempax & 0x00FF));
3722 temp = (tempax & 0xFF00) >> 8;
3723 } else {
3724 temp = (tempax & 0x00FF) >> 8;
3725 }
3726
Aaro Koskinen8104e322011-03-13 12:26:22 +02003727 xgifb_reg_set(pVBInfo->Part2Port, 0x44, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303728 temp = (tempbx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003729 xgifb_reg_and_or(pVBInfo->Part2Port, 0x45, ~0x03F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303730 temp = tempcx & 0x00FF;
3731
3732 if (tempbx & 0x2000)
3733 temp = 0;
3734
3735 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
3736 temp |= 0x18;
3737
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003738 xgifb_reg_and_or(pVBInfo->Part2Port, 0x46, ~0x1F, temp);
Peter Huewe599801f2012-02-09 21:11:45 +01003739 if (pVBInfo->TVInfo & TVSetPAL) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303740 tempbx = 0x0382;
3741 tempcx = 0x007e;
3742 } else {
3743 tempbx = 0x0369;
3744 tempcx = 0x0061;
3745 }
3746
3747 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003748 xgifb_reg_set(pVBInfo->Part2Port, 0x4b, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303749 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003750 xgifb_reg_set(pVBInfo->Part2Port, 0x4c, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303751
3752 temp = ((tempcx & 0xFF00) >> 8) & 0x03;
3753 temp = temp << 2;
3754 temp |= ((tempbx & 0xFF00) >> 8) & 0x03;
3755
Peter Huewe599801f2012-02-09 21:11:45 +01003756 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303757 temp |= 0x10;
3758
Peter Huewe599801f2012-02-09 21:11:45 +01003759 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303760 temp |= 0x20;
3761
Peter Huewe599801f2012-02-09 21:11:45 +01003762 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303763 temp |= 0x60;
3764 }
3765
Aaro Koskinen8104e322011-03-13 12:26:22 +02003766 xgifb_reg_set(pVBInfo->Part2Port, 0x4d, temp);
Aaro Koskinen58839b02011-03-13 12:26:23 +02003767 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x43); /* 301b change */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003768 xgifb_reg_set(pVBInfo->Part2Port, 0x43, (unsigned short) (temp - 3));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303769
Peter Huewe599801f2012-02-09 21:11:45 +01003770 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303771 if (pVBInfo->TVInfo & NTSC1024x768) {
3772 TimingPoint = XGI_NTSC1024AdjTime;
3773 for (i = 0x1c, j = 0; i <= 0x30; i++, j++) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003774 xgifb_reg_set(pVBInfo->Part2Port, i,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303775 TimingPoint[j]);
3776 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02003777 xgifb_reg_set(pVBInfo->Part2Port, 0x43, 0x72);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303778 }
3779 }
3780
Miguel Gómez949eb0a2012-07-06 12:40:36 +02003781 /* Modify for 301C PALM Support */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303782 if (pVBInfo->VBType & VB_XGI301C) {
Peter Huewe599801f2012-02-09 21:11:45 +01003783 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003784 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x08,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303785 0x08); /* PALM Mode */
3786 }
3787
Peter Huewe599801f2012-02-09 21:11:45 +01003788 if (pVBInfo->TVInfo & TVSetPALM) {
Peter Huewe9388ad92013-02-15 20:37:10 +01003789 tempax = xgifb_reg_get(pVBInfo->Part2Port, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303790 tempax--;
Aaro Koskinendc505562011-03-13 12:26:26 +02003791 xgifb_reg_and(pVBInfo->Part2Port, 0x01, tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303792
Aaro Koskinendc505562011-03-13 12:26:26 +02003793 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xEF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303794 }
3795
Peter Huewe599801f2012-02-09 21:11:45 +01003796 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303797 if (!(pVBInfo->VBInfo & SetInSlaveMode))
Aaro Koskinen8104e322011-03-13 12:26:22 +02003798 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303799 }
3800
3801 if (pVBInfo->VBInfo & SetCRT2ToTV)
3802 return;
3803}
3804
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003805static void XGI_SetLCDRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303806 struct xgi_hw_device_info *HwDeviceExtension,
3807 unsigned short RefreshRateTableIndex,
3808 struct vb_device_info *pVBInfo)
3809{
Peter Hueweef9a6b92013-02-03 04:08:43 +01003810 unsigned short pushbx, tempax, tempbx, tempcx, temp, tempah,
3811 tempbh, tempch;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303812
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02003813 struct XGI_LCDDesStruct const *LCDBDesPtr = NULL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303814
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003815 /* si+Ext_ResInfo */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303816 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
3817 return;
3818
3819 tempbx = pVBInfo->HDE; /* RHACTE=HDE-1 */
3820
3821 if (XGI_IsLCDDualLink(pVBInfo))
3822 tempbx = tempbx >> 1;
3823
3824 tempbx -= 1;
3825 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003826 xgifb_reg_set(pVBInfo->Part2Port, 0x2C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303827 temp = (tempbx & 0xFF00) >> 8;
3828 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003829 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2B, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303830 temp = 0x01;
3831
Aaro Koskinen8104e322011-03-13 12:26:22 +02003832 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303833 tempbx = pVBInfo->VDE; /* RTVACTEO=(VDE-1)&0xFF */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303834 tempbx--;
3835 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003836 xgifb_reg_set(pVBInfo->Part2Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303837 temp = ((tempbx & 0xFF00) >> 8) & 0x07;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003838 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0C, ~0x07, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303839
3840 tempcx = pVBInfo->VT - 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303841 temp = tempcx & 0x00FF; /* RVTVT=VT-1 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003842 xgifb_reg_set(pVBInfo->Part2Port, 0x19, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303843 temp = (tempcx & 0xFF00) >> 8;
3844 temp = temp << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003845 xgifb_reg_set(pVBInfo->Part2Port, 0x1A, temp);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003846 xgifb_reg_and_or(pVBInfo->Part2Port, 0x09, 0xF0, 0x00);
3847 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xF0, 0x00);
3848 xgifb_reg_and_or(pVBInfo->Part2Port, 0x17, 0xFB, 0x00);
3849 xgifb_reg_and_or(pVBInfo->Part2Port, 0x18, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303850
Justin P. Mattock558f7582012-10-02 21:17:11 -07003851 /* Customized LCDB Does not add */
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02003852 if ((pVBInfo->VBType & VB_SIS301LV) || (pVBInfo->VBType & VB_SIS302LV))
3853 LCDBDesPtr = XGI_GetLcdPtr(xgifb_lcddldes, ModeNo, ModeIdIndex,
3854 RefreshRateTableIndex, pVBInfo);
3855 else
3856 LCDBDesPtr = XGI_GetLcdPtr(XGI_LCDDesDataTable, ModeNo,
3857 ModeIdIndex, RefreshRateTableIndex,
3858 pVBInfo);
3859
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303860 tempah = pVBInfo->LCDResInfo;
3861 tempah &= PanelResInfo;
3862
Peter Huewe255aabd2012-02-09 21:11:44 +01003863 if ((tempah == Panel_1024x768) || (tempah == Panel_1024x768x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303864 tempbx = 1024;
3865 tempcx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01003866 } else if ((tempah == Panel_1280x1024) ||
3867 (tempah == Panel_1280x1024x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303868 tempbx = 1280;
3869 tempcx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01003870 } else if (tempah == Panel_1400x1050) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303871 tempbx = 1400;
3872 tempcx = 1050;
3873 } else {
3874 tempbx = 1600;
3875 tempcx = 1200;
3876 }
3877
3878 if (pVBInfo->LCDInfo & EnableScalingLCD) {
3879 tempbx = pVBInfo->HDE;
3880 tempcx = pVBInfo->VDE;
3881 }
3882
3883 pushbx = tempbx;
3884 tempax = pVBInfo->VT;
3885 pVBInfo->LCDHDES = LCDBDesPtr->LCDHDES;
3886 pVBInfo->LCDHRS = LCDBDesPtr->LCDHRS;
3887 pVBInfo->LCDVDES = LCDBDesPtr->LCDVDES;
3888 pVBInfo->LCDVRS = LCDBDesPtr->LCDVRS;
3889 tempbx = pVBInfo->LCDVDES;
3890 tempcx += tempbx;
3891
3892 if (tempcx >= tempax)
3893 tempcx -= tempax; /* lcdvdes */
3894
3895 temp = tempbx & 0x00FF; /* RVEQ1EQ=lcdvdes */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003896 xgifb_reg_set(pVBInfo->Part2Port, 0x05, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303897 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003898 xgifb_reg_set(pVBInfo->Part2Port, 0x06, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303899 tempch = ((tempcx & 0xFF00) >> 8) & 0x07;
3900 tempbh = ((tempbx & 0xFF00) >> 8) & 0x07;
3901 tempah = tempch;
3902 tempah = tempah << 3;
3903 tempah |= tempbh;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003904 xgifb_reg_set(pVBInfo->Part2Port, 0x02, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303905
3906 /* getlcdsync() */
3907 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
3908 tempcx = tempbx;
3909 tempax = pVBInfo->VT;
3910 tempbx = pVBInfo->LCDVRS;
3911
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303912 tempcx += tempbx;
3913 if (tempcx >= tempax)
3914 tempcx -= tempax;
3915
3916 temp = tempbx & 0x00FF; /* RTVACTEE=lcdvrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003917 xgifb_reg_set(pVBInfo->Part2Port, 0x04, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303918 temp = (tempbx & 0xFF00) >> 8;
3919 temp = temp << 4;
3920 temp |= (tempcx & 0x000F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003921 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303922 tempcx = pushbx;
3923 tempax = pVBInfo->HT;
3924 tempbx = pVBInfo->LCDHDES;
3925 tempbx &= 0x0FFF;
3926
3927 if (XGI_IsLCDDualLink(pVBInfo)) {
3928 tempax = tempax >> 1;
3929 tempbx = tempbx >> 1;
3930 tempcx = tempcx >> 1;
3931 }
3932
Peter Huewe6896b942012-02-09 21:11:46 +01003933 if (pVBInfo->VBType & VB_SIS302LV)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303934 tempbx += 1;
3935
3936 if (pVBInfo->VBType & VB_XGI301C) /* tap4 */
3937 tempbx += 1;
3938
3939 tempcx += tempbx;
3940
3941 if (tempcx >= tempax)
3942 tempcx -= tempax;
3943
3944 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003945 xgifb_reg_set(pVBInfo->Part2Port, 0x1F, temp); /* RHBLKE=lcdhdes */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303946 temp = ((tempbx & 0xFF00) >> 8) << 4;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003947 xgifb_reg_set(pVBInfo->Part2Port, 0x20, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303948 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003949 xgifb_reg_set(pVBInfo->Part2Port, 0x23, temp); /* RHEQPLE=lcdhdee */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303950 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003951 xgifb_reg_set(pVBInfo->Part2Port, 0x25, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303952
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303953 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
3954 tempcx = tempax;
3955 tempax = pVBInfo->HT;
3956 tempbx = pVBInfo->LCDHRS;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303957 if (XGI_IsLCDDualLink(pVBInfo)) {
3958 tempax = tempax >> 1;
3959 tempbx = tempbx >> 1;
3960 tempcx = tempcx >> 1;
3961 }
3962
Peter Huewe6896b942012-02-09 21:11:46 +01003963 if (pVBInfo->VBType & VB_SIS302LV)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303964 tempbx += 1;
3965
3966 tempcx += tempbx;
3967
3968 if (tempcx >= tempax)
3969 tempcx -= tempax;
3970
3971 temp = tempbx & 0x00FF; /* RHBURSTS=lcdhrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003972 xgifb_reg_set(pVBInfo->Part2Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303973
3974 temp = (tempbx & 0xFF00) >> 8;
3975 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003976 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303977 temp = tempcx & 0x00FF; /* RHSYEXP2S=lcdhre */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003978 xgifb_reg_set(pVBInfo->Part2Port, 0x21, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303979
Peter Huewea3d675c2012-02-09 21:11:47 +01003980 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303981 if (pVBInfo->VGAVDE == 525) {
Peter Huewe6896b942012-02-09 21:11:46 +01003982 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
3983 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303984 | VB_XGI301C)) {
3985 temp = 0xC6;
3986 } else
3987 temp = 0xC4;
3988
Aaro Koskinen8104e322011-03-13 12:26:22 +02003989 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
3990 xgifb_reg_set(pVBInfo->Part2Port, 0x30, 0xB3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303991 }
3992
3993 if (pVBInfo->VGAVDE == 420) {
Peter Huewe6896b942012-02-09 21:11:46 +01003994 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
3995 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303996 | VB_XGI301C)) {
3997 temp = 0x4F;
3998 } else
3999 temp = 0x4E;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004000 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304001 }
4002 }
4003}
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004004
4005/* --------------------------------------------------------------------- */
4006/* Function : XGI_GetTap4Ptr */
4007/* Input : */
4008/* Output : di -> Tap4 Reg. Setting Pointer */
4009/* Description : */
4010/* --------------------------------------------------------------------- */
Aaro Koskinen1cccd9e2012-11-04 21:15:06 +02004011static struct XGI301C_Tap4TimingStruct const
4012*XGI_GetTap4Ptr(unsigned short tempcx, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004013{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304014 unsigned short tempax, tempbx, i;
Aaro Koskinen1cccd9e2012-11-04 21:15:06 +02004015 struct XGI301C_Tap4TimingStruct const *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004016
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304017 if (tempcx == 0) {
4018 tempax = pVBInfo->VGAHDE;
4019 tempbx = pVBInfo->HDE;
4020 } else {
4021 tempax = pVBInfo->VGAVDE;
4022 tempbx = pVBInfo->VDE;
4023 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004024
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004025 if (tempax <= tempbx)
4026 return &xgifb_tap4_timing[0];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304027 else
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004028 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing; /* NTSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004029
Peter Huewe599801f2012-02-09 21:11:45 +01004030 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304031 Tap4TimingPtr = PALTap4Timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004032
Peter Huewe599801f2012-02-09 21:11:45 +01004033 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
4034 if ((pVBInfo->TVInfo & TVSetYPbPr525i) ||
4035 (pVBInfo->TVInfo & TVSetYPbPr525p))
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004036 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing;
Peter Huewe599801f2012-02-09 21:11:45 +01004037 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304038 Tap4TimingPtr = YPbPr750pTap4Timing;
4039 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004040
Peter Huewe599801f2012-02-09 21:11:45 +01004041 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004042 Tap4TimingPtr = xgifb_tap4_timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004043
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304044 i = 0;
4045 while (Tap4TimingPtr[i].DE != 0xFFFF) {
4046 if (Tap4TimingPtr[i].DE == tempax)
4047 break;
4048 i++;
4049 }
4050 return &Tap4TimingPtr[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004051}
4052
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004053static void XGI_SetTap4Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004054{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304055 unsigned short i, j;
Aaro Koskinen1cccd9e2012-11-04 21:15:06 +02004056 struct XGI301C_Tap4TimingStruct const *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004057
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304058 if (!(pVBInfo->VBType & VB_XGI301C))
4059 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004060
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304061 Tap4TimingPtr = XGI_GetTap4Ptr(0, pVBInfo); /* Set Horizontal Scaling */
4062 for (i = 0x80, j = 0; i <= 0xBF; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004063 xgifb_reg_set(pVBInfo->Part2Port, i, Tap4TimingPtr->Reg[j]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004064
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004065 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
Peter Huewe599801f2012-02-09 21:11:45 +01004066 (!(pVBInfo->VBInfo & SetCRT2ToHiVision))) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004067 /* Set Vertical Scaling */
4068 Tap4TimingPtr = XGI_GetTap4Ptr(1, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304069 for (i = 0xC0, j = 0; i < 0xFF; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004070 xgifb_reg_set(pVBInfo->Part2Port,
4071 i,
4072 Tap4TimingPtr->Reg[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304073 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004074
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004075 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
Peter Huewe599801f2012-02-09 21:11:45 +01004076 (!(pVBInfo->VBInfo & SetCRT2ToHiVision)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004077 /* Enable V.Scaling */
4078 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304079 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004080 /* Enable H.Scaling */
4081 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x10);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004082}
4083
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004084static void XGI_SetGroup3(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304085 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004086{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304087 unsigned short i;
Aaro Koskinend21222d2012-09-11 00:15:29 +03004088 unsigned char const *tempdi;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304089 unsigned short modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004090
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004091 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004092 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004093
Aaro Koskinen8104e322011-03-13 12:26:22 +02004094 xgifb_reg_set(pVBInfo->Part3Port, 0x00, 0x00);
Peter Huewe599801f2012-02-09 21:11:45 +01004095 if (pVBInfo->TVInfo & TVSetPAL) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004096 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
4097 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304098 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004099 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xF5);
4100 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xB7);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304101 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004102
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304103 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
4104 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004105
Peter Huewe599801f2012-02-09 21:11:45 +01004106 if (pVBInfo->TVInfo & TVSetPALM) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004107 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
4108 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
4109 xgifb_reg_set(pVBInfo->Part3Port, 0x3D, 0xA8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304110 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004111
Peter Huewe599801f2012-02-09 21:11:45 +01004112 if ((pVBInfo->VBInfo & SetCRT2ToHiVision) || (pVBInfo->VBInfo
4113 & SetCRT2ToYPbPr525750)) {
4114 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304115 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004116
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004117 tempdi = XGI330_HiTVGroup3Data;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304118 if (pVBInfo->SetFlag & TVSimuMode) {
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004119 tempdi = XGI330_HiTVGroup3Simu;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304120 if (!(modeflag & Charx8Dot))
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004121 tempdi = XGI330_HiTVGroup3Text;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304122 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004123
Peter Huewe599801f2012-02-09 21:11:45 +01004124 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004125 tempdi = XGI330_Ren525pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004126
Peter Huewe599801f2012-02-09 21:11:45 +01004127 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004128 tempdi = XGI330_Ren750pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004129
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304130 for (i = 0; i <= 0x3E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004131 xgifb_reg_set(pVBInfo->Part3Port, i, tempdi[i]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004132
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304133 if (pVBInfo->VBType & VB_XGI301C) { /* Marcovision */
Peter Huewe599801f2012-02-09 21:11:45 +01004134 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004135 xgifb_reg_set(pVBInfo->Part3Port, 0x28, 0x3f);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304136 }
4137 }
4138 return;
4139} /* {end of XGI_SetGroup3} */
4140
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004141static void XGI_SetGroup4(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304142 unsigned short RefreshRateTableIndex,
4143 struct xgi_hw_device_info *HwDeviceExtension,
4144 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004145{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304146 unsigned short tempax, tempcx, tempbx, modeflag, temp, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004147
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304148 unsigned long tempebx, tempeax, templong;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004149
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004150 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004151 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304152 temp = pVBInfo->RVBHCFACT;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004153 xgifb_reg_set(pVBInfo->Part4Port, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004154
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304155 tempbx = pVBInfo->RVBHCMAX;
4156 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004157 xgifb_reg_set(pVBInfo->Part4Port, 0x14, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304158 temp2 = ((tempbx & 0xFF00) >> 8) << 7;
4159 tempcx = pVBInfo->VGAHT - 1;
4160 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004161 xgifb_reg_set(pVBInfo->Part4Port, 0x16, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004162
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304163 temp = ((tempcx & 0xFF00) >> 8) << 3;
4164 temp2 |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004165
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304166 tempcx = pVBInfo->VGAVT - 1;
4167 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
4168 tempcx -= 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004169
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304170 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004171 xgifb_reg_set(pVBInfo->Part4Port, 0x17, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304172 temp = temp2 | ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004173 xgifb_reg_set(pVBInfo->Part4Port, 0x15, temp);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004174 xgifb_reg_or(pVBInfo->Part4Port, 0x0D, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304175 tempcx = pVBInfo->VBInfo;
4176 tempbx = pVBInfo->VGAHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004177
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304178 if (modeflag & HalfDCLK)
4179 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004180
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304181 if (XGI_IsLCDDualLink(pVBInfo))
4182 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004183
Peter Huewe599801f2012-02-09 21:11:45 +01004184 if (tempcx & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304185 temp = 0;
4186 if (tempbx <= 1024)
4187 temp = 0xA0;
4188 if (tempbx == 1280)
4189 temp = 0xC0;
4190 } else if (tempcx & SetCRT2ToTV) {
4191 temp = 0xA0;
4192 if (tempbx <= 800)
4193 temp = 0x80;
4194 } else {
4195 temp = 0x80;
4196 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4197 temp = 0;
4198 if (tempbx > 800)
4199 temp = 0x60;
4200 }
4201 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004202
Peter Huewe599801f2012-02-09 21:11:45 +01004203 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304204 temp = 0x00;
4205 if (pVBInfo->VGAHDE == 1280)
4206 temp = 0x40;
4207 if (pVBInfo->VGAHDE == 1024)
4208 temp = 0x20;
4209 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004210 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0E, ~0xEF, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004211
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304212 tempebx = pVBInfo->VDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004213
Peter Huewe599801f2012-02-09 21:11:45 +01004214 if (tempcx & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304215 if (!(temp & 0xE000))
4216 tempbx = tempbx >> 1;
4217 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004218
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304219 tempcx = pVBInfo->RVBHRS;
4220 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004221 xgifb_reg_set(pVBInfo->Part4Port, 0x18, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004222
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304223 tempeax = pVBInfo->VGAVDE;
4224 tempcx |= 0x04000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004225
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304226 if (tempeax <= tempebx) {
4227 tempcx = (tempcx & (~0x4000));
4228 tempeax = pVBInfo->VGAVDE;
4229 } else {
4230 tempeax -= tempebx;
4231 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004232
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304233 templong = (tempeax * 256 * 1024) % tempebx;
4234 tempeax = (tempeax * 256 * 1024) / tempebx;
4235 tempebx = tempeax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004236
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304237 if (templong != 0)
4238 tempebx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004239
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304240 temp = (unsigned short) (tempebx & 0x000000FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004241 xgifb_reg_set(pVBInfo->Part4Port, 0x1B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004242
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304243 temp = (unsigned short) ((tempebx & 0x0000FF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004244 xgifb_reg_set(pVBInfo->Part4Port, 0x1A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304245 tempbx = (unsigned short) (tempebx >> 16);
4246 temp = tempbx & 0x00FF;
4247 temp = temp << 4;
4248 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004249 xgifb_reg_set(pVBInfo->Part4Port, 0x19, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004250
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304251 /* 301b */
Peter Huewe6896b942012-02-09 21:11:46 +01004252 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4253 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304254 temp = 0x0028;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004255 xgifb_reg_set(pVBInfo->Part4Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304256 tempax = pVBInfo->VGAHDE;
4257 if (modeflag & HalfDCLK)
4258 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004259
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304260 if (XGI_IsLCDDualLink(pVBInfo))
4261 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004262
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304263 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4264 if (tempax > 800)
4265 tempax -= 800;
Aaro Koskinend3ae5762012-09-11 00:15:27 +03004266 } else if (pVBInfo->VGAHDE > 800) {
4267 if (pVBInfo->VGAHDE == 1024)
4268 tempax = (tempax * 25 / 32) - 1;
4269 else
4270 tempax = (tempax * 20 / 32) - 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304271 }
4272 tempax -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004273
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304274 temp = (tempax & 0xFF00) >> 8;
4275 temp = ((temp & 0x0003) << 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004276 xgifb_reg_set(pVBInfo->Part4Port, 0x1E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304277 temp = (tempax & 0x00FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004278 xgifb_reg_set(pVBInfo->Part4Port, 0x1D, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004279
Peter Huewe599801f2012-02-09 21:11:45 +01004280 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToHiVision)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304281 if (pVBInfo->VGAHDE > 800)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004282 xgifb_reg_or(pVBInfo->Part4Port, 0x1E, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004283
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304284 }
4285 temp = 0x0036;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004286
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304287 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4288 if (!(pVBInfo->TVInfo & (NTSC1024x768
Peter Huewe599801f2012-02-09 21:11:45 +01004289 | TVSetYPbPr525p | TVSetYPbPr750p
4290 | TVSetHiVision))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304291 temp |= 0x0001;
4292 if ((pVBInfo->VBInfo & SetInSlaveMode)
4293 && (!(pVBInfo->TVInfo
4294 & TVSimuMode)))
4295 temp &= (~0x0001);
4296 }
4297 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004298
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004299 xgifb_reg_and_or(pVBInfo->Part4Port, 0x1F, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304300 tempbx = pVBInfo->HT;
4301 if (XGI_IsLCDDualLink(pVBInfo))
4302 tempbx = tempbx >> 1;
4303 tempbx = (tempbx >> 1) - 2;
4304 temp = ((tempbx & 0x0700) >> 8) << 3;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004305 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304306 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004307 xgifb_reg_set(pVBInfo->Part4Port, 0x22, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304308 }
4309 /* end 301b */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004310
Aaro Koskinen8951dad2012-09-11 00:15:30 +03004311 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004312}
4313
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004314static void XGINew_EnableCRT2(struct vb_device_info *pVBInfo)
4315{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004316 xgifb_reg_and_or(pVBInfo->P3c4, 0x1E, 0xFF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004317}
4318
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004319static void XGI_SetGroup5(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304320 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004321{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304322 if (pVBInfo->ModeType == ModeVGA) {
4323 if (!(pVBInfo->VBInfo & (SetInSlaveMode | LoadDACFlag
Peter Huewe6896b942012-02-09 21:11:46 +01004324 | DisableCRT2Display))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304325 XGINew_EnableCRT2(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304326 }
4327 }
4328 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004329}
4330
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004331static void XGI_EnableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304332 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004333{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004334 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x40);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004335}
4336
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004337static void XGI_DisableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304338 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004339{
4340
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004341 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004342}
4343
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004344static unsigned char XGI_XG21CheckLVDSMode(struct xgifb_video_info *xgifb_info,
4345 unsigned short ModeNo, unsigned short ModeIdIndex,
4346 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004347{
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004348 unsigned short xres, yres, colordepth, modeflag, resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004349
Aaro Koskinenb3979922012-11-04 21:14:52 +02004350 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02004351 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
4352 yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004353 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004354 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004355
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304356 if (!(modeflag & Charx8Dot)) {
4357 xres /= 9;
4358 xres *= 8;
4359 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004360
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004361 if ((ModeNo > 0x13) && (modeflag & HalfDCLK))
4362 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004363
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004364 if ((ModeNo > 0x13) && (modeflag & DoubleScanMode))
4365 yres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004366
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004367 if (xres > xgifb_info->lvds_data.LVDSHDE)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304368 return 0;
Bill Pembertondda08c52010-06-17 13:10:42 -04004369
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004370 if (yres > xgifb_info->lvds_data.LVDSVDE)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304371 return 0;
4372
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004373 if (xres != xgifb_info->lvds_data.LVDSHDE ||
4374 yres != xgifb_info->lvds_data.LVDSVDE) {
4375 colordepth = XGI_GetColorDepth(ModeNo, ModeIdIndex, pVBInfo);
4376 if (colordepth > 2)
4377 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304378 }
4379 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004380}
4381
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004382static void xgifb_set_lvds(struct xgifb_video_info *xgifb_info,
4383 int chip_id,
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004384 unsigned short ModeNo,
4385 unsigned short ModeIdIndex,
4386 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004387{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304388 unsigned char temp, Miscdata;
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004389 unsigned short xres, yres, modeflag, resindex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304390 unsigned short LVDSHT, LVDSHBS, LVDSHRS, LVDSHRE, LVDSHBE;
4391 unsigned short LVDSVT, LVDSVBS, LVDSVRS, LVDSVRE, LVDSVBE;
4392 unsigned short value;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004393
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004394 temp = (unsigned char) ((xgifb_info->lvds_data.LVDS_Capability &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004395 (LCDPolarity << 8)) >> 8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304396 temp &= LCDPolarity;
Peter Huewe9388ad92013-02-15 20:37:10 +01004397 Miscdata = inb(pVBInfo->P3cc);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004398
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004399 outb((Miscdata & 0x3F) | temp, pVBInfo->P3c2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004400
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004401 temp = xgifb_info->lvds_data.LVDS_Capability & LCDPolarity;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004402 /* SR35[7] FP VSync polarity */
4403 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x80, temp & 0x80);
4404 /* SR30[5] FP HSync polarity */
4405 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, ~0x20, (temp & 0x40) >> 1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004406
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004407 if (chip_id == XG27)
4408 XGI_SetXG27FPBits(pVBInfo);
4409 else
4410 XGI_SetXG21FPBits(pVBInfo);
4411
Aaro Koskinenb3979922012-11-04 21:14:52 +02004412 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02004413 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
4414 yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004415 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004416 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004417
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304418 if (!(modeflag & Charx8Dot))
4419 xres = xres * 8 / 9;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004420
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004421 LVDSHT = xgifb_info->lvds_data.LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004422
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004423 LVDSHBS = xres + (xgifb_info->lvds_data.LVDSHDE - xres) / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004424
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304425 if (LVDSHBS > LVDSHT)
4426 LVDSHBS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004427
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004428 LVDSHRS = LVDSHBS + xgifb_info->lvds_data.LVDSHFP;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304429 if (LVDSHRS > LVDSHT)
4430 LVDSHRS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004431
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004432 LVDSHRE = LVDSHRS + xgifb_info->lvds_data.LVDSHSYNC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304433 if (LVDSHRE > LVDSHT)
4434 LVDSHRE -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004435
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004436 LVDSHBE = LVDSHBS + LVDSHT - xgifb_info->lvds_data.LVDSHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004437
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004438 LVDSVT = xgifb_info->lvds_data.LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004439
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004440 LVDSVBS = yres + (xgifb_info->lvds_data.LVDSVDE - yres) / 2;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004441 if (modeflag & DoubleScanMode)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304442 LVDSVBS += yres / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004443
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304444 if (LVDSVBS > LVDSVT)
4445 LVDSVBS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004446
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004447 LVDSVRS = LVDSVBS + xgifb_info->lvds_data.LVDSVFP;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304448 if (LVDSVRS > LVDSVT)
4449 LVDSVRS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004450
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004451 LVDSVRE = LVDSVRS + xgifb_info->lvds_data.LVDSVSYNC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304452 if (LVDSVRE > LVDSVT)
4453 LVDSVRE -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004454
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004455 LVDSVBE = LVDSVBS + LVDSVT - xgifb_info->lvds_data.LVDSVDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004456
Peter Huewe9388ad92013-02-15 20:37:10 +01004457 temp = xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004458 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp & 0x7f); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004459
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304460 if (!(modeflag & Charx8Dot))
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004461 xgifb_reg_or(pVBInfo->P3c4, 0x1, 0x1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004462
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304463 /* HT SR0B[1:0] CR00 */
4464 value = (LVDSHT >> 3) - 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004465 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004466 xgifb_reg_set(pVBInfo->P3d4, 0x0, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004467
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304468 /* HBS SR0B[5:4] CR02 */
4469 value = (LVDSHBS >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004470 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x30, (value & 0x300) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004471 xgifb_reg_set(pVBInfo->P3d4, 0x2, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004472
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304473 /* HBE SR0C[1:0] CR05[7] CR03[4:0] */
4474 value = (LVDSHBE >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004475 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x03, (value & 0xC0) >> 6);
4476 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x80, (value & 0x20) << 2);
4477 xgifb_reg_and_or(pVBInfo->P3d4, 0x03, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004478
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304479 /* HRS SR0B[7:6] CR04 */
4480 value = (LVDSHRS >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004481 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0xC0, (value & 0x300) >> 2);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004482 xgifb_reg_set(pVBInfo->P3d4, 0x4, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004483
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304484 /* Panel HRS SR2F[1:0] SR2E[7:0] */
4485 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004486 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004487 xgifb_reg_set(pVBInfo->P3c4, 0x2E, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004488
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304489 /* HRE SR0C[2] CR05[4:0] */
4490 value = (LVDSHRE >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004491 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x04, (value & 0x20) >> 3);
4492 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004493
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304494 /* Panel HRE SR2F[7:2] */
4495 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004496 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0xFC, value << 2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004497
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304498 /* VT SR0A[0] CR07[5][0] CR06 */
4499 value = LVDSVT - 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004500 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x01, (value & 0x400) >> 10);
4501 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x20, (value & 0x200) >> 4);
4502 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x01, (value & 0x100) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004503 xgifb_reg_set(pVBInfo->P3d4, 0x06, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004504
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304505 /* VBS SR0A[2] CR09[5] CR07[3] CR15 */
4506 value = LVDSVBS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004507 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x04, (value & 0x400) >> 8);
4508 xgifb_reg_and_or(pVBInfo->P3d4, 0x09, ~0x20, (value & 0x200) >> 4);
4509 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x08, (value & 0x100) >> 5);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004510 xgifb_reg_set(pVBInfo->P3d4, 0x15, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004511
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304512 /* VBE SR0A[4] CR16 */
4513 value = LVDSVBE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004514 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x10, (value & 0x100) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004515 xgifb_reg_set(pVBInfo->P3d4, 0x16, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004516
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304517 /* VRS SR0A[3] CR7[7][2] CR10 */
4518 value = LVDSVRS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004519 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x08, (value & 0x400) >> 7);
4520 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x80, (value & 0x200) >> 2);
4521 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x04, (value & 0x100) >> 6);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004522 xgifb_reg_set(pVBInfo->P3d4, 0x10, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004523
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004524 if (chip_id == XG27) {
4525 /* Panel VRS SR35[2:0] SR34[7:0] */
4526 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07,
4527 (value & 0x700) >> 8);
4528 xgifb_reg_set(pVBInfo->P3c4, 0x34, value & 0xFF);
4529 } else {
4530 /* Panel VRS SR3F[1:0] SR34[7:0] SR33[0] */
4531 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0x03,
4532 (value & 0x600) >> 9);
4533 xgifb_reg_set(pVBInfo->P3c4, 0x34, (value >> 1) & 0xFF);
4534 xgifb_reg_and_or(pVBInfo->P3d4, 0x33, ~0x01, value & 0x01);
4535 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004536
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304537 /* VRE SR0A[5] CR11[3:0] */
4538 value = LVDSVRE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004539 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x20, (value & 0x10) << 1);
4540 xgifb_reg_and_or(pVBInfo->P3d4, 0x11, ~0x0F, value & 0x0F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004541
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304542 /* Panel VRE SR3F[7:2] */
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004543 if (chip_id == XG27)
4544 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
4545 (value << 2) & 0xFC);
4546 else
4547 /* SR3F[7] has to be 0, h/w bug */
4548 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
4549 (value << 2) & 0x7C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004550
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304551 for (temp = 0, value = 0; temp < 3; temp++) {
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004552
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004553 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, value);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004554 xgifb_reg_set(pVBInfo->P3c4,
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004555 0x2B, xgifb_info->lvds_data.VCLKData1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004556 xgifb_reg_set(pVBInfo->P3c4,
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004557 0x2C, xgifb_info->lvds_data.VCLKData2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304558 value += 0x10;
4559 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004560
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304561 if (!(modeflag & Charx8Dot)) {
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004562 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004563 outb(0x13, pVBInfo->P3c0); /* set index */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004564 /* set data, panning = 0, shift left 1 dot*/
4565 outb(0x00, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004566
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004567 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004568 outb(0x20, pVBInfo->P3c0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304569
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004570 inb(pVBInfo->P3da); /* reset 3da */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304571 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004572
4573}
4574
4575/* --------------------------------------------------------------------- */
4576/* Function : XGI_IsLCDON */
4577/* Input : */
Bill Pembertondda08c52010-06-17 13:10:42 -04004578/* Output : 0 : Skip PSC Control */
4579/* 1: Disable PSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004580/* Description : */
4581/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004582static unsigned char XGI_IsLCDON(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004583{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304584 unsigned short tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004585
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304586 tempax = pVBInfo->VBInfo;
4587 if (tempax & SetCRT2ToDualEdge)
4588 return 0;
Peter Huewe6896b942012-02-09 21:11:46 +01004589 else if (tempax & (DisableCRT2Display | SwitchCRT2 | SetSimuScanMode))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304590 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004591
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304592 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004593}
4594
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004595/* --------------------------------------------------------------------- */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004596/* Function : XGI_EnableChISLCD */
4597/* Input : */
4598/* Output : 0 -> Not LCD mode */
Peter Huewe06cc47b2013-02-03 22:54:38 +01004599/* Description : if bool enable = true -> enable, else disable */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004600/* --------------------------------------------------------------------- */
Peter Huewe06cc47b2013-02-03 22:54:38 +01004601static unsigned char XGI_EnableChISLCD(struct vb_device_info *pVBInfo,
4602 bool enable)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004603{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304604 unsigned short tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004605
Peter Huewe06cc47b2013-02-03 22:54:38 +01004606 if (enable)
4607 tempbx = pVBInfo->SetFlag & (EnableChA | EnableChB);
4608 else
4609 tempbx = pVBInfo->SetFlag & (DisableChA | DisableChB);
4610
Aaro Koskinen58839b02011-03-13 12:26:23 +02004611 tempah = ~((unsigned short) xgifb_reg_get(pVBInfo->Part1Port, 0x2E));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004612
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304613 if (tempbx & (EnableChA | DisableChA)) {
4614 if (!(tempah & 0x08)) /* Chk LCDA Mode */
4615 return 0;
4616 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004617
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304618 if (!(tempbx & (EnableChB | DisableChB)))
Bill Pembertondda08c52010-06-17 13:10:42 -04004619 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004620
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304621 if (tempah & 0x01) /* Chk LCDB Mode */
4622 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004623
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304624 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004625}
4626
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004627static void XGI_DisableBridge(struct xgifb_video_info *xgifb_info,
4628 struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304629 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004630{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02004631 unsigned short tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004632
Peter Huewe6896b942012-02-09 21:11:46 +01004633 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4634 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304635 tempah = 0x3F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004636 if (!(pVBInfo->VBInfo &
4637 (DisableCRT2Display | SetSimuScanMode))) {
Peter Huewea3d675c2012-02-09 21:11:47 +01004638 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304639 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
4640 tempah = 0x7F; /* Disable Channel A */
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004641 if (!(pVBInfo->VBInfo &
4642 XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004643 /* Disable Channel B */
4644 tempah = 0xBF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004645
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304646 if (pVBInfo->SetFlag & DisableChB)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004647 /* force to disable Cahnnel */
4648 tempah &= 0xBF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004649
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304650 if (pVBInfo->SetFlag & DisableChA)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004651 /* Force to disable Channel B */
4652 tempah &= 0x7F;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304653 }
4654 }
4655 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004656
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004657 /* disable part4_1f */
4658 xgifb_reg_and(pVBInfo->Part4Port, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004659
Peter Huewe6896b942012-02-09 21:11:46 +01004660 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004661 if (((pVBInfo->VBInfo &
Peter Huewe06cc47b2013-02-03 22:54:38 +01004662 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))) ||
4663 (XGI_EnableChISLCD(pVBInfo, false)) ||
4664 (XGI_IsLCDON(pVBInfo)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004665 /* LVDS Driver power down */
4666 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304667 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004668
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304669 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
Peter Huewea3d675c2012-02-09 21:11:47 +01004670 & (DisableCRT2Display | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304671 | SetSimuScanMode))) {
4672 if (pVBInfo->SetFlag & GatingCRT)
4673 XGI_EnableGatingCRT(HwDeviceExtension, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004674 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304675 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004676
Peter Huewea3d675c2012-02-09 21:11:47 +01004677 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304678 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
Peter Huewea3d675c2012-02-09 21:11:47 +01004679 & XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004680 /* Power down */
4681 xgifb_reg_and(pVBInfo->Part1Port, 0x1e, 0xdf);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304682 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004683
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004684 /* disable TV as primary VGA swap */
4685 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004686
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304687 if ((pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToDualEdge)))
Aaro Koskinendc505562011-03-13 12:26:26 +02004688 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004689
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004690 if ((pVBInfo->SetFlag & DisableChB) ||
4691 (pVBInfo->VBInfo &
4692 (DisableCRT2Display | SetSimuScanMode)) ||
Peter Huewea3d675c2012-02-09 21:11:47 +01004693 ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) &&
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004694 (pVBInfo->VBInfo &
4695 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004696 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004697
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004698 if ((pVBInfo->SetFlag & DisableChB) ||
4699 (pVBInfo->VBInfo &
4700 (DisableCRT2Display | SetSimuScanMode)) ||
Peter Huewea3d675c2012-02-09 21:11:47 +01004701 (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) ||
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004702 (pVBInfo->VBInfo &
4703 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))) {
4704 /* save Part1 index 0 */
4705 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
4706 /* BTDAC = 1, avoid VB reset */
4707 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x10);
4708 /* disable CRT2 */
4709 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
4710 /* restore Part1 index 0 */
4711 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304712 }
4713 } else { /* {301} */
4714 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004715 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
4716 /* Disable CRT2 */
4717 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
4718 /* Disable TV asPrimary VGA swap */
4719 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xDF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304720 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004721
Peter Huewea3d675c2012-02-09 21:11:47 +01004722 if (pVBInfo->VBInfo & (DisableCRT2Display | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304723 | SetSimuScanMode))
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004724 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304725 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004726}
4727
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004728/* --------------------------------------------------------------------- */
4729/* Function : XGI_GetTVPtrIndex */
4730/* Input : */
4731/* Output : */
4732/* Description : bx 0 : ExtNTSC */
4733/* 1 : StNTSC */
4734/* 2 : ExtPAL */
4735/* 3 : StPAL */
4736/* 4 : ExtHiTV */
4737/* 5 : StHiTV */
4738/* 6 : Ext525i */
4739/* 7 : St525i */
4740/* 8 : Ext525p */
4741/* 9 : St525p */
4742/* A : Ext750p */
4743/* B : St750p */
4744/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004745static unsigned short XGI_GetTVPtrIndex(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004746{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304747 unsigned short tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004748
Peter Huewe599801f2012-02-09 21:11:45 +01004749 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304750 tempbx = 2;
Peter Huewe599801f2012-02-09 21:11:45 +01004751 if (pVBInfo->TVInfo & TVSetHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304752 tempbx = 4;
Peter Huewe599801f2012-02-09 21:11:45 +01004753 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304754 tempbx = 6;
Peter Huewe599801f2012-02-09 21:11:45 +01004755 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304756 tempbx = 8;
Peter Huewe599801f2012-02-09 21:11:45 +01004757 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304758 tempbx = 10;
4759 if (pVBInfo->TVInfo & TVSimuMode)
4760 tempbx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004761
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304762 return tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004763}
4764
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004765/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004766/* Function : XGI_GetTVPtrIndex2 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004767/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004768/* Output : bx 0 : NTSC */
4769/* 1 : PAL */
4770/* 2 : PALM */
4771/* 3 : PALN */
4772/* 4 : NTSC1024x768 */
4773/* 5 : PAL-M 1024x768 */
4774/* 6-7: reserved */
4775/* cl 0 : YFilter1 */
4776/* 1 : YFilter2 */
4777/* ch 0 : 301A */
4778/* 1 : 301B/302B/301LV/302LV */
4779/* Description : */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004780/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004781static void XGI_GetTVPtrIndex2(unsigned short *tempbx, unsigned char *tempcl,
4782 unsigned char *tempch, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004783{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004784 *tempbx = 0;
4785 *tempcl = 0;
4786 *tempch = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004787
Peter Huewe599801f2012-02-09 21:11:45 +01004788 if (pVBInfo->TVInfo & TVSetPAL)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004789 *tempbx = 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004790
Peter Huewe599801f2012-02-09 21:11:45 +01004791 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004792 *tempbx = 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004793
Peter Huewe599801f2012-02-09 21:11:45 +01004794 if (pVBInfo->TVInfo & TVSetPALN)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004795 *tempbx = 3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004796
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004797 if (pVBInfo->TVInfo & NTSC1024x768) {
4798 *tempbx = 4;
Peter Huewe599801f2012-02-09 21:11:45 +01004799 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004800 *tempbx = 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304801 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004802
Peter Huewe6896b942012-02-09 21:11:46 +01004803 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4804 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004805 if ((!(pVBInfo->VBInfo & SetInSlaveMode)) || (pVBInfo->TVInfo
4806 & TVSimuMode)) {
4807 *tempbx += 8;
4808 *tempcl += 1;
4809 }
4810 }
4811
Peter Huewe6896b942012-02-09 21:11:46 +01004812 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4813 | VB_SIS302LV | VB_XGI301C))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004814 (*tempch)++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004815}
4816
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004817static void XGI_SetDelayComp(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004818{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304819 unsigned char tempah, tempbl, tempbh;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004820
Peter Huewe6896b942012-02-09 21:11:46 +01004821 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4822 | VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01004823 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304824 | SetCRT2ToTV | SetCRT2ToRAMDAC)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304825 tempbh = 0;
Peter Huewe03f76fc2012-06-14 00:21:50 +02004826 tempbl = XGI301TVDelay;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004827
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304828 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
4829 tempbl = tempbl >> 4;
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004830 if (pVBInfo->VBInfo &
4831 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Peter Huewe03f76fc2012-06-14 00:21:50 +02004832 tempbh = XGI301LCDDelay;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004833
Peter Huewea3d675c2012-02-09 21:11:47 +01004834 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304835 tempbl = tempbh;
4836 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004837
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304838 tempbl &= 0x0F;
4839 tempbh &= 0xF0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02004840 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2D);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004841
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304842 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD
4843 | SetCRT2ToTV)) { /* Channel B */
4844 tempah &= 0xF0;
4845 tempah |= tempbl;
4846 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004847
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004848 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
4849 /* Channel A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304850 tempah &= 0x0F;
4851 tempah |= tempbh;
4852 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02004853 xgifb_reg_set(pVBInfo->Part1Port, 0x2D, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304854 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304855 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004856}
4857
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004858static void XGI_SetLCDCap_A(unsigned short tempcx,
4859 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004860{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304861 unsigned short temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004862
Aaro Koskinen58839b02011-03-13 12:26:23 +02004863 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004864
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304865 if (temp & LCDRGB18Bit) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004866 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004867 /* Enable Dither */
4868 (unsigned short) (0x20 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004869 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304870 } else {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004871 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304872 (unsigned short) (0x30 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004873 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304874 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004875}
4876
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004877/* --------------------------------------------------------------------- */
4878/* Function : XGI_SetLCDCap_B */
4879/* Input : cx -> LCD Capability */
4880/* Output : */
4881/* Description : */
4882/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004883static void XGI_SetLCDCap_B(unsigned short tempcx,
4884 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004885{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304886 if (tempcx & EnableLCD24bpp) /* 24bits */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004887 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304888 (unsigned short) (((tempcx & 0x00ff) >> 6)
4889 | 0x0c));
4890 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004891 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304892 (unsigned short) (((tempcx & 0x00ff) >> 6)
4893 | 0x18)); /* Enable Dither */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004894}
4895
Aaro Koskinen7f04ec32011-11-27 23:03:05 +02004896static void XGI_LongWait(struct vb_device_info *pVBInfo)
4897{
4898 unsigned short i;
4899
4900 i = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
4901
4902 if (!(i & 0xC0)) {
4903 for (i = 0; i < 0xFFFF; i++) {
4904 if (!(inb(pVBInfo->P3da) & 0x08))
4905 break;
4906 }
4907
4908 for (i = 0; i < 0xFFFF; i++) {
4909 if ((inb(pVBInfo->P3da) & 0x08))
4910 break;
4911 }
4912 }
4913}
4914
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004915static void SetSpectrum(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004916{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304917 unsigned short index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004918
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304919 index = XGI_GetLCDCapPtr(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004920
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004921 /* disable down spectrum D[4] */
4922 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x8F);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304923 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004924 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x20); /* reset spectrum */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304925 XGI_LongWait(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004926
Aaro Koskinen8104e322011-03-13 12:26:22 +02004927 xgifb_reg_set(pVBInfo->Part4Port, 0x31,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304928 pVBInfo->LCDCapList[index].Spectrum_31);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004929 xgifb_reg_set(pVBInfo->Part4Port, 0x32,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304930 pVBInfo->LCDCapList[index].Spectrum_32);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004931 xgifb_reg_set(pVBInfo->Part4Port, 0x33,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304932 pVBInfo->LCDCapList[index].Spectrum_33);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004933 xgifb_reg_set(pVBInfo->Part4Port, 0x34,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304934 pVBInfo->LCDCapList[index].Spectrum_34);
4935 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004936 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x40); /* enable spectrum */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004937}
4938
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004939static void XGI_SetLCDCap(struct vb_device_info *pVBInfo)
4940{
4941 unsigned short tempcx;
4942
4943 tempcx = pVBInfo->LCDCapList[XGI_GetLCDCapPtr(pVBInfo)].LCD_Capability;
4944
Peter Huewef951dd02013-02-05 00:29:47 +01004945 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV |
4946 VB_SIS302LV | VB_XGI301C)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004947 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01004948 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004949 /* Set 301LV Capability */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004950 xgifb_reg_set(pVBInfo->Part4Port, 0x24,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004951 (unsigned char) (tempcx & 0x1F));
4952 }
4953 /* VB Driving */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004954 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004955 ~((EnableVBCLKDRVLOW | EnablePLLSPLOW) >> 8),
4956 (unsigned short) ((tempcx & (EnableVBCLKDRVLOW
4957 | EnablePLLSPLOW)) >> 8));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004958
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004959 if (pVBInfo->VBInfo & SetCRT2ToLCD)
4960 XGI_SetLCDCap_B(tempcx, pVBInfo);
Peter Huewea3d675c2012-02-09 21:11:47 +01004961 else if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004962 XGI_SetLCDCap_A(tempcx, pVBInfo);
4963
Peter Huewe6896b942012-02-09 21:11:46 +01004964 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004965 if (tempcx & EnableSpectrum)
4966 SetSpectrum(pVBInfo);
4967 }
4968 } else {
4969 /* LVDS,CH7017 */
4970 XGI_SetLCDCap_A(tempcx, pVBInfo);
4971 }
4972}
4973
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004974/* --------------------------------------------------------------------- */
4975/* Function : XGI_SetAntiFlicker */
4976/* Input : */
4977/* Output : */
4978/* Description : Set TV Customized Param. */
4979/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004980static void XGI_SetAntiFlicker(unsigned short ModeNo,
4981 unsigned short ModeIdIndex,
4982 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004983{
Aaro Koskinen36ae0352012-04-07 01:14:08 +03004984 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004985
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304986 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004987
Peter Huewe599801f2012-02-09 21:11:45 +01004988 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304989 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004990
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304991 tempbx = XGI_GetTVPtrIndex(pVBInfo);
4992 tempbx &= 0xFE;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304993 tempah = TVAntiFlickList[tempbx];
4994 tempah = tempah << 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004995
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004996 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0x8F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004997}
4998
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004999static void XGI_SetEdgeEnhance(unsigned short ModeNo,
5000 unsigned short ModeIdIndex,
5001 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005002{
Aaro Koskinen354f49f2012-04-07 01:14:09 +03005003 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005004
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305005 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005006
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305007 tempbx = XGI_GetTVPtrIndex(pVBInfo);
5008 tempbx &= 0xFE;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305009 tempah = TVEdgeList[tempbx];
5010 tempah = tempah << 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005011
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005012 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005013}
5014
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005015static void XGI_SetPhaseIncr(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005016{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305017 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005018
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305019 unsigned char tempcl, tempch;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005020
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305021 unsigned long tempData;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005022
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305023 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
5024 tempData = TVPhaseList[tempbx];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005025
Aaro Koskinen8104e322011-03-13 12:26:22 +02005026 xgifb_reg_set(pVBInfo->Part2Port, 0x31, (unsigned short) (tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305027 & 0x000000FF));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005028 xgifb_reg_set(pVBInfo->Part2Port, 0x32, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305029 & 0x0000FF00) >> 8));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005030 xgifb_reg_set(pVBInfo->Part2Port, 0x33, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305031 & 0x00FF0000) >> 16));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005032 xgifb_reg_set(pVBInfo->Part2Port, 0x34, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305033 & 0xFF000000) >> 24));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005034}
5035
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005036static void XGI_SetYFilter(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305037 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005038{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305039 unsigned short tempbx, index;
Aaro Koskinena68292f2012-11-04 21:15:07 +02005040 unsigned char const *filterPtr;
5041 unsigned char tempcl, tempch, tempal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005042
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305043 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005044
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305045 switch (tempbx) {
5046 case 0x00:
5047 case 0x04:
5048 filterPtr = NTSCYFilter1;
5049 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005050
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305051 case 0x01:
5052 filterPtr = PALYFilter1;
5053 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005054
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305055 case 0x02:
5056 case 0x05:
5057 case 0x0D:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305058 case 0x03:
Aaro Koskinen2555e942011-08-31 21:46:06 +03005059 filterPtr = xgifb_palmn_yfilter1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305060 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005061
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305062 case 0x08:
5063 case 0x0C:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305064 case 0x0A:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305065 case 0x0B:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305066 case 0x09:
Aaro Koskinen80f86f82011-08-31 21:46:05 +03005067 filterPtr = xgifb_yfilter2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305068 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005069
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305070 default:
5071 return;
5072 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005073
Aaro Koskinenb3979922012-11-04 21:14:52 +02005074 tempal = XGI330_EModeIDTable[ModeIdIndex].VB_ExtTVYFilterIndex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305075 if (tempcl == 0)
5076 index = tempal * 4;
5077 else
5078 index = tempal * 7;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005079
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305080 if ((tempcl == 0) && (tempch == 1)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005081 xgifb_reg_set(pVBInfo->Part2Port, 0x35, 0);
5082 xgifb_reg_set(pVBInfo->Part2Port, 0x36, 0);
5083 xgifb_reg_set(pVBInfo->Part2Port, 0x37, 0);
5084 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305085 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005086 xgifb_reg_set(pVBInfo->Part2Port, 0x35, filterPtr[index++]);
5087 xgifb_reg_set(pVBInfo->Part2Port, 0x36, filterPtr[index++]);
5088 xgifb_reg_set(pVBInfo->Part2Port, 0x37, filterPtr[index++]);
5089 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305090 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005091
Peter Huewe6896b942012-02-09 21:11:46 +01005092 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5093 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005094 xgifb_reg_set(pVBInfo->Part2Port, 0x48, filterPtr[index++]);
5095 xgifb_reg_set(pVBInfo->Part2Port, 0x49, filterPtr[index++]);
5096 xgifb_reg_set(pVBInfo->Part2Port, 0x4A, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305097 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005098}
5099
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005100/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005101/* Function : XGI_OEM310Setting */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005102/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005103/* Output : */
5104/* Description : Customized Param. for 301 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005105/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005106static void XGI_OEM310Setting(unsigned short ModeNo,
5107 unsigned short ModeIdIndex,
5108 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005109{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005110 XGI_SetDelayComp(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005111
Peter Huewea3d675c2012-02-09 21:11:47 +01005112 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005113 XGI_SetLCDCap(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005114
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005115 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005116 XGI_SetPhaseIncr(pVBInfo);
5117 XGI_SetYFilter(ModeNo, ModeIdIndex, pVBInfo);
5118 XGI_SetAntiFlicker(ModeNo, ModeIdIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005119
Peter Huewe6896b942012-02-09 21:11:46 +01005120 if (pVBInfo->VBType & VB_SIS301)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005121 XGI_SetEdgeEnhance(ModeNo, ModeIdIndex, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305122 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005123}
5124
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005125/* --------------------------------------------------------------------- */
5126/* Function : XGI_SetCRT2ModeRegs */
5127/* Input : */
5128/* Output : */
5129/* Description : Origin code for crt2group */
5130/* --------------------------------------------------------------------- */
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02005131static void XGI_SetCRT2ModeRegs(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305132 struct xgi_hw_device_info *HwDeviceExtension,
5133 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005134{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305135 unsigned short tempbl;
5136 short tempcl;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005137
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305138 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005139
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305140 tempah = 0;
5141 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005142 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305143 tempah &= ~0x10; /* BTRAMDAC */
5144 tempah |= 0x40; /* BTRAM */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005145
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305146 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
5147 | SetCRT2ToLCD)) {
5148 tempah = 0x40; /* BTDRAM */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005149 tempcl = pVBInfo->ModeType;
5150 tempcl -= ModeVGA;
5151 if (tempcl >= 0) {
5152 /* BT Color */
5153 tempah = (0x008 >> tempcl);
5154 if (tempah == 0)
5155 tempah = 1;
5156 tempah |= 0x040;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305157 }
5158 if (pVBInfo->VBInfo & SetInSlaveMode)
5159 tempah ^= 0x50; /* BTDAC */
5160 }
5161 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005162
Aaro Koskinen8104e322011-03-13 12:26:22 +02005163 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305164 tempah = 0x08;
5165 tempbl = 0xf0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005166
Miguel Gómeze123e462012-07-06 12:40:52 +02005167 if (pVBInfo->VBInfo & DisableCRT2Display)
5168 goto reg_and_or;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005169
Miguel Gómeze123e462012-07-06 12:40:52 +02005170 tempah = 0x00;
5171 tempbl = 0xff;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005172
Miguel Gómeze123e462012-07-06 12:40:52 +02005173 if (!(pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV |
5174 SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
5175 goto reg_and_or;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005176
Miguel Gómeze123e462012-07-06 12:40:52 +02005177 if ((pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) &&
5178 (!(pVBInfo->VBInfo & SetSimuScanMode))) {
5179 tempbl &= 0xf7;
5180 tempah |= 0x01;
5181 goto reg_and_or;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305182 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005183
Miguel Gómeze123e462012-07-06 12:40:52 +02005184 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
5185 tempbl &= 0xf7;
5186 tempah |= 0x01;
5187 }
5188
5189 if (!(pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD)))
5190 goto reg_and_or;
5191
5192 tempbl &= 0xf8;
5193 tempah = 0x01;
5194
5195 if (!(pVBInfo->VBInfo & SetInSlaveMode))
5196 tempah |= 0x02;
5197
5198 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
5199 tempah = tempah ^ 0x05;
5200 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
5201 tempah = tempah ^ 0x01;
5202 }
5203
5204 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
5205 tempah |= 0x08;
5206
5207reg_and_or:
5208 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl, tempah);
5209
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305210 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD
Peter Huewea3d675c2012-02-09 21:11:47 +01005211 | XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305212 tempah &= (~0x08);
5213 if ((pVBInfo->ModeType == ModeVGA) && (!(pVBInfo->VBInfo
5214 & SetInSlaveMode))) {
5215 tempah |= 0x010;
5216 }
5217 tempah |= 0x080;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005218
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305219 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305220 tempah |= 0x020;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005221 if (pVBInfo->VBInfo & DriverMode)
5222 tempah = tempah ^ 0x20;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305223 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005224
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005225 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D, ~0x0BF, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305226 tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005227
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305228 if (pVBInfo->LCDInfo & SetLCDDualLink)
5229 tempah |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005230
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305231 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305232 if (pVBInfo->TVInfo & RPLLDIV2XO)
5233 tempah |= 0x40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305234 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005235
Peter Huewe255aabd2012-02-09 21:11:44 +01005236 if ((pVBInfo->LCDResInfo == Panel_1280x1024)
5237 || (pVBInfo->LCDResInfo == Panel_1280x1024x75))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305238 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005239
Peter Huewe255aabd2012-02-09 21:11:44 +01005240 if (pVBInfo->LCDResInfo == Panel_1280x960)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305241 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005242
Aaro Koskinen8104e322011-03-13 12:26:22 +02005243 xgifb_reg_set(pVBInfo->Part4Port, 0x0C, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305244 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005245
Peter Huewe6896b942012-02-09 21:11:46 +01005246 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5247 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305248 tempah = 0;
5249 tempbl = 0xfb;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005250
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305251 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
5252 tempbl = 0xff;
Peter Huewea3d675c2012-02-09 21:11:47 +01005253 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305254 tempah |= 0x04; /* shampoo 0129 */
5255 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005256
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005257 xgifb_reg_and_or(pVBInfo->Part1Port, 0x13, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305258 tempah = 0x00;
5259 tempbl = 0xcf;
5260 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5261 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5262 tempah |= 0x30;
5263 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005264
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005265 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2c, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305266 tempah = 0;
5267 tempbl = 0x3f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005268
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305269 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5270 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5271 tempah |= 0xc0;
5272 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005273 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305274 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005275
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305276 tempah = 0;
5277 tempbl = 0x7f;
Peter Huewea3d675c2012-02-09 21:11:47 +01005278 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305279 tempbl = 0xff;
5280 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
5281 tempah |= 0x80;
5282 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005283
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005284 xgifb_reg_and_or(pVBInfo->Part4Port, 0x23, tempbl, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005285
Peter Huewe6896b942012-02-09 21:11:46 +01005286 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305287 if (pVBInfo->LCDInfo & SetLCDDualLink) {
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005288 xgifb_reg_or(pVBInfo->Part4Port, 0x27, 0x20);
5289 xgifb_reg_or(pVBInfo->Part4Port, 0x34, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305290 }
5291 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005292}
5293
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005294
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305295void XGI_UnLockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
5296 struct vb_device_info *pVBInfo)
5297{
5298
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005299 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2f, 0xFF, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005300
5301}
5302
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305303void XGI_LockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
5304 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005305{
5306
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005307 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2F, 0xFE, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005308
5309}
5310
Bill Pemberton80adad82010-06-17 13:10:51 -04005311unsigned char XGI_BridgeIsOn(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005312{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305313 unsigned short flag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005314
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305315 if (pVBInfo->IF_DEF_LVDS == 1) {
5316 return 1;
5317 } else {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005318 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305319 if ((flag == 1) || (flag == 2))
5320 return 1; /* 301b */
5321 else
5322 return 0;
5323 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005324}
5325
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005326unsigned short XGI_GetRatePtrCRT2(struct xgi_hw_device_info *pXGIHWDE,
5327 unsigned short ModeNo, unsigned short ModeIdIndex,
5328 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005329{
Peter Huewef2c22602013-02-03 22:54:30 +01005330 const u8 LCDARefreshIndex[] = {
5331 0x00, 0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x00 };
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005332
Peter Hueweef9a6b92013-02-03 04:08:43 +01005333 unsigned short RefreshRateTableIndex, i, index, temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005334
Aaro Koskinen58839b02011-03-13 12:26:23 +02005335 index = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005336 index = index >> pVBInfo->SelectCRT2Rate;
5337 index &= 0x0F;
5338
5339 if (pVBInfo->LCDInfo & LCDNonExpanding)
5340 index = 0;
5341
5342 if (index > 0)
5343 index--;
5344
5345 if (pVBInfo->SetFlag & ProgrammingCRT2) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005346 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005347 if (pVBInfo->IF_DEF_LVDS == 0) {
Peter Huewef2c22602013-02-03 22:54:30 +01005348 temp = LCDARefreshIndex[
5349 pVBInfo->LCDResInfo & 0x07];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005350
5351 if (index > temp)
5352 index = temp;
5353 } else {
5354 index = 0;
5355 }
5356 }
5357 }
5358
Aaro Koskinenb3979922012-11-04 21:14:52 +02005359 RefreshRateTableIndex = XGI330_EModeIDTable[ModeIdIndex].REFindex;
Aaro Koskinena39325d2012-11-04 21:14:53 +02005360 ModeNo = XGI330_RefIndex[RefreshRateTableIndex].ModeID;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005361 if (pXGIHWDE->jChipType >= XG20) { /* for XG20, XG21, XG27 */
Aaro Koskinena39325d2012-11-04 21:14:53 +02005362 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 800) &&
5363 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 600)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005364 index++;
5365 }
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005366 /* do the similar adjustment like XGISearchCRT1Rate() */
Aaro Koskinena39325d2012-11-04 21:14:53 +02005367 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 1024) &&
5368 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 768)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005369 index++;
5370 }
Aaro Koskinena39325d2012-11-04 21:14:53 +02005371 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 1280) &&
5372 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 1024)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005373 index++;
5374 }
5375 }
5376
5377 i = 0;
5378 do {
Aaro Koskinena39325d2012-11-04 21:14:53 +02005379 if (XGI330_RefIndex[RefreshRateTableIndex + i].
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005380 ModeID != ModeNo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005381 break;
Aaro Koskinena39325d2012-11-04 21:14:53 +02005382 temp = XGI330_RefIndex[RefreshRateTableIndex + i].Ext_InfoFlag;
Peter Huewe6896b942012-02-09 21:11:46 +01005383 temp &= ModeTypeMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005384 if (temp < pVBInfo->ModeType)
5385 break;
5386 i++;
5387 index--;
5388
5389 } while (index != 0xFFFF);
5390 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
5391 if (pVBInfo->VBInfo & SetInSlaveMode) {
Aaro Koskinena39325d2012-11-04 21:14:53 +02005392 temp = XGI330_RefIndex[RefreshRateTableIndex + i - 1].
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005393 Ext_InfoFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005394 if (temp & InterlaceMode)
5395 i++;
5396 }
5397 }
5398 i--;
5399 if ((pVBInfo->SetFlag & ProgrammingCRT2)) {
5400 temp = XGI_AjustCRT2Rate(ModeNo, ModeIdIndex,
5401 RefreshRateTableIndex, &i, pVBInfo);
5402 }
Aaro Koskinen9a0b2952011-11-27 23:03:16 +02005403 return RefreshRateTableIndex + i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005404}
5405
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005406static void XGI_SetLCDAGroup(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305407 struct xgi_hw_device_info *HwDeviceExtension,
5408 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005409{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005410 unsigned short RefreshRateTableIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005411
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005412 pVBInfo->SetFlag |= ProgrammingCRT2;
5413 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5414 ModeIdIndex, pVBInfo);
5415 XGI_GetLVDSResInfo(ModeNo, ModeIdIndex, pVBInfo);
5416 XGI_GetLVDSData(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5417 XGI_ModCRT1Regs(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5418 HwDeviceExtension, pVBInfo);
5419 XGI_SetLVDSRegs(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5420 XGI_SetCRT2ECLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005421}
5422
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02005423static unsigned char XGI_SetCRT2Group301(unsigned short ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005424 struct xgi_hw_device_info *HwDeviceExtension,
5425 struct vb_device_info *pVBInfo)
5426{
Peter Huewea9e29e62013-02-03 04:08:44 +01005427 unsigned short ModeIdIndex, RefreshRateTableIndex;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005428
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005429 pVBInfo->SetFlag |= ProgrammingCRT2;
5430 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
5431 pVBInfo->SelectCRT2Rate = 4;
5432 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5433 ModeIdIndex, pVBInfo);
5434 XGI_SaveCRT2Info(ModeNo, pVBInfo);
5435 XGI_GetCRT2ResInfo(ModeNo, ModeIdIndex, pVBInfo);
5436 XGI_GetCRT2Data(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5437 XGI_PreSetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
5438 RefreshRateTableIndex, pVBInfo);
5439 XGI_SetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
5440 RefreshRateTableIndex, pVBInfo);
5441 XGI_SetLockRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
5442 RefreshRateTableIndex, pVBInfo);
5443 XGI_SetGroup2(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5444 HwDeviceExtension, pVBInfo);
5445 XGI_SetLCDRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
5446 RefreshRateTableIndex, pVBInfo);
5447 XGI_SetTap4Regs(pVBInfo);
5448 XGI_SetGroup3(ModeNo, ModeIdIndex, pVBInfo);
5449 XGI_SetGroup4(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5450 HwDeviceExtension, pVBInfo);
5451 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5452 XGI_SetGroup5(ModeNo, ModeIdIndex, pVBInfo);
5453 XGI_AutoThreshold(pVBInfo);
5454 return 1;
5455}
5456
5457void XGI_SenseCRT1(struct vb_device_info *pVBInfo)
5458{
5459 unsigned char CRTCData[17] = { 0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81,
5460 0x0B, 0x3E, 0xE9, 0x0B, 0xDF, 0xE7, 0x04, 0x00, 0x00,
5461 0x05, 0x00 };
5462
5463 unsigned char SR01 = 0, SR1F = 0, SR07 = 0, SR06 = 0;
5464
5465 unsigned char CR17, CR63, SR31;
5466 unsigned short temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005467
5468 int i;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005469 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005470
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005471 /* to fix XG42 single LCD sense to CRT+LCD */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005472 xgifb_reg_set(pVBInfo->P3d4, 0x57, 0x4A);
Peter Huewe9388ad92013-02-15 20:37:10 +01005473 xgifb_reg_set(pVBInfo->P3d4, 0x53, (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005474 pVBInfo->P3d4, 0x53) | 0x02));
5475
Peter Huewe9388ad92013-02-15 20:37:10 +01005476 SR31 = xgifb_reg_get(pVBInfo->P3c4, 0x31);
5477 CR63 = xgifb_reg_get(pVBInfo->P3d4, 0x63);
5478 SR01 = xgifb_reg_get(pVBInfo->P3c4, 0x01);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005479
Aaro Koskinen8104e322011-03-13 12:26:22 +02005480 xgifb_reg_set(pVBInfo->P3c4, 0x01, (unsigned char) (SR01 & 0xDF));
5481 xgifb_reg_set(pVBInfo->P3d4, 0x63, (unsigned char) (CR63 & 0xBF));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005482
Peter Huewe9388ad92013-02-15 20:37:10 +01005483 CR17 = xgifb_reg_get(pVBInfo->P3d4, 0x17);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005484 xgifb_reg_set(pVBInfo->P3d4, 0x17, (unsigned char) (CR17 | 0x80));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005485
Peter Huewe9388ad92013-02-15 20:37:10 +01005486 SR1F = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005487 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) (SR1F | 0x04));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005488
Peter Huewe9388ad92013-02-15 20:37:10 +01005489 SR07 = xgifb_reg_get(pVBInfo->P3c4, 0x07);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005490 xgifb_reg_set(pVBInfo->P3c4, 0x07, (unsigned char) (SR07 & 0xFB));
Peter Huewe9388ad92013-02-15 20:37:10 +01005491 SR06 = xgifb_reg_get(pVBInfo->P3c4, 0x06);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005492 xgifb_reg_set(pVBInfo->P3c4, 0x06, (unsigned char) (SR06 & 0xC3));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005493
Aaro Koskinen8104e322011-03-13 12:26:22 +02005494 xgifb_reg_set(pVBInfo->P3d4, 0x11, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005495
5496 for (i = 0; i < 8; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005497 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) i, CRTCData[i]);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005498
5499 for (i = 8; i < 11; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005500 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 8),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005501 CRTCData[i]);
5502
5503 for (i = 11; i < 13; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005504 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 4),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005505 CRTCData[i]);
5506
5507 for (i = 13; i < 16; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005508 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i - 3),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005509 CRTCData[i]);
5510
Aaro Koskinen8104e322011-03-13 12:26:22 +02005511 xgifb_reg_set(pVBInfo->P3c4, 0x0E, (unsigned char) (CRTCData[16]
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005512 & 0xE0));
5513
Aaro Koskinen8104e322011-03-13 12:26:22 +02005514 xgifb_reg_set(pVBInfo->P3c4, 0x31, 0x00);
5515 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x1B);
5516 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE1);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005517
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005518 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005519
Peter Huewe771f3ee2013-02-15 20:37:13 +01005520 for (i = 0; i < 256 * 3; i++) {
5521 outb(0x0F, (pVBInfo->P3c8 + 1)); /* DAC_TEST_PARMS */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005522 }
5523
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005524 mdelay(1);
5525
5526 XGI_WaitDisply(pVBInfo);
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02005527 temp = inb(pVBInfo->P3c2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005528
5529 if (temp & 0x10)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005530 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005531 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005532 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005533
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005534 /* avoid display something, set BLACK DAC if not restore DAC */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005535 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005536
Peter Huewe771f3ee2013-02-15 20:37:13 +01005537 for (i = 0; i < 256 * 3; i++) {
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005538 outb(0, (pVBInfo->P3c8 + 1));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005539 }
5540
Aaro Koskinen8104e322011-03-13 12:26:22 +02005541 xgifb_reg_set(pVBInfo->P3c4, 0x01, SR01);
5542 xgifb_reg_set(pVBInfo->P3d4, 0x63, CR63);
5543 xgifb_reg_set(pVBInfo->P3c4, 0x31, SR31);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005544
Peter Huewe9388ad92013-02-15 20:37:10 +01005545 xgifb_reg_set(pVBInfo->P3d4, 0x53, (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005546 pVBInfo->P3d4, 0x53) & 0xFD));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005547 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) SR1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005548}
5549
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005550static void XGI_EnableBridge(struct xgifb_video_info *xgifb_info,
5551 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005552 struct vb_device_info *pVBInfo)
5553{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02005554 unsigned short tempah;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005555
Peter Huewe6896b942012-02-09 21:11:46 +01005556 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5557 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005558 if (!(pVBInfo->SetFlag & DisableChA)) {
Peter Huewe66b43eb2013-02-15 20:37:09 +01005559 if ((pVBInfo->SetFlag & EnableChA) ||
5560 (pVBInfo->VBInfo & SetCRT2ToDualEdge)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005561 /* Power on */
5562 xgifb_reg_set(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005563 }
5564 }
5565
5566 if (!(pVBInfo->SetFlag & DisableChB)) {
5567 if ((pVBInfo->SetFlag & EnableChB) || (pVBInfo->VBInfo
5568 & (SetCRT2ToLCD | SetCRT2ToTV
5569 | SetCRT2ToRAMDAC))) {
Peter Huewe9388ad92013-02-15 20:37:10 +01005570 tempah = xgifb_reg_get(pVBInfo->P3c4, 0x32);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005571 tempah &= 0xDF;
5572 if (pVBInfo->VBInfo & SetInSlaveMode) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005573 if (!(pVBInfo->VBInfo &
5574 SetCRT2ToRAMDAC))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005575 tempah |= 0x20;
5576 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02005577 xgifb_reg_set(pVBInfo->P3c4, 0x32, tempah);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005578 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005579
Peter Huewe9388ad92013-02-15 20:37:10 +01005580 tempah = xgifb_reg_get(pVBInfo->Part1Port,
5581 0x2E);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005582
5583 if (!(tempah & 0x80))
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005584 xgifb_reg_or(pVBInfo->Part1Port,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005585 0x2E, 0x80);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005586 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005587 }
5588 }
5589
5590 if ((pVBInfo->SetFlag & (EnableChA | EnableChB))
5591 || (!(pVBInfo->VBInfo & DisableCRT2Display))) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005592 xgifb_reg_and_or(pVBInfo->Part2Port, 0x00, ~0xE0,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005593 0x20); /* shampoo 0129 */
Peter Huewe6896b942012-02-09 21:11:46 +01005594 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Peter Huewe06cc47b2013-02-03 22:54:38 +01005595 if (!XGI_EnableChISLCD(pVBInfo, false)) {
5596 if (XGI_EnableChISLCD(pVBInfo, true) ||
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005597 (pVBInfo->VBInfo &
Peter Huewea3d675c2012-02-09 21:11:47 +01005598 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005599 /* LVDS PLL power on */
Aaro Koskinendc505562011-03-13 12:26:26 +02005600 xgifb_reg_and(
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005601 pVBInfo->Part4Port,
5602 0x2A,
5603 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005604 }
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005605 /* LVDS Driver power on */
5606 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005607 }
5608 }
5609
5610 tempah = 0x00;
5611
5612 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5613 tempah = 0xc0;
5614
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005615 if (!(pVBInfo->VBInfo & SetSimuScanMode) &&
5616 (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) &&
5617 (pVBInfo->VBInfo & SetCRT2ToDualEdge)) {
5618 tempah = tempah & 0x40;
5619 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
5620 tempah = tempah ^ 0xC0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005621
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005622 if (pVBInfo->SetFlag & DisableChB)
5623 tempah &= 0xBF;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005624
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005625 if (pVBInfo->SetFlag & DisableChA)
5626 tempah &= 0x7F;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005627
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005628 if (pVBInfo->SetFlag & EnableChB)
5629 tempah |= 0x40;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005630
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005631 if (pVBInfo->SetFlag & EnableChA)
5632 tempah |= 0x80;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005633 }
5634 }
5635
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005636 /* EnablePart4_1F */
5637 xgifb_reg_or(pVBInfo->Part4Port, 0x1F, tempah);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005638
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005639 if (!(pVBInfo->SetFlag & DisableChA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005640 if (!(pVBInfo->SetFlag & GatingCRT)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005641 XGI_DisableGatingCRT(HwDeviceExtension,
5642 pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005643 XGI_DisplayOn(xgifb_info, HwDeviceExtension,
5644 pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005645 }
5646 }
5647 } /* 301 */
5648 else { /* LVDS */
5649 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD
Peter Huewea3d675c2012-02-09 21:11:47 +01005650 | XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005651 /* enable CRT2 */
5652 xgifb_reg_or(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005653
Peter Huewe9388ad92013-02-15 20:37:10 +01005654 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2E);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005655 if (!(tempah & 0x80))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005656 xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005657
Aaro Koskinendc505562011-03-13 12:26:26 +02005658 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005659 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005660 } /* End of VB */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005661}
5662
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005663static void XGI_SetCRT1Group(struct xgifb_video_info *xgifb_info,
5664 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005665 unsigned short ModeNo, unsigned short ModeIdIndex,
5666 struct vb_device_info *pVBInfo)
5667{
Aaro Koskinena1579612012-04-07 01:14:05 +03005668 unsigned short RefreshRateTableIndex, temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005669
Aaro Koskinena1579612012-04-07 01:14:05 +03005670 XGI_SetSeqRegs(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinen3625c9a2012-11-04 21:14:51 +02005671 outb(XGI330_StandTable.MISC, pVBInfo->P3c2);
Aaro Koskinena1579612012-04-07 01:14:05 +03005672 XGI_SetCRTCRegs(HwDeviceExtension, pVBInfo);
5673 XGI_SetATTRegs(ModeNo, ModeIdIndex, pVBInfo);
5674 XGI_SetGRCRegs(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005675 XGI_ClearExt1Regs(pVBInfo);
5676
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005677 if (HwDeviceExtension->jChipType == XG27) {
5678 if (pVBInfo->IF_DEF_LVDS == 0)
5679 XGI_SetDefaultVCLK(pVBInfo);
5680 }
5681
5682 temp = ~ProgrammingCRT2;
5683 pVBInfo->SetFlag &= temp;
5684 pVBInfo->SelectCRT2Rate = 0;
5685
Peter Huewe6896b942012-02-09 21:11:46 +01005686 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5687 | VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005688 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005689 | SetInSlaveMode)) {
5690 pVBInfo->SetFlag |= ProgrammingCRT2;
5691 }
5692 }
5693
5694 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5695 ModeIdIndex, pVBInfo);
5696 if (RefreshRateTableIndex != 0xFFFF) {
5697 XGI_SetSync(RefreshRateTableIndex, pVBInfo);
5698 XGI_SetCRT1CRTC(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5699 pVBInfo, HwDeviceExtension);
5700 XGI_SetCRT1DE(HwDeviceExtension, ModeNo, ModeIdIndex,
5701 RefreshRateTableIndex, pVBInfo);
5702 XGI_SetCRT1Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5703 HwDeviceExtension, pVBInfo);
5704 XGI_SetCRT1VCLK(ModeNo, ModeIdIndex, HwDeviceExtension,
5705 RefreshRateTableIndex, pVBInfo);
5706 }
5707
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005708 if (HwDeviceExtension->jChipType >= XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005709 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005710 if (temp & 0xA0) {
5711
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005712 if (HwDeviceExtension->jChipType == XG27)
5713 XGI_SetXG27CRTC(ModeNo, ModeIdIndex,
5714 RefreshRateTableIndex, pVBInfo);
5715 else
5716 XGI_SetXG21CRTC(ModeNo, ModeIdIndex,
5717 RefreshRateTableIndex, pVBInfo);
5718
5719 XGI_UpdateXG21CRTC(ModeNo, pVBInfo,
5720 RefreshRateTableIndex);
5721
Aaro Koskinen105d8d02011-08-31 21:46:00 +03005722 xgifb_set_lcd(HwDeviceExtension->jChipType,
5723 pVBInfo, RefreshRateTableIndex, ModeNo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005724
Aaro Koskinen64db29f2011-08-31 21:46:01 +03005725 if (pVBInfo->IF_DEF_LVDS == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005726 xgifb_set_lvds(xgifb_info,
5727 HwDeviceExtension->jChipType,
Aaro Koskinen64db29f2011-08-31 21:46:01 +03005728 ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005729 }
5730 }
5731
5732 pVBInfo->SetFlag &= (~ProgrammingCRT2);
5733 XGI_SetCRT1FIFO(ModeNo, HwDeviceExtension, pVBInfo);
5734 XGI_SetCRT1ModeRegs(HwDeviceExtension, ModeNo, ModeIdIndex,
5735 RefreshRateTableIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005736 XGI_LoadDAC(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005737}
5738
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005739unsigned char XGISetModeNew(struct xgifb_video_info *xgifb_info,
5740 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005741 unsigned short ModeNo)
5742{
5743 unsigned short ModeIdIndex;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005744 struct vb_device_info VBINF;
5745 struct vb_device_info *pVBInfo = &VBINF;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005746 pVBInfo->IF_DEF_LVDS = 0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005747
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005748 if (HwDeviceExtension->jChipType >= XG20) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005749 pVBInfo->IF_DEF_YPbPr = 0;
5750 pVBInfo->IF_DEF_HiVision = 0;
5751 pVBInfo->IF_DEF_CRT2Monitor = 0;
5752 pVBInfo->VBType = 0; /*set VBType default 0*/
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005753 } else {
5754 pVBInfo->IF_DEF_YPbPr = 1;
5755 pVBInfo->IF_DEF_HiVision = 1;
Aaro Koskinen06587332011-03-13 12:26:10 +02005756 pVBInfo->IF_DEF_CRT2Monitor = 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005757 }
5758
Aaro Koskinen56810a92013-01-21 02:57:47 +02005759 XGIRegInit(pVBInfo, xgifb_info->vga_base);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005760
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005761 /* for x86 Linux, XG21 LVDS */
5762 if (HwDeviceExtension->jChipType == XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005763 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005764 pVBInfo->IF_DEF_LVDS = 1;
5765 }
5766 if (HwDeviceExtension->jChipType == XG27) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005767 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0) {
5768 if (xgifb_reg_get(pVBInfo->P3d4, 0x30) & 0x20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005769 pVBInfo->IF_DEF_LVDS = 1;
5770 }
5771 }
5772
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005773 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005774 XGI_GetVBType(pVBInfo);
5775
5776 InitTo330Pointer(HwDeviceExtension->jChipType, pVBInfo);
Aaro Koskinenef497f42011-11-27 23:03:21 +02005777 if (ModeNo & 0x80)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005778 ModeNo = ModeNo & 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005779 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005780
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005781 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005782 XGI_UnLockCRT2(HwDeviceExtension, pVBInfo);
5783
5784 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
5785
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005786 if (HwDeviceExtension->jChipType < XG20) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005787 XGI_GetVBInfo(ModeNo, ModeIdIndex, HwDeviceExtension, pVBInfo);
5788 XGI_GetTVInfo(ModeNo, ModeIdIndex, pVBInfo);
5789 XGI_GetLCDInfo(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005790 XGI_DisableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005791
Peter Huewee44adfd2013-02-03 22:54:39 +01005792 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA) ||
5793 (!(pVBInfo->VBInfo & SwitchCRT2))) {
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005794 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005795 ModeIdIndex, pVBInfo);
5796
Peter Huewea3d675c2012-02-09 21:11:47 +01005797 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005798 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
5799 HwDeviceExtension, pVBInfo);
5800 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005801 }
5802
Peter Huewe6896b942012-02-09 21:11:46 +01005803 if (pVBInfo->VBInfo & (SetSimuScanMode | SwitchCRT2)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005804 switch (HwDeviceExtension->ujVBChipID) {
Peter Huewee44adfd2013-02-03 22:54:39 +01005805 case VB_CHIP_301: /* fall through */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005806 case VB_CHIP_302:
5807 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
5808 pVBInfo); /*add for CRT2 */
5809 break;
5810
5811 default:
5812 break;
5813 }
5814 }
5815
5816 XGI_SetCRT2ModeRegs(ModeNo, HwDeviceExtension, pVBInfo);
5817 XGI_OEM310Setting(ModeNo, ModeIdIndex, pVBInfo); /*0212*/
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005818 XGI_EnableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005819 } /* !XG20 */
5820 else {
5821 if (pVBInfo->IF_DEF_LVDS == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005822 if (!XGI_XG21CheckLVDSMode(xgifb_info, ModeNo,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005823 ModeIdIndex,
5824 pVBInfo))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005825 return 0;
5826
Aaro Koskinenb3979922012-11-04 21:14:52 +02005827 pVBInfo->ModeType = XGI330_EModeIDTable[ModeIdIndex].
Peter Huewe6896b942012-02-09 21:11:46 +01005828 Ext_ModeFlag & ModeTypeMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005829
5830 pVBInfo->SetFlag = 0;
Aaro Koskinen83f76a92011-08-31 21:45:58 +03005831 pVBInfo->VBInfo = DisableCRT2Display;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005832
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005833 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005834
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005835 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
5836 ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005837
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005838 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005839 }
5840
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005841 XGI_UpdateModeInfo(HwDeviceExtension, pVBInfo);
5842
Miguel Gómez3bcc2462012-07-06 12:40:53 +02005843 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005844 XGI_LockCRT2(HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005845
5846 return 1;
5847}