blob: bee4b388c2980ce0bd362fbd40809f8e81e5ba87 [file] [log] [blame]
Aaro Koskinend80aaa02011-02-17 23:29:14 +02001#include <linux/delay.h>
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002#include "XGIfb.h"
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004#include "vb_def.h"
Aaro Koskinen56810a92013-01-21 02:57:47 +02005#include "vb_init.h"
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006#include "vb_util.h"
7#include "vb_table.h"
Miguel Gómeze0541022012-06-18 13:12:05 +02008#include "vb_setmode.h"
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02009
10#define IndexMask 0xff
Peter Huewe95072592012-06-14 00:21:48 +020011#define TVCLKBASE_315_25 (TVCLKBASE_315 + 25)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020012
Aaro Koskinen624554d2011-10-11 21:47:35 +030013static const unsigned short XGINew_VGA_DAC[] = {
Bill Pemberton82d6eb52010-06-17 13:10:46 -040014 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
15 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F,
16 0x00, 0x05, 0x08, 0x0B, 0x0E, 0x11, 0x14, 0x18,
17 0x1C, 0x20, 0x24, 0x28, 0x2D, 0x32, 0x38, 0x3F,
18 0x00, 0x10, 0x1F, 0x2F, 0x3F, 0x1F, 0x27, 0x2F,
19 0x37, 0x3F, 0x2D, 0x31, 0x36, 0x3A, 0x3F, 0x00,
20 0x07, 0x0E, 0x15, 0x1C, 0x0E, 0x11, 0x15, 0x18,
21 0x1C, 0x14, 0x16, 0x18, 0x1A, 0x1C, 0x00, 0x04,
22 0x08, 0x0C, 0x10, 0x08, 0x0A, 0x0C, 0x0E, 0x10,
23 0x0B, 0x0C, 0x0D, 0x0F, 0x10};
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020024
Bill Pemberton80adad82010-06-17 13:10:51 -040025void InitTo330Pointer(unsigned char ChipType, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020026{
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +030027 pVBInfo->MCLKData = XGI340New_MCLKData;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020028
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053029 pVBInfo->LCDResInfo = 0;
30 pVBInfo->LCDTypeInfo = 0;
31 pVBInfo->LCDInfo = 0;
32 pVBInfo->VBInfo = 0;
33 pVBInfo->TVInfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020034
Aaro Koskinen597d96b2013-03-27 23:53:15 +020035 pVBInfo->SR18 = XGI340_SR18;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053036 pVBInfo->CR40 = XGI340_cr41;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020037
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053038 /* 310 customization related */
Peter Huewe6896b942012-02-09 21:11:46 +010039 if ((pVBInfo->VBType & VB_SIS301LV) || (pVBInfo->VBType & VB_SIS302LV))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053040 pVBInfo->LCDCapList = XGI_LCDDLCapList;
41 else
42 pVBInfo->LCDCapList = XGI_LCDCapList;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020043
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053044 if (ChipType >= XG20)
Peter Huewe6d12dae2012-06-14 00:21:52 +020045 pVBInfo->XGINew_CR97 = 0x10;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020046
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053047 if (ChipType == XG27) {
Dmitry Eremin-Solenikov64903112012-03-19 21:50:09 +040048 unsigned char temp;
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +030049 pVBInfo->MCLKData = XGI27New_MCLKData;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053050 pVBInfo->CR40 = XGI27_cr41;
Peter Huewe6d12dae2012-06-14 00:21:52 +020051 pVBInfo->XGINew_CR97 = 0xc1;
Aaro Koskinen597d96b2013-03-27 23:53:15 +020052 pVBInfo->SR18 = XG27_SR18;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020053
Dmitry Eremin-Solenikov64903112012-03-19 21:50:09 +040054 /*Z11m DDR*/
55 temp = xgifb_reg_get(pVBInfo->P3c4, 0x3B);
56 /* SR3B[7][3]MAA15 MAA11 (Power on Trapping) */
57 if (((temp & 0x88) == 0x80) || ((temp & 0x88) == 0x08))
Peter Huewe6d12dae2012-06-14 00:21:52 +020058 pVBInfo->XGINew_CR97 = 0x80;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053059 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020060
61}
62
Kenji Toyama1d7f6562011-04-23 19:36:49 +080063static void XGI_SetSeqRegs(unsigned short ModeNo,
Kenji Toyama1d7f6562011-04-23 19:36:49 +080064 unsigned short ModeIdIndex,
65 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020066{
Peter Huewe76a58992013-02-03 22:54:34 +010067 unsigned char SRdata, i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020068
Aaro Koskinen8104e322011-03-13 12:26:22 +020069 xgifb_reg_set(pVBInfo->P3c4, 0x00, 0x03); /* Set SR0 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020070
Peter Huewe76a58992013-02-03 22:54:34 +010071 for (i = 0; i < 4; i++) {
72 /* Get SR1,2,3,4 from file */
73 /* SR1 is with screen off 0x20 */
74 SRdata = XGI330_StandTable.SR[i];
75 xgifb_reg_set(pVBInfo->P3c4, i+1, SRdata); /* Set SR 1 2 3 4 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053076 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020077}
78
Aaro Koskinen063b9c42011-03-08 22:16:13 +020079static void XGI_SetCRTCRegs(struct xgi_hw_device_info *HwDeviceExtension,
Kenji Toyama1d7f6562011-04-23 19:36:49 +080080 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020081{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053082 unsigned char CRTCdata;
83 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020084
Peter Huewe9388ad92013-02-15 20:37:10 +010085 CRTCdata = xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053086 CRTCdata &= 0x7f;
Aaro Koskinen8104e322011-03-13 12:26:22 +020087 xgifb_reg_set(pVBInfo->P3d4, 0x11, CRTCdata); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020088
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053089 for (i = 0; i <= 0x18; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +080090 /* Get CRTC from file */
Aaro Koskinen3625c9a2012-11-04 21:14:51 +020091 CRTCdata = XGI330_StandTable.CRTC[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +020092 xgifb_reg_set(pVBInfo->P3d4, i, CRTCdata); /* Set CRTC(3d4) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053093 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020094}
95
Kenji Toyama1d7f6562011-04-23 19:36:49 +080096static void XGI_SetATTRegs(unsigned short ModeNo,
Kenji Toyama1d7f6562011-04-23 19:36:49 +080097 unsigned short ModeIdIndex,
98 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020099{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530100 unsigned char ARdata;
101 unsigned short i, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200102
Aaro Koskinenb3979922012-11-04 21:14:52 +0200103 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200104
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530105 for (i = 0; i <= 0x13; i++) {
Aaro Koskinen3625c9a2012-11-04 21:14:51 +0200106 ARdata = XGI330_StandTable.ATTR[i];
Miguel Gómez661a6382012-07-06 12:40:45 +0200107
108 if ((modeflag & Charx8Dot) && i == 0x13) { /* ifndef Dot9 */
109 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
110 ARdata = 0;
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300111 } else if ((pVBInfo->VBInfo &
Miguel Gómez661a6382012-07-06 12:40:45 +0200112 (SetCRT2ToTV | SetCRT2ToLCD)) &&
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300113 (pVBInfo->VBInfo & SetInSlaveMode)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530114 ARdata = 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530115 }
116 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200117
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200118 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200119 outb(i, pVBInfo->P3c0); /* set index */
120 outb(ARdata, pVBInfo->P3c0); /* set data */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530121 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200122
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200123 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200124 outb(0x14, pVBInfo->P3c0); /* set index */
125 outb(0x00, pVBInfo->P3c0); /* set data */
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200126 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200127 outb(0x20, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200128}
129
Aaro Koskinena1579612012-04-07 01:14:05 +0300130static void XGI_SetGRCRegs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200131{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530132 unsigned char GRdata;
133 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200134
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530135 for (i = 0; i <= 0x08; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800136 /* Get GR from file */
Aaro Koskinen3625c9a2012-11-04 21:14:51 +0200137 GRdata = XGI330_StandTable.GRC[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200138 xgifb_reg_set(pVBInfo->P3ce, i, GRdata); /* Set GR(3ce) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530139 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200140
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530141 if (pVBInfo->ModeType > ModeVGA) {
Peter Huewe9388ad92013-02-15 20:37:10 +0100142 GRdata = xgifb_reg_get(pVBInfo->P3ce, 0x05);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530143 GRdata &= 0xBF; /* 256 color disable */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200144 xgifb_reg_set(pVBInfo->P3ce, 0x05, GRdata);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530145 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200146}
147
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200148static void XGI_ClearExt1Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200149{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530150 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200151
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530152 for (i = 0x0A; i <= 0x0E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +0200153 xgifb_reg_set(pVBInfo->P3c4, i, 0x00); /* Clear SR0A-SR0E */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200154}
155
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200156static unsigned char XGI_SetDefaultVCLK(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200157{
158
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200159 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x20);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200160 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[0].SR2B);
161 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[0].SR2C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200162
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200163 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x10);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200164 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[1].SR2B);
165 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[1].SR2C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200166
Aaro Koskinendc505562011-03-13 12:26:26 +0200167 xgifb_reg_and(pVBInfo->P3c4, 0x31, ~0x30);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530168 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200169}
170
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200171static unsigned char XGI_AjustCRT2Rate(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530172 unsigned short ModeIdIndex,
173 unsigned short RefreshRateTableIndex, unsigned short *i,
174 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200175{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530176 unsigned short tempax, tempbx, resinfo, modeflag, infoflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200177
Aaro Koskinenb3979922012-11-04 21:14:52 +0200178 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
179 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinena39325d2012-11-04 21:14:53 +0200180 tempbx = XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530181 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200182
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530183 if (pVBInfo->IF_DEF_LVDS == 0) {
184 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
185 tempax |= SupportRAMDAC2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200186
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530187 if (pVBInfo->VBType & VB_XGI301C)
188 tempax |= SupportCRT2in301C;
189 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200190
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800191 /* 301b */
Peter Huewea3d675c2012-02-09 21:11:47 +0100192 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530193 tempax |= SupportLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200194
Miguel Gómez3b175622012-07-06 12:40:46 +0200195 if (pVBInfo->LCDResInfo != Panel_1280x1024 &&
196 pVBInfo->LCDResInfo != Panel_1280x960 &&
197 (pVBInfo->LCDInfo & LCDNonExpanding) &&
198 resinfo >= 9)
199 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530200 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200201
Peter Huewe599801f2012-02-09 21:11:45 +0100202 if (pVBInfo->VBInfo & SetCRT2ToHiVision) { /* for HiTV */
Aaro Koskinen31fb40f2012-09-11 00:15:15 +0300203 tempax |= SupportHiVision;
204 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
205 ((resinfo == 4) ||
206 (resinfo == 3 &&
207 (pVBInfo->SetFlag & TVSimuMode)) ||
208 (resinfo > 7)))
Miguel Gómez3b175622012-07-06 12:40:46 +0200209 return 0;
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300210 } else if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO |
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800211 SetCRT2ToSVIDEO |
212 SetCRT2ToSCART |
Peter Huewe599801f2012-02-09 21:11:45 +0100213 SetCRT2ToYPbPr525750 |
214 SetCRT2ToHiVision)) {
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300215 tempax |= SupportTV;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200216
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300217 if (pVBInfo->VBType & (VB_SIS301B |
218 VB_SIS302B |
219 VB_SIS301LV |
220 VB_SIS302LV |
221 VB_XGI301C))
222 tempax |= SupportTV1024;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200223
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300224 if (!(pVBInfo->VBInfo & TVSetPAL) &&
225 (modeflag & NoSupportSimuTV) &&
226 (pVBInfo->VBInfo & SetInSlaveMode) &&
227 (!(pVBInfo->VBInfo & SetNotSimuMode)))
228 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530229 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300230 } else if (pVBInfo->VBInfo & SetCRT2ToLCD) { /* for LVDS */
231 tempax |= SupportLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200232
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300233 if (resinfo > 0x08)
234 return 0; /* 1024x768 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200235
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300236 if (pVBInfo->LCDResInfo < Panel_1024x768) {
237 if (resinfo > 0x07)
238 return 0; /* 800x600 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200239
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300240 if (resinfo == 0x04)
241 return 0; /* 512x384 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530242 }
243 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200244
Aaro Koskinena39325d2012-11-04 21:14:53 +0200245 for (; XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID ==
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800246 tempbx; (*i)--) {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200247 infoflag = XGI330_RefIndex[RefreshRateTableIndex + (*i)].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800248 Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530249 if (infoflag & tempax)
250 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200251
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530252 if ((*i) == 0)
253 break;
254 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200255
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530256 for ((*i) = 0;; (*i)++) {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200257 infoflag = XGI330_RefIndex[RefreshRateTableIndex + (*i)].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800258 Ext_InfoFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +0200259 if (XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530260 != tempbx) {
261 return 0;
262 }
263
264 if (infoflag & tempax)
265 return 1;
266 }
267 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200268}
269
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200270static void XGI_SetSync(unsigned short RefreshRateTableIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530271 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200272{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530273 unsigned short sync, temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200274
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800275 /* di+0x00 */
Aaro Koskinena39325d2012-11-04 21:14:53 +0200276 sync = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag >> 8;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530277 sync &= 0xC0;
278 temp = 0x2F;
279 temp |= sync;
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200280 outb(temp, pVBInfo->P3c2); /* Set Misc(3c2) */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200281}
282
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200283static void XGI_SetCRT1Timing_H(struct vb_device_info *pVBInfo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530284 struct xgi_hw_device_info *HwDeviceExtension)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200285{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530286 unsigned char data, data1, pushax;
287 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200288
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800289 /* unlock cr0-7 */
Peter Huewe9388ad92013-02-15 20:37:10 +0100290 data = xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530291 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200292 xgifb_reg_set(pVBInfo->P3d4, 0x11, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200293
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200294 data = pVBInfo->TimingH.data[0];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200295 xgifb_reg_set(pVBInfo->P3d4, 0, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200296
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530297 for (i = 0x01; i <= 0x04; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200298 data = pVBInfo->TimingH.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200299 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 1), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530300 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200301
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530302 for (i = 0x05; i <= 0x06; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200303 data = pVBInfo->TimingH.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200304 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i + 6), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530305 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200306
Peter Huewe9388ad92013-02-15 20:37:10 +0100307 j = xgifb_reg_get(pVBInfo->P3c4, 0x0e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530308 j &= 0x1F;
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200309 data = pVBInfo->TimingH.data[7];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530310 data &= 0xE0;
311 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200312 xgifb_reg_set(pVBInfo->P3c4, 0x0e, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200313
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530314 if (HwDeviceExtension->jChipType >= XG20) {
Peter Huewe9388ad92013-02-15 20:37:10 +0100315 data = xgifb_reg_get(pVBInfo->P3d4, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530316 data = data - 1;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200317 xgifb_reg_set(pVBInfo->P3d4, 0x04, data);
Peter Huewe9388ad92013-02-15 20:37:10 +0100318 data = xgifb_reg_get(pVBInfo->P3d4, 0x05);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530319 data1 = data;
320 data1 &= 0xE0;
321 data &= 0x1F;
322 if (data == 0) {
323 pushax = data;
Peter Huewe9388ad92013-02-15 20:37:10 +0100324 data = xgifb_reg_get(pVBInfo->P3c4, 0x0c);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530325 data &= 0xFB;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200326 xgifb_reg_set(pVBInfo->P3c4, 0x0c, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530327 data = pushax;
328 }
329 data = data - 1;
330 data |= data1;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200331 xgifb_reg_set(pVBInfo->P3d4, 0x05, data);
Peter Huewe9388ad92013-02-15 20:37:10 +0100332 data = xgifb_reg_get(pVBInfo->P3c4, 0x0e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530333 data = data >> 5;
334 data = data + 3;
335 if (data > 7)
336 data = data - 7;
337 data = data << 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200338 xgifb_reg_and_or(pVBInfo->P3c4, 0x0e, ~0xE0, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530339 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200340}
341
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800342static void XGI_SetCRT1Timing_V(unsigned short ModeIdIndex,
343 unsigned short ModeNo,
344 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200345{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530346 unsigned char data;
347 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200348
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530349 for (i = 0x00; i <= 0x01; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200350 data = pVBInfo->TimingV.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200351 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 6), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530352 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200353
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530354 for (i = 0x02; i <= 0x03; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200355 data = pVBInfo->TimingV.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200356 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x0e), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530357 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200358
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530359 for (i = 0x04; i <= 0x05; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200360 data = pVBInfo->TimingV.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200361 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x11), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530362 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200363
Peter Huewe9388ad92013-02-15 20:37:10 +0100364 j = xgifb_reg_get(pVBInfo->P3c4, 0x0a);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530365 j &= 0xC0;
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200366 data = pVBInfo->TimingV.data[6];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530367 data &= 0x3F;
368 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200369 xgifb_reg_set(pVBInfo->P3c4, 0x0a, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200370
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200371 data = pVBInfo->TimingV.data[6];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530372 data &= 0x80;
373 data = data >> 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200374
Aaro Koskinenb3979922012-11-04 21:14:52 +0200375 i = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530376 i &= DoubleScanMode;
377 if (i)
378 data |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200379
Peter Huewe9388ad92013-02-15 20:37:10 +0100380 j = xgifb_reg_get(pVBInfo->P3d4, 0x09);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530381 j &= 0x5F;
382 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200383 xgifb_reg_set(pVBInfo->P3d4, 0x09, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200384}
385
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200386static void XGI_SetCRT1CRTC(unsigned short ModeNo, unsigned short ModeIdIndex,
387 unsigned short RefreshRateTableIndex,
388 struct vb_device_info *pVBInfo,
389 struct xgi_hw_device_info *HwDeviceExtension)
390{
391 unsigned char index, data;
392 unsigned short i;
393
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800394 /* Get index */
Aaro Koskinena39325d2012-11-04 21:14:53 +0200395 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200396 index = index & IndexMask;
397
Peter Huewe9388ad92013-02-15 20:37:10 +0100398 data = xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200399 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200400 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200401
402 for (i = 0; i < 8; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200403 pVBInfo->TimingH.data[i]
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200404 = XGI_CRT1Table[index].CR[i];
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200405
406 for (i = 0; i < 7; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200407 pVBInfo->TimingV.data[i]
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200408 = XGI_CRT1Table[index].CR[i + 8];
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200409
410 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
411
412 XGI_SetCRT1Timing_V(ModeIdIndex, ModeNo, pVBInfo);
413
414 if (pVBInfo->ModeType > 0x03)
Aaro Koskinen8104e322011-03-13 12:26:22 +0200415 xgifb_reg_set(pVBInfo->P3d4, 0x14, 0x4F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200416}
417
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200418/* --------------------------------------------------------------------- */
419/* Function : XGI_SetXG21CRTC */
420/* Input : Stand or enhance CRTC table */
421/* Output : Fill CRT Hsync/Vsync to SR2E/SR2F/SR30/SR33/SR34/SR3F */
422/* Description : Set LCD timing */
423/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200424static void XGI_SetXG21CRTC(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530425 unsigned short RefreshRateTableIndex,
426 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200427{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300428 unsigned char index, Tempax, Tempbx, Tempcx, Tempdx;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530429 unsigned short Temp1, Temp2, Temp3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200430
Aaro Koskinena39325d2012-11-04 21:14:53 +0200431 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300432 /* Tempax: CR4 HRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200433 Tempax = XGI_CRT1Table[index].CR[3];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300434 Tempcx = Tempax; /* Tempcx: HRS */
435 /* SR2E[7:0]->HRS */
436 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200437
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200438 Tempdx = XGI_CRT1Table[index].CR[5]; /* SRB */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300439 Tempdx &= 0xC0; /* Tempdx[7:6]: SRB[7:6] */
440 Temp1 = Tempdx; /* Temp1[7:6]: HRS[9:8] */
441 Temp1 <<= 2; /* Temp1[9:8]: HRS[9:8] */
442 Temp1 |= Tempax; /* Temp1[9:0]: HRS[9:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800443
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200444 Tempax = XGI_CRT1Table[index].CR[4]; /* CR5 HRE */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300445 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200446
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200447 Tempbx = XGI_CRT1Table[index].CR[6]; /* SRC */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300448 Tempbx &= 0x04; /* Tempbx[2]: HRE[5] */
449 Tempbx <<= 3; /* Tempbx[5]: HRE[5] */
450 Tempax |= Tempbx; /* Tempax[5:0]: HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200451
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300452 Temp2 = Temp1 & 0x3C0; /* Temp2[9:6]: HRS[9:6] */
453 Temp2 |= Tempax; /* Temp2[9:0]: HRE[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200454
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300455 Tempcx &= 0x3F; /* Tempcx[5:0]: HRS[5:0] */
456 if (Tempax < Tempcx) /* HRE < HRS */
457 Temp2 |= 0x40; /* Temp2 + 0x40 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200458
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300459 Temp2 &= 0xFF;
460 Tempax = (unsigned char) Temp2; /* Tempax: HRE[7:0] */
461 Tempax <<= 2; /* Tempax[7:2]: HRE[5:0] */
462 Tempdx >>= 6; /* Tempdx[7:6]->[1:0] HRS[9:8] */
463 Tempax |= Tempdx; /* HRE[5:0]HRS[9:8] */
464 /* SR2F D[7:2]->HRE, D[1:0]->HRS */
465 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
466 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200467
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300468 /* CR10 VRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200469 Tempax = XGI_CRT1Table[index].CR[10];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300470 Tempbx = Tempax; /* Tempbx: VRS */
471 Tempax &= 0x01; /* Tempax[0]: VRS[0] */
472 xgifb_reg_or(pVBInfo->P3c4, 0x33, Tempax); /* SR33[0]->VRS[0] */
473 /* CR7[2][7] VRE */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200474 Tempax = XGI_CRT1Table[index].CR[9];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300475 Tempcx = Tempbx >> 1; /* Tempcx[6:0]: VRS[7:1] */
476 Tempdx = Tempax & 0x04; /* Tempdx[2]: CR7[2] */
477 Tempdx <<= 5; /* Tempdx[7]: VRS[8] */
478 Tempcx |= Tempdx; /* Tempcx[7:0]: VRS[8:1] */
479 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempcx); /* SR34[8:1]->VRS */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200480
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300481 Temp1 = Tempdx; /* Temp1[7]: Tempdx[7] */
482 Temp1 <<= 1; /* Temp1[8]: VRS[8] */
483 Temp1 |= Tempbx; /* Temp1[8:0]: VRS[8:0] */
484 Tempax &= 0x80;
485 Temp2 = Tempax << 2; /* Temp2[9]: VRS[9] */
486 Temp1 |= Temp2; /* Temp1[9:0]: VRS[9:0] */
487 /* Tempax: SRA */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200488 Tempax = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300489 Tempax &= 0x08; /* Tempax[3]: VRS[3] */
490 Temp2 = Tempax;
491 Temp2 <<= 7; /* Temp2[10]: VRS[10] */
492 Temp1 |= Temp2; /* Temp1[10:0]: VRS[10:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200493
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300494 /* Tempax: CR11 VRE */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200495 Tempax = XGI_CRT1Table[index].CR[11];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300496 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
497 /* Tempbx: SRA */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200498 Tempbx = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300499 Tempbx &= 0x20; /* Tempbx[5]: VRE[5] */
500 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
501 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
502 Temp2 = Temp1 & 0x7E0; /* Temp2[10:5]: VRS[10:5] */
503 Temp2 |= Tempax; /* Temp2[10:5]: VRE[10:5] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200504
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300505 Temp3 = Temp1 & 0x1F; /* Temp3[4:0]: VRS[4:0] */
506 if (Tempax < Temp3) /* VRE < VRS */
507 Temp2 |= 0x20; /* VRE + 0x20 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200508
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300509 Temp2 &= 0xFF;
510 Tempax = (unsigned char) Temp2; /* Tempax: VRE[7:0] */
511 Tempax <<= 2; /* Tempax[7:0]; VRE[5:0]00 */
512 Temp1 &= 0x600; /* Temp1[10:9]: VRS[10:9] */
513 Temp1 >>= 9; /* Temp1[1:0]: VRS[10:9] */
514 Tempbx = (unsigned char) Temp1;
515 Tempax |= Tempbx; /* Tempax[7:0]: VRE[5:0]VRS[10:9] */
516 Tempax &= 0x7F;
517 /* SR3F D[7:2]->VRE D[1:0]->VRS */
518 xgifb_reg_set(pVBInfo->P3c4, 0x3F, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200519}
520
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800521static void XGI_SetXG27CRTC(unsigned short ModeNo,
522 unsigned short ModeIdIndex,
523 unsigned short RefreshRateTableIndex,
524 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200525{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300526 unsigned short index, Tempax, Tempbx, Tempcx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200527
Aaro Koskinena39325d2012-11-04 21:14:53 +0200528 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300529 /* Tempax: CR4 HRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200530 Tempax = XGI_CRT1Table[index].CR[3];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300531 Tempbx = Tempax; /* Tempbx: HRS[7:0] */
532 /* SR2E[7:0]->HRS */
533 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200534
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300535 /* SR0B */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200536 Tempax = XGI_CRT1Table[index].CR[5];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300537 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
538 Tempbx |= (Tempax << 2); /* Tempbx: HRS[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200539
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200540 Tempax = XGI_CRT1Table[index].CR[4]; /* CR5 HRE */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300541 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
542 Tempcx = Tempax; /* Tempcx: HRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200543
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200544 Tempax = XGI_CRT1Table[index].CR[6]; /* SRC */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300545 Tempax &= 0x04; /* Tempax[2]: HRE[5] */
546 Tempax <<= 3; /* Tempax[5]: HRE[5] */
547 Tempcx |= Tempax; /* Tempcx[5:0]: HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200548
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300549 Tempbx = Tempbx & 0x3C0; /* Tempbx[9:6]: HRS[9:6] */
550 Tempbx |= Tempcx; /* Tempbx: HRS[9:6]HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200551
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300552 /* Tempax: CR4 HRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200553 Tempax = XGI_CRT1Table[index].CR[3];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300554 Tempax &= 0x3F; /* Tempax: HRS[5:0] */
555 if (Tempcx <= Tempax) /* HRE[5:0] < HRS[5:0] */
556 Tempbx += 0x40; /* Tempbx= Tempbx + 0x40 : HRE[9:0]*/
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200557
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200558 Tempax = XGI_CRT1Table[index].CR[5]; /* SR0B */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300559 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
560 Tempax >>= 6; /* Tempax[1:0]: HRS[9:8]*/
561 Tempax |= ((Tempbx << 2) & 0xFF); /* Tempax[7:2]: HRE[5:0] */
562 /* SR2F [7:2][1:0]: HRE[5:0]HRS[9:8] */
563 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
564 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200565
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300566 /* CR10 VRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200567 Tempax = XGI_CRT1Table[index].CR[10];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300568 /* SR34[7:0]->VRS[7:0] */
569 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200570
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300571 Tempcx = Tempax; /* Tempcx <= VRS[7:0] */
572 /* CR7[7][2] VRS[9][8] */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200573 Tempax = XGI_CRT1Table[index].CR[9];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300574 Tempbx = Tempax; /* Tempbx <= CR07[7:0] */
575 Tempax = Tempax & 0x04; /* Tempax[2]: CR7[2]: VRS[8] */
576 Tempax >>= 2; /* Tempax[0]: VRS[8] */
577 /* SR35[0]: VRS[8] */
578 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x01, Tempax);
579 Tempcx |= (Tempax << 8); /* Tempcx <= VRS[8:0] */
580 Tempcx |= ((Tempbx & 0x80) << 2); /* Tempcx <= VRS[9:0] */
581 /* Tempax: SR0A */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200582 Tempax = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300583 Tempax &= 0x08; /* SR0A[3] VRS[10] */
584 Tempcx |= (Tempax << 7); /* Tempcx <= VRS[10:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200585
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300586 /* Tempax: CR11 VRE */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200587 Tempax = XGI_CRT1Table[index].CR[11];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300588 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
589 /* Tempbx: SR0A */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200590 Tempbx = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300591 Tempbx &= 0x20; /* Tempbx[5]: SR0A[5]: VRE[4] */
592 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
593 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
594 Tempbx = Tempcx; /* Tempbx: VRS[10:0] */
595 Tempbx &= 0x7E0; /* Tempbx[10:5]: VRS[10:5] */
596 Tempbx |= Tempax; /* Tempbx: VRS[10:5]VRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200597
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300598 if (Tempbx <= Tempcx) /* VRE <= VRS */
599 Tempbx |= 0x20; /* VRE + 0x20 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200600
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300601 /* Tempax: Tempax[7:0]; VRE[5:0]00 */
602 Tempax = (Tempbx << 2) & 0xFF;
603 /* SR3F[7:2]:VRE[5:0] */
604 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC, Tempax);
605 Tempax = Tempcx >> 8;
606 /* SR35[2:0]:VRS[10:8] */
607 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200608}
609
Aaro Koskinena2d08cf2011-11-27 23:03:08 +0200610static void XGI_SetXG27FPBits(struct vb_device_info *pVBInfo)
611{
612 unsigned char temp;
613
614 /* D[1:0] 01: 18bit, 00: dual 12, 10: single 24 */
615 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
616 temp = (temp & 3) << 6;
617 /* SR06[7]0: dual 12/1: single 24 [6] 18bit Dither <= 0 h/w recommend */
618 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0xc0, temp & 0x80);
619 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: 24bits */
620 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
621
622}
623
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300624static void xgifb_set_lcd(int chip_id,
625 struct vb_device_info *pVBInfo,
626 unsigned short RefreshRateTableIndex,
627 unsigned short ModeNo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200628{
Peter Huewee2e544c2013-02-03 04:08:46 +0100629 unsigned short temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200630
Aaro Koskinen8104e322011-03-13 12:26:22 +0200631 xgifb_reg_set(pVBInfo->P3d4, 0x2E, 0x00);
632 xgifb_reg_set(pVBInfo->P3d4, 0x2F, 0x00);
633 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x00);
634 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x00);
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300635
636 if (chip_id == XG27) {
Peter Huewee2e544c2013-02-03 04:08:46 +0100637 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
638 if ((temp & 0x03) == 0) { /* dual 12 */
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300639 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x13);
640 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x13);
641 }
642 }
643
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300644 if (chip_id == XG27) {
645 XGI_SetXG27FPBits(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530646 } else {
Peter Huewee2e544c2013-02-03 04:08:46 +0100647 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
648 if (temp & 0x01) {
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300649 /* 18 bits FP */
650 xgifb_reg_or(pVBInfo->P3c4, 0x06, 0x40);
651 xgifb_reg_or(pVBInfo->P3c4, 0x09, 0x40);
652 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530653 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200654
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +0200655 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x01); /* Negative blank polarity */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200656
Aaro Koskinendc505562011-03-13 12:26:26 +0200657 xgifb_reg_and(pVBInfo->P3c4, 0x30, ~0x20); /* Hsync polarity */
658 xgifb_reg_and(pVBInfo->P3c4, 0x35, ~0x80); /* Vsync polarity */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200659
Peter Huewee2e544c2013-02-03 04:08:46 +0100660 temp = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
661 if (temp & 0x4000)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300662 /* Hsync polarity */
663 xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20);
Peter Huewee2e544c2013-02-03 04:08:46 +0100664 if (temp & 0x8000)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300665 /* Vsync polarity */
666 xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200667}
668
669/* --------------------------------------------------------------------- */
670/* Function : XGI_UpdateXG21CRTC */
671/* Input : */
672/* Output : CRT1 CRTC */
673/* Description : Modify CRT1 Hsync/Vsync to fix LCD mode timing */
674/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800675static void XGI_UpdateXG21CRTC(unsigned short ModeNo,
676 struct vb_device_info *pVBInfo,
677 unsigned short RefreshRateTableIndex)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200678{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300679 int index = -1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200680
Aaro Koskinendc505562011-03-13 12:26:26 +0200681 xgifb_reg_and(pVBInfo->P3d4, 0x11, 0x7F); /* Unlock CR0~7 */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300682 if (ModeNo == 0x2E &&
Aaro Koskinena39325d2012-11-04 21:14:53 +0200683 (XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC ==
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300684 RES640x480x60))
685 index = 12;
Aaro Koskinena39325d2012-11-04 21:14:53 +0200686 else if (ModeNo == 0x2E && (XGI330_RefIndex[RefreshRateTableIndex].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800687 Ext_CRT1CRTC == RES640x480x72))
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300688 index = 13;
689 else if (ModeNo == 0x2F)
690 index = 14;
691 else if (ModeNo == 0x50)
692 index = 15;
693 else if (ModeNo == 0x59)
694 index = 16;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200695
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530696 if (index != -1) {
Aaro Koskinen8104e322011-03-13 12:26:22 +0200697 xgifb_reg_set(pVBInfo->P3d4, 0x02,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200698 XGI_UpdateCRT1Table[index].CR02);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200699 xgifb_reg_set(pVBInfo->P3d4, 0x03,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200700 XGI_UpdateCRT1Table[index].CR03);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200701 xgifb_reg_set(pVBInfo->P3d4, 0x15,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200702 XGI_UpdateCRT1Table[index].CR15);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200703 xgifb_reg_set(pVBInfo->P3d4, 0x16,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200704 XGI_UpdateCRT1Table[index].CR16);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530705 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200706}
707
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200708static void XGI_SetCRT1DE(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530709 unsigned short ModeNo, unsigned short ModeIdIndex,
710 unsigned short RefreshRateTableIndex,
711 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200712{
Bill Pemberton82d6eb52010-06-17 13:10:46 -0400713 unsigned short resindex, tempax, tempbx, tempcx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200714
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530715 unsigned char data;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200716
Aaro Koskinenb3979922012-11-04 21:14:52 +0200717 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200718
Aaro Koskinenb3979922012-11-04 21:14:52 +0200719 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinene8e6c752012-11-04 21:15:00 +0200720 tempax = XGI330_ModeResInfo[resindex].HTotal;
721 tempbx = XGI330_ModeResInfo[resindex].VTotal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200722
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530723 if (modeflag & HalfDCLK)
724 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200725
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300726 if (modeflag & HalfDCLK)
727 tempax = tempax << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200728
Aaro Koskinena39325d2012-11-04 21:14:53 +0200729 temp = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200730
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300731 if (temp & InterlaceMode)
732 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200733
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300734 if (modeflag & DoubleScanMode)
735 tempbx = tempbx << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200736
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530737 tempcx = 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200738
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530739 tempax /= tempcx;
740 tempax -= 1;
741 tempbx -= 1;
742 tempcx = tempax;
Peter Huewe9388ad92013-02-15 20:37:10 +0100743 temp = xgifb_reg_get(pVBInfo->P3d4, 0x11);
744 data = xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530745 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200746 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
747 xgifb_reg_set(pVBInfo->P3d4, 0x01, (unsigned short) (tempcx & 0xff));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200748 xgifb_reg_and_or(pVBInfo->P3d4, 0x0b, ~0x0c,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530749 (unsigned short) ((tempcx & 0x0ff00) >> 10));
Aaro Koskinen8104e322011-03-13 12:26:22 +0200750 xgifb_reg_set(pVBInfo->P3d4, 0x12, (unsigned short) (tempbx & 0xff));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530751 tempax = 0;
752 tempbx = tempbx >> 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200753
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530754 if (tempbx & 0x01)
755 tempax |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200756
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530757 if (tempbx & 0x02)
758 tempax |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200759
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200760 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x42, tempax);
Peter Huewe9388ad92013-02-15 20:37:10 +0100761 data = xgifb_reg_get(pVBInfo->P3d4, 0x07);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530762 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200763
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530764 if (tempbx & 0x04)
765 tempax |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200766
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200767 xgifb_reg_and_or(pVBInfo->P3d4, 0x0a, ~0x02, tempax);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200768 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200769}
770
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800771static void XGI_SetCRT1Offset(unsigned short ModeNo,
772 unsigned short ModeIdIndex,
773 unsigned short RefreshRateTableIndex,
774 struct xgi_hw_device_info *HwDeviceExtension,
775 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200776{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530777 unsigned short temp, ah, al, temp2, i, DisplayUnit;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200778
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530779 /* GetOffset */
Aaro Koskinenb3979922012-11-04 21:14:52 +0200780 temp = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeInfo;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530781 temp = temp >> 8;
Aaro Koskinen224114c2012-11-04 21:14:59 +0200782 temp = XGI330_ScreenOffset[temp];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200783
Aaro Koskinena39325d2012-11-04 21:14:53 +0200784 temp2 = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530785 temp2 &= InterlaceMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200786
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530787 if (temp2)
788 temp = temp << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200789
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530790 temp2 = pVBInfo->ModeType - ModeEGA;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200791
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530792 switch (temp2) {
793 case 0:
794 temp2 = 1;
795 break;
796 case 1:
797 temp2 = 2;
798 break;
799 case 2:
800 temp2 = 4;
801 break;
802 case 3:
803 temp2 = 4;
804 break;
805 case 4:
806 temp2 = 6;
807 break;
808 case 5:
809 temp2 = 8;
810 break;
811 default:
812 break;
813 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200814
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530815 if ((ModeNo >= 0x26) && (ModeNo <= 0x28))
816 temp = temp * temp2 + temp2 / 2;
817 else
818 temp *= temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200819
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530820 /* SetOffset */
821 DisplayUnit = temp;
822 temp2 = temp;
823 temp = temp >> 8; /* ah */
824 temp &= 0x0F;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200825 i = xgifb_reg_get(pVBInfo->P3c4, 0x0E);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530826 i &= 0xF0;
827 i |= temp;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200828 xgifb_reg_set(pVBInfo->P3c4, 0x0E, i);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200829
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530830 temp = (unsigned char) temp2;
831 temp &= 0xFF; /* al */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200832 xgifb_reg_set(pVBInfo->P3d4, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200833
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530834 /* SetDisplayUnit */
Aaro Koskinena39325d2012-11-04 21:14:53 +0200835 temp2 = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530836 temp2 &= InterlaceMode;
837 if (temp2)
838 DisplayUnit >>= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200839
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530840 DisplayUnit = DisplayUnit << 5;
841 ah = (DisplayUnit & 0xff00) >> 8;
842 al = DisplayUnit & 0x00ff;
843 if (al == 0)
844 ah += 1;
845 else
846 ah += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200847
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530848 if (HwDeviceExtension->jChipType >= XG20)
849 if ((ModeNo == 0x4A) | (ModeNo == 0x49))
850 ah -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200851
Aaro Koskinen8104e322011-03-13 12:26:22 +0200852 xgifb_reg_set(pVBInfo->P3c4, 0x10, ah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200853}
854
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200855static unsigned short XGI_GetVCLK2Ptr(unsigned short ModeNo,
856 unsigned short ModeIdIndex,
857 unsigned short RefreshRateTableIndex,
858 struct xgi_hw_device_info *HwDeviceExtension,
859 struct vb_device_info *pVBInfo)
860{
Peter Hueweef9a6b92013-02-03 04:08:43 +0100861 unsigned short VCLKIndex, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200862
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300863 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +0200864 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200865
Aaro Koskinen7ac54d02013-02-09 00:03:43 +0200866 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) { /*301b*/
867 if (pVBInfo->LCDResInfo != Panel_1024x768)
868 /* LCDXlat2VCLK */
869 VCLKIndex = VCLK108_2_315 + 5;
870 else
871 VCLKIndex = VCLK65_315 + 2; /* LCDXlat1VCLK */
872 } else if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
873 if (pVBInfo->SetFlag & RPLLDIV2XO)
874 VCLKIndex = TVCLKBASE_315_25 + HiTVVCLKDIV2;
875 else
876 VCLKIndex = TVCLKBASE_315_25 + HiTVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200877
Aaro Koskinen7ac54d02013-02-09 00:03:43 +0200878 if (pVBInfo->SetFlag & TVSimuMode) {
879 if (modeflag & Charx8Dot) {
880 VCLKIndex = TVCLKBASE_315_25 + HiTVSimuVCLK;
881 } else {
882 VCLKIndex = TVCLKBASE_315_25 + HiTVTextVCLK;
Aaro Koskinen798b4da2011-11-27 23:03:20 +0200883 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200884 }
Aaro Koskinen7ac54d02013-02-09 00:03:43 +0200885
886 /* 301lv */
887 if (pVBInfo->VBType & VB_SIS301LV) {
888 if (pVBInfo->SetFlag & RPLLDIV2XO)
889 VCLKIndex = YPbPr525iVCLK_2;
890 else
891 VCLKIndex = YPbPr525iVCLK;
892 }
893 } else if (pVBInfo->VBInfo & SetCRT2ToTV) {
894 if (pVBInfo->SetFlag & RPLLDIV2XO)
895 VCLKIndex = TVCLKBASE_315_25 + TVVCLKDIV2;
896 else
897 VCLKIndex = TVCLKBASE_315_25 + TVVCLK;
898 } else { /* for CRT2 */
899 /* di+Ext_CRTVCLK */
900 VCLKIndex = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
901 VCLKIndex &= IndexMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200902 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200903
904 return VCLKIndex;
905}
906
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800907static void XGI_SetCRT1VCLK(unsigned short ModeNo,
908 unsigned short ModeIdIndex,
909 struct xgi_hw_device_info *HwDeviceExtension,
910 unsigned short RefreshRateTableIndex,
911 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200912{
Bill Pemberton108afbf2010-06-17 13:10:47 -0400913 unsigned char index, data;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530914 unsigned short vclkindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200915
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530916 if (pVBInfo->IF_DEF_LVDS == 1) {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200917 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200918 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200919 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200920 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[index].SR2B);
921 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[index].SR2C);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200922 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Peter Huewe6896b942012-02-09 21:11:46 +0100923 } else if ((pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
924 | VB_SIS302LV | VB_XGI301C)) && (pVBInfo->VBInfo
Peter Huewea3d675c2012-02-09 21:11:47 +0100925 & XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530926 vclkindex = XGI_GetVCLK2Ptr(ModeNo, ModeIdIndex,
927 RefreshRateTableIndex, HwDeviceExtension,
928 pVBInfo);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200929 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200930 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200931 data = XGI_VBVCLKData[vclkindex].Part4_A;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200932 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200933 data = XGI_VBVCLKData[vclkindex].Part4_B;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200934 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
935 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530936 } else {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200937 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200938 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200939 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200940 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[index].SR2B);
941 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[index].SR2C);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200942 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530943 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200944
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530945 if (HwDeviceExtension->jChipType >= XG20) {
Aaro Koskinenb3979922012-11-04 21:14:52 +0200946 if (XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag &
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800947 HalfDCLK) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200948 data = xgifb_reg_get(pVBInfo->P3c4, 0x2B);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200949 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200950 data = xgifb_reg_get(pVBInfo->P3c4, 0x2C);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530951 index = data;
952 index &= 0xE0;
953 data &= 0x1F;
954 data = data << 1;
955 data += 1;
956 data |= index;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200957 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530958 }
959 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200960}
961
Aaro Koskinene85f2032011-11-27 23:03:07 +0200962static void XGI_SetXG21FPBits(struct vb_device_info *pVBInfo)
963{
964 unsigned char temp;
965
966 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37); /* D[0] 1: 18bit */
967 temp = (temp & 1) << 6;
968 /* SR06[6] 18bit Dither */
969 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x40, temp);
970 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: dual 12bits */
971 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
972
973}
974
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200975static void XGI_SetCRT1FIFO(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530976 struct xgi_hw_device_info *HwDeviceExtension,
977 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200978{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530979 unsigned short data;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200980
Aaro Koskinen58839b02011-03-13 12:26:23 +0200981 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530982 data &= 0xfe;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200983 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data); /* diable auto-threshold */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200984
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300985 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0x34);
986 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
987 data &= 0xC0;
988 xgifb_reg_set(pVBInfo->P3c4, 0x09, data | 0x30);
989 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
990 data |= 0x01;
991 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200992
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530993 if (HwDeviceExtension->jChipType == XG21)
994 XGI_SetXG21FPBits(pVBInfo); /* Fix SR9[7:6] can't read back */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200995}
996
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200997static void XGI_SetVCLKState(struct xgi_hw_device_info *HwDeviceExtension,
998 unsigned short ModeNo, unsigned short RefreshRateTableIndex,
999 struct vb_device_info *pVBInfo)
1000{
1001 unsigned short data, data2 = 0;
1002 short VCLK;
1003
1004 unsigned char index;
1005
Aaro Koskinena39325d2012-11-04 21:14:53 +02001006 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001007 index &= IndexMask;
Aaro Koskinenacfe0932012-11-04 21:14:58 +02001008 VCLK = XGI_VCLKData[index].CLOCK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001009
Aaro Koskinen58839b02011-03-13 12:26:23 +02001010 data = xgifb_reg_get(pVBInfo->P3c4, 0x32);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001011 data &= 0xf3;
1012 if (VCLK >= 200)
1013 data |= 0x0c; /* VCLK > 200 */
1014
1015 if (HwDeviceExtension->jChipType >= XG20)
1016 data &= ~0x04; /* 2 pixel mode */
1017
Aaro Koskinen8104e322011-03-13 12:26:22 +02001018 xgifb_reg_set(pVBInfo->P3c4, 0x32, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001019
1020 if (HwDeviceExtension->jChipType < XG20) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001021 data = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001022 data &= 0xE7;
1023 if (VCLK < 200)
1024 data |= 0x10;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001025 xgifb_reg_set(pVBInfo->P3c4, 0x1F, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001026 }
1027
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001028 data2 = 0x00;
1029
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001030 xgifb_reg_and_or(pVBInfo->P3c4, 0x07, 0xFC, data2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001031 if (HwDeviceExtension->jChipType >= XG27)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001032 xgifb_reg_and_or(pVBInfo->P3c4, 0x40, 0xFC, data2 & 0x03);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001033
1034}
1035
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001036static void XGI_SetCRT1ModeRegs(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301037 unsigned short ModeNo, unsigned short ModeIdIndex,
1038 unsigned short RefreshRateTableIndex,
1039 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001040{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301041 unsigned short data, data2, data3, infoflag = 0, modeflag, resindex,
1042 xres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001043
Aaro Koskinenb3979922012-11-04 21:14:52 +02001044 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02001045 infoflag = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001046
Aaro Koskinen58839b02011-03-13 12:26:23 +02001047 if (xgifb_reg_get(pVBInfo->P3d4, 0x31) & 0x01)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001048 xgifb_reg_and_or(pVBInfo->P3c4, 0x1F, 0x3F, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001049
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001050 data = infoflag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301051 data2 = 0;
Aaro Koskinen969f7f32012-04-07 01:14:03 +03001052 data2 |= 0x02;
1053 data3 = pVBInfo->ModeType - ModeVGA;
1054 data3 = data3 << 2;
1055 data2 |= data3;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301056 data &= InterlaceMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001057
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301058 if (data)
1059 data2 |= 0x20;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001060
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001061 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x3F, data2);
Aaro Koskinenb3979922012-11-04 21:14:52 +02001062 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02001063 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001064
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301065 data = 0x0000;
1066 if (infoflag & InterlaceMode) {
1067 if (xres == 1024)
1068 data = 0x0035;
1069 else if (xres == 1280)
1070 data = 0x0048;
1071 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001072
Peter Huewe5d1c2a92013-02-03 22:54:37 +01001073 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFF, data);
1074 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFC, 0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001075
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301076 if (modeflag & HalfDCLK)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001077 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xF7, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001078
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301079 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001080
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301081 if (modeflag & LineCompareOff)
1082 data2 |= 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001083
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001084 xgifb_reg_and_or(pVBInfo->P3c4, 0x0F, ~0x48, data2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301085 data = 0x60;
Aaro Koskinen969f7f32012-04-07 01:14:03 +03001086 data = data ^ 0x60;
1087 data = data ^ 0xA0;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001088 xgifb_reg_and_or(pVBInfo->P3c4, 0x21, 0x1F, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001089
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301090 XGI_SetVCLKState(HwDeviceExtension, ModeNo, RefreshRateTableIndex,
1091 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001092
Aaro Koskinen58839b02011-03-13 12:26:23 +02001093 data = xgifb_reg_get(pVBInfo->P3d4, 0x31);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001094
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301095 if (HwDeviceExtension->jChipType == XG27) {
1096 if (data & 0x40)
1097 data = 0x2c;
1098 else
1099 data = 0x6c;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001100 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02001101 xgifb_reg_or(pVBInfo->P3d4, 0x51, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301102 } else if (HwDeviceExtension->jChipType >= XG20) {
1103 if (data & 0x40)
1104 data = 0x33;
1105 else
1106 data = 0x73;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001107 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
1108 xgifb_reg_set(pVBInfo->P3d4, 0x51, 0x02);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301109 } else {
1110 if (data & 0x40)
1111 data = 0x2c;
1112 else
1113 data = 0x6c;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001114 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301115 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001116
1117}
1118
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001119static void XGI_WriteDAC(unsigned short dl,
1120 unsigned short ah,
1121 unsigned short al,
1122 unsigned short dh,
1123 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001124{
1125 unsigned short temp, bh, bl;
1126
1127 bh = ah;
1128 bl = al;
1129
1130 if (dl != 0) {
1131 temp = bh;
1132 bh = dh;
1133 dh = temp;
1134 if (dl == 1) {
1135 temp = bl;
1136 bl = dh;
1137 dh = temp;
1138 } else {
1139 temp = bl;
1140 bl = bh;
1141 bh = temp;
1142 }
1143 }
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001144 outb((unsigned short) dh, pVBInfo->P3c9);
1145 outb((unsigned short) bh, pVBInfo->P3c9);
1146 outb((unsigned short) bl, pVBInfo->P3c9);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001147}
1148
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001149static void XGI_LoadDAC(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301150 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001151{
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001152 unsigned short data, data2, i, k, m, n, o, si, di, bx, dl, al, ah, dh;
1153 const unsigned short *table = XGINew_VGA_DAC;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001154
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001155 outb(0xFF, pVBInfo->P3c6);
1156 outb(0x00, pVBInfo->P3c8);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001157
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001158 for (i = 0; i < 16; i++) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301159 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001160
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301161 for (k = 0; k < 3; k++) {
1162 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001163
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301164 if (data & 0x01)
1165 data2 = 0x2A;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001166
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301167 if (data & 0x02)
1168 data2 += 0x15;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001169
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001170 outb(data2, pVBInfo->P3c9);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301171 data = data >> 2;
1172 }
1173 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001174
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001175 for (i = 16; i < 32; i++) {
1176 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001177
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001178 for (k = 0; k < 3; k++)
1179 outb(data, pVBInfo->P3c9);
1180 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001181
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001182 si = 32;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001183
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001184 for (m = 0; m < 9; m++) {
1185 di = si;
1186 bx = si + 0x04;
1187 dl = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001188
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001189 for (n = 0; n < 3; n++) {
1190 for (o = 0; o < 5; o++) {
1191 dh = table[si];
1192 ah = table[di];
1193 al = table[bx];
1194 si++;
1195 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301196 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001197
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001198 si -= 2;
1199
1200 for (o = 0; o < 3; o++) {
1201 dh = table[bx];
1202 ah = table[di];
1203 al = table[si];
1204 si--;
1205 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1206 }
1207
1208 dl++;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301209 }
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001210
1211 si += 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301212 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001213}
1214
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001215static void XGI_GetLVDSResInfo(unsigned short ModeNo,
1216 unsigned short ModeIdIndex,
1217 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001218{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301219 unsigned short resindex, xres, yres, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001220
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001221 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02001222 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001223
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001224 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02001225 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001226
Aaro Koskinene8e6c752012-11-04 21:15:00 +02001227 xres = XGI330_ModeResInfo[resindex].HTotal;
1228 yres = XGI330_ModeResInfo[resindex].VTotal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001229
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001230 if (modeflag & HalfDCLK)
1231 xres = xres << 1;
1232
1233 if (modeflag & DoubleScanMode)
1234 yres = yres << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001235
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301236 if (xres == 720)
1237 xres = 640;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001238
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301239 pVBInfo->VGAHDE = xres;
1240 pVBInfo->HDE = xres;
1241 pVBInfo->VGAVDE = yres;
1242 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001243}
1244
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001245static void const *XGI_GetLcdPtr(struct XGI330_LCDDataTablStruct const *table,
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001246 unsigned short ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001247 unsigned short ModeIdIndex,
1248 unsigned short RefreshRateTableIndex,
1249 struct vb_device_info *pVBInfo)
1250{
Aaro Koskinen6c27b372012-11-04 21:14:45 +02001251 unsigned short i, tempdx, tempbx, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001252
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001253 tempbx = 0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001254
Aaro Koskinenb3979922012-11-04 21:14:52 +02001255 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001256
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001257 i = 0;
1258
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001259 while (table[i].PANELID != 0xff) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001260 tempdx = pVBInfo->LCDResInfo;
1261 if (tempbx & 0x0080) { /* OEMUtil */
1262 tempbx &= (~0x0080);
1263 tempdx = pVBInfo->LCDTypeInfo;
1264 }
1265
1266 if (pVBInfo->LCDInfo & EnableScalingLCD)
1267 tempdx &= (~PanelResInfo);
1268
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001269 if (table[i].PANELID == tempdx) {
1270 tempbx = table[i].MASK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001271 tempdx = pVBInfo->LCDInfo;
1272
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001273 if (modeflag & HalfDCLK)
1274 tempdx |= SetLCDLowResolution;
1275
1276 tempbx &= tempdx;
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001277 if (tempbx == table[i].CAP)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001278 break;
1279 }
1280 i++;
1281 }
1282
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001283 return table[i].DATAPTR;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001284}
1285
Aaro Koskinen24572542012-09-11 00:15:21 +03001286static struct SiS_TVData const *XGI_GetTVPtr(unsigned short ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001287 unsigned short ModeIdIndex,
1288 unsigned short RefreshRateTableIndex,
1289 struct vb_device_info *pVBInfo)
1290{
Aaro Koskinen56d276c2012-09-11 00:15:19 +03001291 unsigned short i, tempdx, tempal, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001292
Aaro Koskinenb3979922012-11-04 21:14:52 +02001293 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02001294 tempal = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001295 tempal = tempal & 0x3f;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001296 tempdx = pVBInfo->TVInfo;
1297
1298 if (pVBInfo->VBInfo & SetInSlaveMode)
1299 tempdx = tempdx | SetTVLockMode;
1300
1301 if (modeflag & HalfDCLK)
1302 tempdx = tempdx | SetTVLowResolution;
1303
1304 i = 0;
1305
Aaro Koskinen6265ee42012-09-11 00:15:20 +03001306 while (XGI_TVDataTable[i].MASK != 0xffff) {
1307 if ((tempdx & XGI_TVDataTable[i].MASK) ==
1308 XGI_TVDataTable[i].CAP)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001309 break;
1310 i++;
1311 }
1312
Aaro Koskinen18ba8662012-09-11 00:15:22 +03001313 return &XGI_TVDataTable[i].DATAPTR[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001314}
1315
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001316static void XGI_GetLVDSData(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301317 unsigned short RefreshRateTableIndex,
1318 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001319{
Aaro Koskinen6008f872012-11-04 21:14:49 +02001320 struct SiS_LVDSData const *LCDPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001321
Aaro Koskinen6008f872012-11-04 21:14:49 +02001322 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
1323 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001324
Aaro Koskinen6008f872012-11-04 21:14:49 +02001325 LCDPtr = XGI_GetLcdPtr(XGI_EPLLCDDataPtr, ModeNo, ModeIdIndex,
1326 RefreshRateTableIndex, pVBInfo);
1327 pVBInfo->VGAHT = LCDPtr->VGAHT;
1328 pVBInfo->VGAVT = LCDPtr->VGAVT;
1329 pVBInfo->HT = LCDPtr->LCDHT;
1330 pVBInfo->VT = LCDPtr->LCDVT;
1331
1332 if (pVBInfo->LCDInfo & (SetLCDtoNonExpanding | EnableScalingLCD))
1333 return;
1334
1335 if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
1336 (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
1337 pVBInfo->HDE = 1024;
1338 pVBInfo->VDE = 768;
1339 } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
1340 (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
1341 pVBInfo->HDE = 1280;
1342 pVBInfo->VDE = 1024;
1343 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
1344 pVBInfo->HDE = 1400;
1345 pVBInfo->VDE = 1050;
1346 } else {
1347 pVBInfo->HDE = 1600;
1348 pVBInfo->VDE = 1200;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301349 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001350}
1351
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001352static void XGI_ModCRT1Regs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301353 unsigned short RefreshRateTableIndex,
1354 struct xgi_hw_device_info *HwDeviceExtension,
1355 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001356{
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001357 unsigned short i;
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001358 struct XGI_LVDSCRT1HDataStruct const *LCDPtr = NULL;
1359 struct XGI_LVDSCRT1VDataStruct const *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001360
Peter Huewea3d675c2012-02-09 21:11:47 +01001361 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001362 LCDPtr = XGI_GetLcdPtr(xgifb_epllcd_crt1_h, ModeNo, ModeIdIndex,
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +03001363 RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001364
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001365 for (i = 0; i < 8; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +02001366 pVBInfo->TimingH.data[i] = LCDPtr[0].Reg[i];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301367 }
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001368
1369 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
1370
Peter Huewea3d675c2012-02-09 21:11:47 +01001371 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001372 LCDPtr1 = XGI_GetLcdPtr(xgifb_epllcd_crt1_v, ModeNo,
1373 ModeIdIndex, RefreshRateTableIndex,
1374 pVBInfo);
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001375 for (i = 0; i < 7; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +02001376 pVBInfo->TimingV.data[i] = LCDPtr1[0].Reg[i];
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001377 }
1378
1379 XGI_SetCRT1Timing_V(ModeIdIndex, ModeNo, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001380}
1381
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001382static unsigned short XGI_GetLCDCapPtr(struct vb_device_info *pVBInfo)
1383{
1384 unsigned char tempal, tempah, tempbl, i;
1385
Aaro Koskinen58839b02011-03-13 12:26:23 +02001386 tempah = xgifb_reg_get(pVBInfo->P3d4, 0x36);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001387 tempal = tempah & 0x0F;
1388 tempah = tempah & 0xF0;
1389 i = 0;
1390 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1391
1392 while (tempbl != 0xFF) {
1393 if (tempbl & 0x80) { /* OEMUtil */
1394 tempal = tempah;
1395 tempbl = tempbl & ~(0x80);
1396 }
1397
1398 if (tempal == tempbl)
1399 break;
1400
1401 i++;
1402
1403 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1404 }
1405
1406 return i;
1407}
1408
1409static unsigned short XGI_GetLCDCapPtr1(struct vb_device_info *pVBInfo)
1410{
1411 unsigned short tempah, tempal, tempbl, i;
1412
1413 tempal = pVBInfo->LCDResInfo;
1414 tempah = pVBInfo->LCDTypeInfo;
1415
1416 i = 0;
1417 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1418
1419 while (tempbl != 0xFF) {
1420 if ((tempbl & 0x80) && (tempbl != 0x80)) {
1421 tempal = tempah;
1422 tempbl &= ~0x80;
1423 }
1424
1425 if (tempal == tempbl)
1426 break;
1427
1428 i++;
1429 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1430 }
1431
1432 if (tempbl == 0xFF) {
Peter Huewe255aabd2012-02-09 21:11:44 +01001433 pVBInfo->LCDResInfo = Panel_1024x768;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001434 pVBInfo->LCDTypeInfo = 0;
1435 i = 0;
1436 }
1437
1438 return i;
1439}
1440
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001441static void XGI_GetLCDSync(unsigned short *HSyncWidth,
1442 unsigned short *VSyncWidth,
1443 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001444{
1445 unsigned short Index;
1446
1447 Index = XGI_GetLCDCapPtr(pVBInfo);
1448 *HSyncWidth = pVBInfo->LCDCapList[Index].LCD_HSyncWidth;
1449 *VSyncWidth = pVBInfo->LCDCapList[Index].LCD_VSyncWidth;
1450
1451 return;
1452}
1453
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001454static void XGI_SetLVDSRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301455 unsigned short RefreshRateTableIndex,
1456 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001457{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301458 unsigned short tempbx, tempax, tempcx, tempdx, push1, push2, modeflag;
1459 unsigned long temp, temp1, temp2, temp3, push3;
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001460 struct XGI330_LCDDataDesStruct2 const *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001461
Aaro Koskinenb3979922012-11-04 21:14:52 +02001462 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Peter Huewe826215d2013-02-05 00:29:46 +01001463 LCDPtr1 = XGI_GetLcdPtr(XGI_EPLLCDDesDataPtr, ModeNo, ModeIdIndex,
1464 RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001465
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001466 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
1467 push1 = tempbx;
1468 push2 = tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001469
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001470 /* GetLCDResInfo */
Peter Huewe255aabd2012-02-09 21:11:44 +01001471 if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
1472 (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001473 tempax = 1024;
1474 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01001475 } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
1476 (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001477 tempax = 1280;
1478 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01001479 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001480 tempax = 1400;
1481 tempbx = 1050;
1482 } else {
1483 tempax = 1600;
1484 tempbx = 1200;
1485 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001486
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001487 if (pVBInfo->LCDInfo & SetLCDtoNonExpanding) {
1488 pVBInfo->HDE = tempax;
1489 pVBInfo->VDE = tempbx;
1490 pVBInfo->VGAHDE = tempax;
1491 pVBInfo->VGAVDE = tempbx;
1492 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001493
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001494 tempax = pVBInfo->HT;
1495
Peter Huewe826215d2013-02-05 00:29:46 +01001496 tempbx = LCDPtr1->LCDHDES;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001497
1498 tempcx = pVBInfo->HDE;
1499 tempbx = tempbx & 0x0fff;
1500 tempcx += tempbx;
1501
1502 if (tempcx >= tempax)
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001503 tempcx -= tempax;
1504
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001505 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, tempbx & 0x07);
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001506
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001507 tempcx = tempcx >> 3;
1508 tempbx = tempbx >> 3;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001509
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001510 xgifb_reg_set(pVBInfo->Part1Port, 0x16,
1511 (unsigned short) (tempbx & 0xff));
1512 xgifb_reg_set(pVBInfo->Part1Port, 0x17,
1513 (unsigned short) (tempcx & 0xff));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001514
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001515 tempax = pVBInfo->HT;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001516
Peter Huewe826215d2013-02-05 00:29:46 +01001517 tempbx = LCDPtr1->LCDHRS;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001518
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001519 tempcx = push2;
1520
1521 if (pVBInfo->LCDInfo & EnableScalingLCD)
1522 tempcx = LCDPtr1->LCDHSync;
1523
1524 tempcx += tempbx;
1525
1526 if (tempcx >= tempax)
1527 tempcx -= tempax;
1528
1529 tempax = tempbx & 0x07;
1530 tempax = tempax >> 5;
1531 tempcx = tempcx >> 3;
1532 tempbx = tempbx >> 3;
1533
1534 tempcx &= 0x1f;
1535 tempax |= tempcx;
1536
1537 xgifb_reg_set(pVBInfo->Part1Port, 0x15, tempax);
1538 xgifb_reg_set(pVBInfo->Part1Port, 0x14,
1539 (unsigned short) (tempbx & 0xff));
1540
1541 tempax = pVBInfo->VT;
Peter Huewe826215d2013-02-05 00:29:46 +01001542 tempbx = LCDPtr1->LCDVDES;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001543 tempcx = pVBInfo->VDE;
1544
1545 tempbx = tempbx & 0x0fff;
1546 tempcx += tempbx;
1547 if (tempcx >= tempax)
1548 tempcx -= tempax;
1549
1550 xgifb_reg_set(pVBInfo->Part1Port, 0x1b,
1551 (unsigned short) (tempbx & 0xff));
1552 xgifb_reg_set(pVBInfo->Part1Port, 0x1c,
1553 (unsigned short) (tempcx & 0xff));
1554
1555 tempbx = (tempbx >> 8) & 0x07;
1556 tempcx = (tempcx >> 8) & 0x07;
1557
1558 xgifb_reg_set(pVBInfo->Part1Port, 0x1d,
1559 (unsigned short) ((tempcx << 3)
1560 | tempbx));
1561
1562 tempax = pVBInfo->VT;
Peter Huewe826215d2013-02-05 00:29:46 +01001563 tempbx = LCDPtr1->LCDVRS;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001564
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001565 tempcx = push1;
1566
1567 if (pVBInfo->LCDInfo & EnableScalingLCD)
1568 tempcx = LCDPtr1->LCDVSync;
1569
1570 tempcx += tempbx;
1571 if (tempcx >= tempax)
1572 tempcx -= tempax;
1573
1574 xgifb_reg_set(pVBInfo->Part1Port, 0x18,
1575 (unsigned short) (tempbx & 0xff));
1576 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, ~0x0f,
1577 (unsigned short) (tempcx & 0x0f));
1578
1579 tempax = ((tempbx >> 8) & 0x07) << 3;
1580
1581 tempbx = pVBInfo->VGAVDE;
1582 if (tempbx != pVBInfo->VDE)
1583 tempax |= 0x40;
1584
Peter Huewea3d675c2012-02-09 21:11:47 +01001585 if (pVBInfo->LCDInfo & XGI_EnableLVDSDDA)
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001586 tempax |= 0x40;
1587
1588 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1a, 0x07,
1589 tempax);
1590
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001591 tempbx = pVBInfo->VDE;
1592 tempax = pVBInfo->VGAVDE;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001593
1594 temp = tempax; /* 0430 ylshieh */
1595 temp1 = (temp << 18) / tempbx;
1596
1597 tempdx = (unsigned short) ((temp << 18) % tempbx);
1598
1599 if (tempdx != 0)
1600 temp1 += 1;
1601
1602 temp2 = temp1;
1603 push3 = temp2;
1604
1605 xgifb_reg_set(pVBInfo->Part1Port, 0x37,
1606 (unsigned short) (temp2 & 0xff));
1607 xgifb_reg_set(pVBInfo->Part1Port, 0x36,
1608 (unsigned short) ((temp2 >> 8) & 0xff));
1609
1610 tempbx = (unsigned short) (temp2 >> 16);
1611 tempax = tempbx & 0x03;
1612
1613 tempbx = pVBInfo->VGAVDE;
1614 if (tempbx == pVBInfo->VDE)
1615 tempax |= 0x04;
1616
1617 xgifb_reg_set(pVBInfo->Part1Port, 0x35, tempax);
1618
1619 if (pVBInfo->VBType & VB_XGI301C) {
1620 temp2 = push3;
1621 xgifb_reg_set(pVBInfo->Part4Port,
1622 0x3c,
1623 (unsigned short) (temp2 & 0xff));
1624 xgifb_reg_set(pVBInfo->Part4Port,
1625 0x3b,
1626 (unsigned short) ((temp2 >> 8) &
1627 0xff));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001628 tempbx = (unsigned short) (temp2 >> 16);
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001629 xgifb_reg_and_or(pVBInfo->Part4Port, 0x3a,
1630 ~0xc0,
1631 (unsigned short) ((tempbx &
1632 0xff) << 6));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001633
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001634 tempcx = pVBInfo->VGAVDE;
1635 if (tempcx == pVBInfo->VDE)
1636 xgifb_reg_and_or(pVBInfo->Part4Port,
1637 0x30, ~0x0c, 0x00);
1638 else
1639 xgifb_reg_and_or(pVBInfo->Part4Port,
1640 0x30, ~0x0c, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301641 }
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001642
1643 tempcx = pVBInfo->VGAHDE;
1644 tempbx = pVBInfo->HDE;
1645
1646 temp1 = tempcx << 16;
1647
1648 tempax = (unsigned short) (temp1 / tempbx);
1649
1650 if ((tempbx & 0xffff) == (tempcx & 0xffff))
1651 tempax = 65535;
1652
1653 temp3 = tempax;
1654 temp1 = pVBInfo->VGAHDE << 16;
1655
1656 temp1 /= temp3;
1657 temp3 = temp3 << 16;
1658 temp1 -= 1;
1659
1660 temp3 = (temp3 & 0xffff0000) + (temp1 & 0xffff);
1661
1662 tempax = (unsigned short) (temp3 & 0xff);
1663 xgifb_reg_set(pVBInfo->Part1Port, 0x1f, tempax);
1664
1665 temp1 = pVBInfo->VGAVDE << 18;
1666 temp1 = temp1 / push3;
1667 tempbx = (unsigned short) (temp1 & 0xffff);
1668
Peter Huewe255aabd2012-02-09 21:11:44 +01001669 if (pVBInfo->LCDResInfo == Panel_1024x768)
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001670 tempbx -= 1;
1671
1672 tempax = ((tempbx >> 8) & 0xff) << 3;
1673 tempax |= (unsigned short) ((temp3 >> 8) & 0x07);
1674 xgifb_reg_set(pVBInfo->Part1Port, 0x20,
1675 (unsigned short) (tempax & 0xff));
1676 xgifb_reg_set(pVBInfo->Part1Port, 0x21,
1677 (unsigned short) (tempbx & 0xff));
1678
1679 temp3 = temp3 >> 16;
1680
1681 if (modeflag & HalfDCLK)
1682 temp3 = temp3 >> 1;
1683
1684 xgifb_reg_set(pVBInfo->Part1Port, 0x22,
1685 (unsigned short) ((temp3 >> 8) & 0xff));
1686 xgifb_reg_set(pVBInfo->Part1Port, 0x23,
1687 (unsigned short) (temp3 & 0xff));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001688}
1689
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001690/* --------------------------------------------------------------------- */
1691/* Function : XGI_GETLCDVCLKPtr */
1692/* Input : */
1693/* Output : al -> VCLK Index */
1694/* Description : */
1695/* --------------------------------------------------------------------- */
1696static void XGI_GetLCDVCLKPtr(unsigned char *di_0, unsigned char *di_1,
1697 struct vb_device_info *pVBInfo)
1698{
1699 unsigned short index;
1700
Peter Huewea3d675c2012-02-09 21:11:47 +01001701 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001702 index = XGI_GetLCDCapPtr1(pVBInfo);
1703
1704 if (pVBInfo->VBInfo & SetCRT2ToLCD) { /* LCDB */
1705 *di_0 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData1;
1706 *di_1 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData2;
1707 } else { /* LCDA */
1708 *di_0 = pVBInfo->LCDCapList[index].LCDA_VCLKData1;
1709 *di_1 = pVBInfo->LCDCapList[index].LCDA_VCLKData2;
1710 }
1711 }
1712 return;
1713}
1714
1715static unsigned char XGI_GetVCLKPtr(unsigned short RefreshRateTableIndex,
1716 unsigned short ModeNo, unsigned short ModeIdIndex,
1717 struct vb_device_info *pVBInfo)
1718{
1719
1720 unsigned short index, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001721 unsigned char tempal;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001722
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001723 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02001724 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001725
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001726 if ((pVBInfo->SetFlag & ProgrammingCRT2) &&
1727 (!(pVBInfo->LCDInfo & EnableScalingLCD))) { /* {LCDA/LCDB} */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001728 index = XGI_GetLCDCapPtr(pVBInfo);
1729 tempal = pVBInfo->LCDCapList[index].LCD_VCLK;
1730
Peter Huewea3d675c2012-02-09 21:11:47 +01001731 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001732 return tempal;
1733
1734 /* {TV} */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001735 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01001736 (VB_SIS301B |
1737 VB_SIS302B |
1738 VB_SIS301LV |
1739 VB_SIS302LV |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001740 VB_XGI301C)) {
Peter Huewe599801f2012-02-09 21:11:45 +01001741 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001742 tempal = TVCLKBASE_315 + HiTVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001743 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
Peter Hueweccc8cb22012-02-09 21:11:48 +01001744 tempal = TVCLKBASE_315 + HiTVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001745 if (pVBInfo->TVInfo & TVSimuMode) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001746 tempal = TVCLKBASE_315 + HiTVSimuVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001747 if (!(modeflag & Charx8Dot))
Miguel Gómez3bcc2462012-07-06 12:40:53 +02001748 tempal = TVCLKBASE_315 +
1749 HiTVTextVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001750
1751 }
1752 return tempal;
1753 }
1754
Peter Huewe599801f2012-02-09 21:11:45 +01001755 if (pVBInfo->TVInfo & TVSetYPbPr750p) {
Peter Huewea3d675c2012-02-09 21:11:47 +01001756 tempal = XGI_YPbPr750pVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001757 return tempal;
1758 }
1759
Peter Huewe599801f2012-02-09 21:11:45 +01001760 if (pVBInfo->TVInfo & TVSetYPbPr525p) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001761 tempal = YPbPr525pVCLK;
1762 return tempal;
1763 }
1764
1765 tempal = NTSC1024VCLK;
1766
1767 if (!(pVBInfo->TVInfo & NTSC1024x768)) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001768 tempal = TVCLKBASE_315 + TVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001769 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
Peter Hueweccc8cb22012-02-09 21:11:48 +01001770 tempal = TVCLKBASE_315 + TVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001771 }
1772
1773 if (pVBInfo->VBInfo & SetCRT2ToTV)
1774 return tempal;
1775 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001776 } /* {End of VB} */
1777
Peter Huewe516354e2013-02-15 20:37:11 +01001778 inb((pVBInfo->P3ca + 0x02));
Aaro Koskinena39325d2012-11-04 21:14:53 +02001779 tempal = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001780 return tempal;
1781}
1782
1783static void XGI_GetVCLKLen(unsigned char tempal, unsigned char *di_0,
1784 unsigned char *di_1, struct vb_device_info *pVBInfo)
1785{
Peter Huewe6896b942012-02-09 21:11:46 +01001786 if (pVBInfo->VBType & (VB_SIS301 | VB_SIS301B | VB_SIS302B
1787 | VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +02001788 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) &&
1789 (pVBInfo->SetFlag & ProgrammingCRT2)) {
Aaro Koskinene8cb03d2012-09-11 00:15:31 +03001790 *di_0 = XGI_VBVCLKData[tempal].Part4_A;
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +03001791 *di_1 = XGI_VBVCLKData[tempal].Part4_B;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001792 }
1793 } else {
1794 *di_0 = XGI_VCLKData[tempal].SR2B;
1795 *di_1 = XGI_VCLKData[tempal].SR2C;
1796 }
1797}
1798
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001799static void XGI_SetCRT2ECLK(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301800 unsigned short RefreshRateTableIndex,
1801 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001802{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301803 unsigned char di_0, di_1, tempal;
1804 int i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001805
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301806 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
1807 pVBInfo);
1808 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
1809 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001810
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301811 for (i = 0; i < 4; i++) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001812 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, ~0x30,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301813 (unsigned short) (0x10 * i));
Peter Huewea3d675c2012-02-09 21:11:47 +01001814 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301815 && (!(pVBInfo->VBInfo & SetInSlaveMode))) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001816 xgifb_reg_set(pVBInfo->P3c4, 0x2e, di_0);
1817 xgifb_reg_set(pVBInfo->P3c4, 0x2f, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301818 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001819 xgifb_reg_set(pVBInfo->P3c4, 0x2b, di_0);
1820 xgifb_reg_set(pVBInfo->P3c4, 0x2c, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301821 }
1822 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001823}
1824
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001825static void XGI_UpdateModeInfo(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301826 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001827{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301828 unsigned short tempcl, tempch, temp, tempbl, tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001829
Peter Huewe6896b942012-02-09 21:11:46 +01001830 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
1831 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301832 tempcl = 0;
1833 tempch = 0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02001834 temp = xgifb_reg_get(pVBInfo->P3c4, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001835
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301836 if (!(temp & 0x20)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001837 temp = xgifb_reg_get(pVBInfo->P3d4, 0x17);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301838 if (temp & 0x80) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001839 temp = xgifb_reg_get(pVBInfo->P3d4, 0x53);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301840 if (!(temp & 0x40))
1841 tempcl |= ActiveCRT1;
1842 }
1843 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001844
Aaro Koskinen58839b02011-03-13 12:26:23 +02001845 temp = xgifb_reg_get(pVBInfo->Part1Port, 0x2e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301846 temp &= 0x0f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001847
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301848 if (!(temp == 0x08)) {
Miguel Gómez949eb0a2012-07-06 12:40:36 +02001849 /* Check ChannelA */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001850 tempax = xgifb_reg_get(pVBInfo->Part1Port, 0x13);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301851 if (tempax & 0x04)
1852 tempcl = tempcl | ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001853
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301854 temp &= 0x05;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001855
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301856 if (!(tempcl & ActiveLCD))
1857 if (temp == 0x01)
1858 tempcl |= ActiveCRT2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001859
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301860 if (temp == 0x04)
1861 tempcl |= ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001862
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301863 if (temp == 0x05) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001864 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001865
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301866 if (!(temp & 0x08))
1867 tempch |= ActiveAVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001868
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301869 if (!(temp & 0x04))
1870 tempch |= ActiveSVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001871
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301872 if (temp & 0x02)
1873 tempch |= ActiveSCART;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001874
Peter Huewe599801f2012-02-09 21:11:45 +01001875 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301876 if (temp & 0x01)
1877 tempch |= ActiveHiTV;
1878 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001879
Peter Huewe599801f2012-02-09 21:11:45 +01001880 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001881 temp = xgifb_reg_get(
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301882 pVBInfo->Part2Port,
1883 0x4d);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001884
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301885 if (temp & 0x10)
1886 tempch |= ActiveYPbPr;
1887 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001888
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301889 if (tempch != 0)
1890 tempcl |= ActiveTV;
1891 }
1892 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001893
Aaro Koskinen58839b02011-03-13 12:26:23 +02001894 temp = xgifb_reg_get(pVBInfo->P3d4, 0x3d);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301895 if (tempcl & ActiveLCD) {
1896 if ((pVBInfo->SetFlag & ReserveTVOption)) {
1897 if (temp & ActiveTV)
1898 tempcl |= ActiveTV;
1899 }
1900 }
1901 temp = tempcl;
Peter Huewea3d675c2012-02-09 21:11:47 +01001902 tempbl = ~XGI_ModeSwitchStatus;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001903 xgifb_reg_and_or(pVBInfo->P3d4, 0x3d, tempbl, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001904
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301905 if (!(pVBInfo->SetFlag & ReserveTVOption))
Aaro Koskinen8104e322011-03-13 12:26:22 +02001906 xgifb_reg_set(pVBInfo->P3d4, 0x3e, tempch);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301907 } else {
1908 return;
1909 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001910}
1911
Bill Pemberton80adad82010-06-17 13:10:51 -04001912void XGI_GetVBType(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001913{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301914 unsigned short flag, tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001915
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001916 if (pVBInfo->IF_DEF_LVDS != 0)
1917 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001918
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001919 tempbx = VB_SIS302B;
1920 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
1921 if (flag == 0x02)
1922 goto finish;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001923
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001924 tempbx = VB_SIS301;
1925 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x01);
1926 if (flag < 0xB0)
1927 goto finish;
1928
1929 tempbx = VB_SIS301B;
1930 if (flag < 0xC0)
1931 goto bigger_than_0xB0;
1932
1933 tempbx = VB_XGI301C;
1934 if (flag < 0xD0)
1935 goto bigger_than_0xB0;
1936
1937 tempbx = VB_SIS301LV;
1938 if (flag < 0xE0)
1939 goto bigger_than_0xB0;
1940
1941 tempbx = VB_SIS302LV;
1942 tempah = xgifb_reg_get(pVBInfo->Part4Port, 0x39);
1943 if (tempah != 0xFF)
1944 tempbx = VB_XGI301C;
1945
1946bigger_than_0xB0:
1947 if (tempbx & (VB_SIS301B | VB_SIS302B)) {
1948 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x23);
1949 if (!(flag & 0x02))
1950 tempbx = tempbx | VB_NoLCD;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301951 }
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001952
1953finish:
1954 pVBInfo->VBType = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001955}
1956
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02001957static void XGI_GetVBInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301958 struct xgi_hw_device_info *HwDeviceExtension,
1959 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001960{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301961 unsigned short tempax, push, tempbx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001962
Aaro Koskinenb3979922012-11-04 21:14:52 +02001963 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301964 pVBInfo->SetFlag = 0;
Peter Huewe6896b942012-02-09 21:11:46 +01001965 pVBInfo->ModeType = modeflag & ModeTypeMask;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301966 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001967
Miguel Gómezf9317352012-07-06 12:40:48 +02001968 if (!(pVBInfo->VBType & 0xFFFF))
1969 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001970
Miguel Gómezf9317352012-07-06 12:40:48 +02001971 /* Check Display Device */
1972 temp = xgifb_reg_get(pVBInfo->P3d4, 0x30);
1973 tempbx = tempbx | temp;
1974 temp = xgifb_reg_get(pVBInfo->P3d4, 0x31);
1975 push = temp;
1976 push = push << 8;
1977 tempax = temp << 8;
1978 tempbx = tempbx | tempax;
1979 temp = (SetCRT2ToDualEdge | SetCRT2ToYPbPr525750 | XGI_SetCRT2ToLCDA
1980 | SetInSlaveMode | DisableCRT2Display);
1981 temp = 0xFFFF ^ temp;
1982 tempbx &= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001983
Miguel Gómezf9317352012-07-06 12:40:48 +02001984 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001985
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001986 if (pVBInfo->VBType & (VB_SIS302B | VB_SIS301LV | VB_SIS302LV |
1987 VB_XGI301C)) {
1988 if (temp & EnableDualEdge) {
1989 tempbx |= SetCRT2ToDualEdge;
1990 if (temp & SetToLCDA)
1991 tempbx |= XGI_SetCRT2ToLCDA;
Miguel Gómezf9317352012-07-06 12:40:48 +02001992 }
1993 }
1994
1995 if (pVBInfo->IF_DEF_YPbPr == 1) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001996 if (pVBInfo->VBType & (VB_SIS301LV|VB_SIS302LV|VB_XGI301C)) {
Miguel Gómezf9317352012-07-06 12:40:48 +02001997 if (temp & SetYPbPr) {
1998 if (pVBInfo->IF_DEF_HiVision == 1) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001999 /* shampoo add for new scratch */
2000 temp = xgifb_reg_get(pVBInfo->P3d4,
2001 0x35);
Miguel Gómezf9317352012-07-06 12:40:48 +02002002 temp &= YPbPrMode;
2003 tempbx |= SetCRT2ToHiVision;
2004
2005 if (temp != YPbPrMode1080i) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002006 tempbx &= (~SetCRT2ToHiVision);
2007 tempbx |= SetCRT2ToYPbPr525750;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302008 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302009 }
2010 }
2011 }
Miguel Gómezf9317352012-07-06 12:40:48 +02002012 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002013
Miguel Gómezf9317352012-07-06 12:40:48 +02002014 tempax = push; /* restore CR31 */
2015
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002016 if (pVBInfo->IF_DEF_YPbPr == 1) {
2017 if (pVBInfo->IF_DEF_HiVision == 1)
2018 temp = 0x09FC;
2019 else
2020 temp = 0x097C;
2021 } else if (pVBInfo->IF_DEF_HiVision == 1) {
2022 temp = 0x01FC;
2023 } else {
2024 temp = 0x017C;
Miguel Gómezf9317352012-07-06 12:40:48 +02002025 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002026
Miguel Gómezf9317352012-07-06 12:40:48 +02002027 if (!(tempbx & temp)) {
2028 tempax |= DisableCRT2Display;
2029 tempbx = 0;
2030 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002031
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03002032 if (!(pVBInfo->VBType & VB_NoLCD)) {
2033 if (tempbx & XGI_SetCRT2ToLCDA) {
2034 if (tempbx & SetSimuScanMode)
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002035 tempbx &= (~(SetCRT2ToLCD | SetCRT2ToRAMDAC |
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03002036 SwitchCRT2));
2037 else
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002038 tempbx &= (~(SetCRT2ToLCD | SetCRT2ToRAMDAC |
2039 SetCRT2ToTV | SwitchCRT2));
Miguel Gómezf9317352012-07-06 12:40:48 +02002040 }
2041 }
2042
2043 /* shampoo add */
2044 /* for driver abnormal */
2045 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode))) {
2046 if (pVBInfo->IF_DEF_CRT2Monitor == 1) {
2047 if (tempbx & SetCRT2ToRAMDAC) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002048 tempbx &= (0xFF00 | SetCRT2ToRAMDAC |
2049 SwitchCRT2 | SetSimuScanMode);
Peter Huewe599801f2012-02-09 21:11:45 +01002050 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302051 }
Miguel Gómezf9317352012-07-06 12:40:48 +02002052 } else {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002053 tempbx &= (~(SetCRT2ToRAMDAC | SetCRT2ToLCD |
Miguel Gómezf9317352012-07-06 12:40:48 +02002054 SetCRT2ToTV));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302055 }
Miguel Gómezf9317352012-07-06 12:40:48 +02002056 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002057
Miguel Gómezf9317352012-07-06 12:40:48 +02002058 if (!(pVBInfo->VBType & VB_NoLCD)) {
2059 if (tempbx & SetCRT2ToLCD) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002060 tempbx &= (0xFF00 | SetCRT2ToLCD | SwitchCRT2 |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002061 SetSimuScanMode);
Peter Huewe599801f2012-02-09 21:11:45 +01002062 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302063 }
Miguel Gómezf9317352012-07-06 12:40:48 +02002064 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002065
Miguel Gómezf9317352012-07-06 12:40:48 +02002066 if (tempbx & SetCRT2ToSCART) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002067 tempbx &= (0xFF00 | SetCRT2ToSCART | SwitchCRT2 |
Miguel Gómezf9317352012-07-06 12:40:48 +02002068 SetSimuScanMode);
2069 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
2070 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002071
Miguel Gómezf9317352012-07-06 12:40:48 +02002072 if (pVBInfo->IF_DEF_YPbPr == 1) {
2073 if (tempbx & SetCRT2ToYPbPr525750)
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002074 tempbx &= (0xFF00 | SwitchCRT2 | SetSimuScanMode);
Miguel Gómezf9317352012-07-06 12:40:48 +02002075 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002076
Miguel Gómezf9317352012-07-06 12:40:48 +02002077 if (pVBInfo->IF_DEF_HiVision == 1) {
2078 if (tempbx & SetCRT2ToHiVision)
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002079 tempbx &= (0xFF00 | SetCRT2ToHiVision | SwitchCRT2 |
Miguel Gómezf9317352012-07-06 12:40:48 +02002080 SetSimuScanMode);
2081 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002082
Miguel Gómezf9317352012-07-06 12:40:48 +02002083 if (tempax & DisableCRT2Display) { /* Set Display Device Info */
2084 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode)))
2085 tempbx = DisableCRT2Display;
2086 }
2087
2088 if (!(tempbx & DisableCRT2Display)) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002089 if ((!(tempbx & DriverMode)) || (!(modeflag & CRT2Mode))) {
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03002090 if (!(tempbx & XGI_SetCRT2ToLCDA))
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002091 tempbx |= (SetInSlaveMode | SetSimuScanMode);
Miguel Gómezf9317352012-07-06 12:40:48 +02002092 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002093
Miguel Gómezf9317352012-07-06 12:40:48 +02002094 /* LCD+TV can't support in slave mode
2095 * (Force LCDA+TV->LCDB) */
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002096 if ((tempbx & SetInSlaveMode) && (tempbx & XGI_SetCRT2ToLCDA)) {
2097 tempbx ^= (SetCRT2ToLCD | XGI_SetCRT2ToLCDA |
Miguel Gómezf9317352012-07-06 12:40:48 +02002098 SetCRT2ToDualEdge);
2099 pVBInfo->SetFlag |= ReserveTVOption;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302100 }
2101 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002102
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302103 pVBInfo->VBInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002104}
2105
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02002106static void XGI_GetTVInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302107 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002108{
Peter Huewe5fc699f2013-02-03 04:08:45 +01002109 unsigned short tempbx = 0, resinfo = 0, modeflag, index1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002110
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302111 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinenb3979922012-11-04 21:14:52 +02002112 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2113 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002114
Peter Huewe5fc699f2013-02-03 04:08:45 +01002115 tempbx = xgifb_reg_get(pVBInfo->P3d4, 0x35);
2116 if (tempbx & TVSetPAL) {
2117 tempbx &= (SetCHTVOverScan |
2118 TVSetPALM |
2119 TVSetPALN |
2120 TVSetPAL);
2121 if (tempbx & TVSetPALM)
2122 /* set to NTSC if PAL-M */
2123 tempbx &= ~TVSetPAL;
2124 } else
2125 tempbx &= (SetCHTVOverScan |
2126 TVSetNTSCJ |
2127 TVSetPAL);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002128
Aaro Koskinena8b35292013-02-09 00:03:45 +02002129 if (pVBInfo->VBInfo & SetCRT2ToSCART)
2130 tempbx |= TVSetPAL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002131
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302132 if (pVBInfo->IF_DEF_YPbPr == 1) {
Peter Huewe599801f2012-02-09 21:11:45 +01002133 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002134 index1 = xgifb_reg_get(pVBInfo->P3d4, 0x35);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302135 index1 &= YPbPrMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002136
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302137 if (index1 == YPbPrMode525i)
Peter Huewe599801f2012-02-09 21:11:45 +01002138 tempbx |= TVSetYPbPr525i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002139
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302140 if (index1 == YPbPrMode525p)
Peter Huewe599801f2012-02-09 21:11:45 +01002141 tempbx = tempbx | TVSetYPbPr525p;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302142 if (index1 == YPbPrMode750p)
Peter Huewe599801f2012-02-09 21:11:45 +01002143 tempbx = tempbx | TVSetYPbPr750p;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302144 }
2145 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002146
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302147 if (pVBInfo->IF_DEF_HiVision == 1) {
Peter Huewe599801f2012-02-09 21:11:45 +01002148 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
2149 tempbx = tempbx | TVSetHiVision | TVSetPAL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302150 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002151
Aaro Koskinena8b35292013-02-09 00:03:45 +02002152 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
2153 (!(pVBInfo->VBInfo & SetNotSimuMode)))
2154 tempbx |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002155
Aaro Koskinena8b35292013-02-09 00:03:45 +02002156 if (!(tempbx & TVSetPAL) && (modeflag > 13) && (resinfo == 8))
2157 /* NTSC 1024x768, */
2158 tempbx |= NTSC1024x768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002159
Aaro Koskinena8b35292013-02-09 00:03:45 +02002160 tempbx |= RPLLDIV2XO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002161
Aaro Koskinena8b35292013-02-09 00:03:45 +02002162 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
2163 if (pVBInfo->VBInfo & SetInSlaveMode)
2164 tempbx &= (~RPLLDIV2XO);
2165 } else if (tempbx & (TVSetYPbPr525p | TVSetYPbPr750p)) {
2166 tempbx &= (~RPLLDIV2XO);
2167 } else if (!(pVBInfo->VBType & (VB_SIS301B | VB_SIS302B |
2168 VB_SIS301LV | VB_SIS302LV |
2169 VB_XGI301C))) {
2170 if (tempbx & TVSimuMode)
2171 tempbx &= (~RPLLDIV2XO);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302172 }
2173 }
2174 pVBInfo->TVInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002175}
2176
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02002177static unsigned char XGI_GetLCDInfo(unsigned short ModeNo,
2178 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002179{
Peter Hueweef9a6b92013-02-03 04:08:43 +01002180 unsigned short temp, tempax, tempbx, resinfo = 0, LCDIdIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002181
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302182 pVBInfo->LCDResInfo = 0;
2183 pVBInfo->LCDTypeInfo = 0;
2184 pVBInfo->LCDInfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002185
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002186 /* si+Ext_ResInfo // */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002187 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinen58839b02011-03-13 12:26:23 +02002188 temp = xgifb_reg_get(pVBInfo->P3d4, 0x36); /* Get LCD Res.Info */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302189 tempbx = temp & 0x0F;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002190
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302191 if (tempbx == 0)
Peter Huewe255aabd2012-02-09 21:11:44 +01002192 tempbx = Panel_1024x768; /* default */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002193
Miguel Gómez949eb0a2012-07-06 12:40:36 +02002194 /* LCD75 */
Peter Huewe255aabd2012-02-09 21:11:44 +01002195 if ((tempbx == Panel_1024x768) || (tempbx == Panel_1280x1024)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302196 if (pVBInfo->VBInfo & DriverMode) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002197 tempax = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Peter Huewea3d675c2012-02-09 21:11:47 +01002198 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302199 tempax &= 0x0F;
2200 else
2201 tempax = tempax >> 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002202
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302203 if ((resinfo == 6) || (resinfo == 9)) {
2204 if (tempax >= 3)
2205 tempbx |= PanelRef75Hz;
2206 } else if ((resinfo == 7) || (resinfo == 8)) {
2207 if (tempax >= 4)
2208 tempbx |= PanelRef75Hz;
2209 }
2210 }
2211 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002212
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302213 pVBInfo->LCDResInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002214
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302215 /* End of LCD75 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002216
Peter Huewea3d675c2012-02-09 21:11:47 +01002217 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302218 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002219
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302220 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002221
Aaro Koskinen58839b02011-03-13 12:26:23 +02002222 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002223
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302224 temp &= (ScalingLCD | LCDNonExpanding | LCDSyncBit | SetPWDEnable);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002225
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302226 tempbx |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002227
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302228 LCDIdIndex = XGI_GetLCDCapPtr1(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002229
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302230 tempax = pVBInfo->LCDCapList[LCDIdIndex].LCD_Capability;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002231
Aaro Koskinen718e7152013-02-09 00:03:46 +02002232 if (((pVBInfo->VBType & VB_SIS302LV) ||
2233 (pVBInfo->VBType & VB_XGI301C)) && (tempax & XGI_LCDDualLink))
2234 tempbx |= SetLCDDualLink;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002235
Aaro Koskinen718e7152013-02-09 00:03:46 +02002236 if ((pVBInfo->LCDResInfo == Panel_1400x1050) &&
2237 (pVBInfo->VBInfo & SetCRT2ToLCD) && (resinfo == 9) &&
2238 (!(tempbx & EnableScalingLCD)))
2239 /*
2240 * set to center in 1280x1024 LCDB
2241 * for Panel_1400x1050
2242 */
2243 tempbx |= SetLCDtoNonExpanding;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002244
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302245 if (pVBInfo->VBInfo & SetInSlaveMode) {
2246 if (pVBInfo->VBInfo & SetNotSimuMode)
Peter Huewea3d675c2012-02-09 21:11:47 +01002247 tempbx |= XGI_LCDVESATiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302248 } else {
Peter Huewea3d675c2012-02-09 21:11:47 +01002249 tempbx |= XGI_LCDVESATiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302250 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002251
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302252 pVBInfo->LCDInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002253
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302254 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002255}
2256
Bill Pemberton108afbf2010-06-17 13:10:47 -04002257unsigned char XGI_SearchModeID(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302258 unsigned short *ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002259{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002260 for (*ModeIdIndex = 0;; (*ModeIdIndex)++) {
Aaro Koskinenb3979922012-11-04 21:14:52 +02002261 if (XGI330_EModeIDTable[*ModeIdIndex].Ext_ModeID == ModeNo)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002262 break;
Aaro Koskinenb3979922012-11-04 21:14:52 +02002263 if (XGI330_EModeIDTable[*ModeIdIndex].Ext_ModeID == 0xFF)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002264 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302265 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002266
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302267 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002268}
2269
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002270static unsigned char XG21GPIODataTransfer(unsigned char ujDate)
2271{
2272 unsigned char ujRet = 0;
2273 unsigned char i = 0;
2274
2275 for (i = 0; i < 8; i++) {
2276 ujRet = ujRet << 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002277 ujRet |= (ujDate >> i) & 1;
2278 }
2279
2280 return ujRet;
2281}
2282
2283/*----------------------------------------------------------------------------*/
2284/* output */
2285/* bl[5] : LVDS signal */
2286/* bl[1] : LVDS backlight */
2287/* bl[0] : LVDS VDD */
2288/*----------------------------------------------------------------------------*/
2289static unsigned char XGI_XG21GetPSCValue(struct vb_device_info *pVBInfo)
2290{
2291 unsigned char CR4A, temp;
2292
Aaro Koskinen58839b02011-03-13 12:26:23 +02002293 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02002294 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x23); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002295
Aaro Koskinen58839b02011-03-13 12:26:23 +02002296 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002297
2298 temp = XG21GPIODataTransfer(temp);
2299 temp &= 0x23;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002300 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002301 return temp;
2302}
2303
2304/*----------------------------------------------------------------------------*/
2305/* output */
2306/* bl[5] : LVDS signal */
2307/* bl[1] : LVDS backlight */
2308/* bl[0] : LVDS VDD */
2309/*----------------------------------------------------------------------------*/
2310static unsigned char XGI_XG27GetPSCValue(struct vb_device_info *pVBInfo)
2311{
2312 unsigned char CR4A, CRB4, temp;
2313
Aaro Koskinen58839b02011-03-13 12:26:23 +02002314 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02002315 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x0C); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002316
Aaro Koskinen58839b02011-03-13 12:26:23 +02002317 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002318
2319 temp &= 0x0C;
2320 temp >>= 2;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002321 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinen58839b02011-03-13 12:26:23 +02002322 CRB4 = xgifb_reg_get(pVBInfo->P3d4, 0xB4);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002323 temp |= ((CRB4 & 0x04) << 3);
2324 return temp;
2325}
2326
Aaro Koskinen0ebf5382011-11-27 23:03:09 +02002327/*----------------------------------------------------------------------------*/
2328/* input */
2329/* bl[5] : 1;LVDS signal on */
2330/* bl[1] : 1;LVDS backlight on */
2331/* bl[0] : 1:LVDS VDD on */
2332/* bh: 100000b : clear bit 5, to set bit5 */
2333/* 000010b : clear bit 1, to set bit1 */
2334/* 000001b : clear bit 0, to set bit0 */
2335/*----------------------------------------------------------------------------*/
2336static void XGI_XG21BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
2337 struct vb_device_info *pVBInfo)
2338{
2339 unsigned char CR4A, temp;
2340
2341 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
2342 tempbh &= 0x23;
2343 tempbl &= 0x23;
2344 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
2345
2346 if (tempbh & 0x20) {
2347 temp = (tempbl >> 4) & 0x02;
2348
2349 /* CR B4[1] */
2350 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
2351
2352 }
2353
2354 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
2355
2356 temp = XG21GPIODataTransfer(temp);
2357 temp &= ~tempbh;
2358 temp |= tempbl;
2359 xgifb_reg_set(pVBInfo->P3d4, 0x48, temp);
2360}
2361
Aaro Koskinen776115a2011-11-27 23:03:10 +02002362static void XGI_XG27BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
2363 struct vb_device_info *pVBInfo)
2364{
2365 unsigned char CR4A, temp;
2366 unsigned short tempbh0, tempbl0;
2367
2368 tempbh0 = tempbh;
2369 tempbl0 = tempbl;
2370 tempbh0 &= 0x20;
2371 tempbl0 &= 0x20;
2372 tempbh0 >>= 3;
2373 tempbl0 >>= 3;
2374
2375 if (tempbh & 0x20) {
2376 temp = (tempbl >> 4) & 0x02;
2377
2378 /* CR B4[1] */
2379 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
2380
2381 }
2382 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~tempbh0, tempbl0);
2383
2384 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
2385 tempbh &= 0x03;
2386 tempbl &= 0x03;
2387 tempbh <<= 2;
2388 tempbl <<= 2; /* GPIOC,GPIOD */
2389 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
2390 xgifb_reg_and_or(pVBInfo->P3d4, 0x48, ~tempbh, tempbl);
2391}
2392
Aaro Koskinenfab04b92011-12-06 00:10:45 +02002393static void XGI_DisplayOn(struct xgifb_video_info *xgifb_info,
2394 struct xgi_hw_device_info *pXGIHWDE,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302395 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002396{
2397
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002398 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302399 if (pXGIHWDE->jChipType == XG21) {
2400 if (pVBInfo->IF_DEF_LVDS == 1) {
2401 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002402 /* LVDS VDD on */
2403 XGI_XG21BLSignalVDD(0x01, 0x01, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002404 mdelay(xgifb_info->lvds_data.PSC_S2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302405 }
2406 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002407 /* LVDS signal on */
2408 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002409 mdelay(xgifb_info->lvds_data.PSC_S3);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002410 /* LVDS backlight on */
2411 XGI_XG21BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302412 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002413 /* DVO/DVI signal on */
2414 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302415 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002416
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302417 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002418
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302419 if (pXGIHWDE->jChipType == XG27) {
2420 if (pVBInfo->IF_DEF_LVDS == 1) {
2421 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002422 /* LVDS VDD on */
2423 XGI_XG27BLSignalVDD(0x01, 0x01, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002424 mdelay(xgifb_info->lvds_data.PSC_S2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302425 }
2426 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002427 /* LVDS signal on */
2428 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002429 mdelay(xgifb_info->lvds_data.PSC_S3);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002430 /* LVDS backlight on */
2431 XGI_XG27BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302432 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002433 /* DVO/DVI signal on */
2434 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302435 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002436
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302437 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002438}
2439
Aaro Koskinenfab04b92011-12-06 00:10:45 +02002440void XGI_DisplayOff(struct xgifb_video_info *xgifb_info,
2441 struct xgi_hw_device_info *pXGIHWDE,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302442 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002443{
2444
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302445 if (pXGIHWDE->jChipType == XG21) {
2446 if (pVBInfo->IF_DEF_LVDS == 1) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002447 /* LVDS backlight off */
2448 XGI_XG21BLSignalVDD(0x02, 0x00, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002449 mdelay(xgifb_info->lvds_data.PSC_S3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302450 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002451 /* DVO/DVI signal off */
2452 XGI_XG21BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302453 }
2454 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002455
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302456 if (pXGIHWDE->jChipType == XG27) {
2457 if ((XGI_XG27GetPSCValue(pVBInfo) & 0x2)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002458 /* LVDS backlight off */
2459 XGI_XG27BLSignalVDD(0x02, 0x00, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002460 mdelay(xgifb_info->lvds_data.PSC_S3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302461 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002462
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302463 if (pVBInfo->IF_DEF_LVDS == 0)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002464 /* DVO/DVI signal off */
2465 XGI_XG27BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302466 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002467
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002468 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x20);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002469}
2470
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002471static void XGI_WaitDisply(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002472{
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02002473 while ((inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302474 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002475
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02002476 while (!(inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302477 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002478}
2479
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002480static void XGI_AutoThreshold(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002481{
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002482 xgifb_reg_or(pVBInfo->Part1Port, 0x01, 0x40);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002483}
2484
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002485static void XGI_SaveCRT2Info(unsigned short ModeNo,
2486 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002487{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302488 unsigned short temp1, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002489
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002490 /* reserve CR34 for CRT1 Mode No */
2491 xgifb_reg_set(pVBInfo->P3d4, 0x34, ModeNo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302492 temp1 = (pVBInfo->VBInfo & SetInSlaveMode) >> 8;
2493 temp2 = ~(SetInSlaveMode >> 8);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002494 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, temp2, temp1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002495}
2496
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002497static void XGI_GetCRT2ResInfo(unsigned short ModeNo,
2498 unsigned short ModeIdIndex,
2499 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002500{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302501 unsigned short xres, yres, modeflag, resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002502
Aaro Koskinenb3979922012-11-04 21:14:52 +02002503 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02002504 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
2505 yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002506 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002507 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002508
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002509 if (modeflag & HalfDCLK)
2510 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002511
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002512 if (modeflag & DoubleScanMode)
2513 yres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002514
Miguel Gómez3339db82012-07-06 12:40:49 +02002515 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
2516 goto exit;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002517
Aaro Koskinen22006832013-02-09 00:03:47 +02002518 if (pVBInfo->LCDResInfo == Panel_1600x1200) {
2519 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
2520 if (yres == 1024)
2521 yres = 1056;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302522 }
Aaro Koskinen22006832013-02-09 00:03:47 +02002523 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002524
Aaro Koskinen22006832013-02-09 00:03:47 +02002525 if (pVBInfo->LCDResInfo == Panel_1280x1024) {
2526 if (yres == 400)
2527 yres = 405;
2528 else if (yres == 350)
2529 yres = 360;
Miguel Gómez3339db82012-07-06 12:40:49 +02002530
Aaro Koskinen22006832013-02-09 00:03:47 +02002531 if (pVBInfo->LCDInfo & XGI_LCDVESATiming) {
2532 if (yres == 360)
2533 yres = 375;
Miguel Gómez3339db82012-07-06 12:40:49 +02002534 }
Aaro Koskinen22006832013-02-09 00:03:47 +02002535 }
Miguel Gómez3339db82012-07-06 12:40:49 +02002536
Aaro Koskinen22006832013-02-09 00:03:47 +02002537 if (pVBInfo->LCDResInfo == Panel_1024x768) {
2538 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
2539 if (!(pVBInfo->LCDInfo & LCDNonExpanding)) {
2540 if (yres == 350)
2541 yres = 357;
2542 else if (yres == 400)
2543 yres = 420;
2544 else if (yres == 480)
2545 yres = 525;
Miguel Gómez3339db82012-07-06 12:40:49 +02002546 }
2547 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302548 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002549
Miguel Gómez3339db82012-07-06 12:40:49 +02002550 if (xres == 720)
2551 xres = 640;
2552
2553exit:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302554 pVBInfo->VGAHDE = xres;
2555 pVBInfo->HDE = xres;
2556 pVBInfo->VGAVDE = yres;
2557 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002558}
2559
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002560static unsigned char XGI_IsLCDDualLink(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002561{
2562
Peter Huewea3d675c2012-02-09 21:11:47 +01002563 if ((pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) &&
Dan Carpentera65fd092011-01-04 09:02:27 +03002564 (pVBInfo->LCDInfo & SetLCDDualLink)) /* shampoo0129 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302565 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002566
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302567 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002568}
2569
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002570static void XGI_GetRAMDAC2DATA(unsigned short ModeNo,
2571 unsigned short ModeIdIndex,
2572 unsigned short RefreshRateTableIndex,
2573 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002574{
2575 unsigned short tempax, tempbx, temp1, temp2, modeflag = 0, tempcx,
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002576 CRT1Index;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002577
2578 pVBInfo->RVBHCMAX = 1;
2579 pVBInfo->RVBHCFACT = 1;
Aaro Koskinenb3979922012-11-04 21:14:52 +02002580 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02002581 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002582 CRT1Index &= IndexMask;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002583 temp1 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[0];
2584 temp2 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[5];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002585 tempax = (temp1 & 0xFF) | ((temp2 & 0x03) << 8);
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002586 tempbx = (unsigned short) XGI_CRT1Table[CRT1Index].CR[8];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002587 tempcx = (unsigned short)
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002588 XGI_CRT1Table[CRT1Index].CR[14] << 8;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002589 tempcx &= 0x0100;
2590 tempcx = tempcx << 2;
2591 tempbx |= tempcx;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002592 temp1 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[9];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002593
2594 if (temp1 & 0x01)
2595 tempbx |= 0x0100;
2596
2597 if (temp1 & 0x20)
2598 tempbx |= 0x0200;
2599 tempax += 5;
2600
2601 if (modeflag & Charx8Dot)
2602 tempax *= 8;
2603 else
2604 tempax *= 9;
2605
2606 pVBInfo->VGAHT = tempax;
2607 pVBInfo->HT = tempax;
2608 tempbx++;
2609 pVBInfo->VGAVT = tempbx;
2610 pVBInfo->VT = tempbx;
2611}
2612
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002613static void XGI_GetCRT2Data(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302614 unsigned short RefreshRateTableIndex,
2615 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002616{
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02002617 unsigned short tempax = 0, tempbx = 0, modeflag, resinfo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002618
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02002619 struct SiS_LCDData const *LCDPtr = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002620
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002621 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002622 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2623 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302624 pVBInfo->NewFlickerMode = 0;
2625 pVBInfo->RVBHRS = 50;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002626
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302627 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
2628 XGI_GetRAMDAC2DATA(ModeNo, ModeIdIndex, RefreshRateTableIndex,
2629 pVBInfo);
2630 return;
2631 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002632
Peter Huewea3d675c2012-02-09 21:11:47 +01002633 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02002634 LCDPtr = XGI_GetLcdPtr(XGI_LCDDataTable, ModeNo, ModeIdIndex,
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +03002635 RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002636
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302637 pVBInfo->RVBHCMAX = LCDPtr->RVBHCMAX;
2638 pVBInfo->RVBHCFACT = LCDPtr->RVBHCFACT;
2639 pVBInfo->VGAHT = LCDPtr->VGAHT;
2640 pVBInfo->VGAVT = LCDPtr->VGAVT;
2641 pVBInfo->HT = LCDPtr->LCDHT;
2642 pVBInfo->VT = LCDPtr->LCDVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002643
Peter Huewe255aabd2012-02-09 21:11:44 +01002644 if (pVBInfo->LCDResInfo == Panel_1024x768) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302645 tempax = 1024;
2646 tempbx = 768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002647
Peter Huewea3d675c2012-02-09 21:11:47 +01002648 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302649 if (pVBInfo->VGAVDE == 357)
2650 tempbx = 527;
2651 else if (pVBInfo->VGAVDE == 420)
2652 tempbx = 620;
2653 else if (pVBInfo->VGAVDE == 525)
2654 tempbx = 775;
2655 else if (pVBInfo->VGAVDE == 600)
2656 tempbx = 775;
Peter Huewe7580d7f2013-05-18 00:19:54 +02002657 }
Peter Huewe255aabd2012-02-09 21:11:44 +01002658 } else if (pVBInfo->LCDResInfo == Panel_1024x768x75) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302659 tempax = 1024;
2660 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01002661 } else if (pVBInfo->LCDResInfo == Panel_1280x1024) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302662 tempax = 1280;
2663 if (pVBInfo->VGAVDE == 360)
2664 tempbx = 768;
2665 else if (pVBInfo->VGAVDE == 375)
2666 tempbx = 800;
2667 else if (pVBInfo->VGAVDE == 405)
2668 tempbx = 864;
2669 else
2670 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01002671 } else if (pVBInfo->LCDResInfo == Panel_1280x1024x75) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302672 tempax = 1280;
2673 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01002674 } else if (pVBInfo->LCDResInfo == Panel_1280x960) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302675 tempax = 1280;
2676 if (pVBInfo->VGAVDE == 350)
2677 tempbx = 700;
2678 else if (pVBInfo->VGAVDE == 400)
2679 tempbx = 800;
2680 else if (pVBInfo->VGAVDE == 1024)
2681 tempbx = 960;
2682 else
2683 tempbx = 960;
Peter Huewe255aabd2012-02-09 21:11:44 +01002684 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302685 tempax = 1400;
2686 tempbx = 1050;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002687
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302688 if (pVBInfo->VGAVDE == 1024) {
2689 tempax = 1280;
2690 tempbx = 1024;
2691 }
Peter Huewe255aabd2012-02-09 21:11:44 +01002692 } else if (pVBInfo->LCDResInfo == Panel_1600x1200) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302693 tempax = 1600;
2694 tempbx = 1200; /* alan 10/14/2003 */
Peter Huewea3d675c2012-02-09 21:11:47 +01002695 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302696 if (pVBInfo->VGAVDE == 350)
2697 tempbx = 875;
2698 else if (pVBInfo->VGAVDE == 400)
2699 tempbx = 1000;
2700 }
2701 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002702
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302703 if (pVBInfo->LCDInfo & LCDNonExpanding) {
2704 tempax = pVBInfo->VGAHDE;
2705 tempbx = pVBInfo->VGAVDE;
2706 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002707
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302708 pVBInfo->HDE = tempax;
2709 pVBInfo->VDE = tempbx;
2710 return;
2711 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002712
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302713 if (pVBInfo->VBInfo & (SetCRT2ToTV)) {
Aaro Koskinen24572542012-09-11 00:15:21 +03002714 struct SiS_TVData const *TVPtr;
2715
2716 TVPtr = XGI_GetTVPtr(ModeNo, ModeIdIndex, RefreshRateTableIndex,
2717 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002718
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302719 pVBInfo->RVBHCMAX = TVPtr->RVBHCMAX;
2720 pVBInfo->RVBHCFACT = TVPtr->RVBHCFACT;
2721 pVBInfo->VGAHT = TVPtr->VGAHT;
2722 pVBInfo->VGAVT = TVPtr->VGAVT;
2723 pVBInfo->HDE = TVPtr->TVHDE;
2724 pVBInfo->VDE = TVPtr->TVVDE;
2725 pVBInfo->RVBHRS = TVPtr->RVBHRS;
2726 pVBInfo->NewFlickerMode = TVPtr->FlickerMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002727
Peter Huewe599801f2012-02-09 21:11:45 +01002728 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302729 if (resinfo == 0x08)
2730 pVBInfo->NewFlickerMode = 0x40;
2731 else if (resinfo == 0x09)
2732 pVBInfo->NewFlickerMode = 0x40;
2733 else if (resinfo == 0x12)
2734 pVBInfo->NewFlickerMode = 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002735
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302736 if (pVBInfo->VGAVDE == 350)
2737 pVBInfo->TVInfo |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002738
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302739 tempax = ExtHiTVHT;
2740 tempbx = ExtHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002741
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302742 if (pVBInfo->VBInfo & SetInSlaveMode) {
2743 if (pVBInfo->TVInfo & TVSimuMode) {
2744 tempax = StHiTVHT;
2745 tempbx = StHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002746
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302747 if (!(modeflag & Charx8Dot)) {
2748 tempax = StHiTextTVHT;
2749 tempbx = StHiTextTVVT;
2750 }
2751 }
2752 }
Peter Huewe599801f2012-02-09 21:11:45 +01002753 } else if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
2754 if (pVBInfo->TVInfo & TVSetYPbPr750p) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302755 tempax = YPbPrTV750pHT; /* Ext750pTVHT */
2756 tempbx = YPbPrTV750pVT; /* Ext750pTVVT */
2757 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002758
Peter Huewe599801f2012-02-09 21:11:45 +01002759 if (pVBInfo->TVInfo & TVSetYPbPr525p) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302760 tempax = YPbPrTV525pHT; /* Ext525pTVHT */
2761 tempbx = YPbPrTV525pVT; /* Ext525pTVVT */
Peter Huewe599801f2012-02-09 21:11:45 +01002762 } else if (pVBInfo->TVInfo & TVSetYPbPr525i) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302763 tempax = YPbPrTV525iHT; /* Ext525iTVHT */
2764 tempbx = YPbPrTV525iVT; /* Ext525iTVVT */
2765 if (pVBInfo->TVInfo & NTSC1024x768)
2766 tempax = NTSC1024x768HT;
2767 }
2768 } else {
2769 tempax = PALHT;
2770 tempbx = PALVT;
Peter Huewe599801f2012-02-09 21:11:45 +01002771 if (!(pVBInfo->TVInfo & TVSetPAL)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302772 tempax = NTSCHT;
2773 tempbx = NTSCVT;
2774 if (pVBInfo->TVInfo & NTSC1024x768)
2775 tempax = NTSC1024x768HT;
2776 }
2777 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002778
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302779 pVBInfo->HT = tempax;
2780 pVBInfo->VT = tempbx;
2781 return;
2782 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002783}
2784
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002785static void XGI_SetCRT2VCLK(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302786 unsigned short RefreshRateTableIndex,
2787 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002788{
Bill Pemberton108afbf2010-06-17 13:10:47 -04002789 unsigned char di_0, di_1, tempal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002790
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302791 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
2792 pVBInfo);
2793 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
2794 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002795
Peter Huewe6896b942012-02-09 21:11:46 +01002796 if (pVBInfo->VBType & VB_SIS301) { /* shampoo 0129 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302797 /* 301 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002798 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, 0x10);
2799 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
2800 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302801 } else { /* 301b/302b/301lv/302lv */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002802 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
2803 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302804 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002805
Aaro Koskinen8104e322011-03-13 12:26:22 +02002806 xgifb_reg_set(pVBInfo->Part4Port, 0x00, 0x12);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002807
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302808 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02002809 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x28);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302810 else
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02002811 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002812}
2813
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002814static unsigned short XGI_GetColorDepth(unsigned short ModeNo,
2815 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002816{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002817 unsigned short ColorDepth[6] = { 1, 2, 4, 4, 6, 8 };
2818 short index;
2819 unsigned short modeflag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302820
Aaro Koskinenb3979922012-11-04 21:14:52 +02002821 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Peter Huewe6896b942012-02-09 21:11:46 +01002822 index = (modeflag & ModeTypeMask) - ModeEGA;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302823
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002824 if (index < 0)
2825 index = 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302826
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002827 return ColorDepth[index];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302828}
2829
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002830static unsigned short XGI_GetOffset(unsigned short ModeNo,
2831 unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302832 unsigned short RefreshRateTableIndex,
2833 struct xgi_hw_device_info *HwDeviceExtension,
2834 struct vb_device_info *pVBInfo)
2835{
2836 unsigned short temp, colordepth, modeinfo, index, infoflag,
2837 ColorDepth[] = { 0x01, 0x02, 0x04 };
2838
Aaro Koskinenb3979922012-11-04 21:14:52 +02002839 modeinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeInfo;
Aaro Koskinena39325d2012-11-04 21:14:53 +02002840 infoflag = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302841
2842 index = (modeinfo >> 8) & 0xFF;
2843
Aaro Koskinen224114c2012-11-04 21:14:59 +02002844 temp = XGI330_ScreenOffset[index];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302845
2846 if (infoflag & InterlaceMode)
2847 temp = temp << 1;
2848
2849 colordepth = XGI_GetColorDepth(ModeNo, ModeIdIndex, pVBInfo);
2850
2851 if ((ModeNo >= 0x7C) && (ModeNo <= 0x7E)) {
2852 temp = ModeNo - 0x7C;
2853 colordepth = ColorDepth[temp];
2854 temp = 0x6B;
2855 if (infoflag & InterlaceMode)
2856 temp = temp << 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302857 }
Peter Huewe053004b2013-02-15 20:37:12 +01002858 return temp * colordepth;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302859}
2860
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002861static void XGI_SetCRT2Offset(unsigned short ModeNo,
2862 unsigned short ModeIdIndex,
2863 unsigned short RefreshRateTableIndex,
2864 struct xgi_hw_device_info *HwDeviceExtension,
2865 struct vb_device_info *pVBInfo)
2866{
2867 unsigned short offset;
2868 unsigned char temp;
2869
2870 if (pVBInfo->VBInfo & SetInSlaveMode)
2871 return;
2872
2873 offset = XGI_GetOffset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
2874 HwDeviceExtension, pVBInfo);
2875 temp = (unsigned char) (offset & 0xFF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002876 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002877 temp = (unsigned char) ((offset & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002878 xgifb_reg_set(pVBInfo->Part1Port, 0x09, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002879 temp = (unsigned char) (((offset >> 3) & 0xFF) + 1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002880 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002881}
2882
Randy Dunlap89229672010-08-10 08:46:44 -07002883static void XGI_SetCRT2FIFO(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002884{
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002885 /* threshold high ,disable auto threshold */
2886 xgifb_reg_set(pVBInfo->Part1Port, 0x01, 0x3B);
2887 /* threshold low default 04h */
2888 xgifb_reg_and_or(pVBInfo->Part1Port, 0x02, ~(0x3F), 0x04);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002889}
2890
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002891static void XGI_PreSetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302892 struct xgi_hw_device_info *HwDeviceExtension,
2893 unsigned short RefreshRateTableIndex,
2894 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002895{
Peter Hueweef9a6b92013-02-03 04:08:43 +01002896 u8 tempcx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002897
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302898 XGI_SetCRT2Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
2899 HwDeviceExtension, pVBInfo);
2900 XGI_SetCRT2FIFO(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002901
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302902 for (tempcx = 4; tempcx < 7; tempcx++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02002903 xgifb_reg_set(pVBInfo->Part1Port, tempcx, 0x0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002904
Aaro Koskinen8104e322011-03-13 12:26:22 +02002905 xgifb_reg_set(pVBInfo->Part1Port, 0x50, 0x00);
2906 xgifb_reg_set(pVBInfo->Part1Port, 0x02, 0x44); /* temp 0206 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002907}
2908
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002909static void XGI_SetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302910 struct xgi_hw_device_info *HwDeviceExtension,
2911 unsigned short RefreshRateTableIndex,
2912 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002913{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302914 unsigned short temp = 0, tempax = 0, tempbx = 0, tempcx = 0,
Peter Hueweef9a6b92013-02-03 04:08:43 +01002915 pushbx = 0, CRT1Index, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002916
Aaro Koskinena39325d2012-11-04 21:14:53 +02002917 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002918 CRT1Index &= IndexMask;
Aaro Koskinenb3979922012-11-04 21:14:52 +02002919 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002920
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302921 /* bainy change table name */
2922 if (modeflag & HalfDCLK) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002923 /* BTVGA2HT 0x08,0x09 */
2924 temp = (pVBInfo->VGAHT / 2 - 1) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002925 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302926 temp = (((pVBInfo->VGAHT / 2 - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002927 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002928 /* BTVGA2HDEE 0x0A,0x0C */
2929 temp = (pVBInfo->VGAHDE / 2 + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002930 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302931 tempcx = ((pVBInfo->VGAHT - pVBInfo->VGAHDE) / 2) >> 2;
2932 pushbx = pVBInfo->VGAHDE / 2 + 16;
2933 tempcx = tempcx >> 1;
2934 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
2935 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002936
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302937 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002938 tempbx = XGI_CRT1Table[CRT1Index].CR[4];
2939 tempbx |= ((XGI_CRT1Table[CRT1Index].CR[14] &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002940 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302941 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002942 tempcx = XGI_CRT1Table[CRT1Index].CR[5];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302943 tempcx &= 0x1F;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002944 temp = XGI_CRT1Table[CRT1Index].CR[15];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302945 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
2946 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
2947 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002948
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302949 tempbx += 4;
2950 tempcx += 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002951
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302952 if (tempcx > (pVBInfo->VGAHT / 2))
2953 tempcx = pVBInfo->VGAHT / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002954
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302955 temp = tempbx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002956
Aaro Koskinen8104e322011-03-13 12:26:22 +02002957 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302958 } else {
2959 temp = (pVBInfo->VGAHT - 1) & 0x0FF; /* BTVGA2HT 0x08,0x09 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002960 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302961 temp = (((pVBInfo->VGAHT - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002962 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002963 /* BTVGA2HDEE 0x0A,0x0C */
2964 temp = (pVBInfo->VGAHDE + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002965 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302966 tempcx = (pVBInfo->VGAHT - pVBInfo->VGAHDE) >> 2; /* cx */
2967 pushbx = pVBInfo->VGAHDE + 16;
2968 tempcx = tempcx >> 1;
2969 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
2970 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002971
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302972 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002973 tempbx = XGI_CRT1Table[CRT1Index].CR[3];
2974 tempbx |= ((XGI_CRT1Table[CRT1Index].CR[5] &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002975 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302976 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002977 tempcx = XGI_CRT1Table[CRT1Index].CR[4];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302978 tempcx &= 0x1F;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002979 temp = XGI_CRT1Table[CRT1Index].CR[6];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302980 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
2981 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
2982 tempbx += 16;
2983 tempcx += 16;
2984 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002985
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302986 if (tempcx > pVBInfo->VGAHT)
2987 tempcx = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002988
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302989 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002990 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302991 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002992
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302993 tempax = (tempax & 0x00FF) | (tempbx & 0xFF00);
2994 tempbx = pushbx;
2995 tempbx = (tempbx & 0x00FF) | ((tempbx & 0xFF00) << 4);
2996 tempax |= (tempbx & 0xFF00);
2997 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002998 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302999 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003000 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303001 tempcx = (pVBInfo->VGAVT - 1);
3002 temp = tempcx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003003
Aaro Koskinen8104e322011-03-13 12:26:22 +02003004 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303005 tempbx = pVBInfo->VGAVDE - 1;
3006 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003007 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303008 temp = ((tempbx & 0xFF00) << 3) >> 8;
3009 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003010 xgifb_reg_set(pVBInfo->Part1Port, 0x12, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003011
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003012 /* BTVGA2VRS 0x10,0x11 */
3013 tempbx = (pVBInfo->VGAVT + pVBInfo->VGAVDE) >> 1;
3014 /* BTVGA2VRE 0x11 */
3015 tempcx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) >> 4) + tempbx + 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003016
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303017 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003018 tempbx = XGI_CRT1Table[CRT1Index].CR[10];
3019 temp = XGI_CRT1Table[CRT1Index].CR[9];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003020
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303021 if (temp & 0x04)
3022 tempbx |= 0x0100;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003023
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303024 if (temp & 0x080)
3025 tempbx |= 0x0200;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003026
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003027 temp = XGI_CRT1Table[CRT1Index].CR[14];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003028
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303029 if (temp & 0x08)
3030 tempbx |= 0x0400;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003031
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003032 temp = XGI_CRT1Table[CRT1Index].CR[11];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303033 tempcx = (tempcx & 0xFF00) | (temp & 0x00FF);
3034 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003035
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303036 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003037 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303038 temp = ((tempbx & 0xFF00) >> 8) << 4;
3039 temp = ((tempcx & 0x000F) | (temp));
Aaro Koskinen8104e322011-03-13 12:26:22 +02003040 xgifb_reg_set(pVBInfo->Part1Port, 0x11, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303041 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003042
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303043 if (modeflag & DoubleScanMode)
3044 tempax |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003045
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303046 if (modeflag & HalfDCLK)
3047 tempax |= 0x40;
3048
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003049 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2C, ~0x0C0, tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003050}
3051
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003052static unsigned short XGI_GetVGAHT2(struct vb_device_info *pVBInfo)
3053{
3054 unsigned long tempax, tempbx;
3055
3056 tempbx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) * pVBInfo->RVBHCMAX)
3057 & 0xFFFF;
3058 tempax = (pVBInfo->VT - pVBInfo->VDE) * pVBInfo->RVBHCFACT;
3059 tempax = (tempax * pVBInfo->HT) / tempbx;
3060
3061 return (unsigned short) tempax;
3062}
3063
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003064static void XGI_SetLockRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303065 struct xgi_hw_device_info *HwDeviceExtension,
3066 unsigned short RefreshRateTableIndex,
3067 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003068{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303069 unsigned short push1, push2, tempax, tempbx = 0, tempcx, temp, resinfo,
Peter Hueweef9a6b92013-02-03 04:08:43 +01003070 modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003071
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003072 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02003073 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3074 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003075
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303076 if (!(pVBInfo->VBInfo & SetInSlaveMode))
3077 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003078
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303079 temp = 0xFF; /* set MAX HT */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003080 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303081 tempcx = 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003082
Peter Huewe6896b942012-02-09 21:11:46 +01003083 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303084 modeflag |= Charx8Dot;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003085
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303086 tempax = pVBInfo->VGAHDE; /* 0x04 Horizontal Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003087
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303088 if (modeflag & HalfDCLK)
3089 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003090
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303091 tempax = (tempax / tempcx) - 1;
3092 tempbx |= ((tempax & 0x00FF) << 8);
3093 temp = tempax & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003094 xgifb_reg_set(pVBInfo->Part1Port, 0x04, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003095
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303096 temp = (tempbx & 0xFF00) >> 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003097
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303098 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Peter Huewe6896b942012-02-09 21:11:46 +01003099 if (!(pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3100 | VB_SIS302LV | VB_XGI301C)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303101 temp += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003102
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03003103 if ((pVBInfo->VBInfo & SetCRT2ToHiVision) &&
3104 !(pVBInfo->VBType & VB_SIS301LV) && (resinfo == 7))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303105 temp -= 2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303106 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003107
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003108 /* 0x05 Horizontal Display Start */
3109 xgifb_reg_set(pVBInfo->Part1Port, 0x05, temp);
3110 /* 0x06 Horizontal Blank end */
3111 xgifb_reg_set(pVBInfo->Part1Port, 0x06, 0x03);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003112
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303113 if (!(pVBInfo->VBInfo & DisableCRT2Display)) { /* 030226 bainy */
3114 if (pVBInfo->VBInfo & SetCRT2ToTV)
3115 tempax = pVBInfo->VGAHT;
3116 else
3117 tempax = XGI_GetVGAHT2(pVBInfo);
3118 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003119
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303120 if (tempax >= pVBInfo->VGAHT)
3121 tempax = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003122
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303123 if (modeflag & HalfDCLK)
3124 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003125
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303126 tempax = (tempax / tempcx) - 5;
3127 tempcx = tempax; /* 20030401 0x07 horizontal Retrace Start */
Peter Huewe599801f2012-02-09 21:11:45 +01003128 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303129 temp = (tempbx & 0x00FF) - 1;
3130 if (!(modeflag & HalfDCLK)) {
3131 temp -= 6;
3132 if (pVBInfo->TVInfo & TVSimuMode) {
3133 temp -= 4;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003134 temp -= 10;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303135 }
3136 }
3137 } else {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303138 tempbx = (tempbx & 0xFF00) >> 8;
3139 tempcx = (tempcx + tempbx) >> 1;
3140 temp = (tempcx & 0x00FF) + 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003141
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303142 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3143 temp -= 1;
3144 if (!(modeflag & HalfDCLK)) {
3145 if ((modeflag & Charx8Dot)) {
3146 temp += 4;
3147 if (pVBInfo->VGAHDE >= 800)
3148 temp -= 6;
3149 }
3150 }
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003151 } else if (!(modeflag & HalfDCLK)) {
3152 temp -= 4;
Peter Huewe255aabd2012-02-09 21:11:44 +01003153 if (pVBInfo->LCDResInfo != Panel_1280x960 &&
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003154 pVBInfo->VGAHDE >= 800) {
3155 temp -= 7;
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003156 if (pVBInfo->VGAHDE >= 1280 &&
Peter Huewe255aabd2012-02-09 21:11:44 +01003157 pVBInfo->LCDResInfo != Panel_1280x960 &&
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003158 (pVBInfo->LCDInfo & LCDNonExpanding))
3159 temp += 28;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303160 }
3161 }
3162 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003163
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003164 /* 0x07 Horizontal Retrace Start */
3165 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
3166 /* 0x08 Horizontal Retrace End */
3167 xgifb_reg_set(pVBInfo->Part1Port, 0x08, 0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003168
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303169 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3170 if (pVBInfo->TVInfo & TVSimuMode) {
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003171 if (ModeNo == 0x50) {
Peter Huewe85b38472013-05-13 23:41:49 +02003172 if (pVBInfo->TVInfo == SetNTSCTV) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003173 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303174 0x07, 0x30);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003175 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303176 0x08, 0x03);
3177 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003178 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303179 0x07, 0x2f);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003180 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303181 0x08, 0x02);
3182 }
3183 }
3184 }
3185 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003186
Aaro Koskinen8104e322011-03-13 12:26:22 +02003187 xgifb_reg_set(pVBInfo->Part1Port, 0x18, 0x03); /* 0x18 SR0B */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003188 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0xF0, 0x00);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003189 xgifb_reg_set(pVBInfo->Part1Port, 0x09, 0xFF); /* 0x09 Set Max VT */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003190
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303191 tempbx = pVBInfo->VGAVT;
3192 push1 = tempbx;
3193 tempcx = 0x121;
3194 tempbx = pVBInfo->VGAVDE; /* 0x0E Virtical Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003195
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303196 if (tempbx == 357)
3197 tempbx = 350;
3198 if (tempbx == 360)
3199 tempbx = 350;
3200 if (tempbx == 375)
3201 tempbx = 350;
3202 if (tempbx == 405)
3203 tempbx = 400;
3204 if (tempbx == 525)
3205 tempbx = 480;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003206
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303207 push2 = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003208
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303209 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
Peter Huewe255aabd2012-02-09 21:11:44 +01003210 if (pVBInfo->LCDResInfo == Panel_1024x768) {
Peter Huewea3d675c2012-02-09 21:11:47 +01003211 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303212 if (tempbx == 350)
3213 tempbx += 5;
3214 if (tempbx == 480)
3215 tempbx += 5;
3216 }
3217 }
3218 }
3219 tempbx--;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303220 tempbx--;
3221 temp = tempbx & 0x00FF;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003222 /* 0x10 vertical Blank Start */
3223 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303224 tempbx = push2;
3225 tempbx--;
3226 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003227 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003228
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303229 if (tempbx & 0x0100)
3230 tempcx |= 0x0002;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003231
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303232 tempax = 0x000B;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003233
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303234 if (modeflag & DoubleScanMode)
3235 tempax |= 0x08000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003236
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303237 if (tempbx & 0x0200)
3238 tempcx |= 0x0040;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003239
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303240 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003241 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003242
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303243 if (tempbx & 0x0400)
3244 tempcx |= 0x0600;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003245
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003246 /* 0x11 Vertival Blank End */
3247 xgifb_reg_set(pVBInfo->Part1Port, 0x11, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303248
3249 tempax = push1;
3250 tempax -= tempbx; /* 0x0C Vertical Retrace Start */
3251 tempax = tempax >> 2;
3252 push1 = tempax; /* push ax */
3253
3254 if (resinfo != 0x09) {
3255 tempax = tempax << 1;
3256 tempbx += tempax;
3257 }
3258
Peter Huewe599801f2012-02-09 21:11:45 +01003259 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Miguel Gómez470c5332012-07-06 12:40:50 +02003260 if ((pVBInfo->VBType & VB_SIS301LV) &&
3261 !(pVBInfo->TVInfo & TVSetHiVision)) {
3262 if ((pVBInfo->TVInfo & TVSimuMode) &&
3263 (pVBInfo->TVInfo & TVSetPAL)) {
3264 if (!(pVBInfo->VBType & VB_SIS301LV) ||
3265 !(pVBInfo->TVInfo &
3266 (TVSetYPbPr525p |
3267 TVSetYPbPr750p |
3268 TVSetHiVision)))
3269 tempbx += 40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303270 }
3271 } else {
3272 tempbx -= 10;
3273 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003274 } else if (pVBInfo->TVInfo & TVSimuMode) {
3275 if (pVBInfo->TVInfo & TVSetPAL) {
3276 if (pVBInfo->VBType & VB_SIS301LV) {
3277 if (!(pVBInfo->TVInfo &
3278 (TVSetYPbPr525p |
3279 TVSetYPbPr750p |
3280 TVSetHiVision)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303281 tempbx += 40;
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003282 } else {
3283 tempbx += 40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303284 }
3285 }
3286 }
3287 tempax = push1;
3288 tempax = tempax >> 2;
3289 tempax++;
3290 tempax += tempbx;
3291 push1 = tempax; /* push ax */
3292
Peter Huewe599801f2012-02-09 21:11:45 +01003293 if ((pVBInfo->TVInfo & TVSetPAL)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303294 if (tempbx <= 513) {
3295 if (tempax >= 513)
3296 tempbx = 513;
3297 }
3298 }
3299
3300 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003301 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303302 tempbx--;
3303 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003304 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303305
3306 if (tempbx & 0x0100)
3307 tempcx |= 0x0008;
3308
3309 if (tempbx & 0x0200)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003310 xgifb_reg_and_or(pVBInfo->Part1Port, 0x0B, 0x0FF, 0x20);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303311
3312 tempbx++;
3313
3314 if (tempbx & 0x0100)
3315 tempcx |= 0x0004;
3316
3317 if (tempbx & 0x0200)
3318 tempcx |= 0x0080;
3319
3320 if (tempbx & 0x0400)
3321 tempcx |= 0x0C00;
3322
3323 tempbx = push1; /* pop ax */
3324 temp = tempbx & 0x00FF;
3325 temp &= 0x0F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003326 /* 0x0D vertical Retrace End */
3327 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303328
3329 if (tempbx & 0x0010)
3330 tempcx |= 0x2000;
3331
3332 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003333 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp); /* 0x0A CR07 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303334 temp = (tempcx & 0x0FF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003335 xgifb_reg_set(pVBInfo->Part1Port, 0x17, temp); /* 0x17 SR0A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303336 tempax = modeflag;
3337 temp = (tempax & 0xFF00) >> 8;
3338
3339 temp = (temp >> 1) & 0x09;
3340
Peter Huewe6896b942012-02-09 21:11:46 +01003341 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303342 temp |= 0x01;
3343
Aaro Koskinen8104e322011-03-13 12:26:22 +02003344 xgifb_reg_set(pVBInfo->Part1Port, 0x16, temp); /* 0x16 SR01 */
3345 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, 0); /* 0x0F CR14 */
3346 xgifb_reg_set(pVBInfo->Part1Port, 0x12, 0); /* 0x12 CR17 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303347
3348 if (pVBInfo->LCDInfo & LCDRGB18Bit)
3349 temp = 0x80;
3350 else
3351 temp = 0x00;
3352
Aaro Koskinen8104e322011-03-13 12:26:22 +02003353 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, temp); /* 0x1A SR0E */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303354
3355 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003356}
3357
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003358static void XGI_SetGroup2(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303359 unsigned short RefreshRateTableIndex,
3360 struct xgi_hw_device_info *HwDeviceExtension,
3361 struct vb_device_info *pVBInfo)
3362{
3363 unsigned short i, j, tempax, tempbx, tempcx, temp, push1, push2,
Peter Hueweef9a6b92013-02-03 04:08:43 +01003364 modeflag;
Aaro Koskinend21222d2012-09-11 00:15:29 +03003365 unsigned char const *TimingPoint;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303366
3367 unsigned long longtemp, tempeax, tempebx, temp2, tempecx;
3368
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003369 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02003370 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303371
3372 tempax = 0;
3373
3374 if (!(pVBInfo->VBInfo & SetCRT2ToAVIDEO))
3375 tempax |= 0x0800;
3376
3377 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3378 tempax |= 0x0400;
3379
3380 if (pVBInfo->VBInfo & SetCRT2ToSCART)
3381 tempax |= 0x0200;
3382
Peter Huewe599801f2012-02-09 21:11:45 +01003383 if (!(pVBInfo->TVInfo & TVSetPAL))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303384 tempax |= 0x1000;
3385
Peter Huewe599801f2012-02-09 21:11:45 +01003386 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303387 tempax |= 0x0100;
3388
Peter Huewe599801f2012-02-09 21:11:45 +01003389 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303390 tempax &= 0xfe00;
3391
3392 tempax = (tempax & 0xff00) >> 8;
3393
Aaro Koskinen8104e322011-03-13 12:26:22 +02003394 xgifb_reg_set(pVBInfo->Part2Port, 0x0, tempax);
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003395 TimingPoint = XGI330_NTSCTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303396
Peter Huewe599801f2012-02-09 21:11:45 +01003397 if (pVBInfo->TVInfo & TVSetPAL)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003398 TimingPoint = XGI330_PALTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303399
Peter Huewe599801f2012-02-09 21:11:45 +01003400 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003401 TimingPoint = XGI330_HiTVExtTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303402
3403 if (pVBInfo->VBInfo & SetInSlaveMode)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003404 TimingPoint = XGI330_HiTVSt2Timing;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303405
3406 if (pVBInfo->SetFlag & TVSimuMode)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003407 TimingPoint = XGI330_HiTVSt1Timing;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303408
3409 if (!(modeflag & Charx8Dot))
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003410 TimingPoint = XGI330_HiTVTextTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303411 }
3412
Peter Huewe599801f2012-02-09 21:11:45 +01003413 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
3414 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003415 TimingPoint = XGI330_YPbPr525iTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303416
Peter Huewe599801f2012-02-09 21:11:45 +01003417 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003418 TimingPoint = XGI330_YPbPr525pTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303419
Peter Huewe599801f2012-02-09 21:11:45 +01003420 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003421 TimingPoint = XGI330_YPbPr750pTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303422 }
3423
3424 for (i = 0x01, j = 0; i <= 0x2D; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02003425 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303426
3427 for (i = 0x39; i <= 0x45; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003428 /* di->temp2[j] */
3429 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303430
3431 if (pVBInfo->VBInfo & SetCRT2ToTV)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003432 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303433
3434 temp = pVBInfo->NewFlickerMode;
3435 temp &= 0x80;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003436 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xFF, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303437
Peter Huewe599801f2012-02-09 21:11:45 +01003438 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303439 tempax = 520;
3440 else
3441 tempax = 440;
3442
3443 if (pVBInfo->VDE <= tempax) {
3444 tempax -= pVBInfo->VDE;
3445 tempax = tempax >> 2;
3446 tempax = (tempax & 0x00FF) | ((tempax & 0x00FF) << 8);
3447 push1 = tempax;
3448 temp = (tempax & 0xFF00) >> 8;
3449 temp += (unsigned short) TimingPoint[0];
3450
Peter Huewe6896b942012-02-09 21:11:46 +01003451 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3452 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303453 if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO
3454 | SetCRT2ToSVIDEO | SetCRT2ToSCART
Peter Huewe599801f2012-02-09 21:11:45 +01003455 | SetCRT2ToYPbPr525750)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303456 tempcx = pVBInfo->VGAHDE;
3457 if (tempcx >= 1024) {
3458 temp = 0x17; /* NTSC */
Peter Huewe599801f2012-02-09 21:11:45 +01003459 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303460 temp = 0x19; /* PAL */
3461 }
3462 }
3463 }
3464
Aaro Koskinen8104e322011-03-13 12:26:22 +02003465 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303466 tempax = push1;
3467 temp = (tempax & 0xFF00) >> 8;
3468 temp += TimingPoint[1];
3469
Peter Huewe6896b942012-02-09 21:11:46 +01003470 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3471 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303472 if ((pVBInfo->VBInfo & (SetCRT2ToAVIDEO
3473 | SetCRT2ToSVIDEO | SetCRT2ToSCART
Peter Huewe599801f2012-02-09 21:11:45 +01003474 | SetCRT2ToYPbPr525750))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303475 tempcx = pVBInfo->VGAHDE;
3476 if (tempcx >= 1024) {
3477 temp = 0x1D; /* NTSC */
Peter Huewe599801f2012-02-09 21:11:45 +01003478 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303479 temp = 0x52; /* PAL */
3480 }
3481 }
3482 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02003483 xgifb_reg_set(pVBInfo->Part2Port, 0x02, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303484 }
3485
3486 /* 301b */
3487 tempcx = pVBInfo->HT;
3488
3489 if (XGI_IsLCDDualLink(pVBInfo))
3490 tempcx = tempcx >> 1;
3491
3492 tempcx -= 2;
3493 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003494 xgifb_reg_set(pVBInfo->Part2Port, 0x1B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303495
3496 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003497 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303498
3499 tempcx = pVBInfo->HT >> 1;
3500 push1 = tempcx; /* push cx */
3501 tempcx += 7;
3502
Peter Huewe599801f2012-02-09 21:11:45 +01003503 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303504 tempcx -= 4;
3505
3506 temp = tempcx & 0x00FF;
3507 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003508 xgifb_reg_and_or(pVBInfo->Part2Port, 0x22, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303509
3510 tempbx = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
3511 tempbx += tempcx;
3512 push2 = tempbx;
3513 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003514 xgifb_reg_set(pVBInfo->Part2Port, 0x24, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303515 temp = (tempbx & 0xFF00) >> 8;
3516 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003517 xgifb_reg_and_or(pVBInfo->Part2Port, 0x25, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303518
3519 tempbx = push2;
3520 tempbx = tempbx + 8;
Peter Huewe599801f2012-02-09 21:11:45 +01003521 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303522 tempbx = tempbx - 4;
3523 tempcx = tempbx;
3524 }
3525
3526 temp = (tempbx & 0x00FF) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003527 xgifb_reg_and_or(pVBInfo->Part2Port, 0x29, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303528
3529 j += 2;
3530 tempcx += (TimingPoint[j] | ((TimingPoint[j + 1]) << 8));
3531 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003532 xgifb_reg_set(pVBInfo->Part2Port, 0x27, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303533 temp = ((tempcx & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003534 xgifb_reg_and_or(pVBInfo->Part2Port, 0x28, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303535
3536 tempcx += 8;
Peter Huewe599801f2012-02-09 21:11:45 +01003537 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303538 tempcx -= 4;
3539
3540 temp = tempcx & 0xFF;
3541 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003542 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2A, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303543
3544 tempcx = push1; /* pop cx */
3545 j += 2;
3546 temp = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
3547 tempcx -= temp;
3548 temp = tempcx & 0x00FF;
3549 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003550 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2D, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303551
3552 tempcx -= 11;
3553
3554 if (!(pVBInfo->VBInfo & SetCRT2ToTV)) {
3555 tempax = XGI_GetVGAHT2(pVBInfo);
3556 tempcx = tempax - 1;
3557 }
3558 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003559 xgifb_reg_set(pVBInfo->Part2Port, 0x2E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303560
3561 tempbx = pVBInfo->VDE;
3562
3563 if (pVBInfo->VGAVDE == 360)
3564 tempbx = 746;
3565 if (pVBInfo->VGAVDE == 375)
3566 tempbx = 746;
3567 if (pVBInfo->VGAVDE == 405)
3568 tempbx = 853;
3569
3570 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003571 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01003572 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003573 if (!(pVBInfo->TVInfo &
Peter Huewe599801f2012-02-09 21:11:45 +01003574 (TVSetYPbPr525p | TVSetYPbPr750p)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303575 tempbx = tempbx >> 1;
3576 } else
3577 tempbx = tempbx >> 1;
3578 }
3579
3580 tempbx -= 2;
3581 temp = tempbx & 0x00FF;
3582
Peter Huewe599801f2012-02-09 21:11:45 +01003583 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Huewe6896b942012-02-09 21:11:46 +01003584 if (pVBInfo->VBType & VB_SIS301LV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003585 if (pVBInfo->TVInfo & TVSetHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303586 if (pVBInfo->VBInfo & SetInSlaveMode) {
3587 if (ModeNo == 0x2f)
3588 temp += 1;
3589 }
3590 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003591 } else if (pVBInfo->VBInfo & SetInSlaveMode) {
3592 if (ModeNo == 0x2f)
3593 temp += 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303594 }
3595 }
3596
Aaro Koskinen8104e322011-03-13 12:26:22 +02003597 xgifb_reg_set(pVBInfo->Part2Port, 0x2F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303598
3599 temp = (tempcx & 0xFF00) >> 8;
3600 temp |= ((tempbx & 0xFF00) >> 8) << 6;
3601
Peter Huewe599801f2012-02-09 21:11:45 +01003602 if (!(pVBInfo->VBInfo & SetCRT2ToHiVision)) {
Peter Huewe6896b942012-02-09 21:11:46 +01003603 if (pVBInfo->VBType & VB_SIS301LV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003604 if (pVBInfo->TVInfo & TVSetHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303605 temp |= 0x10;
3606
3607 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3608 temp |= 0x20;
3609 }
3610 } else {
3611 temp |= 0x10;
3612 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3613 temp |= 0x20;
3614 }
3615 }
3616
Aaro Koskinen8104e322011-03-13 12:26:22 +02003617 xgifb_reg_set(pVBInfo->Part2Port, 0x30, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303618
Peter Huewe6896b942012-02-09 21:11:46 +01003619 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3620 | VB_SIS302LV | VB_XGI301C)) { /* TV gatingno */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303621 tempbx = pVBInfo->VDE;
3622 tempcx = tempbx - 2;
3623
3624 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003625 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p
3626 | TVSetYPbPr750p)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303627 tempbx = tempbx >> 1;
3628 }
3629
Peter Huewe6896b942012-02-09 21:11:46 +01003630 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303631 temp = 0;
3632 if (tempcx & 0x0400)
3633 temp |= 0x20;
3634
3635 if (tempbx & 0x0400)
3636 temp |= 0x40;
3637
Aaro Koskinen8104e322011-03-13 12:26:22 +02003638 xgifb_reg_set(pVBInfo->Part4Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303639 }
3640
3641 temp = (((tempbx - 3) & 0x0300) >> 8) << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003642 xgifb_reg_set(pVBInfo->Part2Port, 0x46, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303643 temp = (tempbx - 3) & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003644 xgifb_reg_set(pVBInfo->Part2Port, 0x47, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303645 }
3646
3647 tempbx = tempbx & 0x00FF;
3648
3649 if (!(modeflag & HalfDCLK)) {
3650 tempcx = pVBInfo->VGAHDE;
3651 if (tempcx >= pVBInfo->HDE) {
3652 tempbx |= 0x2000;
3653 tempax &= 0x00FF;
3654 }
3655 }
3656
3657 tempcx = 0x0101;
3658
3659 if (pVBInfo->VBInfo & SetCRT2ToTV) { /*301b*/
3660 if (pVBInfo->VGAHDE >= 1024) {
3661 tempcx = 0x1920;
3662 if (pVBInfo->VGAHDE >= 1280) {
3663 tempcx = 0x1420;
3664 tempbx = tempbx & 0xDFFF;
3665 }
3666 }
3667 }
3668
3669 if (!(tempbx & 0x2000)) {
3670 if (modeflag & HalfDCLK)
3671 tempcx = (tempcx & 0xFF00) | ((tempcx & 0x00FF) << 1);
3672
3673 push1 = tempbx;
3674 tempeax = pVBInfo->VGAHDE;
3675 tempebx = (tempcx & 0xFF00) >> 8;
3676 longtemp = tempeax * tempebx;
3677 tempecx = tempcx & 0x00FF;
3678 longtemp = longtemp / tempecx;
3679
3680 /* 301b */
3681 tempecx = 8 * 1024;
3682
Peter Huewe6896b942012-02-09 21:11:46 +01003683 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3684 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303685 tempecx = tempecx * 8;
3686 }
3687
3688 longtemp = longtemp * tempecx;
3689 tempecx = pVBInfo->HDE;
3690 temp2 = longtemp % tempecx;
3691 tempeax = longtemp / tempecx;
3692 if (temp2 != 0)
3693 tempeax += 1;
3694
3695 tempax = (unsigned short) tempeax;
3696
3697 /* 301b */
Peter Huewe6896b942012-02-09 21:11:46 +01003698 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3699 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303700 tempcx = ((tempax & 0xFF00) >> 5) >> 8;
3701 }
3702 /* end 301b */
3703
3704 tempbx = push1;
3705 tempbx = (unsigned short) (((tempeax & 0x0000FF00) & 0x1F00)
3706 | (tempbx & 0x00FF));
3707 tempax = (unsigned short) (((tempeax & 0x000000FF) << 8)
3708 | (tempax & 0x00FF));
3709 temp = (tempax & 0xFF00) >> 8;
3710 } else {
3711 temp = (tempax & 0x00FF) >> 8;
3712 }
3713
Aaro Koskinen8104e322011-03-13 12:26:22 +02003714 xgifb_reg_set(pVBInfo->Part2Port, 0x44, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303715 temp = (tempbx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003716 xgifb_reg_and_or(pVBInfo->Part2Port, 0x45, ~0x03F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303717 temp = tempcx & 0x00FF;
3718
3719 if (tempbx & 0x2000)
3720 temp = 0;
3721
3722 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
3723 temp |= 0x18;
3724
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003725 xgifb_reg_and_or(pVBInfo->Part2Port, 0x46, ~0x1F, temp);
Peter Huewe599801f2012-02-09 21:11:45 +01003726 if (pVBInfo->TVInfo & TVSetPAL) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303727 tempbx = 0x0382;
3728 tempcx = 0x007e;
3729 } else {
3730 tempbx = 0x0369;
3731 tempcx = 0x0061;
3732 }
3733
3734 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003735 xgifb_reg_set(pVBInfo->Part2Port, 0x4b, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303736 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003737 xgifb_reg_set(pVBInfo->Part2Port, 0x4c, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303738
3739 temp = ((tempcx & 0xFF00) >> 8) & 0x03;
3740 temp = temp << 2;
3741 temp |= ((tempbx & 0xFF00) >> 8) & 0x03;
3742
Peter Huewe599801f2012-02-09 21:11:45 +01003743 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303744 temp |= 0x10;
3745
Peter Huewe599801f2012-02-09 21:11:45 +01003746 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303747 temp |= 0x20;
3748
Peter Huewe599801f2012-02-09 21:11:45 +01003749 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303750 temp |= 0x60;
3751 }
3752
Aaro Koskinen8104e322011-03-13 12:26:22 +02003753 xgifb_reg_set(pVBInfo->Part2Port, 0x4d, temp);
Aaro Koskinen58839b02011-03-13 12:26:23 +02003754 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x43); /* 301b change */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003755 xgifb_reg_set(pVBInfo->Part2Port, 0x43, (unsigned short) (temp - 3));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303756
Peter Huewe599801f2012-02-09 21:11:45 +01003757 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303758 if (pVBInfo->TVInfo & NTSC1024x768) {
3759 TimingPoint = XGI_NTSC1024AdjTime;
3760 for (i = 0x1c, j = 0; i <= 0x30; i++, j++) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003761 xgifb_reg_set(pVBInfo->Part2Port, i,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303762 TimingPoint[j]);
3763 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02003764 xgifb_reg_set(pVBInfo->Part2Port, 0x43, 0x72);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303765 }
3766 }
3767
Miguel Gómez949eb0a2012-07-06 12:40:36 +02003768 /* Modify for 301C PALM Support */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303769 if (pVBInfo->VBType & VB_XGI301C) {
Peter Huewe599801f2012-02-09 21:11:45 +01003770 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003771 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x08,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303772 0x08); /* PALM Mode */
3773 }
3774
Peter Huewe599801f2012-02-09 21:11:45 +01003775 if (pVBInfo->TVInfo & TVSetPALM) {
Peter Huewe9388ad92013-02-15 20:37:10 +01003776 tempax = xgifb_reg_get(pVBInfo->Part2Port, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303777 tempax--;
Aaro Koskinendc505562011-03-13 12:26:26 +02003778 xgifb_reg_and(pVBInfo->Part2Port, 0x01, tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303779
Aaro Koskinendc505562011-03-13 12:26:26 +02003780 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xEF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303781 }
3782
Peter Huewe599801f2012-02-09 21:11:45 +01003783 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303784 if (!(pVBInfo->VBInfo & SetInSlaveMode))
Aaro Koskinen8104e322011-03-13 12:26:22 +02003785 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303786 }
3787
3788 if (pVBInfo->VBInfo & SetCRT2ToTV)
3789 return;
3790}
3791
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003792static void XGI_SetLCDRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303793 struct xgi_hw_device_info *HwDeviceExtension,
3794 unsigned short RefreshRateTableIndex,
3795 struct vb_device_info *pVBInfo)
3796{
Peter Hueweef9a6b92013-02-03 04:08:43 +01003797 unsigned short pushbx, tempax, tempbx, tempcx, temp, tempah,
3798 tempbh, tempch;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303799
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02003800 struct XGI_LCDDesStruct const *LCDBDesPtr = NULL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303801
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003802 /* si+Ext_ResInfo */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303803 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
3804 return;
3805
3806 tempbx = pVBInfo->HDE; /* RHACTE=HDE-1 */
3807
3808 if (XGI_IsLCDDualLink(pVBInfo))
3809 tempbx = tempbx >> 1;
3810
3811 tempbx -= 1;
3812 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003813 xgifb_reg_set(pVBInfo->Part2Port, 0x2C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303814 temp = (tempbx & 0xFF00) >> 8;
3815 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003816 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2B, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303817 temp = 0x01;
3818
Aaro Koskinen8104e322011-03-13 12:26:22 +02003819 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303820 tempbx = pVBInfo->VDE; /* RTVACTEO=(VDE-1)&0xFF */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303821 tempbx--;
3822 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003823 xgifb_reg_set(pVBInfo->Part2Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303824 temp = ((tempbx & 0xFF00) >> 8) & 0x07;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003825 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0C, ~0x07, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303826
3827 tempcx = pVBInfo->VT - 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303828 temp = tempcx & 0x00FF; /* RVTVT=VT-1 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003829 xgifb_reg_set(pVBInfo->Part2Port, 0x19, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303830 temp = (tempcx & 0xFF00) >> 8;
3831 temp = temp << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003832 xgifb_reg_set(pVBInfo->Part2Port, 0x1A, temp);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003833 xgifb_reg_and_or(pVBInfo->Part2Port, 0x09, 0xF0, 0x00);
3834 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xF0, 0x00);
3835 xgifb_reg_and_or(pVBInfo->Part2Port, 0x17, 0xFB, 0x00);
3836 xgifb_reg_and_or(pVBInfo->Part2Port, 0x18, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303837
Justin P. Mattock558f7582012-10-02 21:17:11 -07003838 /* Customized LCDB Does not add */
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02003839 if ((pVBInfo->VBType & VB_SIS301LV) || (pVBInfo->VBType & VB_SIS302LV))
3840 LCDBDesPtr = XGI_GetLcdPtr(xgifb_lcddldes, ModeNo, ModeIdIndex,
3841 RefreshRateTableIndex, pVBInfo);
3842 else
3843 LCDBDesPtr = XGI_GetLcdPtr(XGI_LCDDesDataTable, ModeNo,
3844 ModeIdIndex, RefreshRateTableIndex,
3845 pVBInfo);
3846
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303847 tempah = pVBInfo->LCDResInfo;
3848 tempah &= PanelResInfo;
3849
Peter Huewe255aabd2012-02-09 21:11:44 +01003850 if ((tempah == Panel_1024x768) || (tempah == Panel_1024x768x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303851 tempbx = 1024;
3852 tempcx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01003853 } else if ((tempah == Panel_1280x1024) ||
3854 (tempah == Panel_1280x1024x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303855 tempbx = 1280;
3856 tempcx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01003857 } else if (tempah == Panel_1400x1050) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303858 tempbx = 1400;
3859 tempcx = 1050;
3860 } else {
3861 tempbx = 1600;
3862 tempcx = 1200;
3863 }
3864
3865 if (pVBInfo->LCDInfo & EnableScalingLCD) {
3866 tempbx = pVBInfo->HDE;
3867 tempcx = pVBInfo->VDE;
3868 }
3869
3870 pushbx = tempbx;
3871 tempax = pVBInfo->VT;
3872 pVBInfo->LCDHDES = LCDBDesPtr->LCDHDES;
3873 pVBInfo->LCDHRS = LCDBDesPtr->LCDHRS;
3874 pVBInfo->LCDVDES = LCDBDesPtr->LCDVDES;
3875 pVBInfo->LCDVRS = LCDBDesPtr->LCDVRS;
3876 tempbx = pVBInfo->LCDVDES;
3877 tempcx += tempbx;
3878
3879 if (tempcx >= tempax)
3880 tempcx -= tempax; /* lcdvdes */
3881
3882 temp = tempbx & 0x00FF; /* RVEQ1EQ=lcdvdes */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003883 xgifb_reg_set(pVBInfo->Part2Port, 0x05, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303884 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003885 xgifb_reg_set(pVBInfo->Part2Port, 0x06, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303886 tempch = ((tempcx & 0xFF00) >> 8) & 0x07;
3887 tempbh = ((tempbx & 0xFF00) >> 8) & 0x07;
3888 tempah = tempch;
3889 tempah = tempah << 3;
3890 tempah |= tempbh;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003891 xgifb_reg_set(pVBInfo->Part2Port, 0x02, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303892
3893 /* getlcdsync() */
3894 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
3895 tempcx = tempbx;
3896 tempax = pVBInfo->VT;
3897 tempbx = pVBInfo->LCDVRS;
3898
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303899 tempcx += tempbx;
3900 if (tempcx >= tempax)
3901 tempcx -= tempax;
3902
3903 temp = tempbx & 0x00FF; /* RTVACTEE=lcdvrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003904 xgifb_reg_set(pVBInfo->Part2Port, 0x04, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303905 temp = (tempbx & 0xFF00) >> 8;
3906 temp = temp << 4;
3907 temp |= (tempcx & 0x000F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003908 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303909 tempcx = pushbx;
3910 tempax = pVBInfo->HT;
3911 tempbx = pVBInfo->LCDHDES;
3912 tempbx &= 0x0FFF;
3913
3914 if (XGI_IsLCDDualLink(pVBInfo)) {
3915 tempax = tempax >> 1;
3916 tempbx = tempbx >> 1;
3917 tempcx = tempcx >> 1;
3918 }
3919
Peter Huewe6896b942012-02-09 21:11:46 +01003920 if (pVBInfo->VBType & VB_SIS302LV)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303921 tempbx += 1;
3922
3923 if (pVBInfo->VBType & VB_XGI301C) /* tap4 */
3924 tempbx += 1;
3925
3926 tempcx += tempbx;
3927
3928 if (tempcx >= tempax)
3929 tempcx -= tempax;
3930
3931 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003932 xgifb_reg_set(pVBInfo->Part2Port, 0x1F, temp); /* RHBLKE=lcdhdes */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303933 temp = ((tempbx & 0xFF00) >> 8) << 4;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003934 xgifb_reg_set(pVBInfo->Part2Port, 0x20, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303935 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003936 xgifb_reg_set(pVBInfo->Part2Port, 0x23, temp); /* RHEQPLE=lcdhdee */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303937 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003938 xgifb_reg_set(pVBInfo->Part2Port, 0x25, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303939
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303940 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
3941 tempcx = tempax;
3942 tempax = pVBInfo->HT;
3943 tempbx = pVBInfo->LCDHRS;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303944 if (XGI_IsLCDDualLink(pVBInfo)) {
3945 tempax = tempax >> 1;
3946 tempbx = tempbx >> 1;
3947 tempcx = tempcx >> 1;
3948 }
3949
Peter Huewe6896b942012-02-09 21:11:46 +01003950 if (pVBInfo->VBType & VB_SIS302LV)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303951 tempbx += 1;
3952
3953 tempcx += tempbx;
3954
3955 if (tempcx >= tempax)
3956 tempcx -= tempax;
3957
3958 temp = tempbx & 0x00FF; /* RHBURSTS=lcdhrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003959 xgifb_reg_set(pVBInfo->Part2Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303960
3961 temp = (tempbx & 0xFF00) >> 8;
3962 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003963 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303964 temp = tempcx & 0x00FF; /* RHSYEXP2S=lcdhre */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003965 xgifb_reg_set(pVBInfo->Part2Port, 0x21, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303966
Peter Huewea3d675c2012-02-09 21:11:47 +01003967 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303968 if (pVBInfo->VGAVDE == 525) {
Peter Huewe6896b942012-02-09 21:11:46 +01003969 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
3970 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303971 | VB_XGI301C)) {
3972 temp = 0xC6;
3973 } else
3974 temp = 0xC4;
3975
Aaro Koskinen8104e322011-03-13 12:26:22 +02003976 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
3977 xgifb_reg_set(pVBInfo->Part2Port, 0x30, 0xB3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303978 }
3979
3980 if (pVBInfo->VGAVDE == 420) {
Peter Huewe6896b942012-02-09 21:11:46 +01003981 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
3982 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303983 | VB_XGI301C)) {
3984 temp = 0x4F;
3985 } else
3986 temp = 0x4E;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003987 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303988 }
3989 }
3990}
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003991
3992/* --------------------------------------------------------------------- */
3993/* Function : XGI_GetTap4Ptr */
3994/* Input : */
3995/* Output : di -> Tap4 Reg. Setting Pointer */
3996/* Description : */
3997/* --------------------------------------------------------------------- */
Aaro Koskinen1cccd9e2012-11-04 21:15:06 +02003998static struct XGI301C_Tap4TimingStruct const
3999*XGI_GetTap4Ptr(unsigned short tempcx, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004000{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304001 unsigned short tempax, tempbx, i;
Aaro Koskinen1cccd9e2012-11-04 21:15:06 +02004002 struct XGI301C_Tap4TimingStruct const *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004003
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304004 if (tempcx == 0) {
4005 tempax = pVBInfo->VGAHDE;
4006 tempbx = pVBInfo->HDE;
4007 } else {
4008 tempax = pVBInfo->VGAVDE;
4009 tempbx = pVBInfo->VDE;
4010 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004011
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004012 if (tempax <= tempbx)
4013 return &xgifb_tap4_timing[0];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304014 else
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004015 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing; /* NTSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004016
Peter Huewe599801f2012-02-09 21:11:45 +01004017 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304018 Tap4TimingPtr = PALTap4Timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004019
Peter Huewe599801f2012-02-09 21:11:45 +01004020 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
4021 if ((pVBInfo->TVInfo & TVSetYPbPr525i) ||
4022 (pVBInfo->TVInfo & TVSetYPbPr525p))
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004023 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing;
Peter Huewe599801f2012-02-09 21:11:45 +01004024 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304025 Tap4TimingPtr = YPbPr750pTap4Timing;
4026 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004027
Peter Huewe599801f2012-02-09 21:11:45 +01004028 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004029 Tap4TimingPtr = xgifb_tap4_timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004030
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304031 i = 0;
4032 while (Tap4TimingPtr[i].DE != 0xFFFF) {
4033 if (Tap4TimingPtr[i].DE == tempax)
4034 break;
4035 i++;
4036 }
4037 return &Tap4TimingPtr[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004038}
4039
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004040static void XGI_SetTap4Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004041{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304042 unsigned short i, j;
Aaro Koskinen1cccd9e2012-11-04 21:15:06 +02004043 struct XGI301C_Tap4TimingStruct const *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004044
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304045 if (!(pVBInfo->VBType & VB_XGI301C))
4046 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004047
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304048 Tap4TimingPtr = XGI_GetTap4Ptr(0, pVBInfo); /* Set Horizontal Scaling */
4049 for (i = 0x80, j = 0; i <= 0xBF; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004050 xgifb_reg_set(pVBInfo->Part2Port, i, Tap4TimingPtr->Reg[j]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004051
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004052 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
Peter Huewe599801f2012-02-09 21:11:45 +01004053 (!(pVBInfo->VBInfo & SetCRT2ToHiVision))) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004054 /* Set Vertical Scaling */
4055 Tap4TimingPtr = XGI_GetTap4Ptr(1, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304056 for (i = 0xC0, j = 0; i < 0xFF; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004057 xgifb_reg_set(pVBInfo->Part2Port,
4058 i,
4059 Tap4TimingPtr->Reg[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304060 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004061
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004062 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
Peter Huewe599801f2012-02-09 21:11:45 +01004063 (!(pVBInfo->VBInfo & SetCRT2ToHiVision)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004064 /* Enable V.Scaling */
4065 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304066 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004067 /* Enable H.Scaling */
4068 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x10);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004069}
4070
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004071static void XGI_SetGroup3(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304072 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004073{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304074 unsigned short i;
Aaro Koskinend21222d2012-09-11 00:15:29 +03004075 unsigned char const *tempdi;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304076 unsigned short modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004077
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004078 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004079 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004080
Aaro Koskinen8104e322011-03-13 12:26:22 +02004081 xgifb_reg_set(pVBInfo->Part3Port, 0x00, 0x00);
Peter Huewe599801f2012-02-09 21:11:45 +01004082 if (pVBInfo->TVInfo & TVSetPAL) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004083 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
4084 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304085 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004086 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xF5);
4087 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xB7);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304088 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004089
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304090 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
4091 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004092
Peter Huewe599801f2012-02-09 21:11:45 +01004093 if (pVBInfo->TVInfo & TVSetPALM) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004094 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
4095 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
4096 xgifb_reg_set(pVBInfo->Part3Port, 0x3D, 0xA8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304097 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004098
Peter Huewe599801f2012-02-09 21:11:45 +01004099 if ((pVBInfo->VBInfo & SetCRT2ToHiVision) || (pVBInfo->VBInfo
4100 & SetCRT2ToYPbPr525750)) {
4101 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304102 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004103
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004104 tempdi = XGI330_HiTVGroup3Data;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304105 if (pVBInfo->SetFlag & TVSimuMode) {
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004106 tempdi = XGI330_HiTVGroup3Simu;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304107 if (!(modeflag & Charx8Dot))
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004108 tempdi = XGI330_HiTVGroup3Text;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304109 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004110
Peter Huewe599801f2012-02-09 21:11:45 +01004111 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004112 tempdi = XGI330_Ren525pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004113
Peter Huewe599801f2012-02-09 21:11:45 +01004114 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004115 tempdi = XGI330_Ren750pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004116
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304117 for (i = 0; i <= 0x3E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004118 xgifb_reg_set(pVBInfo->Part3Port, i, tempdi[i]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004119
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304120 if (pVBInfo->VBType & VB_XGI301C) { /* Marcovision */
Peter Huewe599801f2012-02-09 21:11:45 +01004121 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004122 xgifb_reg_set(pVBInfo->Part3Port, 0x28, 0x3f);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304123 }
4124 }
4125 return;
4126} /* {end of XGI_SetGroup3} */
4127
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004128static void XGI_SetGroup4(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304129 unsigned short RefreshRateTableIndex,
4130 struct xgi_hw_device_info *HwDeviceExtension,
4131 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004132{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304133 unsigned short tempax, tempcx, tempbx, modeflag, temp, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004134
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304135 unsigned long tempebx, tempeax, templong;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004136
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004137 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004138 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304139 temp = pVBInfo->RVBHCFACT;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004140 xgifb_reg_set(pVBInfo->Part4Port, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004141
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304142 tempbx = pVBInfo->RVBHCMAX;
4143 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004144 xgifb_reg_set(pVBInfo->Part4Port, 0x14, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304145 temp2 = ((tempbx & 0xFF00) >> 8) << 7;
4146 tempcx = pVBInfo->VGAHT - 1;
4147 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004148 xgifb_reg_set(pVBInfo->Part4Port, 0x16, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004149
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304150 temp = ((tempcx & 0xFF00) >> 8) << 3;
4151 temp2 |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004152
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304153 tempcx = pVBInfo->VGAVT - 1;
4154 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
4155 tempcx -= 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004156
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304157 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004158 xgifb_reg_set(pVBInfo->Part4Port, 0x17, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304159 temp = temp2 | ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004160 xgifb_reg_set(pVBInfo->Part4Port, 0x15, temp);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004161 xgifb_reg_or(pVBInfo->Part4Port, 0x0D, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304162 tempcx = pVBInfo->VBInfo;
4163 tempbx = pVBInfo->VGAHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004164
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304165 if (modeflag & HalfDCLK)
4166 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004167
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304168 if (XGI_IsLCDDualLink(pVBInfo))
4169 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004170
Peter Huewe599801f2012-02-09 21:11:45 +01004171 if (tempcx & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304172 temp = 0;
4173 if (tempbx <= 1024)
4174 temp = 0xA0;
4175 if (tempbx == 1280)
4176 temp = 0xC0;
4177 } else if (tempcx & SetCRT2ToTV) {
4178 temp = 0xA0;
4179 if (tempbx <= 800)
4180 temp = 0x80;
4181 } else {
4182 temp = 0x80;
4183 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4184 temp = 0;
4185 if (tempbx > 800)
4186 temp = 0x60;
4187 }
4188 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004189
Peter Huewe599801f2012-02-09 21:11:45 +01004190 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304191 temp = 0x00;
4192 if (pVBInfo->VGAHDE == 1280)
4193 temp = 0x40;
4194 if (pVBInfo->VGAHDE == 1024)
4195 temp = 0x20;
4196 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004197 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0E, ~0xEF, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004198
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304199 tempebx = pVBInfo->VDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004200
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304201 tempcx = pVBInfo->RVBHRS;
4202 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004203 xgifb_reg_set(pVBInfo->Part4Port, 0x18, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004204
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304205 tempeax = pVBInfo->VGAVDE;
4206 tempcx |= 0x04000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004207
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304208 if (tempeax <= tempebx) {
4209 tempcx = (tempcx & (~0x4000));
4210 tempeax = pVBInfo->VGAVDE;
4211 } else {
4212 tempeax -= tempebx;
4213 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004214
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304215 templong = (tempeax * 256 * 1024) % tempebx;
4216 tempeax = (tempeax * 256 * 1024) / tempebx;
4217 tempebx = tempeax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004218
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304219 if (templong != 0)
4220 tempebx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004221
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304222 temp = (unsigned short) (tempebx & 0x000000FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004223 xgifb_reg_set(pVBInfo->Part4Port, 0x1B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004224
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304225 temp = (unsigned short) ((tempebx & 0x0000FF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004226 xgifb_reg_set(pVBInfo->Part4Port, 0x1A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304227 tempbx = (unsigned short) (tempebx >> 16);
4228 temp = tempbx & 0x00FF;
4229 temp = temp << 4;
4230 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004231 xgifb_reg_set(pVBInfo->Part4Port, 0x19, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004232
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304233 /* 301b */
Peter Huewe6896b942012-02-09 21:11:46 +01004234 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4235 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304236 temp = 0x0028;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004237 xgifb_reg_set(pVBInfo->Part4Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304238 tempax = pVBInfo->VGAHDE;
4239 if (modeflag & HalfDCLK)
4240 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004241
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304242 if (XGI_IsLCDDualLink(pVBInfo))
4243 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004244
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304245 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4246 if (tempax > 800)
4247 tempax -= 800;
Aaro Koskinend3ae5762012-09-11 00:15:27 +03004248 } else if (pVBInfo->VGAHDE > 800) {
4249 if (pVBInfo->VGAHDE == 1024)
4250 tempax = (tempax * 25 / 32) - 1;
4251 else
4252 tempax = (tempax * 20 / 32) - 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304253 }
4254 tempax -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004255
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304256 temp = (tempax & 0xFF00) >> 8;
4257 temp = ((temp & 0x0003) << 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004258 xgifb_reg_set(pVBInfo->Part4Port, 0x1E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304259 temp = (tempax & 0x00FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004260 xgifb_reg_set(pVBInfo->Part4Port, 0x1D, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004261
Peter Huewe599801f2012-02-09 21:11:45 +01004262 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToHiVision)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304263 if (pVBInfo->VGAHDE > 800)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004264 xgifb_reg_or(pVBInfo->Part4Port, 0x1E, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004265
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304266 }
4267 temp = 0x0036;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004268
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304269 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4270 if (!(pVBInfo->TVInfo & (NTSC1024x768
Peter Huewe599801f2012-02-09 21:11:45 +01004271 | TVSetYPbPr525p | TVSetYPbPr750p
4272 | TVSetHiVision))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304273 temp |= 0x0001;
4274 if ((pVBInfo->VBInfo & SetInSlaveMode)
4275 && (!(pVBInfo->TVInfo
4276 & TVSimuMode)))
4277 temp &= (~0x0001);
4278 }
4279 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004280
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004281 xgifb_reg_and_or(pVBInfo->Part4Port, 0x1F, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304282 tempbx = pVBInfo->HT;
4283 if (XGI_IsLCDDualLink(pVBInfo))
4284 tempbx = tempbx >> 1;
4285 tempbx = (tempbx >> 1) - 2;
4286 temp = ((tempbx & 0x0700) >> 8) << 3;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004287 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304288 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004289 xgifb_reg_set(pVBInfo->Part4Port, 0x22, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304290 }
4291 /* end 301b */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004292
Aaro Koskinen8951dad2012-09-11 00:15:30 +03004293 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004294}
4295
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004296static void XGINew_EnableCRT2(struct vb_device_info *pVBInfo)
4297{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004298 xgifb_reg_and_or(pVBInfo->P3c4, 0x1E, 0xFF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004299}
4300
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004301static void XGI_SetGroup5(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304302 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004303{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304304 if (pVBInfo->ModeType == ModeVGA) {
4305 if (!(pVBInfo->VBInfo & (SetInSlaveMode | LoadDACFlag
Peter Huewe6896b942012-02-09 21:11:46 +01004306 | DisableCRT2Display))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304307 XGINew_EnableCRT2(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304308 }
4309 }
4310 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004311}
4312
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004313static void XGI_EnableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304314 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004315{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004316 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x40);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004317}
4318
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004319static void XGI_DisableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304320 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004321{
4322
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004323 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004324}
4325
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004326static unsigned char XGI_XG21CheckLVDSMode(struct xgifb_video_info *xgifb_info,
4327 unsigned short ModeNo, unsigned short ModeIdIndex,
4328 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004329{
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004330 unsigned short xres, yres, colordepth, modeflag, resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004331
Aaro Koskinenb3979922012-11-04 21:14:52 +02004332 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02004333 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
4334 yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004335 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004336 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004337
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304338 if (!(modeflag & Charx8Dot)) {
4339 xres /= 9;
4340 xres *= 8;
4341 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004342
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004343 if ((ModeNo > 0x13) && (modeflag & HalfDCLK))
4344 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004345
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004346 if ((ModeNo > 0x13) && (modeflag & DoubleScanMode))
4347 yres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004348
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004349 if (xres > xgifb_info->lvds_data.LVDSHDE)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304350 return 0;
Bill Pembertondda08c52010-06-17 13:10:42 -04004351
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004352 if (yres > xgifb_info->lvds_data.LVDSVDE)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304353 return 0;
4354
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004355 if (xres != xgifb_info->lvds_data.LVDSHDE ||
4356 yres != xgifb_info->lvds_data.LVDSVDE) {
4357 colordepth = XGI_GetColorDepth(ModeNo, ModeIdIndex, pVBInfo);
4358 if (colordepth > 2)
4359 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304360 }
4361 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004362}
4363
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004364static void xgifb_set_lvds(struct xgifb_video_info *xgifb_info,
4365 int chip_id,
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004366 unsigned short ModeNo,
4367 unsigned short ModeIdIndex,
4368 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004369{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304370 unsigned char temp, Miscdata;
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004371 unsigned short xres, yres, modeflag, resindex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304372 unsigned short LVDSHT, LVDSHBS, LVDSHRS, LVDSHRE, LVDSHBE;
4373 unsigned short LVDSVT, LVDSVBS, LVDSVRS, LVDSVRE, LVDSVBE;
4374 unsigned short value;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004375
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004376 temp = (unsigned char) ((xgifb_info->lvds_data.LVDS_Capability &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004377 (LCDPolarity << 8)) >> 8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304378 temp &= LCDPolarity;
Peter Huewe9388ad92013-02-15 20:37:10 +01004379 Miscdata = inb(pVBInfo->P3cc);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004380
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004381 outb((Miscdata & 0x3F) | temp, pVBInfo->P3c2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004382
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004383 temp = xgifb_info->lvds_data.LVDS_Capability & LCDPolarity;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004384 /* SR35[7] FP VSync polarity */
4385 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x80, temp & 0x80);
4386 /* SR30[5] FP HSync polarity */
4387 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, ~0x20, (temp & 0x40) >> 1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004388
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004389 if (chip_id == XG27)
4390 XGI_SetXG27FPBits(pVBInfo);
4391 else
4392 XGI_SetXG21FPBits(pVBInfo);
4393
Aaro Koskinenb3979922012-11-04 21:14:52 +02004394 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02004395 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
4396 yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004397 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004398 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004399
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304400 if (!(modeflag & Charx8Dot))
4401 xres = xres * 8 / 9;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004402
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004403 LVDSHT = xgifb_info->lvds_data.LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004404
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004405 LVDSHBS = xres + (xgifb_info->lvds_data.LVDSHDE - xres) / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004406
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304407 if (LVDSHBS > LVDSHT)
4408 LVDSHBS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004409
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004410 LVDSHRS = LVDSHBS + xgifb_info->lvds_data.LVDSHFP;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304411 if (LVDSHRS > LVDSHT)
4412 LVDSHRS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004413
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004414 LVDSHRE = LVDSHRS + xgifb_info->lvds_data.LVDSHSYNC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304415 if (LVDSHRE > LVDSHT)
4416 LVDSHRE -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004417
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004418 LVDSHBE = LVDSHBS + LVDSHT - xgifb_info->lvds_data.LVDSHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004419
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004420 LVDSVT = xgifb_info->lvds_data.LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004421
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004422 LVDSVBS = yres + (xgifb_info->lvds_data.LVDSVDE - yres) / 2;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004423 if (modeflag & DoubleScanMode)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304424 LVDSVBS += yres / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004425
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304426 if (LVDSVBS > LVDSVT)
4427 LVDSVBS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004428
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004429 LVDSVRS = LVDSVBS + xgifb_info->lvds_data.LVDSVFP;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304430 if (LVDSVRS > LVDSVT)
4431 LVDSVRS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004432
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004433 LVDSVRE = LVDSVRS + xgifb_info->lvds_data.LVDSVSYNC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304434 if (LVDSVRE > LVDSVT)
4435 LVDSVRE -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004436
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004437 LVDSVBE = LVDSVBS + LVDSVT - xgifb_info->lvds_data.LVDSVDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004438
Peter Huewe9388ad92013-02-15 20:37:10 +01004439 temp = xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004440 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp & 0x7f); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004441
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304442 if (!(modeflag & Charx8Dot))
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004443 xgifb_reg_or(pVBInfo->P3c4, 0x1, 0x1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004444
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304445 /* HT SR0B[1:0] CR00 */
4446 value = (LVDSHT >> 3) - 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004447 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004448 xgifb_reg_set(pVBInfo->P3d4, 0x0, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004449
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304450 /* HBS SR0B[5:4] CR02 */
4451 value = (LVDSHBS >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004452 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x30, (value & 0x300) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004453 xgifb_reg_set(pVBInfo->P3d4, 0x2, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004454
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304455 /* HBE SR0C[1:0] CR05[7] CR03[4:0] */
4456 value = (LVDSHBE >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004457 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x03, (value & 0xC0) >> 6);
4458 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x80, (value & 0x20) << 2);
4459 xgifb_reg_and_or(pVBInfo->P3d4, 0x03, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004460
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304461 /* HRS SR0B[7:6] CR04 */
4462 value = (LVDSHRS >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004463 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0xC0, (value & 0x300) >> 2);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004464 xgifb_reg_set(pVBInfo->P3d4, 0x4, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004465
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304466 /* Panel HRS SR2F[1:0] SR2E[7:0] */
4467 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004468 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004469 xgifb_reg_set(pVBInfo->P3c4, 0x2E, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004470
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304471 /* HRE SR0C[2] CR05[4:0] */
4472 value = (LVDSHRE >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004473 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x04, (value & 0x20) >> 3);
4474 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004475
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304476 /* Panel HRE SR2F[7:2] */
4477 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004478 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0xFC, value << 2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004479
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304480 /* VT SR0A[0] CR07[5][0] CR06 */
4481 value = LVDSVT - 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004482 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x01, (value & 0x400) >> 10);
4483 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x20, (value & 0x200) >> 4);
4484 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x01, (value & 0x100) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004485 xgifb_reg_set(pVBInfo->P3d4, 0x06, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004486
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304487 /* VBS SR0A[2] CR09[5] CR07[3] CR15 */
4488 value = LVDSVBS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004489 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x04, (value & 0x400) >> 8);
4490 xgifb_reg_and_or(pVBInfo->P3d4, 0x09, ~0x20, (value & 0x200) >> 4);
4491 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x08, (value & 0x100) >> 5);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004492 xgifb_reg_set(pVBInfo->P3d4, 0x15, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004493
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304494 /* VBE SR0A[4] CR16 */
4495 value = LVDSVBE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004496 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x10, (value & 0x100) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004497 xgifb_reg_set(pVBInfo->P3d4, 0x16, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004498
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304499 /* VRS SR0A[3] CR7[7][2] CR10 */
4500 value = LVDSVRS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004501 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x08, (value & 0x400) >> 7);
4502 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x80, (value & 0x200) >> 2);
4503 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x04, (value & 0x100) >> 6);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004504 xgifb_reg_set(pVBInfo->P3d4, 0x10, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004505
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004506 if (chip_id == XG27) {
4507 /* Panel VRS SR35[2:0] SR34[7:0] */
4508 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07,
4509 (value & 0x700) >> 8);
4510 xgifb_reg_set(pVBInfo->P3c4, 0x34, value & 0xFF);
4511 } else {
4512 /* Panel VRS SR3F[1:0] SR34[7:0] SR33[0] */
4513 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0x03,
4514 (value & 0x600) >> 9);
4515 xgifb_reg_set(pVBInfo->P3c4, 0x34, (value >> 1) & 0xFF);
4516 xgifb_reg_and_or(pVBInfo->P3d4, 0x33, ~0x01, value & 0x01);
4517 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004518
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304519 /* VRE SR0A[5] CR11[3:0] */
4520 value = LVDSVRE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004521 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x20, (value & 0x10) << 1);
4522 xgifb_reg_and_or(pVBInfo->P3d4, 0x11, ~0x0F, value & 0x0F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004523
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304524 /* Panel VRE SR3F[7:2] */
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004525 if (chip_id == XG27)
4526 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
4527 (value << 2) & 0xFC);
4528 else
4529 /* SR3F[7] has to be 0, h/w bug */
4530 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
4531 (value << 2) & 0x7C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004532
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304533 for (temp = 0, value = 0; temp < 3; temp++) {
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004534
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004535 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, value);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004536 xgifb_reg_set(pVBInfo->P3c4,
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004537 0x2B, xgifb_info->lvds_data.VCLKData1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004538 xgifb_reg_set(pVBInfo->P3c4,
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004539 0x2C, xgifb_info->lvds_data.VCLKData2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304540 value += 0x10;
4541 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004542
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304543 if (!(modeflag & Charx8Dot)) {
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004544 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004545 outb(0x13, pVBInfo->P3c0); /* set index */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004546 /* set data, panning = 0, shift left 1 dot*/
4547 outb(0x00, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004548
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004549 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004550 outb(0x20, pVBInfo->P3c0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304551
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004552 inb(pVBInfo->P3da); /* reset 3da */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304553 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004554
4555}
4556
4557/* --------------------------------------------------------------------- */
4558/* Function : XGI_IsLCDON */
4559/* Input : */
Bill Pembertondda08c52010-06-17 13:10:42 -04004560/* Output : 0 : Skip PSC Control */
4561/* 1: Disable PSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004562/* Description : */
4563/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004564static unsigned char XGI_IsLCDON(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004565{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304566 unsigned short tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004567
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304568 tempax = pVBInfo->VBInfo;
4569 if (tempax & SetCRT2ToDualEdge)
4570 return 0;
Peter Huewe6896b942012-02-09 21:11:46 +01004571 else if (tempax & (DisableCRT2Display | SwitchCRT2 | SetSimuScanMode))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304572 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004573
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304574 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004575}
4576
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004577/* --------------------------------------------------------------------- */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004578/* Function : XGI_EnableChISLCD */
4579/* Input : */
4580/* Output : 0 -> Not LCD mode */
Peter Huewe06cc47b2013-02-03 22:54:38 +01004581/* Description : if bool enable = true -> enable, else disable */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004582/* --------------------------------------------------------------------- */
Peter Huewe06cc47b2013-02-03 22:54:38 +01004583static unsigned char XGI_EnableChISLCD(struct vb_device_info *pVBInfo,
4584 bool enable)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004585{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304586 unsigned short tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004587
Peter Huewe06cc47b2013-02-03 22:54:38 +01004588 if (enable)
4589 tempbx = pVBInfo->SetFlag & (EnableChA | EnableChB);
4590 else
4591 tempbx = pVBInfo->SetFlag & (DisableChA | DisableChB);
4592
Aaro Koskinen58839b02011-03-13 12:26:23 +02004593 tempah = ~((unsigned short) xgifb_reg_get(pVBInfo->Part1Port, 0x2E));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004594
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304595 if (tempbx & (EnableChA | DisableChA)) {
4596 if (!(tempah & 0x08)) /* Chk LCDA Mode */
4597 return 0;
4598 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004599
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304600 if (!(tempbx & (EnableChB | DisableChB)))
Bill Pembertondda08c52010-06-17 13:10:42 -04004601 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004602
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304603 if (tempah & 0x01) /* Chk LCDB Mode */
4604 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004605
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304606 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004607}
4608
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004609static void XGI_DisableBridge(struct xgifb_video_info *xgifb_info,
4610 struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304611 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004612{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02004613 unsigned short tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004614
Peter Huewe6896b942012-02-09 21:11:46 +01004615 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4616 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304617 tempah = 0x3F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004618 if (!(pVBInfo->VBInfo &
4619 (DisableCRT2Display | SetSimuScanMode))) {
Peter Huewea3d675c2012-02-09 21:11:47 +01004620 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304621 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
4622 tempah = 0x7F; /* Disable Channel A */
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004623 if (!(pVBInfo->VBInfo &
4624 XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004625 /* Disable Channel B */
4626 tempah = 0xBF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004627
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304628 if (pVBInfo->SetFlag & DisableChB)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004629 /* force to disable Cahnnel */
4630 tempah &= 0xBF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004631
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304632 if (pVBInfo->SetFlag & DisableChA)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004633 /* Force to disable Channel B */
4634 tempah &= 0x7F;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304635 }
4636 }
4637 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004638
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004639 /* disable part4_1f */
4640 xgifb_reg_and(pVBInfo->Part4Port, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004641
Peter Huewe6896b942012-02-09 21:11:46 +01004642 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004643 if (((pVBInfo->VBInfo &
Peter Huewe06cc47b2013-02-03 22:54:38 +01004644 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))) ||
4645 (XGI_EnableChISLCD(pVBInfo, false)) ||
4646 (XGI_IsLCDON(pVBInfo)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004647 /* LVDS Driver power down */
4648 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304649 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004650
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304651 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
Peter Huewea3d675c2012-02-09 21:11:47 +01004652 & (DisableCRT2Display | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304653 | SetSimuScanMode))) {
4654 if (pVBInfo->SetFlag & GatingCRT)
4655 XGI_EnableGatingCRT(HwDeviceExtension, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004656 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304657 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004658
Peter Huewea3d675c2012-02-09 21:11:47 +01004659 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304660 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
Peter Huewea3d675c2012-02-09 21:11:47 +01004661 & XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004662 /* Power down */
4663 xgifb_reg_and(pVBInfo->Part1Port, 0x1e, 0xdf);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304664 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004665
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004666 /* disable TV as primary VGA swap */
4667 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004668
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304669 if ((pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToDualEdge)))
Aaro Koskinendc505562011-03-13 12:26:26 +02004670 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004671
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004672 if ((pVBInfo->SetFlag & DisableChB) ||
4673 (pVBInfo->VBInfo &
4674 (DisableCRT2Display | SetSimuScanMode)) ||
Peter Huewea3d675c2012-02-09 21:11:47 +01004675 ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) &&
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004676 (pVBInfo->VBInfo &
4677 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004678 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004679
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004680 if ((pVBInfo->SetFlag & DisableChB) ||
4681 (pVBInfo->VBInfo &
4682 (DisableCRT2Display | SetSimuScanMode)) ||
Peter Huewea3d675c2012-02-09 21:11:47 +01004683 (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) ||
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004684 (pVBInfo->VBInfo &
4685 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))) {
4686 /* save Part1 index 0 */
4687 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
4688 /* BTDAC = 1, avoid VB reset */
4689 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x10);
4690 /* disable CRT2 */
4691 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
4692 /* restore Part1 index 0 */
4693 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304694 }
4695 } else { /* {301} */
4696 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004697 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
4698 /* Disable CRT2 */
4699 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
4700 /* Disable TV asPrimary VGA swap */
4701 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xDF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304702 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004703
Peter Huewea3d675c2012-02-09 21:11:47 +01004704 if (pVBInfo->VBInfo & (DisableCRT2Display | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304705 | SetSimuScanMode))
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004706 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304707 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004708}
4709
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004710/* --------------------------------------------------------------------- */
4711/* Function : XGI_GetTVPtrIndex */
4712/* Input : */
4713/* Output : */
4714/* Description : bx 0 : ExtNTSC */
4715/* 1 : StNTSC */
4716/* 2 : ExtPAL */
4717/* 3 : StPAL */
4718/* 4 : ExtHiTV */
4719/* 5 : StHiTV */
4720/* 6 : Ext525i */
4721/* 7 : St525i */
4722/* 8 : Ext525p */
4723/* 9 : St525p */
4724/* A : Ext750p */
4725/* B : St750p */
4726/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004727static unsigned short XGI_GetTVPtrIndex(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004728{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304729 unsigned short tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004730
Peter Huewe599801f2012-02-09 21:11:45 +01004731 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304732 tempbx = 2;
Peter Huewe599801f2012-02-09 21:11:45 +01004733 if (pVBInfo->TVInfo & TVSetHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304734 tempbx = 4;
Peter Huewe599801f2012-02-09 21:11:45 +01004735 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304736 tempbx = 6;
Peter Huewe599801f2012-02-09 21:11:45 +01004737 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304738 tempbx = 8;
Peter Huewe599801f2012-02-09 21:11:45 +01004739 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304740 tempbx = 10;
4741 if (pVBInfo->TVInfo & TVSimuMode)
4742 tempbx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004743
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304744 return tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004745}
4746
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004747/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004748/* Function : XGI_GetTVPtrIndex2 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004749/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004750/* Output : bx 0 : NTSC */
4751/* 1 : PAL */
4752/* 2 : PALM */
4753/* 3 : PALN */
4754/* 4 : NTSC1024x768 */
4755/* 5 : PAL-M 1024x768 */
4756/* 6-7: reserved */
4757/* cl 0 : YFilter1 */
4758/* 1 : YFilter2 */
4759/* ch 0 : 301A */
4760/* 1 : 301B/302B/301LV/302LV */
4761/* Description : */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004762/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004763static void XGI_GetTVPtrIndex2(unsigned short *tempbx, unsigned char *tempcl,
4764 unsigned char *tempch, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004765{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004766 *tempbx = 0;
4767 *tempcl = 0;
4768 *tempch = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004769
Peter Huewe599801f2012-02-09 21:11:45 +01004770 if (pVBInfo->TVInfo & TVSetPAL)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004771 *tempbx = 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004772
Peter Huewe599801f2012-02-09 21:11:45 +01004773 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004774 *tempbx = 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004775
Peter Huewe599801f2012-02-09 21:11:45 +01004776 if (pVBInfo->TVInfo & TVSetPALN)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004777 *tempbx = 3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004778
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004779 if (pVBInfo->TVInfo & NTSC1024x768) {
4780 *tempbx = 4;
Peter Huewe599801f2012-02-09 21:11:45 +01004781 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004782 *tempbx = 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304783 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004784
Peter Huewe6896b942012-02-09 21:11:46 +01004785 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4786 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004787 if ((!(pVBInfo->VBInfo & SetInSlaveMode)) || (pVBInfo->TVInfo
4788 & TVSimuMode)) {
4789 *tempbx += 8;
4790 *tempcl += 1;
4791 }
4792 }
4793
Peter Huewe6896b942012-02-09 21:11:46 +01004794 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4795 | VB_SIS302LV | VB_XGI301C))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004796 (*tempch)++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004797}
4798
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004799static void XGI_SetDelayComp(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004800{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304801 unsigned char tempah, tempbl, tempbh;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004802
Peter Huewe6896b942012-02-09 21:11:46 +01004803 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4804 | VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01004805 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304806 | SetCRT2ToTV | SetCRT2ToRAMDAC)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304807 tempbh = 0;
Peter Huewe03f76fc2012-06-14 00:21:50 +02004808 tempbl = XGI301TVDelay;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004809
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304810 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
4811 tempbl = tempbl >> 4;
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004812 if (pVBInfo->VBInfo &
4813 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Peter Huewe03f76fc2012-06-14 00:21:50 +02004814 tempbh = XGI301LCDDelay;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004815
Peter Huewea3d675c2012-02-09 21:11:47 +01004816 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304817 tempbl = tempbh;
4818 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004819
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304820 tempbl &= 0x0F;
4821 tempbh &= 0xF0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02004822 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2D);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004823
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304824 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD
4825 | SetCRT2ToTV)) { /* Channel B */
4826 tempah &= 0xF0;
4827 tempah |= tempbl;
4828 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004829
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004830 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
4831 /* Channel A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304832 tempah &= 0x0F;
4833 tempah |= tempbh;
4834 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02004835 xgifb_reg_set(pVBInfo->Part1Port, 0x2D, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304836 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304837 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004838}
4839
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004840static void XGI_SetLCDCap_A(unsigned short tempcx,
4841 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004842{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304843 unsigned short temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004844
Aaro Koskinen58839b02011-03-13 12:26:23 +02004845 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004846
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304847 if (temp & LCDRGB18Bit) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004848 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004849 /* Enable Dither */
4850 (unsigned short) (0x20 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004851 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304852 } else {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004853 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304854 (unsigned short) (0x30 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004855 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304856 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004857}
4858
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004859/* --------------------------------------------------------------------- */
4860/* Function : XGI_SetLCDCap_B */
4861/* Input : cx -> LCD Capability */
4862/* Output : */
4863/* Description : */
4864/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004865static void XGI_SetLCDCap_B(unsigned short tempcx,
4866 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004867{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304868 if (tempcx & EnableLCD24bpp) /* 24bits */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004869 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304870 (unsigned short) (((tempcx & 0x00ff) >> 6)
4871 | 0x0c));
4872 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004873 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304874 (unsigned short) (((tempcx & 0x00ff) >> 6)
4875 | 0x18)); /* Enable Dither */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004876}
4877
Aaro Koskinen7f04ec32011-11-27 23:03:05 +02004878static void XGI_LongWait(struct vb_device_info *pVBInfo)
4879{
4880 unsigned short i;
4881
4882 i = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
4883
4884 if (!(i & 0xC0)) {
4885 for (i = 0; i < 0xFFFF; i++) {
4886 if (!(inb(pVBInfo->P3da) & 0x08))
4887 break;
4888 }
4889
4890 for (i = 0; i < 0xFFFF; i++) {
4891 if ((inb(pVBInfo->P3da) & 0x08))
4892 break;
4893 }
4894 }
4895}
4896
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004897static void SetSpectrum(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004898{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304899 unsigned short index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004900
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304901 index = XGI_GetLCDCapPtr(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004902
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004903 /* disable down spectrum D[4] */
4904 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x8F);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304905 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004906 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x20); /* reset spectrum */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304907 XGI_LongWait(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004908
Aaro Koskinen8104e322011-03-13 12:26:22 +02004909 xgifb_reg_set(pVBInfo->Part4Port, 0x31,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304910 pVBInfo->LCDCapList[index].Spectrum_31);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004911 xgifb_reg_set(pVBInfo->Part4Port, 0x32,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304912 pVBInfo->LCDCapList[index].Spectrum_32);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004913 xgifb_reg_set(pVBInfo->Part4Port, 0x33,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304914 pVBInfo->LCDCapList[index].Spectrum_33);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004915 xgifb_reg_set(pVBInfo->Part4Port, 0x34,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304916 pVBInfo->LCDCapList[index].Spectrum_34);
4917 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004918 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x40); /* enable spectrum */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004919}
4920
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004921static void XGI_SetLCDCap(struct vb_device_info *pVBInfo)
4922{
4923 unsigned short tempcx;
4924
4925 tempcx = pVBInfo->LCDCapList[XGI_GetLCDCapPtr(pVBInfo)].LCD_Capability;
4926
Peter Huewef951dd02013-02-05 00:29:47 +01004927 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV |
4928 VB_SIS302LV | VB_XGI301C)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004929 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01004930 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004931 /* Set 301LV Capability */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004932 xgifb_reg_set(pVBInfo->Part4Port, 0x24,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004933 (unsigned char) (tempcx & 0x1F));
4934 }
4935 /* VB Driving */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004936 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004937 ~((EnableVBCLKDRVLOW | EnablePLLSPLOW) >> 8),
4938 (unsigned short) ((tempcx & (EnableVBCLKDRVLOW
4939 | EnablePLLSPLOW)) >> 8));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004940
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004941 if (pVBInfo->VBInfo & SetCRT2ToLCD)
4942 XGI_SetLCDCap_B(tempcx, pVBInfo);
Peter Huewea3d675c2012-02-09 21:11:47 +01004943 else if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004944 XGI_SetLCDCap_A(tempcx, pVBInfo);
4945
Peter Huewe6896b942012-02-09 21:11:46 +01004946 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004947 if (tempcx & EnableSpectrum)
4948 SetSpectrum(pVBInfo);
4949 }
4950 } else {
4951 /* LVDS,CH7017 */
4952 XGI_SetLCDCap_A(tempcx, pVBInfo);
4953 }
4954}
4955
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004956/* --------------------------------------------------------------------- */
4957/* Function : XGI_SetAntiFlicker */
4958/* Input : */
4959/* Output : */
4960/* Description : Set TV Customized Param. */
4961/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004962static void XGI_SetAntiFlicker(unsigned short ModeNo,
4963 unsigned short ModeIdIndex,
4964 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004965{
Aaro Koskinen36ae0352012-04-07 01:14:08 +03004966 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004967
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304968 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004969
Peter Huewe599801f2012-02-09 21:11:45 +01004970 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304971 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004972
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304973 tempbx = XGI_GetTVPtrIndex(pVBInfo);
4974 tempbx &= 0xFE;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304975 tempah = TVAntiFlickList[tempbx];
4976 tempah = tempah << 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004977
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004978 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0x8F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004979}
4980
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004981static void XGI_SetEdgeEnhance(unsigned short ModeNo,
4982 unsigned short ModeIdIndex,
4983 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004984{
Aaro Koskinen354f49f2012-04-07 01:14:09 +03004985 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004986
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304987 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004988
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304989 tempbx = XGI_GetTVPtrIndex(pVBInfo);
4990 tempbx &= 0xFE;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304991 tempah = TVEdgeList[tempbx];
4992 tempah = tempah << 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004993
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004994 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004995}
4996
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004997static void XGI_SetPhaseIncr(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004998{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304999 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005000
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305001 unsigned char tempcl, tempch;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005002
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305003 unsigned long tempData;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005004
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305005 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
5006 tempData = TVPhaseList[tempbx];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005007
Aaro Koskinen8104e322011-03-13 12:26:22 +02005008 xgifb_reg_set(pVBInfo->Part2Port, 0x31, (unsigned short) (tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305009 & 0x000000FF));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005010 xgifb_reg_set(pVBInfo->Part2Port, 0x32, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305011 & 0x0000FF00) >> 8));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005012 xgifb_reg_set(pVBInfo->Part2Port, 0x33, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305013 & 0x00FF0000) >> 16));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005014 xgifb_reg_set(pVBInfo->Part2Port, 0x34, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305015 & 0xFF000000) >> 24));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005016}
5017
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005018static void XGI_SetYFilter(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305019 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005020{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305021 unsigned short tempbx, index;
Aaro Koskinena68292f2012-11-04 21:15:07 +02005022 unsigned char const *filterPtr;
5023 unsigned char tempcl, tempch, tempal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005024
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305025 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005026
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305027 switch (tempbx) {
5028 case 0x00:
5029 case 0x04:
5030 filterPtr = NTSCYFilter1;
5031 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005032
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305033 case 0x01:
5034 filterPtr = PALYFilter1;
5035 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005036
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305037 case 0x02:
5038 case 0x05:
5039 case 0x0D:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305040 case 0x03:
Aaro Koskinen2555e942011-08-31 21:46:06 +03005041 filterPtr = xgifb_palmn_yfilter1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305042 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005043
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305044 case 0x08:
5045 case 0x0C:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305046 case 0x0A:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305047 case 0x0B:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305048 case 0x09:
Aaro Koskinen80f86f82011-08-31 21:46:05 +03005049 filterPtr = xgifb_yfilter2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305050 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005051
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305052 default:
5053 return;
5054 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005055
Aaro Koskinenb3979922012-11-04 21:14:52 +02005056 tempal = XGI330_EModeIDTable[ModeIdIndex].VB_ExtTVYFilterIndex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305057 if (tempcl == 0)
5058 index = tempal * 4;
5059 else
5060 index = tempal * 7;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005061
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305062 if ((tempcl == 0) && (tempch == 1)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005063 xgifb_reg_set(pVBInfo->Part2Port, 0x35, 0);
5064 xgifb_reg_set(pVBInfo->Part2Port, 0x36, 0);
5065 xgifb_reg_set(pVBInfo->Part2Port, 0x37, 0);
5066 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305067 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005068 xgifb_reg_set(pVBInfo->Part2Port, 0x35, filterPtr[index++]);
5069 xgifb_reg_set(pVBInfo->Part2Port, 0x36, filterPtr[index++]);
5070 xgifb_reg_set(pVBInfo->Part2Port, 0x37, filterPtr[index++]);
5071 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305072 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005073
Peter Huewe6896b942012-02-09 21:11:46 +01005074 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5075 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005076 xgifb_reg_set(pVBInfo->Part2Port, 0x48, filterPtr[index++]);
5077 xgifb_reg_set(pVBInfo->Part2Port, 0x49, filterPtr[index++]);
5078 xgifb_reg_set(pVBInfo->Part2Port, 0x4A, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305079 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005080}
5081
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005082/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005083/* Function : XGI_OEM310Setting */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005084/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005085/* Output : */
5086/* Description : Customized Param. for 301 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005087/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005088static void XGI_OEM310Setting(unsigned short ModeNo,
5089 unsigned short ModeIdIndex,
5090 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005091{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005092 XGI_SetDelayComp(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005093
Peter Huewea3d675c2012-02-09 21:11:47 +01005094 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005095 XGI_SetLCDCap(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005096
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005097 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005098 XGI_SetPhaseIncr(pVBInfo);
5099 XGI_SetYFilter(ModeNo, ModeIdIndex, pVBInfo);
5100 XGI_SetAntiFlicker(ModeNo, ModeIdIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005101
Peter Huewe6896b942012-02-09 21:11:46 +01005102 if (pVBInfo->VBType & VB_SIS301)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005103 XGI_SetEdgeEnhance(ModeNo, ModeIdIndex, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305104 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005105}
5106
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005107/* --------------------------------------------------------------------- */
5108/* Function : XGI_SetCRT2ModeRegs */
5109/* Input : */
5110/* Output : */
5111/* Description : Origin code for crt2group */
5112/* --------------------------------------------------------------------- */
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02005113static void XGI_SetCRT2ModeRegs(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305114 struct xgi_hw_device_info *HwDeviceExtension,
5115 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005116{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305117 unsigned short tempbl;
5118 short tempcl;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005119
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305120 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005121
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305122 tempah = 0;
5123 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005124 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305125 tempah &= ~0x10; /* BTRAMDAC */
5126 tempah |= 0x40; /* BTRAM */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005127
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305128 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
5129 | SetCRT2ToLCD)) {
5130 tempah = 0x40; /* BTDRAM */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005131 tempcl = pVBInfo->ModeType;
5132 tempcl -= ModeVGA;
5133 if (tempcl >= 0) {
5134 /* BT Color */
5135 tempah = (0x008 >> tempcl);
5136 if (tempah == 0)
5137 tempah = 1;
5138 tempah |= 0x040;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305139 }
5140 if (pVBInfo->VBInfo & SetInSlaveMode)
5141 tempah ^= 0x50; /* BTDAC */
5142 }
5143 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005144
Aaro Koskinen8104e322011-03-13 12:26:22 +02005145 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305146 tempah = 0x08;
5147 tempbl = 0xf0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005148
Miguel Gómeze123e462012-07-06 12:40:52 +02005149 if (pVBInfo->VBInfo & DisableCRT2Display)
5150 goto reg_and_or;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005151
Miguel Gómeze123e462012-07-06 12:40:52 +02005152 tempah = 0x00;
5153 tempbl = 0xff;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005154
Miguel Gómeze123e462012-07-06 12:40:52 +02005155 if (!(pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV |
5156 SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
5157 goto reg_and_or;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005158
Miguel Gómeze123e462012-07-06 12:40:52 +02005159 if ((pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) &&
5160 (!(pVBInfo->VBInfo & SetSimuScanMode))) {
5161 tempbl &= 0xf7;
5162 tempah |= 0x01;
5163 goto reg_and_or;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305164 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005165
Miguel Gómeze123e462012-07-06 12:40:52 +02005166 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
5167 tempbl &= 0xf7;
5168 tempah |= 0x01;
5169 }
5170
5171 if (!(pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD)))
5172 goto reg_and_or;
5173
5174 tempbl &= 0xf8;
5175 tempah = 0x01;
5176
5177 if (!(pVBInfo->VBInfo & SetInSlaveMode))
5178 tempah |= 0x02;
5179
5180 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
5181 tempah = tempah ^ 0x05;
5182 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
5183 tempah = tempah ^ 0x01;
5184 }
5185
5186 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
5187 tempah |= 0x08;
5188
5189reg_and_or:
5190 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl, tempah);
5191
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305192 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD
Peter Huewea3d675c2012-02-09 21:11:47 +01005193 | XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305194 tempah &= (~0x08);
5195 if ((pVBInfo->ModeType == ModeVGA) && (!(pVBInfo->VBInfo
5196 & SetInSlaveMode))) {
5197 tempah |= 0x010;
5198 }
5199 tempah |= 0x080;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005200
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305201 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305202 tempah |= 0x020;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005203 if (pVBInfo->VBInfo & DriverMode)
5204 tempah = tempah ^ 0x20;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305205 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005206
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005207 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D, ~0x0BF, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305208 tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005209
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305210 if (pVBInfo->LCDInfo & SetLCDDualLink)
5211 tempah |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005212
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305213 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305214 if (pVBInfo->TVInfo & RPLLDIV2XO)
5215 tempah |= 0x40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305216 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005217
Peter Huewe255aabd2012-02-09 21:11:44 +01005218 if ((pVBInfo->LCDResInfo == Panel_1280x1024)
5219 || (pVBInfo->LCDResInfo == Panel_1280x1024x75))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305220 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005221
Peter Huewe255aabd2012-02-09 21:11:44 +01005222 if (pVBInfo->LCDResInfo == Panel_1280x960)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305223 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005224
Aaro Koskinen8104e322011-03-13 12:26:22 +02005225 xgifb_reg_set(pVBInfo->Part4Port, 0x0C, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305226 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005227
Peter Huewe6896b942012-02-09 21:11:46 +01005228 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5229 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305230 tempah = 0;
5231 tempbl = 0xfb;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005232
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305233 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
5234 tempbl = 0xff;
Peter Huewea3d675c2012-02-09 21:11:47 +01005235 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305236 tempah |= 0x04; /* shampoo 0129 */
5237 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005238
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005239 xgifb_reg_and_or(pVBInfo->Part1Port, 0x13, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305240 tempah = 0x00;
5241 tempbl = 0xcf;
5242 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5243 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5244 tempah |= 0x30;
5245 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005246
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005247 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2c, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305248 tempah = 0;
5249 tempbl = 0x3f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005250
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305251 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5252 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5253 tempah |= 0xc0;
5254 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005255 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305256 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005257
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305258 tempah = 0;
5259 tempbl = 0x7f;
Peter Huewea3d675c2012-02-09 21:11:47 +01005260 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305261 tempbl = 0xff;
5262 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
5263 tempah |= 0x80;
5264 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005265
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005266 xgifb_reg_and_or(pVBInfo->Part4Port, 0x23, tempbl, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005267
Peter Huewe6896b942012-02-09 21:11:46 +01005268 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305269 if (pVBInfo->LCDInfo & SetLCDDualLink) {
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005270 xgifb_reg_or(pVBInfo->Part4Port, 0x27, 0x20);
5271 xgifb_reg_or(pVBInfo->Part4Port, 0x34, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305272 }
5273 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005274}
5275
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005276
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305277void XGI_UnLockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
5278 struct vb_device_info *pVBInfo)
5279{
5280
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005281 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2f, 0xFF, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005282
5283}
5284
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305285void XGI_LockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
5286 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005287{
5288
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005289 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2F, 0xFE, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005290
5291}
5292
Bill Pemberton80adad82010-06-17 13:10:51 -04005293unsigned char XGI_BridgeIsOn(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005294{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305295 unsigned short flag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005296
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305297 if (pVBInfo->IF_DEF_LVDS == 1) {
5298 return 1;
5299 } else {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005300 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305301 if ((flag == 1) || (flag == 2))
5302 return 1; /* 301b */
5303 else
5304 return 0;
5305 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005306}
5307
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005308unsigned short XGI_GetRatePtrCRT2(struct xgi_hw_device_info *pXGIHWDE,
5309 unsigned short ModeNo, unsigned short ModeIdIndex,
5310 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005311{
Peter Huewef2c22602013-02-03 22:54:30 +01005312 const u8 LCDARefreshIndex[] = {
5313 0x00, 0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x00 };
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005314
Peter Hueweef9a6b92013-02-03 04:08:43 +01005315 unsigned short RefreshRateTableIndex, i, index, temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005316
Aaro Koskinen58839b02011-03-13 12:26:23 +02005317 index = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005318 index = index >> pVBInfo->SelectCRT2Rate;
5319 index &= 0x0F;
5320
5321 if (pVBInfo->LCDInfo & LCDNonExpanding)
5322 index = 0;
5323
5324 if (index > 0)
5325 index--;
5326
5327 if (pVBInfo->SetFlag & ProgrammingCRT2) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005328 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005329 if (pVBInfo->IF_DEF_LVDS == 0) {
Peter Huewef2c22602013-02-03 22:54:30 +01005330 temp = LCDARefreshIndex[
5331 pVBInfo->LCDResInfo & 0x07];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005332
5333 if (index > temp)
5334 index = temp;
5335 } else {
5336 index = 0;
5337 }
5338 }
5339 }
5340
Aaro Koskinenb3979922012-11-04 21:14:52 +02005341 RefreshRateTableIndex = XGI330_EModeIDTable[ModeIdIndex].REFindex;
Aaro Koskinena39325d2012-11-04 21:14:53 +02005342 ModeNo = XGI330_RefIndex[RefreshRateTableIndex].ModeID;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005343 if (pXGIHWDE->jChipType >= XG20) { /* for XG20, XG21, XG27 */
Aaro Koskinena39325d2012-11-04 21:14:53 +02005344 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 800) &&
5345 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 600)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005346 index++;
5347 }
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005348 /* do the similar adjustment like XGISearchCRT1Rate() */
Aaro Koskinena39325d2012-11-04 21:14:53 +02005349 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 1024) &&
5350 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 768)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005351 index++;
5352 }
Aaro Koskinena39325d2012-11-04 21:14:53 +02005353 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 1280) &&
5354 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 1024)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005355 index++;
5356 }
5357 }
5358
5359 i = 0;
5360 do {
Aaro Koskinena39325d2012-11-04 21:14:53 +02005361 if (XGI330_RefIndex[RefreshRateTableIndex + i].
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005362 ModeID != ModeNo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005363 break;
Aaro Koskinena39325d2012-11-04 21:14:53 +02005364 temp = XGI330_RefIndex[RefreshRateTableIndex + i].Ext_InfoFlag;
Peter Huewe6896b942012-02-09 21:11:46 +01005365 temp &= ModeTypeMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005366 if (temp < pVBInfo->ModeType)
5367 break;
5368 i++;
5369 index--;
5370
5371 } while (index != 0xFFFF);
5372 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
5373 if (pVBInfo->VBInfo & SetInSlaveMode) {
Aaro Koskinena39325d2012-11-04 21:14:53 +02005374 temp = XGI330_RefIndex[RefreshRateTableIndex + i - 1].
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005375 Ext_InfoFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005376 if (temp & InterlaceMode)
5377 i++;
5378 }
5379 }
5380 i--;
5381 if ((pVBInfo->SetFlag & ProgrammingCRT2)) {
5382 temp = XGI_AjustCRT2Rate(ModeNo, ModeIdIndex,
5383 RefreshRateTableIndex, &i, pVBInfo);
5384 }
Aaro Koskinen9a0b2952011-11-27 23:03:16 +02005385 return RefreshRateTableIndex + i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005386}
5387
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005388static void XGI_SetLCDAGroup(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305389 struct xgi_hw_device_info *HwDeviceExtension,
5390 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005391{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005392 unsigned short RefreshRateTableIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005393
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005394 pVBInfo->SetFlag |= ProgrammingCRT2;
5395 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5396 ModeIdIndex, pVBInfo);
5397 XGI_GetLVDSResInfo(ModeNo, ModeIdIndex, pVBInfo);
5398 XGI_GetLVDSData(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5399 XGI_ModCRT1Regs(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5400 HwDeviceExtension, pVBInfo);
5401 XGI_SetLVDSRegs(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5402 XGI_SetCRT2ECLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005403}
5404
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02005405static unsigned char XGI_SetCRT2Group301(unsigned short ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005406 struct xgi_hw_device_info *HwDeviceExtension,
5407 struct vb_device_info *pVBInfo)
5408{
Peter Huewea9e29e62013-02-03 04:08:44 +01005409 unsigned short ModeIdIndex, RefreshRateTableIndex;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005410
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005411 pVBInfo->SetFlag |= ProgrammingCRT2;
5412 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
5413 pVBInfo->SelectCRT2Rate = 4;
5414 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5415 ModeIdIndex, pVBInfo);
5416 XGI_SaveCRT2Info(ModeNo, pVBInfo);
5417 XGI_GetCRT2ResInfo(ModeNo, ModeIdIndex, pVBInfo);
5418 XGI_GetCRT2Data(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5419 XGI_PreSetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
5420 RefreshRateTableIndex, pVBInfo);
5421 XGI_SetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
5422 RefreshRateTableIndex, pVBInfo);
5423 XGI_SetLockRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
5424 RefreshRateTableIndex, pVBInfo);
5425 XGI_SetGroup2(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5426 HwDeviceExtension, pVBInfo);
5427 XGI_SetLCDRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
5428 RefreshRateTableIndex, pVBInfo);
5429 XGI_SetTap4Regs(pVBInfo);
5430 XGI_SetGroup3(ModeNo, ModeIdIndex, pVBInfo);
5431 XGI_SetGroup4(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5432 HwDeviceExtension, pVBInfo);
5433 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5434 XGI_SetGroup5(ModeNo, ModeIdIndex, pVBInfo);
5435 XGI_AutoThreshold(pVBInfo);
5436 return 1;
5437}
5438
5439void XGI_SenseCRT1(struct vb_device_info *pVBInfo)
5440{
5441 unsigned char CRTCData[17] = { 0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81,
5442 0x0B, 0x3E, 0xE9, 0x0B, 0xDF, 0xE7, 0x04, 0x00, 0x00,
5443 0x05, 0x00 };
5444
5445 unsigned char SR01 = 0, SR1F = 0, SR07 = 0, SR06 = 0;
5446
5447 unsigned char CR17, CR63, SR31;
5448 unsigned short temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005449
5450 int i;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005451 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005452
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005453 /* to fix XG42 single LCD sense to CRT+LCD */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005454 xgifb_reg_set(pVBInfo->P3d4, 0x57, 0x4A);
Peter Huewe9388ad92013-02-15 20:37:10 +01005455 xgifb_reg_set(pVBInfo->P3d4, 0x53, (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005456 pVBInfo->P3d4, 0x53) | 0x02));
5457
Peter Huewe9388ad92013-02-15 20:37:10 +01005458 SR31 = xgifb_reg_get(pVBInfo->P3c4, 0x31);
5459 CR63 = xgifb_reg_get(pVBInfo->P3d4, 0x63);
5460 SR01 = xgifb_reg_get(pVBInfo->P3c4, 0x01);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005461
Aaro Koskinen8104e322011-03-13 12:26:22 +02005462 xgifb_reg_set(pVBInfo->P3c4, 0x01, (unsigned char) (SR01 & 0xDF));
5463 xgifb_reg_set(pVBInfo->P3d4, 0x63, (unsigned char) (CR63 & 0xBF));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005464
Peter Huewe9388ad92013-02-15 20:37:10 +01005465 CR17 = xgifb_reg_get(pVBInfo->P3d4, 0x17);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005466 xgifb_reg_set(pVBInfo->P3d4, 0x17, (unsigned char) (CR17 | 0x80));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005467
Peter Huewe9388ad92013-02-15 20:37:10 +01005468 SR1F = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005469 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) (SR1F | 0x04));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005470
Peter Huewe9388ad92013-02-15 20:37:10 +01005471 SR07 = xgifb_reg_get(pVBInfo->P3c4, 0x07);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005472 xgifb_reg_set(pVBInfo->P3c4, 0x07, (unsigned char) (SR07 & 0xFB));
Peter Huewe9388ad92013-02-15 20:37:10 +01005473 SR06 = xgifb_reg_get(pVBInfo->P3c4, 0x06);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005474 xgifb_reg_set(pVBInfo->P3c4, 0x06, (unsigned char) (SR06 & 0xC3));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005475
Aaro Koskinen8104e322011-03-13 12:26:22 +02005476 xgifb_reg_set(pVBInfo->P3d4, 0x11, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005477
5478 for (i = 0; i < 8; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005479 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) i, CRTCData[i]);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005480
5481 for (i = 8; i < 11; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005482 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 8),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005483 CRTCData[i]);
5484
5485 for (i = 11; i < 13; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005486 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 4),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005487 CRTCData[i]);
5488
5489 for (i = 13; i < 16; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005490 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i - 3),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005491 CRTCData[i]);
5492
Aaro Koskinen8104e322011-03-13 12:26:22 +02005493 xgifb_reg_set(pVBInfo->P3c4, 0x0E, (unsigned char) (CRTCData[16]
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005494 & 0xE0));
5495
Aaro Koskinen8104e322011-03-13 12:26:22 +02005496 xgifb_reg_set(pVBInfo->P3c4, 0x31, 0x00);
5497 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x1B);
5498 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE1);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005499
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005500 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005501
Peter Huewe771f3ee2013-02-15 20:37:13 +01005502 for (i = 0; i < 256 * 3; i++) {
5503 outb(0x0F, (pVBInfo->P3c8 + 1)); /* DAC_TEST_PARMS */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005504 }
5505
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005506 mdelay(1);
5507
5508 XGI_WaitDisply(pVBInfo);
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02005509 temp = inb(pVBInfo->P3c2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005510
5511 if (temp & 0x10)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005512 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005513 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005514 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005515
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005516 /* avoid display something, set BLACK DAC if not restore DAC */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005517 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005518
Peter Huewe771f3ee2013-02-15 20:37:13 +01005519 for (i = 0; i < 256 * 3; i++) {
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005520 outb(0, (pVBInfo->P3c8 + 1));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005521 }
5522
Aaro Koskinen8104e322011-03-13 12:26:22 +02005523 xgifb_reg_set(pVBInfo->P3c4, 0x01, SR01);
5524 xgifb_reg_set(pVBInfo->P3d4, 0x63, CR63);
5525 xgifb_reg_set(pVBInfo->P3c4, 0x31, SR31);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005526
Peter Huewe9388ad92013-02-15 20:37:10 +01005527 xgifb_reg_set(pVBInfo->P3d4, 0x53, (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005528 pVBInfo->P3d4, 0x53) & 0xFD));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005529 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) SR1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005530}
5531
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005532static void XGI_EnableBridge(struct xgifb_video_info *xgifb_info,
5533 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005534 struct vb_device_info *pVBInfo)
5535{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02005536 unsigned short tempah;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005537
Peter Huewe6896b942012-02-09 21:11:46 +01005538 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5539 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005540 if (!(pVBInfo->SetFlag & DisableChA)) {
Peter Huewe66b43eb2013-02-15 20:37:09 +01005541 if ((pVBInfo->SetFlag & EnableChA) ||
5542 (pVBInfo->VBInfo & SetCRT2ToDualEdge)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005543 /* Power on */
5544 xgifb_reg_set(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005545 }
5546 }
5547
5548 if (!(pVBInfo->SetFlag & DisableChB)) {
5549 if ((pVBInfo->SetFlag & EnableChB) || (pVBInfo->VBInfo
5550 & (SetCRT2ToLCD | SetCRT2ToTV
5551 | SetCRT2ToRAMDAC))) {
Peter Huewe9388ad92013-02-15 20:37:10 +01005552 tempah = xgifb_reg_get(pVBInfo->P3c4, 0x32);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005553 tempah &= 0xDF;
5554 if (pVBInfo->VBInfo & SetInSlaveMode) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005555 if (!(pVBInfo->VBInfo &
5556 SetCRT2ToRAMDAC))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005557 tempah |= 0x20;
5558 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02005559 xgifb_reg_set(pVBInfo->P3c4, 0x32, tempah);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005560 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005561
Peter Huewe9388ad92013-02-15 20:37:10 +01005562 tempah = xgifb_reg_get(pVBInfo->Part1Port,
5563 0x2E);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005564
5565 if (!(tempah & 0x80))
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005566 xgifb_reg_or(pVBInfo->Part1Port,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005567 0x2E, 0x80);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005568 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005569 }
5570 }
5571
5572 if ((pVBInfo->SetFlag & (EnableChA | EnableChB))
5573 || (!(pVBInfo->VBInfo & DisableCRT2Display))) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005574 xgifb_reg_and_or(pVBInfo->Part2Port, 0x00, ~0xE0,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005575 0x20); /* shampoo 0129 */
Peter Huewe6896b942012-02-09 21:11:46 +01005576 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Peter Huewe06cc47b2013-02-03 22:54:38 +01005577 if (!XGI_EnableChISLCD(pVBInfo, false)) {
5578 if (XGI_EnableChISLCD(pVBInfo, true) ||
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005579 (pVBInfo->VBInfo &
Peter Huewea3d675c2012-02-09 21:11:47 +01005580 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005581 /* LVDS PLL power on */
Aaro Koskinendc505562011-03-13 12:26:26 +02005582 xgifb_reg_and(
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005583 pVBInfo->Part4Port,
5584 0x2A,
5585 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005586 }
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005587 /* LVDS Driver power on */
5588 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005589 }
5590 }
5591
5592 tempah = 0x00;
5593
5594 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5595 tempah = 0xc0;
5596
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005597 if (!(pVBInfo->VBInfo & SetSimuScanMode) &&
5598 (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) &&
5599 (pVBInfo->VBInfo & SetCRT2ToDualEdge)) {
5600 tempah = tempah & 0x40;
5601 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
5602 tempah = tempah ^ 0xC0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005603
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005604 if (pVBInfo->SetFlag & DisableChB)
5605 tempah &= 0xBF;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005606
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005607 if (pVBInfo->SetFlag & DisableChA)
5608 tempah &= 0x7F;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005609
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005610 if (pVBInfo->SetFlag & EnableChB)
5611 tempah |= 0x40;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005612
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005613 if (pVBInfo->SetFlag & EnableChA)
5614 tempah |= 0x80;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005615 }
5616 }
5617
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005618 /* EnablePart4_1F */
5619 xgifb_reg_or(pVBInfo->Part4Port, 0x1F, tempah);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005620
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005621 if (!(pVBInfo->SetFlag & DisableChA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005622 if (!(pVBInfo->SetFlag & GatingCRT)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005623 XGI_DisableGatingCRT(HwDeviceExtension,
5624 pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005625 XGI_DisplayOn(xgifb_info, HwDeviceExtension,
5626 pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005627 }
5628 }
5629 } /* 301 */
5630 else { /* LVDS */
5631 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD
Peter Huewea3d675c2012-02-09 21:11:47 +01005632 | XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005633 /* enable CRT2 */
5634 xgifb_reg_or(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005635
Peter Huewe9388ad92013-02-15 20:37:10 +01005636 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2E);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005637 if (!(tempah & 0x80))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005638 xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005639
Aaro Koskinendc505562011-03-13 12:26:26 +02005640 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005641 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005642 } /* End of VB */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005643}
5644
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005645static void XGI_SetCRT1Group(struct xgifb_video_info *xgifb_info,
5646 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005647 unsigned short ModeNo, unsigned short ModeIdIndex,
5648 struct vb_device_info *pVBInfo)
5649{
Aaro Koskinena1579612012-04-07 01:14:05 +03005650 unsigned short RefreshRateTableIndex, temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005651
Aaro Koskinena1579612012-04-07 01:14:05 +03005652 XGI_SetSeqRegs(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinen3625c9a2012-11-04 21:14:51 +02005653 outb(XGI330_StandTable.MISC, pVBInfo->P3c2);
Aaro Koskinena1579612012-04-07 01:14:05 +03005654 XGI_SetCRTCRegs(HwDeviceExtension, pVBInfo);
5655 XGI_SetATTRegs(ModeNo, ModeIdIndex, pVBInfo);
5656 XGI_SetGRCRegs(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005657 XGI_ClearExt1Regs(pVBInfo);
5658
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005659 if (HwDeviceExtension->jChipType == XG27) {
5660 if (pVBInfo->IF_DEF_LVDS == 0)
5661 XGI_SetDefaultVCLK(pVBInfo);
5662 }
5663
5664 temp = ~ProgrammingCRT2;
5665 pVBInfo->SetFlag &= temp;
5666 pVBInfo->SelectCRT2Rate = 0;
5667
Peter Huewe6896b942012-02-09 21:11:46 +01005668 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5669 | VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005670 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005671 | SetInSlaveMode)) {
5672 pVBInfo->SetFlag |= ProgrammingCRT2;
5673 }
5674 }
5675
5676 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5677 ModeIdIndex, pVBInfo);
5678 if (RefreshRateTableIndex != 0xFFFF) {
5679 XGI_SetSync(RefreshRateTableIndex, pVBInfo);
5680 XGI_SetCRT1CRTC(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5681 pVBInfo, HwDeviceExtension);
5682 XGI_SetCRT1DE(HwDeviceExtension, ModeNo, ModeIdIndex,
5683 RefreshRateTableIndex, pVBInfo);
5684 XGI_SetCRT1Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5685 HwDeviceExtension, pVBInfo);
5686 XGI_SetCRT1VCLK(ModeNo, ModeIdIndex, HwDeviceExtension,
5687 RefreshRateTableIndex, pVBInfo);
5688 }
5689
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005690 if (HwDeviceExtension->jChipType >= XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005691 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005692 if (temp & 0xA0) {
5693
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005694 if (HwDeviceExtension->jChipType == XG27)
5695 XGI_SetXG27CRTC(ModeNo, ModeIdIndex,
5696 RefreshRateTableIndex, pVBInfo);
5697 else
5698 XGI_SetXG21CRTC(ModeNo, ModeIdIndex,
5699 RefreshRateTableIndex, pVBInfo);
5700
5701 XGI_UpdateXG21CRTC(ModeNo, pVBInfo,
5702 RefreshRateTableIndex);
5703
Aaro Koskinen105d8d02011-08-31 21:46:00 +03005704 xgifb_set_lcd(HwDeviceExtension->jChipType,
5705 pVBInfo, RefreshRateTableIndex, ModeNo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005706
Aaro Koskinen64db29f2011-08-31 21:46:01 +03005707 if (pVBInfo->IF_DEF_LVDS == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005708 xgifb_set_lvds(xgifb_info,
5709 HwDeviceExtension->jChipType,
Aaro Koskinen64db29f2011-08-31 21:46:01 +03005710 ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005711 }
5712 }
5713
5714 pVBInfo->SetFlag &= (~ProgrammingCRT2);
5715 XGI_SetCRT1FIFO(ModeNo, HwDeviceExtension, pVBInfo);
5716 XGI_SetCRT1ModeRegs(HwDeviceExtension, ModeNo, ModeIdIndex,
5717 RefreshRateTableIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005718 XGI_LoadDAC(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005719}
5720
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005721unsigned char XGISetModeNew(struct xgifb_video_info *xgifb_info,
5722 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005723 unsigned short ModeNo)
5724{
5725 unsigned short ModeIdIndex;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005726 struct vb_device_info VBINF;
5727 struct vb_device_info *pVBInfo = &VBINF;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005728 pVBInfo->IF_DEF_LVDS = 0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005729
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005730 if (HwDeviceExtension->jChipType >= XG20) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005731 pVBInfo->IF_DEF_YPbPr = 0;
5732 pVBInfo->IF_DEF_HiVision = 0;
5733 pVBInfo->IF_DEF_CRT2Monitor = 0;
5734 pVBInfo->VBType = 0; /*set VBType default 0*/
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005735 } else {
5736 pVBInfo->IF_DEF_YPbPr = 1;
5737 pVBInfo->IF_DEF_HiVision = 1;
Aaro Koskinen06587332011-03-13 12:26:10 +02005738 pVBInfo->IF_DEF_CRT2Monitor = 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005739 }
5740
Aaro Koskinen56810a92013-01-21 02:57:47 +02005741 XGIRegInit(pVBInfo, xgifb_info->vga_base);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005742
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005743 /* for x86 Linux, XG21 LVDS */
5744 if (HwDeviceExtension->jChipType == XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005745 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005746 pVBInfo->IF_DEF_LVDS = 1;
5747 }
5748 if (HwDeviceExtension->jChipType == XG27) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005749 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0) {
5750 if (xgifb_reg_get(pVBInfo->P3d4, 0x30) & 0x20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005751 pVBInfo->IF_DEF_LVDS = 1;
5752 }
5753 }
5754
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005755 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005756 XGI_GetVBType(pVBInfo);
5757
5758 InitTo330Pointer(HwDeviceExtension->jChipType, pVBInfo);
Aaro Koskinenef497f42011-11-27 23:03:21 +02005759 if (ModeNo & 0x80)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005760 ModeNo = ModeNo & 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005761 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005762
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005763 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005764 XGI_UnLockCRT2(HwDeviceExtension, pVBInfo);
5765
5766 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
5767
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005768 if (HwDeviceExtension->jChipType < XG20) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005769 XGI_GetVBInfo(ModeNo, ModeIdIndex, HwDeviceExtension, pVBInfo);
5770 XGI_GetTVInfo(ModeNo, ModeIdIndex, pVBInfo);
5771 XGI_GetLCDInfo(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005772 XGI_DisableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005773
Peter Huewee44adfd2013-02-03 22:54:39 +01005774 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA) ||
5775 (!(pVBInfo->VBInfo & SwitchCRT2))) {
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005776 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005777 ModeIdIndex, pVBInfo);
5778
Peter Huewea3d675c2012-02-09 21:11:47 +01005779 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005780 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
5781 HwDeviceExtension, pVBInfo);
5782 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005783 }
5784
Peter Huewe6896b942012-02-09 21:11:46 +01005785 if (pVBInfo->VBInfo & (SetSimuScanMode | SwitchCRT2)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005786 switch (HwDeviceExtension->ujVBChipID) {
Peter Huewee44adfd2013-02-03 22:54:39 +01005787 case VB_CHIP_301: /* fall through */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005788 case VB_CHIP_302:
5789 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
5790 pVBInfo); /*add for CRT2 */
5791 break;
5792
5793 default:
5794 break;
5795 }
5796 }
5797
5798 XGI_SetCRT2ModeRegs(ModeNo, HwDeviceExtension, pVBInfo);
5799 XGI_OEM310Setting(ModeNo, ModeIdIndex, pVBInfo); /*0212*/
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005800 XGI_EnableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005801 } /* !XG20 */
5802 else {
5803 if (pVBInfo->IF_DEF_LVDS == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005804 if (!XGI_XG21CheckLVDSMode(xgifb_info, ModeNo,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005805 ModeIdIndex,
5806 pVBInfo))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005807 return 0;
5808
Aaro Koskinenb3979922012-11-04 21:14:52 +02005809 pVBInfo->ModeType = XGI330_EModeIDTable[ModeIdIndex].
Peter Huewe6896b942012-02-09 21:11:46 +01005810 Ext_ModeFlag & ModeTypeMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005811
5812 pVBInfo->SetFlag = 0;
Aaro Koskinen83f76a92011-08-31 21:45:58 +03005813 pVBInfo->VBInfo = DisableCRT2Display;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005814
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005815 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005816
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005817 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
5818 ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005819
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005820 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005821 }
5822
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005823 XGI_UpdateModeInfo(HwDeviceExtension, pVBInfo);
5824
Miguel Gómez3bcc2462012-07-06 12:40:53 +02005825 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005826 XGI_LockCRT2(HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005827
5828 return 1;
5829}