blob: e469a8e7906f03ff846086764afa1966788387d0 [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"
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005#include "vb_util.h"
6#include "vb_table.h"
Miguel Gómeze0541022012-06-18 13:12:05 +02007#include "vb_setmode.h"
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02008
9#define IndexMask 0xff
Peter Huewe95072592012-06-14 00:21:48 +020010#define TVCLKBASE_315_25 (TVCLKBASE_315 + 25)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020011
Aaro Koskinen624554d2011-10-11 21:47:35 +030012static const unsigned short XGINew_VGA_DAC[] = {
Bill Pemberton82d6eb52010-06-17 13:10:46 -040013 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
14 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F,
15 0x00, 0x05, 0x08, 0x0B, 0x0E, 0x11, 0x14, 0x18,
16 0x1C, 0x20, 0x24, 0x28, 0x2D, 0x32, 0x38, 0x3F,
17 0x00, 0x10, 0x1F, 0x2F, 0x3F, 0x1F, 0x27, 0x2F,
18 0x37, 0x3F, 0x2D, 0x31, 0x36, 0x3A, 0x3F, 0x00,
19 0x07, 0x0E, 0x15, 0x1C, 0x0E, 0x11, 0x15, 0x18,
20 0x1C, 0x14, 0x16, 0x18, 0x1A, 0x1C, 0x00, 0x04,
21 0x08, 0x0C, 0x10, 0x08, 0x0A, 0x0C, 0x0E, 0x10,
22 0x0B, 0x0C, 0x0D, 0x0F, 0x10};
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020023
Bill Pemberton80adad82010-06-17 13:10:51 -040024void InitTo330Pointer(unsigned char ChipType, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020025{
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +030026 pVBInfo->MCLKData = XGI340New_MCLKData;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020027
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053028 pVBInfo->LCDResInfo = 0;
29 pVBInfo->LCDTypeInfo = 0;
30 pVBInfo->LCDInfo = 0;
31 pVBInfo->VBInfo = 0;
32 pVBInfo->TVInfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020033
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053034 pVBInfo->SR15 = XGI340_SR13;
35 pVBInfo->CR40 = XGI340_cr41;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020036
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053037 /* 310 customization related */
Peter Huewe6896b942012-02-09 21:11:46 +010038 if ((pVBInfo->VBType & VB_SIS301LV) || (pVBInfo->VBType & VB_SIS302LV))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053039 pVBInfo->LCDCapList = XGI_LCDDLCapList;
40 else
41 pVBInfo->LCDCapList = XGI_LCDCapList;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020042
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053043 if (ChipType >= XG20)
Peter Huewe6d12dae2012-06-14 00:21:52 +020044 pVBInfo->XGINew_CR97 = 0x10;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020045
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053046 if (ChipType == XG27) {
Dmitry Eremin-Solenikov64903112012-03-19 21:50:09 +040047 unsigned char temp;
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +030048 pVBInfo->MCLKData = XGI27New_MCLKData;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053049 pVBInfo->CR40 = XGI27_cr41;
Peter Huewe6d12dae2012-06-14 00:21:52 +020050 pVBInfo->XGINew_CR97 = 0xc1;
Dmitry Eremin-Solenikov64903112012-03-19 21:50:09 +040051 pVBInfo->SR15 = XG27_SR13;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020052
Dmitry Eremin-Solenikov64903112012-03-19 21:50:09 +040053 /*Z11m DDR*/
54 temp = xgifb_reg_get(pVBInfo->P3c4, 0x3B);
55 /* SR3B[7][3]MAA15 MAA11 (Power on Trapping) */
56 if (((temp & 0x88) == 0x80) || ((temp & 0x88) == 0x08))
Peter Huewe6d12dae2012-06-14 00:21:52 +020057 pVBInfo->XGINew_CR97 = 0x80;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053058 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020059
60}
61
Kenji Toyama1d7f6562011-04-23 19:36:49 +080062static void XGI_SetSeqRegs(unsigned short ModeNo,
Kenji Toyama1d7f6562011-04-23 19:36:49 +080063 unsigned short ModeIdIndex,
64 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020065{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053066 unsigned char tempah, SRdata;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053067 unsigned short i, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020068
Aaro Koskinenb3979922012-11-04 21:14:52 +020069 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020070
Aaro Koskinen8104e322011-03-13 12:26:22 +020071 xgifb_reg_set(pVBInfo->P3c4, 0x00, 0x03); /* Set SR0 */
Aaro Koskinen3625c9a2012-11-04 21:14:51 +020072 tempah = XGI330_StandTable.SR[0];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020073
Peter Huewea3d675c2012-02-09 21:11:47 +010074 i = XGI_SetCRT2ToLCDA;
75 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053076 tempah |= 0x01;
Aaro Koskinend3ae5762012-09-11 00:15:27 +030077 } else if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD)) {
78 if (pVBInfo->VBInfo & SetInSlaveMode)
79 tempah |= 0x01;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053080 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020081
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053082 tempah |= 0x20; /* screen off */
Aaro Koskinen8104e322011-03-13 12:26:22 +020083 xgifb_reg_set(pVBInfo->P3c4, 0x01, tempah); /* Set SR1 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020084
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053085 for (i = 02; i <= 04; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +080086 /* Get SR2,3,4 from file */
Aaro Koskinen3625c9a2012-11-04 21:14:51 +020087 SRdata = XGI330_StandTable.SR[i - 1];
Aaro Koskinen8104e322011-03-13 12:26:22 +020088 xgifb_reg_set(pVBInfo->P3c4, i, SRdata); /* Set SR2 3 4 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053089 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020090}
91
Aaro Koskinen063b9c42011-03-08 22:16:13 +020092static void XGI_SetCRTCRegs(struct xgi_hw_device_info *HwDeviceExtension,
Kenji Toyama1d7f6562011-04-23 19:36:49 +080093 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020094{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053095 unsigned char CRTCdata;
96 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020097
Aaro Koskinen58839b02011-03-13 12:26:23 +020098 CRTCdata = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053099 CRTCdata &= 0x7f;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200100 xgifb_reg_set(pVBInfo->P3d4, 0x11, CRTCdata); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200101
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530102 for (i = 0; i <= 0x18; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800103 /* Get CRTC from file */
Aaro Koskinen3625c9a2012-11-04 21:14:51 +0200104 CRTCdata = XGI330_StandTable.CRTC[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200105 xgifb_reg_set(pVBInfo->P3d4, i, CRTCdata); /* Set CRTC(3d4) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530106 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200107}
108
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800109static void XGI_SetATTRegs(unsigned short ModeNo,
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800110 unsigned short ModeIdIndex,
111 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200112{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530113 unsigned char ARdata;
114 unsigned short i, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200115
Aaro Koskinenb3979922012-11-04 21:14:52 +0200116 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200117
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530118 for (i = 0; i <= 0x13; i++) {
Aaro Koskinen3625c9a2012-11-04 21:14:51 +0200119 ARdata = XGI330_StandTable.ATTR[i];
Miguel Gómez661a6382012-07-06 12:40:45 +0200120
121 if ((modeflag & Charx8Dot) && i == 0x13) { /* ifndef Dot9 */
122 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
123 ARdata = 0;
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300124 } else if ((pVBInfo->VBInfo &
Miguel Gómez661a6382012-07-06 12:40:45 +0200125 (SetCRT2ToTV | SetCRT2ToLCD)) &&
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300126 (pVBInfo->VBInfo & SetInSlaveMode)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530127 ARdata = 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530128 }
129 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200130
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200131 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200132 outb(i, pVBInfo->P3c0); /* set index */
133 outb(ARdata, pVBInfo->P3c0); /* set data */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530134 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200135
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200136 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200137 outb(0x14, pVBInfo->P3c0); /* set index */
138 outb(0x00, pVBInfo->P3c0); /* set data */
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200139 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200140 outb(0x20, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200141}
142
Aaro Koskinena1579612012-04-07 01:14:05 +0300143static void XGI_SetGRCRegs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200144{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530145 unsigned char GRdata;
146 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200147
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530148 for (i = 0; i <= 0x08; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800149 /* Get GR from file */
Aaro Koskinen3625c9a2012-11-04 21:14:51 +0200150 GRdata = XGI330_StandTable.GRC[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200151 xgifb_reg_set(pVBInfo->P3ce, i, GRdata); /* Set GR(3ce) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530152 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200153
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530154 if (pVBInfo->ModeType > ModeVGA) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200155 GRdata = (unsigned char) xgifb_reg_get(pVBInfo->P3ce, 0x05);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530156 GRdata &= 0xBF; /* 256 color disable */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200157 xgifb_reg_set(pVBInfo->P3ce, 0x05, GRdata);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530158 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200159}
160
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200161static void XGI_ClearExt1Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200162{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530163 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200164
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530165 for (i = 0x0A; i <= 0x0E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +0200166 xgifb_reg_set(pVBInfo->P3c4, i, 0x00); /* Clear SR0A-SR0E */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200167}
168
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200169static unsigned char XGI_SetDefaultVCLK(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200170{
171
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200172 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x20);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200173 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[0].SR2B);
174 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[0].SR2C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200175
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200176 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x10);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200177 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[1].SR2B);
178 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[1].SR2C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200179
Aaro Koskinendc505562011-03-13 12:26:26 +0200180 xgifb_reg_and(pVBInfo->P3c4, 0x31, ~0x30);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530181 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200182}
183
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200184static unsigned char XGI_AjustCRT2Rate(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530185 unsigned short ModeIdIndex,
186 unsigned short RefreshRateTableIndex, unsigned short *i,
187 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200188{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530189 unsigned short tempax, tempbx, resinfo, modeflag, infoflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200190
Aaro Koskinenb3979922012-11-04 21:14:52 +0200191 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
192 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinena39325d2012-11-04 21:14:53 +0200193 tempbx = XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530194 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200195
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530196 if (pVBInfo->IF_DEF_LVDS == 0) {
197 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
198 tempax |= SupportRAMDAC2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200199
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530200 if (pVBInfo->VBType & VB_XGI301C)
201 tempax |= SupportCRT2in301C;
202 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200203
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800204 /* 301b */
Peter Huewea3d675c2012-02-09 21:11:47 +0100205 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530206 tempax |= SupportLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200207
Miguel Gómez3b175622012-07-06 12:40:46 +0200208 if (pVBInfo->LCDResInfo != Panel_1280x1024 &&
209 pVBInfo->LCDResInfo != Panel_1280x960 &&
210 (pVBInfo->LCDInfo & LCDNonExpanding) &&
211 resinfo >= 9)
212 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530213 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200214
Peter Huewe599801f2012-02-09 21:11:45 +0100215 if (pVBInfo->VBInfo & SetCRT2ToHiVision) { /* for HiTV */
Aaro Koskinen31fb40f2012-09-11 00:15:15 +0300216 tempax |= SupportHiVision;
217 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
218 ((resinfo == 4) ||
219 (resinfo == 3 &&
220 (pVBInfo->SetFlag & TVSimuMode)) ||
221 (resinfo > 7)))
Miguel Gómez3b175622012-07-06 12:40:46 +0200222 return 0;
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300223 } else if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO |
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800224 SetCRT2ToSVIDEO |
225 SetCRT2ToSCART |
Peter Huewe599801f2012-02-09 21:11:45 +0100226 SetCRT2ToYPbPr525750 |
227 SetCRT2ToHiVision)) {
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300228 tempax |= SupportTV;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200229
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300230 if (pVBInfo->VBType & (VB_SIS301B |
231 VB_SIS302B |
232 VB_SIS301LV |
233 VB_SIS302LV |
234 VB_XGI301C))
235 tempax |= SupportTV1024;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200236
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300237 if (!(pVBInfo->VBInfo & TVSetPAL) &&
238 (modeflag & NoSupportSimuTV) &&
239 (pVBInfo->VBInfo & SetInSlaveMode) &&
240 (!(pVBInfo->VBInfo & SetNotSimuMode)))
241 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530242 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300243 } else if (pVBInfo->VBInfo & SetCRT2ToLCD) { /* for LVDS */
244 tempax |= SupportLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200245
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300246 if (resinfo > 0x08)
247 return 0; /* 1024x768 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200248
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300249 if (pVBInfo->LCDResInfo < Panel_1024x768) {
250 if (resinfo > 0x07)
251 return 0; /* 800x600 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200252
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300253 if (resinfo == 0x04)
254 return 0; /* 512x384 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530255 }
256 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200257
Aaro Koskinena39325d2012-11-04 21:14:53 +0200258 for (; XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID ==
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800259 tempbx; (*i)--) {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200260 infoflag = XGI330_RefIndex[RefreshRateTableIndex + (*i)].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800261 Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530262 if (infoflag & tempax)
263 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200264
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530265 if ((*i) == 0)
266 break;
267 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200268
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530269 for ((*i) = 0;; (*i)++) {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200270 infoflag = XGI330_RefIndex[RefreshRateTableIndex + (*i)].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800271 Ext_InfoFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +0200272 if (XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530273 != tempbx) {
274 return 0;
275 }
276
277 if (infoflag & tempax)
278 return 1;
279 }
280 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200281}
282
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200283static void XGI_SetSync(unsigned short RefreshRateTableIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530284 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200285{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530286 unsigned short sync, temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200287
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800288 /* di+0x00 */
Aaro Koskinena39325d2012-11-04 21:14:53 +0200289 sync = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag >> 8;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530290 sync &= 0xC0;
291 temp = 0x2F;
292 temp |= sync;
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200293 outb(temp, pVBInfo->P3c2); /* Set Misc(3c2) */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200294}
295
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200296static void XGI_SetCRT1Timing_H(struct vb_device_info *pVBInfo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530297 struct xgi_hw_device_info *HwDeviceExtension)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200298{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530299 unsigned char data, data1, pushax;
300 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200301
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800302 /* unlock cr0-7 */
303 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530304 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200305 xgifb_reg_set(pVBInfo->P3d4, 0x11, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200306
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200307 data = pVBInfo->TimingH.data[0];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200308 xgifb_reg_set(pVBInfo->P3d4, 0, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200309
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530310 for (i = 0x01; i <= 0x04; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200311 data = pVBInfo->TimingH.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200312 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 1), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530313 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200314
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530315 for (i = 0x05; i <= 0x06; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200316 data = pVBInfo->TimingH.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200317 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i + 6), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530318 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200319
Aaro Koskinen58839b02011-03-13 12:26:23 +0200320 j = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530321 j &= 0x1F;
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200322 data = pVBInfo->TimingH.data[7];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530323 data &= 0xE0;
324 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200325 xgifb_reg_set(pVBInfo->P3c4, 0x0e, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200326
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530327 if (HwDeviceExtension->jChipType >= XG20) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200328 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530329 data = data - 1;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200330 xgifb_reg_set(pVBInfo->P3d4, 0x04, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200331 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x05);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530332 data1 = data;
333 data1 &= 0xE0;
334 data &= 0x1F;
335 if (data == 0) {
336 pushax = data;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200337 data = (unsigned char) xgifb_reg_get(pVBInfo->P3c4,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530338 0x0c);
339 data &= 0xFB;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200340 xgifb_reg_set(pVBInfo->P3c4, 0x0c, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530341 data = pushax;
342 }
343 data = data - 1;
344 data |= data1;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200345 xgifb_reg_set(pVBInfo->P3d4, 0x05, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200346 data = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530347 data = data >> 5;
348 data = data + 3;
349 if (data > 7)
350 data = data - 7;
351 data = data << 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200352 xgifb_reg_and_or(pVBInfo->P3c4, 0x0e, ~0xE0, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530353 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200354}
355
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800356static void XGI_SetCRT1Timing_V(unsigned short ModeIdIndex,
357 unsigned short ModeNo,
358 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200359{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530360 unsigned char data;
361 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200362
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530363 for (i = 0x00; i <= 0x01; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200364 data = pVBInfo->TimingV.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200365 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 6), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530366 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200367
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530368 for (i = 0x02; i <= 0x03; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200369 data = pVBInfo->TimingV.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200370 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x0e), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530371 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200372
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530373 for (i = 0x04; i <= 0x05; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200374 data = pVBInfo->TimingV.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200375 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x11), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530376 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200377
Aaro Koskinen58839b02011-03-13 12:26:23 +0200378 j = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0a);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530379 j &= 0xC0;
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200380 data = pVBInfo->TimingV.data[6];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530381 data &= 0x3F;
382 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200383 xgifb_reg_set(pVBInfo->P3c4, 0x0a, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200384
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200385 data = pVBInfo->TimingV.data[6];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530386 data &= 0x80;
387 data = data >> 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200388
Aaro Koskinenb3979922012-11-04 21:14:52 +0200389 i = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530390 i &= DoubleScanMode;
391 if (i)
392 data |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200393
Aaro Koskinen58839b02011-03-13 12:26:23 +0200394 j = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x09);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530395 j &= 0x5F;
396 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200397 xgifb_reg_set(pVBInfo->P3d4, 0x09, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200398}
399
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200400static void XGI_SetCRT1CRTC(unsigned short ModeNo, unsigned short ModeIdIndex,
401 unsigned short RefreshRateTableIndex,
402 struct vb_device_info *pVBInfo,
403 struct xgi_hw_device_info *HwDeviceExtension)
404{
405 unsigned char index, data;
406 unsigned short i;
407
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800408 /* Get index */
Aaro Koskinena39325d2012-11-04 21:14:53 +0200409 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200410 index = index & IndexMask;
411
Aaro Koskinen58839b02011-03-13 12:26:23 +0200412 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200413 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200414 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200415
416 for (i = 0; i < 8; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200417 pVBInfo->TimingH.data[i]
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200418 = XGI_CRT1Table[index].CR[i];
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200419
420 for (i = 0; i < 7; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200421 pVBInfo->TimingV.data[i]
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200422 = XGI_CRT1Table[index].CR[i + 8];
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200423
424 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
425
426 XGI_SetCRT1Timing_V(ModeIdIndex, ModeNo, pVBInfo);
427
428 if (pVBInfo->ModeType > 0x03)
Aaro Koskinen8104e322011-03-13 12:26:22 +0200429 xgifb_reg_set(pVBInfo->P3d4, 0x14, 0x4F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200430}
431
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200432/* --------------------------------------------------------------------- */
433/* Function : XGI_SetXG21CRTC */
434/* Input : Stand or enhance CRTC table */
435/* Output : Fill CRT Hsync/Vsync to SR2E/SR2F/SR30/SR33/SR34/SR3F */
436/* Description : Set LCD timing */
437/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200438static void XGI_SetXG21CRTC(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530439 unsigned short RefreshRateTableIndex,
440 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200441{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300442 unsigned char index, Tempax, Tempbx, Tempcx, Tempdx;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530443 unsigned short Temp1, Temp2, Temp3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200444
Aaro Koskinena39325d2012-11-04 21:14:53 +0200445 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300446 /* Tempax: CR4 HRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200447 Tempax = XGI_CRT1Table[index].CR[3];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300448 Tempcx = Tempax; /* Tempcx: HRS */
449 /* SR2E[7:0]->HRS */
450 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200451
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200452 Tempdx = XGI_CRT1Table[index].CR[5]; /* SRB */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300453 Tempdx &= 0xC0; /* Tempdx[7:6]: SRB[7:6] */
454 Temp1 = Tempdx; /* Temp1[7:6]: HRS[9:8] */
455 Temp1 <<= 2; /* Temp1[9:8]: HRS[9:8] */
456 Temp1 |= Tempax; /* Temp1[9:0]: HRS[9:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800457
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200458 Tempax = XGI_CRT1Table[index].CR[4]; /* CR5 HRE */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300459 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200460
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200461 Tempbx = XGI_CRT1Table[index].CR[6]; /* SRC */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300462 Tempbx &= 0x04; /* Tempbx[2]: HRE[5] */
463 Tempbx <<= 3; /* Tempbx[5]: HRE[5] */
464 Tempax |= Tempbx; /* Tempax[5:0]: HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200465
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300466 Temp2 = Temp1 & 0x3C0; /* Temp2[9:6]: HRS[9:6] */
467 Temp2 |= Tempax; /* Temp2[9:0]: HRE[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200468
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300469 Tempcx &= 0x3F; /* Tempcx[5:0]: HRS[5:0] */
470 if (Tempax < Tempcx) /* HRE < HRS */
471 Temp2 |= 0x40; /* Temp2 + 0x40 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200472
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300473 Temp2 &= 0xFF;
474 Tempax = (unsigned char) Temp2; /* Tempax: HRE[7:0] */
475 Tempax <<= 2; /* Tempax[7:2]: HRE[5:0] */
476 Tempdx >>= 6; /* Tempdx[7:6]->[1:0] HRS[9:8] */
477 Tempax |= Tempdx; /* HRE[5:0]HRS[9:8] */
478 /* SR2F D[7:2]->HRE, D[1:0]->HRS */
479 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
480 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200481
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300482 /* CR10 VRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200483 Tempax = XGI_CRT1Table[index].CR[10];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300484 Tempbx = Tempax; /* Tempbx: VRS */
485 Tempax &= 0x01; /* Tempax[0]: VRS[0] */
486 xgifb_reg_or(pVBInfo->P3c4, 0x33, Tempax); /* SR33[0]->VRS[0] */
487 /* CR7[2][7] VRE */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200488 Tempax = XGI_CRT1Table[index].CR[9];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300489 Tempcx = Tempbx >> 1; /* Tempcx[6:0]: VRS[7:1] */
490 Tempdx = Tempax & 0x04; /* Tempdx[2]: CR7[2] */
491 Tempdx <<= 5; /* Tempdx[7]: VRS[8] */
492 Tempcx |= Tempdx; /* Tempcx[7:0]: VRS[8:1] */
493 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempcx); /* SR34[8:1]->VRS */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200494
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300495 Temp1 = Tempdx; /* Temp1[7]: Tempdx[7] */
496 Temp1 <<= 1; /* Temp1[8]: VRS[8] */
497 Temp1 |= Tempbx; /* Temp1[8:0]: VRS[8:0] */
498 Tempax &= 0x80;
499 Temp2 = Tempax << 2; /* Temp2[9]: VRS[9] */
500 Temp1 |= Temp2; /* Temp1[9:0]: VRS[9:0] */
501 /* Tempax: SRA */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200502 Tempax = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300503 Tempax &= 0x08; /* Tempax[3]: VRS[3] */
504 Temp2 = Tempax;
505 Temp2 <<= 7; /* Temp2[10]: VRS[10] */
506 Temp1 |= Temp2; /* Temp1[10:0]: VRS[10:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200507
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300508 /* Tempax: CR11 VRE */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200509 Tempax = XGI_CRT1Table[index].CR[11];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300510 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
511 /* Tempbx: SRA */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200512 Tempbx = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300513 Tempbx &= 0x20; /* Tempbx[5]: VRE[5] */
514 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
515 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
516 Temp2 = Temp1 & 0x7E0; /* Temp2[10:5]: VRS[10:5] */
517 Temp2 |= Tempax; /* Temp2[10:5]: VRE[10:5] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200518
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300519 Temp3 = Temp1 & 0x1F; /* Temp3[4:0]: VRS[4:0] */
520 if (Tempax < Temp3) /* VRE < VRS */
521 Temp2 |= 0x20; /* VRE + 0x20 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200522
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300523 Temp2 &= 0xFF;
524 Tempax = (unsigned char) Temp2; /* Tempax: VRE[7:0] */
525 Tempax <<= 2; /* Tempax[7:0]; VRE[5:0]00 */
526 Temp1 &= 0x600; /* Temp1[10:9]: VRS[10:9] */
527 Temp1 >>= 9; /* Temp1[1:0]: VRS[10:9] */
528 Tempbx = (unsigned char) Temp1;
529 Tempax |= Tempbx; /* Tempax[7:0]: VRE[5:0]VRS[10:9] */
530 Tempax &= 0x7F;
531 /* SR3F D[7:2]->VRE D[1:0]->VRS */
532 xgifb_reg_set(pVBInfo->P3c4, 0x3F, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200533}
534
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800535static void XGI_SetXG27CRTC(unsigned short ModeNo,
536 unsigned short ModeIdIndex,
537 unsigned short RefreshRateTableIndex,
538 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200539{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300540 unsigned short index, Tempax, Tempbx, Tempcx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200541
Aaro Koskinena39325d2012-11-04 21:14:53 +0200542 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300543 /* Tempax: CR4 HRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200544 Tempax = XGI_CRT1Table[index].CR[3];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300545 Tempbx = Tempax; /* Tempbx: HRS[7:0] */
546 /* SR2E[7:0]->HRS */
547 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200548
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300549 /* SR0B */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200550 Tempax = XGI_CRT1Table[index].CR[5];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300551 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
552 Tempbx |= (Tempax << 2); /* Tempbx: HRS[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200553
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200554 Tempax = XGI_CRT1Table[index].CR[4]; /* CR5 HRE */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300555 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
556 Tempcx = Tempax; /* Tempcx: HRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200557
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200558 Tempax = XGI_CRT1Table[index].CR[6]; /* SRC */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300559 Tempax &= 0x04; /* Tempax[2]: HRE[5] */
560 Tempax <<= 3; /* Tempax[5]: HRE[5] */
561 Tempcx |= Tempax; /* Tempcx[5:0]: HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200562
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300563 Tempbx = Tempbx & 0x3C0; /* Tempbx[9:6]: HRS[9:6] */
564 Tempbx |= Tempcx; /* Tempbx: HRS[9:6]HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200565
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300566 /* Tempax: CR4 HRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200567 Tempax = XGI_CRT1Table[index].CR[3];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300568 Tempax &= 0x3F; /* Tempax: HRS[5:0] */
569 if (Tempcx <= Tempax) /* HRE[5:0] < HRS[5:0] */
570 Tempbx += 0x40; /* Tempbx= Tempbx + 0x40 : HRE[9:0]*/
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200571
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200572 Tempax = XGI_CRT1Table[index].CR[5]; /* SR0B */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300573 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
574 Tempax >>= 6; /* Tempax[1:0]: HRS[9:8]*/
575 Tempax |= ((Tempbx << 2) & 0xFF); /* Tempax[7:2]: HRE[5:0] */
576 /* SR2F [7:2][1:0]: HRE[5:0]HRS[9:8] */
577 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
578 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200579
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300580 /* CR10 VRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200581 Tempax = XGI_CRT1Table[index].CR[10];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300582 /* SR34[7:0]->VRS[7:0] */
583 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200584
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300585 Tempcx = Tempax; /* Tempcx <= VRS[7:0] */
586 /* CR7[7][2] VRS[9][8] */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200587 Tempax = XGI_CRT1Table[index].CR[9];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300588 Tempbx = Tempax; /* Tempbx <= CR07[7:0] */
589 Tempax = Tempax & 0x04; /* Tempax[2]: CR7[2]: VRS[8] */
590 Tempax >>= 2; /* Tempax[0]: VRS[8] */
591 /* SR35[0]: VRS[8] */
592 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x01, Tempax);
593 Tempcx |= (Tempax << 8); /* Tempcx <= VRS[8:0] */
594 Tempcx |= ((Tempbx & 0x80) << 2); /* Tempcx <= VRS[9:0] */
595 /* Tempax: SR0A */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200596 Tempax = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300597 Tempax &= 0x08; /* SR0A[3] VRS[10] */
598 Tempcx |= (Tempax << 7); /* Tempcx <= VRS[10:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200599
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300600 /* Tempax: CR11 VRE */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200601 Tempax = XGI_CRT1Table[index].CR[11];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300602 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
603 /* Tempbx: SR0A */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200604 Tempbx = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300605 Tempbx &= 0x20; /* Tempbx[5]: SR0A[5]: VRE[4] */
606 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
607 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
608 Tempbx = Tempcx; /* Tempbx: VRS[10:0] */
609 Tempbx &= 0x7E0; /* Tempbx[10:5]: VRS[10:5] */
610 Tempbx |= Tempax; /* Tempbx: VRS[10:5]VRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200611
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300612 if (Tempbx <= Tempcx) /* VRE <= VRS */
613 Tempbx |= 0x20; /* VRE + 0x20 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200614
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300615 /* Tempax: Tempax[7:0]; VRE[5:0]00 */
616 Tempax = (Tempbx << 2) & 0xFF;
617 /* SR3F[7:2]:VRE[5:0] */
618 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC, Tempax);
619 Tempax = Tempcx >> 8;
620 /* SR35[2:0]:VRS[10:8] */
621 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200622}
623
Aaro Koskinena2d08cf2011-11-27 23:03:08 +0200624static void XGI_SetXG27FPBits(struct vb_device_info *pVBInfo)
625{
626 unsigned char temp;
627
628 /* D[1:0] 01: 18bit, 00: dual 12, 10: single 24 */
629 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
630 temp = (temp & 3) << 6;
631 /* SR06[7]0: dual 12/1: single 24 [6] 18bit Dither <= 0 h/w recommend */
632 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0xc0, temp & 0x80);
633 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: 24bits */
634 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
635
636}
637
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300638static void xgifb_set_lcd(int chip_id,
639 struct vb_device_info *pVBInfo,
640 unsigned short RefreshRateTableIndex,
641 unsigned short ModeNo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200642{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300643 unsigned short Data, Temp;
Bill Pemberton82d6eb52010-06-17 13:10:46 -0400644 unsigned short XGI_P3cc;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200645
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530646 XGI_P3cc = pVBInfo->P3cc;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200647
Aaro Koskinen8104e322011-03-13 12:26:22 +0200648 xgifb_reg_set(pVBInfo->P3d4, 0x2E, 0x00);
649 xgifb_reg_set(pVBInfo->P3d4, 0x2F, 0x00);
650 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x00);
651 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x00);
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300652
653 if (chip_id == XG27) {
654 Temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
655 if ((Temp & 0x03) == 0) { /* dual 12 */
656 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x13);
657 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x13);
658 }
659 }
660
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300661 if (chip_id == XG27) {
662 XGI_SetXG27FPBits(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530663 } else {
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300664 Temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
665 if (Temp & 0x01) {
666 /* 18 bits FP */
667 xgifb_reg_or(pVBInfo->P3c4, 0x06, 0x40);
668 xgifb_reg_or(pVBInfo->P3c4, 0x09, 0x40);
669 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530670 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200671
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +0200672 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x01); /* Negative blank polarity */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200673
Aaro Koskinendc505562011-03-13 12:26:26 +0200674 xgifb_reg_and(pVBInfo->P3c4, 0x30, ~0x20); /* Hsync polarity */
675 xgifb_reg_and(pVBInfo->P3c4, 0x35, ~0x80); /* Vsync polarity */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200676
Aaro Koskinena39325d2012-11-04 21:14:53 +0200677 Data = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300678 if (Data & 0x4000)
679 /* Hsync polarity */
680 xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20);
681 if (Data & 0x8000)
682 /* Vsync polarity */
683 xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200684}
685
686/* --------------------------------------------------------------------- */
687/* Function : XGI_UpdateXG21CRTC */
688/* Input : */
689/* Output : CRT1 CRTC */
690/* Description : Modify CRT1 Hsync/Vsync to fix LCD mode timing */
691/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800692static void XGI_UpdateXG21CRTC(unsigned short ModeNo,
693 struct vb_device_info *pVBInfo,
694 unsigned short RefreshRateTableIndex)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200695{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300696 int index = -1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200697
Aaro Koskinendc505562011-03-13 12:26:26 +0200698 xgifb_reg_and(pVBInfo->P3d4, 0x11, 0x7F); /* Unlock CR0~7 */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300699 if (ModeNo == 0x2E &&
Aaro Koskinena39325d2012-11-04 21:14:53 +0200700 (XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC ==
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300701 RES640x480x60))
702 index = 12;
Aaro Koskinena39325d2012-11-04 21:14:53 +0200703 else if (ModeNo == 0x2E && (XGI330_RefIndex[RefreshRateTableIndex].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800704 Ext_CRT1CRTC == RES640x480x72))
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300705 index = 13;
706 else if (ModeNo == 0x2F)
707 index = 14;
708 else if (ModeNo == 0x50)
709 index = 15;
710 else if (ModeNo == 0x59)
711 index = 16;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200712
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530713 if (index != -1) {
Aaro Koskinen8104e322011-03-13 12:26:22 +0200714 xgifb_reg_set(pVBInfo->P3d4, 0x02,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200715 XGI_UpdateCRT1Table[index].CR02);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200716 xgifb_reg_set(pVBInfo->P3d4, 0x03,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200717 XGI_UpdateCRT1Table[index].CR03);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200718 xgifb_reg_set(pVBInfo->P3d4, 0x15,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200719 XGI_UpdateCRT1Table[index].CR15);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200720 xgifb_reg_set(pVBInfo->P3d4, 0x16,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200721 XGI_UpdateCRT1Table[index].CR16);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530722 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200723}
724
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200725static void XGI_SetCRT1DE(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530726 unsigned short ModeNo, unsigned short ModeIdIndex,
727 unsigned short RefreshRateTableIndex,
728 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200729{
Bill Pemberton82d6eb52010-06-17 13:10:46 -0400730 unsigned short resindex, tempax, tempbx, tempcx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200731
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530732 unsigned char data;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200733
Aaro Koskinenb3979922012-11-04 21:14:52 +0200734 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200735
Aaro Koskinenb3979922012-11-04 21:14:52 +0200736 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinene8e6c752012-11-04 21:15:00 +0200737 tempax = XGI330_ModeResInfo[resindex].HTotal;
738 tempbx = XGI330_ModeResInfo[resindex].VTotal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200739
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530740 if (modeflag & HalfDCLK)
741 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200742
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300743 if (modeflag & HalfDCLK)
744 tempax = tempax << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200745
Aaro Koskinena39325d2012-11-04 21:14:53 +0200746 temp = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200747
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300748 if (temp & InterlaceMode)
749 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200750
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300751 if (modeflag & DoubleScanMode)
752 tempbx = tempbx << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200753
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530754 tempcx = 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200755
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530756 tempax /= tempcx;
757 tempax -= 1;
758 tempbx -= 1;
759 tempcx = tempax;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200760 temp = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
761 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530762 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200763 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
764 xgifb_reg_set(pVBInfo->P3d4, 0x01, (unsigned short) (tempcx & 0xff));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200765 xgifb_reg_and_or(pVBInfo->P3d4, 0x0b, ~0x0c,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530766 (unsigned short) ((tempcx & 0x0ff00) >> 10));
Aaro Koskinen8104e322011-03-13 12:26:22 +0200767 xgifb_reg_set(pVBInfo->P3d4, 0x12, (unsigned short) (tempbx & 0xff));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530768 tempax = 0;
769 tempbx = tempbx >> 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200770
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530771 if (tempbx & 0x01)
772 tempax |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200773
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530774 if (tempbx & 0x02)
775 tempax |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200776
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200777 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x42, tempax);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200778 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x07);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530779 data &= 0xFF;
780 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200781
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530782 if (tempbx & 0x04)
783 tempax |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200784
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200785 xgifb_reg_and_or(pVBInfo->P3d4, 0x0a, ~0x02, tempax);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200786 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200787}
788
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800789static void XGI_SetCRT1Offset(unsigned short ModeNo,
790 unsigned short ModeIdIndex,
791 unsigned short RefreshRateTableIndex,
792 struct xgi_hw_device_info *HwDeviceExtension,
793 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200794{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530795 unsigned short temp, ah, al, temp2, i, DisplayUnit;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200796
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530797 /* GetOffset */
Aaro Koskinenb3979922012-11-04 21:14:52 +0200798 temp = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeInfo;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530799 temp = temp >> 8;
Aaro Koskinen224114c2012-11-04 21:14:59 +0200800 temp = XGI330_ScreenOffset[temp];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200801
Aaro Koskinena39325d2012-11-04 21:14:53 +0200802 temp2 = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530803 temp2 &= InterlaceMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200804
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530805 if (temp2)
806 temp = temp << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200807
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530808 temp2 = pVBInfo->ModeType - ModeEGA;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200809
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530810 switch (temp2) {
811 case 0:
812 temp2 = 1;
813 break;
814 case 1:
815 temp2 = 2;
816 break;
817 case 2:
818 temp2 = 4;
819 break;
820 case 3:
821 temp2 = 4;
822 break;
823 case 4:
824 temp2 = 6;
825 break;
826 case 5:
827 temp2 = 8;
828 break;
829 default:
830 break;
831 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200832
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530833 if ((ModeNo >= 0x26) && (ModeNo <= 0x28))
834 temp = temp * temp2 + temp2 / 2;
835 else
836 temp *= temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200837
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530838 /* SetOffset */
839 DisplayUnit = temp;
840 temp2 = temp;
841 temp = temp >> 8; /* ah */
842 temp &= 0x0F;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200843 i = xgifb_reg_get(pVBInfo->P3c4, 0x0E);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530844 i &= 0xF0;
845 i |= temp;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200846 xgifb_reg_set(pVBInfo->P3c4, 0x0E, i);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200847
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530848 temp = (unsigned char) temp2;
849 temp &= 0xFF; /* al */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200850 xgifb_reg_set(pVBInfo->P3d4, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200851
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530852 /* SetDisplayUnit */
Aaro Koskinena39325d2012-11-04 21:14:53 +0200853 temp2 = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530854 temp2 &= InterlaceMode;
855 if (temp2)
856 DisplayUnit >>= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200857
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530858 DisplayUnit = DisplayUnit << 5;
859 ah = (DisplayUnit & 0xff00) >> 8;
860 al = DisplayUnit & 0x00ff;
861 if (al == 0)
862 ah += 1;
863 else
864 ah += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200865
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530866 if (HwDeviceExtension->jChipType >= XG20)
867 if ((ModeNo == 0x4A) | (ModeNo == 0x49))
868 ah -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200869
Aaro Koskinen8104e322011-03-13 12:26:22 +0200870 xgifb_reg_set(pVBInfo->P3c4, 0x10, ah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200871}
872
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200873static unsigned short XGI_GetVCLK2Ptr(unsigned short ModeNo,
874 unsigned short ModeIdIndex,
875 unsigned short RefreshRateTableIndex,
876 struct xgi_hw_device_info *HwDeviceExtension,
877 struct vb_device_info *pVBInfo)
878{
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200879 unsigned short CRT2Index, VCLKIndex;
880 unsigned short modeflag, resinfo;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200881
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300882 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +0200883 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
884 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinena39325d2012-11-04 21:14:53 +0200885 CRT2Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200886
887 if (pVBInfo->IF_DEF_LVDS == 0) {
888 CRT2Index = CRT2Index >> 6; /* for LCD */
Miguel Gómez3bcc2462012-07-06 12:40:53 +0200889 if (pVBInfo->VBInfo &
890 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) { /*301b*/
Peter Huewe255aabd2012-02-09 21:11:44 +0100891 if (pVBInfo->LCDResInfo != Panel_1024x768)
Miguel Gómez3bcc2462012-07-06 12:40:53 +0200892 /* LCDXlat2VCLK */
893 VCLKIndex = VCLK108_2_315 + 5;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200894 else
Peter Huewef477d3e2012-06-14 00:21:47 +0200895 VCLKIndex = VCLK65_315 + 2; /* LCDXlat1VCLK */
Peter Huewe599801f2012-02-09 21:11:45 +0100896 } else if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +0200897 if (pVBInfo->SetFlag & RPLLDIV2XO)
Peter Huewe95072592012-06-14 00:21:48 +0200898 VCLKIndex = TVCLKBASE_315_25 + HiTVVCLKDIV2;
Miguel Gómez3bcc2462012-07-06 12:40:53 +0200899 else
Peter Huewe95072592012-06-14 00:21:48 +0200900 VCLKIndex = TVCLKBASE_315_25 + HiTVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200901
Aaro Koskinen798b4da2011-11-27 23:03:20 +0200902 if (pVBInfo->SetFlag & TVSimuMode) {
903 if (modeflag & Charx8Dot) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +0200904 VCLKIndex = TVCLKBASE_315_25 +
905 HiTVSimuVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200906 } else {
Miguel Gómez3bcc2462012-07-06 12:40:53 +0200907 VCLKIndex = TVCLKBASE_315_25 +
908 HiTVTextVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200909 }
Aaro Koskinen798b4da2011-11-27 23:03:20 +0200910 }
911
912 /* 301lv */
Aaro Koskinen31fb40f2012-09-11 00:15:15 +0300913 if (pVBInfo->VBType & VB_SIS301LV) {
914 if (pVBInfo->SetFlag & RPLLDIV2XO)
Aaro Koskinen798b4da2011-11-27 23:03:20 +0200915 VCLKIndex = YPbPr525iVCLK_2;
916 else
917 VCLKIndex = YPbPr525iVCLK;
918 }
919 } else if (pVBInfo->VBInfo & SetCRT2ToTV) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +0200920 if (pVBInfo->SetFlag & RPLLDIV2XO)
Peter Huewe95072592012-06-14 00:21:48 +0200921 VCLKIndex = TVCLKBASE_315_25 + TVVCLKDIV2;
Miguel Gómez3bcc2462012-07-06 12:40:53 +0200922 else
Peter Huewe95072592012-06-14 00:21:48 +0200923 VCLKIndex = TVCLKBASE_315_25 + TVVCLK;
Aaro Koskinen798b4da2011-11-27 23:03:20 +0200924 } else { /* for CRT2 */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300925 /* di+Ext_CRTVCLK */
Aaro Koskinena39325d2012-11-04 21:14:53 +0200926 VCLKIndex = XGI330_RefIndex[RefreshRateTableIndex].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800927 Ext_CRTVCLK;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300928 VCLKIndex &= IndexMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200929 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300930 } else if ((pVBInfo->LCDResInfo == Panel_800x600) ||
931 (pVBInfo->LCDResInfo == Panel_320x480)) { /* LVDS */
932 VCLKIndex = VCLK40; /* LVDSXlat1VCLK */
933 } else {
934 VCLKIndex = VCLK65_315 + 2; /* LVDSXlat2VCLK, LVDSXlat3VCLK */
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200935 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200936
937 return VCLKIndex;
938}
939
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800940static void XGI_SetCRT1VCLK(unsigned short ModeNo,
941 unsigned short ModeIdIndex,
942 struct xgi_hw_device_info *HwDeviceExtension,
943 unsigned short RefreshRateTableIndex,
944 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200945{
Bill Pemberton108afbf2010-06-17 13:10:47 -0400946 unsigned char index, data;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530947 unsigned short vclkindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200948
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530949 if (pVBInfo->IF_DEF_LVDS == 1) {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200950 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200951 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200952 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200953 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[index].SR2B);
954 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[index].SR2C);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200955 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Peter Huewe6896b942012-02-09 21:11:46 +0100956 } else if ((pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
957 | VB_SIS302LV | VB_XGI301C)) && (pVBInfo->VBInfo
Peter Huewea3d675c2012-02-09 21:11:47 +0100958 & XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530959 vclkindex = XGI_GetVCLK2Ptr(ModeNo, ModeIdIndex,
960 RefreshRateTableIndex, HwDeviceExtension,
961 pVBInfo);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200962 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200963 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200964 data = XGI_VBVCLKData[vclkindex].Part4_A;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200965 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200966 data = XGI_VBVCLKData[vclkindex].Part4_B;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200967 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
968 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530969 } else {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200970 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200971 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200972 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200973 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[index].SR2B);
974 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[index].SR2C);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200975 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530976 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200977
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530978 if (HwDeviceExtension->jChipType >= XG20) {
Aaro Koskinenb3979922012-11-04 21:14:52 +0200979 if (XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag &
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800980 HalfDCLK) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200981 data = xgifb_reg_get(pVBInfo->P3c4, 0x2B);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200982 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200983 data = xgifb_reg_get(pVBInfo->P3c4, 0x2C);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530984 index = data;
985 index &= 0xE0;
986 data &= 0x1F;
987 data = data << 1;
988 data += 1;
989 data |= index;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200990 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530991 }
992 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200993}
994
Aaro Koskinene85f2032011-11-27 23:03:07 +0200995static void XGI_SetXG21FPBits(struct vb_device_info *pVBInfo)
996{
997 unsigned char temp;
998
999 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37); /* D[0] 1: 18bit */
1000 temp = (temp & 1) << 6;
1001 /* SR06[6] 18bit Dither */
1002 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x40, temp);
1003 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: dual 12bits */
1004 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
1005
1006}
1007
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001008static void XGI_SetCRT1FIFO(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301009 struct xgi_hw_device_info *HwDeviceExtension,
1010 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001011{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301012 unsigned short data;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001013
Aaro Koskinen58839b02011-03-13 12:26:23 +02001014 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301015 data &= 0xfe;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001016 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data); /* diable auto-threshold */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001017
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001018 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0x34);
1019 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
1020 data &= 0xC0;
1021 xgifb_reg_set(pVBInfo->P3c4, 0x09, data | 0x30);
1022 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
1023 data |= 0x01;
1024 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001025
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301026 if (HwDeviceExtension->jChipType == XG21)
1027 XGI_SetXG21FPBits(pVBInfo); /* Fix SR9[7:6] can't read back */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001028}
1029
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001030static void XGI_SetVCLKState(struct xgi_hw_device_info *HwDeviceExtension,
1031 unsigned short ModeNo, unsigned short RefreshRateTableIndex,
1032 struct vb_device_info *pVBInfo)
1033{
1034 unsigned short data, data2 = 0;
1035 short VCLK;
1036
1037 unsigned char index;
1038
Aaro Koskinena39325d2012-11-04 21:14:53 +02001039 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001040 index &= IndexMask;
Aaro Koskinenacfe0932012-11-04 21:14:58 +02001041 VCLK = XGI_VCLKData[index].CLOCK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001042
Aaro Koskinen58839b02011-03-13 12:26:23 +02001043 data = xgifb_reg_get(pVBInfo->P3c4, 0x32);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001044 data &= 0xf3;
1045 if (VCLK >= 200)
1046 data |= 0x0c; /* VCLK > 200 */
1047
1048 if (HwDeviceExtension->jChipType >= XG20)
1049 data &= ~0x04; /* 2 pixel mode */
1050
Aaro Koskinen8104e322011-03-13 12:26:22 +02001051 xgifb_reg_set(pVBInfo->P3c4, 0x32, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001052
1053 if (HwDeviceExtension->jChipType < XG20) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001054 data = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001055 data &= 0xE7;
1056 if (VCLK < 200)
1057 data |= 0x10;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001058 xgifb_reg_set(pVBInfo->P3c4, 0x1F, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001059 }
1060
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001061 data2 = 0x00;
1062
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001063 xgifb_reg_and_or(pVBInfo->P3c4, 0x07, 0xFC, data2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001064 if (HwDeviceExtension->jChipType >= XG27)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001065 xgifb_reg_and_or(pVBInfo->P3c4, 0x40, 0xFC, data2 & 0x03);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001066
1067}
1068
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001069static void XGI_SetCRT1ModeRegs(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301070 unsigned short ModeNo, unsigned short ModeIdIndex,
1071 unsigned short RefreshRateTableIndex,
1072 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001073{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301074 unsigned short data, data2, data3, infoflag = 0, modeflag, resindex,
1075 xres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001076
Aaro Koskinenb3979922012-11-04 21:14:52 +02001077 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02001078 infoflag = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001079
Aaro Koskinen58839b02011-03-13 12:26:23 +02001080 if (xgifb_reg_get(pVBInfo->P3d4, 0x31) & 0x01)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001081 xgifb_reg_and_or(pVBInfo->P3c4, 0x1F, 0x3F, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001082
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001083 data = infoflag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301084 data2 = 0;
Aaro Koskinen969f7f32012-04-07 01:14:03 +03001085 data2 |= 0x02;
1086 data3 = pVBInfo->ModeType - ModeVGA;
1087 data3 = data3 << 2;
1088 data2 |= data3;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301089 data &= InterlaceMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001090
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301091 if (data)
1092 data2 |= 0x20;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001093
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001094 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x3F, data2);
Aaro Koskinenb3979922012-11-04 21:14:52 +02001095 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02001096 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001097
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301098 data = 0x0000;
1099 if (infoflag & InterlaceMode) {
1100 if (xres == 1024)
1101 data = 0x0035;
1102 else if (xres == 1280)
1103 data = 0x0048;
1104 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001105
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301106 data2 = data & 0x00FF;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001107 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFF, data2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301108 data2 = (data & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001109 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFC, data2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001110
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301111 if (modeflag & HalfDCLK)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001112 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xF7, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001113
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301114 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001115
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301116 if (modeflag & LineCompareOff)
1117 data2 |= 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001118
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001119 xgifb_reg_and_or(pVBInfo->P3c4, 0x0F, ~0x48, data2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301120 data = 0x60;
Aaro Koskinen969f7f32012-04-07 01:14:03 +03001121 data = data ^ 0x60;
1122 data = data ^ 0xA0;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001123 xgifb_reg_and_or(pVBInfo->P3c4, 0x21, 0x1F, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001124
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301125 XGI_SetVCLKState(HwDeviceExtension, ModeNo, RefreshRateTableIndex,
1126 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001127
Aaro Koskinen58839b02011-03-13 12:26:23 +02001128 data = xgifb_reg_get(pVBInfo->P3d4, 0x31);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001129
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301130 if (HwDeviceExtension->jChipType == XG27) {
1131 if (data & 0x40)
1132 data = 0x2c;
1133 else
1134 data = 0x6c;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001135 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02001136 xgifb_reg_or(pVBInfo->P3d4, 0x51, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301137 } else if (HwDeviceExtension->jChipType >= XG20) {
1138 if (data & 0x40)
1139 data = 0x33;
1140 else
1141 data = 0x73;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001142 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
1143 xgifb_reg_set(pVBInfo->P3d4, 0x51, 0x02);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301144 } else {
1145 if (data & 0x40)
1146 data = 0x2c;
1147 else
1148 data = 0x6c;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001149 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301150 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001151
1152}
1153
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001154static void XGI_WriteDAC(unsigned short dl,
1155 unsigned short ah,
1156 unsigned short al,
1157 unsigned short dh,
1158 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001159{
1160 unsigned short temp, bh, bl;
1161
1162 bh = ah;
1163 bl = al;
1164
1165 if (dl != 0) {
1166 temp = bh;
1167 bh = dh;
1168 dh = temp;
1169 if (dl == 1) {
1170 temp = bl;
1171 bl = dh;
1172 dh = temp;
1173 } else {
1174 temp = bl;
1175 bl = bh;
1176 bh = temp;
1177 }
1178 }
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001179 outb((unsigned short) dh, pVBInfo->P3c9);
1180 outb((unsigned short) bh, pVBInfo->P3c9);
1181 outb((unsigned short) bl, pVBInfo->P3c9);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001182}
1183
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001184static void XGI_LoadDAC(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301185 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001186{
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001187 unsigned short data, data2, i, k, m, n, o, si, di, bx, dl, al, ah, dh;
1188 const unsigned short *table = XGINew_VGA_DAC;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001189
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001190 outb(0xFF, pVBInfo->P3c6);
1191 outb(0x00, pVBInfo->P3c8);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001192
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001193 for (i = 0; i < 16; i++) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301194 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001195
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301196 for (k = 0; k < 3; k++) {
1197 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001198
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301199 if (data & 0x01)
1200 data2 = 0x2A;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001201
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301202 if (data & 0x02)
1203 data2 += 0x15;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001204
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001205 outb(data2, pVBInfo->P3c9);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301206 data = data >> 2;
1207 }
1208 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001209
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001210 for (i = 16; i < 32; i++) {
1211 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001212
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001213 for (k = 0; k < 3; k++)
1214 outb(data, pVBInfo->P3c9);
1215 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001216
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001217 si = 32;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001218
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001219 for (m = 0; m < 9; m++) {
1220 di = si;
1221 bx = si + 0x04;
1222 dl = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001223
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001224 for (n = 0; n < 3; n++) {
1225 for (o = 0; o < 5; o++) {
1226 dh = table[si];
1227 ah = table[di];
1228 al = table[bx];
1229 si++;
1230 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301231 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001232
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001233 si -= 2;
1234
1235 for (o = 0; o < 3; o++) {
1236 dh = table[bx];
1237 ah = table[di];
1238 al = table[si];
1239 si--;
1240 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1241 }
1242
1243 dl++;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301244 }
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001245
1246 si += 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301247 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001248}
1249
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001250static void XGI_GetLVDSResInfo(unsigned short ModeNo,
1251 unsigned short ModeIdIndex,
1252 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001253{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301254 unsigned short resindex, xres, yres, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001255
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001256 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02001257 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001258
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001259 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02001260 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001261
Aaro Koskinene8e6c752012-11-04 21:15:00 +02001262 xres = XGI330_ModeResInfo[resindex].HTotal;
1263 yres = XGI330_ModeResInfo[resindex].VTotal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001264
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001265 if (modeflag & HalfDCLK)
1266 xres = xres << 1;
1267
1268 if (modeflag & DoubleScanMode)
1269 yres = yres << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001270
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301271 if (xres == 720)
1272 xres = 640;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001273
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301274 pVBInfo->VGAHDE = xres;
1275 pVBInfo->HDE = xres;
1276 pVBInfo->VGAVDE = yres;
1277 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001278}
1279
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001280static void const *XGI_GetLcdPtr(struct XGI330_LCDDataTablStruct const *table,
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001281 unsigned short ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001282 unsigned short ModeIdIndex,
1283 unsigned short RefreshRateTableIndex,
1284 struct vb_device_info *pVBInfo)
1285{
Aaro Koskinen6c27b372012-11-04 21:14:45 +02001286 unsigned short i, tempdx, tempbx, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001287
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001288 tempbx = 0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001289
Aaro Koskinenb3979922012-11-04 21:14:52 +02001290 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001291
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001292 i = 0;
1293
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001294 while (table[i].PANELID != 0xff) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001295 tempdx = pVBInfo->LCDResInfo;
1296 if (tempbx & 0x0080) { /* OEMUtil */
1297 tempbx &= (~0x0080);
1298 tempdx = pVBInfo->LCDTypeInfo;
1299 }
1300
1301 if (pVBInfo->LCDInfo & EnableScalingLCD)
1302 tempdx &= (~PanelResInfo);
1303
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001304 if (table[i].PANELID == tempdx) {
1305 tempbx = table[i].MASK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001306 tempdx = pVBInfo->LCDInfo;
1307
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001308 if (modeflag & HalfDCLK)
1309 tempdx |= SetLCDLowResolution;
1310
1311 tempbx &= tempdx;
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001312 if (tempbx == table[i].CAP)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001313 break;
1314 }
1315 i++;
1316 }
1317
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001318 return table[i].DATAPTR;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001319}
1320
Aaro Koskinen24572542012-09-11 00:15:21 +03001321static struct SiS_TVData const *XGI_GetTVPtr(unsigned short ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001322 unsigned short ModeIdIndex,
1323 unsigned short RefreshRateTableIndex,
1324 struct vb_device_info *pVBInfo)
1325{
Aaro Koskinen56d276c2012-09-11 00:15:19 +03001326 unsigned short i, tempdx, tempal, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001327
Aaro Koskinenb3979922012-11-04 21:14:52 +02001328 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02001329 tempal = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001330 tempal = tempal & 0x3f;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001331 tempdx = pVBInfo->TVInfo;
1332
1333 if (pVBInfo->VBInfo & SetInSlaveMode)
1334 tempdx = tempdx | SetTVLockMode;
1335
1336 if (modeflag & HalfDCLK)
1337 tempdx = tempdx | SetTVLowResolution;
1338
1339 i = 0;
1340
Aaro Koskinen6265ee42012-09-11 00:15:20 +03001341 while (XGI_TVDataTable[i].MASK != 0xffff) {
1342 if ((tempdx & XGI_TVDataTable[i].MASK) ==
1343 XGI_TVDataTable[i].CAP)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001344 break;
1345 i++;
1346 }
1347
Aaro Koskinen18ba8662012-09-11 00:15:22 +03001348 return &XGI_TVDataTable[i].DATAPTR[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001349}
1350
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001351static void XGI_GetLVDSData(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301352 unsigned short RefreshRateTableIndex,
1353 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001354{
Aaro Koskinen6008f872012-11-04 21:14:49 +02001355 struct SiS_LVDSData const *LCDPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001356
Aaro Koskinen6008f872012-11-04 21:14:49 +02001357 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
1358 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001359
Aaro Koskinen6008f872012-11-04 21:14:49 +02001360 LCDPtr = XGI_GetLcdPtr(XGI_EPLLCDDataPtr, ModeNo, ModeIdIndex,
1361 RefreshRateTableIndex, pVBInfo);
1362 pVBInfo->VGAHT = LCDPtr->VGAHT;
1363 pVBInfo->VGAVT = LCDPtr->VGAVT;
1364 pVBInfo->HT = LCDPtr->LCDHT;
1365 pVBInfo->VT = LCDPtr->LCDVT;
1366
1367 if (pVBInfo->LCDInfo & (SetLCDtoNonExpanding | EnableScalingLCD))
1368 return;
1369
1370 if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
1371 (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
1372 pVBInfo->HDE = 1024;
1373 pVBInfo->VDE = 768;
1374 } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
1375 (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
1376 pVBInfo->HDE = 1280;
1377 pVBInfo->VDE = 1024;
1378 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
1379 pVBInfo->HDE = 1400;
1380 pVBInfo->VDE = 1050;
1381 } else {
1382 pVBInfo->HDE = 1600;
1383 pVBInfo->VDE = 1200;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301384 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001385}
1386
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001387static void XGI_ModCRT1Regs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301388 unsigned short RefreshRateTableIndex,
1389 struct xgi_hw_device_info *HwDeviceExtension,
1390 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001391{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301392 unsigned char index;
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001393 unsigned short i;
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001394 struct XGI_LVDSCRT1HDataStruct const *LCDPtr = NULL;
1395 struct XGI_LVDSCRT1VDataStruct const *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001396
Aaro Koskinena39325d2012-11-04 21:14:53 +02001397 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301398 index = index & IndexMask;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001399
Peter Huewea3d675c2012-02-09 21:11:47 +01001400 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001401 LCDPtr = XGI_GetLcdPtr(xgifb_epllcd_crt1_h, ModeNo, ModeIdIndex,
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +03001402 RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001403
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001404 for (i = 0; i < 8; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +02001405 pVBInfo->TimingH.data[i] = LCDPtr[0].Reg[i];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301406 }
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001407
1408 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
1409
Peter Huewea3d675c2012-02-09 21:11:47 +01001410 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001411 LCDPtr1 = XGI_GetLcdPtr(xgifb_epllcd_crt1_v, ModeNo,
1412 ModeIdIndex, RefreshRateTableIndex,
1413 pVBInfo);
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001414 for (i = 0; i < 7; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +02001415 pVBInfo->TimingV.data[i] = LCDPtr1[0].Reg[i];
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001416 }
1417
1418 XGI_SetCRT1Timing_V(ModeIdIndex, ModeNo, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001419}
1420
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001421static unsigned short XGI_GetLCDCapPtr(struct vb_device_info *pVBInfo)
1422{
1423 unsigned char tempal, tempah, tempbl, i;
1424
Aaro Koskinen58839b02011-03-13 12:26:23 +02001425 tempah = xgifb_reg_get(pVBInfo->P3d4, 0x36);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001426 tempal = tempah & 0x0F;
1427 tempah = tempah & 0xF0;
1428 i = 0;
1429 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1430
1431 while (tempbl != 0xFF) {
1432 if (tempbl & 0x80) { /* OEMUtil */
1433 tempal = tempah;
1434 tempbl = tempbl & ~(0x80);
1435 }
1436
1437 if (tempal == tempbl)
1438 break;
1439
1440 i++;
1441
1442 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1443 }
1444
1445 return i;
1446}
1447
1448static unsigned short XGI_GetLCDCapPtr1(struct vb_device_info *pVBInfo)
1449{
1450 unsigned short tempah, tempal, tempbl, i;
1451
1452 tempal = pVBInfo->LCDResInfo;
1453 tempah = pVBInfo->LCDTypeInfo;
1454
1455 i = 0;
1456 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1457
1458 while (tempbl != 0xFF) {
1459 if ((tempbl & 0x80) && (tempbl != 0x80)) {
1460 tempal = tempah;
1461 tempbl &= ~0x80;
1462 }
1463
1464 if (tempal == tempbl)
1465 break;
1466
1467 i++;
1468 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1469 }
1470
1471 if (tempbl == 0xFF) {
Peter Huewe255aabd2012-02-09 21:11:44 +01001472 pVBInfo->LCDResInfo = Panel_1024x768;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001473 pVBInfo->LCDTypeInfo = 0;
1474 i = 0;
1475 }
1476
1477 return i;
1478}
1479
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001480static void XGI_GetLCDSync(unsigned short *HSyncWidth,
1481 unsigned short *VSyncWidth,
1482 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001483{
1484 unsigned short Index;
1485
1486 Index = XGI_GetLCDCapPtr(pVBInfo);
1487 *HSyncWidth = pVBInfo->LCDCapList[Index].LCD_HSyncWidth;
1488 *VSyncWidth = pVBInfo->LCDCapList[Index].LCD_VSyncWidth;
1489
1490 return;
1491}
1492
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001493static void XGI_SetLVDSRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301494 unsigned short RefreshRateTableIndex,
1495 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001496{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301497 unsigned short tempbx, tempax, tempcx, tempdx, push1, push2, modeflag;
1498 unsigned long temp, temp1, temp2, temp3, push3;
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001499 struct XGI_LCDDesStruct const *LCDPtr = NULL;
1500 struct XGI330_LCDDataDesStruct2 const *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001501
Aaro Koskinenb3979922012-11-04 21:14:52 +02001502 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinen66cface2011-08-31 21:46:13 +03001503 if (pVBInfo->LCDInfo & EnableScalingLCD)
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001504 LCDPtr1 = XGI_GetLcdPtr(XGI_EPLLCDDesDataPtr, ModeNo,
1505 ModeIdIndex, RefreshRateTableIndex,
1506 pVBInfo);
Aaro Koskinen66cface2011-08-31 21:46:13 +03001507 else
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001508 LCDPtr = XGI_GetLcdPtr(XGI_EPLLCDDesDataPtr, ModeNo,
1509 ModeIdIndex, RefreshRateTableIndex,
1510 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001511
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001512 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
1513 push1 = tempbx;
1514 push2 = tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001515
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001516 /* GetLCDResInfo */
Peter Huewe255aabd2012-02-09 21:11:44 +01001517 if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
1518 (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001519 tempax = 1024;
1520 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01001521 } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
1522 (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001523 tempax = 1280;
1524 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01001525 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001526 tempax = 1400;
1527 tempbx = 1050;
1528 } else {
1529 tempax = 1600;
1530 tempbx = 1200;
1531 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001532
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001533 if (pVBInfo->LCDInfo & SetLCDtoNonExpanding) {
1534 pVBInfo->HDE = tempax;
1535 pVBInfo->VDE = tempbx;
1536 pVBInfo->VGAHDE = tempax;
1537 pVBInfo->VGAVDE = tempbx;
1538 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001539
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001540 tempax = pVBInfo->HT;
1541
1542 if (pVBInfo->LCDInfo & EnableScalingLCD)
1543 tempbx = LCDPtr1->LCDHDES;
1544 else
1545 tempbx = LCDPtr->LCDHDES;
1546
1547 tempcx = pVBInfo->HDE;
1548 tempbx = tempbx & 0x0fff;
1549 tempcx += tempbx;
1550
1551 if (tempcx >= tempax)
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001552 tempcx -= tempax;
1553
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001554 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, tempbx & 0x07);
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001555
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001556 tempcx = tempcx >> 3;
1557 tempbx = tempbx >> 3;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001558
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001559 xgifb_reg_set(pVBInfo->Part1Port, 0x16,
1560 (unsigned short) (tempbx & 0xff));
1561 xgifb_reg_set(pVBInfo->Part1Port, 0x17,
1562 (unsigned short) (tempcx & 0xff));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001563
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001564 tempax = pVBInfo->HT;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001565
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001566 if (pVBInfo->LCDInfo & EnableScalingLCD)
1567 tempbx = LCDPtr1->LCDHRS;
1568 else
1569 tempbx = LCDPtr->LCDHRS;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001570
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001571 tempcx = push2;
1572
1573 if (pVBInfo->LCDInfo & EnableScalingLCD)
1574 tempcx = LCDPtr1->LCDHSync;
1575
1576 tempcx += tempbx;
1577
1578 if (tempcx >= tempax)
1579 tempcx -= tempax;
1580
1581 tempax = tempbx & 0x07;
1582 tempax = tempax >> 5;
1583 tempcx = tempcx >> 3;
1584 tempbx = tempbx >> 3;
1585
1586 tempcx &= 0x1f;
1587 tempax |= tempcx;
1588
1589 xgifb_reg_set(pVBInfo->Part1Port, 0x15, tempax);
1590 xgifb_reg_set(pVBInfo->Part1Port, 0x14,
1591 (unsigned short) (tempbx & 0xff));
1592
1593 tempax = pVBInfo->VT;
1594 if (pVBInfo->LCDInfo & EnableScalingLCD)
1595 tempbx = LCDPtr1->LCDVDES;
1596 else
1597 tempbx = LCDPtr->LCDVDES;
1598 tempcx = pVBInfo->VDE;
1599
1600 tempbx = tempbx & 0x0fff;
1601 tempcx += tempbx;
1602 if (tempcx >= tempax)
1603 tempcx -= tempax;
1604
1605 xgifb_reg_set(pVBInfo->Part1Port, 0x1b,
1606 (unsigned short) (tempbx & 0xff));
1607 xgifb_reg_set(pVBInfo->Part1Port, 0x1c,
1608 (unsigned short) (tempcx & 0xff));
1609
1610 tempbx = (tempbx >> 8) & 0x07;
1611 tempcx = (tempcx >> 8) & 0x07;
1612
1613 xgifb_reg_set(pVBInfo->Part1Port, 0x1d,
1614 (unsigned short) ((tempcx << 3)
1615 | tempbx));
1616
1617 tempax = pVBInfo->VT;
1618 if (pVBInfo->LCDInfo & EnableScalingLCD)
1619 tempbx = LCDPtr1->LCDVRS;
1620 else
1621 tempbx = LCDPtr->LCDVRS;
1622
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001623 tempcx = push1;
1624
1625 if (pVBInfo->LCDInfo & EnableScalingLCD)
1626 tempcx = LCDPtr1->LCDVSync;
1627
1628 tempcx += tempbx;
1629 if (tempcx >= tempax)
1630 tempcx -= tempax;
1631
1632 xgifb_reg_set(pVBInfo->Part1Port, 0x18,
1633 (unsigned short) (tempbx & 0xff));
1634 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, ~0x0f,
1635 (unsigned short) (tempcx & 0x0f));
1636
1637 tempax = ((tempbx >> 8) & 0x07) << 3;
1638
1639 tempbx = pVBInfo->VGAVDE;
1640 if (tempbx != pVBInfo->VDE)
1641 tempax |= 0x40;
1642
Peter Huewea3d675c2012-02-09 21:11:47 +01001643 if (pVBInfo->LCDInfo & XGI_EnableLVDSDDA)
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001644 tempax |= 0x40;
1645
1646 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1a, 0x07,
1647 tempax);
1648
1649 tempcx = pVBInfo->VGAVT;
1650 tempbx = pVBInfo->VDE;
1651 tempax = pVBInfo->VGAVDE;
1652 tempcx -= tempax;
1653
1654 temp = tempax; /* 0430 ylshieh */
1655 temp1 = (temp << 18) / tempbx;
1656
1657 tempdx = (unsigned short) ((temp << 18) % tempbx);
1658
1659 if (tempdx != 0)
1660 temp1 += 1;
1661
1662 temp2 = temp1;
1663 push3 = temp2;
1664
1665 xgifb_reg_set(pVBInfo->Part1Port, 0x37,
1666 (unsigned short) (temp2 & 0xff));
1667 xgifb_reg_set(pVBInfo->Part1Port, 0x36,
1668 (unsigned short) ((temp2 >> 8) & 0xff));
1669
1670 tempbx = (unsigned short) (temp2 >> 16);
1671 tempax = tempbx & 0x03;
1672
1673 tempbx = pVBInfo->VGAVDE;
1674 if (tempbx == pVBInfo->VDE)
1675 tempax |= 0x04;
1676
1677 xgifb_reg_set(pVBInfo->Part1Port, 0x35, tempax);
1678
1679 if (pVBInfo->VBType & VB_XGI301C) {
1680 temp2 = push3;
1681 xgifb_reg_set(pVBInfo->Part4Port,
1682 0x3c,
1683 (unsigned short) (temp2 & 0xff));
1684 xgifb_reg_set(pVBInfo->Part4Port,
1685 0x3b,
1686 (unsigned short) ((temp2 >> 8) &
1687 0xff));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001688 tempbx = (unsigned short) (temp2 >> 16);
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001689 xgifb_reg_and_or(pVBInfo->Part4Port, 0x3a,
1690 ~0xc0,
1691 (unsigned short) ((tempbx &
1692 0xff) << 6));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001693
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001694 tempcx = pVBInfo->VGAVDE;
1695 if (tempcx == pVBInfo->VDE)
1696 xgifb_reg_and_or(pVBInfo->Part4Port,
1697 0x30, ~0x0c, 0x00);
1698 else
1699 xgifb_reg_and_or(pVBInfo->Part4Port,
1700 0x30, ~0x0c, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301701 }
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001702
1703 tempcx = pVBInfo->VGAHDE;
1704 tempbx = pVBInfo->HDE;
1705
1706 temp1 = tempcx << 16;
1707
1708 tempax = (unsigned short) (temp1 / tempbx);
1709
1710 if ((tempbx & 0xffff) == (tempcx & 0xffff))
1711 tempax = 65535;
1712
1713 temp3 = tempax;
1714 temp1 = pVBInfo->VGAHDE << 16;
1715
1716 temp1 /= temp3;
1717 temp3 = temp3 << 16;
1718 temp1 -= 1;
1719
1720 temp3 = (temp3 & 0xffff0000) + (temp1 & 0xffff);
1721
1722 tempax = (unsigned short) (temp3 & 0xff);
1723 xgifb_reg_set(pVBInfo->Part1Port, 0x1f, tempax);
1724
1725 temp1 = pVBInfo->VGAVDE << 18;
1726 temp1 = temp1 / push3;
1727 tempbx = (unsigned short) (temp1 & 0xffff);
1728
Peter Huewe255aabd2012-02-09 21:11:44 +01001729 if (pVBInfo->LCDResInfo == Panel_1024x768)
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001730 tempbx -= 1;
1731
1732 tempax = ((tempbx >> 8) & 0xff) << 3;
1733 tempax |= (unsigned short) ((temp3 >> 8) & 0x07);
1734 xgifb_reg_set(pVBInfo->Part1Port, 0x20,
1735 (unsigned short) (tempax & 0xff));
1736 xgifb_reg_set(pVBInfo->Part1Port, 0x21,
1737 (unsigned short) (tempbx & 0xff));
1738
1739 temp3 = temp3 >> 16;
1740
1741 if (modeflag & HalfDCLK)
1742 temp3 = temp3 >> 1;
1743
1744 xgifb_reg_set(pVBInfo->Part1Port, 0x22,
1745 (unsigned short) ((temp3 >> 8) & 0xff));
1746 xgifb_reg_set(pVBInfo->Part1Port, 0x23,
1747 (unsigned short) (temp3 & 0xff));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001748}
1749
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001750/* --------------------------------------------------------------------- */
1751/* Function : XGI_GETLCDVCLKPtr */
1752/* Input : */
1753/* Output : al -> VCLK Index */
1754/* Description : */
1755/* --------------------------------------------------------------------- */
1756static void XGI_GetLCDVCLKPtr(unsigned char *di_0, unsigned char *di_1,
1757 struct vb_device_info *pVBInfo)
1758{
1759 unsigned short index;
1760
Peter Huewea3d675c2012-02-09 21:11:47 +01001761 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001762 index = XGI_GetLCDCapPtr1(pVBInfo);
1763
1764 if (pVBInfo->VBInfo & SetCRT2ToLCD) { /* LCDB */
1765 *di_0 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData1;
1766 *di_1 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData2;
1767 } else { /* LCDA */
1768 *di_0 = pVBInfo->LCDCapList[index].LCDA_VCLKData1;
1769 *di_1 = pVBInfo->LCDCapList[index].LCDA_VCLKData2;
1770 }
1771 }
1772 return;
1773}
1774
1775static unsigned char XGI_GetVCLKPtr(unsigned short RefreshRateTableIndex,
1776 unsigned short ModeNo, unsigned short ModeIdIndex,
1777 struct vb_device_info *pVBInfo)
1778{
1779
1780 unsigned short index, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001781 unsigned char tempal;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001782
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001783 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02001784 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001785
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001786 if ((pVBInfo->SetFlag & ProgrammingCRT2) &&
1787 (!(pVBInfo->LCDInfo & EnableScalingLCD))) { /* {LCDA/LCDB} */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001788 index = XGI_GetLCDCapPtr(pVBInfo);
1789 tempal = pVBInfo->LCDCapList[index].LCD_VCLK;
1790
Peter Huewea3d675c2012-02-09 21:11:47 +01001791 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001792 return tempal;
1793
1794 /* {TV} */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001795 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01001796 (VB_SIS301B |
1797 VB_SIS302B |
1798 VB_SIS301LV |
1799 VB_SIS302LV |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001800 VB_XGI301C)) {
Peter Huewe599801f2012-02-09 21:11:45 +01001801 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001802 tempal = TVCLKBASE_315 + HiTVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001803 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
Peter Hueweccc8cb22012-02-09 21:11:48 +01001804 tempal = TVCLKBASE_315 + HiTVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001805 if (pVBInfo->TVInfo & TVSimuMode) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001806 tempal = TVCLKBASE_315 + HiTVSimuVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001807 if (!(modeflag & Charx8Dot))
Miguel Gómez3bcc2462012-07-06 12:40:53 +02001808 tempal = TVCLKBASE_315 +
1809 HiTVTextVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001810
1811 }
1812 return tempal;
1813 }
1814
Peter Huewe599801f2012-02-09 21:11:45 +01001815 if (pVBInfo->TVInfo & TVSetYPbPr750p) {
Peter Huewea3d675c2012-02-09 21:11:47 +01001816 tempal = XGI_YPbPr750pVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001817 return tempal;
1818 }
1819
Peter Huewe599801f2012-02-09 21:11:45 +01001820 if (pVBInfo->TVInfo & TVSetYPbPr525p) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001821 tempal = YPbPr525pVCLK;
1822 return tempal;
1823 }
1824
1825 tempal = NTSC1024VCLK;
1826
1827 if (!(pVBInfo->TVInfo & NTSC1024x768)) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001828 tempal = TVCLKBASE_315 + TVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001829 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
Peter Hueweccc8cb22012-02-09 21:11:48 +01001830 tempal = TVCLKBASE_315 + TVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001831 }
1832
1833 if (pVBInfo->VBInfo & SetCRT2ToTV)
1834 return tempal;
1835 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001836 } /* {End of VB} */
1837
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02001838 tempal = (unsigned char) inb((pVBInfo->P3ca + 0x02));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001839 tempal = tempal >> 2;
1840 tempal &= 0x03;
1841
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001842 /* for Dot8 Scaling LCD */
1843 if ((pVBInfo->LCDInfo & EnableScalingLCD) && (modeflag & Charx8Dot))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001844 tempal = tempal ^ tempal; /* ; set to VCLK25MHz always */
1845
Aaro Koskinena39325d2012-11-04 21:14:53 +02001846 tempal = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001847 return tempal;
1848}
1849
1850static void XGI_GetVCLKLen(unsigned char tempal, unsigned char *di_0,
1851 unsigned char *di_1, struct vb_device_info *pVBInfo)
1852{
Peter Huewe6896b942012-02-09 21:11:46 +01001853 if (pVBInfo->VBType & (VB_SIS301 | VB_SIS301B | VB_SIS302B
1854 | VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +02001855 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) &&
1856 (pVBInfo->SetFlag & ProgrammingCRT2)) {
Aaro Koskinene8cb03d2012-09-11 00:15:31 +03001857 *di_0 = XGI_VBVCLKData[tempal].Part4_A;
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +03001858 *di_1 = XGI_VBVCLKData[tempal].Part4_B;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001859 }
1860 } else {
1861 *di_0 = XGI_VCLKData[tempal].SR2B;
1862 *di_1 = XGI_VCLKData[tempal].SR2C;
1863 }
1864}
1865
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001866static void XGI_SetCRT2ECLK(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301867 unsigned short RefreshRateTableIndex,
1868 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001869{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301870 unsigned char di_0, di_1, tempal;
1871 int i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001872
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301873 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
1874 pVBInfo);
1875 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
1876 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001877
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301878 for (i = 0; i < 4; i++) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001879 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, ~0x30,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301880 (unsigned short) (0x10 * i));
Peter Huewea3d675c2012-02-09 21:11:47 +01001881 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301882 && (!(pVBInfo->VBInfo & SetInSlaveMode))) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001883 xgifb_reg_set(pVBInfo->P3c4, 0x2e, di_0);
1884 xgifb_reg_set(pVBInfo->P3c4, 0x2f, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301885 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001886 xgifb_reg_set(pVBInfo->P3c4, 0x2b, di_0);
1887 xgifb_reg_set(pVBInfo->P3c4, 0x2c, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301888 }
1889 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001890}
1891
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001892static void XGI_UpdateModeInfo(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301893 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001894{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301895 unsigned short tempcl, tempch, temp, tempbl, tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001896
Peter Huewe6896b942012-02-09 21:11:46 +01001897 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
1898 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301899 tempcl = 0;
1900 tempch = 0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02001901 temp = xgifb_reg_get(pVBInfo->P3c4, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001902
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301903 if (!(temp & 0x20)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001904 temp = xgifb_reg_get(pVBInfo->P3d4, 0x17);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301905 if (temp & 0x80) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001906 temp = xgifb_reg_get(pVBInfo->P3d4, 0x53);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301907 if (!(temp & 0x40))
1908 tempcl |= ActiveCRT1;
1909 }
1910 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001911
Aaro Koskinen58839b02011-03-13 12:26:23 +02001912 temp = xgifb_reg_get(pVBInfo->Part1Port, 0x2e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301913 temp &= 0x0f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001914
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301915 if (!(temp == 0x08)) {
Miguel Gómez949eb0a2012-07-06 12:40:36 +02001916 /* Check ChannelA */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001917 tempax = xgifb_reg_get(pVBInfo->Part1Port, 0x13);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301918 if (tempax & 0x04)
1919 tempcl = tempcl | ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001920
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301921 temp &= 0x05;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001922
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301923 if (!(tempcl & ActiveLCD))
1924 if (temp == 0x01)
1925 tempcl |= ActiveCRT2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001926
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301927 if (temp == 0x04)
1928 tempcl |= ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001929
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301930 if (temp == 0x05) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001931 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001932
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301933 if (!(temp & 0x08))
1934 tempch |= ActiveAVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001935
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301936 if (!(temp & 0x04))
1937 tempch |= ActiveSVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001938
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301939 if (temp & 0x02)
1940 tempch |= ActiveSCART;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001941
Peter Huewe599801f2012-02-09 21:11:45 +01001942 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301943 if (temp & 0x01)
1944 tempch |= ActiveHiTV;
1945 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001946
Peter Huewe599801f2012-02-09 21:11:45 +01001947 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001948 temp = xgifb_reg_get(
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301949 pVBInfo->Part2Port,
1950 0x4d);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001951
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301952 if (temp & 0x10)
1953 tempch |= ActiveYPbPr;
1954 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001955
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301956 if (tempch != 0)
1957 tempcl |= ActiveTV;
1958 }
1959 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001960
Aaro Koskinen58839b02011-03-13 12:26:23 +02001961 temp = xgifb_reg_get(pVBInfo->P3d4, 0x3d);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301962 if (tempcl & ActiveLCD) {
1963 if ((pVBInfo->SetFlag & ReserveTVOption)) {
1964 if (temp & ActiveTV)
1965 tempcl |= ActiveTV;
1966 }
1967 }
1968 temp = tempcl;
Peter Huewea3d675c2012-02-09 21:11:47 +01001969 tempbl = ~XGI_ModeSwitchStatus;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001970 xgifb_reg_and_or(pVBInfo->P3d4, 0x3d, tempbl, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001971
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301972 if (!(pVBInfo->SetFlag & ReserveTVOption))
Aaro Koskinen8104e322011-03-13 12:26:22 +02001973 xgifb_reg_set(pVBInfo->P3d4, 0x3e, tempch);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301974 } else {
1975 return;
1976 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001977}
1978
Bill Pemberton80adad82010-06-17 13:10:51 -04001979void XGI_GetVBType(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001980{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301981 unsigned short flag, tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001982
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001983 if (pVBInfo->IF_DEF_LVDS != 0)
1984 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001985
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001986 tempbx = VB_SIS302B;
1987 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
1988 if (flag == 0x02)
1989 goto finish;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001990
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001991 tempbx = VB_SIS301;
1992 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x01);
1993 if (flag < 0xB0)
1994 goto finish;
1995
1996 tempbx = VB_SIS301B;
1997 if (flag < 0xC0)
1998 goto bigger_than_0xB0;
1999
2000 tempbx = VB_XGI301C;
2001 if (flag < 0xD0)
2002 goto bigger_than_0xB0;
2003
2004 tempbx = VB_SIS301LV;
2005 if (flag < 0xE0)
2006 goto bigger_than_0xB0;
2007
2008 tempbx = VB_SIS302LV;
2009 tempah = xgifb_reg_get(pVBInfo->Part4Port, 0x39);
2010 if (tempah != 0xFF)
2011 tempbx = VB_XGI301C;
2012
2013bigger_than_0xB0:
2014 if (tempbx & (VB_SIS301B | VB_SIS302B)) {
2015 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x23);
2016 if (!(flag & 0x02))
2017 tempbx = tempbx | VB_NoLCD;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302018 }
Miguel Gómez7eec23a2012-07-06 12:40:47 +02002019
2020finish:
2021 pVBInfo->VBType = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002022}
2023
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02002024static void XGI_GetVBInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302025 struct xgi_hw_device_info *HwDeviceExtension,
2026 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002027{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302028 unsigned short tempax, push, tempbx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002029
Aaro Koskinenb3979922012-11-04 21:14:52 +02002030 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302031 pVBInfo->SetFlag = 0;
Peter Huewe6896b942012-02-09 21:11:46 +01002032 pVBInfo->ModeType = modeflag & ModeTypeMask;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302033 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002034
Miguel Gómezf9317352012-07-06 12:40:48 +02002035 if (!(pVBInfo->VBType & 0xFFFF))
2036 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002037
Miguel Gómezf9317352012-07-06 12:40:48 +02002038 /* Check Display Device */
2039 temp = xgifb_reg_get(pVBInfo->P3d4, 0x30);
2040 tempbx = tempbx | temp;
2041 temp = xgifb_reg_get(pVBInfo->P3d4, 0x31);
2042 push = temp;
2043 push = push << 8;
2044 tempax = temp << 8;
2045 tempbx = tempbx | tempax;
2046 temp = (SetCRT2ToDualEdge | SetCRT2ToYPbPr525750 | XGI_SetCRT2ToLCDA
2047 | SetInSlaveMode | DisableCRT2Display);
2048 temp = 0xFFFF ^ temp;
2049 tempbx &= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002050
Miguel Gómezf9317352012-07-06 12:40:48 +02002051 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002052
Aaro Koskinen4d8f5ca2012-09-11 00:15:17 +03002053 if (pVBInfo->IF_DEF_LVDS == 0) {
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03002054 if (pVBInfo->VBType &
2055 (VB_SIS302B |
2056 VB_SIS301LV |
2057 VB_SIS302LV |
2058 VB_XGI301C)) {
2059 if (temp & EnableDualEdge) {
2060 tempbx |= SetCRT2ToDualEdge;
2061 if (temp & SetToLCDA)
2062 tempbx |= XGI_SetCRT2ToLCDA;
Miguel Gómezf9317352012-07-06 12:40:48 +02002063 }
2064 }
2065 }
2066
2067 if (pVBInfo->IF_DEF_YPbPr == 1) {
2068 if (((pVBInfo->IF_DEF_LVDS == 0) &&
2069 ((pVBInfo->VBType & VB_SIS301LV) ||
2070 (pVBInfo->VBType & VB_SIS302LV) ||
2071 (pVBInfo->VBType & VB_XGI301C)))) {
2072 if (temp & SetYPbPr) {
2073 if (pVBInfo->IF_DEF_HiVision == 1) {
2074 /* shampoo add for new
2075 * scratch */
2076 temp = xgifb_reg_get(
2077 pVBInfo->P3d4,
2078 0x35);
2079 temp &= YPbPrMode;
2080 tempbx |= SetCRT2ToHiVision;
2081
2082 if (temp != YPbPrMode1080i) {
2083 tempbx &=
2084 (~SetCRT2ToHiVision);
2085 tempbx |=
2086 SetCRT2ToYPbPr525750;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302087 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302088 }
2089 }
2090 }
Miguel Gómezf9317352012-07-06 12:40:48 +02002091 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002092
Miguel Gómezf9317352012-07-06 12:40:48 +02002093 tempax = push; /* restore CR31 */
2094
2095 if (pVBInfo->IF_DEF_LVDS == 0) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302096 if (pVBInfo->IF_DEF_YPbPr == 1) {
Miguel Gómezf9317352012-07-06 12:40:48 +02002097 if (pVBInfo->IF_DEF_HiVision == 1)
2098 temp = 0x09FC;
2099 else
2100 temp = 0x097C;
Aaro Koskinend3ae5762012-09-11 00:15:27 +03002101 } else if (pVBInfo->IF_DEF_HiVision == 1) {
2102 temp = 0x01FC;
Miguel Gómezf9317352012-07-06 12:40:48 +02002103 } else {
Aaro Koskinend3ae5762012-09-11 00:15:27 +03002104 temp = 0x017C;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302105 }
Justin P. Mattock558f7582012-10-02 21:17:11 -07002106 } else { /* 3rd party chip */
Miguel Gómezf9317352012-07-06 12:40:48 +02002107 temp = SetCRT2ToLCD;
2108 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002109
Miguel Gómezf9317352012-07-06 12:40:48 +02002110 if (!(tempbx & temp)) {
2111 tempax |= DisableCRT2Display;
2112 tempbx = 0;
2113 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002114
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03002115 if (!(pVBInfo->VBType & VB_NoLCD)) {
2116 if (tempbx & XGI_SetCRT2ToLCDA) {
2117 if (tempbx & SetSimuScanMode)
2118 tempbx &= (~(SetCRT2ToLCD |
2119 SetCRT2ToRAMDAC |
2120 SwitchCRT2));
2121 else
2122 tempbx &= (~(SetCRT2ToLCD |
2123 SetCRT2ToRAMDAC |
2124 SetCRT2ToTV |
2125 SwitchCRT2));
Miguel Gómezf9317352012-07-06 12:40:48 +02002126 }
2127 }
2128
2129 /* shampoo add */
2130 /* for driver abnormal */
2131 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode))) {
2132 if (pVBInfo->IF_DEF_CRT2Monitor == 1) {
2133 if (tempbx & SetCRT2ToRAMDAC) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002134 tempbx &= (0xFF00 |
Miguel Gómezf9317352012-07-06 12:40:48 +02002135 SetCRT2ToRAMDAC |
Peter Huewe6896b942012-02-09 21:11:46 +01002136 SwitchCRT2 |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002137 SetSimuScanMode);
Peter Huewe599801f2012-02-09 21:11:45 +01002138 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302139 }
Miguel Gómezf9317352012-07-06 12:40:48 +02002140 } else {
2141 tempbx &= (~(SetCRT2ToRAMDAC |
2142 SetCRT2ToLCD |
2143 SetCRT2ToTV));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302144 }
Miguel Gómezf9317352012-07-06 12:40:48 +02002145 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002146
Miguel Gómezf9317352012-07-06 12:40:48 +02002147 if (!(pVBInfo->VBType & VB_NoLCD)) {
2148 if (tempbx & SetCRT2ToLCD) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002149 tempbx &= (0xFF00 |
Miguel Gómezf9317352012-07-06 12:40:48 +02002150 SetCRT2ToLCD |
Peter Huewe6896b942012-02-09 21:11:46 +01002151 SwitchCRT2 |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002152 SetSimuScanMode);
Peter Huewe599801f2012-02-09 21:11:45 +01002153 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302154 }
Miguel Gómezf9317352012-07-06 12:40:48 +02002155 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002156
Miguel Gómezf9317352012-07-06 12:40:48 +02002157 if (tempbx & SetCRT2ToSCART) {
2158 tempbx &= (0xFF00 |
2159 SetCRT2ToSCART |
2160 SwitchCRT2 |
2161 SetSimuScanMode);
2162 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
2163 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002164
Miguel Gómezf9317352012-07-06 12:40:48 +02002165 if (pVBInfo->IF_DEF_YPbPr == 1) {
2166 if (tempbx & SetCRT2ToYPbPr525750)
2167 tempbx &= (0xFF00 |
2168 SwitchCRT2 |
2169 SetSimuScanMode);
2170 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002171
Miguel Gómezf9317352012-07-06 12:40:48 +02002172 if (pVBInfo->IF_DEF_HiVision == 1) {
2173 if (tempbx & SetCRT2ToHiVision)
2174 tempbx &= (0xFF00 |
2175 SetCRT2ToHiVision |
2176 SwitchCRT2 |
2177 SetSimuScanMode);
2178 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002179
Miguel Gómezf9317352012-07-06 12:40:48 +02002180 if (tempax & DisableCRT2Display) { /* Set Display Device Info */
2181 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode)))
2182 tempbx = DisableCRT2Display;
2183 }
2184
2185 if (!(tempbx & DisableCRT2Display)) {
2186 if ((!(tempbx & DriverMode)) ||
2187 (!(modeflag & CRT2Mode))) {
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03002188 if (!(tempbx & XGI_SetCRT2ToLCDA))
2189 tempbx |= (SetInSlaveMode |
2190 SetSimuScanMode);
Miguel Gómezf9317352012-07-06 12:40:48 +02002191 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002192
Miguel Gómezf9317352012-07-06 12:40:48 +02002193 /* LCD+TV can't support in slave mode
2194 * (Force LCDA+TV->LCDB) */
2195 if ((tempbx & SetInSlaveMode) &&
2196 (tempbx & XGI_SetCRT2ToLCDA)) {
2197 tempbx ^= (SetCRT2ToLCD |
2198 XGI_SetCRT2ToLCDA |
2199 SetCRT2ToDualEdge);
2200 pVBInfo->SetFlag |= ReserveTVOption;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302201 }
2202 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002203
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302204 pVBInfo->VBInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002205}
2206
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02002207static void XGI_GetTVInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302208 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002209{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302210 unsigned short temp, tempbx = 0, resinfo = 0, modeflag, index1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002211
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302212 tempbx = 0;
2213 resinfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002214
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302215 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinenb3979922012-11-04 21:14:52 +02002216 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2217 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002218
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302219 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002220 temp = xgifb_reg_get(pVBInfo->P3d4, 0x35);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302221 tempbx = temp;
Peter Huewe599801f2012-02-09 21:11:45 +01002222 if (tempbx & TVSetPAL) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002223 tempbx &= (SetCHTVOverScan |
Peter Huewe599801f2012-02-09 21:11:45 +01002224 TVSetPALM |
2225 TVSetPALN |
2226 TVSetPAL);
2227 if (tempbx & TVSetPALM)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002228 /* set to NTSC if PAL-M */
Peter Huewe599801f2012-02-09 21:11:45 +01002229 tempbx &= ~TVSetPAL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302230 } else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002231 tempbx &= (SetCHTVOverScan |
Peter Huewe599801f2012-02-09 21:11:45 +01002232 TVSetNTSCJ |
2233 TVSetPAL);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302234 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002235
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302236 if (pVBInfo->IF_DEF_LVDS == 0) {
2237 if (pVBInfo->VBInfo & SetCRT2ToSCART)
Peter Huewe599801f2012-02-09 21:11:45 +01002238 tempbx |= TVSetPAL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302239 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002240
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302241 if (pVBInfo->IF_DEF_YPbPr == 1) {
Peter Huewe599801f2012-02-09 21:11:45 +01002242 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002243 index1 = xgifb_reg_get(pVBInfo->P3d4, 0x35);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302244 index1 &= YPbPrMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002245
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302246 if (index1 == YPbPrMode525i)
Peter Huewe599801f2012-02-09 21:11:45 +01002247 tempbx |= TVSetYPbPr525i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002248
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302249 if (index1 == YPbPrMode525p)
Peter Huewe599801f2012-02-09 21:11:45 +01002250 tempbx = tempbx | TVSetYPbPr525p;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302251 if (index1 == YPbPrMode750p)
Peter Huewe599801f2012-02-09 21:11:45 +01002252 tempbx = tempbx | TVSetYPbPr750p;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302253 }
2254 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002255
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302256 if (pVBInfo->IF_DEF_HiVision == 1) {
Peter Huewe599801f2012-02-09 21:11:45 +01002257 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
2258 tempbx = tempbx | TVSetHiVision | TVSetPAL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302259 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002260
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302261 if (pVBInfo->IF_DEF_LVDS == 0) { /* shampoo */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002262 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
2263 (!(pVBInfo->VBInfo & SetNotSimuMode)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302264 tempbx |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002265
Peter Huewe599801f2012-02-09 21:11:45 +01002266 if (!(tempbx & TVSetPAL) &&
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002267 (modeflag > 13) &&
2268 (resinfo == 8)) /* NTSC 1024x768, */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302269 tempbx |= NTSC1024x768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002270
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302271 tempbx |= RPLLDIV2XO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002272
Peter Huewe599801f2012-02-09 21:11:45 +01002273 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302274 if (pVBInfo->VBInfo & SetInSlaveMode)
2275 tempbx &= (~RPLLDIV2XO);
Aaro Koskinend3ae5762012-09-11 00:15:27 +03002276 } else if (tempbx &
2277 (TVSetYPbPr525p | TVSetYPbPr750p)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302278 tempbx &= (~RPLLDIV2XO);
Aaro Koskinend3ae5762012-09-11 00:15:27 +03002279 } else if (!(pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01002280 (VB_SIS301B |
2281 VB_SIS302B |
2282 VB_SIS301LV |
2283 VB_SIS302LV |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002284 VB_XGI301C))) {
Aaro Koskinend3ae5762012-09-11 00:15:27 +03002285 if (tempbx & TVSimuMode)
2286 tempbx &= (~RPLLDIV2XO);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302287 }
2288 }
2289 }
2290 pVBInfo->TVInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002291}
2292
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02002293static unsigned char XGI_GetLCDInfo(unsigned short ModeNo,
2294 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002295{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302296 unsigned short temp, tempax, tempbx, modeflag, resinfo = 0, LCDIdIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002297
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302298 pVBInfo->LCDResInfo = 0;
2299 pVBInfo->LCDTypeInfo = 0;
2300 pVBInfo->LCDInfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002301
Aaro Koskinenb3979922012-11-04 21:14:52 +02002302 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002303 /* si+Ext_ResInfo // */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002304 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinen58839b02011-03-13 12:26:23 +02002305 temp = xgifb_reg_get(pVBInfo->P3d4, 0x36); /* Get LCD Res.Info */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302306 tempbx = temp & 0x0F;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002307
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302308 if (tempbx == 0)
Peter Huewe255aabd2012-02-09 21:11:44 +01002309 tempbx = Panel_1024x768; /* default */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002310
Miguel Gómez949eb0a2012-07-06 12:40:36 +02002311 /* LCD75 */
Peter Huewe255aabd2012-02-09 21:11:44 +01002312 if ((tempbx == Panel_1024x768) || (tempbx == Panel_1280x1024)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302313 if (pVBInfo->VBInfo & DriverMode) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002314 tempax = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Peter Huewea3d675c2012-02-09 21:11:47 +01002315 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302316 tempax &= 0x0F;
2317 else
2318 tempax = tempax >> 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002319
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302320 if ((resinfo == 6) || (resinfo == 9)) {
2321 if (tempax >= 3)
2322 tempbx |= PanelRef75Hz;
2323 } else if ((resinfo == 7) || (resinfo == 8)) {
2324 if (tempax >= 4)
2325 tempbx |= PanelRef75Hz;
2326 }
2327 }
2328 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002329
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302330 pVBInfo->LCDResInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002331
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302332 /* End of LCD75 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002333
Peter Huewea3d675c2012-02-09 21:11:47 +01002334 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302335 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002336
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302337 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002338
Aaro Koskinen58839b02011-03-13 12:26:23 +02002339 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002340
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302341 temp &= (ScalingLCD | LCDNonExpanding | LCDSyncBit | SetPWDEnable);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002342
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302343 tempbx |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002344
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302345 LCDIdIndex = XGI_GetLCDCapPtr1(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002346
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302347 tempax = pVBInfo->LCDCapList[LCDIdIndex].LCD_Capability;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002348
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302349 if (pVBInfo->IF_DEF_LVDS == 0) { /* shampoo */
Peter Huewe6896b942012-02-09 21:11:46 +01002350 if (((pVBInfo->VBType & VB_SIS302LV) || (pVBInfo->VBType
Peter Huewea3d675c2012-02-09 21:11:47 +01002351 & VB_XGI301C)) && (tempax & XGI_LCDDualLink)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302352 tempbx |= SetLCDDualLink;
2353 }
2354 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002355
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302356 if (pVBInfo->IF_DEF_LVDS == 0) {
Peter Huewe255aabd2012-02-09 21:11:44 +01002357 if ((pVBInfo->LCDResInfo == Panel_1400x1050) && (pVBInfo->VBInfo
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002358 & SetCRT2ToLCD) && (resinfo == 9) &&
2359 (!(tempbx & EnableScalingLCD)))
Miguel Gómez3bcc2462012-07-06 12:40:53 +02002360 /*
2361 * set to center in 1280x1024 LCDB
2362 * for Panel_1400x1050
2363 */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002364 tempbx |= SetLCDtoNonExpanding;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302365 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002366
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302367 if (pVBInfo->VBInfo & SetInSlaveMode) {
2368 if (pVBInfo->VBInfo & SetNotSimuMode)
Peter Huewea3d675c2012-02-09 21:11:47 +01002369 tempbx |= XGI_LCDVESATiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302370 } else {
Peter Huewea3d675c2012-02-09 21:11:47 +01002371 tempbx |= XGI_LCDVESATiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302372 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002373
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302374 pVBInfo->LCDInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002375
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302376 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002377}
2378
Bill Pemberton108afbf2010-06-17 13:10:47 -04002379unsigned char XGI_SearchModeID(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302380 unsigned short *ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002381{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002382 for (*ModeIdIndex = 0;; (*ModeIdIndex)++) {
Aaro Koskinenb3979922012-11-04 21:14:52 +02002383 if (XGI330_EModeIDTable[*ModeIdIndex].Ext_ModeID == ModeNo)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002384 break;
Aaro Koskinenb3979922012-11-04 21:14:52 +02002385 if (XGI330_EModeIDTable[*ModeIdIndex].Ext_ModeID == 0xFF)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002386 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302387 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002388
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302389 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002390}
2391
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002392static unsigned char XG21GPIODataTransfer(unsigned char ujDate)
2393{
2394 unsigned char ujRet = 0;
2395 unsigned char i = 0;
2396
2397 for (i = 0; i < 8; i++) {
2398 ujRet = ujRet << 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002399 ujRet |= (ujDate >> i) & 1;
2400 }
2401
2402 return ujRet;
2403}
2404
2405/*----------------------------------------------------------------------------*/
2406/* output */
2407/* bl[5] : LVDS signal */
2408/* bl[1] : LVDS backlight */
2409/* bl[0] : LVDS VDD */
2410/*----------------------------------------------------------------------------*/
2411static unsigned char XGI_XG21GetPSCValue(struct vb_device_info *pVBInfo)
2412{
2413 unsigned char CR4A, temp;
2414
Aaro Koskinen58839b02011-03-13 12:26:23 +02002415 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02002416 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x23); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002417
Aaro Koskinen58839b02011-03-13 12:26:23 +02002418 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002419
2420 temp = XG21GPIODataTransfer(temp);
2421 temp &= 0x23;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002422 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002423 return temp;
2424}
2425
2426/*----------------------------------------------------------------------------*/
2427/* output */
2428/* bl[5] : LVDS signal */
2429/* bl[1] : LVDS backlight */
2430/* bl[0] : LVDS VDD */
2431/*----------------------------------------------------------------------------*/
2432static unsigned char XGI_XG27GetPSCValue(struct vb_device_info *pVBInfo)
2433{
2434 unsigned char CR4A, CRB4, temp;
2435
Aaro Koskinen58839b02011-03-13 12:26:23 +02002436 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02002437 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x0C); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002438
Aaro Koskinen58839b02011-03-13 12:26:23 +02002439 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002440
2441 temp &= 0x0C;
2442 temp >>= 2;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002443 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinen58839b02011-03-13 12:26:23 +02002444 CRB4 = xgifb_reg_get(pVBInfo->P3d4, 0xB4);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002445 temp |= ((CRB4 & 0x04) << 3);
2446 return temp;
2447}
2448
Aaro Koskinen0ebf5382011-11-27 23:03:09 +02002449/*----------------------------------------------------------------------------*/
2450/* input */
2451/* bl[5] : 1;LVDS signal on */
2452/* bl[1] : 1;LVDS backlight on */
2453/* bl[0] : 1:LVDS VDD on */
2454/* bh: 100000b : clear bit 5, to set bit5 */
2455/* 000010b : clear bit 1, to set bit1 */
2456/* 000001b : clear bit 0, to set bit0 */
2457/*----------------------------------------------------------------------------*/
2458static void XGI_XG21BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
2459 struct vb_device_info *pVBInfo)
2460{
2461 unsigned char CR4A, temp;
2462
2463 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
2464 tempbh &= 0x23;
2465 tempbl &= 0x23;
2466 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
2467
2468 if (tempbh & 0x20) {
2469 temp = (tempbl >> 4) & 0x02;
2470
2471 /* CR B4[1] */
2472 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
2473
2474 }
2475
2476 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
2477
2478 temp = XG21GPIODataTransfer(temp);
2479 temp &= ~tempbh;
2480 temp |= tempbl;
2481 xgifb_reg_set(pVBInfo->P3d4, 0x48, temp);
2482}
2483
Aaro Koskinen776115a2011-11-27 23:03:10 +02002484static void XGI_XG27BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
2485 struct vb_device_info *pVBInfo)
2486{
2487 unsigned char CR4A, temp;
2488 unsigned short tempbh0, tempbl0;
2489
2490 tempbh0 = tempbh;
2491 tempbl0 = tempbl;
2492 tempbh0 &= 0x20;
2493 tempbl0 &= 0x20;
2494 tempbh0 >>= 3;
2495 tempbl0 >>= 3;
2496
2497 if (tempbh & 0x20) {
2498 temp = (tempbl >> 4) & 0x02;
2499
2500 /* CR B4[1] */
2501 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
2502
2503 }
2504 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~tempbh0, tempbl0);
2505
2506 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
2507 tempbh &= 0x03;
2508 tempbl &= 0x03;
2509 tempbh <<= 2;
2510 tempbl <<= 2; /* GPIOC,GPIOD */
2511 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
2512 xgifb_reg_and_or(pVBInfo->P3d4, 0x48, ~tempbh, tempbl);
2513}
2514
Aaro Koskinenfab04b92011-12-06 00:10:45 +02002515static void XGI_DisplayOn(struct xgifb_video_info *xgifb_info,
2516 struct xgi_hw_device_info *pXGIHWDE,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302517 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002518{
2519
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002520 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302521 if (pXGIHWDE->jChipType == XG21) {
2522 if (pVBInfo->IF_DEF_LVDS == 1) {
2523 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002524 /* LVDS VDD on */
2525 XGI_XG21BLSignalVDD(0x01, 0x01, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002526 mdelay(xgifb_info->lvds_data.PSC_S2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302527 }
2528 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002529 /* LVDS signal on */
2530 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002531 mdelay(xgifb_info->lvds_data.PSC_S3);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002532 /* LVDS backlight on */
2533 XGI_XG21BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302534 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002535 /* DVO/DVI signal on */
2536 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302537 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002538
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302539 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002540
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302541 if (pXGIHWDE->jChipType == XG27) {
2542 if (pVBInfo->IF_DEF_LVDS == 1) {
2543 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002544 /* LVDS VDD on */
2545 XGI_XG27BLSignalVDD(0x01, 0x01, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002546 mdelay(xgifb_info->lvds_data.PSC_S2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302547 }
2548 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002549 /* LVDS signal on */
2550 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002551 mdelay(xgifb_info->lvds_data.PSC_S3);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002552 /* LVDS backlight on */
2553 XGI_XG27BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302554 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002555 /* DVO/DVI signal on */
2556 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302557 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002558
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302559 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002560}
2561
Aaro Koskinenfab04b92011-12-06 00:10:45 +02002562void XGI_DisplayOff(struct xgifb_video_info *xgifb_info,
2563 struct xgi_hw_device_info *pXGIHWDE,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302564 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002565{
2566
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302567 if (pXGIHWDE->jChipType == XG21) {
2568 if (pVBInfo->IF_DEF_LVDS == 1) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002569 /* LVDS backlight off */
2570 XGI_XG21BLSignalVDD(0x02, 0x00, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002571 mdelay(xgifb_info->lvds_data.PSC_S3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302572 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002573 /* DVO/DVI signal off */
2574 XGI_XG21BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302575 }
2576 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002577
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302578 if (pXGIHWDE->jChipType == XG27) {
2579 if ((XGI_XG27GetPSCValue(pVBInfo) & 0x2)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002580 /* LVDS backlight off */
2581 XGI_XG27BLSignalVDD(0x02, 0x00, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002582 mdelay(xgifb_info->lvds_data.PSC_S3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302583 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002584
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302585 if (pVBInfo->IF_DEF_LVDS == 0)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002586 /* DVO/DVI signal off */
2587 XGI_XG27BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302588 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002589
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002590 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x20);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002591}
2592
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002593static void XGI_WaitDisply(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002594{
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02002595 while ((inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302596 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002597
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02002598 while (!(inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302599 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002600}
2601
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002602static void XGI_AutoThreshold(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002603{
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002604 xgifb_reg_or(pVBInfo->Part1Port, 0x01, 0x40);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002605}
2606
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002607static void XGI_SaveCRT2Info(unsigned short ModeNo,
2608 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002609{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302610 unsigned short temp1, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002611
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002612 /* reserve CR34 for CRT1 Mode No */
2613 xgifb_reg_set(pVBInfo->P3d4, 0x34, ModeNo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302614 temp1 = (pVBInfo->VBInfo & SetInSlaveMode) >> 8;
2615 temp2 = ~(SetInSlaveMode >> 8);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002616 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, temp2, temp1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002617}
2618
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002619static void XGI_GetCRT2ResInfo(unsigned short ModeNo,
2620 unsigned short ModeIdIndex,
2621 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002622{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302623 unsigned short xres, yres, modeflag, resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002624
Aaro Koskinenb3979922012-11-04 21:14:52 +02002625 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02002626 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
2627 yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002628 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002629 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002630
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002631 if (modeflag & HalfDCLK)
2632 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002633
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002634 if (modeflag & DoubleScanMode)
2635 yres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002636
Miguel Gómez3339db82012-07-06 12:40:49 +02002637 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
2638 goto exit;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002639
Miguel Gómez3339db82012-07-06 12:40:49 +02002640 if (pVBInfo->IF_DEF_LVDS == 0) {
2641 if (pVBInfo->LCDResInfo == Panel_1600x1200) {
2642 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
2643 if (yres == 1024)
2644 yres = 1056;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302645 }
2646 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002647
Miguel Gómez3339db82012-07-06 12:40:49 +02002648 if (pVBInfo->LCDResInfo == Panel_1280x1024) {
2649 if (yres == 400)
2650 yres = 405;
2651 else if (yres == 350)
2652 yres = 360;
2653
2654 if (pVBInfo->LCDInfo & XGI_LCDVESATiming) {
2655 if (yres == 360)
2656 yres = 375;
2657 }
2658 }
2659
2660 if (pVBInfo->LCDResInfo == Panel_1024x768) {
2661 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
2662 if (!(pVBInfo->LCDInfo & LCDNonExpanding)) {
2663 if (yres == 350)
2664 yres = 357;
2665 else if (yres == 400)
2666 yres = 420;
2667 else if (yres == 480)
2668 yres = 525;
2669 }
2670 }
2671 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302672 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002673
Miguel Gómez3339db82012-07-06 12:40:49 +02002674 if (xres == 720)
2675 xres = 640;
2676
2677exit:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302678 pVBInfo->VGAHDE = xres;
2679 pVBInfo->HDE = xres;
2680 pVBInfo->VGAVDE = yres;
2681 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002682}
2683
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002684static unsigned char XGI_IsLCDDualLink(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002685{
2686
Peter Huewea3d675c2012-02-09 21:11:47 +01002687 if ((pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) &&
Dan Carpentera65fd092011-01-04 09:02:27 +03002688 (pVBInfo->LCDInfo & SetLCDDualLink)) /* shampoo0129 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302689 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002690
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302691 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002692}
2693
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002694static void XGI_GetRAMDAC2DATA(unsigned short ModeNo,
2695 unsigned short ModeIdIndex,
2696 unsigned short RefreshRateTableIndex,
2697 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002698{
2699 unsigned short tempax, tempbx, temp1, temp2, modeflag = 0, tempcx,
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002700 CRT1Index;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002701
2702 pVBInfo->RVBHCMAX = 1;
2703 pVBInfo->RVBHCFACT = 1;
Aaro Koskinenb3979922012-11-04 21:14:52 +02002704 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02002705 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002706 CRT1Index &= IndexMask;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002707 temp1 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[0];
2708 temp2 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[5];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002709 tempax = (temp1 & 0xFF) | ((temp2 & 0x03) << 8);
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002710 tempbx = (unsigned short) XGI_CRT1Table[CRT1Index].CR[8];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002711 tempcx = (unsigned short)
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002712 XGI_CRT1Table[CRT1Index].CR[14] << 8;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002713 tempcx &= 0x0100;
2714 tempcx = tempcx << 2;
2715 tempbx |= tempcx;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002716 temp1 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[9];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002717
2718 if (temp1 & 0x01)
2719 tempbx |= 0x0100;
2720
2721 if (temp1 & 0x20)
2722 tempbx |= 0x0200;
2723 tempax += 5;
2724
2725 if (modeflag & Charx8Dot)
2726 tempax *= 8;
2727 else
2728 tempax *= 9;
2729
2730 pVBInfo->VGAHT = tempax;
2731 pVBInfo->HT = tempax;
2732 tempbx++;
2733 pVBInfo->VGAVT = tempbx;
2734 pVBInfo->VT = tempbx;
2735}
2736
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002737static void XGI_GetCRT2Data(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302738 unsigned short RefreshRateTableIndex,
2739 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002740{
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02002741 unsigned short tempax = 0, tempbx = 0, modeflag, resinfo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002742
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02002743 struct SiS_LCDData const *LCDPtr = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002744
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002745 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002746 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2747 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302748 pVBInfo->NewFlickerMode = 0;
2749 pVBInfo->RVBHRS = 50;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002750
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302751 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
2752 XGI_GetRAMDAC2DATA(ModeNo, ModeIdIndex, RefreshRateTableIndex,
2753 pVBInfo);
2754 return;
2755 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002756
Peter Huewea3d675c2012-02-09 21:11:47 +01002757 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02002758 LCDPtr = XGI_GetLcdPtr(XGI_LCDDataTable, ModeNo, ModeIdIndex,
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +03002759 RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002760
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302761 pVBInfo->RVBHCMAX = LCDPtr->RVBHCMAX;
2762 pVBInfo->RVBHCFACT = LCDPtr->RVBHCFACT;
2763 pVBInfo->VGAHT = LCDPtr->VGAHT;
2764 pVBInfo->VGAVT = LCDPtr->VGAVT;
2765 pVBInfo->HT = LCDPtr->LCDHT;
2766 pVBInfo->VT = LCDPtr->LCDVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002767
Peter Huewe255aabd2012-02-09 21:11:44 +01002768 if (pVBInfo->LCDResInfo == Panel_1024x768) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302769 tempax = 1024;
2770 tempbx = 768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002771
Peter Huewea3d675c2012-02-09 21:11:47 +01002772 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302773 if (pVBInfo->VGAVDE == 357)
2774 tempbx = 527;
2775 else if (pVBInfo->VGAVDE == 420)
2776 tempbx = 620;
2777 else if (pVBInfo->VGAVDE == 525)
2778 tempbx = 775;
2779 else if (pVBInfo->VGAVDE == 600)
2780 tempbx = 775;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302781 else
2782 tempbx = 768;
2783 } else
2784 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01002785 } else if (pVBInfo->LCDResInfo == Panel_1024x768x75) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302786 tempax = 1024;
2787 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01002788 } else if (pVBInfo->LCDResInfo == Panel_1280x1024) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302789 tempax = 1280;
2790 if (pVBInfo->VGAVDE == 360)
2791 tempbx = 768;
2792 else if (pVBInfo->VGAVDE == 375)
2793 tempbx = 800;
2794 else if (pVBInfo->VGAVDE == 405)
2795 tempbx = 864;
2796 else
2797 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01002798 } else if (pVBInfo->LCDResInfo == Panel_1280x1024x75) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302799 tempax = 1280;
2800 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01002801 } else if (pVBInfo->LCDResInfo == Panel_1280x960) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302802 tempax = 1280;
2803 if (pVBInfo->VGAVDE == 350)
2804 tempbx = 700;
2805 else if (pVBInfo->VGAVDE == 400)
2806 tempbx = 800;
2807 else if (pVBInfo->VGAVDE == 1024)
2808 tempbx = 960;
2809 else
2810 tempbx = 960;
Peter Huewe255aabd2012-02-09 21:11:44 +01002811 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302812 tempax = 1400;
2813 tempbx = 1050;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002814
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302815 if (pVBInfo->VGAVDE == 1024) {
2816 tempax = 1280;
2817 tempbx = 1024;
2818 }
Peter Huewe255aabd2012-02-09 21:11:44 +01002819 } else if (pVBInfo->LCDResInfo == Panel_1600x1200) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302820 tempax = 1600;
2821 tempbx = 1200; /* alan 10/14/2003 */
Peter Huewea3d675c2012-02-09 21:11:47 +01002822 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302823 if (pVBInfo->VGAVDE == 350)
2824 tempbx = 875;
2825 else if (pVBInfo->VGAVDE == 400)
2826 tempbx = 1000;
2827 }
2828 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002829
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302830 if (pVBInfo->LCDInfo & LCDNonExpanding) {
2831 tempax = pVBInfo->VGAHDE;
2832 tempbx = pVBInfo->VGAVDE;
2833 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002834
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302835 pVBInfo->HDE = tempax;
2836 pVBInfo->VDE = tempbx;
2837 return;
2838 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002839
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302840 if (pVBInfo->VBInfo & (SetCRT2ToTV)) {
Aaro Koskinen24572542012-09-11 00:15:21 +03002841 struct SiS_TVData const *TVPtr;
2842
2843 TVPtr = XGI_GetTVPtr(ModeNo, ModeIdIndex, RefreshRateTableIndex,
2844 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002845
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302846 pVBInfo->RVBHCMAX = TVPtr->RVBHCMAX;
2847 pVBInfo->RVBHCFACT = TVPtr->RVBHCFACT;
2848 pVBInfo->VGAHT = TVPtr->VGAHT;
2849 pVBInfo->VGAVT = TVPtr->VGAVT;
2850 pVBInfo->HDE = TVPtr->TVHDE;
2851 pVBInfo->VDE = TVPtr->TVVDE;
2852 pVBInfo->RVBHRS = TVPtr->RVBHRS;
2853 pVBInfo->NewFlickerMode = TVPtr->FlickerMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002854
Peter Huewe599801f2012-02-09 21:11:45 +01002855 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302856 if (resinfo == 0x08)
2857 pVBInfo->NewFlickerMode = 0x40;
2858 else if (resinfo == 0x09)
2859 pVBInfo->NewFlickerMode = 0x40;
2860 else if (resinfo == 0x12)
2861 pVBInfo->NewFlickerMode = 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002862
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302863 if (pVBInfo->VGAVDE == 350)
2864 pVBInfo->TVInfo |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002865
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302866 tempax = ExtHiTVHT;
2867 tempbx = ExtHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002868
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302869 if (pVBInfo->VBInfo & SetInSlaveMode) {
2870 if (pVBInfo->TVInfo & TVSimuMode) {
2871 tempax = StHiTVHT;
2872 tempbx = StHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002873
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302874 if (!(modeflag & Charx8Dot)) {
2875 tempax = StHiTextTVHT;
2876 tempbx = StHiTextTVVT;
2877 }
2878 }
2879 }
Peter Huewe599801f2012-02-09 21:11:45 +01002880 } else if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
2881 if (pVBInfo->TVInfo & TVSetYPbPr750p) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302882 tempax = YPbPrTV750pHT; /* Ext750pTVHT */
2883 tempbx = YPbPrTV750pVT; /* Ext750pTVVT */
2884 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002885
Peter Huewe599801f2012-02-09 21:11:45 +01002886 if (pVBInfo->TVInfo & TVSetYPbPr525p) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302887 tempax = YPbPrTV525pHT; /* Ext525pTVHT */
2888 tempbx = YPbPrTV525pVT; /* Ext525pTVVT */
Peter Huewe599801f2012-02-09 21:11:45 +01002889 } else if (pVBInfo->TVInfo & TVSetYPbPr525i) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302890 tempax = YPbPrTV525iHT; /* Ext525iTVHT */
2891 tempbx = YPbPrTV525iVT; /* Ext525iTVVT */
2892 if (pVBInfo->TVInfo & NTSC1024x768)
2893 tempax = NTSC1024x768HT;
2894 }
2895 } else {
2896 tempax = PALHT;
2897 tempbx = PALVT;
Peter Huewe599801f2012-02-09 21:11:45 +01002898 if (!(pVBInfo->TVInfo & TVSetPAL)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302899 tempax = NTSCHT;
2900 tempbx = NTSCVT;
2901 if (pVBInfo->TVInfo & NTSC1024x768)
2902 tempax = NTSC1024x768HT;
2903 }
2904 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002905
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302906 pVBInfo->HT = tempax;
2907 pVBInfo->VT = tempbx;
2908 return;
2909 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002910}
2911
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002912static void XGI_SetCRT2VCLK(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302913 unsigned short RefreshRateTableIndex,
2914 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002915{
Bill Pemberton108afbf2010-06-17 13:10:47 -04002916 unsigned char di_0, di_1, tempal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002917
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302918 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
2919 pVBInfo);
2920 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
2921 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002922
Peter Huewe6896b942012-02-09 21:11:46 +01002923 if (pVBInfo->VBType & VB_SIS301) { /* shampoo 0129 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302924 /* 301 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002925 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, 0x10);
2926 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
2927 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302928 } else { /* 301b/302b/301lv/302lv */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002929 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
2930 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302931 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002932
Aaro Koskinen8104e322011-03-13 12:26:22 +02002933 xgifb_reg_set(pVBInfo->Part4Port, 0x00, 0x12);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002934
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302935 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02002936 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x28);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302937 else
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02002938 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002939}
2940
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002941static unsigned short XGI_GetColorDepth(unsigned short ModeNo,
2942 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002943{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002944 unsigned short ColorDepth[6] = { 1, 2, 4, 4, 6, 8 };
2945 short index;
2946 unsigned short modeflag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302947
Aaro Koskinenb3979922012-11-04 21:14:52 +02002948 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Peter Huewe6896b942012-02-09 21:11:46 +01002949 index = (modeflag & ModeTypeMask) - ModeEGA;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302950
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002951 if (index < 0)
2952 index = 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302953
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002954 return ColorDepth[index];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302955}
2956
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002957static unsigned short XGI_GetOffset(unsigned short ModeNo,
2958 unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302959 unsigned short RefreshRateTableIndex,
2960 struct xgi_hw_device_info *HwDeviceExtension,
2961 struct vb_device_info *pVBInfo)
2962{
2963 unsigned short temp, colordepth, modeinfo, index, infoflag,
2964 ColorDepth[] = { 0x01, 0x02, 0x04 };
2965
Aaro Koskinenb3979922012-11-04 21:14:52 +02002966 modeinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeInfo;
Aaro Koskinena39325d2012-11-04 21:14:53 +02002967 infoflag = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302968
2969 index = (modeinfo >> 8) & 0xFF;
2970
Aaro Koskinen224114c2012-11-04 21:14:59 +02002971 temp = XGI330_ScreenOffset[index];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302972
2973 if (infoflag & InterlaceMode)
2974 temp = temp << 1;
2975
2976 colordepth = XGI_GetColorDepth(ModeNo, ModeIdIndex, pVBInfo);
2977
2978 if ((ModeNo >= 0x7C) && (ModeNo <= 0x7E)) {
2979 temp = ModeNo - 0x7C;
2980 colordepth = ColorDepth[temp];
2981 temp = 0x6B;
2982 if (infoflag & InterlaceMode)
2983 temp = temp << 1;
2984 return temp * colordepth;
2985 } else {
2986 return temp * colordepth;
2987 }
2988}
2989
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002990static void XGI_SetCRT2Offset(unsigned short ModeNo,
2991 unsigned short ModeIdIndex,
2992 unsigned short RefreshRateTableIndex,
2993 struct xgi_hw_device_info *HwDeviceExtension,
2994 struct vb_device_info *pVBInfo)
2995{
2996 unsigned short offset;
2997 unsigned char temp;
2998
2999 if (pVBInfo->VBInfo & SetInSlaveMode)
3000 return;
3001
3002 offset = XGI_GetOffset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
3003 HwDeviceExtension, pVBInfo);
3004 temp = (unsigned char) (offset & 0xFF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003005 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003006 temp = (unsigned char) ((offset & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003007 xgifb_reg_set(pVBInfo->Part1Port, 0x09, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003008 temp = (unsigned char) (((offset >> 3) & 0xFF) + 1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003009 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003010}
3011
Randy Dunlap89229672010-08-10 08:46:44 -07003012static void XGI_SetCRT2FIFO(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003013{
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003014 /* threshold high ,disable auto threshold */
3015 xgifb_reg_set(pVBInfo->Part1Port, 0x01, 0x3B);
3016 /* threshold low default 04h */
3017 xgifb_reg_and_or(pVBInfo->Part1Port, 0x02, ~(0x3F), 0x04);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003018}
3019
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003020static void XGI_PreSetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303021 struct xgi_hw_device_info *HwDeviceExtension,
3022 unsigned short RefreshRateTableIndex,
3023 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003024{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303025 unsigned short tempcx = 0, CRT1Index = 0, resinfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003026
Aaro Koskinena39325d2012-11-04 21:14:53 +02003027 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003028 CRT1Index &= IndexMask;
Aaro Koskinenb3979922012-11-04 21:14:52 +02003029 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003030
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303031 XGI_SetCRT2Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
3032 HwDeviceExtension, pVBInfo);
3033 XGI_SetCRT2FIFO(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003034
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303035 for (tempcx = 4; tempcx < 7; tempcx++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02003036 xgifb_reg_set(pVBInfo->Part1Port, tempcx, 0x0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003037
Aaro Koskinen8104e322011-03-13 12:26:22 +02003038 xgifb_reg_set(pVBInfo->Part1Port, 0x50, 0x00);
3039 xgifb_reg_set(pVBInfo->Part1Port, 0x02, 0x44); /* temp 0206 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003040}
3041
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003042static void XGI_SetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303043 struct xgi_hw_device_info *HwDeviceExtension,
3044 unsigned short RefreshRateTableIndex,
3045 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003046{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303047 unsigned short temp = 0, tempax = 0, tempbx = 0, tempcx = 0,
3048 pushbx = 0, CRT1Index = 0, modeflag, resinfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003049
Aaro Koskinena39325d2012-11-04 21:14:53 +02003050 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003051 CRT1Index &= IndexMask;
Aaro Koskinenb3979922012-11-04 21:14:52 +02003052 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
3053 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003054
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303055 /* bainy change table name */
3056 if (modeflag & HalfDCLK) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003057 /* BTVGA2HT 0x08,0x09 */
3058 temp = (pVBInfo->VGAHT / 2 - 1) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003059 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303060 temp = (((pVBInfo->VGAHT / 2 - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003061 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003062 /* BTVGA2HDEE 0x0A,0x0C */
3063 temp = (pVBInfo->VGAHDE / 2 + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003064 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303065 tempcx = ((pVBInfo->VGAHT - pVBInfo->VGAHDE) / 2) >> 2;
3066 pushbx = pVBInfo->VGAHDE / 2 + 16;
3067 tempcx = tempcx >> 1;
3068 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
3069 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003070
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303071 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003072 tempbx = XGI_CRT1Table[CRT1Index].CR[4];
3073 tempbx |= ((XGI_CRT1Table[CRT1Index].CR[14] &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003074 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303075 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003076 tempcx = XGI_CRT1Table[CRT1Index].CR[5];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303077 tempcx &= 0x1F;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003078 temp = XGI_CRT1Table[CRT1Index].CR[15];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303079 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
3080 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
3081 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003082
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303083 tempbx += 4;
3084 tempcx += 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003085
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303086 if (tempcx > (pVBInfo->VGAHT / 2))
3087 tempcx = pVBInfo->VGAHT / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003088
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303089 temp = tempbx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003090
Aaro Koskinen8104e322011-03-13 12:26:22 +02003091 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303092 } else {
3093 temp = (pVBInfo->VGAHT - 1) & 0x0FF; /* BTVGA2HT 0x08,0x09 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003094 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303095 temp = (((pVBInfo->VGAHT - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003096 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003097 /* BTVGA2HDEE 0x0A,0x0C */
3098 temp = (pVBInfo->VGAHDE + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003099 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303100 tempcx = (pVBInfo->VGAHT - pVBInfo->VGAHDE) >> 2; /* cx */
3101 pushbx = pVBInfo->VGAHDE + 16;
3102 tempcx = tempcx >> 1;
3103 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
3104 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003105
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303106 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003107 tempbx = XGI_CRT1Table[CRT1Index].CR[3];
3108 tempbx |= ((XGI_CRT1Table[CRT1Index].CR[5] &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003109 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303110 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003111 tempcx = XGI_CRT1Table[CRT1Index].CR[4];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303112 tempcx &= 0x1F;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003113 temp = XGI_CRT1Table[CRT1Index].CR[6];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303114 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
3115 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
3116 tempbx += 16;
3117 tempcx += 16;
3118 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003119
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303120 if (tempcx > pVBInfo->VGAHT)
3121 tempcx = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003122
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303123 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003124 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303125 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003126
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303127 tempax = (tempax & 0x00FF) | (tempbx & 0xFF00);
3128 tempbx = pushbx;
3129 tempbx = (tempbx & 0x00FF) | ((tempbx & 0xFF00) << 4);
3130 tempax |= (tempbx & 0xFF00);
3131 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003132 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303133 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003134 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303135 tempcx = (pVBInfo->VGAVT - 1);
3136 temp = tempcx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003137
Aaro Koskinen8104e322011-03-13 12:26:22 +02003138 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303139 tempbx = pVBInfo->VGAVDE - 1;
3140 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003141 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303142 temp = ((tempbx & 0xFF00) << 3) >> 8;
3143 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003144 xgifb_reg_set(pVBInfo->Part1Port, 0x12, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003145
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303146 tempax = pVBInfo->VGAVDE;
3147 tempbx = pVBInfo->VGAVDE;
3148 tempcx = pVBInfo->VGAVT;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003149 /* BTVGA2VRS 0x10,0x11 */
3150 tempbx = (pVBInfo->VGAVT + pVBInfo->VGAVDE) >> 1;
3151 /* BTVGA2VRE 0x11 */
3152 tempcx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) >> 4) + tempbx + 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003153
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303154 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003155 tempbx = XGI_CRT1Table[CRT1Index].CR[10];
3156 temp = XGI_CRT1Table[CRT1Index].CR[9];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003157
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303158 if (temp & 0x04)
3159 tempbx |= 0x0100;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003160
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303161 if (temp & 0x080)
3162 tempbx |= 0x0200;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003163
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003164 temp = XGI_CRT1Table[CRT1Index].CR[14];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003165
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303166 if (temp & 0x08)
3167 tempbx |= 0x0400;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003168
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003169 temp = XGI_CRT1Table[CRT1Index].CR[11];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303170 tempcx = (tempcx & 0xFF00) | (temp & 0x00FF);
3171 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003172
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303173 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003174 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303175 temp = ((tempbx & 0xFF00) >> 8) << 4;
3176 temp = ((tempcx & 0x000F) | (temp));
Aaro Koskinen8104e322011-03-13 12:26:22 +02003177 xgifb_reg_set(pVBInfo->Part1Port, 0x11, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303178 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003179
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303180 if (modeflag & DoubleScanMode)
3181 tempax |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003182
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303183 if (modeflag & HalfDCLK)
3184 tempax |= 0x40;
3185
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003186 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2C, ~0x0C0, tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003187}
3188
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003189static unsigned short XGI_GetVGAHT2(struct vb_device_info *pVBInfo)
3190{
3191 unsigned long tempax, tempbx;
3192
3193 tempbx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) * pVBInfo->RVBHCMAX)
3194 & 0xFFFF;
3195 tempax = (pVBInfo->VT - pVBInfo->VDE) * pVBInfo->RVBHCFACT;
3196 tempax = (tempax * pVBInfo->HT) / tempbx;
3197
3198 return (unsigned short) tempax;
3199}
3200
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003201static void XGI_SetLockRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303202 struct xgi_hw_device_info *HwDeviceExtension,
3203 unsigned short RefreshRateTableIndex,
3204 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003205{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303206 unsigned short push1, push2, tempax, tempbx = 0, tempcx, temp, resinfo,
3207 modeflag, CRT1Index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003208
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003209 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02003210 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3211 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinena39325d2012-11-04 21:14:53 +02003212 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003213 CRT1Index &= IndexMask;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003214
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303215 if (!(pVBInfo->VBInfo & SetInSlaveMode))
3216 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003217
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303218 temp = 0xFF; /* set MAX HT */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003219 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303220 tempcx = 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003221
Peter Huewe6896b942012-02-09 21:11:46 +01003222 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303223 modeflag |= Charx8Dot;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003224
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303225 tempax = pVBInfo->VGAHDE; /* 0x04 Horizontal Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003226
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303227 if (modeflag & HalfDCLK)
3228 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003229
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303230 tempax = (tempax / tempcx) - 1;
3231 tempbx |= ((tempax & 0x00FF) << 8);
3232 temp = tempax & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003233 xgifb_reg_set(pVBInfo->Part1Port, 0x04, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003234
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303235 temp = (tempbx & 0xFF00) >> 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003236
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303237 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Peter Huewe6896b942012-02-09 21:11:46 +01003238 if (!(pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3239 | VB_SIS302LV | VB_XGI301C)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303240 temp += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003241
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03003242 if ((pVBInfo->VBInfo & SetCRT2ToHiVision) &&
3243 !(pVBInfo->VBType & VB_SIS301LV) && (resinfo == 7))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303244 temp -= 2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303245 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003246
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003247 /* 0x05 Horizontal Display Start */
3248 xgifb_reg_set(pVBInfo->Part1Port, 0x05, temp);
3249 /* 0x06 Horizontal Blank end */
3250 xgifb_reg_set(pVBInfo->Part1Port, 0x06, 0x03);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003251
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303252 if (!(pVBInfo->VBInfo & DisableCRT2Display)) { /* 030226 bainy */
3253 if (pVBInfo->VBInfo & SetCRT2ToTV)
3254 tempax = pVBInfo->VGAHT;
3255 else
3256 tempax = XGI_GetVGAHT2(pVBInfo);
3257 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003258
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303259 if (tempax >= pVBInfo->VGAHT)
3260 tempax = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003261
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303262 if (modeflag & HalfDCLK)
3263 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003264
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303265 tempax = (tempax / tempcx) - 5;
3266 tempcx = tempax; /* 20030401 0x07 horizontal Retrace Start */
Peter Huewe599801f2012-02-09 21:11:45 +01003267 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303268 temp = (tempbx & 0x00FF) - 1;
3269 if (!(modeflag & HalfDCLK)) {
3270 temp -= 6;
3271 if (pVBInfo->TVInfo & TVSimuMode) {
3272 temp -= 4;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003273 temp -= 10;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303274 }
3275 }
3276 } else {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303277 tempbx = (tempbx & 0xFF00) >> 8;
3278 tempcx = (tempcx + tempbx) >> 1;
3279 temp = (tempcx & 0x00FF) + 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003280
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303281 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3282 temp -= 1;
3283 if (!(modeflag & HalfDCLK)) {
3284 if ((modeflag & Charx8Dot)) {
3285 temp += 4;
3286 if (pVBInfo->VGAHDE >= 800)
3287 temp -= 6;
3288 }
3289 }
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003290 } else if (!(modeflag & HalfDCLK)) {
3291 temp -= 4;
Peter Huewe255aabd2012-02-09 21:11:44 +01003292 if (pVBInfo->LCDResInfo != Panel_1280x960 &&
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003293 pVBInfo->VGAHDE >= 800) {
3294 temp -= 7;
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003295 if (pVBInfo->VGAHDE >= 1280 &&
Peter Huewe255aabd2012-02-09 21:11:44 +01003296 pVBInfo->LCDResInfo != Panel_1280x960 &&
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003297 (pVBInfo->LCDInfo & LCDNonExpanding))
3298 temp += 28;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303299 }
3300 }
3301 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003302
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003303 /* 0x07 Horizontal Retrace Start */
3304 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
3305 /* 0x08 Horizontal Retrace End */
3306 xgifb_reg_set(pVBInfo->Part1Port, 0x08, 0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003307
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303308 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3309 if (pVBInfo->TVInfo & TVSimuMode) {
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003310 if (ModeNo == 0x50) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303311 if (pVBInfo->TVInfo & SetNTSCTV) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003312 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303313 0x07, 0x30);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003314 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303315 0x08, 0x03);
3316 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003317 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303318 0x07, 0x2f);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003319 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303320 0x08, 0x02);
3321 }
3322 }
3323 }
3324 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003325
Aaro Koskinen8104e322011-03-13 12:26:22 +02003326 xgifb_reg_set(pVBInfo->Part1Port, 0x18, 0x03); /* 0x18 SR0B */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003327 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0xF0, 0x00);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003328 xgifb_reg_set(pVBInfo->Part1Port, 0x09, 0xFF); /* 0x09 Set Max VT */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003329
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303330 tempbx = pVBInfo->VGAVT;
3331 push1 = tempbx;
3332 tempcx = 0x121;
3333 tempbx = pVBInfo->VGAVDE; /* 0x0E Virtical Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003334
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303335 if (tempbx == 357)
3336 tempbx = 350;
3337 if (tempbx == 360)
3338 tempbx = 350;
3339 if (tempbx == 375)
3340 tempbx = 350;
3341 if (tempbx == 405)
3342 tempbx = 400;
3343 if (tempbx == 525)
3344 tempbx = 480;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003345
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303346 push2 = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003347
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303348 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
Peter Huewe255aabd2012-02-09 21:11:44 +01003349 if (pVBInfo->LCDResInfo == Panel_1024x768) {
Peter Huewea3d675c2012-02-09 21:11:47 +01003350 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303351 if (tempbx == 350)
3352 tempbx += 5;
3353 if (tempbx == 480)
3354 tempbx += 5;
3355 }
3356 }
3357 }
3358 tempbx--;
3359 temp = tempbx & 0x00FF;
3360 tempbx--;
3361 temp = tempbx & 0x00FF;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003362 /* 0x10 vertical Blank Start */
3363 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303364 tempbx = push2;
3365 tempbx--;
3366 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003367 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003368
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303369 if (tempbx & 0x0100)
3370 tempcx |= 0x0002;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003371
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303372 tempax = 0x000B;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003373
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303374 if (modeflag & DoubleScanMode)
3375 tempax |= 0x08000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003376
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303377 if (tempbx & 0x0200)
3378 tempcx |= 0x0040;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003379
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303380 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003381 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003382
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303383 if (tempbx & 0x0400)
3384 tempcx |= 0x0600;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003385
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003386 /* 0x11 Vertival Blank End */
3387 xgifb_reg_set(pVBInfo->Part1Port, 0x11, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303388
3389 tempax = push1;
3390 tempax -= tempbx; /* 0x0C Vertical Retrace Start */
3391 tempax = tempax >> 2;
3392 push1 = tempax; /* push ax */
3393
3394 if (resinfo != 0x09) {
3395 tempax = tempax << 1;
3396 tempbx += tempax;
3397 }
3398
Peter Huewe599801f2012-02-09 21:11:45 +01003399 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Miguel Gómez470c5332012-07-06 12:40:50 +02003400 if ((pVBInfo->VBType & VB_SIS301LV) &&
3401 !(pVBInfo->TVInfo & TVSetHiVision)) {
3402 if ((pVBInfo->TVInfo & TVSimuMode) &&
3403 (pVBInfo->TVInfo & TVSetPAL)) {
3404 if (!(pVBInfo->VBType & VB_SIS301LV) ||
3405 !(pVBInfo->TVInfo &
3406 (TVSetYPbPr525p |
3407 TVSetYPbPr750p |
3408 TVSetHiVision)))
3409 tempbx += 40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303410 }
3411 } else {
3412 tempbx -= 10;
3413 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003414 } else if (pVBInfo->TVInfo & TVSimuMode) {
3415 if (pVBInfo->TVInfo & TVSetPAL) {
3416 if (pVBInfo->VBType & VB_SIS301LV) {
3417 if (!(pVBInfo->TVInfo &
3418 (TVSetYPbPr525p |
3419 TVSetYPbPr750p |
3420 TVSetHiVision)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303421 tempbx += 40;
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003422 } else {
3423 tempbx += 40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303424 }
3425 }
3426 }
3427 tempax = push1;
3428 tempax = tempax >> 2;
3429 tempax++;
3430 tempax += tempbx;
3431 push1 = tempax; /* push ax */
3432
Peter Huewe599801f2012-02-09 21:11:45 +01003433 if ((pVBInfo->TVInfo & TVSetPAL)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303434 if (tempbx <= 513) {
3435 if (tempax >= 513)
3436 tempbx = 513;
3437 }
3438 }
3439
3440 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003441 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303442 tempbx--;
3443 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003444 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303445
3446 if (tempbx & 0x0100)
3447 tempcx |= 0x0008;
3448
3449 if (tempbx & 0x0200)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003450 xgifb_reg_and_or(pVBInfo->Part1Port, 0x0B, 0x0FF, 0x20);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303451
3452 tempbx++;
3453
3454 if (tempbx & 0x0100)
3455 tempcx |= 0x0004;
3456
3457 if (tempbx & 0x0200)
3458 tempcx |= 0x0080;
3459
3460 if (tempbx & 0x0400)
3461 tempcx |= 0x0C00;
3462
3463 tempbx = push1; /* pop ax */
3464 temp = tempbx & 0x00FF;
3465 temp &= 0x0F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003466 /* 0x0D vertical Retrace End */
3467 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303468
3469 if (tempbx & 0x0010)
3470 tempcx |= 0x2000;
3471
3472 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003473 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp); /* 0x0A CR07 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303474 temp = (tempcx & 0x0FF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003475 xgifb_reg_set(pVBInfo->Part1Port, 0x17, temp); /* 0x17 SR0A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303476 tempax = modeflag;
3477 temp = (tempax & 0xFF00) >> 8;
3478
3479 temp = (temp >> 1) & 0x09;
3480
Peter Huewe6896b942012-02-09 21:11:46 +01003481 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303482 temp |= 0x01;
3483
Aaro Koskinen8104e322011-03-13 12:26:22 +02003484 xgifb_reg_set(pVBInfo->Part1Port, 0x16, temp); /* 0x16 SR01 */
3485 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, 0); /* 0x0F CR14 */
3486 xgifb_reg_set(pVBInfo->Part1Port, 0x12, 0); /* 0x12 CR17 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303487
3488 if (pVBInfo->LCDInfo & LCDRGB18Bit)
3489 temp = 0x80;
3490 else
3491 temp = 0x00;
3492
Aaro Koskinen8104e322011-03-13 12:26:22 +02003493 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, temp); /* 0x1A SR0E */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303494
3495 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003496}
3497
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003498static void XGI_SetGroup2(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303499 unsigned short RefreshRateTableIndex,
3500 struct xgi_hw_device_info *HwDeviceExtension,
3501 struct vb_device_info *pVBInfo)
3502{
3503 unsigned short i, j, tempax, tempbx, tempcx, temp, push1, push2,
3504 modeflag, resinfo, crt2crtc;
Aaro Koskinend21222d2012-09-11 00:15:29 +03003505 unsigned char const *TimingPoint;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303506
3507 unsigned long longtemp, tempeax, tempebx, temp2, tempecx;
3508
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003509 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02003510 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3511 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinena39325d2012-11-04 21:14:53 +02003512 crt2crtc = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303513
3514 tempax = 0;
3515
3516 if (!(pVBInfo->VBInfo & SetCRT2ToAVIDEO))
3517 tempax |= 0x0800;
3518
3519 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3520 tempax |= 0x0400;
3521
3522 if (pVBInfo->VBInfo & SetCRT2ToSCART)
3523 tempax |= 0x0200;
3524
Peter Huewe599801f2012-02-09 21:11:45 +01003525 if (!(pVBInfo->TVInfo & TVSetPAL))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303526 tempax |= 0x1000;
3527
Peter Huewe599801f2012-02-09 21:11:45 +01003528 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303529 tempax |= 0x0100;
3530
Peter Huewe599801f2012-02-09 21:11:45 +01003531 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303532 tempax &= 0xfe00;
3533
3534 tempax = (tempax & 0xff00) >> 8;
3535
Aaro Koskinen8104e322011-03-13 12:26:22 +02003536 xgifb_reg_set(pVBInfo->Part2Port, 0x0, tempax);
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003537 TimingPoint = XGI330_NTSCTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303538
Peter Huewe599801f2012-02-09 21:11:45 +01003539 if (pVBInfo->TVInfo & TVSetPAL)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003540 TimingPoint = XGI330_PALTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303541
Peter Huewe599801f2012-02-09 21:11:45 +01003542 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003543 TimingPoint = XGI330_HiTVExtTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303544
3545 if (pVBInfo->VBInfo & SetInSlaveMode)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003546 TimingPoint = XGI330_HiTVSt2Timing;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303547
3548 if (pVBInfo->SetFlag & TVSimuMode)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003549 TimingPoint = XGI330_HiTVSt1Timing;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303550
3551 if (!(modeflag & Charx8Dot))
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003552 TimingPoint = XGI330_HiTVTextTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303553 }
3554
Peter Huewe599801f2012-02-09 21:11:45 +01003555 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
3556 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003557 TimingPoint = XGI330_YPbPr525iTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303558
Peter Huewe599801f2012-02-09 21:11:45 +01003559 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003560 TimingPoint = XGI330_YPbPr525pTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303561
Peter Huewe599801f2012-02-09 21:11:45 +01003562 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003563 TimingPoint = XGI330_YPbPr750pTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303564 }
3565
3566 for (i = 0x01, j = 0; i <= 0x2D; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02003567 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303568
3569 for (i = 0x39; i <= 0x45; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003570 /* di->temp2[j] */
3571 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303572
3573 if (pVBInfo->VBInfo & SetCRT2ToTV)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003574 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303575
3576 temp = pVBInfo->NewFlickerMode;
3577 temp &= 0x80;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003578 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xFF, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303579
Peter Huewe599801f2012-02-09 21:11:45 +01003580 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303581 tempax = 950;
3582
Peter Huewe599801f2012-02-09 21:11:45 +01003583 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303584 tempax = 520;
3585 else
3586 tempax = 440;
3587
3588 if (pVBInfo->VDE <= tempax) {
3589 tempax -= pVBInfo->VDE;
3590 tempax = tempax >> 2;
3591 tempax = (tempax & 0x00FF) | ((tempax & 0x00FF) << 8);
3592 push1 = tempax;
3593 temp = (tempax & 0xFF00) >> 8;
3594 temp += (unsigned short) TimingPoint[0];
3595
Peter Huewe6896b942012-02-09 21:11:46 +01003596 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3597 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303598 if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO
3599 | SetCRT2ToSVIDEO | SetCRT2ToSCART
Peter Huewe599801f2012-02-09 21:11:45 +01003600 | SetCRT2ToYPbPr525750)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303601 tempcx = pVBInfo->VGAHDE;
3602 if (tempcx >= 1024) {
3603 temp = 0x17; /* NTSC */
Peter Huewe599801f2012-02-09 21:11:45 +01003604 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303605 temp = 0x19; /* PAL */
3606 }
3607 }
3608 }
3609
Aaro Koskinen8104e322011-03-13 12:26:22 +02003610 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303611 tempax = push1;
3612 temp = (tempax & 0xFF00) >> 8;
3613 temp += TimingPoint[1];
3614
Peter Huewe6896b942012-02-09 21:11:46 +01003615 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3616 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303617 if ((pVBInfo->VBInfo & (SetCRT2ToAVIDEO
3618 | SetCRT2ToSVIDEO | SetCRT2ToSCART
Peter Huewe599801f2012-02-09 21:11:45 +01003619 | SetCRT2ToYPbPr525750))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303620 tempcx = pVBInfo->VGAHDE;
3621 if (tempcx >= 1024) {
3622 temp = 0x1D; /* NTSC */
Peter Huewe599801f2012-02-09 21:11:45 +01003623 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303624 temp = 0x52; /* PAL */
3625 }
3626 }
3627 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02003628 xgifb_reg_set(pVBInfo->Part2Port, 0x02, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303629 }
3630
3631 /* 301b */
3632 tempcx = pVBInfo->HT;
3633
3634 if (XGI_IsLCDDualLink(pVBInfo))
3635 tempcx = tempcx >> 1;
3636
3637 tempcx -= 2;
3638 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003639 xgifb_reg_set(pVBInfo->Part2Port, 0x1B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303640
3641 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003642 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303643
3644 tempcx = pVBInfo->HT >> 1;
3645 push1 = tempcx; /* push cx */
3646 tempcx += 7;
3647
Peter Huewe599801f2012-02-09 21:11:45 +01003648 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303649 tempcx -= 4;
3650
3651 temp = tempcx & 0x00FF;
3652 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003653 xgifb_reg_and_or(pVBInfo->Part2Port, 0x22, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303654
3655 tempbx = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
3656 tempbx += tempcx;
3657 push2 = tempbx;
3658 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003659 xgifb_reg_set(pVBInfo->Part2Port, 0x24, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303660 temp = (tempbx & 0xFF00) >> 8;
3661 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003662 xgifb_reg_and_or(pVBInfo->Part2Port, 0x25, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303663
3664 tempbx = push2;
3665 tempbx = tempbx + 8;
Peter Huewe599801f2012-02-09 21:11:45 +01003666 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303667 tempbx = tempbx - 4;
3668 tempcx = tempbx;
3669 }
3670
3671 temp = (tempbx & 0x00FF) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003672 xgifb_reg_and_or(pVBInfo->Part2Port, 0x29, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303673
3674 j += 2;
3675 tempcx += (TimingPoint[j] | ((TimingPoint[j + 1]) << 8));
3676 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003677 xgifb_reg_set(pVBInfo->Part2Port, 0x27, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303678 temp = ((tempcx & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003679 xgifb_reg_and_or(pVBInfo->Part2Port, 0x28, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303680
3681 tempcx += 8;
Peter Huewe599801f2012-02-09 21:11:45 +01003682 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303683 tempcx -= 4;
3684
3685 temp = tempcx & 0xFF;
3686 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003687 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2A, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303688
3689 tempcx = push1; /* pop cx */
3690 j += 2;
3691 temp = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
3692 tempcx -= temp;
3693 temp = tempcx & 0x00FF;
3694 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003695 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2D, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303696
3697 tempcx -= 11;
3698
3699 if (!(pVBInfo->VBInfo & SetCRT2ToTV)) {
3700 tempax = XGI_GetVGAHT2(pVBInfo);
3701 tempcx = tempax - 1;
3702 }
3703 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003704 xgifb_reg_set(pVBInfo->Part2Port, 0x2E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303705
3706 tempbx = pVBInfo->VDE;
3707
3708 if (pVBInfo->VGAVDE == 360)
3709 tempbx = 746;
3710 if (pVBInfo->VGAVDE == 375)
3711 tempbx = 746;
3712 if (pVBInfo->VGAVDE == 405)
3713 tempbx = 853;
3714
3715 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003716 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01003717 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003718 if (!(pVBInfo->TVInfo &
Peter Huewe599801f2012-02-09 21:11:45 +01003719 (TVSetYPbPr525p | TVSetYPbPr750p)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303720 tempbx = tempbx >> 1;
3721 } else
3722 tempbx = tempbx >> 1;
3723 }
3724
3725 tempbx -= 2;
3726 temp = tempbx & 0x00FF;
3727
Peter Huewe599801f2012-02-09 21:11:45 +01003728 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Huewe6896b942012-02-09 21:11:46 +01003729 if (pVBInfo->VBType & VB_SIS301LV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003730 if (pVBInfo->TVInfo & TVSetHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303731 if (pVBInfo->VBInfo & SetInSlaveMode) {
3732 if (ModeNo == 0x2f)
3733 temp += 1;
3734 }
3735 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003736 } else if (pVBInfo->VBInfo & SetInSlaveMode) {
3737 if (ModeNo == 0x2f)
3738 temp += 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303739 }
3740 }
3741
Aaro Koskinen8104e322011-03-13 12:26:22 +02003742 xgifb_reg_set(pVBInfo->Part2Port, 0x2F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303743
3744 temp = (tempcx & 0xFF00) >> 8;
3745 temp |= ((tempbx & 0xFF00) >> 8) << 6;
3746
Peter Huewe599801f2012-02-09 21:11:45 +01003747 if (!(pVBInfo->VBInfo & SetCRT2ToHiVision)) {
Peter Huewe6896b942012-02-09 21:11:46 +01003748 if (pVBInfo->VBType & VB_SIS301LV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003749 if (pVBInfo->TVInfo & TVSetHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303750 temp |= 0x10;
3751
3752 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3753 temp |= 0x20;
3754 }
3755 } else {
3756 temp |= 0x10;
3757 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3758 temp |= 0x20;
3759 }
3760 }
3761
Aaro Koskinen8104e322011-03-13 12:26:22 +02003762 xgifb_reg_set(pVBInfo->Part2Port, 0x30, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303763
Peter Huewe6896b942012-02-09 21:11:46 +01003764 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3765 | VB_SIS302LV | VB_XGI301C)) { /* TV gatingno */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303766 tempbx = pVBInfo->VDE;
3767 tempcx = tempbx - 2;
3768
3769 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003770 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p
3771 | TVSetYPbPr750p)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303772 tempbx = tempbx >> 1;
3773 }
3774
Peter Huewe6896b942012-02-09 21:11:46 +01003775 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303776 temp = 0;
3777 if (tempcx & 0x0400)
3778 temp |= 0x20;
3779
3780 if (tempbx & 0x0400)
3781 temp |= 0x40;
3782
Aaro Koskinen8104e322011-03-13 12:26:22 +02003783 xgifb_reg_set(pVBInfo->Part4Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303784 }
3785
3786 temp = (((tempbx - 3) & 0x0300) >> 8) << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003787 xgifb_reg_set(pVBInfo->Part2Port, 0x46, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303788 temp = (tempbx - 3) & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003789 xgifb_reg_set(pVBInfo->Part2Port, 0x47, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303790 }
3791
3792 tempbx = tempbx & 0x00FF;
3793
3794 if (!(modeflag & HalfDCLK)) {
3795 tempcx = pVBInfo->VGAHDE;
3796 if (tempcx >= pVBInfo->HDE) {
3797 tempbx |= 0x2000;
3798 tempax &= 0x00FF;
3799 }
3800 }
3801
3802 tempcx = 0x0101;
3803
3804 if (pVBInfo->VBInfo & SetCRT2ToTV) { /*301b*/
3805 if (pVBInfo->VGAHDE >= 1024) {
3806 tempcx = 0x1920;
3807 if (pVBInfo->VGAHDE >= 1280) {
3808 tempcx = 0x1420;
3809 tempbx = tempbx & 0xDFFF;
3810 }
3811 }
3812 }
3813
3814 if (!(tempbx & 0x2000)) {
3815 if (modeflag & HalfDCLK)
3816 tempcx = (tempcx & 0xFF00) | ((tempcx & 0x00FF) << 1);
3817
3818 push1 = tempbx;
3819 tempeax = pVBInfo->VGAHDE;
3820 tempebx = (tempcx & 0xFF00) >> 8;
3821 longtemp = tempeax * tempebx;
3822 tempecx = tempcx & 0x00FF;
3823 longtemp = longtemp / tempecx;
3824
3825 /* 301b */
3826 tempecx = 8 * 1024;
3827
Peter Huewe6896b942012-02-09 21:11:46 +01003828 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3829 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303830 tempecx = tempecx * 8;
3831 }
3832
3833 longtemp = longtemp * tempecx;
3834 tempecx = pVBInfo->HDE;
3835 temp2 = longtemp % tempecx;
3836 tempeax = longtemp / tempecx;
3837 if (temp2 != 0)
3838 tempeax += 1;
3839
3840 tempax = (unsigned short) tempeax;
3841
3842 /* 301b */
Peter Huewe6896b942012-02-09 21:11:46 +01003843 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3844 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303845 tempcx = ((tempax & 0xFF00) >> 5) >> 8;
3846 }
3847 /* end 301b */
3848
3849 tempbx = push1;
3850 tempbx = (unsigned short) (((tempeax & 0x0000FF00) & 0x1F00)
3851 | (tempbx & 0x00FF));
3852 tempax = (unsigned short) (((tempeax & 0x000000FF) << 8)
3853 | (tempax & 0x00FF));
3854 temp = (tempax & 0xFF00) >> 8;
3855 } else {
3856 temp = (tempax & 0x00FF) >> 8;
3857 }
3858
Aaro Koskinen8104e322011-03-13 12:26:22 +02003859 xgifb_reg_set(pVBInfo->Part2Port, 0x44, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303860 temp = (tempbx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003861 xgifb_reg_and_or(pVBInfo->Part2Port, 0x45, ~0x03F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303862 temp = tempcx & 0x00FF;
3863
3864 if (tempbx & 0x2000)
3865 temp = 0;
3866
3867 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
3868 temp |= 0x18;
3869
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003870 xgifb_reg_and_or(pVBInfo->Part2Port, 0x46, ~0x1F, temp);
Peter Huewe599801f2012-02-09 21:11:45 +01003871 if (pVBInfo->TVInfo & TVSetPAL) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303872 tempbx = 0x0382;
3873 tempcx = 0x007e;
3874 } else {
3875 tempbx = 0x0369;
3876 tempcx = 0x0061;
3877 }
3878
3879 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003880 xgifb_reg_set(pVBInfo->Part2Port, 0x4b, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303881 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003882 xgifb_reg_set(pVBInfo->Part2Port, 0x4c, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303883
3884 temp = ((tempcx & 0xFF00) >> 8) & 0x03;
3885 temp = temp << 2;
3886 temp |= ((tempbx & 0xFF00) >> 8) & 0x03;
3887
Peter Huewe599801f2012-02-09 21:11:45 +01003888 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303889 temp |= 0x10;
3890
Peter Huewe599801f2012-02-09 21:11:45 +01003891 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303892 temp |= 0x20;
3893
Peter Huewe599801f2012-02-09 21:11:45 +01003894 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303895 temp |= 0x60;
3896 }
3897
Aaro Koskinen8104e322011-03-13 12:26:22 +02003898 xgifb_reg_set(pVBInfo->Part2Port, 0x4d, temp);
Aaro Koskinen58839b02011-03-13 12:26:23 +02003899 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x43); /* 301b change */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003900 xgifb_reg_set(pVBInfo->Part2Port, 0x43, (unsigned short) (temp - 3));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303901
Peter Huewe599801f2012-02-09 21:11:45 +01003902 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303903 if (pVBInfo->TVInfo & NTSC1024x768) {
3904 TimingPoint = XGI_NTSC1024AdjTime;
3905 for (i = 0x1c, j = 0; i <= 0x30; i++, j++) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003906 xgifb_reg_set(pVBInfo->Part2Port, i,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303907 TimingPoint[j]);
3908 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02003909 xgifb_reg_set(pVBInfo->Part2Port, 0x43, 0x72);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303910 }
3911 }
3912
Miguel Gómez949eb0a2012-07-06 12:40:36 +02003913 /* Modify for 301C PALM Support */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303914 if (pVBInfo->VBType & VB_XGI301C) {
Peter Huewe599801f2012-02-09 21:11:45 +01003915 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003916 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x08,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303917 0x08); /* PALM Mode */
3918 }
3919
Peter Huewe599801f2012-02-09 21:11:45 +01003920 if (pVBInfo->TVInfo & TVSetPALM) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003921 tempax = (unsigned char) xgifb_reg_get(pVBInfo->Part2Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303922 0x01);
3923 tempax--;
Aaro Koskinendc505562011-03-13 12:26:26 +02003924 xgifb_reg_and(pVBInfo->Part2Port, 0x01, tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303925
Aaro Koskinendc505562011-03-13 12:26:26 +02003926 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xEF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303927 }
3928
Peter Huewe599801f2012-02-09 21:11:45 +01003929 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303930 if (!(pVBInfo->VBInfo & SetInSlaveMode))
Aaro Koskinen8104e322011-03-13 12:26:22 +02003931 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303932 }
3933
3934 if (pVBInfo->VBInfo & SetCRT2ToTV)
3935 return;
3936}
3937
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003938static void XGI_SetLCDRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303939 struct xgi_hw_device_info *HwDeviceExtension,
3940 unsigned short RefreshRateTableIndex,
3941 struct vb_device_info *pVBInfo)
3942{
3943 unsigned short push1, push2, pushbx, tempax, tempbx, tempcx, temp,
3944 tempah, tempbh, tempch, resinfo, modeflag, CRT1Index;
3945
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02003946 struct XGI_LCDDesStruct const *LCDBDesPtr = NULL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303947
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003948 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02003949 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3950 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinena39325d2012-11-04 21:14:53 +02003951 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003952 CRT1Index &= IndexMask;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303953
3954 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
3955 return;
3956
3957 tempbx = pVBInfo->HDE; /* RHACTE=HDE-1 */
3958
3959 if (XGI_IsLCDDualLink(pVBInfo))
3960 tempbx = tempbx >> 1;
3961
3962 tempbx -= 1;
3963 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003964 xgifb_reg_set(pVBInfo->Part2Port, 0x2C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303965 temp = (tempbx & 0xFF00) >> 8;
3966 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003967 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2B, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303968 temp = 0x01;
3969
Aaro Koskinen8104e322011-03-13 12:26:22 +02003970 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303971 tempbx = pVBInfo->VDE; /* RTVACTEO=(VDE-1)&0xFF */
3972 push1 = tempbx;
3973 tempbx--;
3974 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003975 xgifb_reg_set(pVBInfo->Part2Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303976 temp = ((tempbx & 0xFF00) >> 8) & 0x07;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003977 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0C, ~0x07, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303978
3979 tempcx = pVBInfo->VT - 1;
3980 push2 = tempcx + 1;
3981 temp = tempcx & 0x00FF; /* RVTVT=VT-1 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003982 xgifb_reg_set(pVBInfo->Part2Port, 0x19, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303983 temp = (tempcx & 0xFF00) >> 8;
3984 temp = temp << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003985 xgifb_reg_set(pVBInfo->Part2Port, 0x1A, temp);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003986 xgifb_reg_and_or(pVBInfo->Part2Port, 0x09, 0xF0, 0x00);
3987 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xF0, 0x00);
3988 xgifb_reg_and_or(pVBInfo->Part2Port, 0x17, 0xFB, 0x00);
3989 xgifb_reg_and_or(pVBInfo->Part2Port, 0x18, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303990
Justin P. Mattock558f7582012-10-02 21:17:11 -07003991 /* Customized LCDB Does not add */
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02003992 if ((pVBInfo->VBType & VB_SIS301LV) || (pVBInfo->VBType & VB_SIS302LV))
3993 LCDBDesPtr = XGI_GetLcdPtr(xgifb_lcddldes, ModeNo, ModeIdIndex,
3994 RefreshRateTableIndex, pVBInfo);
3995 else
3996 LCDBDesPtr = XGI_GetLcdPtr(XGI_LCDDesDataTable, ModeNo,
3997 ModeIdIndex, RefreshRateTableIndex,
3998 pVBInfo);
3999
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304000 tempah = pVBInfo->LCDResInfo;
4001 tempah &= PanelResInfo;
4002
Peter Huewe255aabd2012-02-09 21:11:44 +01004003 if ((tempah == Panel_1024x768) || (tempah == Panel_1024x768x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304004 tempbx = 1024;
4005 tempcx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01004006 } else if ((tempah == Panel_1280x1024) ||
4007 (tempah == Panel_1280x1024x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304008 tempbx = 1280;
4009 tempcx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01004010 } else if (tempah == Panel_1400x1050) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304011 tempbx = 1400;
4012 tempcx = 1050;
4013 } else {
4014 tempbx = 1600;
4015 tempcx = 1200;
4016 }
4017
4018 if (pVBInfo->LCDInfo & EnableScalingLCD) {
4019 tempbx = pVBInfo->HDE;
4020 tempcx = pVBInfo->VDE;
4021 }
4022
4023 pushbx = tempbx;
4024 tempax = pVBInfo->VT;
4025 pVBInfo->LCDHDES = LCDBDesPtr->LCDHDES;
4026 pVBInfo->LCDHRS = LCDBDesPtr->LCDHRS;
4027 pVBInfo->LCDVDES = LCDBDesPtr->LCDVDES;
4028 pVBInfo->LCDVRS = LCDBDesPtr->LCDVRS;
4029 tempbx = pVBInfo->LCDVDES;
4030 tempcx += tempbx;
4031
4032 if (tempcx >= tempax)
4033 tempcx -= tempax; /* lcdvdes */
4034
4035 temp = tempbx & 0x00FF; /* RVEQ1EQ=lcdvdes */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004036 xgifb_reg_set(pVBInfo->Part2Port, 0x05, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304037 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004038 xgifb_reg_set(pVBInfo->Part2Port, 0x06, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304039 tempch = ((tempcx & 0xFF00) >> 8) & 0x07;
4040 tempbh = ((tempbx & 0xFF00) >> 8) & 0x07;
4041 tempah = tempch;
4042 tempah = tempah << 3;
4043 tempah |= tempbh;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004044 xgifb_reg_set(pVBInfo->Part2Port, 0x02, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304045
4046 /* getlcdsync() */
4047 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
4048 tempcx = tempbx;
4049 tempax = pVBInfo->VT;
4050 tempbx = pVBInfo->LCDVRS;
4051
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304052 tempcx += tempbx;
4053 if (tempcx >= tempax)
4054 tempcx -= tempax;
4055
4056 temp = tempbx & 0x00FF; /* RTVACTEE=lcdvrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004057 xgifb_reg_set(pVBInfo->Part2Port, 0x04, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304058 temp = (tempbx & 0xFF00) >> 8;
4059 temp = temp << 4;
4060 temp |= (tempcx & 0x000F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004061 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304062 tempcx = pushbx;
4063 tempax = pVBInfo->HT;
4064 tempbx = pVBInfo->LCDHDES;
4065 tempbx &= 0x0FFF;
4066
4067 if (XGI_IsLCDDualLink(pVBInfo)) {
4068 tempax = tempax >> 1;
4069 tempbx = tempbx >> 1;
4070 tempcx = tempcx >> 1;
4071 }
4072
Peter Huewe6896b942012-02-09 21:11:46 +01004073 if (pVBInfo->VBType & VB_SIS302LV)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304074 tempbx += 1;
4075
4076 if (pVBInfo->VBType & VB_XGI301C) /* tap4 */
4077 tempbx += 1;
4078
4079 tempcx += tempbx;
4080
4081 if (tempcx >= tempax)
4082 tempcx -= tempax;
4083
4084 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004085 xgifb_reg_set(pVBInfo->Part2Port, 0x1F, temp); /* RHBLKE=lcdhdes */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304086 temp = ((tempbx & 0xFF00) >> 8) << 4;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004087 xgifb_reg_set(pVBInfo->Part2Port, 0x20, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304088 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004089 xgifb_reg_set(pVBInfo->Part2Port, 0x23, temp); /* RHEQPLE=lcdhdee */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304090 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004091 xgifb_reg_set(pVBInfo->Part2Port, 0x25, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304092
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304093 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
4094 tempcx = tempax;
4095 tempax = pVBInfo->HT;
4096 tempbx = pVBInfo->LCDHRS;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304097 if (XGI_IsLCDDualLink(pVBInfo)) {
4098 tempax = tempax >> 1;
4099 tempbx = tempbx >> 1;
4100 tempcx = tempcx >> 1;
4101 }
4102
Peter Huewe6896b942012-02-09 21:11:46 +01004103 if (pVBInfo->VBType & VB_SIS302LV)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304104 tempbx += 1;
4105
4106 tempcx += tempbx;
4107
4108 if (tempcx >= tempax)
4109 tempcx -= tempax;
4110
4111 temp = tempbx & 0x00FF; /* RHBURSTS=lcdhrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004112 xgifb_reg_set(pVBInfo->Part2Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304113
4114 temp = (tempbx & 0xFF00) >> 8;
4115 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004116 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304117 temp = tempcx & 0x00FF; /* RHSYEXP2S=lcdhre */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004118 xgifb_reg_set(pVBInfo->Part2Port, 0x21, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304119
Peter Huewea3d675c2012-02-09 21:11:47 +01004120 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304121 if (pVBInfo->VGAVDE == 525) {
Peter Huewe6896b942012-02-09 21:11:46 +01004122 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
4123 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304124 | VB_XGI301C)) {
4125 temp = 0xC6;
4126 } else
4127 temp = 0xC4;
4128
Aaro Koskinen8104e322011-03-13 12:26:22 +02004129 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
4130 xgifb_reg_set(pVBInfo->Part2Port, 0x30, 0xB3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304131 }
4132
4133 if (pVBInfo->VGAVDE == 420) {
Peter Huewe6896b942012-02-09 21:11:46 +01004134 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
4135 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304136 | VB_XGI301C)) {
4137 temp = 0x4F;
4138 } else
4139 temp = 0x4E;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004140 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304141 }
4142 }
4143}
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004144
4145/* --------------------------------------------------------------------- */
4146/* Function : XGI_GetTap4Ptr */
4147/* Input : */
4148/* Output : di -> Tap4 Reg. Setting Pointer */
4149/* Description : */
4150/* --------------------------------------------------------------------- */
Aaro Koskinen1cccd9e2012-11-04 21:15:06 +02004151static struct XGI301C_Tap4TimingStruct const
4152*XGI_GetTap4Ptr(unsigned short tempcx, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004153{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304154 unsigned short tempax, tempbx, i;
Aaro Koskinen1cccd9e2012-11-04 21:15:06 +02004155 struct XGI301C_Tap4TimingStruct const *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004156
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304157 if (tempcx == 0) {
4158 tempax = pVBInfo->VGAHDE;
4159 tempbx = pVBInfo->HDE;
4160 } else {
4161 tempax = pVBInfo->VGAVDE;
4162 tempbx = pVBInfo->VDE;
4163 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004164
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004165 if (tempax <= tempbx)
4166 return &xgifb_tap4_timing[0];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304167 else
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004168 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing; /* NTSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004169
Peter Huewe599801f2012-02-09 21:11:45 +01004170 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304171 Tap4TimingPtr = PALTap4Timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004172
Peter Huewe599801f2012-02-09 21:11:45 +01004173 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
4174 if ((pVBInfo->TVInfo & TVSetYPbPr525i) ||
4175 (pVBInfo->TVInfo & TVSetYPbPr525p))
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004176 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing;
Peter Huewe599801f2012-02-09 21:11:45 +01004177 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304178 Tap4TimingPtr = YPbPr750pTap4Timing;
4179 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004180
Peter Huewe599801f2012-02-09 21:11:45 +01004181 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004182 Tap4TimingPtr = xgifb_tap4_timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004183
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304184 i = 0;
4185 while (Tap4TimingPtr[i].DE != 0xFFFF) {
4186 if (Tap4TimingPtr[i].DE == tempax)
4187 break;
4188 i++;
4189 }
4190 return &Tap4TimingPtr[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004191}
4192
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004193static void XGI_SetTap4Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004194{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304195 unsigned short i, j;
Aaro Koskinen1cccd9e2012-11-04 21:15:06 +02004196 struct XGI301C_Tap4TimingStruct const *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004197
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304198 if (!(pVBInfo->VBType & VB_XGI301C))
4199 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004200
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304201 Tap4TimingPtr = XGI_GetTap4Ptr(0, pVBInfo); /* Set Horizontal Scaling */
4202 for (i = 0x80, j = 0; i <= 0xBF; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004203 xgifb_reg_set(pVBInfo->Part2Port, i, Tap4TimingPtr->Reg[j]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004204
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004205 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
Peter Huewe599801f2012-02-09 21:11:45 +01004206 (!(pVBInfo->VBInfo & SetCRT2ToHiVision))) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004207 /* Set Vertical Scaling */
4208 Tap4TimingPtr = XGI_GetTap4Ptr(1, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304209 for (i = 0xC0, j = 0; i < 0xFF; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004210 xgifb_reg_set(pVBInfo->Part2Port,
4211 i,
4212 Tap4TimingPtr->Reg[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304213 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004214
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004215 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
Peter Huewe599801f2012-02-09 21:11:45 +01004216 (!(pVBInfo->VBInfo & SetCRT2ToHiVision)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004217 /* Enable V.Scaling */
4218 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304219 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004220 /* Enable H.Scaling */
4221 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x10);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004222}
4223
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004224static void XGI_SetGroup3(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304225 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004226{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304227 unsigned short i;
Aaro Koskinend21222d2012-09-11 00:15:29 +03004228 unsigned char const *tempdi;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304229 unsigned short modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004230
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004231 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004232 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004233
Aaro Koskinen8104e322011-03-13 12:26:22 +02004234 xgifb_reg_set(pVBInfo->Part3Port, 0x00, 0x00);
Peter Huewe599801f2012-02-09 21:11:45 +01004235 if (pVBInfo->TVInfo & TVSetPAL) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004236 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
4237 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304238 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004239 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xF5);
4240 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xB7);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304241 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004242
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304243 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
4244 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004245
Peter Huewe599801f2012-02-09 21:11:45 +01004246 if (pVBInfo->TVInfo & TVSetPALM) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004247 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
4248 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
4249 xgifb_reg_set(pVBInfo->Part3Port, 0x3D, 0xA8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304250 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004251
Peter Huewe599801f2012-02-09 21:11:45 +01004252 if ((pVBInfo->VBInfo & SetCRT2ToHiVision) || (pVBInfo->VBInfo
4253 & SetCRT2ToYPbPr525750)) {
4254 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304255 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004256
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004257 tempdi = XGI330_HiTVGroup3Data;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304258 if (pVBInfo->SetFlag & TVSimuMode) {
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004259 tempdi = XGI330_HiTVGroup3Simu;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304260 if (!(modeflag & Charx8Dot))
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004261 tempdi = XGI330_HiTVGroup3Text;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304262 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004263
Peter Huewe599801f2012-02-09 21:11:45 +01004264 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004265 tempdi = XGI330_Ren525pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004266
Peter Huewe599801f2012-02-09 21:11:45 +01004267 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004268 tempdi = XGI330_Ren750pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004269
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304270 for (i = 0; i <= 0x3E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004271 xgifb_reg_set(pVBInfo->Part3Port, i, tempdi[i]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004272
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304273 if (pVBInfo->VBType & VB_XGI301C) { /* Marcovision */
Peter Huewe599801f2012-02-09 21:11:45 +01004274 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004275 xgifb_reg_set(pVBInfo->Part3Port, 0x28, 0x3f);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304276 }
4277 }
4278 return;
4279} /* {end of XGI_SetGroup3} */
4280
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004281static void XGI_SetGroup4(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304282 unsigned short RefreshRateTableIndex,
4283 struct xgi_hw_device_info *HwDeviceExtension,
4284 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004285{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304286 unsigned short tempax, tempcx, tempbx, modeflag, temp, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004287
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304288 unsigned long tempebx, tempeax, templong;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004289
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004290 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004291 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304292 temp = pVBInfo->RVBHCFACT;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004293 xgifb_reg_set(pVBInfo->Part4Port, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004294
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304295 tempbx = pVBInfo->RVBHCMAX;
4296 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004297 xgifb_reg_set(pVBInfo->Part4Port, 0x14, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304298 temp2 = ((tempbx & 0xFF00) >> 8) << 7;
4299 tempcx = pVBInfo->VGAHT - 1;
4300 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004301 xgifb_reg_set(pVBInfo->Part4Port, 0x16, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004302
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304303 temp = ((tempcx & 0xFF00) >> 8) << 3;
4304 temp2 |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004305
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304306 tempcx = pVBInfo->VGAVT - 1;
4307 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
4308 tempcx -= 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004309
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304310 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004311 xgifb_reg_set(pVBInfo->Part4Port, 0x17, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304312 temp = temp2 | ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004313 xgifb_reg_set(pVBInfo->Part4Port, 0x15, temp);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004314 xgifb_reg_or(pVBInfo->Part4Port, 0x0D, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304315 tempcx = pVBInfo->VBInfo;
4316 tempbx = pVBInfo->VGAHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004317
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304318 if (modeflag & HalfDCLK)
4319 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004320
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304321 if (XGI_IsLCDDualLink(pVBInfo))
4322 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004323
Peter Huewe599801f2012-02-09 21:11:45 +01004324 if (tempcx & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304325 temp = 0;
4326 if (tempbx <= 1024)
4327 temp = 0xA0;
4328 if (tempbx == 1280)
4329 temp = 0xC0;
4330 } else if (tempcx & SetCRT2ToTV) {
4331 temp = 0xA0;
4332 if (tempbx <= 800)
4333 temp = 0x80;
4334 } else {
4335 temp = 0x80;
4336 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4337 temp = 0;
4338 if (tempbx > 800)
4339 temp = 0x60;
4340 }
4341 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004342
Peter Huewe599801f2012-02-09 21:11:45 +01004343 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304344 temp = 0x00;
4345 if (pVBInfo->VGAHDE == 1280)
4346 temp = 0x40;
4347 if (pVBInfo->VGAHDE == 1024)
4348 temp = 0x20;
4349 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004350 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0E, ~0xEF, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004351
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304352 tempebx = pVBInfo->VDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004353
Peter Huewe599801f2012-02-09 21:11:45 +01004354 if (tempcx & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304355 if (!(temp & 0xE000))
4356 tempbx = tempbx >> 1;
4357 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004358
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304359 tempcx = pVBInfo->RVBHRS;
4360 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004361 xgifb_reg_set(pVBInfo->Part4Port, 0x18, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004362
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304363 tempeax = pVBInfo->VGAVDE;
4364 tempcx |= 0x04000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004365
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304366 if (tempeax <= tempebx) {
4367 tempcx = (tempcx & (~0x4000));
4368 tempeax = pVBInfo->VGAVDE;
4369 } else {
4370 tempeax -= tempebx;
4371 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004372
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304373 templong = (tempeax * 256 * 1024) % tempebx;
4374 tempeax = (tempeax * 256 * 1024) / tempebx;
4375 tempebx = tempeax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004376
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304377 if (templong != 0)
4378 tempebx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004379
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304380 temp = (unsigned short) (tempebx & 0x000000FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004381 xgifb_reg_set(pVBInfo->Part4Port, 0x1B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004382
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304383 temp = (unsigned short) ((tempebx & 0x0000FF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004384 xgifb_reg_set(pVBInfo->Part4Port, 0x1A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304385 tempbx = (unsigned short) (tempebx >> 16);
4386 temp = tempbx & 0x00FF;
4387 temp = temp << 4;
4388 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004389 xgifb_reg_set(pVBInfo->Part4Port, 0x19, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004390
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304391 /* 301b */
Peter Huewe6896b942012-02-09 21:11:46 +01004392 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4393 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304394 temp = 0x0028;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004395 xgifb_reg_set(pVBInfo->Part4Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304396 tempax = pVBInfo->VGAHDE;
4397 if (modeflag & HalfDCLK)
4398 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004399
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304400 if (XGI_IsLCDDualLink(pVBInfo))
4401 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004402
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304403 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4404 if (tempax > 800)
4405 tempax -= 800;
Aaro Koskinend3ae5762012-09-11 00:15:27 +03004406 } else if (pVBInfo->VGAHDE > 800) {
4407 if (pVBInfo->VGAHDE == 1024)
4408 tempax = (tempax * 25 / 32) - 1;
4409 else
4410 tempax = (tempax * 20 / 32) - 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304411 }
4412 tempax -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004413
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304414 temp = (tempax & 0xFF00) >> 8;
4415 temp = ((temp & 0x0003) << 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004416 xgifb_reg_set(pVBInfo->Part4Port, 0x1E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304417 temp = (tempax & 0x00FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004418 xgifb_reg_set(pVBInfo->Part4Port, 0x1D, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004419
Peter Huewe599801f2012-02-09 21:11:45 +01004420 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToHiVision)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304421 if (pVBInfo->VGAHDE > 800)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004422 xgifb_reg_or(pVBInfo->Part4Port, 0x1E, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004423
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304424 }
4425 temp = 0x0036;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004426
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304427 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4428 if (!(pVBInfo->TVInfo & (NTSC1024x768
Peter Huewe599801f2012-02-09 21:11:45 +01004429 | TVSetYPbPr525p | TVSetYPbPr750p
4430 | TVSetHiVision))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304431 temp |= 0x0001;
4432 if ((pVBInfo->VBInfo & SetInSlaveMode)
4433 && (!(pVBInfo->TVInfo
4434 & TVSimuMode)))
4435 temp &= (~0x0001);
4436 }
4437 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004438
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004439 xgifb_reg_and_or(pVBInfo->Part4Port, 0x1F, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304440 tempbx = pVBInfo->HT;
4441 if (XGI_IsLCDDualLink(pVBInfo))
4442 tempbx = tempbx >> 1;
4443 tempbx = (tempbx >> 1) - 2;
4444 temp = ((tempbx & 0x0700) >> 8) << 3;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004445 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304446 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004447 xgifb_reg_set(pVBInfo->Part4Port, 0x22, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304448 }
4449 /* end 301b */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004450
Aaro Koskinen8951dad2012-09-11 00:15:30 +03004451 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004452}
4453
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004454static void XGINew_EnableCRT2(struct vb_device_info *pVBInfo)
4455{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004456 xgifb_reg_and_or(pVBInfo->P3c4, 0x1E, 0xFF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004457}
4458
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004459static void XGI_SetGroup5(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304460 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004461{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304462 unsigned short Pindex, Pdata;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004463
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304464 Pindex = pVBInfo->Part5Port;
4465 Pdata = pVBInfo->Part5Port + 1;
4466 if (pVBInfo->ModeType == ModeVGA) {
4467 if (!(pVBInfo->VBInfo & (SetInSlaveMode | LoadDACFlag
Peter Huewe6896b942012-02-09 21:11:46 +01004468 | DisableCRT2Display))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304469 XGINew_EnableCRT2(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304470 }
4471 }
4472 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004473}
4474
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004475static void XGI_EnableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304476 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004477{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004478 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x40);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004479}
4480
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004481static void XGI_DisableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304482 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004483{
4484
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004485 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004486}
4487
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004488static unsigned char XGI_XG21CheckLVDSMode(struct xgifb_video_info *xgifb_info,
4489 unsigned short ModeNo, unsigned short ModeIdIndex,
4490 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004491{
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004492 unsigned short xres, yres, colordepth, modeflag, resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004493
Aaro Koskinenb3979922012-11-04 21:14:52 +02004494 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02004495 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
4496 yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004497 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004498 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004499
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304500 if (!(modeflag & Charx8Dot)) {
4501 xres /= 9;
4502 xres *= 8;
4503 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004504
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004505 if ((ModeNo > 0x13) && (modeflag & HalfDCLK))
4506 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004507
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004508 if ((ModeNo > 0x13) && (modeflag & DoubleScanMode))
4509 yres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004510
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004511 if (xres > xgifb_info->lvds_data.LVDSHDE)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304512 return 0;
Bill Pembertondda08c52010-06-17 13:10:42 -04004513
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004514 if (yres > xgifb_info->lvds_data.LVDSVDE)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304515 return 0;
4516
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004517 if (xres != xgifb_info->lvds_data.LVDSHDE ||
4518 yres != xgifb_info->lvds_data.LVDSVDE) {
4519 colordepth = XGI_GetColorDepth(ModeNo, ModeIdIndex, pVBInfo);
4520 if (colordepth > 2)
4521 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304522 }
4523 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004524}
4525
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004526static void xgifb_set_lvds(struct xgifb_video_info *xgifb_info,
4527 int chip_id,
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004528 unsigned short ModeNo,
4529 unsigned short ModeIdIndex,
4530 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004531{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304532 unsigned char temp, Miscdata;
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004533 unsigned short xres, yres, modeflag, resindex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304534 unsigned short LVDSHT, LVDSHBS, LVDSHRS, LVDSHRE, LVDSHBE;
4535 unsigned short LVDSVT, LVDSVBS, LVDSVRS, LVDSVRE, LVDSVBE;
4536 unsigned short value;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004537
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004538 temp = (unsigned char) ((xgifb_info->lvds_data.LVDS_Capability &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004539 (LCDPolarity << 8)) >> 8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304540 temp &= LCDPolarity;
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004541 Miscdata = (unsigned char) inb(pVBInfo->P3cc);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004542
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004543 outb((Miscdata & 0x3F) | temp, pVBInfo->P3c2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004544
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004545 temp = xgifb_info->lvds_data.LVDS_Capability & LCDPolarity;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004546 /* SR35[7] FP VSync polarity */
4547 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x80, temp & 0x80);
4548 /* SR30[5] FP HSync polarity */
4549 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, ~0x20, (temp & 0x40) >> 1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004550
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004551 if (chip_id == XG27)
4552 XGI_SetXG27FPBits(pVBInfo);
4553 else
4554 XGI_SetXG21FPBits(pVBInfo);
4555
Aaro Koskinenb3979922012-11-04 21:14:52 +02004556 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02004557 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
4558 yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004559 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004560 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004561
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304562 if (!(modeflag & Charx8Dot))
4563 xres = xres * 8 / 9;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004564
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004565 LVDSHT = xgifb_info->lvds_data.LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004566
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004567 LVDSHBS = xres + (xgifb_info->lvds_data.LVDSHDE - xres) / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004568
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304569 if (LVDSHBS > LVDSHT)
4570 LVDSHBS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004571
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004572 LVDSHRS = LVDSHBS + xgifb_info->lvds_data.LVDSHFP;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304573 if (LVDSHRS > LVDSHT)
4574 LVDSHRS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004575
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004576 LVDSHRE = LVDSHRS + xgifb_info->lvds_data.LVDSHSYNC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304577 if (LVDSHRE > LVDSHT)
4578 LVDSHRE -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004579
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004580 LVDSHBE = LVDSHBS + LVDSHT - xgifb_info->lvds_data.LVDSHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004581
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004582 LVDSVT = xgifb_info->lvds_data.LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004583
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004584 LVDSVBS = yres + (xgifb_info->lvds_data.LVDSVDE - yres) / 2;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004585 if (modeflag & DoubleScanMode)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304586 LVDSVBS += yres / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004587
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304588 if (LVDSVBS > LVDSVT)
4589 LVDSVBS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004590
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004591 LVDSVRS = LVDSVBS + xgifb_info->lvds_data.LVDSVFP;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304592 if (LVDSVRS > LVDSVT)
4593 LVDSVRS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004594
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004595 LVDSVRE = LVDSVRS + xgifb_info->lvds_data.LVDSVSYNC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304596 if (LVDSVRE > LVDSVT)
4597 LVDSVRE -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004598
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004599 LVDSVBE = LVDSVBS + LVDSVT - xgifb_info->lvds_data.LVDSVDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004600
Aaro Koskinen58839b02011-03-13 12:26:23 +02004601 temp = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004602 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp & 0x7f); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004603
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304604 if (!(modeflag & Charx8Dot))
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004605 xgifb_reg_or(pVBInfo->P3c4, 0x1, 0x1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004606
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304607 /* HT SR0B[1:0] CR00 */
4608 value = (LVDSHT >> 3) - 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004609 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004610 xgifb_reg_set(pVBInfo->P3d4, 0x0, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004611
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304612 /* HBS SR0B[5:4] CR02 */
4613 value = (LVDSHBS >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004614 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x30, (value & 0x300) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004615 xgifb_reg_set(pVBInfo->P3d4, 0x2, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004616
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304617 /* HBE SR0C[1:0] CR05[7] CR03[4:0] */
4618 value = (LVDSHBE >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004619 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x03, (value & 0xC0) >> 6);
4620 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x80, (value & 0x20) << 2);
4621 xgifb_reg_and_or(pVBInfo->P3d4, 0x03, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004622
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304623 /* HRS SR0B[7:6] CR04 */
4624 value = (LVDSHRS >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004625 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0xC0, (value & 0x300) >> 2);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004626 xgifb_reg_set(pVBInfo->P3d4, 0x4, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004627
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304628 /* Panel HRS SR2F[1:0] SR2E[7:0] */
4629 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004630 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004631 xgifb_reg_set(pVBInfo->P3c4, 0x2E, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004632
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304633 /* HRE SR0C[2] CR05[4:0] */
4634 value = (LVDSHRE >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004635 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x04, (value & 0x20) >> 3);
4636 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004637
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304638 /* Panel HRE SR2F[7:2] */
4639 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004640 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0xFC, value << 2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004641
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304642 /* VT SR0A[0] CR07[5][0] CR06 */
4643 value = LVDSVT - 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004644 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x01, (value & 0x400) >> 10);
4645 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x20, (value & 0x200) >> 4);
4646 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x01, (value & 0x100) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004647 xgifb_reg_set(pVBInfo->P3d4, 0x06, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004648
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304649 /* VBS SR0A[2] CR09[5] CR07[3] CR15 */
4650 value = LVDSVBS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004651 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x04, (value & 0x400) >> 8);
4652 xgifb_reg_and_or(pVBInfo->P3d4, 0x09, ~0x20, (value & 0x200) >> 4);
4653 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x08, (value & 0x100) >> 5);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004654 xgifb_reg_set(pVBInfo->P3d4, 0x15, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004655
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304656 /* VBE SR0A[4] CR16 */
4657 value = LVDSVBE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004658 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x10, (value & 0x100) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004659 xgifb_reg_set(pVBInfo->P3d4, 0x16, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004660
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304661 /* VRS SR0A[3] CR7[7][2] CR10 */
4662 value = LVDSVRS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004663 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x08, (value & 0x400) >> 7);
4664 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x80, (value & 0x200) >> 2);
4665 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x04, (value & 0x100) >> 6);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004666 xgifb_reg_set(pVBInfo->P3d4, 0x10, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004667
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004668 if (chip_id == XG27) {
4669 /* Panel VRS SR35[2:0] SR34[7:0] */
4670 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07,
4671 (value & 0x700) >> 8);
4672 xgifb_reg_set(pVBInfo->P3c4, 0x34, value & 0xFF);
4673 } else {
4674 /* Panel VRS SR3F[1:0] SR34[7:0] SR33[0] */
4675 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0x03,
4676 (value & 0x600) >> 9);
4677 xgifb_reg_set(pVBInfo->P3c4, 0x34, (value >> 1) & 0xFF);
4678 xgifb_reg_and_or(pVBInfo->P3d4, 0x33, ~0x01, value & 0x01);
4679 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004680
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304681 /* VRE SR0A[5] CR11[3:0] */
4682 value = LVDSVRE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004683 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x20, (value & 0x10) << 1);
4684 xgifb_reg_and_or(pVBInfo->P3d4, 0x11, ~0x0F, value & 0x0F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004685
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304686 /* Panel VRE SR3F[7:2] */
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004687 if (chip_id == XG27)
4688 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
4689 (value << 2) & 0xFC);
4690 else
4691 /* SR3F[7] has to be 0, h/w bug */
4692 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
4693 (value << 2) & 0x7C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004694
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304695 for (temp = 0, value = 0; temp < 3; temp++) {
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004696
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004697 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, value);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004698 xgifb_reg_set(pVBInfo->P3c4,
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004699 0x2B, xgifb_info->lvds_data.VCLKData1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004700 xgifb_reg_set(pVBInfo->P3c4,
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004701 0x2C, xgifb_info->lvds_data.VCLKData2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304702 value += 0x10;
4703 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004704
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304705 if (!(modeflag & Charx8Dot)) {
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004706 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004707 outb(0x13, pVBInfo->P3c0); /* set index */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004708 /* set data, panning = 0, shift left 1 dot*/
4709 outb(0x00, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004710
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004711 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004712 outb(0x20, pVBInfo->P3c0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304713
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004714 inb(pVBInfo->P3da); /* reset 3da */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304715 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004716
4717}
4718
4719/* --------------------------------------------------------------------- */
4720/* Function : XGI_IsLCDON */
4721/* Input : */
Bill Pembertondda08c52010-06-17 13:10:42 -04004722/* Output : 0 : Skip PSC Control */
4723/* 1: Disable PSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004724/* Description : */
4725/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004726static unsigned char XGI_IsLCDON(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004727{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304728 unsigned short tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004729
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304730 tempax = pVBInfo->VBInfo;
4731 if (tempax & SetCRT2ToDualEdge)
4732 return 0;
Peter Huewe6896b942012-02-09 21:11:46 +01004733 else if (tempax & (DisableCRT2Display | SwitchCRT2 | SetSimuScanMode))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304734 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004735
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304736 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004737}
4738
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004739/* --------------------------------------------------------------------- */
4740/* Function : XGI_DisableChISLCD */
4741/* Input : */
Bill Pembertondda08c52010-06-17 13:10:42 -04004742/* Output : 0 -> Not LCD Mode */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004743/* Description : */
4744/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004745static unsigned char XGI_DisableChISLCD(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004746{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304747 unsigned short tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004748
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304749 tempbx = pVBInfo->SetFlag & (DisableChA | DisableChB);
Aaro Koskinen58839b02011-03-13 12:26:23 +02004750 tempah = ~((unsigned short) xgifb_reg_get(pVBInfo->Part1Port, 0x2E));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004751
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304752 if (tempbx & (EnableChA | DisableChA)) {
4753 if (!(tempah & 0x08)) /* Chk LCDA Mode */
4754 return 0;
4755 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004756
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304757 if (!(tempbx & (EnableChB | DisableChB)))
4758 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004759
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304760 if (tempah & 0x01) /* Chk LCDB Mode */
4761 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004762
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304763 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004764}
4765
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004766/* --------------------------------------------------------------------- */
4767/* Function : XGI_EnableChISLCD */
4768/* Input : */
4769/* Output : 0 -> Not LCD mode */
4770/* Description : */
4771/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004772static unsigned char XGI_EnableChISLCD(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004773{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304774 unsigned short tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004775
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304776 tempbx = pVBInfo->SetFlag & (EnableChA | EnableChB);
Aaro Koskinen58839b02011-03-13 12:26:23 +02004777 tempah = ~((unsigned short) xgifb_reg_get(pVBInfo->Part1Port, 0x2E));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004778
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304779 if (tempbx & (EnableChA | DisableChA)) {
4780 if (!(tempah & 0x08)) /* Chk LCDA Mode */
4781 return 0;
4782 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004783
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304784 if (!(tempbx & (EnableChB | DisableChB)))
Bill Pembertondda08c52010-06-17 13:10:42 -04004785 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004786
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304787 if (tempah & 0x01) /* Chk LCDB Mode */
4788 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004789
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304790 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004791}
4792
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004793static void XGI_DisableBridge(struct xgifb_video_info *xgifb_info,
4794 struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304795 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004796{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02004797 unsigned short tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004798
Peter Huewe6896b942012-02-09 21:11:46 +01004799 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4800 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304801 tempah = 0x3F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004802 if (!(pVBInfo->VBInfo &
4803 (DisableCRT2Display | SetSimuScanMode))) {
Peter Huewea3d675c2012-02-09 21:11:47 +01004804 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304805 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
4806 tempah = 0x7F; /* Disable Channel A */
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004807 if (!(pVBInfo->VBInfo &
4808 XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004809 /* Disable Channel B */
4810 tempah = 0xBF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004811
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304812 if (pVBInfo->SetFlag & DisableChB)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004813 /* force to disable Cahnnel */
4814 tempah &= 0xBF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004815
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304816 if (pVBInfo->SetFlag & DisableChA)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004817 /* Force to disable Channel B */
4818 tempah &= 0x7F;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304819 }
4820 }
4821 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004822
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004823 /* disable part4_1f */
4824 xgifb_reg_and(pVBInfo->Part4Port, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004825
Peter Huewe6896b942012-02-09 21:11:46 +01004826 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004827 if (((pVBInfo->VBInfo &
4828 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
4829 || (XGI_DisableChISLCD(pVBInfo))
4830 || (XGI_IsLCDON(pVBInfo)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004831 /* LVDS Driver power down */
4832 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304833 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004834
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304835 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
Peter Huewea3d675c2012-02-09 21:11:47 +01004836 & (DisableCRT2Display | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304837 | SetSimuScanMode))) {
4838 if (pVBInfo->SetFlag & GatingCRT)
4839 XGI_EnableGatingCRT(HwDeviceExtension, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004840 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304841 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004842
Peter Huewea3d675c2012-02-09 21:11:47 +01004843 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304844 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
Peter Huewea3d675c2012-02-09 21:11:47 +01004845 & XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004846 /* Power down */
4847 xgifb_reg_and(pVBInfo->Part1Port, 0x1e, 0xdf);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304848 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004849
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004850 /* disable TV as primary VGA swap */
4851 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004852
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304853 if ((pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToDualEdge)))
Aaro Koskinendc505562011-03-13 12:26:26 +02004854 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004855
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004856 if ((pVBInfo->SetFlag & DisableChB) ||
4857 (pVBInfo->VBInfo &
4858 (DisableCRT2Display | SetSimuScanMode)) ||
Peter Huewea3d675c2012-02-09 21:11:47 +01004859 ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) &&
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004860 (pVBInfo->VBInfo &
4861 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004862 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004863
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004864 if ((pVBInfo->SetFlag & DisableChB) ||
4865 (pVBInfo->VBInfo &
4866 (DisableCRT2Display | SetSimuScanMode)) ||
Peter Huewea3d675c2012-02-09 21:11:47 +01004867 (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) ||
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004868 (pVBInfo->VBInfo &
4869 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))) {
4870 /* save Part1 index 0 */
4871 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
4872 /* BTDAC = 1, avoid VB reset */
4873 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x10);
4874 /* disable CRT2 */
4875 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
4876 /* restore Part1 index 0 */
4877 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304878 }
4879 } else { /* {301} */
4880 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004881 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
4882 /* Disable CRT2 */
4883 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
4884 /* Disable TV asPrimary VGA swap */
4885 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xDF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304886 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004887
Peter Huewea3d675c2012-02-09 21:11:47 +01004888 if (pVBInfo->VBInfo & (DisableCRT2Display | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304889 | SetSimuScanMode))
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004890 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304891 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004892}
4893
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004894/* --------------------------------------------------------------------- */
4895/* Function : XGI_GetTVPtrIndex */
4896/* Input : */
4897/* Output : */
4898/* Description : bx 0 : ExtNTSC */
4899/* 1 : StNTSC */
4900/* 2 : ExtPAL */
4901/* 3 : StPAL */
4902/* 4 : ExtHiTV */
4903/* 5 : StHiTV */
4904/* 6 : Ext525i */
4905/* 7 : St525i */
4906/* 8 : Ext525p */
4907/* 9 : St525p */
4908/* A : Ext750p */
4909/* B : St750p */
4910/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004911static unsigned short XGI_GetTVPtrIndex(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004912{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304913 unsigned short tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004914
Peter Huewe599801f2012-02-09 21:11:45 +01004915 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304916 tempbx = 2;
Peter Huewe599801f2012-02-09 21:11:45 +01004917 if (pVBInfo->TVInfo & TVSetHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304918 tempbx = 4;
Peter Huewe599801f2012-02-09 21:11:45 +01004919 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304920 tempbx = 6;
Peter Huewe599801f2012-02-09 21:11:45 +01004921 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304922 tempbx = 8;
Peter Huewe599801f2012-02-09 21:11:45 +01004923 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304924 tempbx = 10;
4925 if (pVBInfo->TVInfo & TVSimuMode)
4926 tempbx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004927
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304928 return tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004929}
4930
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004931/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004932/* Function : XGI_GetTVPtrIndex2 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004933/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004934/* Output : bx 0 : NTSC */
4935/* 1 : PAL */
4936/* 2 : PALM */
4937/* 3 : PALN */
4938/* 4 : NTSC1024x768 */
4939/* 5 : PAL-M 1024x768 */
4940/* 6-7: reserved */
4941/* cl 0 : YFilter1 */
4942/* 1 : YFilter2 */
4943/* ch 0 : 301A */
4944/* 1 : 301B/302B/301LV/302LV */
4945/* Description : */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004946/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004947static void XGI_GetTVPtrIndex2(unsigned short *tempbx, unsigned char *tempcl,
4948 unsigned char *tempch, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004949{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004950 *tempbx = 0;
4951 *tempcl = 0;
4952 *tempch = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004953
Peter Huewe599801f2012-02-09 21:11:45 +01004954 if (pVBInfo->TVInfo & TVSetPAL)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004955 *tempbx = 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004956
Peter Huewe599801f2012-02-09 21:11:45 +01004957 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004958 *tempbx = 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004959
Peter Huewe599801f2012-02-09 21:11:45 +01004960 if (pVBInfo->TVInfo & TVSetPALN)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004961 *tempbx = 3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004962
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004963 if (pVBInfo->TVInfo & NTSC1024x768) {
4964 *tempbx = 4;
Peter Huewe599801f2012-02-09 21:11:45 +01004965 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004966 *tempbx = 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304967 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004968
Peter Huewe6896b942012-02-09 21:11:46 +01004969 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4970 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004971 if ((!(pVBInfo->VBInfo & SetInSlaveMode)) || (pVBInfo->TVInfo
4972 & TVSimuMode)) {
4973 *tempbx += 8;
4974 *tempcl += 1;
4975 }
4976 }
4977
Peter Huewe6896b942012-02-09 21:11:46 +01004978 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4979 | VB_SIS302LV | VB_XGI301C))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004980 (*tempch)++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004981}
4982
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004983static void XGI_SetDelayComp(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004984{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304985 unsigned char tempah, tempbl, tempbh;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004986
Peter Huewe6896b942012-02-09 21:11:46 +01004987 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4988 | VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01004989 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304990 | SetCRT2ToTV | SetCRT2ToRAMDAC)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304991 tempbh = 0;
Peter Huewe03f76fc2012-06-14 00:21:50 +02004992 tempbl = XGI301TVDelay;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004993
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304994 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
4995 tempbl = tempbl >> 4;
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004996 if (pVBInfo->VBInfo &
4997 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Peter Huewe03f76fc2012-06-14 00:21:50 +02004998 tempbh = XGI301LCDDelay;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004999
Peter Huewea3d675c2012-02-09 21:11:47 +01005000 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305001 tempbl = tempbh;
5002 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005003
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305004 tempbl &= 0x0F;
5005 tempbh &= 0xF0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02005006 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2D);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005007
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305008 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD
5009 | SetCRT2ToTV)) { /* Channel B */
5010 tempah &= 0xF0;
5011 tempah |= tempbl;
5012 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005013
Miguel Gómez3bcc2462012-07-06 12:40:53 +02005014 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
5015 /* Channel A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305016 tempah &= 0x0F;
5017 tempah |= tempbh;
5018 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02005019 xgifb_reg_set(pVBInfo->Part1Port, 0x2D, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305020 }
5021 } else if (pVBInfo->IF_DEF_LVDS == 1) {
5022 tempbl = 0;
5023 tempbh = 0;
5024 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
Peter Huewe03f76fc2012-06-14 00:21:50 +02005025 tempah = XGI301LCDDelay;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305026 tempah &= 0x0f;
5027 tempah = tempah << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005028 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2D, 0x0f,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305029 tempah);
5030 }
5031 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005032}
5033
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005034static void XGI_SetLCDCap_A(unsigned short tempcx,
5035 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005036{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305037 unsigned short temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005038
Aaro Koskinen58839b02011-03-13 12:26:23 +02005039 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005040
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305041 if (temp & LCDRGB18Bit) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005042 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005043 /* Enable Dither */
5044 (unsigned short) (0x20 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005045 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305046 } else {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005047 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305048 (unsigned short) (0x30 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005049 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305050 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005051}
5052
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005053/* --------------------------------------------------------------------- */
5054/* Function : XGI_SetLCDCap_B */
5055/* Input : cx -> LCD Capability */
5056/* Output : */
5057/* Description : */
5058/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005059static void XGI_SetLCDCap_B(unsigned short tempcx,
5060 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005061{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305062 if (tempcx & EnableLCD24bpp) /* 24bits */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005063 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305064 (unsigned short) (((tempcx & 0x00ff) >> 6)
5065 | 0x0c));
5066 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005067 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305068 (unsigned short) (((tempcx & 0x00ff) >> 6)
5069 | 0x18)); /* Enable Dither */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005070}
5071
Aaro Koskinen7f04ec32011-11-27 23:03:05 +02005072static void XGI_LongWait(struct vb_device_info *pVBInfo)
5073{
5074 unsigned short i;
5075
5076 i = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
5077
5078 if (!(i & 0xC0)) {
5079 for (i = 0; i < 0xFFFF; i++) {
5080 if (!(inb(pVBInfo->P3da) & 0x08))
5081 break;
5082 }
5083
5084 for (i = 0; i < 0xFFFF; i++) {
5085 if ((inb(pVBInfo->P3da) & 0x08))
5086 break;
5087 }
5088 }
5089}
5090
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005091static void SetSpectrum(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005092{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305093 unsigned short index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005094
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305095 index = XGI_GetLCDCapPtr(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005096
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005097 /* disable down spectrum D[4] */
5098 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x8F);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305099 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005100 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x20); /* reset spectrum */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305101 XGI_LongWait(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005102
Aaro Koskinen8104e322011-03-13 12:26:22 +02005103 xgifb_reg_set(pVBInfo->Part4Port, 0x31,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305104 pVBInfo->LCDCapList[index].Spectrum_31);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005105 xgifb_reg_set(pVBInfo->Part4Port, 0x32,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305106 pVBInfo->LCDCapList[index].Spectrum_32);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005107 xgifb_reg_set(pVBInfo->Part4Port, 0x33,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305108 pVBInfo->LCDCapList[index].Spectrum_33);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005109 xgifb_reg_set(pVBInfo->Part4Port, 0x34,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305110 pVBInfo->LCDCapList[index].Spectrum_34);
5111 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005112 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x40); /* enable spectrum */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005113}
5114
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005115static void XGI_SetLCDCap(struct vb_device_info *pVBInfo)
5116{
5117 unsigned short tempcx;
5118
5119 tempcx = pVBInfo->LCDCapList[XGI_GetLCDCapPtr(pVBInfo)].LCD_Capability;
5120
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005121 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01005122 (VB_SIS301B |
5123 VB_SIS302B |
5124 VB_SIS301LV |
5125 VB_SIS302LV |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005126 VB_XGI301C)) { /* 301LV/302LV only */
5127 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01005128 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005129 /* Set 301LV Capability */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005130 xgifb_reg_set(pVBInfo->Part4Port, 0x24,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005131 (unsigned char) (tempcx & 0x1F));
5132 }
5133 /* VB Driving */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005134 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005135 ~((EnableVBCLKDRVLOW | EnablePLLSPLOW) >> 8),
5136 (unsigned short) ((tempcx & (EnableVBCLKDRVLOW
5137 | EnablePLLSPLOW)) >> 8));
5138 }
5139
Peter Huewe6896b942012-02-09 21:11:46 +01005140 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5141 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005142 if (pVBInfo->VBInfo & SetCRT2ToLCD)
5143 XGI_SetLCDCap_B(tempcx, pVBInfo);
Peter Huewea3d675c2012-02-09 21:11:47 +01005144 else if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005145 XGI_SetLCDCap_A(tempcx, pVBInfo);
5146
Peter Huewe6896b942012-02-09 21:11:46 +01005147 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005148 if (tempcx & EnableSpectrum)
5149 SetSpectrum(pVBInfo);
5150 }
5151 } else {
5152 /* LVDS,CH7017 */
5153 XGI_SetLCDCap_A(tempcx, pVBInfo);
5154 }
5155}
5156
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005157/* --------------------------------------------------------------------- */
5158/* Function : XGI_SetAntiFlicker */
5159/* Input : */
5160/* Output : */
5161/* Description : Set TV Customized Param. */
5162/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005163static void XGI_SetAntiFlicker(unsigned short ModeNo,
5164 unsigned short ModeIdIndex,
5165 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005166{
Aaro Koskinen36ae0352012-04-07 01:14:08 +03005167 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005168
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305169 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005170
Peter Huewe599801f2012-02-09 21:11:45 +01005171 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305172 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005173
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305174 tempbx = XGI_GetTVPtrIndex(pVBInfo);
5175 tempbx &= 0xFE;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305176 tempah = TVAntiFlickList[tempbx];
5177 tempah = tempah << 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005178
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005179 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0x8F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005180}
5181
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005182static void XGI_SetEdgeEnhance(unsigned short ModeNo,
5183 unsigned short ModeIdIndex,
5184 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005185{
Aaro Koskinen354f49f2012-04-07 01:14:09 +03005186 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005187
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305188 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005189
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305190 tempbx = XGI_GetTVPtrIndex(pVBInfo);
5191 tempbx &= 0xFE;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305192 tempah = TVEdgeList[tempbx];
5193 tempah = tempah << 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005194
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005195 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005196}
5197
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005198static void XGI_SetPhaseIncr(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005199{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305200 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005201
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305202 unsigned char tempcl, tempch;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005203
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305204 unsigned long tempData;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005205
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305206 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
5207 tempData = TVPhaseList[tempbx];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005208
Aaro Koskinen8104e322011-03-13 12:26:22 +02005209 xgifb_reg_set(pVBInfo->Part2Port, 0x31, (unsigned short) (tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305210 & 0x000000FF));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005211 xgifb_reg_set(pVBInfo->Part2Port, 0x32, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305212 & 0x0000FF00) >> 8));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005213 xgifb_reg_set(pVBInfo->Part2Port, 0x33, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305214 & 0x00FF0000) >> 16));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005215 xgifb_reg_set(pVBInfo->Part2Port, 0x34, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305216 & 0xFF000000) >> 24));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005217}
5218
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005219static void XGI_SetYFilter(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305220 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005221{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305222 unsigned short tempbx, index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005223
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305224 unsigned char tempcl, tempch, tempal, *filterPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005225
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305226 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005227
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305228 switch (tempbx) {
5229 case 0x00:
5230 case 0x04:
5231 filterPtr = NTSCYFilter1;
5232 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005233
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305234 case 0x01:
5235 filterPtr = PALYFilter1;
5236 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005237
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305238 case 0x02:
5239 case 0x05:
5240 case 0x0D:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305241 case 0x03:
Aaro Koskinen2555e942011-08-31 21:46:06 +03005242 filterPtr = xgifb_palmn_yfilter1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305243 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005244
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305245 case 0x08:
5246 case 0x0C:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305247 case 0x0A:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305248 case 0x0B:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305249 case 0x09:
Aaro Koskinen80f86f82011-08-31 21:46:05 +03005250 filterPtr = xgifb_yfilter2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305251 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005252
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305253 default:
5254 return;
5255 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005256
Aaro Koskinenb3979922012-11-04 21:14:52 +02005257 tempal = XGI330_EModeIDTable[ModeIdIndex].VB_ExtTVYFilterIndex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305258 if (tempcl == 0)
5259 index = tempal * 4;
5260 else
5261 index = tempal * 7;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005262
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305263 if ((tempcl == 0) && (tempch == 1)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005264 xgifb_reg_set(pVBInfo->Part2Port, 0x35, 0);
5265 xgifb_reg_set(pVBInfo->Part2Port, 0x36, 0);
5266 xgifb_reg_set(pVBInfo->Part2Port, 0x37, 0);
5267 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305268 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005269 xgifb_reg_set(pVBInfo->Part2Port, 0x35, filterPtr[index++]);
5270 xgifb_reg_set(pVBInfo->Part2Port, 0x36, filterPtr[index++]);
5271 xgifb_reg_set(pVBInfo->Part2Port, 0x37, filterPtr[index++]);
5272 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305273 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005274
Peter Huewe6896b942012-02-09 21:11:46 +01005275 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5276 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005277 xgifb_reg_set(pVBInfo->Part2Port, 0x48, filterPtr[index++]);
5278 xgifb_reg_set(pVBInfo->Part2Port, 0x49, filterPtr[index++]);
5279 xgifb_reg_set(pVBInfo->Part2Port, 0x4A, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305280 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005281}
5282
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005283/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005284/* Function : XGI_OEM310Setting */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005285/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005286/* Output : */
5287/* Description : Customized Param. for 301 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005288/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005289static void XGI_OEM310Setting(unsigned short ModeNo,
5290 unsigned short ModeIdIndex,
5291 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005292{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005293 XGI_SetDelayComp(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005294
Peter Huewea3d675c2012-02-09 21:11:47 +01005295 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005296 XGI_SetLCDCap(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005297
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005298 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005299 XGI_SetPhaseIncr(pVBInfo);
5300 XGI_SetYFilter(ModeNo, ModeIdIndex, pVBInfo);
5301 XGI_SetAntiFlicker(ModeNo, ModeIdIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005302
Peter Huewe6896b942012-02-09 21:11:46 +01005303 if (pVBInfo->VBType & VB_SIS301)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005304 XGI_SetEdgeEnhance(ModeNo, ModeIdIndex, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305305 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005306}
5307
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005308/* --------------------------------------------------------------------- */
5309/* Function : XGI_SetCRT2ModeRegs */
5310/* Input : */
5311/* Output : */
5312/* Description : Origin code for crt2group */
5313/* --------------------------------------------------------------------- */
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02005314static void XGI_SetCRT2ModeRegs(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305315 struct xgi_hw_device_info *HwDeviceExtension,
5316 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005317{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305318 unsigned short tempbl;
5319 short tempcl;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005320
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305321 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005322
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305323 tempah = 0;
5324 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005325 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305326 tempah &= ~0x10; /* BTRAMDAC */
5327 tempah |= 0x40; /* BTRAM */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005328
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305329 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
5330 | SetCRT2ToLCD)) {
5331 tempah = 0x40; /* BTDRAM */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005332 tempcl = pVBInfo->ModeType;
5333 tempcl -= ModeVGA;
5334 if (tempcl >= 0) {
5335 /* BT Color */
5336 tempah = (0x008 >> tempcl);
5337 if (tempah == 0)
5338 tempah = 1;
5339 tempah |= 0x040;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305340 }
5341 if (pVBInfo->VBInfo & SetInSlaveMode)
5342 tempah ^= 0x50; /* BTDAC */
5343 }
5344 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005345
Aaro Koskinen8104e322011-03-13 12:26:22 +02005346 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305347 tempah = 0x08;
5348 tempbl = 0xf0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005349
Miguel Gómeze123e462012-07-06 12:40:52 +02005350 if (pVBInfo->VBInfo & DisableCRT2Display)
5351 goto reg_and_or;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005352
Miguel Gómeze123e462012-07-06 12:40:52 +02005353 tempah = 0x00;
5354 tempbl = 0xff;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005355
Miguel Gómeze123e462012-07-06 12:40:52 +02005356 if (!(pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV |
5357 SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
5358 goto reg_and_or;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005359
Miguel Gómeze123e462012-07-06 12:40:52 +02005360 if ((pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) &&
5361 (!(pVBInfo->VBInfo & SetSimuScanMode))) {
5362 tempbl &= 0xf7;
5363 tempah |= 0x01;
5364 goto reg_and_or;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305365 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005366
Miguel Gómeze123e462012-07-06 12:40:52 +02005367 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
5368 tempbl &= 0xf7;
5369 tempah |= 0x01;
5370 }
5371
5372 if (!(pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD)))
5373 goto reg_and_or;
5374
5375 tempbl &= 0xf8;
5376 tempah = 0x01;
5377
5378 if (!(pVBInfo->VBInfo & SetInSlaveMode))
5379 tempah |= 0x02;
5380
5381 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
5382 tempah = tempah ^ 0x05;
5383 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
5384 tempah = tempah ^ 0x01;
5385 }
5386
5387 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
5388 tempah |= 0x08;
5389
5390reg_and_or:
5391 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl, tempah);
5392
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305393 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD
Peter Huewea3d675c2012-02-09 21:11:47 +01005394 | XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305395 tempah &= (~0x08);
5396 if ((pVBInfo->ModeType == ModeVGA) && (!(pVBInfo->VBInfo
5397 & SetInSlaveMode))) {
5398 tempah |= 0x010;
5399 }
5400 tempah |= 0x080;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005401
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305402 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305403 tempah |= 0x020;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005404 if (pVBInfo->VBInfo & DriverMode)
5405 tempah = tempah ^ 0x20;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305406 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005407
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005408 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D, ~0x0BF, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305409 tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005410
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305411 if (pVBInfo->LCDInfo & SetLCDDualLink)
5412 tempah |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005413
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305414 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305415 if (pVBInfo->TVInfo & RPLLDIV2XO)
5416 tempah |= 0x40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305417 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005418
Peter Huewe255aabd2012-02-09 21:11:44 +01005419 if ((pVBInfo->LCDResInfo == Panel_1280x1024)
5420 || (pVBInfo->LCDResInfo == Panel_1280x1024x75))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305421 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005422
Peter Huewe255aabd2012-02-09 21:11:44 +01005423 if (pVBInfo->LCDResInfo == Panel_1280x960)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305424 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005425
Aaro Koskinen8104e322011-03-13 12:26:22 +02005426 xgifb_reg_set(pVBInfo->Part4Port, 0x0C, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305427 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005428
Peter Huewe6896b942012-02-09 21:11:46 +01005429 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5430 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305431 tempah = 0;
5432 tempbl = 0xfb;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005433
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305434 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
5435 tempbl = 0xff;
Peter Huewea3d675c2012-02-09 21:11:47 +01005436 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305437 tempah |= 0x04; /* shampoo 0129 */
5438 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005439
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005440 xgifb_reg_and_or(pVBInfo->Part1Port, 0x13, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305441 tempah = 0x00;
5442 tempbl = 0xcf;
5443 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5444 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5445 tempah |= 0x30;
5446 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005447
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005448 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2c, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305449 tempah = 0;
5450 tempbl = 0x3f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005451
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305452 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5453 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5454 tempah |= 0xc0;
5455 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005456 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305457 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005458
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305459 tempah = 0;
5460 tempbl = 0x7f;
Peter Huewea3d675c2012-02-09 21:11:47 +01005461 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305462 tempbl = 0xff;
5463 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
5464 tempah |= 0x80;
5465 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005466
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005467 xgifb_reg_and_or(pVBInfo->Part4Port, 0x23, tempbl, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005468
Peter Huewe6896b942012-02-09 21:11:46 +01005469 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305470 if (pVBInfo->LCDInfo & SetLCDDualLink) {
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005471 xgifb_reg_or(pVBInfo->Part4Port, 0x27, 0x20);
5472 xgifb_reg_or(pVBInfo->Part4Port, 0x34, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305473 }
5474 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005475}
5476
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005477
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305478void XGI_UnLockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
5479 struct vb_device_info *pVBInfo)
5480{
5481
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005482 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2f, 0xFF, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005483
5484}
5485
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305486void XGI_LockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
5487 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005488{
5489
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005490 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2F, 0xFE, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005491
5492}
5493
Bill Pemberton80adad82010-06-17 13:10:51 -04005494unsigned char XGI_BridgeIsOn(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005495{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305496 unsigned short flag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005497
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305498 if (pVBInfo->IF_DEF_LVDS == 1) {
5499 return 1;
5500 } else {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005501 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305502 if ((flag == 1) || (flag == 2))
5503 return 1; /* 301b */
5504 else
5505 return 0;
5506 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005507}
5508
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005509unsigned short XGI_GetRatePtrCRT2(struct xgi_hw_device_info *pXGIHWDE,
5510 unsigned short ModeNo, unsigned short ModeIdIndex,
5511 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005512{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005513 short LCDRefreshIndex[] = { 0x00, 0x00, 0x03, 0x01 },
5514 LCDARefreshIndex[] = { 0x00, 0x00, 0x03, 0x01, 0x01,
5515 0x01, 0x01 };
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005516
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005517 unsigned short RefreshRateTableIndex, i, modeflag, index, temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005518
Aaro Koskinenb3979922012-11-04 21:14:52 +02005519 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005520
Aaro Koskinen58839b02011-03-13 12:26:23 +02005521 index = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005522 index = index >> pVBInfo->SelectCRT2Rate;
5523 index &= 0x0F;
5524
5525 if (pVBInfo->LCDInfo & LCDNonExpanding)
5526 index = 0;
5527
5528 if (index > 0)
5529 index--;
5530
5531 if (pVBInfo->SetFlag & ProgrammingCRT2) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005532 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005533 if (pVBInfo->IF_DEF_LVDS == 0) {
Peter Huewe6896b942012-02-09 21:11:46 +01005534 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
5535 | VB_SIS301LV | VB_SIS302LV
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005536 | VB_XGI301C))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005537 /* 301b */
5538 temp = LCDARefreshIndex[
5539 pVBInfo->LCDResInfo & 0x0F];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005540 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005541 temp = LCDRefreshIndex[
5542 pVBInfo->LCDResInfo & 0x0F];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005543
5544 if (index > temp)
5545 index = temp;
5546 } else {
5547 index = 0;
5548 }
5549 }
5550 }
5551
Aaro Koskinenb3979922012-11-04 21:14:52 +02005552 RefreshRateTableIndex = XGI330_EModeIDTable[ModeIdIndex].REFindex;
Aaro Koskinena39325d2012-11-04 21:14:53 +02005553 ModeNo = XGI330_RefIndex[RefreshRateTableIndex].ModeID;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005554 if (pXGIHWDE->jChipType >= XG20) { /* for XG20, XG21, XG27 */
Aaro Koskinena39325d2012-11-04 21:14:53 +02005555 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 800) &&
5556 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 600)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005557 index++;
5558 }
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005559 /* do the similar adjustment like XGISearchCRT1Rate() */
Aaro Koskinena39325d2012-11-04 21:14:53 +02005560 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 1024) &&
5561 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 768)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005562 index++;
5563 }
Aaro Koskinena39325d2012-11-04 21:14:53 +02005564 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 1280) &&
5565 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 1024)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005566 index++;
5567 }
5568 }
5569
5570 i = 0;
5571 do {
Aaro Koskinena39325d2012-11-04 21:14:53 +02005572 if (XGI330_RefIndex[RefreshRateTableIndex + i].
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005573 ModeID != ModeNo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005574 break;
Aaro Koskinena39325d2012-11-04 21:14:53 +02005575 temp = XGI330_RefIndex[RefreshRateTableIndex + i].Ext_InfoFlag;
Peter Huewe6896b942012-02-09 21:11:46 +01005576 temp &= ModeTypeMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005577 if (temp < pVBInfo->ModeType)
5578 break;
5579 i++;
5580 index--;
5581
5582 } while (index != 0xFFFF);
5583 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
5584 if (pVBInfo->VBInfo & SetInSlaveMode) {
Aaro Koskinena39325d2012-11-04 21:14:53 +02005585 temp = XGI330_RefIndex[RefreshRateTableIndex + i - 1].
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005586 Ext_InfoFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005587 if (temp & InterlaceMode)
5588 i++;
5589 }
5590 }
5591 i--;
5592 if ((pVBInfo->SetFlag & ProgrammingCRT2)) {
5593 temp = XGI_AjustCRT2Rate(ModeNo, ModeIdIndex,
5594 RefreshRateTableIndex, &i, pVBInfo);
5595 }
Aaro Koskinen9a0b2952011-11-27 23:03:16 +02005596 return RefreshRateTableIndex + i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005597}
5598
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005599static void XGI_SetLCDAGroup(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305600 struct xgi_hw_device_info *HwDeviceExtension,
5601 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005602{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005603 unsigned short RefreshRateTableIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005604
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005605 pVBInfo->SetFlag |= ProgrammingCRT2;
5606 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5607 ModeIdIndex, pVBInfo);
5608 XGI_GetLVDSResInfo(ModeNo, ModeIdIndex, pVBInfo);
5609 XGI_GetLVDSData(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5610 XGI_ModCRT1Regs(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5611 HwDeviceExtension, pVBInfo);
5612 XGI_SetLVDSRegs(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5613 XGI_SetCRT2ECLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005614}
5615
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02005616static unsigned char XGI_SetCRT2Group301(unsigned short ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005617 struct xgi_hw_device_info *HwDeviceExtension,
5618 struct vb_device_info *pVBInfo)
5619{
5620 unsigned short tempbx, ModeIdIndex, RefreshRateTableIndex;
5621
5622 tempbx = pVBInfo->VBInfo;
5623 pVBInfo->SetFlag |= ProgrammingCRT2;
5624 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
5625 pVBInfo->SelectCRT2Rate = 4;
5626 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5627 ModeIdIndex, pVBInfo);
5628 XGI_SaveCRT2Info(ModeNo, pVBInfo);
5629 XGI_GetCRT2ResInfo(ModeNo, ModeIdIndex, pVBInfo);
5630 XGI_GetCRT2Data(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5631 XGI_PreSetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
5632 RefreshRateTableIndex, pVBInfo);
5633 XGI_SetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
5634 RefreshRateTableIndex, pVBInfo);
5635 XGI_SetLockRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
5636 RefreshRateTableIndex, pVBInfo);
5637 XGI_SetGroup2(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5638 HwDeviceExtension, pVBInfo);
5639 XGI_SetLCDRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
5640 RefreshRateTableIndex, pVBInfo);
5641 XGI_SetTap4Regs(pVBInfo);
5642 XGI_SetGroup3(ModeNo, ModeIdIndex, pVBInfo);
5643 XGI_SetGroup4(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5644 HwDeviceExtension, pVBInfo);
5645 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5646 XGI_SetGroup5(ModeNo, ModeIdIndex, pVBInfo);
5647 XGI_AutoThreshold(pVBInfo);
5648 return 1;
5649}
5650
5651void XGI_SenseCRT1(struct vb_device_info *pVBInfo)
5652{
5653 unsigned char CRTCData[17] = { 0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81,
5654 0x0B, 0x3E, 0xE9, 0x0B, 0xDF, 0xE7, 0x04, 0x00, 0x00,
5655 0x05, 0x00 };
5656
5657 unsigned char SR01 = 0, SR1F = 0, SR07 = 0, SR06 = 0;
5658
5659 unsigned char CR17, CR63, SR31;
5660 unsigned short temp;
5661 unsigned char DAC_TEST_PARMS[3] = { 0x0F, 0x0F, 0x0F };
5662
5663 int i;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005664 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005665
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005666 /* to fix XG42 single LCD sense to CRT+LCD */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005667 xgifb_reg_set(pVBInfo->P3d4, 0x57, 0x4A);
Aaro Koskinen58839b02011-03-13 12:26:23 +02005668 xgifb_reg_set(pVBInfo->P3d4, 0x53, (unsigned char) (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005669 pVBInfo->P3d4, 0x53) | 0x02));
5670
Aaro Koskinen58839b02011-03-13 12:26:23 +02005671 SR31 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x31);
5672 CR63 = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x63);
5673 SR01 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x01);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005674
Aaro Koskinen8104e322011-03-13 12:26:22 +02005675 xgifb_reg_set(pVBInfo->P3c4, 0x01, (unsigned char) (SR01 & 0xDF));
5676 xgifb_reg_set(pVBInfo->P3d4, 0x63, (unsigned char) (CR63 & 0xBF));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005677
Aaro Koskinen58839b02011-03-13 12:26:23 +02005678 CR17 = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x17);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005679 xgifb_reg_set(pVBInfo->P3d4, 0x17, (unsigned char) (CR17 | 0x80));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005680
Aaro Koskinen58839b02011-03-13 12:26:23 +02005681 SR1F = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005682 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) (SR1F | 0x04));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005683
Aaro Koskinen58839b02011-03-13 12:26:23 +02005684 SR07 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x07);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005685 xgifb_reg_set(pVBInfo->P3c4, 0x07, (unsigned char) (SR07 & 0xFB));
Aaro Koskinen58839b02011-03-13 12:26:23 +02005686 SR06 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x06);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005687 xgifb_reg_set(pVBInfo->P3c4, 0x06, (unsigned char) (SR06 & 0xC3));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005688
Aaro Koskinen8104e322011-03-13 12:26:22 +02005689 xgifb_reg_set(pVBInfo->P3d4, 0x11, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005690
5691 for (i = 0; i < 8; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005692 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) i, CRTCData[i]);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005693
5694 for (i = 8; i < 11; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005695 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 8),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005696 CRTCData[i]);
5697
5698 for (i = 11; i < 13; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005699 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 4),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005700 CRTCData[i]);
5701
5702 for (i = 13; i < 16; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005703 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i - 3),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005704 CRTCData[i]);
5705
Aaro Koskinen8104e322011-03-13 12:26:22 +02005706 xgifb_reg_set(pVBInfo->P3c4, 0x0E, (unsigned char) (CRTCData[16]
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005707 & 0xE0));
5708
Aaro Koskinen8104e322011-03-13 12:26:22 +02005709 xgifb_reg_set(pVBInfo->P3c4, 0x31, 0x00);
5710 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x1B);
5711 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE1);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005712
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005713 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005714
5715 for (i = 0; i < 256; i++) {
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005716 outb((unsigned char) DAC_TEST_PARMS[0], (pVBInfo->P3c8 + 1));
5717 outb((unsigned char) DAC_TEST_PARMS[1], (pVBInfo->P3c8 + 1));
5718 outb((unsigned char) DAC_TEST_PARMS[2], (pVBInfo->P3c8 + 1));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005719 }
5720
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005721 mdelay(1);
5722
5723 XGI_WaitDisply(pVBInfo);
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02005724 temp = inb(pVBInfo->P3c2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005725
5726 if (temp & 0x10)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005727 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005728 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005729 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005730
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005731 /* avoid display something, set BLACK DAC if not restore DAC */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005732 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005733
5734 for (i = 0; i < 256; i++) {
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005735 outb(0, (pVBInfo->P3c8 + 1));
5736 outb(0, (pVBInfo->P3c8 + 1));
5737 outb(0, (pVBInfo->P3c8 + 1));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005738 }
5739
Aaro Koskinen8104e322011-03-13 12:26:22 +02005740 xgifb_reg_set(pVBInfo->P3c4, 0x01, SR01);
5741 xgifb_reg_set(pVBInfo->P3d4, 0x63, CR63);
5742 xgifb_reg_set(pVBInfo->P3c4, 0x31, SR31);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005743
Aaro Koskinen58839b02011-03-13 12:26:23 +02005744 xgifb_reg_set(pVBInfo->P3d4, 0x53, (unsigned char) (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005745 pVBInfo->P3d4, 0x53) & 0xFD));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005746 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) SR1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005747}
5748
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005749static void XGI_EnableBridge(struct xgifb_video_info *xgifb_info,
5750 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005751 struct vb_device_info *pVBInfo)
5752{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02005753 unsigned short tempah;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005754
Peter Huewe6896b942012-02-09 21:11:46 +01005755 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5756 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005757 if (!(pVBInfo->SetFlag & DisableChA)) {
5758 if (pVBInfo->SetFlag & EnableChA) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005759 /* Power on */
5760 xgifb_reg_set(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinend3ae5762012-09-11 00:15:27 +03005761 } else if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
5762 /* Power on */
5763 xgifb_reg_set(pVBInfo->Part1Port,
5764 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005765 }
5766 }
5767
5768 if (!(pVBInfo->SetFlag & DisableChB)) {
5769 if ((pVBInfo->SetFlag & EnableChB) || (pVBInfo->VBInfo
5770 & (SetCRT2ToLCD | SetCRT2ToTV
5771 | SetCRT2ToRAMDAC))) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005772 tempah = (unsigned char) xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005773 pVBInfo->P3c4, 0x32);
5774 tempah &= 0xDF;
5775 if (pVBInfo->VBInfo & SetInSlaveMode) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005776 if (!(pVBInfo->VBInfo &
5777 SetCRT2ToRAMDAC))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005778 tempah |= 0x20;
5779 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02005780 xgifb_reg_set(pVBInfo->P3c4, 0x32, tempah);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005781 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005782
Aaro Koskinen58839b02011-03-13 12:26:23 +02005783 tempah = (unsigned char) xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005784 pVBInfo->Part1Port, 0x2E);
5785
5786 if (!(tempah & 0x80))
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005787 xgifb_reg_or(pVBInfo->Part1Port,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005788 0x2E, 0x80);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005789 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005790 }
5791 }
5792
5793 if ((pVBInfo->SetFlag & (EnableChA | EnableChB))
5794 || (!(pVBInfo->VBInfo & DisableCRT2Display))) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005795 xgifb_reg_and_or(pVBInfo->Part2Port, 0x00, ~0xE0,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005796 0x20); /* shampoo 0129 */
Peter Huewe6896b942012-02-09 21:11:46 +01005797 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005798 if (!XGI_DisableChISLCD(pVBInfo)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005799 if (XGI_EnableChISLCD(pVBInfo) ||
5800 (pVBInfo->VBInfo &
Peter Huewea3d675c2012-02-09 21:11:47 +01005801 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005802 /* LVDS PLL power on */
Aaro Koskinendc505562011-03-13 12:26:26 +02005803 xgifb_reg_and(
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005804 pVBInfo->Part4Port,
5805 0x2A,
5806 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005807 }
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005808 /* LVDS Driver power on */
5809 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005810 }
5811 }
5812
5813 tempah = 0x00;
5814
5815 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5816 tempah = 0xc0;
5817
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005818 if (!(pVBInfo->VBInfo & SetSimuScanMode) &&
5819 (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) &&
5820 (pVBInfo->VBInfo & SetCRT2ToDualEdge)) {
5821 tempah = tempah & 0x40;
5822 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
5823 tempah = tempah ^ 0xC0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005824
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005825 if (pVBInfo->SetFlag & DisableChB)
5826 tempah &= 0xBF;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005827
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005828 if (pVBInfo->SetFlag & DisableChA)
5829 tempah &= 0x7F;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005830
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005831 if (pVBInfo->SetFlag & EnableChB)
5832 tempah |= 0x40;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005833
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005834 if (pVBInfo->SetFlag & EnableChA)
5835 tempah |= 0x80;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005836 }
5837 }
5838
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005839 /* EnablePart4_1F */
5840 xgifb_reg_or(pVBInfo->Part4Port, 0x1F, tempah);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005841
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005842 if (!(pVBInfo->SetFlag & DisableChA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005843 if (!(pVBInfo->SetFlag & GatingCRT)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005844 XGI_DisableGatingCRT(HwDeviceExtension,
5845 pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005846 XGI_DisplayOn(xgifb_info, HwDeviceExtension,
5847 pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005848 }
5849 }
5850 } /* 301 */
5851 else { /* LVDS */
5852 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD
Peter Huewea3d675c2012-02-09 21:11:47 +01005853 | XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005854 /* enable CRT2 */
5855 xgifb_reg_or(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005856
Aaro Koskinen58839b02011-03-13 12:26:23 +02005857 tempah = (unsigned char) xgifb_reg_get(pVBInfo->Part1Port,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005858 0x2E);
5859 if (!(tempah & 0x80))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005860 xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005861
Aaro Koskinendc505562011-03-13 12:26:26 +02005862 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005863 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005864 } /* End of VB */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005865}
5866
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005867static void XGI_SetCRT1Group(struct xgifb_video_info *xgifb_info,
5868 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005869 unsigned short ModeNo, unsigned short ModeIdIndex,
5870 struct vb_device_info *pVBInfo)
5871{
Aaro Koskinena1579612012-04-07 01:14:05 +03005872 unsigned short RefreshRateTableIndex, temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005873
Aaro Koskinena1579612012-04-07 01:14:05 +03005874 XGI_SetSeqRegs(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinen3625c9a2012-11-04 21:14:51 +02005875 outb(XGI330_StandTable.MISC, pVBInfo->P3c2);
Aaro Koskinena1579612012-04-07 01:14:05 +03005876 XGI_SetCRTCRegs(HwDeviceExtension, pVBInfo);
5877 XGI_SetATTRegs(ModeNo, ModeIdIndex, pVBInfo);
5878 XGI_SetGRCRegs(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005879 XGI_ClearExt1Regs(pVBInfo);
5880
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005881 if (HwDeviceExtension->jChipType == XG27) {
5882 if (pVBInfo->IF_DEF_LVDS == 0)
5883 XGI_SetDefaultVCLK(pVBInfo);
5884 }
5885
5886 temp = ~ProgrammingCRT2;
5887 pVBInfo->SetFlag &= temp;
5888 pVBInfo->SelectCRT2Rate = 0;
5889
Peter Huewe6896b942012-02-09 21:11:46 +01005890 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5891 | VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005892 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005893 | SetInSlaveMode)) {
5894 pVBInfo->SetFlag |= ProgrammingCRT2;
5895 }
5896 }
5897
5898 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5899 ModeIdIndex, pVBInfo);
5900 if (RefreshRateTableIndex != 0xFFFF) {
5901 XGI_SetSync(RefreshRateTableIndex, pVBInfo);
5902 XGI_SetCRT1CRTC(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5903 pVBInfo, HwDeviceExtension);
5904 XGI_SetCRT1DE(HwDeviceExtension, ModeNo, ModeIdIndex,
5905 RefreshRateTableIndex, pVBInfo);
5906 XGI_SetCRT1Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5907 HwDeviceExtension, pVBInfo);
5908 XGI_SetCRT1VCLK(ModeNo, ModeIdIndex, HwDeviceExtension,
5909 RefreshRateTableIndex, pVBInfo);
5910 }
5911
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005912 if (HwDeviceExtension->jChipType >= XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005913 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005914 if (temp & 0xA0) {
5915
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005916 if (HwDeviceExtension->jChipType == XG27)
5917 XGI_SetXG27CRTC(ModeNo, ModeIdIndex,
5918 RefreshRateTableIndex, pVBInfo);
5919 else
5920 XGI_SetXG21CRTC(ModeNo, ModeIdIndex,
5921 RefreshRateTableIndex, pVBInfo);
5922
5923 XGI_UpdateXG21CRTC(ModeNo, pVBInfo,
5924 RefreshRateTableIndex);
5925
Aaro Koskinen105d8d02011-08-31 21:46:00 +03005926 xgifb_set_lcd(HwDeviceExtension->jChipType,
5927 pVBInfo, RefreshRateTableIndex, ModeNo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005928
Aaro Koskinen64db29f2011-08-31 21:46:01 +03005929 if (pVBInfo->IF_DEF_LVDS == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005930 xgifb_set_lvds(xgifb_info,
5931 HwDeviceExtension->jChipType,
Aaro Koskinen64db29f2011-08-31 21:46:01 +03005932 ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005933 }
5934 }
5935
5936 pVBInfo->SetFlag &= (~ProgrammingCRT2);
5937 XGI_SetCRT1FIFO(ModeNo, HwDeviceExtension, pVBInfo);
5938 XGI_SetCRT1ModeRegs(HwDeviceExtension, ModeNo, ModeIdIndex,
5939 RefreshRateTableIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005940 XGI_LoadDAC(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005941}
5942
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005943unsigned char XGISetModeNew(struct xgifb_video_info *xgifb_info,
5944 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005945 unsigned short ModeNo)
5946{
5947 unsigned short ModeIdIndex;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005948 struct vb_device_info VBINF;
5949 struct vb_device_info *pVBInfo = &VBINF;
Dmitry Eremin-Solenikov9a801f22012-03-19 21:50:13 +04005950 pVBInfo->BaseAddr = xgifb_info->vga_base;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005951 pVBInfo->IF_DEF_LVDS = 0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005952
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005953 if (HwDeviceExtension->jChipType >= XG20) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005954 pVBInfo->IF_DEF_YPbPr = 0;
5955 pVBInfo->IF_DEF_HiVision = 0;
5956 pVBInfo->IF_DEF_CRT2Monitor = 0;
5957 pVBInfo->VBType = 0; /*set VBType default 0*/
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005958 } else {
5959 pVBInfo->IF_DEF_YPbPr = 1;
5960 pVBInfo->IF_DEF_HiVision = 1;
Aaro Koskinen06587332011-03-13 12:26:10 +02005961 pVBInfo->IF_DEF_CRT2Monitor = 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005962 }
5963
5964 pVBInfo->P3c4 = pVBInfo->BaseAddr + 0x14;
5965 pVBInfo->P3d4 = pVBInfo->BaseAddr + 0x24;
5966 pVBInfo->P3c0 = pVBInfo->BaseAddr + 0x10;
5967 pVBInfo->P3ce = pVBInfo->BaseAddr + 0x1e;
5968 pVBInfo->P3c2 = pVBInfo->BaseAddr + 0x12;
5969 pVBInfo->P3cc = pVBInfo->BaseAddr + 0x1C;
5970 pVBInfo->P3ca = pVBInfo->BaseAddr + 0x1a;
5971 pVBInfo->P3c6 = pVBInfo->BaseAddr + 0x16;
5972 pVBInfo->P3c7 = pVBInfo->BaseAddr + 0x17;
5973 pVBInfo->P3c8 = pVBInfo->BaseAddr + 0x18;
5974 pVBInfo->P3c9 = pVBInfo->BaseAddr + 0x19;
5975 pVBInfo->P3da = pVBInfo->BaseAddr + 0x2A;
5976 pVBInfo->Part0Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_00;
Peter Huewe6896b942012-02-09 21:11:46 +01005977 pVBInfo->Part1Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_04;
5978 pVBInfo->Part2Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_10;
5979 pVBInfo->Part3Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_12;
5980 pVBInfo->Part4Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_14;
5981 pVBInfo->Part5Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_14 + 2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005982
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005983 /* for x86 Linux, XG21 LVDS */
5984 if (HwDeviceExtension->jChipType == XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005985 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005986 pVBInfo->IF_DEF_LVDS = 1;
5987 }
5988 if (HwDeviceExtension->jChipType == XG27) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005989 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0) {
5990 if (xgifb_reg_get(pVBInfo->P3d4, 0x30) & 0x20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005991 pVBInfo->IF_DEF_LVDS = 1;
5992 }
5993 }
5994
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005995 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005996 XGI_GetVBType(pVBInfo);
5997
5998 InitTo330Pointer(HwDeviceExtension->jChipType, pVBInfo);
Aaro Koskinenef497f42011-11-27 23:03:21 +02005999 if (ModeNo & 0x80)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006000 ModeNo = ModeNo & 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +02006001 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006002
Miguel Gómez949eb0a2012-07-06 12:40:36 +02006003 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006004 XGI_UnLockCRT2(HwDeviceExtension, pVBInfo);
6005
6006 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
6007
Miguel Gómez949eb0a2012-07-06 12:40:36 +02006008 if (HwDeviceExtension->jChipType < XG20) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006009 XGI_GetVBInfo(ModeNo, ModeIdIndex, HwDeviceExtension, pVBInfo);
6010 XGI_GetTVInfo(ModeNo, ModeIdIndex, pVBInfo);
6011 XGI_GetLCDInfo(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006012 XGI_DisableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006013
Peter Huewea3d675c2012-02-09 21:11:47 +01006014 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA)) {
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006015 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006016 ModeIdIndex, pVBInfo);
6017
Peter Huewea3d675c2012-02-09 21:11:47 +01006018 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006019 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
6020 HwDeviceExtension, pVBInfo);
6021 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +03006022 } else if (!(pVBInfo->VBInfo & SwitchCRT2)) {
6023 XGI_SetCRT1Group(xgifb_info,
6024 HwDeviceExtension, ModeNo,
6025 ModeIdIndex, pVBInfo);
6026 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
6027 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
6028 HwDeviceExtension,
6029 pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006030 }
6031 }
6032
Peter Huewe6896b942012-02-09 21:11:46 +01006033 if (pVBInfo->VBInfo & (SetSimuScanMode | SwitchCRT2)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006034 switch (HwDeviceExtension->ujVBChipID) {
6035 case VB_CHIP_301:
6036 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
6037 pVBInfo); /*add for CRT2 */
6038 break;
6039
6040 case VB_CHIP_302:
6041 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
6042 pVBInfo); /*add for CRT2 */
6043 break;
6044
6045 default:
6046 break;
6047 }
6048 }
6049
6050 XGI_SetCRT2ModeRegs(ModeNo, HwDeviceExtension, pVBInfo);
6051 XGI_OEM310Setting(ModeNo, ModeIdIndex, pVBInfo); /*0212*/
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006052 XGI_EnableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006053 } /* !XG20 */
6054 else {
6055 if (pVBInfo->IF_DEF_LVDS == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006056 if (!XGI_XG21CheckLVDSMode(xgifb_info, ModeNo,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006057 ModeIdIndex,
6058 pVBInfo))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006059 return 0;
6060
Aaro Koskinenb3979922012-11-04 21:14:52 +02006061 pVBInfo->ModeType = XGI330_EModeIDTable[ModeIdIndex].
Peter Huewe6896b942012-02-09 21:11:46 +01006062 Ext_ModeFlag & ModeTypeMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006063
6064 pVBInfo->SetFlag = 0;
Aaro Koskinen83f76a92011-08-31 21:45:58 +03006065 pVBInfo->VBInfo = DisableCRT2Display;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006066
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006067 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006068
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006069 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
6070 ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006071
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006072 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006073 }
6074
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006075 XGI_UpdateModeInfo(HwDeviceExtension, pVBInfo);
6076
Miguel Gómez3bcc2462012-07-06 12:40:53 +02006077 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006078 XGI_LockCRT2(HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006079
6080 return 1;
6081}