blob: f5a9bb2e5473c5eaf036a32fd732c4a18c6d071e [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
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053035 pVBInfo->SR15 = XGI340_SR13;
36 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;
Dmitry Eremin-Solenikov64903112012-03-19 21:50:09 +040052 pVBInfo->SR15 = XG27_SR13;
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 Huewe9388ad92013-02-15 20:37:10 +01001781 tempal = inb((pVBInfo->P3ca + 0x02));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001782 tempal = tempal >> 2;
1783 tempal &= 0x03;
1784
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001785 /* for Dot8 Scaling LCD */
1786 if ((pVBInfo->LCDInfo & EnableScalingLCD) && (modeflag & Charx8Dot))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001787 tempal = tempal ^ tempal; /* ; set to VCLK25MHz always */
1788
Aaro Koskinena39325d2012-11-04 21:14:53 +02001789 tempal = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001790 return tempal;
1791}
1792
1793static void XGI_GetVCLKLen(unsigned char tempal, unsigned char *di_0,
1794 unsigned char *di_1, struct vb_device_info *pVBInfo)
1795{
Peter Huewe6896b942012-02-09 21:11:46 +01001796 if (pVBInfo->VBType & (VB_SIS301 | VB_SIS301B | VB_SIS302B
1797 | VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +02001798 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) &&
1799 (pVBInfo->SetFlag & ProgrammingCRT2)) {
Aaro Koskinene8cb03d2012-09-11 00:15:31 +03001800 *di_0 = XGI_VBVCLKData[tempal].Part4_A;
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +03001801 *di_1 = XGI_VBVCLKData[tempal].Part4_B;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001802 }
1803 } else {
1804 *di_0 = XGI_VCLKData[tempal].SR2B;
1805 *di_1 = XGI_VCLKData[tempal].SR2C;
1806 }
1807}
1808
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001809static void XGI_SetCRT2ECLK(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301810 unsigned short RefreshRateTableIndex,
1811 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001812{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301813 unsigned char di_0, di_1, tempal;
1814 int i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001815
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301816 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
1817 pVBInfo);
1818 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
1819 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001820
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301821 for (i = 0; i < 4; i++) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001822 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, ~0x30,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301823 (unsigned short) (0x10 * i));
Peter Huewea3d675c2012-02-09 21:11:47 +01001824 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301825 && (!(pVBInfo->VBInfo & SetInSlaveMode))) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001826 xgifb_reg_set(pVBInfo->P3c4, 0x2e, di_0);
1827 xgifb_reg_set(pVBInfo->P3c4, 0x2f, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301828 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001829 xgifb_reg_set(pVBInfo->P3c4, 0x2b, di_0);
1830 xgifb_reg_set(pVBInfo->P3c4, 0x2c, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301831 }
1832 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001833}
1834
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001835static void XGI_UpdateModeInfo(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301836 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001837{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301838 unsigned short tempcl, tempch, temp, tempbl, tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001839
Peter Huewe6896b942012-02-09 21:11:46 +01001840 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
1841 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301842 tempcl = 0;
1843 tempch = 0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02001844 temp = xgifb_reg_get(pVBInfo->P3c4, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001845
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301846 if (!(temp & 0x20)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001847 temp = xgifb_reg_get(pVBInfo->P3d4, 0x17);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301848 if (temp & 0x80) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001849 temp = xgifb_reg_get(pVBInfo->P3d4, 0x53);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301850 if (!(temp & 0x40))
1851 tempcl |= ActiveCRT1;
1852 }
1853 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001854
Aaro Koskinen58839b02011-03-13 12:26:23 +02001855 temp = xgifb_reg_get(pVBInfo->Part1Port, 0x2e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301856 temp &= 0x0f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001857
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301858 if (!(temp == 0x08)) {
Miguel Gómez949eb0a2012-07-06 12:40:36 +02001859 /* Check ChannelA */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001860 tempax = xgifb_reg_get(pVBInfo->Part1Port, 0x13);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301861 if (tempax & 0x04)
1862 tempcl = tempcl | ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001863
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301864 temp &= 0x05;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001865
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301866 if (!(tempcl & ActiveLCD))
1867 if (temp == 0x01)
1868 tempcl |= ActiveCRT2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001869
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301870 if (temp == 0x04)
1871 tempcl |= ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001872
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301873 if (temp == 0x05) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001874 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001875
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301876 if (!(temp & 0x08))
1877 tempch |= ActiveAVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001878
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301879 if (!(temp & 0x04))
1880 tempch |= ActiveSVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001881
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301882 if (temp & 0x02)
1883 tempch |= ActiveSCART;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001884
Peter Huewe599801f2012-02-09 21:11:45 +01001885 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301886 if (temp & 0x01)
1887 tempch |= ActiveHiTV;
1888 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001889
Peter Huewe599801f2012-02-09 21:11:45 +01001890 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001891 temp = xgifb_reg_get(
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301892 pVBInfo->Part2Port,
1893 0x4d);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001894
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301895 if (temp & 0x10)
1896 tempch |= ActiveYPbPr;
1897 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001898
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301899 if (tempch != 0)
1900 tempcl |= ActiveTV;
1901 }
1902 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001903
Aaro Koskinen58839b02011-03-13 12:26:23 +02001904 temp = xgifb_reg_get(pVBInfo->P3d4, 0x3d);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301905 if (tempcl & ActiveLCD) {
1906 if ((pVBInfo->SetFlag & ReserveTVOption)) {
1907 if (temp & ActiveTV)
1908 tempcl |= ActiveTV;
1909 }
1910 }
1911 temp = tempcl;
Peter Huewea3d675c2012-02-09 21:11:47 +01001912 tempbl = ~XGI_ModeSwitchStatus;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001913 xgifb_reg_and_or(pVBInfo->P3d4, 0x3d, tempbl, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001914
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301915 if (!(pVBInfo->SetFlag & ReserveTVOption))
Aaro Koskinen8104e322011-03-13 12:26:22 +02001916 xgifb_reg_set(pVBInfo->P3d4, 0x3e, tempch);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301917 } else {
1918 return;
1919 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001920}
1921
Bill Pemberton80adad82010-06-17 13:10:51 -04001922void XGI_GetVBType(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001923{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301924 unsigned short flag, tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001925
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001926 if (pVBInfo->IF_DEF_LVDS != 0)
1927 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001928
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001929 tempbx = VB_SIS302B;
1930 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
1931 if (flag == 0x02)
1932 goto finish;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001933
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001934 tempbx = VB_SIS301;
1935 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x01);
1936 if (flag < 0xB0)
1937 goto finish;
1938
1939 tempbx = VB_SIS301B;
1940 if (flag < 0xC0)
1941 goto bigger_than_0xB0;
1942
1943 tempbx = VB_XGI301C;
1944 if (flag < 0xD0)
1945 goto bigger_than_0xB0;
1946
1947 tempbx = VB_SIS301LV;
1948 if (flag < 0xE0)
1949 goto bigger_than_0xB0;
1950
1951 tempbx = VB_SIS302LV;
1952 tempah = xgifb_reg_get(pVBInfo->Part4Port, 0x39);
1953 if (tempah != 0xFF)
1954 tempbx = VB_XGI301C;
1955
1956bigger_than_0xB0:
1957 if (tempbx & (VB_SIS301B | VB_SIS302B)) {
1958 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x23);
1959 if (!(flag & 0x02))
1960 tempbx = tempbx | VB_NoLCD;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301961 }
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001962
1963finish:
1964 pVBInfo->VBType = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001965}
1966
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02001967static void XGI_GetVBInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301968 struct xgi_hw_device_info *HwDeviceExtension,
1969 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001970{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301971 unsigned short tempax, push, tempbx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001972
Aaro Koskinenb3979922012-11-04 21:14:52 +02001973 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301974 pVBInfo->SetFlag = 0;
Peter Huewe6896b942012-02-09 21:11:46 +01001975 pVBInfo->ModeType = modeflag & ModeTypeMask;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301976 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001977
Miguel Gómezf9317352012-07-06 12:40:48 +02001978 if (!(pVBInfo->VBType & 0xFFFF))
1979 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001980
Miguel Gómezf9317352012-07-06 12:40:48 +02001981 /* Check Display Device */
1982 temp = xgifb_reg_get(pVBInfo->P3d4, 0x30);
1983 tempbx = tempbx | temp;
1984 temp = xgifb_reg_get(pVBInfo->P3d4, 0x31);
1985 push = temp;
1986 push = push << 8;
1987 tempax = temp << 8;
1988 tempbx = tempbx | tempax;
1989 temp = (SetCRT2ToDualEdge | SetCRT2ToYPbPr525750 | XGI_SetCRT2ToLCDA
1990 | SetInSlaveMode | DisableCRT2Display);
1991 temp = 0xFFFF ^ temp;
1992 tempbx &= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001993
Miguel Gómezf9317352012-07-06 12:40:48 +02001994 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001995
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001996 if (pVBInfo->VBType & (VB_SIS302B | VB_SIS301LV | VB_SIS302LV |
1997 VB_XGI301C)) {
1998 if (temp & EnableDualEdge) {
1999 tempbx |= SetCRT2ToDualEdge;
2000 if (temp & SetToLCDA)
2001 tempbx |= XGI_SetCRT2ToLCDA;
Miguel Gómezf9317352012-07-06 12:40:48 +02002002 }
2003 }
2004
2005 if (pVBInfo->IF_DEF_YPbPr == 1) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002006 if (pVBInfo->VBType & (VB_SIS301LV|VB_SIS302LV|VB_XGI301C)) {
Miguel Gómezf9317352012-07-06 12:40:48 +02002007 if (temp & SetYPbPr) {
2008 if (pVBInfo->IF_DEF_HiVision == 1) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002009 /* shampoo add for new scratch */
2010 temp = xgifb_reg_get(pVBInfo->P3d4,
2011 0x35);
Miguel Gómezf9317352012-07-06 12:40:48 +02002012 temp &= YPbPrMode;
2013 tempbx |= SetCRT2ToHiVision;
2014
2015 if (temp != YPbPrMode1080i) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002016 tempbx &= (~SetCRT2ToHiVision);
2017 tempbx |= SetCRT2ToYPbPr525750;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302018 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302019 }
2020 }
2021 }
Miguel Gómezf9317352012-07-06 12:40:48 +02002022 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002023
Miguel Gómezf9317352012-07-06 12:40:48 +02002024 tempax = push; /* restore CR31 */
2025
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002026 if (pVBInfo->IF_DEF_YPbPr == 1) {
2027 if (pVBInfo->IF_DEF_HiVision == 1)
2028 temp = 0x09FC;
2029 else
2030 temp = 0x097C;
2031 } else if (pVBInfo->IF_DEF_HiVision == 1) {
2032 temp = 0x01FC;
2033 } else {
2034 temp = 0x017C;
Miguel Gómezf9317352012-07-06 12:40:48 +02002035 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002036
Miguel Gómezf9317352012-07-06 12:40:48 +02002037 if (!(tempbx & temp)) {
2038 tempax |= DisableCRT2Display;
2039 tempbx = 0;
2040 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002041
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03002042 if (!(pVBInfo->VBType & VB_NoLCD)) {
2043 if (tempbx & XGI_SetCRT2ToLCDA) {
2044 if (tempbx & SetSimuScanMode)
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002045 tempbx &= (~(SetCRT2ToLCD | SetCRT2ToRAMDAC |
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03002046 SwitchCRT2));
2047 else
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002048 tempbx &= (~(SetCRT2ToLCD | SetCRT2ToRAMDAC |
2049 SetCRT2ToTV | SwitchCRT2));
Miguel Gómezf9317352012-07-06 12:40:48 +02002050 }
2051 }
2052
2053 /* shampoo add */
2054 /* for driver abnormal */
2055 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode))) {
2056 if (pVBInfo->IF_DEF_CRT2Monitor == 1) {
2057 if (tempbx & SetCRT2ToRAMDAC) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002058 tempbx &= (0xFF00 | SetCRT2ToRAMDAC |
2059 SwitchCRT2 | SetSimuScanMode);
Peter Huewe599801f2012-02-09 21:11:45 +01002060 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302061 }
Miguel Gómezf9317352012-07-06 12:40:48 +02002062 } else {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002063 tempbx &= (~(SetCRT2ToRAMDAC | SetCRT2ToLCD |
Miguel Gómezf9317352012-07-06 12:40:48 +02002064 SetCRT2ToTV));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302065 }
Miguel Gómezf9317352012-07-06 12:40:48 +02002066 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002067
Miguel Gómezf9317352012-07-06 12:40:48 +02002068 if (!(pVBInfo->VBType & VB_NoLCD)) {
2069 if (tempbx & SetCRT2ToLCD) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002070 tempbx &= (0xFF00 | SetCRT2ToLCD | SwitchCRT2 |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002071 SetSimuScanMode);
Peter Huewe599801f2012-02-09 21:11:45 +01002072 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302073 }
Miguel Gómezf9317352012-07-06 12:40:48 +02002074 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002075
Miguel Gómezf9317352012-07-06 12:40:48 +02002076 if (tempbx & SetCRT2ToSCART) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002077 tempbx &= (0xFF00 | SetCRT2ToSCART | SwitchCRT2 |
Miguel Gómezf9317352012-07-06 12:40:48 +02002078 SetSimuScanMode);
2079 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
2080 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002081
Miguel Gómezf9317352012-07-06 12:40:48 +02002082 if (pVBInfo->IF_DEF_YPbPr == 1) {
2083 if (tempbx & SetCRT2ToYPbPr525750)
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002084 tempbx &= (0xFF00 | SwitchCRT2 | SetSimuScanMode);
Miguel Gómezf9317352012-07-06 12:40:48 +02002085 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002086
Miguel Gómezf9317352012-07-06 12:40:48 +02002087 if (pVBInfo->IF_DEF_HiVision == 1) {
2088 if (tempbx & SetCRT2ToHiVision)
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002089 tempbx &= (0xFF00 | SetCRT2ToHiVision | SwitchCRT2 |
Miguel Gómezf9317352012-07-06 12:40:48 +02002090 SetSimuScanMode);
2091 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002092
Miguel Gómezf9317352012-07-06 12:40:48 +02002093 if (tempax & DisableCRT2Display) { /* Set Display Device Info */
2094 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode)))
2095 tempbx = DisableCRT2Display;
2096 }
2097
2098 if (!(tempbx & DisableCRT2Display)) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002099 if ((!(tempbx & DriverMode)) || (!(modeflag & CRT2Mode))) {
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03002100 if (!(tempbx & XGI_SetCRT2ToLCDA))
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002101 tempbx |= (SetInSlaveMode | SetSimuScanMode);
Miguel Gómezf9317352012-07-06 12:40:48 +02002102 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002103
Miguel Gómezf9317352012-07-06 12:40:48 +02002104 /* LCD+TV can't support in slave mode
2105 * (Force LCDA+TV->LCDB) */
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002106 if ((tempbx & SetInSlaveMode) && (tempbx & XGI_SetCRT2ToLCDA)) {
2107 tempbx ^= (SetCRT2ToLCD | XGI_SetCRT2ToLCDA |
Miguel Gómezf9317352012-07-06 12:40:48 +02002108 SetCRT2ToDualEdge);
2109 pVBInfo->SetFlag |= ReserveTVOption;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302110 }
2111 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002112
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302113 pVBInfo->VBInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002114}
2115
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02002116static void XGI_GetTVInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302117 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002118{
Peter Huewe5fc699f2013-02-03 04:08:45 +01002119 unsigned short tempbx = 0, resinfo = 0, modeflag, index1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002120
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302121 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinenb3979922012-11-04 21:14:52 +02002122 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2123 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002124
Peter Huewe5fc699f2013-02-03 04:08:45 +01002125 tempbx = xgifb_reg_get(pVBInfo->P3d4, 0x35);
2126 if (tempbx & TVSetPAL) {
2127 tempbx &= (SetCHTVOverScan |
2128 TVSetPALM |
2129 TVSetPALN |
2130 TVSetPAL);
2131 if (tempbx & TVSetPALM)
2132 /* set to NTSC if PAL-M */
2133 tempbx &= ~TVSetPAL;
2134 } else
2135 tempbx &= (SetCHTVOverScan |
2136 TVSetNTSCJ |
2137 TVSetPAL);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002138
Aaro Koskinena8b35292013-02-09 00:03:45 +02002139 if (pVBInfo->VBInfo & SetCRT2ToSCART)
2140 tempbx |= TVSetPAL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002141
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302142 if (pVBInfo->IF_DEF_YPbPr == 1) {
Peter Huewe599801f2012-02-09 21:11:45 +01002143 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002144 index1 = xgifb_reg_get(pVBInfo->P3d4, 0x35);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302145 index1 &= YPbPrMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002146
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302147 if (index1 == YPbPrMode525i)
Peter Huewe599801f2012-02-09 21:11:45 +01002148 tempbx |= TVSetYPbPr525i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002149
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302150 if (index1 == YPbPrMode525p)
Peter Huewe599801f2012-02-09 21:11:45 +01002151 tempbx = tempbx | TVSetYPbPr525p;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302152 if (index1 == YPbPrMode750p)
Peter Huewe599801f2012-02-09 21:11:45 +01002153 tempbx = tempbx | TVSetYPbPr750p;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302154 }
2155 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002156
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302157 if (pVBInfo->IF_DEF_HiVision == 1) {
Peter Huewe599801f2012-02-09 21:11:45 +01002158 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
2159 tempbx = tempbx | TVSetHiVision | TVSetPAL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302160 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002161
Aaro Koskinena8b35292013-02-09 00:03:45 +02002162 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
2163 (!(pVBInfo->VBInfo & SetNotSimuMode)))
2164 tempbx |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002165
Aaro Koskinena8b35292013-02-09 00:03:45 +02002166 if (!(tempbx & TVSetPAL) && (modeflag > 13) && (resinfo == 8))
2167 /* NTSC 1024x768, */
2168 tempbx |= NTSC1024x768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002169
Aaro Koskinena8b35292013-02-09 00:03:45 +02002170 tempbx |= RPLLDIV2XO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002171
Aaro Koskinena8b35292013-02-09 00:03:45 +02002172 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
2173 if (pVBInfo->VBInfo & SetInSlaveMode)
2174 tempbx &= (~RPLLDIV2XO);
2175 } else if (tempbx & (TVSetYPbPr525p | TVSetYPbPr750p)) {
2176 tempbx &= (~RPLLDIV2XO);
2177 } else if (!(pVBInfo->VBType & (VB_SIS301B | VB_SIS302B |
2178 VB_SIS301LV | VB_SIS302LV |
2179 VB_XGI301C))) {
2180 if (tempbx & TVSimuMode)
2181 tempbx &= (~RPLLDIV2XO);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302182 }
2183 }
2184 pVBInfo->TVInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002185}
2186
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02002187static unsigned char XGI_GetLCDInfo(unsigned short ModeNo,
2188 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002189{
Peter Hueweef9a6b92013-02-03 04:08:43 +01002190 unsigned short temp, tempax, tempbx, resinfo = 0, LCDIdIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002191
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302192 pVBInfo->LCDResInfo = 0;
2193 pVBInfo->LCDTypeInfo = 0;
2194 pVBInfo->LCDInfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002195
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002196 /* si+Ext_ResInfo // */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002197 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinen58839b02011-03-13 12:26:23 +02002198 temp = xgifb_reg_get(pVBInfo->P3d4, 0x36); /* Get LCD Res.Info */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302199 tempbx = temp & 0x0F;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002200
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302201 if (tempbx == 0)
Peter Huewe255aabd2012-02-09 21:11:44 +01002202 tempbx = Panel_1024x768; /* default */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002203
Miguel Gómez949eb0a2012-07-06 12:40:36 +02002204 /* LCD75 */
Peter Huewe255aabd2012-02-09 21:11:44 +01002205 if ((tempbx == Panel_1024x768) || (tempbx == Panel_1280x1024)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302206 if (pVBInfo->VBInfo & DriverMode) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002207 tempax = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Peter Huewea3d675c2012-02-09 21:11:47 +01002208 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302209 tempax &= 0x0F;
2210 else
2211 tempax = tempax >> 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002212
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302213 if ((resinfo == 6) || (resinfo == 9)) {
2214 if (tempax >= 3)
2215 tempbx |= PanelRef75Hz;
2216 } else if ((resinfo == 7) || (resinfo == 8)) {
2217 if (tempax >= 4)
2218 tempbx |= PanelRef75Hz;
2219 }
2220 }
2221 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002222
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302223 pVBInfo->LCDResInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002224
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302225 /* End of LCD75 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002226
Peter Huewea3d675c2012-02-09 21:11:47 +01002227 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302228 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002229
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302230 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002231
Aaro Koskinen58839b02011-03-13 12:26:23 +02002232 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002233
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302234 temp &= (ScalingLCD | LCDNonExpanding | LCDSyncBit | SetPWDEnable);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002235
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302236 tempbx |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002237
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302238 LCDIdIndex = XGI_GetLCDCapPtr1(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002239
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302240 tempax = pVBInfo->LCDCapList[LCDIdIndex].LCD_Capability;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002241
Aaro Koskinen718e7152013-02-09 00:03:46 +02002242 if (((pVBInfo->VBType & VB_SIS302LV) ||
2243 (pVBInfo->VBType & VB_XGI301C)) && (tempax & XGI_LCDDualLink))
2244 tempbx |= SetLCDDualLink;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002245
Aaro Koskinen718e7152013-02-09 00:03:46 +02002246 if ((pVBInfo->LCDResInfo == Panel_1400x1050) &&
2247 (pVBInfo->VBInfo & SetCRT2ToLCD) && (resinfo == 9) &&
2248 (!(tempbx & EnableScalingLCD)))
2249 /*
2250 * set to center in 1280x1024 LCDB
2251 * for Panel_1400x1050
2252 */
2253 tempbx |= SetLCDtoNonExpanding;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002254
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302255 if (pVBInfo->VBInfo & SetInSlaveMode) {
2256 if (pVBInfo->VBInfo & SetNotSimuMode)
Peter Huewea3d675c2012-02-09 21:11:47 +01002257 tempbx |= XGI_LCDVESATiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302258 } else {
Peter Huewea3d675c2012-02-09 21:11:47 +01002259 tempbx |= XGI_LCDVESATiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302260 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002261
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302262 pVBInfo->LCDInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002263
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302264 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002265}
2266
Bill Pemberton108afbf2010-06-17 13:10:47 -04002267unsigned char XGI_SearchModeID(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302268 unsigned short *ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002269{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002270 for (*ModeIdIndex = 0;; (*ModeIdIndex)++) {
Aaro Koskinenb3979922012-11-04 21:14:52 +02002271 if (XGI330_EModeIDTable[*ModeIdIndex].Ext_ModeID == ModeNo)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002272 break;
Aaro Koskinenb3979922012-11-04 21:14:52 +02002273 if (XGI330_EModeIDTable[*ModeIdIndex].Ext_ModeID == 0xFF)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002274 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302275 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002276
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302277 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002278}
2279
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002280static unsigned char XG21GPIODataTransfer(unsigned char ujDate)
2281{
2282 unsigned char ujRet = 0;
2283 unsigned char i = 0;
2284
2285 for (i = 0; i < 8; i++) {
2286 ujRet = ujRet << 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002287 ujRet |= (ujDate >> i) & 1;
2288 }
2289
2290 return ujRet;
2291}
2292
2293/*----------------------------------------------------------------------------*/
2294/* output */
2295/* bl[5] : LVDS signal */
2296/* bl[1] : LVDS backlight */
2297/* bl[0] : LVDS VDD */
2298/*----------------------------------------------------------------------------*/
2299static unsigned char XGI_XG21GetPSCValue(struct vb_device_info *pVBInfo)
2300{
2301 unsigned char CR4A, temp;
2302
Aaro Koskinen58839b02011-03-13 12:26:23 +02002303 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02002304 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x23); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002305
Aaro Koskinen58839b02011-03-13 12:26:23 +02002306 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002307
2308 temp = XG21GPIODataTransfer(temp);
2309 temp &= 0x23;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002310 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002311 return temp;
2312}
2313
2314/*----------------------------------------------------------------------------*/
2315/* output */
2316/* bl[5] : LVDS signal */
2317/* bl[1] : LVDS backlight */
2318/* bl[0] : LVDS VDD */
2319/*----------------------------------------------------------------------------*/
2320static unsigned char XGI_XG27GetPSCValue(struct vb_device_info *pVBInfo)
2321{
2322 unsigned char CR4A, CRB4, temp;
2323
Aaro Koskinen58839b02011-03-13 12:26:23 +02002324 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02002325 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x0C); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002326
Aaro Koskinen58839b02011-03-13 12:26:23 +02002327 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002328
2329 temp &= 0x0C;
2330 temp >>= 2;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002331 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinen58839b02011-03-13 12:26:23 +02002332 CRB4 = xgifb_reg_get(pVBInfo->P3d4, 0xB4);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002333 temp |= ((CRB4 & 0x04) << 3);
2334 return temp;
2335}
2336
Aaro Koskinen0ebf5382011-11-27 23:03:09 +02002337/*----------------------------------------------------------------------------*/
2338/* input */
2339/* bl[5] : 1;LVDS signal on */
2340/* bl[1] : 1;LVDS backlight on */
2341/* bl[0] : 1:LVDS VDD on */
2342/* bh: 100000b : clear bit 5, to set bit5 */
2343/* 000010b : clear bit 1, to set bit1 */
2344/* 000001b : clear bit 0, to set bit0 */
2345/*----------------------------------------------------------------------------*/
2346static void XGI_XG21BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
2347 struct vb_device_info *pVBInfo)
2348{
2349 unsigned char CR4A, temp;
2350
2351 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
2352 tempbh &= 0x23;
2353 tempbl &= 0x23;
2354 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
2355
2356 if (tempbh & 0x20) {
2357 temp = (tempbl >> 4) & 0x02;
2358
2359 /* CR B4[1] */
2360 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
2361
2362 }
2363
2364 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
2365
2366 temp = XG21GPIODataTransfer(temp);
2367 temp &= ~tempbh;
2368 temp |= tempbl;
2369 xgifb_reg_set(pVBInfo->P3d4, 0x48, temp);
2370}
2371
Aaro Koskinen776115a2011-11-27 23:03:10 +02002372static void XGI_XG27BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
2373 struct vb_device_info *pVBInfo)
2374{
2375 unsigned char CR4A, temp;
2376 unsigned short tempbh0, tempbl0;
2377
2378 tempbh0 = tempbh;
2379 tempbl0 = tempbl;
2380 tempbh0 &= 0x20;
2381 tempbl0 &= 0x20;
2382 tempbh0 >>= 3;
2383 tempbl0 >>= 3;
2384
2385 if (tempbh & 0x20) {
2386 temp = (tempbl >> 4) & 0x02;
2387
2388 /* CR B4[1] */
2389 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
2390
2391 }
2392 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~tempbh0, tempbl0);
2393
2394 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
2395 tempbh &= 0x03;
2396 tempbl &= 0x03;
2397 tempbh <<= 2;
2398 tempbl <<= 2; /* GPIOC,GPIOD */
2399 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
2400 xgifb_reg_and_or(pVBInfo->P3d4, 0x48, ~tempbh, tempbl);
2401}
2402
Aaro Koskinenfab04b92011-12-06 00:10:45 +02002403static void XGI_DisplayOn(struct xgifb_video_info *xgifb_info,
2404 struct xgi_hw_device_info *pXGIHWDE,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302405 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002406{
2407
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002408 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302409 if (pXGIHWDE->jChipType == XG21) {
2410 if (pVBInfo->IF_DEF_LVDS == 1) {
2411 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002412 /* LVDS VDD on */
2413 XGI_XG21BLSignalVDD(0x01, 0x01, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002414 mdelay(xgifb_info->lvds_data.PSC_S2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302415 }
2416 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002417 /* LVDS signal on */
2418 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002419 mdelay(xgifb_info->lvds_data.PSC_S3);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002420 /* LVDS backlight on */
2421 XGI_XG21BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302422 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002423 /* DVO/DVI signal on */
2424 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302425 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002426
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302427 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002428
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302429 if (pXGIHWDE->jChipType == XG27) {
2430 if (pVBInfo->IF_DEF_LVDS == 1) {
2431 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002432 /* LVDS VDD on */
2433 XGI_XG27BLSignalVDD(0x01, 0x01, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002434 mdelay(xgifb_info->lvds_data.PSC_S2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302435 }
2436 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002437 /* LVDS signal on */
2438 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002439 mdelay(xgifb_info->lvds_data.PSC_S3);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002440 /* LVDS backlight on */
2441 XGI_XG27BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302442 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002443 /* DVO/DVI signal on */
2444 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302445 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002446
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302447 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002448}
2449
Aaro Koskinenfab04b92011-12-06 00:10:45 +02002450void XGI_DisplayOff(struct xgifb_video_info *xgifb_info,
2451 struct xgi_hw_device_info *pXGIHWDE,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302452 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002453{
2454
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302455 if (pXGIHWDE->jChipType == XG21) {
2456 if (pVBInfo->IF_DEF_LVDS == 1) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002457 /* LVDS backlight off */
2458 XGI_XG21BLSignalVDD(0x02, 0x00, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002459 mdelay(xgifb_info->lvds_data.PSC_S3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302460 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002461 /* DVO/DVI signal off */
2462 XGI_XG21BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302463 }
2464 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002465
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302466 if (pXGIHWDE->jChipType == XG27) {
2467 if ((XGI_XG27GetPSCValue(pVBInfo) & 0x2)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002468 /* LVDS backlight off */
2469 XGI_XG27BLSignalVDD(0x02, 0x00, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002470 mdelay(xgifb_info->lvds_data.PSC_S3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302471 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002472
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302473 if (pVBInfo->IF_DEF_LVDS == 0)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002474 /* DVO/DVI signal off */
2475 XGI_XG27BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302476 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002477
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002478 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x20);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002479}
2480
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002481static void XGI_WaitDisply(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002482{
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02002483 while ((inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302484 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002485
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02002486 while (!(inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302487 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002488}
2489
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002490static void XGI_AutoThreshold(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002491{
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002492 xgifb_reg_or(pVBInfo->Part1Port, 0x01, 0x40);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002493}
2494
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002495static void XGI_SaveCRT2Info(unsigned short ModeNo,
2496 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002497{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302498 unsigned short temp1, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002499
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002500 /* reserve CR34 for CRT1 Mode No */
2501 xgifb_reg_set(pVBInfo->P3d4, 0x34, ModeNo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302502 temp1 = (pVBInfo->VBInfo & SetInSlaveMode) >> 8;
2503 temp2 = ~(SetInSlaveMode >> 8);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002504 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, temp2, temp1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002505}
2506
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002507static void XGI_GetCRT2ResInfo(unsigned short ModeNo,
2508 unsigned short ModeIdIndex,
2509 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002510{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302511 unsigned short xres, yres, modeflag, resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002512
Aaro Koskinenb3979922012-11-04 21:14:52 +02002513 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02002514 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
2515 yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002516 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002517 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002518
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002519 if (modeflag & HalfDCLK)
2520 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002521
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002522 if (modeflag & DoubleScanMode)
2523 yres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002524
Miguel Gómez3339db82012-07-06 12:40:49 +02002525 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
2526 goto exit;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002527
Aaro Koskinen22006832013-02-09 00:03:47 +02002528 if (pVBInfo->LCDResInfo == Panel_1600x1200) {
2529 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
2530 if (yres == 1024)
2531 yres = 1056;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302532 }
Aaro Koskinen22006832013-02-09 00:03:47 +02002533 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002534
Aaro Koskinen22006832013-02-09 00:03:47 +02002535 if (pVBInfo->LCDResInfo == Panel_1280x1024) {
2536 if (yres == 400)
2537 yres = 405;
2538 else if (yres == 350)
2539 yres = 360;
Miguel Gómez3339db82012-07-06 12:40:49 +02002540
Aaro Koskinen22006832013-02-09 00:03:47 +02002541 if (pVBInfo->LCDInfo & XGI_LCDVESATiming) {
2542 if (yres == 360)
2543 yres = 375;
Miguel Gómez3339db82012-07-06 12:40:49 +02002544 }
Aaro Koskinen22006832013-02-09 00:03:47 +02002545 }
Miguel Gómez3339db82012-07-06 12:40:49 +02002546
Aaro Koskinen22006832013-02-09 00:03:47 +02002547 if (pVBInfo->LCDResInfo == Panel_1024x768) {
2548 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
2549 if (!(pVBInfo->LCDInfo & LCDNonExpanding)) {
2550 if (yres == 350)
2551 yres = 357;
2552 else if (yres == 400)
2553 yres = 420;
2554 else if (yres == 480)
2555 yres = 525;
Miguel Gómez3339db82012-07-06 12:40:49 +02002556 }
2557 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302558 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002559
Miguel Gómez3339db82012-07-06 12:40:49 +02002560 if (xres == 720)
2561 xres = 640;
2562
2563exit:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302564 pVBInfo->VGAHDE = xres;
2565 pVBInfo->HDE = xres;
2566 pVBInfo->VGAVDE = yres;
2567 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002568}
2569
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002570static unsigned char XGI_IsLCDDualLink(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002571{
2572
Peter Huewea3d675c2012-02-09 21:11:47 +01002573 if ((pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) &&
Dan Carpentera65fd092011-01-04 09:02:27 +03002574 (pVBInfo->LCDInfo & SetLCDDualLink)) /* shampoo0129 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302575 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002576
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302577 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002578}
2579
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002580static void XGI_GetRAMDAC2DATA(unsigned short ModeNo,
2581 unsigned short ModeIdIndex,
2582 unsigned short RefreshRateTableIndex,
2583 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002584{
2585 unsigned short tempax, tempbx, temp1, temp2, modeflag = 0, tempcx,
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002586 CRT1Index;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002587
2588 pVBInfo->RVBHCMAX = 1;
2589 pVBInfo->RVBHCFACT = 1;
Aaro Koskinenb3979922012-11-04 21:14:52 +02002590 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02002591 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002592 CRT1Index &= IndexMask;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002593 temp1 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[0];
2594 temp2 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[5];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002595 tempax = (temp1 & 0xFF) | ((temp2 & 0x03) << 8);
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002596 tempbx = (unsigned short) XGI_CRT1Table[CRT1Index].CR[8];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002597 tempcx = (unsigned short)
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002598 XGI_CRT1Table[CRT1Index].CR[14] << 8;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002599 tempcx &= 0x0100;
2600 tempcx = tempcx << 2;
2601 tempbx |= tempcx;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002602 temp1 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[9];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002603
2604 if (temp1 & 0x01)
2605 tempbx |= 0x0100;
2606
2607 if (temp1 & 0x20)
2608 tempbx |= 0x0200;
2609 tempax += 5;
2610
2611 if (modeflag & Charx8Dot)
2612 tempax *= 8;
2613 else
2614 tempax *= 9;
2615
2616 pVBInfo->VGAHT = tempax;
2617 pVBInfo->HT = tempax;
2618 tempbx++;
2619 pVBInfo->VGAVT = tempbx;
2620 pVBInfo->VT = tempbx;
2621}
2622
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002623static void XGI_GetCRT2Data(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302624 unsigned short RefreshRateTableIndex,
2625 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002626{
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02002627 unsigned short tempax = 0, tempbx = 0, modeflag, resinfo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002628
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02002629 struct SiS_LCDData const *LCDPtr = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002630
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002631 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002632 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2633 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302634 pVBInfo->NewFlickerMode = 0;
2635 pVBInfo->RVBHRS = 50;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002636
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302637 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
2638 XGI_GetRAMDAC2DATA(ModeNo, ModeIdIndex, RefreshRateTableIndex,
2639 pVBInfo);
2640 return;
2641 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002642
Peter Huewea3d675c2012-02-09 21:11:47 +01002643 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02002644 LCDPtr = XGI_GetLcdPtr(XGI_LCDDataTable, ModeNo, ModeIdIndex,
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +03002645 RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002646
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302647 pVBInfo->RVBHCMAX = LCDPtr->RVBHCMAX;
2648 pVBInfo->RVBHCFACT = LCDPtr->RVBHCFACT;
2649 pVBInfo->VGAHT = LCDPtr->VGAHT;
2650 pVBInfo->VGAVT = LCDPtr->VGAVT;
2651 pVBInfo->HT = LCDPtr->LCDHT;
2652 pVBInfo->VT = LCDPtr->LCDVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002653
Peter Huewe255aabd2012-02-09 21:11:44 +01002654 if (pVBInfo->LCDResInfo == Panel_1024x768) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302655 tempax = 1024;
2656 tempbx = 768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002657
Peter Huewea3d675c2012-02-09 21:11:47 +01002658 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302659 if (pVBInfo->VGAVDE == 357)
2660 tempbx = 527;
2661 else if (pVBInfo->VGAVDE == 420)
2662 tempbx = 620;
2663 else if (pVBInfo->VGAVDE == 525)
2664 tempbx = 775;
2665 else if (pVBInfo->VGAVDE == 600)
2666 tempbx = 775;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302667 else
2668 tempbx = 768;
2669 } else
2670 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01002671 } else if (pVBInfo->LCDResInfo == Panel_1024x768x75) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302672 tempax = 1024;
2673 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01002674 } else if (pVBInfo->LCDResInfo == Panel_1280x1024) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302675 tempax = 1280;
2676 if (pVBInfo->VGAVDE == 360)
2677 tempbx = 768;
2678 else if (pVBInfo->VGAVDE == 375)
2679 tempbx = 800;
2680 else if (pVBInfo->VGAVDE == 405)
2681 tempbx = 864;
2682 else
2683 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01002684 } else if (pVBInfo->LCDResInfo == Panel_1280x1024x75) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302685 tempax = 1280;
2686 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01002687 } else if (pVBInfo->LCDResInfo == Panel_1280x960) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302688 tempax = 1280;
2689 if (pVBInfo->VGAVDE == 350)
2690 tempbx = 700;
2691 else if (pVBInfo->VGAVDE == 400)
2692 tempbx = 800;
2693 else if (pVBInfo->VGAVDE == 1024)
2694 tempbx = 960;
2695 else
2696 tempbx = 960;
Peter Huewe255aabd2012-02-09 21:11:44 +01002697 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302698 tempax = 1400;
2699 tempbx = 1050;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002700
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302701 if (pVBInfo->VGAVDE == 1024) {
2702 tempax = 1280;
2703 tempbx = 1024;
2704 }
Peter Huewe255aabd2012-02-09 21:11:44 +01002705 } else if (pVBInfo->LCDResInfo == Panel_1600x1200) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302706 tempax = 1600;
2707 tempbx = 1200; /* alan 10/14/2003 */
Peter Huewea3d675c2012-02-09 21:11:47 +01002708 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302709 if (pVBInfo->VGAVDE == 350)
2710 tempbx = 875;
2711 else if (pVBInfo->VGAVDE == 400)
2712 tempbx = 1000;
2713 }
2714 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002715
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302716 if (pVBInfo->LCDInfo & LCDNonExpanding) {
2717 tempax = pVBInfo->VGAHDE;
2718 tempbx = pVBInfo->VGAVDE;
2719 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002720
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302721 pVBInfo->HDE = tempax;
2722 pVBInfo->VDE = tempbx;
2723 return;
2724 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002725
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302726 if (pVBInfo->VBInfo & (SetCRT2ToTV)) {
Aaro Koskinen24572542012-09-11 00:15:21 +03002727 struct SiS_TVData const *TVPtr;
2728
2729 TVPtr = XGI_GetTVPtr(ModeNo, ModeIdIndex, RefreshRateTableIndex,
2730 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002731
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302732 pVBInfo->RVBHCMAX = TVPtr->RVBHCMAX;
2733 pVBInfo->RVBHCFACT = TVPtr->RVBHCFACT;
2734 pVBInfo->VGAHT = TVPtr->VGAHT;
2735 pVBInfo->VGAVT = TVPtr->VGAVT;
2736 pVBInfo->HDE = TVPtr->TVHDE;
2737 pVBInfo->VDE = TVPtr->TVVDE;
2738 pVBInfo->RVBHRS = TVPtr->RVBHRS;
2739 pVBInfo->NewFlickerMode = TVPtr->FlickerMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002740
Peter Huewe599801f2012-02-09 21:11:45 +01002741 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302742 if (resinfo == 0x08)
2743 pVBInfo->NewFlickerMode = 0x40;
2744 else if (resinfo == 0x09)
2745 pVBInfo->NewFlickerMode = 0x40;
2746 else if (resinfo == 0x12)
2747 pVBInfo->NewFlickerMode = 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002748
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302749 if (pVBInfo->VGAVDE == 350)
2750 pVBInfo->TVInfo |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002751
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302752 tempax = ExtHiTVHT;
2753 tempbx = ExtHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002754
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302755 if (pVBInfo->VBInfo & SetInSlaveMode) {
2756 if (pVBInfo->TVInfo & TVSimuMode) {
2757 tempax = StHiTVHT;
2758 tempbx = StHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002759
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302760 if (!(modeflag & Charx8Dot)) {
2761 tempax = StHiTextTVHT;
2762 tempbx = StHiTextTVVT;
2763 }
2764 }
2765 }
Peter Huewe599801f2012-02-09 21:11:45 +01002766 } else if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
2767 if (pVBInfo->TVInfo & TVSetYPbPr750p) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302768 tempax = YPbPrTV750pHT; /* Ext750pTVHT */
2769 tempbx = YPbPrTV750pVT; /* Ext750pTVVT */
2770 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002771
Peter Huewe599801f2012-02-09 21:11:45 +01002772 if (pVBInfo->TVInfo & TVSetYPbPr525p) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302773 tempax = YPbPrTV525pHT; /* Ext525pTVHT */
2774 tempbx = YPbPrTV525pVT; /* Ext525pTVVT */
Peter Huewe599801f2012-02-09 21:11:45 +01002775 } else if (pVBInfo->TVInfo & TVSetYPbPr525i) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302776 tempax = YPbPrTV525iHT; /* Ext525iTVHT */
2777 tempbx = YPbPrTV525iVT; /* Ext525iTVVT */
2778 if (pVBInfo->TVInfo & NTSC1024x768)
2779 tempax = NTSC1024x768HT;
2780 }
2781 } else {
2782 tempax = PALHT;
2783 tempbx = PALVT;
Peter Huewe599801f2012-02-09 21:11:45 +01002784 if (!(pVBInfo->TVInfo & TVSetPAL)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302785 tempax = NTSCHT;
2786 tempbx = NTSCVT;
2787 if (pVBInfo->TVInfo & NTSC1024x768)
2788 tempax = NTSC1024x768HT;
2789 }
2790 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002791
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302792 pVBInfo->HT = tempax;
2793 pVBInfo->VT = tempbx;
2794 return;
2795 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002796}
2797
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002798static void XGI_SetCRT2VCLK(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302799 unsigned short RefreshRateTableIndex,
2800 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002801{
Bill Pemberton108afbf2010-06-17 13:10:47 -04002802 unsigned char di_0, di_1, tempal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002803
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302804 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
2805 pVBInfo);
2806 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
2807 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002808
Peter Huewe6896b942012-02-09 21:11:46 +01002809 if (pVBInfo->VBType & VB_SIS301) { /* shampoo 0129 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302810 /* 301 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002811 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, 0x10);
2812 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
2813 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302814 } else { /* 301b/302b/301lv/302lv */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002815 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
2816 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302817 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002818
Aaro Koskinen8104e322011-03-13 12:26:22 +02002819 xgifb_reg_set(pVBInfo->Part4Port, 0x00, 0x12);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002820
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302821 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02002822 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x28);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302823 else
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02002824 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002825}
2826
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002827static unsigned short XGI_GetColorDepth(unsigned short ModeNo,
2828 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002829{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002830 unsigned short ColorDepth[6] = { 1, 2, 4, 4, 6, 8 };
2831 short index;
2832 unsigned short modeflag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302833
Aaro Koskinenb3979922012-11-04 21:14:52 +02002834 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Peter Huewe6896b942012-02-09 21:11:46 +01002835 index = (modeflag & ModeTypeMask) - ModeEGA;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302836
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002837 if (index < 0)
2838 index = 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302839
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002840 return ColorDepth[index];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302841}
2842
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002843static unsigned short XGI_GetOffset(unsigned short ModeNo,
2844 unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302845 unsigned short RefreshRateTableIndex,
2846 struct xgi_hw_device_info *HwDeviceExtension,
2847 struct vb_device_info *pVBInfo)
2848{
2849 unsigned short temp, colordepth, modeinfo, index, infoflag,
2850 ColorDepth[] = { 0x01, 0x02, 0x04 };
2851
Aaro Koskinenb3979922012-11-04 21:14:52 +02002852 modeinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeInfo;
Aaro Koskinena39325d2012-11-04 21:14:53 +02002853 infoflag = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302854
2855 index = (modeinfo >> 8) & 0xFF;
2856
Aaro Koskinen224114c2012-11-04 21:14:59 +02002857 temp = XGI330_ScreenOffset[index];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302858
2859 if (infoflag & InterlaceMode)
2860 temp = temp << 1;
2861
2862 colordepth = XGI_GetColorDepth(ModeNo, ModeIdIndex, pVBInfo);
2863
2864 if ((ModeNo >= 0x7C) && (ModeNo <= 0x7E)) {
2865 temp = ModeNo - 0x7C;
2866 colordepth = ColorDepth[temp];
2867 temp = 0x6B;
2868 if (infoflag & InterlaceMode)
2869 temp = temp << 1;
2870 return temp * colordepth;
2871 } else {
2872 return temp * colordepth;
2873 }
2874}
2875
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002876static void XGI_SetCRT2Offset(unsigned short ModeNo,
2877 unsigned short ModeIdIndex,
2878 unsigned short RefreshRateTableIndex,
2879 struct xgi_hw_device_info *HwDeviceExtension,
2880 struct vb_device_info *pVBInfo)
2881{
2882 unsigned short offset;
2883 unsigned char temp;
2884
2885 if (pVBInfo->VBInfo & SetInSlaveMode)
2886 return;
2887
2888 offset = XGI_GetOffset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
2889 HwDeviceExtension, pVBInfo);
2890 temp = (unsigned char) (offset & 0xFF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002891 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002892 temp = (unsigned char) ((offset & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002893 xgifb_reg_set(pVBInfo->Part1Port, 0x09, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002894 temp = (unsigned char) (((offset >> 3) & 0xFF) + 1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002895 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002896}
2897
Randy Dunlap89229672010-08-10 08:46:44 -07002898static void XGI_SetCRT2FIFO(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002899{
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002900 /* threshold high ,disable auto threshold */
2901 xgifb_reg_set(pVBInfo->Part1Port, 0x01, 0x3B);
2902 /* threshold low default 04h */
2903 xgifb_reg_and_or(pVBInfo->Part1Port, 0x02, ~(0x3F), 0x04);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002904}
2905
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002906static void XGI_PreSetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302907 struct xgi_hw_device_info *HwDeviceExtension,
2908 unsigned short RefreshRateTableIndex,
2909 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002910{
Peter Hueweef9a6b92013-02-03 04:08:43 +01002911 u8 tempcx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002912
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302913 XGI_SetCRT2Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
2914 HwDeviceExtension, pVBInfo);
2915 XGI_SetCRT2FIFO(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002916
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302917 for (tempcx = 4; tempcx < 7; tempcx++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02002918 xgifb_reg_set(pVBInfo->Part1Port, tempcx, 0x0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002919
Aaro Koskinen8104e322011-03-13 12:26:22 +02002920 xgifb_reg_set(pVBInfo->Part1Port, 0x50, 0x00);
2921 xgifb_reg_set(pVBInfo->Part1Port, 0x02, 0x44); /* temp 0206 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002922}
2923
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002924static void XGI_SetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302925 struct xgi_hw_device_info *HwDeviceExtension,
2926 unsigned short RefreshRateTableIndex,
2927 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002928{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302929 unsigned short temp = 0, tempax = 0, tempbx = 0, tempcx = 0,
Peter Hueweef9a6b92013-02-03 04:08:43 +01002930 pushbx = 0, CRT1Index, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002931
Aaro Koskinena39325d2012-11-04 21:14:53 +02002932 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002933 CRT1Index &= IndexMask;
Aaro Koskinenb3979922012-11-04 21:14:52 +02002934 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002935
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302936 /* bainy change table name */
2937 if (modeflag & HalfDCLK) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002938 /* BTVGA2HT 0x08,0x09 */
2939 temp = (pVBInfo->VGAHT / 2 - 1) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002940 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302941 temp = (((pVBInfo->VGAHT / 2 - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002942 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002943 /* BTVGA2HDEE 0x0A,0x0C */
2944 temp = (pVBInfo->VGAHDE / 2 + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002945 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302946 tempcx = ((pVBInfo->VGAHT - pVBInfo->VGAHDE) / 2) >> 2;
2947 pushbx = pVBInfo->VGAHDE / 2 + 16;
2948 tempcx = tempcx >> 1;
2949 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
2950 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002951
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302952 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002953 tempbx = XGI_CRT1Table[CRT1Index].CR[4];
2954 tempbx |= ((XGI_CRT1Table[CRT1Index].CR[14] &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002955 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302956 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002957 tempcx = XGI_CRT1Table[CRT1Index].CR[5];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302958 tempcx &= 0x1F;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002959 temp = XGI_CRT1Table[CRT1Index].CR[15];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302960 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
2961 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
2962 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002963
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302964 tempbx += 4;
2965 tempcx += 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002966
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302967 if (tempcx > (pVBInfo->VGAHT / 2))
2968 tempcx = pVBInfo->VGAHT / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002969
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302970 temp = tempbx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002971
Aaro Koskinen8104e322011-03-13 12:26:22 +02002972 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302973 } else {
2974 temp = (pVBInfo->VGAHT - 1) & 0x0FF; /* BTVGA2HT 0x08,0x09 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002975 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302976 temp = (((pVBInfo->VGAHT - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002977 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002978 /* BTVGA2HDEE 0x0A,0x0C */
2979 temp = (pVBInfo->VGAHDE + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002980 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302981 tempcx = (pVBInfo->VGAHT - pVBInfo->VGAHDE) >> 2; /* cx */
2982 pushbx = pVBInfo->VGAHDE + 16;
2983 tempcx = tempcx >> 1;
2984 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
2985 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002986
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302987 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002988 tempbx = XGI_CRT1Table[CRT1Index].CR[3];
2989 tempbx |= ((XGI_CRT1Table[CRT1Index].CR[5] &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002990 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302991 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002992 tempcx = XGI_CRT1Table[CRT1Index].CR[4];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302993 tempcx &= 0x1F;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002994 temp = XGI_CRT1Table[CRT1Index].CR[6];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302995 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
2996 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
2997 tempbx += 16;
2998 tempcx += 16;
2999 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003000
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303001 if (tempcx > pVBInfo->VGAHT)
3002 tempcx = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003003
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303004 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003005 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303006 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003007
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303008 tempax = (tempax & 0x00FF) | (tempbx & 0xFF00);
3009 tempbx = pushbx;
3010 tempbx = (tempbx & 0x00FF) | ((tempbx & 0xFF00) << 4);
3011 tempax |= (tempbx & 0xFF00);
3012 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003013 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303014 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003015 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303016 tempcx = (pVBInfo->VGAVT - 1);
3017 temp = tempcx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003018
Aaro Koskinen8104e322011-03-13 12:26:22 +02003019 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303020 tempbx = pVBInfo->VGAVDE - 1;
3021 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003022 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303023 temp = ((tempbx & 0xFF00) << 3) >> 8;
3024 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003025 xgifb_reg_set(pVBInfo->Part1Port, 0x12, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003026
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303027 tempax = pVBInfo->VGAVDE;
3028 tempbx = pVBInfo->VGAVDE;
3029 tempcx = pVBInfo->VGAVT;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003030 /* BTVGA2VRS 0x10,0x11 */
3031 tempbx = (pVBInfo->VGAVT + pVBInfo->VGAVDE) >> 1;
3032 /* BTVGA2VRE 0x11 */
3033 tempcx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) >> 4) + tempbx + 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003034
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303035 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003036 tempbx = XGI_CRT1Table[CRT1Index].CR[10];
3037 temp = XGI_CRT1Table[CRT1Index].CR[9];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003038
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303039 if (temp & 0x04)
3040 tempbx |= 0x0100;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003041
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303042 if (temp & 0x080)
3043 tempbx |= 0x0200;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003044
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003045 temp = XGI_CRT1Table[CRT1Index].CR[14];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003046
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303047 if (temp & 0x08)
3048 tempbx |= 0x0400;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003049
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003050 temp = XGI_CRT1Table[CRT1Index].CR[11];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303051 tempcx = (tempcx & 0xFF00) | (temp & 0x00FF);
3052 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003053
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303054 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003055 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303056 temp = ((tempbx & 0xFF00) >> 8) << 4;
3057 temp = ((tempcx & 0x000F) | (temp));
Aaro Koskinen8104e322011-03-13 12:26:22 +02003058 xgifb_reg_set(pVBInfo->Part1Port, 0x11, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303059 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003060
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303061 if (modeflag & DoubleScanMode)
3062 tempax |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003063
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303064 if (modeflag & HalfDCLK)
3065 tempax |= 0x40;
3066
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003067 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2C, ~0x0C0, tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003068}
3069
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003070static unsigned short XGI_GetVGAHT2(struct vb_device_info *pVBInfo)
3071{
3072 unsigned long tempax, tempbx;
3073
3074 tempbx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) * pVBInfo->RVBHCMAX)
3075 & 0xFFFF;
3076 tempax = (pVBInfo->VT - pVBInfo->VDE) * pVBInfo->RVBHCFACT;
3077 tempax = (tempax * pVBInfo->HT) / tempbx;
3078
3079 return (unsigned short) tempax;
3080}
3081
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003082static void XGI_SetLockRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303083 struct xgi_hw_device_info *HwDeviceExtension,
3084 unsigned short RefreshRateTableIndex,
3085 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003086{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303087 unsigned short push1, push2, tempax, tempbx = 0, tempcx, temp, resinfo,
Peter Hueweef9a6b92013-02-03 04:08:43 +01003088 modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003089
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003090 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02003091 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3092 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003093
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303094 if (!(pVBInfo->VBInfo & SetInSlaveMode))
3095 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003096
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303097 temp = 0xFF; /* set MAX HT */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003098 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303099 tempcx = 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003100
Peter Huewe6896b942012-02-09 21:11:46 +01003101 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303102 modeflag |= Charx8Dot;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003103
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303104 tempax = pVBInfo->VGAHDE; /* 0x04 Horizontal Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003105
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303106 if (modeflag & HalfDCLK)
3107 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003108
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303109 tempax = (tempax / tempcx) - 1;
3110 tempbx |= ((tempax & 0x00FF) << 8);
3111 temp = tempax & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003112 xgifb_reg_set(pVBInfo->Part1Port, 0x04, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003113
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303114 temp = (tempbx & 0xFF00) >> 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003115
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303116 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Peter Huewe6896b942012-02-09 21:11:46 +01003117 if (!(pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3118 | VB_SIS302LV | VB_XGI301C)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303119 temp += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003120
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03003121 if ((pVBInfo->VBInfo & SetCRT2ToHiVision) &&
3122 !(pVBInfo->VBType & VB_SIS301LV) && (resinfo == 7))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303123 temp -= 2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303124 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003125
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003126 /* 0x05 Horizontal Display Start */
3127 xgifb_reg_set(pVBInfo->Part1Port, 0x05, temp);
3128 /* 0x06 Horizontal Blank end */
3129 xgifb_reg_set(pVBInfo->Part1Port, 0x06, 0x03);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003130
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303131 if (!(pVBInfo->VBInfo & DisableCRT2Display)) { /* 030226 bainy */
3132 if (pVBInfo->VBInfo & SetCRT2ToTV)
3133 tempax = pVBInfo->VGAHT;
3134 else
3135 tempax = XGI_GetVGAHT2(pVBInfo);
3136 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003137
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303138 if (tempax >= pVBInfo->VGAHT)
3139 tempax = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003140
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303141 if (modeflag & HalfDCLK)
3142 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003143
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303144 tempax = (tempax / tempcx) - 5;
3145 tempcx = tempax; /* 20030401 0x07 horizontal Retrace Start */
Peter Huewe599801f2012-02-09 21:11:45 +01003146 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303147 temp = (tempbx & 0x00FF) - 1;
3148 if (!(modeflag & HalfDCLK)) {
3149 temp -= 6;
3150 if (pVBInfo->TVInfo & TVSimuMode) {
3151 temp -= 4;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003152 temp -= 10;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303153 }
3154 }
3155 } else {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303156 tempbx = (tempbx & 0xFF00) >> 8;
3157 tempcx = (tempcx + tempbx) >> 1;
3158 temp = (tempcx & 0x00FF) + 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003159
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303160 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3161 temp -= 1;
3162 if (!(modeflag & HalfDCLK)) {
3163 if ((modeflag & Charx8Dot)) {
3164 temp += 4;
3165 if (pVBInfo->VGAHDE >= 800)
3166 temp -= 6;
3167 }
3168 }
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003169 } else if (!(modeflag & HalfDCLK)) {
3170 temp -= 4;
Peter Huewe255aabd2012-02-09 21:11:44 +01003171 if (pVBInfo->LCDResInfo != Panel_1280x960 &&
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003172 pVBInfo->VGAHDE >= 800) {
3173 temp -= 7;
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003174 if (pVBInfo->VGAHDE >= 1280 &&
Peter Huewe255aabd2012-02-09 21:11:44 +01003175 pVBInfo->LCDResInfo != Panel_1280x960 &&
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003176 (pVBInfo->LCDInfo & LCDNonExpanding))
3177 temp += 28;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303178 }
3179 }
3180 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003181
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003182 /* 0x07 Horizontal Retrace Start */
3183 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
3184 /* 0x08 Horizontal Retrace End */
3185 xgifb_reg_set(pVBInfo->Part1Port, 0x08, 0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003186
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303187 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3188 if (pVBInfo->TVInfo & TVSimuMode) {
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003189 if (ModeNo == 0x50) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303190 if (pVBInfo->TVInfo & SetNTSCTV) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003191 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303192 0x07, 0x30);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003193 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303194 0x08, 0x03);
3195 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003196 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303197 0x07, 0x2f);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003198 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303199 0x08, 0x02);
3200 }
3201 }
3202 }
3203 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003204
Aaro Koskinen8104e322011-03-13 12:26:22 +02003205 xgifb_reg_set(pVBInfo->Part1Port, 0x18, 0x03); /* 0x18 SR0B */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003206 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0xF0, 0x00);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003207 xgifb_reg_set(pVBInfo->Part1Port, 0x09, 0xFF); /* 0x09 Set Max VT */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003208
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303209 tempbx = pVBInfo->VGAVT;
3210 push1 = tempbx;
3211 tempcx = 0x121;
3212 tempbx = pVBInfo->VGAVDE; /* 0x0E Virtical Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003213
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303214 if (tempbx == 357)
3215 tempbx = 350;
3216 if (tempbx == 360)
3217 tempbx = 350;
3218 if (tempbx == 375)
3219 tempbx = 350;
3220 if (tempbx == 405)
3221 tempbx = 400;
3222 if (tempbx == 525)
3223 tempbx = 480;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003224
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303225 push2 = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003226
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303227 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
Peter Huewe255aabd2012-02-09 21:11:44 +01003228 if (pVBInfo->LCDResInfo == Panel_1024x768) {
Peter Huewea3d675c2012-02-09 21:11:47 +01003229 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303230 if (tempbx == 350)
3231 tempbx += 5;
3232 if (tempbx == 480)
3233 tempbx += 5;
3234 }
3235 }
3236 }
3237 tempbx--;
3238 temp = tempbx & 0x00FF;
3239 tempbx--;
3240 temp = tempbx & 0x00FF;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003241 /* 0x10 vertical Blank Start */
3242 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303243 tempbx = push2;
3244 tempbx--;
3245 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003246 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003247
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303248 if (tempbx & 0x0100)
3249 tempcx |= 0x0002;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003250
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303251 tempax = 0x000B;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003252
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303253 if (modeflag & DoubleScanMode)
3254 tempax |= 0x08000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003255
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303256 if (tempbx & 0x0200)
3257 tempcx |= 0x0040;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003258
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303259 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003260 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003261
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303262 if (tempbx & 0x0400)
3263 tempcx |= 0x0600;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003264
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003265 /* 0x11 Vertival Blank End */
3266 xgifb_reg_set(pVBInfo->Part1Port, 0x11, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303267
3268 tempax = push1;
3269 tempax -= tempbx; /* 0x0C Vertical Retrace Start */
3270 tempax = tempax >> 2;
3271 push1 = tempax; /* push ax */
3272
3273 if (resinfo != 0x09) {
3274 tempax = tempax << 1;
3275 tempbx += tempax;
3276 }
3277
Peter Huewe599801f2012-02-09 21:11:45 +01003278 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Miguel Gómez470c5332012-07-06 12:40:50 +02003279 if ((pVBInfo->VBType & VB_SIS301LV) &&
3280 !(pVBInfo->TVInfo & TVSetHiVision)) {
3281 if ((pVBInfo->TVInfo & TVSimuMode) &&
3282 (pVBInfo->TVInfo & TVSetPAL)) {
3283 if (!(pVBInfo->VBType & VB_SIS301LV) ||
3284 !(pVBInfo->TVInfo &
3285 (TVSetYPbPr525p |
3286 TVSetYPbPr750p |
3287 TVSetHiVision)))
3288 tempbx += 40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303289 }
3290 } else {
3291 tempbx -= 10;
3292 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003293 } else if (pVBInfo->TVInfo & TVSimuMode) {
3294 if (pVBInfo->TVInfo & TVSetPAL) {
3295 if (pVBInfo->VBType & VB_SIS301LV) {
3296 if (!(pVBInfo->TVInfo &
3297 (TVSetYPbPr525p |
3298 TVSetYPbPr750p |
3299 TVSetHiVision)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303300 tempbx += 40;
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003301 } else {
3302 tempbx += 40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303303 }
3304 }
3305 }
3306 tempax = push1;
3307 tempax = tempax >> 2;
3308 tempax++;
3309 tempax += tempbx;
3310 push1 = tempax; /* push ax */
3311
Peter Huewe599801f2012-02-09 21:11:45 +01003312 if ((pVBInfo->TVInfo & TVSetPAL)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303313 if (tempbx <= 513) {
3314 if (tempax >= 513)
3315 tempbx = 513;
3316 }
3317 }
3318
3319 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003320 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303321 tempbx--;
3322 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003323 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303324
3325 if (tempbx & 0x0100)
3326 tempcx |= 0x0008;
3327
3328 if (tempbx & 0x0200)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003329 xgifb_reg_and_or(pVBInfo->Part1Port, 0x0B, 0x0FF, 0x20);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303330
3331 tempbx++;
3332
3333 if (tempbx & 0x0100)
3334 tempcx |= 0x0004;
3335
3336 if (tempbx & 0x0200)
3337 tempcx |= 0x0080;
3338
3339 if (tempbx & 0x0400)
3340 tempcx |= 0x0C00;
3341
3342 tempbx = push1; /* pop ax */
3343 temp = tempbx & 0x00FF;
3344 temp &= 0x0F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003345 /* 0x0D vertical Retrace End */
3346 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303347
3348 if (tempbx & 0x0010)
3349 tempcx |= 0x2000;
3350
3351 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003352 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp); /* 0x0A CR07 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303353 temp = (tempcx & 0x0FF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003354 xgifb_reg_set(pVBInfo->Part1Port, 0x17, temp); /* 0x17 SR0A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303355 tempax = modeflag;
3356 temp = (tempax & 0xFF00) >> 8;
3357
3358 temp = (temp >> 1) & 0x09;
3359
Peter Huewe6896b942012-02-09 21:11:46 +01003360 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303361 temp |= 0x01;
3362
Aaro Koskinen8104e322011-03-13 12:26:22 +02003363 xgifb_reg_set(pVBInfo->Part1Port, 0x16, temp); /* 0x16 SR01 */
3364 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, 0); /* 0x0F CR14 */
3365 xgifb_reg_set(pVBInfo->Part1Port, 0x12, 0); /* 0x12 CR17 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303366
3367 if (pVBInfo->LCDInfo & LCDRGB18Bit)
3368 temp = 0x80;
3369 else
3370 temp = 0x00;
3371
Aaro Koskinen8104e322011-03-13 12:26:22 +02003372 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, temp); /* 0x1A SR0E */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303373
3374 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003375}
3376
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003377static void XGI_SetGroup2(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303378 unsigned short RefreshRateTableIndex,
3379 struct xgi_hw_device_info *HwDeviceExtension,
3380 struct vb_device_info *pVBInfo)
3381{
3382 unsigned short i, j, tempax, tempbx, tempcx, temp, push1, push2,
Peter Hueweef9a6b92013-02-03 04:08:43 +01003383 modeflag;
Aaro Koskinend21222d2012-09-11 00:15:29 +03003384 unsigned char const *TimingPoint;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303385
3386 unsigned long longtemp, tempeax, tempebx, temp2, tempecx;
3387
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003388 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02003389 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303390
3391 tempax = 0;
3392
3393 if (!(pVBInfo->VBInfo & SetCRT2ToAVIDEO))
3394 tempax |= 0x0800;
3395
3396 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3397 tempax |= 0x0400;
3398
3399 if (pVBInfo->VBInfo & SetCRT2ToSCART)
3400 tempax |= 0x0200;
3401
Peter Huewe599801f2012-02-09 21:11:45 +01003402 if (!(pVBInfo->TVInfo & TVSetPAL))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303403 tempax |= 0x1000;
3404
Peter Huewe599801f2012-02-09 21:11:45 +01003405 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303406 tempax |= 0x0100;
3407
Peter Huewe599801f2012-02-09 21:11:45 +01003408 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303409 tempax &= 0xfe00;
3410
3411 tempax = (tempax & 0xff00) >> 8;
3412
Aaro Koskinen8104e322011-03-13 12:26:22 +02003413 xgifb_reg_set(pVBInfo->Part2Port, 0x0, tempax);
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003414 TimingPoint = XGI330_NTSCTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303415
Peter Huewe599801f2012-02-09 21:11:45 +01003416 if (pVBInfo->TVInfo & TVSetPAL)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003417 TimingPoint = XGI330_PALTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303418
Peter Huewe599801f2012-02-09 21:11:45 +01003419 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003420 TimingPoint = XGI330_HiTVExtTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303421
3422 if (pVBInfo->VBInfo & SetInSlaveMode)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003423 TimingPoint = XGI330_HiTVSt2Timing;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303424
3425 if (pVBInfo->SetFlag & TVSimuMode)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003426 TimingPoint = XGI330_HiTVSt1Timing;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303427
3428 if (!(modeflag & Charx8Dot))
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003429 TimingPoint = XGI330_HiTVTextTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303430 }
3431
Peter Huewe599801f2012-02-09 21:11:45 +01003432 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
3433 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003434 TimingPoint = XGI330_YPbPr525iTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303435
Peter Huewe599801f2012-02-09 21:11:45 +01003436 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003437 TimingPoint = XGI330_YPbPr525pTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303438
Peter Huewe599801f2012-02-09 21:11:45 +01003439 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003440 TimingPoint = XGI330_YPbPr750pTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303441 }
3442
3443 for (i = 0x01, j = 0; i <= 0x2D; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02003444 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303445
3446 for (i = 0x39; i <= 0x45; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003447 /* di->temp2[j] */
3448 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303449
3450 if (pVBInfo->VBInfo & SetCRT2ToTV)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003451 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303452
3453 temp = pVBInfo->NewFlickerMode;
3454 temp &= 0x80;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003455 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xFF, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303456
Peter Huewe599801f2012-02-09 21:11:45 +01003457 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303458 tempax = 950;
3459
Peter Huewe599801f2012-02-09 21:11:45 +01003460 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303461 tempax = 520;
3462 else
3463 tempax = 440;
3464
3465 if (pVBInfo->VDE <= tempax) {
3466 tempax -= pVBInfo->VDE;
3467 tempax = tempax >> 2;
3468 tempax = (tempax & 0x00FF) | ((tempax & 0x00FF) << 8);
3469 push1 = tempax;
3470 temp = (tempax & 0xFF00) >> 8;
3471 temp += (unsigned short) TimingPoint[0];
3472
Peter Huewe6896b942012-02-09 21:11:46 +01003473 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3474 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303475 if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO
3476 | SetCRT2ToSVIDEO | SetCRT2ToSCART
Peter Huewe599801f2012-02-09 21:11:45 +01003477 | SetCRT2ToYPbPr525750)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303478 tempcx = pVBInfo->VGAHDE;
3479 if (tempcx >= 1024) {
3480 temp = 0x17; /* NTSC */
Peter Huewe599801f2012-02-09 21:11:45 +01003481 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303482 temp = 0x19; /* PAL */
3483 }
3484 }
3485 }
3486
Aaro Koskinen8104e322011-03-13 12:26:22 +02003487 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303488 tempax = push1;
3489 temp = (tempax & 0xFF00) >> 8;
3490 temp += TimingPoint[1];
3491
Peter Huewe6896b942012-02-09 21:11:46 +01003492 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3493 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303494 if ((pVBInfo->VBInfo & (SetCRT2ToAVIDEO
3495 | SetCRT2ToSVIDEO | SetCRT2ToSCART
Peter Huewe599801f2012-02-09 21:11:45 +01003496 | SetCRT2ToYPbPr525750))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303497 tempcx = pVBInfo->VGAHDE;
3498 if (tempcx >= 1024) {
3499 temp = 0x1D; /* NTSC */
Peter Huewe599801f2012-02-09 21:11:45 +01003500 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303501 temp = 0x52; /* PAL */
3502 }
3503 }
3504 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02003505 xgifb_reg_set(pVBInfo->Part2Port, 0x02, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303506 }
3507
3508 /* 301b */
3509 tempcx = pVBInfo->HT;
3510
3511 if (XGI_IsLCDDualLink(pVBInfo))
3512 tempcx = tempcx >> 1;
3513
3514 tempcx -= 2;
3515 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003516 xgifb_reg_set(pVBInfo->Part2Port, 0x1B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303517
3518 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003519 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303520
3521 tempcx = pVBInfo->HT >> 1;
3522 push1 = tempcx; /* push cx */
3523 tempcx += 7;
3524
Peter Huewe599801f2012-02-09 21:11:45 +01003525 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303526 tempcx -= 4;
3527
3528 temp = tempcx & 0x00FF;
3529 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003530 xgifb_reg_and_or(pVBInfo->Part2Port, 0x22, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303531
3532 tempbx = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
3533 tempbx += tempcx;
3534 push2 = tempbx;
3535 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003536 xgifb_reg_set(pVBInfo->Part2Port, 0x24, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303537 temp = (tempbx & 0xFF00) >> 8;
3538 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003539 xgifb_reg_and_or(pVBInfo->Part2Port, 0x25, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303540
3541 tempbx = push2;
3542 tempbx = tempbx + 8;
Peter Huewe599801f2012-02-09 21:11:45 +01003543 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303544 tempbx = tempbx - 4;
3545 tempcx = tempbx;
3546 }
3547
3548 temp = (tempbx & 0x00FF) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003549 xgifb_reg_and_or(pVBInfo->Part2Port, 0x29, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303550
3551 j += 2;
3552 tempcx += (TimingPoint[j] | ((TimingPoint[j + 1]) << 8));
3553 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003554 xgifb_reg_set(pVBInfo->Part2Port, 0x27, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303555 temp = ((tempcx & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003556 xgifb_reg_and_or(pVBInfo->Part2Port, 0x28, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303557
3558 tempcx += 8;
Peter Huewe599801f2012-02-09 21:11:45 +01003559 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303560 tempcx -= 4;
3561
3562 temp = tempcx & 0xFF;
3563 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003564 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2A, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303565
3566 tempcx = push1; /* pop cx */
3567 j += 2;
3568 temp = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
3569 tempcx -= temp;
3570 temp = tempcx & 0x00FF;
3571 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003572 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2D, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303573
3574 tempcx -= 11;
3575
3576 if (!(pVBInfo->VBInfo & SetCRT2ToTV)) {
3577 tempax = XGI_GetVGAHT2(pVBInfo);
3578 tempcx = tempax - 1;
3579 }
3580 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003581 xgifb_reg_set(pVBInfo->Part2Port, 0x2E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303582
3583 tempbx = pVBInfo->VDE;
3584
3585 if (pVBInfo->VGAVDE == 360)
3586 tempbx = 746;
3587 if (pVBInfo->VGAVDE == 375)
3588 tempbx = 746;
3589 if (pVBInfo->VGAVDE == 405)
3590 tempbx = 853;
3591
3592 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003593 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01003594 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003595 if (!(pVBInfo->TVInfo &
Peter Huewe599801f2012-02-09 21:11:45 +01003596 (TVSetYPbPr525p | TVSetYPbPr750p)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303597 tempbx = tempbx >> 1;
3598 } else
3599 tempbx = tempbx >> 1;
3600 }
3601
3602 tempbx -= 2;
3603 temp = tempbx & 0x00FF;
3604
Peter Huewe599801f2012-02-09 21:11:45 +01003605 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Huewe6896b942012-02-09 21:11:46 +01003606 if (pVBInfo->VBType & VB_SIS301LV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003607 if (pVBInfo->TVInfo & TVSetHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303608 if (pVBInfo->VBInfo & SetInSlaveMode) {
3609 if (ModeNo == 0x2f)
3610 temp += 1;
3611 }
3612 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003613 } else if (pVBInfo->VBInfo & SetInSlaveMode) {
3614 if (ModeNo == 0x2f)
3615 temp += 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303616 }
3617 }
3618
Aaro Koskinen8104e322011-03-13 12:26:22 +02003619 xgifb_reg_set(pVBInfo->Part2Port, 0x2F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303620
3621 temp = (tempcx & 0xFF00) >> 8;
3622 temp |= ((tempbx & 0xFF00) >> 8) << 6;
3623
Peter Huewe599801f2012-02-09 21:11:45 +01003624 if (!(pVBInfo->VBInfo & SetCRT2ToHiVision)) {
Peter Huewe6896b942012-02-09 21:11:46 +01003625 if (pVBInfo->VBType & VB_SIS301LV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003626 if (pVBInfo->TVInfo & TVSetHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303627 temp |= 0x10;
3628
3629 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3630 temp |= 0x20;
3631 }
3632 } else {
3633 temp |= 0x10;
3634 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3635 temp |= 0x20;
3636 }
3637 }
3638
Aaro Koskinen8104e322011-03-13 12:26:22 +02003639 xgifb_reg_set(pVBInfo->Part2Port, 0x30, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303640
Peter Huewe6896b942012-02-09 21:11:46 +01003641 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3642 | VB_SIS302LV | VB_XGI301C)) { /* TV gatingno */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303643 tempbx = pVBInfo->VDE;
3644 tempcx = tempbx - 2;
3645
3646 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003647 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p
3648 | TVSetYPbPr750p)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303649 tempbx = tempbx >> 1;
3650 }
3651
Peter Huewe6896b942012-02-09 21:11:46 +01003652 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303653 temp = 0;
3654 if (tempcx & 0x0400)
3655 temp |= 0x20;
3656
3657 if (tempbx & 0x0400)
3658 temp |= 0x40;
3659
Aaro Koskinen8104e322011-03-13 12:26:22 +02003660 xgifb_reg_set(pVBInfo->Part4Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303661 }
3662
3663 temp = (((tempbx - 3) & 0x0300) >> 8) << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003664 xgifb_reg_set(pVBInfo->Part2Port, 0x46, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303665 temp = (tempbx - 3) & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003666 xgifb_reg_set(pVBInfo->Part2Port, 0x47, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303667 }
3668
3669 tempbx = tempbx & 0x00FF;
3670
3671 if (!(modeflag & HalfDCLK)) {
3672 tempcx = pVBInfo->VGAHDE;
3673 if (tempcx >= pVBInfo->HDE) {
3674 tempbx |= 0x2000;
3675 tempax &= 0x00FF;
3676 }
3677 }
3678
3679 tempcx = 0x0101;
3680
3681 if (pVBInfo->VBInfo & SetCRT2ToTV) { /*301b*/
3682 if (pVBInfo->VGAHDE >= 1024) {
3683 tempcx = 0x1920;
3684 if (pVBInfo->VGAHDE >= 1280) {
3685 tempcx = 0x1420;
3686 tempbx = tempbx & 0xDFFF;
3687 }
3688 }
3689 }
3690
3691 if (!(tempbx & 0x2000)) {
3692 if (modeflag & HalfDCLK)
3693 tempcx = (tempcx & 0xFF00) | ((tempcx & 0x00FF) << 1);
3694
3695 push1 = tempbx;
3696 tempeax = pVBInfo->VGAHDE;
3697 tempebx = (tempcx & 0xFF00) >> 8;
3698 longtemp = tempeax * tempebx;
3699 tempecx = tempcx & 0x00FF;
3700 longtemp = longtemp / tempecx;
3701
3702 /* 301b */
3703 tempecx = 8 * 1024;
3704
Peter Huewe6896b942012-02-09 21:11:46 +01003705 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3706 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303707 tempecx = tempecx * 8;
3708 }
3709
3710 longtemp = longtemp * tempecx;
3711 tempecx = pVBInfo->HDE;
3712 temp2 = longtemp % tempecx;
3713 tempeax = longtemp / tempecx;
3714 if (temp2 != 0)
3715 tempeax += 1;
3716
3717 tempax = (unsigned short) tempeax;
3718
3719 /* 301b */
Peter Huewe6896b942012-02-09 21:11:46 +01003720 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3721 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303722 tempcx = ((tempax & 0xFF00) >> 5) >> 8;
3723 }
3724 /* end 301b */
3725
3726 tempbx = push1;
3727 tempbx = (unsigned short) (((tempeax & 0x0000FF00) & 0x1F00)
3728 | (tempbx & 0x00FF));
3729 tempax = (unsigned short) (((tempeax & 0x000000FF) << 8)
3730 | (tempax & 0x00FF));
3731 temp = (tempax & 0xFF00) >> 8;
3732 } else {
3733 temp = (tempax & 0x00FF) >> 8;
3734 }
3735
Aaro Koskinen8104e322011-03-13 12:26:22 +02003736 xgifb_reg_set(pVBInfo->Part2Port, 0x44, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303737 temp = (tempbx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003738 xgifb_reg_and_or(pVBInfo->Part2Port, 0x45, ~0x03F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303739 temp = tempcx & 0x00FF;
3740
3741 if (tempbx & 0x2000)
3742 temp = 0;
3743
3744 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
3745 temp |= 0x18;
3746
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003747 xgifb_reg_and_or(pVBInfo->Part2Port, 0x46, ~0x1F, temp);
Peter Huewe599801f2012-02-09 21:11:45 +01003748 if (pVBInfo->TVInfo & TVSetPAL) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303749 tempbx = 0x0382;
3750 tempcx = 0x007e;
3751 } else {
3752 tempbx = 0x0369;
3753 tempcx = 0x0061;
3754 }
3755
3756 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003757 xgifb_reg_set(pVBInfo->Part2Port, 0x4b, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303758 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003759 xgifb_reg_set(pVBInfo->Part2Port, 0x4c, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303760
3761 temp = ((tempcx & 0xFF00) >> 8) & 0x03;
3762 temp = temp << 2;
3763 temp |= ((tempbx & 0xFF00) >> 8) & 0x03;
3764
Peter Huewe599801f2012-02-09 21:11:45 +01003765 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303766 temp |= 0x10;
3767
Peter Huewe599801f2012-02-09 21:11:45 +01003768 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303769 temp |= 0x20;
3770
Peter Huewe599801f2012-02-09 21:11:45 +01003771 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303772 temp |= 0x60;
3773 }
3774
Aaro Koskinen8104e322011-03-13 12:26:22 +02003775 xgifb_reg_set(pVBInfo->Part2Port, 0x4d, temp);
Aaro Koskinen58839b02011-03-13 12:26:23 +02003776 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x43); /* 301b change */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003777 xgifb_reg_set(pVBInfo->Part2Port, 0x43, (unsigned short) (temp - 3));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303778
Peter Huewe599801f2012-02-09 21:11:45 +01003779 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303780 if (pVBInfo->TVInfo & NTSC1024x768) {
3781 TimingPoint = XGI_NTSC1024AdjTime;
3782 for (i = 0x1c, j = 0; i <= 0x30; i++, j++) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003783 xgifb_reg_set(pVBInfo->Part2Port, i,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303784 TimingPoint[j]);
3785 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02003786 xgifb_reg_set(pVBInfo->Part2Port, 0x43, 0x72);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303787 }
3788 }
3789
Miguel Gómez949eb0a2012-07-06 12:40:36 +02003790 /* Modify for 301C PALM Support */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303791 if (pVBInfo->VBType & VB_XGI301C) {
Peter Huewe599801f2012-02-09 21:11:45 +01003792 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003793 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x08,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303794 0x08); /* PALM Mode */
3795 }
3796
Peter Huewe599801f2012-02-09 21:11:45 +01003797 if (pVBInfo->TVInfo & TVSetPALM) {
Peter Huewe9388ad92013-02-15 20:37:10 +01003798 tempax = xgifb_reg_get(pVBInfo->Part2Port, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303799 tempax--;
Aaro Koskinendc505562011-03-13 12:26:26 +02003800 xgifb_reg_and(pVBInfo->Part2Port, 0x01, tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303801
Aaro Koskinendc505562011-03-13 12:26:26 +02003802 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xEF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303803 }
3804
Peter Huewe599801f2012-02-09 21:11:45 +01003805 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303806 if (!(pVBInfo->VBInfo & SetInSlaveMode))
Aaro Koskinen8104e322011-03-13 12:26:22 +02003807 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303808 }
3809
3810 if (pVBInfo->VBInfo & SetCRT2ToTV)
3811 return;
3812}
3813
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003814static void XGI_SetLCDRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303815 struct xgi_hw_device_info *HwDeviceExtension,
3816 unsigned short RefreshRateTableIndex,
3817 struct vb_device_info *pVBInfo)
3818{
Peter Hueweef9a6b92013-02-03 04:08:43 +01003819 unsigned short pushbx, tempax, tempbx, tempcx, temp, tempah,
3820 tempbh, tempch;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303821
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02003822 struct XGI_LCDDesStruct const *LCDBDesPtr = NULL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303823
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003824 /* si+Ext_ResInfo */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303825 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
3826 return;
3827
3828 tempbx = pVBInfo->HDE; /* RHACTE=HDE-1 */
3829
3830 if (XGI_IsLCDDualLink(pVBInfo))
3831 tempbx = tempbx >> 1;
3832
3833 tempbx -= 1;
3834 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003835 xgifb_reg_set(pVBInfo->Part2Port, 0x2C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303836 temp = (tempbx & 0xFF00) >> 8;
3837 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003838 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2B, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303839 temp = 0x01;
3840
Aaro Koskinen8104e322011-03-13 12:26:22 +02003841 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303842 tempbx = pVBInfo->VDE; /* RTVACTEO=(VDE-1)&0xFF */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303843 tempbx--;
3844 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003845 xgifb_reg_set(pVBInfo->Part2Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303846 temp = ((tempbx & 0xFF00) >> 8) & 0x07;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003847 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0C, ~0x07, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303848
3849 tempcx = pVBInfo->VT - 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303850 temp = tempcx & 0x00FF; /* RVTVT=VT-1 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003851 xgifb_reg_set(pVBInfo->Part2Port, 0x19, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303852 temp = (tempcx & 0xFF00) >> 8;
3853 temp = temp << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003854 xgifb_reg_set(pVBInfo->Part2Port, 0x1A, temp);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003855 xgifb_reg_and_or(pVBInfo->Part2Port, 0x09, 0xF0, 0x00);
3856 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xF0, 0x00);
3857 xgifb_reg_and_or(pVBInfo->Part2Port, 0x17, 0xFB, 0x00);
3858 xgifb_reg_and_or(pVBInfo->Part2Port, 0x18, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303859
Justin P. Mattock558f7582012-10-02 21:17:11 -07003860 /* Customized LCDB Does not add */
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02003861 if ((pVBInfo->VBType & VB_SIS301LV) || (pVBInfo->VBType & VB_SIS302LV))
3862 LCDBDesPtr = XGI_GetLcdPtr(xgifb_lcddldes, ModeNo, ModeIdIndex,
3863 RefreshRateTableIndex, pVBInfo);
3864 else
3865 LCDBDesPtr = XGI_GetLcdPtr(XGI_LCDDesDataTable, ModeNo,
3866 ModeIdIndex, RefreshRateTableIndex,
3867 pVBInfo);
3868
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303869 tempah = pVBInfo->LCDResInfo;
3870 tempah &= PanelResInfo;
3871
Peter Huewe255aabd2012-02-09 21:11:44 +01003872 if ((tempah == Panel_1024x768) || (tempah == Panel_1024x768x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303873 tempbx = 1024;
3874 tempcx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01003875 } else if ((tempah == Panel_1280x1024) ||
3876 (tempah == Panel_1280x1024x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303877 tempbx = 1280;
3878 tempcx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01003879 } else if (tempah == Panel_1400x1050) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303880 tempbx = 1400;
3881 tempcx = 1050;
3882 } else {
3883 tempbx = 1600;
3884 tempcx = 1200;
3885 }
3886
3887 if (pVBInfo->LCDInfo & EnableScalingLCD) {
3888 tempbx = pVBInfo->HDE;
3889 tempcx = pVBInfo->VDE;
3890 }
3891
3892 pushbx = tempbx;
3893 tempax = pVBInfo->VT;
3894 pVBInfo->LCDHDES = LCDBDesPtr->LCDHDES;
3895 pVBInfo->LCDHRS = LCDBDesPtr->LCDHRS;
3896 pVBInfo->LCDVDES = LCDBDesPtr->LCDVDES;
3897 pVBInfo->LCDVRS = LCDBDesPtr->LCDVRS;
3898 tempbx = pVBInfo->LCDVDES;
3899 tempcx += tempbx;
3900
3901 if (tempcx >= tempax)
3902 tempcx -= tempax; /* lcdvdes */
3903
3904 temp = tempbx & 0x00FF; /* RVEQ1EQ=lcdvdes */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003905 xgifb_reg_set(pVBInfo->Part2Port, 0x05, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303906 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003907 xgifb_reg_set(pVBInfo->Part2Port, 0x06, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303908 tempch = ((tempcx & 0xFF00) >> 8) & 0x07;
3909 tempbh = ((tempbx & 0xFF00) >> 8) & 0x07;
3910 tempah = tempch;
3911 tempah = tempah << 3;
3912 tempah |= tempbh;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003913 xgifb_reg_set(pVBInfo->Part2Port, 0x02, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303914
3915 /* getlcdsync() */
3916 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
3917 tempcx = tempbx;
3918 tempax = pVBInfo->VT;
3919 tempbx = pVBInfo->LCDVRS;
3920
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303921 tempcx += tempbx;
3922 if (tempcx >= tempax)
3923 tempcx -= tempax;
3924
3925 temp = tempbx & 0x00FF; /* RTVACTEE=lcdvrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003926 xgifb_reg_set(pVBInfo->Part2Port, 0x04, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303927 temp = (tempbx & 0xFF00) >> 8;
3928 temp = temp << 4;
3929 temp |= (tempcx & 0x000F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003930 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303931 tempcx = pushbx;
3932 tempax = pVBInfo->HT;
3933 tempbx = pVBInfo->LCDHDES;
3934 tempbx &= 0x0FFF;
3935
3936 if (XGI_IsLCDDualLink(pVBInfo)) {
3937 tempax = tempax >> 1;
3938 tempbx = tempbx >> 1;
3939 tempcx = tempcx >> 1;
3940 }
3941
Peter Huewe6896b942012-02-09 21:11:46 +01003942 if (pVBInfo->VBType & VB_SIS302LV)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303943 tempbx += 1;
3944
3945 if (pVBInfo->VBType & VB_XGI301C) /* tap4 */
3946 tempbx += 1;
3947
3948 tempcx += tempbx;
3949
3950 if (tempcx >= tempax)
3951 tempcx -= tempax;
3952
3953 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003954 xgifb_reg_set(pVBInfo->Part2Port, 0x1F, temp); /* RHBLKE=lcdhdes */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303955 temp = ((tempbx & 0xFF00) >> 8) << 4;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003956 xgifb_reg_set(pVBInfo->Part2Port, 0x20, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303957 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003958 xgifb_reg_set(pVBInfo->Part2Port, 0x23, temp); /* RHEQPLE=lcdhdee */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303959 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003960 xgifb_reg_set(pVBInfo->Part2Port, 0x25, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303961
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303962 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
3963 tempcx = tempax;
3964 tempax = pVBInfo->HT;
3965 tempbx = pVBInfo->LCDHRS;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303966 if (XGI_IsLCDDualLink(pVBInfo)) {
3967 tempax = tempax >> 1;
3968 tempbx = tempbx >> 1;
3969 tempcx = tempcx >> 1;
3970 }
3971
Peter Huewe6896b942012-02-09 21:11:46 +01003972 if (pVBInfo->VBType & VB_SIS302LV)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303973 tempbx += 1;
3974
3975 tempcx += tempbx;
3976
3977 if (tempcx >= tempax)
3978 tempcx -= tempax;
3979
3980 temp = tempbx & 0x00FF; /* RHBURSTS=lcdhrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003981 xgifb_reg_set(pVBInfo->Part2Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303982
3983 temp = (tempbx & 0xFF00) >> 8;
3984 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003985 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303986 temp = tempcx & 0x00FF; /* RHSYEXP2S=lcdhre */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003987 xgifb_reg_set(pVBInfo->Part2Port, 0x21, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303988
Peter Huewea3d675c2012-02-09 21:11:47 +01003989 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303990 if (pVBInfo->VGAVDE == 525) {
Peter Huewe6896b942012-02-09 21:11:46 +01003991 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
3992 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303993 | VB_XGI301C)) {
3994 temp = 0xC6;
3995 } else
3996 temp = 0xC4;
3997
Aaro Koskinen8104e322011-03-13 12:26:22 +02003998 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
3999 xgifb_reg_set(pVBInfo->Part2Port, 0x30, 0xB3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304000 }
4001
4002 if (pVBInfo->VGAVDE == 420) {
Peter Huewe6896b942012-02-09 21:11:46 +01004003 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
4004 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304005 | VB_XGI301C)) {
4006 temp = 0x4F;
4007 } else
4008 temp = 0x4E;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004009 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304010 }
4011 }
4012}
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004013
4014/* --------------------------------------------------------------------- */
4015/* Function : XGI_GetTap4Ptr */
4016/* Input : */
4017/* Output : di -> Tap4 Reg. Setting Pointer */
4018/* Description : */
4019/* --------------------------------------------------------------------- */
Aaro Koskinen1cccd9e2012-11-04 21:15:06 +02004020static struct XGI301C_Tap4TimingStruct const
4021*XGI_GetTap4Ptr(unsigned short tempcx, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004022{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304023 unsigned short tempax, tempbx, i;
Aaro Koskinen1cccd9e2012-11-04 21:15:06 +02004024 struct XGI301C_Tap4TimingStruct const *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004025
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304026 if (tempcx == 0) {
4027 tempax = pVBInfo->VGAHDE;
4028 tempbx = pVBInfo->HDE;
4029 } else {
4030 tempax = pVBInfo->VGAVDE;
4031 tempbx = pVBInfo->VDE;
4032 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004033
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004034 if (tempax <= tempbx)
4035 return &xgifb_tap4_timing[0];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304036 else
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004037 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing; /* NTSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004038
Peter Huewe599801f2012-02-09 21:11:45 +01004039 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304040 Tap4TimingPtr = PALTap4Timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004041
Peter Huewe599801f2012-02-09 21:11:45 +01004042 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
4043 if ((pVBInfo->TVInfo & TVSetYPbPr525i) ||
4044 (pVBInfo->TVInfo & TVSetYPbPr525p))
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004045 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing;
Peter Huewe599801f2012-02-09 21:11:45 +01004046 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304047 Tap4TimingPtr = YPbPr750pTap4Timing;
4048 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004049
Peter Huewe599801f2012-02-09 21:11:45 +01004050 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004051 Tap4TimingPtr = xgifb_tap4_timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004052
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304053 i = 0;
4054 while (Tap4TimingPtr[i].DE != 0xFFFF) {
4055 if (Tap4TimingPtr[i].DE == tempax)
4056 break;
4057 i++;
4058 }
4059 return &Tap4TimingPtr[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004060}
4061
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004062static void XGI_SetTap4Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004063{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304064 unsigned short i, j;
Aaro Koskinen1cccd9e2012-11-04 21:15:06 +02004065 struct XGI301C_Tap4TimingStruct const *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004066
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304067 if (!(pVBInfo->VBType & VB_XGI301C))
4068 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004069
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304070 Tap4TimingPtr = XGI_GetTap4Ptr(0, pVBInfo); /* Set Horizontal Scaling */
4071 for (i = 0x80, j = 0; i <= 0xBF; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004072 xgifb_reg_set(pVBInfo->Part2Port, i, Tap4TimingPtr->Reg[j]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004073
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004074 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
Peter Huewe599801f2012-02-09 21:11:45 +01004075 (!(pVBInfo->VBInfo & SetCRT2ToHiVision))) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004076 /* Set Vertical Scaling */
4077 Tap4TimingPtr = XGI_GetTap4Ptr(1, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304078 for (i = 0xC0, j = 0; i < 0xFF; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004079 xgifb_reg_set(pVBInfo->Part2Port,
4080 i,
4081 Tap4TimingPtr->Reg[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304082 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004083
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004084 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
Peter Huewe599801f2012-02-09 21:11:45 +01004085 (!(pVBInfo->VBInfo & SetCRT2ToHiVision)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004086 /* Enable V.Scaling */
4087 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304088 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004089 /* Enable H.Scaling */
4090 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x10);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004091}
4092
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004093static void XGI_SetGroup3(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304094 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004095{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304096 unsigned short i;
Aaro Koskinend21222d2012-09-11 00:15:29 +03004097 unsigned char const *tempdi;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304098 unsigned short modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004099
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004100 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004101 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004102
Aaro Koskinen8104e322011-03-13 12:26:22 +02004103 xgifb_reg_set(pVBInfo->Part3Port, 0x00, 0x00);
Peter Huewe599801f2012-02-09 21:11:45 +01004104 if (pVBInfo->TVInfo & TVSetPAL) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004105 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
4106 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304107 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004108 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xF5);
4109 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xB7);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304110 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004111
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304112 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
4113 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004114
Peter Huewe599801f2012-02-09 21:11:45 +01004115 if (pVBInfo->TVInfo & TVSetPALM) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004116 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
4117 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
4118 xgifb_reg_set(pVBInfo->Part3Port, 0x3D, 0xA8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304119 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004120
Peter Huewe599801f2012-02-09 21:11:45 +01004121 if ((pVBInfo->VBInfo & SetCRT2ToHiVision) || (pVBInfo->VBInfo
4122 & SetCRT2ToYPbPr525750)) {
4123 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304124 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004125
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004126 tempdi = XGI330_HiTVGroup3Data;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304127 if (pVBInfo->SetFlag & TVSimuMode) {
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004128 tempdi = XGI330_HiTVGroup3Simu;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304129 if (!(modeflag & Charx8Dot))
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004130 tempdi = XGI330_HiTVGroup3Text;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304131 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004132
Peter Huewe599801f2012-02-09 21:11:45 +01004133 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004134 tempdi = XGI330_Ren525pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004135
Peter Huewe599801f2012-02-09 21:11:45 +01004136 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004137 tempdi = XGI330_Ren750pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004138
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304139 for (i = 0; i <= 0x3E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004140 xgifb_reg_set(pVBInfo->Part3Port, i, tempdi[i]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004141
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304142 if (pVBInfo->VBType & VB_XGI301C) { /* Marcovision */
Peter Huewe599801f2012-02-09 21:11:45 +01004143 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004144 xgifb_reg_set(pVBInfo->Part3Port, 0x28, 0x3f);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304145 }
4146 }
4147 return;
4148} /* {end of XGI_SetGroup3} */
4149
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004150static void XGI_SetGroup4(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304151 unsigned short RefreshRateTableIndex,
4152 struct xgi_hw_device_info *HwDeviceExtension,
4153 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004154{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304155 unsigned short tempax, tempcx, tempbx, modeflag, temp, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004156
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304157 unsigned long tempebx, tempeax, templong;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004158
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004159 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004160 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304161 temp = pVBInfo->RVBHCFACT;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004162 xgifb_reg_set(pVBInfo->Part4Port, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004163
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304164 tempbx = pVBInfo->RVBHCMAX;
4165 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004166 xgifb_reg_set(pVBInfo->Part4Port, 0x14, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304167 temp2 = ((tempbx & 0xFF00) >> 8) << 7;
4168 tempcx = pVBInfo->VGAHT - 1;
4169 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004170 xgifb_reg_set(pVBInfo->Part4Port, 0x16, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004171
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304172 temp = ((tempcx & 0xFF00) >> 8) << 3;
4173 temp2 |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004174
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304175 tempcx = pVBInfo->VGAVT - 1;
4176 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
4177 tempcx -= 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004178
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304179 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004180 xgifb_reg_set(pVBInfo->Part4Port, 0x17, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304181 temp = temp2 | ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004182 xgifb_reg_set(pVBInfo->Part4Port, 0x15, temp);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004183 xgifb_reg_or(pVBInfo->Part4Port, 0x0D, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304184 tempcx = pVBInfo->VBInfo;
4185 tempbx = pVBInfo->VGAHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004186
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304187 if (modeflag & HalfDCLK)
4188 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004189
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304190 if (XGI_IsLCDDualLink(pVBInfo))
4191 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004192
Peter Huewe599801f2012-02-09 21:11:45 +01004193 if (tempcx & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304194 temp = 0;
4195 if (tempbx <= 1024)
4196 temp = 0xA0;
4197 if (tempbx == 1280)
4198 temp = 0xC0;
4199 } else if (tempcx & SetCRT2ToTV) {
4200 temp = 0xA0;
4201 if (tempbx <= 800)
4202 temp = 0x80;
4203 } else {
4204 temp = 0x80;
4205 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4206 temp = 0;
4207 if (tempbx > 800)
4208 temp = 0x60;
4209 }
4210 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004211
Peter Huewe599801f2012-02-09 21:11:45 +01004212 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304213 temp = 0x00;
4214 if (pVBInfo->VGAHDE == 1280)
4215 temp = 0x40;
4216 if (pVBInfo->VGAHDE == 1024)
4217 temp = 0x20;
4218 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004219 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0E, ~0xEF, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004220
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304221 tempebx = pVBInfo->VDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004222
Peter Huewe599801f2012-02-09 21:11:45 +01004223 if (tempcx & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304224 if (!(temp & 0xE000))
4225 tempbx = tempbx >> 1;
4226 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004227
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304228 tempcx = pVBInfo->RVBHRS;
4229 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004230 xgifb_reg_set(pVBInfo->Part4Port, 0x18, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004231
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304232 tempeax = pVBInfo->VGAVDE;
4233 tempcx |= 0x04000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004234
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304235 if (tempeax <= tempebx) {
4236 tempcx = (tempcx & (~0x4000));
4237 tempeax = pVBInfo->VGAVDE;
4238 } else {
4239 tempeax -= tempebx;
4240 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004241
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304242 templong = (tempeax * 256 * 1024) % tempebx;
4243 tempeax = (tempeax * 256 * 1024) / tempebx;
4244 tempebx = tempeax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004245
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304246 if (templong != 0)
4247 tempebx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004248
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304249 temp = (unsigned short) (tempebx & 0x000000FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004250 xgifb_reg_set(pVBInfo->Part4Port, 0x1B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004251
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304252 temp = (unsigned short) ((tempebx & 0x0000FF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004253 xgifb_reg_set(pVBInfo->Part4Port, 0x1A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304254 tempbx = (unsigned short) (tempebx >> 16);
4255 temp = tempbx & 0x00FF;
4256 temp = temp << 4;
4257 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004258 xgifb_reg_set(pVBInfo->Part4Port, 0x19, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004259
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304260 /* 301b */
Peter Huewe6896b942012-02-09 21:11:46 +01004261 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4262 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304263 temp = 0x0028;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004264 xgifb_reg_set(pVBInfo->Part4Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304265 tempax = pVBInfo->VGAHDE;
4266 if (modeflag & HalfDCLK)
4267 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004268
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304269 if (XGI_IsLCDDualLink(pVBInfo))
4270 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004271
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304272 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4273 if (tempax > 800)
4274 tempax -= 800;
Aaro Koskinend3ae5762012-09-11 00:15:27 +03004275 } else if (pVBInfo->VGAHDE > 800) {
4276 if (pVBInfo->VGAHDE == 1024)
4277 tempax = (tempax * 25 / 32) - 1;
4278 else
4279 tempax = (tempax * 20 / 32) - 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304280 }
4281 tempax -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004282
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304283 temp = (tempax & 0xFF00) >> 8;
4284 temp = ((temp & 0x0003) << 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004285 xgifb_reg_set(pVBInfo->Part4Port, 0x1E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304286 temp = (tempax & 0x00FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004287 xgifb_reg_set(pVBInfo->Part4Port, 0x1D, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004288
Peter Huewe599801f2012-02-09 21:11:45 +01004289 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToHiVision)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304290 if (pVBInfo->VGAHDE > 800)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004291 xgifb_reg_or(pVBInfo->Part4Port, 0x1E, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004292
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304293 }
4294 temp = 0x0036;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004295
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304296 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4297 if (!(pVBInfo->TVInfo & (NTSC1024x768
Peter Huewe599801f2012-02-09 21:11:45 +01004298 | TVSetYPbPr525p | TVSetYPbPr750p
4299 | TVSetHiVision))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304300 temp |= 0x0001;
4301 if ((pVBInfo->VBInfo & SetInSlaveMode)
4302 && (!(pVBInfo->TVInfo
4303 & TVSimuMode)))
4304 temp &= (~0x0001);
4305 }
4306 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004307
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004308 xgifb_reg_and_or(pVBInfo->Part4Port, 0x1F, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304309 tempbx = pVBInfo->HT;
4310 if (XGI_IsLCDDualLink(pVBInfo))
4311 tempbx = tempbx >> 1;
4312 tempbx = (tempbx >> 1) - 2;
4313 temp = ((tempbx & 0x0700) >> 8) << 3;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004314 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304315 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004316 xgifb_reg_set(pVBInfo->Part4Port, 0x22, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304317 }
4318 /* end 301b */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004319
Aaro Koskinen8951dad2012-09-11 00:15:30 +03004320 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004321}
4322
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004323static void XGINew_EnableCRT2(struct vb_device_info *pVBInfo)
4324{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004325 xgifb_reg_and_or(pVBInfo->P3c4, 0x1E, 0xFF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004326}
4327
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004328static void XGI_SetGroup5(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304329 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004330{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304331 if (pVBInfo->ModeType == ModeVGA) {
4332 if (!(pVBInfo->VBInfo & (SetInSlaveMode | LoadDACFlag
Peter Huewe6896b942012-02-09 21:11:46 +01004333 | DisableCRT2Display))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304334 XGINew_EnableCRT2(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304335 }
4336 }
4337 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004338}
4339
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004340static void XGI_EnableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304341 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004342{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004343 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x40);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004344}
4345
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004346static void XGI_DisableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304347 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004348{
4349
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004350 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004351}
4352
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004353static unsigned char XGI_XG21CheckLVDSMode(struct xgifb_video_info *xgifb_info,
4354 unsigned short ModeNo, unsigned short ModeIdIndex,
4355 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004356{
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004357 unsigned short xres, yres, colordepth, modeflag, resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004358
Aaro Koskinenb3979922012-11-04 21:14:52 +02004359 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02004360 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
4361 yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004362 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004363 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004364
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304365 if (!(modeflag & Charx8Dot)) {
4366 xres /= 9;
4367 xres *= 8;
4368 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004369
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004370 if ((ModeNo > 0x13) && (modeflag & HalfDCLK))
4371 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004372
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004373 if ((ModeNo > 0x13) && (modeflag & DoubleScanMode))
4374 yres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004375
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004376 if (xres > xgifb_info->lvds_data.LVDSHDE)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304377 return 0;
Bill Pembertondda08c52010-06-17 13:10:42 -04004378
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004379 if (yres > xgifb_info->lvds_data.LVDSVDE)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304380 return 0;
4381
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004382 if (xres != xgifb_info->lvds_data.LVDSHDE ||
4383 yres != xgifb_info->lvds_data.LVDSVDE) {
4384 colordepth = XGI_GetColorDepth(ModeNo, ModeIdIndex, pVBInfo);
4385 if (colordepth > 2)
4386 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304387 }
4388 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004389}
4390
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004391static void xgifb_set_lvds(struct xgifb_video_info *xgifb_info,
4392 int chip_id,
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004393 unsigned short ModeNo,
4394 unsigned short ModeIdIndex,
4395 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004396{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304397 unsigned char temp, Miscdata;
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004398 unsigned short xres, yres, modeflag, resindex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304399 unsigned short LVDSHT, LVDSHBS, LVDSHRS, LVDSHRE, LVDSHBE;
4400 unsigned short LVDSVT, LVDSVBS, LVDSVRS, LVDSVRE, LVDSVBE;
4401 unsigned short value;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004402
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004403 temp = (unsigned char) ((xgifb_info->lvds_data.LVDS_Capability &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004404 (LCDPolarity << 8)) >> 8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304405 temp &= LCDPolarity;
Peter Huewe9388ad92013-02-15 20:37:10 +01004406 Miscdata = inb(pVBInfo->P3cc);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004407
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004408 outb((Miscdata & 0x3F) | temp, pVBInfo->P3c2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004409
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004410 temp = xgifb_info->lvds_data.LVDS_Capability & LCDPolarity;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004411 /* SR35[7] FP VSync polarity */
4412 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x80, temp & 0x80);
4413 /* SR30[5] FP HSync polarity */
4414 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, ~0x20, (temp & 0x40) >> 1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004415
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004416 if (chip_id == XG27)
4417 XGI_SetXG27FPBits(pVBInfo);
4418 else
4419 XGI_SetXG21FPBits(pVBInfo);
4420
Aaro Koskinenb3979922012-11-04 21:14:52 +02004421 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02004422 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
4423 yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004424 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004425 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004426
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304427 if (!(modeflag & Charx8Dot))
4428 xres = xres * 8 / 9;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004429
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004430 LVDSHT = xgifb_info->lvds_data.LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004431
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004432 LVDSHBS = xres + (xgifb_info->lvds_data.LVDSHDE - xres) / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004433
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304434 if (LVDSHBS > LVDSHT)
4435 LVDSHBS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004436
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004437 LVDSHRS = LVDSHBS + xgifb_info->lvds_data.LVDSHFP;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304438 if (LVDSHRS > LVDSHT)
4439 LVDSHRS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004440
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004441 LVDSHRE = LVDSHRS + xgifb_info->lvds_data.LVDSHSYNC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304442 if (LVDSHRE > LVDSHT)
4443 LVDSHRE -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004444
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004445 LVDSHBE = LVDSHBS + LVDSHT - xgifb_info->lvds_data.LVDSHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004446
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004447 LVDSVT = xgifb_info->lvds_data.LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004448
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004449 LVDSVBS = yres + (xgifb_info->lvds_data.LVDSVDE - yres) / 2;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004450 if (modeflag & DoubleScanMode)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304451 LVDSVBS += yres / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004452
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304453 if (LVDSVBS > LVDSVT)
4454 LVDSVBS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004455
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004456 LVDSVRS = LVDSVBS + xgifb_info->lvds_data.LVDSVFP;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304457 if (LVDSVRS > LVDSVT)
4458 LVDSVRS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004459
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004460 LVDSVRE = LVDSVRS + xgifb_info->lvds_data.LVDSVSYNC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304461 if (LVDSVRE > LVDSVT)
4462 LVDSVRE -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004463
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004464 LVDSVBE = LVDSVBS + LVDSVT - xgifb_info->lvds_data.LVDSVDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004465
Peter Huewe9388ad92013-02-15 20:37:10 +01004466 temp = xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004467 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp & 0x7f); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004468
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304469 if (!(modeflag & Charx8Dot))
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004470 xgifb_reg_or(pVBInfo->P3c4, 0x1, 0x1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004471
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304472 /* HT SR0B[1:0] CR00 */
4473 value = (LVDSHT >> 3) - 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004474 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004475 xgifb_reg_set(pVBInfo->P3d4, 0x0, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004476
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304477 /* HBS SR0B[5:4] CR02 */
4478 value = (LVDSHBS >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004479 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x30, (value & 0x300) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004480 xgifb_reg_set(pVBInfo->P3d4, 0x2, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004481
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304482 /* HBE SR0C[1:0] CR05[7] CR03[4:0] */
4483 value = (LVDSHBE >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004484 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x03, (value & 0xC0) >> 6);
4485 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x80, (value & 0x20) << 2);
4486 xgifb_reg_and_or(pVBInfo->P3d4, 0x03, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004487
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304488 /* HRS SR0B[7:6] CR04 */
4489 value = (LVDSHRS >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004490 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0xC0, (value & 0x300) >> 2);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004491 xgifb_reg_set(pVBInfo->P3d4, 0x4, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004492
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304493 /* Panel HRS SR2F[1:0] SR2E[7:0] */
4494 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004495 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004496 xgifb_reg_set(pVBInfo->P3c4, 0x2E, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004497
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304498 /* HRE SR0C[2] CR05[4:0] */
4499 value = (LVDSHRE >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004500 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x04, (value & 0x20) >> 3);
4501 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004502
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304503 /* Panel HRE SR2F[7:2] */
4504 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004505 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0xFC, value << 2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004506
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304507 /* VT SR0A[0] CR07[5][0] CR06 */
4508 value = LVDSVT - 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004509 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x01, (value & 0x400) >> 10);
4510 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x20, (value & 0x200) >> 4);
4511 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x01, (value & 0x100) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004512 xgifb_reg_set(pVBInfo->P3d4, 0x06, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004513
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304514 /* VBS SR0A[2] CR09[5] CR07[3] CR15 */
4515 value = LVDSVBS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004516 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x04, (value & 0x400) >> 8);
4517 xgifb_reg_and_or(pVBInfo->P3d4, 0x09, ~0x20, (value & 0x200) >> 4);
4518 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x08, (value & 0x100) >> 5);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004519 xgifb_reg_set(pVBInfo->P3d4, 0x15, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004520
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304521 /* VBE SR0A[4] CR16 */
4522 value = LVDSVBE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004523 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x10, (value & 0x100) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004524 xgifb_reg_set(pVBInfo->P3d4, 0x16, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004525
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304526 /* VRS SR0A[3] CR7[7][2] CR10 */
4527 value = LVDSVRS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004528 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x08, (value & 0x400) >> 7);
4529 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x80, (value & 0x200) >> 2);
4530 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x04, (value & 0x100) >> 6);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004531 xgifb_reg_set(pVBInfo->P3d4, 0x10, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004532
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004533 if (chip_id == XG27) {
4534 /* Panel VRS SR35[2:0] SR34[7:0] */
4535 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07,
4536 (value & 0x700) >> 8);
4537 xgifb_reg_set(pVBInfo->P3c4, 0x34, value & 0xFF);
4538 } else {
4539 /* Panel VRS SR3F[1:0] SR34[7:0] SR33[0] */
4540 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0x03,
4541 (value & 0x600) >> 9);
4542 xgifb_reg_set(pVBInfo->P3c4, 0x34, (value >> 1) & 0xFF);
4543 xgifb_reg_and_or(pVBInfo->P3d4, 0x33, ~0x01, value & 0x01);
4544 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004545
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304546 /* VRE SR0A[5] CR11[3:0] */
4547 value = LVDSVRE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004548 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x20, (value & 0x10) << 1);
4549 xgifb_reg_and_or(pVBInfo->P3d4, 0x11, ~0x0F, value & 0x0F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004550
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304551 /* Panel VRE SR3F[7:2] */
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004552 if (chip_id == XG27)
4553 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
4554 (value << 2) & 0xFC);
4555 else
4556 /* SR3F[7] has to be 0, h/w bug */
4557 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
4558 (value << 2) & 0x7C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004559
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304560 for (temp = 0, value = 0; temp < 3; temp++) {
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004561
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004562 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, value);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004563 xgifb_reg_set(pVBInfo->P3c4,
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004564 0x2B, xgifb_info->lvds_data.VCLKData1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004565 xgifb_reg_set(pVBInfo->P3c4,
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004566 0x2C, xgifb_info->lvds_data.VCLKData2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304567 value += 0x10;
4568 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004569
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304570 if (!(modeflag & Charx8Dot)) {
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004571 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004572 outb(0x13, pVBInfo->P3c0); /* set index */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004573 /* set data, panning = 0, shift left 1 dot*/
4574 outb(0x00, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004575
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004576 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004577 outb(0x20, pVBInfo->P3c0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304578
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004579 inb(pVBInfo->P3da); /* reset 3da */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304580 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004581
4582}
4583
4584/* --------------------------------------------------------------------- */
4585/* Function : XGI_IsLCDON */
4586/* Input : */
Bill Pembertondda08c52010-06-17 13:10:42 -04004587/* Output : 0 : Skip PSC Control */
4588/* 1: Disable PSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004589/* Description : */
4590/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004591static unsigned char XGI_IsLCDON(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004592{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304593 unsigned short tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004594
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304595 tempax = pVBInfo->VBInfo;
4596 if (tempax & SetCRT2ToDualEdge)
4597 return 0;
Peter Huewe6896b942012-02-09 21:11:46 +01004598 else if (tempax & (DisableCRT2Display | SwitchCRT2 | SetSimuScanMode))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304599 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004600
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304601 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004602}
4603
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004604/* --------------------------------------------------------------------- */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004605/* Function : XGI_EnableChISLCD */
4606/* Input : */
4607/* Output : 0 -> Not LCD mode */
Peter Huewe06cc47b2013-02-03 22:54:38 +01004608/* Description : if bool enable = true -> enable, else disable */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004609/* --------------------------------------------------------------------- */
Peter Huewe06cc47b2013-02-03 22:54:38 +01004610static unsigned char XGI_EnableChISLCD(struct vb_device_info *pVBInfo,
4611 bool enable)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004612{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304613 unsigned short tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004614
Peter Huewe06cc47b2013-02-03 22:54:38 +01004615 if (enable)
4616 tempbx = pVBInfo->SetFlag & (EnableChA | EnableChB);
4617 else
4618 tempbx = pVBInfo->SetFlag & (DisableChA | DisableChB);
4619
Aaro Koskinen58839b02011-03-13 12:26:23 +02004620 tempah = ~((unsigned short) xgifb_reg_get(pVBInfo->Part1Port, 0x2E));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004621
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304622 if (tempbx & (EnableChA | DisableChA)) {
4623 if (!(tempah & 0x08)) /* Chk LCDA Mode */
4624 return 0;
4625 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004626
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304627 if (!(tempbx & (EnableChB | DisableChB)))
Bill Pembertondda08c52010-06-17 13:10:42 -04004628 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004629
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304630 if (tempah & 0x01) /* Chk LCDB Mode */
4631 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004632
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304633 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004634}
4635
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004636static void XGI_DisableBridge(struct xgifb_video_info *xgifb_info,
4637 struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304638 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004639{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02004640 unsigned short tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004641
Peter Huewe6896b942012-02-09 21:11:46 +01004642 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4643 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304644 tempah = 0x3F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004645 if (!(pVBInfo->VBInfo &
4646 (DisableCRT2Display | SetSimuScanMode))) {
Peter Huewea3d675c2012-02-09 21:11:47 +01004647 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304648 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
4649 tempah = 0x7F; /* Disable Channel A */
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004650 if (!(pVBInfo->VBInfo &
4651 XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004652 /* Disable Channel B */
4653 tempah = 0xBF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004654
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304655 if (pVBInfo->SetFlag & DisableChB)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004656 /* force to disable Cahnnel */
4657 tempah &= 0xBF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004658
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304659 if (pVBInfo->SetFlag & DisableChA)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004660 /* Force to disable Channel B */
4661 tempah &= 0x7F;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304662 }
4663 }
4664 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004665
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004666 /* disable part4_1f */
4667 xgifb_reg_and(pVBInfo->Part4Port, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004668
Peter Huewe6896b942012-02-09 21:11:46 +01004669 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004670 if (((pVBInfo->VBInfo &
Peter Huewe06cc47b2013-02-03 22:54:38 +01004671 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))) ||
4672 (XGI_EnableChISLCD(pVBInfo, false)) ||
4673 (XGI_IsLCDON(pVBInfo)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004674 /* LVDS Driver power down */
4675 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304676 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004677
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304678 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
Peter Huewea3d675c2012-02-09 21:11:47 +01004679 & (DisableCRT2Display | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304680 | SetSimuScanMode))) {
4681 if (pVBInfo->SetFlag & GatingCRT)
4682 XGI_EnableGatingCRT(HwDeviceExtension, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004683 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304684 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004685
Peter Huewea3d675c2012-02-09 21:11:47 +01004686 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304687 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
Peter Huewea3d675c2012-02-09 21:11:47 +01004688 & XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004689 /* Power down */
4690 xgifb_reg_and(pVBInfo->Part1Port, 0x1e, 0xdf);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304691 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004692
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004693 /* disable TV as primary VGA swap */
4694 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004695
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304696 if ((pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToDualEdge)))
Aaro Koskinendc505562011-03-13 12:26:26 +02004697 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004698
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004699 if ((pVBInfo->SetFlag & DisableChB) ||
4700 (pVBInfo->VBInfo &
4701 (DisableCRT2Display | SetSimuScanMode)) ||
Peter Huewea3d675c2012-02-09 21:11:47 +01004702 ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) &&
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004703 (pVBInfo->VBInfo &
4704 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004705 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004706
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004707 if ((pVBInfo->SetFlag & DisableChB) ||
4708 (pVBInfo->VBInfo &
4709 (DisableCRT2Display | SetSimuScanMode)) ||
Peter Huewea3d675c2012-02-09 21:11:47 +01004710 (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) ||
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004711 (pVBInfo->VBInfo &
4712 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))) {
4713 /* save Part1 index 0 */
4714 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
4715 /* BTDAC = 1, avoid VB reset */
4716 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x10);
4717 /* disable CRT2 */
4718 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
4719 /* restore Part1 index 0 */
4720 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304721 }
4722 } else { /* {301} */
4723 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004724 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
4725 /* Disable CRT2 */
4726 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
4727 /* Disable TV asPrimary VGA swap */
4728 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xDF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304729 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004730
Peter Huewea3d675c2012-02-09 21:11:47 +01004731 if (pVBInfo->VBInfo & (DisableCRT2Display | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304732 | SetSimuScanMode))
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004733 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304734 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004735}
4736
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004737/* --------------------------------------------------------------------- */
4738/* Function : XGI_GetTVPtrIndex */
4739/* Input : */
4740/* Output : */
4741/* Description : bx 0 : ExtNTSC */
4742/* 1 : StNTSC */
4743/* 2 : ExtPAL */
4744/* 3 : StPAL */
4745/* 4 : ExtHiTV */
4746/* 5 : StHiTV */
4747/* 6 : Ext525i */
4748/* 7 : St525i */
4749/* 8 : Ext525p */
4750/* 9 : St525p */
4751/* A : Ext750p */
4752/* B : St750p */
4753/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004754static unsigned short XGI_GetTVPtrIndex(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004755{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304756 unsigned short tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004757
Peter Huewe599801f2012-02-09 21:11:45 +01004758 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304759 tempbx = 2;
Peter Huewe599801f2012-02-09 21:11:45 +01004760 if (pVBInfo->TVInfo & TVSetHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304761 tempbx = 4;
Peter Huewe599801f2012-02-09 21:11:45 +01004762 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304763 tempbx = 6;
Peter Huewe599801f2012-02-09 21:11:45 +01004764 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304765 tempbx = 8;
Peter Huewe599801f2012-02-09 21:11:45 +01004766 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304767 tempbx = 10;
4768 if (pVBInfo->TVInfo & TVSimuMode)
4769 tempbx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004770
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304771 return tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004772}
4773
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004774/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004775/* Function : XGI_GetTVPtrIndex2 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004776/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004777/* Output : bx 0 : NTSC */
4778/* 1 : PAL */
4779/* 2 : PALM */
4780/* 3 : PALN */
4781/* 4 : NTSC1024x768 */
4782/* 5 : PAL-M 1024x768 */
4783/* 6-7: reserved */
4784/* cl 0 : YFilter1 */
4785/* 1 : YFilter2 */
4786/* ch 0 : 301A */
4787/* 1 : 301B/302B/301LV/302LV */
4788/* Description : */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004789/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004790static void XGI_GetTVPtrIndex2(unsigned short *tempbx, unsigned char *tempcl,
4791 unsigned char *tempch, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004792{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004793 *tempbx = 0;
4794 *tempcl = 0;
4795 *tempch = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004796
Peter Huewe599801f2012-02-09 21:11:45 +01004797 if (pVBInfo->TVInfo & TVSetPAL)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004798 *tempbx = 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004799
Peter Huewe599801f2012-02-09 21:11:45 +01004800 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004801 *tempbx = 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004802
Peter Huewe599801f2012-02-09 21:11:45 +01004803 if (pVBInfo->TVInfo & TVSetPALN)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004804 *tempbx = 3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004805
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004806 if (pVBInfo->TVInfo & NTSC1024x768) {
4807 *tempbx = 4;
Peter Huewe599801f2012-02-09 21:11:45 +01004808 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004809 *tempbx = 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304810 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004811
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 if ((!(pVBInfo->VBInfo & SetInSlaveMode)) || (pVBInfo->TVInfo
4815 & TVSimuMode)) {
4816 *tempbx += 8;
4817 *tempcl += 1;
4818 }
4819 }
4820
Peter Huewe6896b942012-02-09 21:11:46 +01004821 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4822 | VB_SIS302LV | VB_XGI301C))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004823 (*tempch)++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004824}
4825
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004826static void XGI_SetDelayComp(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004827{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304828 unsigned char tempah, tempbl, tempbh;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004829
Peter Huewe6896b942012-02-09 21:11:46 +01004830 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4831 | VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01004832 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304833 | SetCRT2ToTV | SetCRT2ToRAMDAC)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304834 tempbh = 0;
Peter Huewe03f76fc2012-06-14 00:21:50 +02004835 tempbl = XGI301TVDelay;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004836
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304837 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
4838 tempbl = tempbl >> 4;
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004839 if (pVBInfo->VBInfo &
4840 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Peter Huewe03f76fc2012-06-14 00:21:50 +02004841 tempbh = XGI301LCDDelay;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004842
Peter Huewea3d675c2012-02-09 21:11:47 +01004843 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304844 tempbl = tempbh;
4845 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004846
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304847 tempbl &= 0x0F;
4848 tempbh &= 0xF0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02004849 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2D);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004850
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304851 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD
4852 | SetCRT2ToTV)) { /* Channel B */
4853 tempah &= 0xF0;
4854 tempah |= tempbl;
4855 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004856
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004857 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
4858 /* Channel A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304859 tempah &= 0x0F;
4860 tempah |= tempbh;
4861 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02004862 xgifb_reg_set(pVBInfo->Part1Port, 0x2D, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304863 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304864 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004865}
4866
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004867static void XGI_SetLCDCap_A(unsigned short tempcx,
4868 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004869{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304870 unsigned short temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004871
Aaro Koskinen58839b02011-03-13 12:26:23 +02004872 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004873
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304874 if (temp & LCDRGB18Bit) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004875 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004876 /* Enable Dither */
4877 (unsigned short) (0x20 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004878 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304879 } else {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004880 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304881 (unsigned short) (0x30 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004882 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304883 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004884}
4885
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004886/* --------------------------------------------------------------------- */
4887/* Function : XGI_SetLCDCap_B */
4888/* Input : cx -> LCD Capability */
4889/* Output : */
4890/* Description : */
4891/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004892static void XGI_SetLCDCap_B(unsigned short tempcx,
4893 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004894{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304895 if (tempcx & EnableLCD24bpp) /* 24bits */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004896 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304897 (unsigned short) (((tempcx & 0x00ff) >> 6)
4898 | 0x0c));
4899 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004900 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304901 (unsigned short) (((tempcx & 0x00ff) >> 6)
4902 | 0x18)); /* Enable Dither */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004903}
4904
Aaro Koskinen7f04ec32011-11-27 23:03:05 +02004905static void XGI_LongWait(struct vb_device_info *pVBInfo)
4906{
4907 unsigned short i;
4908
4909 i = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
4910
4911 if (!(i & 0xC0)) {
4912 for (i = 0; i < 0xFFFF; i++) {
4913 if (!(inb(pVBInfo->P3da) & 0x08))
4914 break;
4915 }
4916
4917 for (i = 0; i < 0xFFFF; i++) {
4918 if ((inb(pVBInfo->P3da) & 0x08))
4919 break;
4920 }
4921 }
4922}
4923
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004924static void SetSpectrum(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004925{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304926 unsigned short index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004927
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304928 index = XGI_GetLCDCapPtr(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004929
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004930 /* disable down spectrum D[4] */
4931 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x8F);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304932 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004933 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x20); /* reset spectrum */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304934 XGI_LongWait(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004935
Aaro Koskinen8104e322011-03-13 12:26:22 +02004936 xgifb_reg_set(pVBInfo->Part4Port, 0x31,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304937 pVBInfo->LCDCapList[index].Spectrum_31);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004938 xgifb_reg_set(pVBInfo->Part4Port, 0x32,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304939 pVBInfo->LCDCapList[index].Spectrum_32);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004940 xgifb_reg_set(pVBInfo->Part4Port, 0x33,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304941 pVBInfo->LCDCapList[index].Spectrum_33);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004942 xgifb_reg_set(pVBInfo->Part4Port, 0x34,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304943 pVBInfo->LCDCapList[index].Spectrum_34);
4944 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004945 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x40); /* enable spectrum */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004946}
4947
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004948static void XGI_SetLCDCap(struct vb_device_info *pVBInfo)
4949{
4950 unsigned short tempcx;
4951
4952 tempcx = pVBInfo->LCDCapList[XGI_GetLCDCapPtr(pVBInfo)].LCD_Capability;
4953
Peter Huewef951dd02013-02-05 00:29:47 +01004954 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV |
4955 VB_SIS302LV | VB_XGI301C)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004956 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01004957 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004958 /* Set 301LV Capability */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004959 xgifb_reg_set(pVBInfo->Part4Port, 0x24,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004960 (unsigned char) (tempcx & 0x1F));
4961 }
4962 /* VB Driving */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004963 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004964 ~((EnableVBCLKDRVLOW | EnablePLLSPLOW) >> 8),
4965 (unsigned short) ((tempcx & (EnableVBCLKDRVLOW
4966 | EnablePLLSPLOW)) >> 8));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004967
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004968 if (pVBInfo->VBInfo & SetCRT2ToLCD)
4969 XGI_SetLCDCap_B(tempcx, pVBInfo);
Peter Huewea3d675c2012-02-09 21:11:47 +01004970 else if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004971 XGI_SetLCDCap_A(tempcx, pVBInfo);
4972
Peter Huewe6896b942012-02-09 21:11:46 +01004973 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004974 if (tempcx & EnableSpectrum)
4975 SetSpectrum(pVBInfo);
4976 }
4977 } else {
4978 /* LVDS,CH7017 */
4979 XGI_SetLCDCap_A(tempcx, pVBInfo);
4980 }
4981}
4982
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004983/* --------------------------------------------------------------------- */
4984/* Function : XGI_SetAntiFlicker */
4985/* Input : */
4986/* Output : */
4987/* Description : Set TV Customized Param. */
4988/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004989static void XGI_SetAntiFlicker(unsigned short ModeNo,
4990 unsigned short ModeIdIndex,
4991 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004992{
Aaro Koskinen36ae0352012-04-07 01:14:08 +03004993 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004994
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304995 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004996
Peter Huewe599801f2012-02-09 21:11:45 +01004997 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304998 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004999
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305000 tempbx = XGI_GetTVPtrIndex(pVBInfo);
5001 tempbx &= 0xFE;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305002 tempah = TVAntiFlickList[tempbx];
5003 tempah = tempah << 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005004
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005005 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0x8F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005006}
5007
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005008static void XGI_SetEdgeEnhance(unsigned short ModeNo,
5009 unsigned short ModeIdIndex,
5010 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005011{
Aaro Koskinen354f49f2012-04-07 01:14:09 +03005012 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005013
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305014 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005015
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305016 tempbx = XGI_GetTVPtrIndex(pVBInfo);
5017 tempbx &= 0xFE;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305018 tempah = TVEdgeList[tempbx];
5019 tempah = tempah << 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005020
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005021 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005022}
5023
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005024static void XGI_SetPhaseIncr(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005025{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305026 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005027
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305028 unsigned char tempcl, tempch;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005029
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305030 unsigned long tempData;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005031
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305032 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
5033 tempData = TVPhaseList[tempbx];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005034
Aaro Koskinen8104e322011-03-13 12:26:22 +02005035 xgifb_reg_set(pVBInfo->Part2Port, 0x31, (unsigned short) (tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305036 & 0x000000FF));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005037 xgifb_reg_set(pVBInfo->Part2Port, 0x32, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305038 & 0x0000FF00) >> 8));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005039 xgifb_reg_set(pVBInfo->Part2Port, 0x33, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305040 & 0x00FF0000) >> 16));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005041 xgifb_reg_set(pVBInfo->Part2Port, 0x34, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305042 & 0xFF000000) >> 24));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005043}
5044
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005045static void XGI_SetYFilter(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305046 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005047{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305048 unsigned short tempbx, index;
Aaro Koskinena68292f2012-11-04 21:15:07 +02005049 unsigned char const *filterPtr;
5050 unsigned char tempcl, tempch, tempal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005051
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305052 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005053
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305054 switch (tempbx) {
5055 case 0x00:
5056 case 0x04:
5057 filterPtr = NTSCYFilter1;
5058 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005059
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305060 case 0x01:
5061 filterPtr = PALYFilter1;
5062 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005063
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305064 case 0x02:
5065 case 0x05:
5066 case 0x0D:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305067 case 0x03:
Aaro Koskinen2555e942011-08-31 21:46:06 +03005068 filterPtr = xgifb_palmn_yfilter1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305069 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005070
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305071 case 0x08:
5072 case 0x0C:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305073 case 0x0A:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305074 case 0x0B:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305075 case 0x09:
Aaro Koskinen80f86f82011-08-31 21:46:05 +03005076 filterPtr = xgifb_yfilter2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305077 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005078
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305079 default:
5080 return;
5081 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005082
Aaro Koskinenb3979922012-11-04 21:14:52 +02005083 tempal = XGI330_EModeIDTable[ModeIdIndex].VB_ExtTVYFilterIndex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305084 if (tempcl == 0)
5085 index = tempal * 4;
5086 else
5087 index = tempal * 7;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005088
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305089 if ((tempcl == 0) && (tempch == 1)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005090 xgifb_reg_set(pVBInfo->Part2Port, 0x35, 0);
5091 xgifb_reg_set(pVBInfo->Part2Port, 0x36, 0);
5092 xgifb_reg_set(pVBInfo->Part2Port, 0x37, 0);
5093 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305094 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005095 xgifb_reg_set(pVBInfo->Part2Port, 0x35, filterPtr[index++]);
5096 xgifb_reg_set(pVBInfo->Part2Port, 0x36, filterPtr[index++]);
5097 xgifb_reg_set(pVBInfo->Part2Port, 0x37, filterPtr[index++]);
5098 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305099 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005100
Peter Huewe6896b942012-02-09 21:11:46 +01005101 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5102 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005103 xgifb_reg_set(pVBInfo->Part2Port, 0x48, filterPtr[index++]);
5104 xgifb_reg_set(pVBInfo->Part2Port, 0x49, filterPtr[index++]);
5105 xgifb_reg_set(pVBInfo->Part2Port, 0x4A, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305106 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005107}
5108
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005109/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005110/* Function : XGI_OEM310Setting */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005111/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005112/* Output : */
5113/* Description : Customized Param. for 301 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005114/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005115static void XGI_OEM310Setting(unsigned short ModeNo,
5116 unsigned short ModeIdIndex,
5117 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005118{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005119 XGI_SetDelayComp(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005120
Peter Huewea3d675c2012-02-09 21:11:47 +01005121 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005122 XGI_SetLCDCap(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005123
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005124 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005125 XGI_SetPhaseIncr(pVBInfo);
5126 XGI_SetYFilter(ModeNo, ModeIdIndex, pVBInfo);
5127 XGI_SetAntiFlicker(ModeNo, ModeIdIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005128
Peter Huewe6896b942012-02-09 21:11:46 +01005129 if (pVBInfo->VBType & VB_SIS301)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005130 XGI_SetEdgeEnhance(ModeNo, ModeIdIndex, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305131 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005132}
5133
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005134/* --------------------------------------------------------------------- */
5135/* Function : XGI_SetCRT2ModeRegs */
5136/* Input : */
5137/* Output : */
5138/* Description : Origin code for crt2group */
5139/* --------------------------------------------------------------------- */
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02005140static void XGI_SetCRT2ModeRegs(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305141 struct xgi_hw_device_info *HwDeviceExtension,
5142 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005143{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305144 unsigned short tempbl;
5145 short tempcl;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005146
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305147 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005148
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305149 tempah = 0;
5150 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005151 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305152 tempah &= ~0x10; /* BTRAMDAC */
5153 tempah |= 0x40; /* BTRAM */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005154
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305155 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
5156 | SetCRT2ToLCD)) {
5157 tempah = 0x40; /* BTDRAM */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005158 tempcl = pVBInfo->ModeType;
5159 tempcl -= ModeVGA;
5160 if (tempcl >= 0) {
5161 /* BT Color */
5162 tempah = (0x008 >> tempcl);
5163 if (tempah == 0)
5164 tempah = 1;
5165 tempah |= 0x040;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305166 }
5167 if (pVBInfo->VBInfo & SetInSlaveMode)
5168 tempah ^= 0x50; /* BTDAC */
5169 }
5170 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005171
Aaro Koskinen8104e322011-03-13 12:26:22 +02005172 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305173 tempah = 0x08;
5174 tempbl = 0xf0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005175
Miguel Gómeze123e462012-07-06 12:40:52 +02005176 if (pVBInfo->VBInfo & DisableCRT2Display)
5177 goto reg_and_or;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005178
Miguel Gómeze123e462012-07-06 12:40:52 +02005179 tempah = 0x00;
5180 tempbl = 0xff;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005181
Miguel Gómeze123e462012-07-06 12:40:52 +02005182 if (!(pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV |
5183 SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
5184 goto reg_and_or;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005185
Miguel Gómeze123e462012-07-06 12:40:52 +02005186 if ((pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) &&
5187 (!(pVBInfo->VBInfo & SetSimuScanMode))) {
5188 tempbl &= 0xf7;
5189 tempah |= 0x01;
5190 goto reg_and_or;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305191 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005192
Miguel Gómeze123e462012-07-06 12:40:52 +02005193 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
5194 tempbl &= 0xf7;
5195 tempah |= 0x01;
5196 }
5197
5198 if (!(pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD)))
5199 goto reg_and_or;
5200
5201 tempbl &= 0xf8;
5202 tempah = 0x01;
5203
5204 if (!(pVBInfo->VBInfo & SetInSlaveMode))
5205 tempah |= 0x02;
5206
5207 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
5208 tempah = tempah ^ 0x05;
5209 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
5210 tempah = tempah ^ 0x01;
5211 }
5212
5213 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
5214 tempah |= 0x08;
5215
5216reg_and_or:
5217 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl, tempah);
5218
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305219 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD
Peter Huewea3d675c2012-02-09 21:11:47 +01005220 | XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305221 tempah &= (~0x08);
5222 if ((pVBInfo->ModeType == ModeVGA) && (!(pVBInfo->VBInfo
5223 & SetInSlaveMode))) {
5224 tempah |= 0x010;
5225 }
5226 tempah |= 0x080;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005227
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305228 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305229 tempah |= 0x020;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005230 if (pVBInfo->VBInfo & DriverMode)
5231 tempah = tempah ^ 0x20;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305232 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005233
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005234 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D, ~0x0BF, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305235 tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005236
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305237 if (pVBInfo->LCDInfo & SetLCDDualLink)
5238 tempah |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005239
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305240 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305241 if (pVBInfo->TVInfo & RPLLDIV2XO)
5242 tempah |= 0x40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305243 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005244
Peter Huewe255aabd2012-02-09 21:11:44 +01005245 if ((pVBInfo->LCDResInfo == Panel_1280x1024)
5246 || (pVBInfo->LCDResInfo == Panel_1280x1024x75))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305247 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005248
Peter Huewe255aabd2012-02-09 21:11:44 +01005249 if (pVBInfo->LCDResInfo == Panel_1280x960)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305250 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005251
Aaro Koskinen8104e322011-03-13 12:26:22 +02005252 xgifb_reg_set(pVBInfo->Part4Port, 0x0C, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305253 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005254
Peter Huewe6896b942012-02-09 21:11:46 +01005255 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5256 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305257 tempah = 0;
5258 tempbl = 0xfb;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005259
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305260 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
5261 tempbl = 0xff;
Peter Huewea3d675c2012-02-09 21:11:47 +01005262 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305263 tempah |= 0x04; /* shampoo 0129 */
5264 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005265
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005266 xgifb_reg_and_or(pVBInfo->Part1Port, 0x13, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305267 tempah = 0x00;
5268 tempbl = 0xcf;
5269 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5270 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5271 tempah |= 0x30;
5272 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005273
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005274 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2c, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305275 tempah = 0;
5276 tempbl = 0x3f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005277
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305278 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5279 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5280 tempah |= 0xc0;
5281 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005282 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305283 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005284
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305285 tempah = 0;
5286 tempbl = 0x7f;
Peter Huewea3d675c2012-02-09 21:11:47 +01005287 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305288 tempbl = 0xff;
5289 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
5290 tempah |= 0x80;
5291 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005292
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005293 xgifb_reg_and_or(pVBInfo->Part4Port, 0x23, tempbl, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005294
Peter Huewe6896b942012-02-09 21:11:46 +01005295 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305296 if (pVBInfo->LCDInfo & SetLCDDualLink) {
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005297 xgifb_reg_or(pVBInfo->Part4Port, 0x27, 0x20);
5298 xgifb_reg_or(pVBInfo->Part4Port, 0x34, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305299 }
5300 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005301}
5302
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005303
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305304void XGI_UnLockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
5305 struct vb_device_info *pVBInfo)
5306{
5307
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005308 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2f, 0xFF, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005309
5310}
5311
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305312void XGI_LockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
5313 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005314{
5315
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005316 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2F, 0xFE, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005317
5318}
5319
Bill Pemberton80adad82010-06-17 13:10:51 -04005320unsigned char XGI_BridgeIsOn(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005321{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305322 unsigned short flag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005323
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305324 if (pVBInfo->IF_DEF_LVDS == 1) {
5325 return 1;
5326 } else {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005327 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305328 if ((flag == 1) || (flag == 2))
5329 return 1; /* 301b */
5330 else
5331 return 0;
5332 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005333}
5334
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005335unsigned short XGI_GetRatePtrCRT2(struct xgi_hw_device_info *pXGIHWDE,
5336 unsigned short ModeNo, unsigned short ModeIdIndex,
5337 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005338{
Peter Huewef2c22602013-02-03 22:54:30 +01005339 const u8 LCDARefreshIndex[] = {
5340 0x00, 0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x00 };
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005341
Peter Hueweef9a6b92013-02-03 04:08:43 +01005342 unsigned short RefreshRateTableIndex, i, index, temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005343
Aaro Koskinen58839b02011-03-13 12:26:23 +02005344 index = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005345 index = index >> pVBInfo->SelectCRT2Rate;
5346 index &= 0x0F;
5347
5348 if (pVBInfo->LCDInfo & LCDNonExpanding)
5349 index = 0;
5350
5351 if (index > 0)
5352 index--;
5353
5354 if (pVBInfo->SetFlag & ProgrammingCRT2) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005355 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005356 if (pVBInfo->IF_DEF_LVDS == 0) {
Peter Huewef2c22602013-02-03 22:54:30 +01005357 temp = LCDARefreshIndex[
5358 pVBInfo->LCDResInfo & 0x07];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005359
5360 if (index > temp)
5361 index = temp;
5362 } else {
5363 index = 0;
5364 }
5365 }
5366 }
5367
Aaro Koskinenb3979922012-11-04 21:14:52 +02005368 RefreshRateTableIndex = XGI330_EModeIDTable[ModeIdIndex].REFindex;
Aaro Koskinena39325d2012-11-04 21:14:53 +02005369 ModeNo = XGI330_RefIndex[RefreshRateTableIndex].ModeID;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005370 if (pXGIHWDE->jChipType >= XG20) { /* for XG20, XG21, XG27 */
Aaro Koskinena39325d2012-11-04 21:14:53 +02005371 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 800) &&
5372 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 600)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005373 index++;
5374 }
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005375 /* do the similar adjustment like XGISearchCRT1Rate() */
Aaro Koskinena39325d2012-11-04 21:14:53 +02005376 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 1024) &&
5377 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 768)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005378 index++;
5379 }
Aaro Koskinena39325d2012-11-04 21:14:53 +02005380 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 1280) &&
5381 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 1024)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005382 index++;
5383 }
5384 }
5385
5386 i = 0;
5387 do {
Aaro Koskinena39325d2012-11-04 21:14:53 +02005388 if (XGI330_RefIndex[RefreshRateTableIndex + i].
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005389 ModeID != ModeNo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005390 break;
Aaro Koskinena39325d2012-11-04 21:14:53 +02005391 temp = XGI330_RefIndex[RefreshRateTableIndex + i].Ext_InfoFlag;
Peter Huewe6896b942012-02-09 21:11:46 +01005392 temp &= ModeTypeMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005393 if (temp < pVBInfo->ModeType)
5394 break;
5395 i++;
5396 index--;
5397
5398 } while (index != 0xFFFF);
5399 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
5400 if (pVBInfo->VBInfo & SetInSlaveMode) {
Aaro Koskinena39325d2012-11-04 21:14:53 +02005401 temp = XGI330_RefIndex[RefreshRateTableIndex + i - 1].
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005402 Ext_InfoFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005403 if (temp & InterlaceMode)
5404 i++;
5405 }
5406 }
5407 i--;
5408 if ((pVBInfo->SetFlag & ProgrammingCRT2)) {
5409 temp = XGI_AjustCRT2Rate(ModeNo, ModeIdIndex,
5410 RefreshRateTableIndex, &i, pVBInfo);
5411 }
Aaro Koskinen9a0b2952011-11-27 23:03:16 +02005412 return RefreshRateTableIndex + i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005413}
5414
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005415static void XGI_SetLCDAGroup(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305416 struct xgi_hw_device_info *HwDeviceExtension,
5417 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005418{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005419 unsigned short RefreshRateTableIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005420
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005421 pVBInfo->SetFlag |= ProgrammingCRT2;
5422 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5423 ModeIdIndex, pVBInfo);
5424 XGI_GetLVDSResInfo(ModeNo, ModeIdIndex, pVBInfo);
5425 XGI_GetLVDSData(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5426 XGI_ModCRT1Regs(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5427 HwDeviceExtension, pVBInfo);
5428 XGI_SetLVDSRegs(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5429 XGI_SetCRT2ECLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005430}
5431
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02005432static unsigned char XGI_SetCRT2Group301(unsigned short ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005433 struct xgi_hw_device_info *HwDeviceExtension,
5434 struct vb_device_info *pVBInfo)
5435{
Peter Huewea9e29e62013-02-03 04:08:44 +01005436 unsigned short ModeIdIndex, RefreshRateTableIndex;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005437
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005438 pVBInfo->SetFlag |= ProgrammingCRT2;
5439 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
5440 pVBInfo->SelectCRT2Rate = 4;
5441 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5442 ModeIdIndex, pVBInfo);
5443 XGI_SaveCRT2Info(ModeNo, pVBInfo);
5444 XGI_GetCRT2ResInfo(ModeNo, ModeIdIndex, pVBInfo);
5445 XGI_GetCRT2Data(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5446 XGI_PreSetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
5447 RefreshRateTableIndex, pVBInfo);
5448 XGI_SetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
5449 RefreshRateTableIndex, pVBInfo);
5450 XGI_SetLockRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
5451 RefreshRateTableIndex, pVBInfo);
5452 XGI_SetGroup2(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5453 HwDeviceExtension, pVBInfo);
5454 XGI_SetLCDRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
5455 RefreshRateTableIndex, pVBInfo);
5456 XGI_SetTap4Regs(pVBInfo);
5457 XGI_SetGroup3(ModeNo, ModeIdIndex, pVBInfo);
5458 XGI_SetGroup4(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5459 HwDeviceExtension, pVBInfo);
5460 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5461 XGI_SetGroup5(ModeNo, ModeIdIndex, pVBInfo);
5462 XGI_AutoThreshold(pVBInfo);
5463 return 1;
5464}
5465
5466void XGI_SenseCRT1(struct vb_device_info *pVBInfo)
5467{
5468 unsigned char CRTCData[17] = { 0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81,
5469 0x0B, 0x3E, 0xE9, 0x0B, 0xDF, 0xE7, 0x04, 0x00, 0x00,
5470 0x05, 0x00 };
5471
5472 unsigned char SR01 = 0, SR1F = 0, SR07 = 0, SR06 = 0;
5473
5474 unsigned char CR17, CR63, SR31;
5475 unsigned short temp;
5476 unsigned char DAC_TEST_PARMS[3] = { 0x0F, 0x0F, 0x0F };
5477
5478 int i;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005479 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005480
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005481 /* to fix XG42 single LCD sense to CRT+LCD */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005482 xgifb_reg_set(pVBInfo->P3d4, 0x57, 0x4A);
Peter Huewe9388ad92013-02-15 20:37:10 +01005483 xgifb_reg_set(pVBInfo->P3d4, 0x53, (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005484 pVBInfo->P3d4, 0x53) | 0x02));
5485
Peter Huewe9388ad92013-02-15 20:37:10 +01005486 SR31 = xgifb_reg_get(pVBInfo->P3c4, 0x31);
5487 CR63 = xgifb_reg_get(pVBInfo->P3d4, 0x63);
5488 SR01 = xgifb_reg_get(pVBInfo->P3c4, 0x01);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005489
Aaro Koskinen8104e322011-03-13 12:26:22 +02005490 xgifb_reg_set(pVBInfo->P3c4, 0x01, (unsigned char) (SR01 & 0xDF));
5491 xgifb_reg_set(pVBInfo->P3d4, 0x63, (unsigned char) (CR63 & 0xBF));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005492
Peter Huewe9388ad92013-02-15 20:37:10 +01005493 CR17 = xgifb_reg_get(pVBInfo->P3d4, 0x17);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005494 xgifb_reg_set(pVBInfo->P3d4, 0x17, (unsigned char) (CR17 | 0x80));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005495
Peter Huewe9388ad92013-02-15 20:37:10 +01005496 SR1F = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005497 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) (SR1F | 0x04));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005498
Peter Huewe9388ad92013-02-15 20:37:10 +01005499 SR07 = xgifb_reg_get(pVBInfo->P3c4, 0x07);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005500 xgifb_reg_set(pVBInfo->P3c4, 0x07, (unsigned char) (SR07 & 0xFB));
Peter Huewe9388ad92013-02-15 20:37:10 +01005501 SR06 = xgifb_reg_get(pVBInfo->P3c4, 0x06);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005502 xgifb_reg_set(pVBInfo->P3c4, 0x06, (unsigned char) (SR06 & 0xC3));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005503
Aaro Koskinen8104e322011-03-13 12:26:22 +02005504 xgifb_reg_set(pVBInfo->P3d4, 0x11, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005505
5506 for (i = 0; i < 8; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005507 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) i, CRTCData[i]);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005508
5509 for (i = 8; i < 11; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005510 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 8),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005511 CRTCData[i]);
5512
5513 for (i = 11; i < 13; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005514 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 4),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005515 CRTCData[i]);
5516
5517 for (i = 13; i < 16; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005518 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i - 3),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005519 CRTCData[i]);
5520
Aaro Koskinen8104e322011-03-13 12:26:22 +02005521 xgifb_reg_set(pVBInfo->P3c4, 0x0E, (unsigned char) (CRTCData[16]
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005522 & 0xE0));
5523
Aaro Koskinen8104e322011-03-13 12:26:22 +02005524 xgifb_reg_set(pVBInfo->P3c4, 0x31, 0x00);
5525 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x1B);
5526 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE1);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005527
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005528 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005529
5530 for (i = 0; i < 256; i++) {
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005531 outb((unsigned char) DAC_TEST_PARMS[0], (pVBInfo->P3c8 + 1));
5532 outb((unsigned char) DAC_TEST_PARMS[1], (pVBInfo->P3c8 + 1));
5533 outb((unsigned char) DAC_TEST_PARMS[2], (pVBInfo->P3c8 + 1));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005534 }
5535
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005536 mdelay(1);
5537
5538 XGI_WaitDisply(pVBInfo);
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02005539 temp = inb(pVBInfo->P3c2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005540
5541 if (temp & 0x10)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005542 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005543 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005544 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005545
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005546 /* avoid display something, set BLACK DAC if not restore DAC */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005547 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005548
5549 for (i = 0; i < 256; i++) {
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005550 outb(0, (pVBInfo->P3c8 + 1));
5551 outb(0, (pVBInfo->P3c8 + 1));
5552 outb(0, (pVBInfo->P3c8 + 1));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005553 }
5554
Aaro Koskinen8104e322011-03-13 12:26:22 +02005555 xgifb_reg_set(pVBInfo->P3c4, 0x01, SR01);
5556 xgifb_reg_set(pVBInfo->P3d4, 0x63, CR63);
5557 xgifb_reg_set(pVBInfo->P3c4, 0x31, SR31);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005558
Peter Huewe9388ad92013-02-15 20:37:10 +01005559 xgifb_reg_set(pVBInfo->P3d4, 0x53, (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005560 pVBInfo->P3d4, 0x53) & 0xFD));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005561 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) SR1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005562}
5563
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005564static void XGI_EnableBridge(struct xgifb_video_info *xgifb_info,
5565 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005566 struct vb_device_info *pVBInfo)
5567{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02005568 unsigned short tempah;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005569
Peter Huewe6896b942012-02-09 21:11:46 +01005570 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5571 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005572 if (!(pVBInfo->SetFlag & DisableChA)) {
Peter Huewe66b43eb2013-02-15 20:37:09 +01005573 if ((pVBInfo->SetFlag & EnableChA) ||
5574 (pVBInfo->VBInfo & SetCRT2ToDualEdge)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005575 /* Power on */
5576 xgifb_reg_set(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005577 }
5578 }
5579
5580 if (!(pVBInfo->SetFlag & DisableChB)) {
5581 if ((pVBInfo->SetFlag & EnableChB) || (pVBInfo->VBInfo
5582 & (SetCRT2ToLCD | SetCRT2ToTV
5583 | SetCRT2ToRAMDAC))) {
Peter Huewe9388ad92013-02-15 20:37:10 +01005584 tempah = xgifb_reg_get(pVBInfo->P3c4, 0x32);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005585 tempah &= 0xDF;
5586 if (pVBInfo->VBInfo & SetInSlaveMode) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005587 if (!(pVBInfo->VBInfo &
5588 SetCRT2ToRAMDAC))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005589 tempah |= 0x20;
5590 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02005591 xgifb_reg_set(pVBInfo->P3c4, 0x32, tempah);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005592 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005593
Peter Huewe9388ad92013-02-15 20:37:10 +01005594 tempah = xgifb_reg_get(pVBInfo->Part1Port,
5595 0x2E);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005596
5597 if (!(tempah & 0x80))
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005598 xgifb_reg_or(pVBInfo->Part1Port,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005599 0x2E, 0x80);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005600 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005601 }
5602 }
5603
5604 if ((pVBInfo->SetFlag & (EnableChA | EnableChB))
5605 || (!(pVBInfo->VBInfo & DisableCRT2Display))) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005606 xgifb_reg_and_or(pVBInfo->Part2Port, 0x00, ~0xE0,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005607 0x20); /* shampoo 0129 */
Peter Huewe6896b942012-02-09 21:11:46 +01005608 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Peter Huewe06cc47b2013-02-03 22:54:38 +01005609 if (!XGI_EnableChISLCD(pVBInfo, false)) {
5610 if (XGI_EnableChISLCD(pVBInfo, true) ||
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005611 (pVBInfo->VBInfo &
Peter Huewea3d675c2012-02-09 21:11:47 +01005612 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005613 /* LVDS PLL power on */
Aaro Koskinendc505562011-03-13 12:26:26 +02005614 xgifb_reg_and(
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005615 pVBInfo->Part4Port,
5616 0x2A,
5617 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005618 }
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005619 /* LVDS Driver power on */
5620 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005621 }
5622 }
5623
5624 tempah = 0x00;
5625
5626 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5627 tempah = 0xc0;
5628
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005629 if (!(pVBInfo->VBInfo & SetSimuScanMode) &&
5630 (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) &&
5631 (pVBInfo->VBInfo & SetCRT2ToDualEdge)) {
5632 tempah = tempah & 0x40;
5633 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
5634 tempah = tempah ^ 0xC0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005635
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005636 if (pVBInfo->SetFlag & DisableChB)
5637 tempah &= 0xBF;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005638
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005639 if (pVBInfo->SetFlag & DisableChA)
5640 tempah &= 0x7F;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005641
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005642 if (pVBInfo->SetFlag & EnableChB)
5643 tempah |= 0x40;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005644
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005645 if (pVBInfo->SetFlag & EnableChA)
5646 tempah |= 0x80;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005647 }
5648 }
5649
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005650 /* EnablePart4_1F */
5651 xgifb_reg_or(pVBInfo->Part4Port, 0x1F, tempah);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005652
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005653 if (!(pVBInfo->SetFlag & DisableChA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005654 if (!(pVBInfo->SetFlag & GatingCRT)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005655 XGI_DisableGatingCRT(HwDeviceExtension,
5656 pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005657 XGI_DisplayOn(xgifb_info, HwDeviceExtension,
5658 pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005659 }
5660 }
5661 } /* 301 */
5662 else { /* LVDS */
5663 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD
Peter Huewea3d675c2012-02-09 21:11:47 +01005664 | XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005665 /* enable CRT2 */
5666 xgifb_reg_or(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005667
Peter Huewe9388ad92013-02-15 20:37:10 +01005668 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2E);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005669 if (!(tempah & 0x80))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005670 xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005671
Aaro Koskinendc505562011-03-13 12:26:26 +02005672 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005673 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005674 } /* End of VB */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005675}
5676
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005677static void XGI_SetCRT1Group(struct xgifb_video_info *xgifb_info,
5678 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005679 unsigned short ModeNo, unsigned short ModeIdIndex,
5680 struct vb_device_info *pVBInfo)
5681{
Aaro Koskinena1579612012-04-07 01:14:05 +03005682 unsigned short RefreshRateTableIndex, temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005683
Aaro Koskinena1579612012-04-07 01:14:05 +03005684 XGI_SetSeqRegs(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinen3625c9a2012-11-04 21:14:51 +02005685 outb(XGI330_StandTable.MISC, pVBInfo->P3c2);
Aaro Koskinena1579612012-04-07 01:14:05 +03005686 XGI_SetCRTCRegs(HwDeviceExtension, pVBInfo);
5687 XGI_SetATTRegs(ModeNo, ModeIdIndex, pVBInfo);
5688 XGI_SetGRCRegs(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005689 XGI_ClearExt1Regs(pVBInfo);
5690
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005691 if (HwDeviceExtension->jChipType == XG27) {
5692 if (pVBInfo->IF_DEF_LVDS == 0)
5693 XGI_SetDefaultVCLK(pVBInfo);
5694 }
5695
5696 temp = ~ProgrammingCRT2;
5697 pVBInfo->SetFlag &= temp;
5698 pVBInfo->SelectCRT2Rate = 0;
5699
Peter Huewe6896b942012-02-09 21:11:46 +01005700 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5701 | VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005702 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005703 | SetInSlaveMode)) {
5704 pVBInfo->SetFlag |= ProgrammingCRT2;
5705 }
5706 }
5707
5708 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5709 ModeIdIndex, pVBInfo);
5710 if (RefreshRateTableIndex != 0xFFFF) {
5711 XGI_SetSync(RefreshRateTableIndex, pVBInfo);
5712 XGI_SetCRT1CRTC(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5713 pVBInfo, HwDeviceExtension);
5714 XGI_SetCRT1DE(HwDeviceExtension, ModeNo, ModeIdIndex,
5715 RefreshRateTableIndex, pVBInfo);
5716 XGI_SetCRT1Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5717 HwDeviceExtension, pVBInfo);
5718 XGI_SetCRT1VCLK(ModeNo, ModeIdIndex, HwDeviceExtension,
5719 RefreshRateTableIndex, pVBInfo);
5720 }
5721
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005722 if (HwDeviceExtension->jChipType >= XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005723 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005724 if (temp & 0xA0) {
5725
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005726 if (HwDeviceExtension->jChipType == XG27)
5727 XGI_SetXG27CRTC(ModeNo, ModeIdIndex,
5728 RefreshRateTableIndex, pVBInfo);
5729 else
5730 XGI_SetXG21CRTC(ModeNo, ModeIdIndex,
5731 RefreshRateTableIndex, pVBInfo);
5732
5733 XGI_UpdateXG21CRTC(ModeNo, pVBInfo,
5734 RefreshRateTableIndex);
5735
Aaro Koskinen105d8d02011-08-31 21:46:00 +03005736 xgifb_set_lcd(HwDeviceExtension->jChipType,
5737 pVBInfo, RefreshRateTableIndex, ModeNo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005738
Aaro Koskinen64db29f2011-08-31 21:46:01 +03005739 if (pVBInfo->IF_DEF_LVDS == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005740 xgifb_set_lvds(xgifb_info,
5741 HwDeviceExtension->jChipType,
Aaro Koskinen64db29f2011-08-31 21:46:01 +03005742 ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005743 }
5744 }
5745
5746 pVBInfo->SetFlag &= (~ProgrammingCRT2);
5747 XGI_SetCRT1FIFO(ModeNo, HwDeviceExtension, pVBInfo);
5748 XGI_SetCRT1ModeRegs(HwDeviceExtension, ModeNo, ModeIdIndex,
5749 RefreshRateTableIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005750 XGI_LoadDAC(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005751}
5752
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005753unsigned char XGISetModeNew(struct xgifb_video_info *xgifb_info,
5754 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005755 unsigned short ModeNo)
5756{
5757 unsigned short ModeIdIndex;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005758 struct vb_device_info VBINF;
5759 struct vb_device_info *pVBInfo = &VBINF;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005760 pVBInfo->IF_DEF_LVDS = 0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005761
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005762 if (HwDeviceExtension->jChipType >= XG20) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005763 pVBInfo->IF_DEF_YPbPr = 0;
5764 pVBInfo->IF_DEF_HiVision = 0;
5765 pVBInfo->IF_DEF_CRT2Monitor = 0;
5766 pVBInfo->VBType = 0; /*set VBType default 0*/
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005767 } else {
5768 pVBInfo->IF_DEF_YPbPr = 1;
5769 pVBInfo->IF_DEF_HiVision = 1;
Aaro Koskinen06587332011-03-13 12:26:10 +02005770 pVBInfo->IF_DEF_CRT2Monitor = 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005771 }
5772
Aaro Koskinen56810a92013-01-21 02:57:47 +02005773 XGIRegInit(pVBInfo, xgifb_info->vga_base);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005774
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005775 /* for x86 Linux, XG21 LVDS */
5776 if (HwDeviceExtension->jChipType == XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005777 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005778 pVBInfo->IF_DEF_LVDS = 1;
5779 }
5780 if (HwDeviceExtension->jChipType == XG27) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005781 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0) {
5782 if (xgifb_reg_get(pVBInfo->P3d4, 0x30) & 0x20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005783 pVBInfo->IF_DEF_LVDS = 1;
5784 }
5785 }
5786
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005787 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005788 XGI_GetVBType(pVBInfo);
5789
5790 InitTo330Pointer(HwDeviceExtension->jChipType, pVBInfo);
Aaro Koskinenef497f42011-11-27 23:03:21 +02005791 if (ModeNo & 0x80)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005792 ModeNo = ModeNo & 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005793 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005794
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005795 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005796 XGI_UnLockCRT2(HwDeviceExtension, pVBInfo);
5797
5798 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
5799
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005800 if (HwDeviceExtension->jChipType < XG20) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005801 XGI_GetVBInfo(ModeNo, ModeIdIndex, HwDeviceExtension, pVBInfo);
5802 XGI_GetTVInfo(ModeNo, ModeIdIndex, pVBInfo);
5803 XGI_GetLCDInfo(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005804 XGI_DisableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005805
Peter Huewee44adfd2013-02-03 22:54:39 +01005806 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA) ||
5807 (!(pVBInfo->VBInfo & SwitchCRT2))) {
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005808 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005809 ModeIdIndex, pVBInfo);
5810
Peter Huewea3d675c2012-02-09 21:11:47 +01005811 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005812 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
5813 HwDeviceExtension, pVBInfo);
5814 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005815 }
5816
Peter Huewe6896b942012-02-09 21:11:46 +01005817 if (pVBInfo->VBInfo & (SetSimuScanMode | SwitchCRT2)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005818 switch (HwDeviceExtension->ujVBChipID) {
Peter Huewee44adfd2013-02-03 22:54:39 +01005819 case VB_CHIP_301: /* fall through */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005820 case VB_CHIP_302:
5821 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
5822 pVBInfo); /*add for CRT2 */
5823 break;
5824
5825 default:
5826 break;
5827 }
5828 }
5829
5830 XGI_SetCRT2ModeRegs(ModeNo, HwDeviceExtension, pVBInfo);
5831 XGI_OEM310Setting(ModeNo, ModeIdIndex, pVBInfo); /*0212*/
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005832 XGI_EnableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005833 } /* !XG20 */
5834 else {
5835 if (pVBInfo->IF_DEF_LVDS == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005836 if (!XGI_XG21CheckLVDSMode(xgifb_info, ModeNo,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005837 ModeIdIndex,
5838 pVBInfo))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005839 return 0;
5840
Aaro Koskinenb3979922012-11-04 21:14:52 +02005841 pVBInfo->ModeType = XGI330_EModeIDTable[ModeIdIndex].
Peter Huewe6896b942012-02-09 21:11:46 +01005842 Ext_ModeFlag & ModeTypeMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005843
5844 pVBInfo->SetFlag = 0;
Aaro Koskinen83f76a92011-08-31 21:45:58 +03005845 pVBInfo->VBInfo = DisableCRT2Display;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005846
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005847 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005848
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005849 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
5850 ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005851
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005852 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005853 }
5854
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005855 XGI_UpdateModeInfo(HwDeviceExtension, pVBInfo);
5856
Miguel Gómez3bcc2462012-07-06 12:40:53 +02005857 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005858 XGI_LockCRT2(HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005859
5860 return 1;
5861}