blob: 59423addd2c6f93a215b40dda66cf2d472d19bc1 [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;
27 pVBInfo->ECLKData = XGI340_ECLKData;
28 pVBInfo->VCLKData = XGI_VCLKData;
Aaro Koskinene8cb03d2012-09-11 00:15:31 +030029 pVBInfo->VBVCLKData = XGI_VBVCLKData;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053030 pVBInfo->ScreenOffset = XGI330_ScreenOffset;
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +030031 pVBInfo->StResInfo = XGI330_StResInfo;
32 pVBInfo->ModeResInfo = XGI330_ModeResInfo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020033
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053034 pVBInfo->LCDResInfo = 0;
35 pVBInfo->LCDTypeInfo = 0;
36 pVBInfo->LCDInfo = 0;
37 pVBInfo->VBInfo = 0;
38 pVBInfo->TVInfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020039
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053040 pVBInfo->SR15 = XGI340_SR13;
41 pVBInfo->CR40 = XGI340_cr41;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053042 pVBInfo->CR6B = XGI340_CR6B;
43 pVBInfo->CR6E = XGI340_CR6E;
44 pVBInfo->CR6F = XGI340_CR6F;
45 pVBInfo->CR89 = XGI340_CR89;
46 pVBInfo->AGPReg = XGI340_AGPReg;
47 pVBInfo->SR16 = XGI340_SR16;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020048
Peter Huewe6d12dae2012-06-14 00:21:52 +020049 pVBInfo->SR21 = 0xa3;
50 pVBInfo->SR22 = 0xfb;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020051
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053052 /* 310 customization related */
Peter Huewe6896b942012-02-09 21:11:46 +010053 if ((pVBInfo->VBType & VB_SIS301LV) || (pVBInfo->VBType & VB_SIS302LV))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053054 pVBInfo->LCDCapList = XGI_LCDDLCapList;
55 else
56 pVBInfo->LCDCapList = XGI_LCDCapList;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020057
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053058 if (ChipType >= XG20)
Peter Huewe6d12dae2012-06-14 00:21:52 +020059 pVBInfo->XGINew_CR97 = 0x10;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020060
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053061 if (ChipType == XG27) {
Dmitry Eremin-Solenikov64903112012-03-19 21:50:09 +040062 unsigned char temp;
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +030063 pVBInfo->MCLKData = XGI27New_MCLKData;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053064 pVBInfo->CR40 = XGI27_cr41;
Peter Huewe6d12dae2012-06-14 00:21:52 +020065 pVBInfo->XGINew_CR97 = 0xc1;
Dmitry Eremin-Solenikov64903112012-03-19 21:50:09 +040066 pVBInfo->SR15 = XG27_SR13;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020067
Dmitry Eremin-Solenikov64903112012-03-19 21:50:09 +040068 /*Z11m DDR*/
69 temp = xgifb_reg_get(pVBInfo->P3c4, 0x3B);
70 /* SR3B[7][3]MAA15 MAA11 (Power on Trapping) */
71 if (((temp & 0x88) == 0x80) || ((temp & 0x88) == 0x08))
Peter Huewe6d12dae2012-06-14 00:21:52 +020072 pVBInfo->XGINew_CR97 = 0x80;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053073 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020074
75}
76
Kenji Toyama1d7f6562011-04-23 19:36:49 +080077static void XGI_SetSeqRegs(unsigned short ModeNo,
Kenji Toyama1d7f6562011-04-23 19:36:49 +080078 unsigned short ModeIdIndex,
79 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020080{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053081 unsigned char tempah, SRdata;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053082 unsigned short i, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020083
Aaro Koskinenb3979922012-11-04 21:14:52 +020084 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020085
Aaro Koskinen8104e322011-03-13 12:26:22 +020086 xgifb_reg_set(pVBInfo->P3c4, 0x00, 0x03); /* Set SR0 */
Aaro Koskinen3625c9a2012-11-04 21:14:51 +020087 tempah = XGI330_StandTable.SR[0];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020088
Peter Huewea3d675c2012-02-09 21:11:47 +010089 i = XGI_SetCRT2ToLCDA;
90 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053091 tempah |= 0x01;
Aaro Koskinend3ae5762012-09-11 00:15:27 +030092 } else if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD)) {
93 if (pVBInfo->VBInfo & SetInSlaveMode)
94 tempah |= 0x01;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053095 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020096
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053097 tempah |= 0x20; /* screen off */
Aaro Koskinen8104e322011-03-13 12:26:22 +020098 xgifb_reg_set(pVBInfo->P3c4, 0x01, tempah); /* Set SR1 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020099
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530100 for (i = 02; i <= 04; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800101 /* Get SR2,3,4 from file */
Aaro Koskinen3625c9a2012-11-04 21:14:51 +0200102 SRdata = XGI330_StandTable.SR[i - 1];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200103 xgifb_reg_set(pVBInfo->P3c4, i, SRdata); /* Set SR2 3 4 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530104 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200105}
106
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200107static void XGI_SetCRTCRegs(struct xgi_hw_device_info *HwDeviceExtension,
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800108 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200109{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530110 unsigned char CRTCdata;
111 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200112
Aaro Koskinen58839b02011-03-13 12:26:23 +0200113 CRTCdata = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530114 CRTCdata &= 0x7f;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200115 xgifb_reg_set(pVBInfo->P3d4, 0x11, CRTCdata); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200116
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530117 for (i = 0; i <= 0x18; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800118 /* Get CRTC from file */
Aaro Koskinen3625c9a2012-11-04 21:14:51 +0200119 CRTCdata = XGI330_StandTable.CRTC[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200120 xgifb_reg_set(pVBInfo->P3d4, i, CRTCdata); /* Set CRTC(3d4) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530121 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200122}
123
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800124static void XGI_SetATTRegs(unsigned short ModeNo,
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800125 unsigned short ModeIdIndex,
126 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200127{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530128 unsigned char ARdata;
129 unsigned short i, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200130
Aaro Koskinenb3979922012-11-04 21:14:52 +0200131 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200132
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530133 for (i = 0; i <= 0x13; i++) {
Aaro Koskinen3625c9a2012-11-04 21:14:51 +0200134 ARdata = XGI330_StandTable.ATTR[i];
Miguel Gómez661a6382012-07-06 12:40:45 +0200135
136 if ((modeflag & Charx8Dot) && i == 0x13) { /* ifndef Dot9 */
137 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
138 ARdata = 0;
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300139 } else if ((pVBInfo->VBInfo &
Miguel Gómez661a6382012-07-06 12:40:45 +0200140 (SetCRT2ToTV | SetCRT2ToLCD)) &&
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300141 (pVBInfo->VBInfo & SetInSlaveMode)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530142 ARdata = 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530143 }
144 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200145
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200146 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200147 outb(i, pVBInfo->P3c0); /* set index */
148 outb(ARdata, pVBInfo->P3c0); /* set data */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530149 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200150
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200151 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200152 outb(0x14, pVBInfo->P3c0); /* set index */
153 outb(0x00, pVBInfo->P3c0); /* set data */
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200154 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200155 outb(0x20, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200156}
157
Aaro Koskinena1579612012-04-07 01:14:05 +0300158static void XGI_SetGRCRegs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200159{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530160 unsigned char GRdata;
161 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200162
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530163 for (i = 0; i <= 0x08; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800164 /* Get GR from file */
Aaro Koskinen3625c9a2012-11-04 21:14:51 +0200165 GRdata = XGI330_StandTable.GRC[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200166 xgifb_reg_set(pVBInfo->P3ce, i, GRdata); /* Set GR(3ce) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530167 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200168
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530169 if (pVBInfo->ModeType > ModeVGA) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200170 GRdata = (unsigned char) xgifb_reg_get(pVBInfo->P3ce, 0x05);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530171 GRdata &= 0xBF; /* 256 color disable */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200172 xgifb_reg_set(pVBInfo->P3ce, 0x05, GRdata);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530173 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200174}
175
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200176static void XGI_ClearExt1Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200177{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530178 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200179
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530180 for (i = 0x0A; i <= 0x0E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +0200181 xgifb_reg_set(pVBInfo->P3c4, i, 0x00); /* Clear SR0A-SR0E */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200182}
183
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200184static unsigned char XGI_SetDefaultVCLK(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200185{
186
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200187 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x20);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200188 xgifb_reg_set(pVBInfo->P3c4, 0x2B, pVBInfo->VCLKData[0].SR2B);
189 xgifb_reg_set(pVBInfo->P3c4, 0x2C, pVBInfo->VCLKData[0].SR2C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200190
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200191 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x10);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200192 xgifb_reg_set(pVBInfo->P3c4, 0x2B, pVBInfo->VCLKData[1].SR2B);
193 xgifb_reg_set(pVBInfo->P3c4, 0x2C, pVBInfo->VCLKData[1].SR2C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200194
Aaro Koskinendc505562011-03-13 12:26:26 +0200195 xgifb_reg_and(pVBInfo->P3c4, 0x31, ~0x30);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530196 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200197}
198
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200199static unsigned char XGI_AjustCRT2Rate(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530200 unsigned short ModeIdIndex,
201 unsigned short RefreshRateTableIndex, unsigned short *i,
202 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200203{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530204 unsigned short tempax, tempbx, resinfo, modeflag, infoflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200205
Aaro Koskinenb3979922012-11-04 21:14:52 +0200206 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
207 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinena39325d2012-11-04 21:14:53 +0200208 tempbx = XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530209 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200210
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530211 if (pVBInfo->IF_DEF_LVDS == 0) {
212 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
213 tempax |= SupportRAMDAC2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200214
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530215 if (pVBInfo->VBType & VB_XGI301C)
216 tempax |= SupportCRT2in301C;
217 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200218
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800219 /* 301b */
Peter Huewea3d675c2012-02-09 21:11:47 +0100220 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530221 tempax |= SupportLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200222
Miguel Gómez3b175622012-07-06 12:40:46 +0200223 if (pVBInfo->LCDResInfo != Panel_1280x1024 &&
224 pVBInfo->LCDResInfo != Panel_1280x960 &&
225 (pVBInfo->LCDInfo & LCDNonExpanding) &&
226 resinfo >= 9)
227 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530228 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200229
Peter Huewe599801f2012-02-09 21:11:45 +0100230 if (pVBInfo->VBInfo & SetCRT2ToHiVision) { /* for HiTV */
Aaro Koskinen31fb40f2012-09-11 00:15:15 +0300231 tempax |= SupportHiVision;
232 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
233 ((resinfo == 4) ||
234 (resinfo == 3 &&
235 (pVBInfo->SetFlag & TVSimuMode)) ||
236 (resinfo > 7)))
Miguel Gómez3b175622012-07-06 12:40:46 +0200237 return 0;
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300238 } else if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO |
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800239 SetCRT2ToSVIDEO |
240 SetCRT2ToSCART |
Peter Huewe599801f2012-02-09 21:11:45 +0100241 SetCRT2ToYPbPr525750 |
242 SetCRT2ToHiVision)) {
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300243 tempax |= SupportTV;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200244
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300245 if (pVBInfo->VBType & (VB_SIS301B |
246 VB_SIS302B |
247 VB_SIS301LV |
248 VB_SIS302LV |
249 VB_XGI301C))
250 tempax |= SupportTV1024;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200251
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300252 if (!(pVBInfo->VBInfo & TVSetPAL) &&
253 (modeflag & NoSupportSimuTV) &&
254 (pVBInfo->VBInfo & SetInSlaveMode) &&
255 (!(pVBInfo->VBInfo & SetNotSimuMode)))
256 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530257 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300258 } else if (pVBInfo->VBInfo & SetCRT2ToLCD) { /* for LVDS */
259 tempax |= SupportLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200260
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300261 if (resinfo > 0x08)
262 return 0; /* 1024x768 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200263
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300264 if (pVBInfo->LCDResInfo < Panel_1024x768) {
265 if (resinfo > 0x07)
266 return 0; /* 800x600 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200267
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300268 if (resinfo == 0x04)
269 return 0; /* 512x384 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530270 }
271 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200272
Aaro Koskinena39325d2012-11-04 21:14:53 +0200273 for (; XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID ==
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800274 tempbx; (*i)--) {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200275 infoflag = XGI330_RefIndex[RefreshRateTableIndex + (*i)].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800276 Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530277 if (infoflag & tempax)
278 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200279
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530280 if ((*i) == 0)
281 break;
282 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200283
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530284 for ((*i) = 0;; (*i)++) {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200285 infoflag = XGI330_RefIndex[RefreshRateTableIndex + (*i)].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800286 Ext_InfoFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +0200287 if (XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530288 != tempbx) {
289 return 0;
290 }
291
292 if (infoflag & tempax)
293 return 1;
294 }
295 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200296}
297
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200298static void XGI_SetSync(unsigned short RefreshRateTableIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530299 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200300{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530301 unsigned short sync, temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200302
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800303 /* di+0x00 */
Aaro Koskinena39325d2012-11-04 21:14:53 +0200304 sync = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag >> 8;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530305 sync &= 0xC0;
306 temp = 0x2F;
307 temp |= sync;
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200308 outb(temp, pVBInfo->P3c2); /* Set Misc(3c2) */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200309}
310
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200311static void XGI_SetCRT1Timing_H(struct vb_device_info *pVBInfo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530312 struct xgi_hw_device_info *HwDeviceExtension)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200313{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530314 unsigned char data, data1, pushax;
315 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200316
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800317 /* unlock cr0-7 */
318 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530319 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200320 xgifb_reg_set(pVBInfo->P3d4, 0x11, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200321
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200322 data = pVBInfo->TimingH.data[0];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200323 xgifb_reg_set(pVBInfo->P3d4, 0, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200324
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530325 for (i = 0x01; i <= 0x04; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200326 data = pVBInfo->TimingH.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200327 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 1), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530328 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200329
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530330 for (i = 0x05; i <= 0x06; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200331 data = pVBInfo->TimingH.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200332 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i + 6), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530333 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200334
Aaro Koskinen58839b02011-03-13 12:26:23 +0200335 j = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530336 j &= 0x1F;
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200337 data = pVBInfo->TimingH.data[7];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530338 data &= 0xE0;
339 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200340 xgifb_reg_set(pVBInfo->P3c4, 0x0e, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200341
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530342 if (HwDeviceExtension->jChipType >= XG20) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200343 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530344 data = data - 1;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200345 xgifb_reg_set(pVBInfo->P3d4, 0x04, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200346 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x05);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530347 data1 = data;
348 data1 &= 0xE0;
349 data &= 0x1F;
350 if (data == 0) {
351 pushax = data;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200352 data = (unsigned char) xgifb_reg_get(pVBInfo->P3c4,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530353 0x0c);
354 data &= 0xFB;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200355 xgifb_reg_set(pVBInfo->P3c4, 0x0c, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530356 data = pushax;
357 }
358 data = data - 1;
359 data |= data1;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200360 xgifb_reg_set(pVBInfo->P3d4, 0x05, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200361 data = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530362 data = data >> 5;
363 data = data + 3;
364 if (data > 7)
365 data = data - 7;
366 data = data << 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200367 xgifb_reg_and_or(pVBInfo->P3c4, 0x0e, ~0xE0, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530368 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200369}
370
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800371static void XGI_SetCRT1Timing_V(unsigned short ModeIdIndex,
372 unsigned short ModeNo,
373 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200374{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530375 unsigned char data;
376 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200377
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530378 for (i = 0x00; i <= 0x01; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200379 data = pVBInfo->TimingV.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200380 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 6), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530381 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200382
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530383 for (i = 0x02; i <= 0x03; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200384 data = pVBInfo->TimingV.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200385 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x0e), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530386 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200387
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530388 for (i = 0x04; i <= 0x05; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200389 data = pVBInfo->TimingV.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200390 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x11), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530391 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200392
Aaro Koskinen58839b02011-03-13 12:26:23 +0200393 j = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0a);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530394 j &= 0xC0;
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200395 data = pVBInfo->TimingV.data[6];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530396 data &= 0x3F;
397 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200398 xgifb_reg_set(pVBInfo->P3c4, 0x0a, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200399
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200400 data = pVBInfo->TimingV.data[6];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530401 data &= 0x80;
402 data = data >> 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200403
Aaro Koskinenb3979922012-11-04 21:14:52 +0200404 i = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530405 i &= DoubleScanMode;
406 if (i)
407 data |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200408
Aaro Koskinen58839b02011-03-13 12:26:23 +0200409 j = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x09);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530410 j &= 0x5F;
411 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200412 xgifb_reg_set(pVBInfo->P3d4, 0x09, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200413}
414
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200415static void XGI_SetCRT1CRTC(unsigned short ModeNo, unsigned short ModeIdIndex,
416 unsigned short RefreshRateTableIndex,
417 struct vb_device_info *pVBInfo,
418 struct xgi_hw_device_info *HwDeviceExtension)
419{
420 unsigned char index, data;
421 unsigned short i;
422
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800423 /* Get index */
Aaro Koskinena39325d2012-11-04 21:14:53 +0200424 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200425 index = index & IndexMask;
426
Aaro Koskinen58839b02011-03-13 12:26:23 +0200427 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200428 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200429 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200430
431 for (i = 0; i < 8; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200432 pVBInfo->TimingH.data[i]
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200433 = XGI_CRT1Table[index].CR[i];
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200434
435 for (i = 0; i < 7; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200436 pVBInfo->TimingV.data[i]
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200437 = XGI_CRT1Table[index].CR[i + 8];
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200438
439 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
440
441 XGI_SetCRT1Timing_V(ModeIdIndex, ModeNo, pVBInfo);
442
443 if (pVBInfo->ModeType > 0x03)
Aaro Koskinen8104e322011-03-13 12:26:22 +0200444 xgifb_reg_set(pVBInfo->P3d4, 0x14, 0x4F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200445}
446
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200447/* --------------------------------------------------------------------- */
448/* Function : XGI_SetXG21CRTC */
449/* Input : Stand or enhance CRTC table */
450/* Output : Fill CRT Hsync/Vsync to SR2E/SR2F/SR30/SR33/SR34/SR3F */
451/* Description : Set LCD timing */
452/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200453static void XGI_SetXG21CRTC(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530454 unsigned short RefreshRateTableIndex,
455 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200456{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300457 unsigned char index, Tempax, Tempbx, Tempcx, Tempdx;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530458 unsigned short Temp1, Temp2, Temp3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200459
Aaro Koskinena39325d2012-11-04 21:14:53 +0200460 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300461 /* Tempax: CR4 HRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200462 Tempax = XGI_CRT1Table[index].CR[3];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300463 Tempcx = Tempax; /* Tempcx: HRS */
464 /* SR2E[7:0]->HRS */
465 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200466
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200467 Tempdx = XGI_CRT1Table[index].CR[5]; /* SRB */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300468 Tempdx &= 0xC0; /* Tempdx[7:6]: SRB[7:6] */
469 Temp1 = Tempdx; /* Temp1[7:6]: HRS[9:8] */
470 Temp1 <<= 2; /* Temp1[9:8]: HRS[9:8] */
471 Temp1 |= Tempax; /* Temp1[9:0]: HRS[9:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800472
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200473 Tempax = XGI_CRT1Table[index].CR[4]; /* CR5 HRE */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300474 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200475
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200476 Tempbx = XGI_CRT1Table[index].CR[6]; /* SRC */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300477 Tempbx &= 0x04; /* Tempbx[2]: HRE[5] */
478 Tempbx <<= 3; /* Tempbx[5]: HRE[5] */
479 Tempax |= Tempbx; /* Tempax[5:0]: HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200480
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300481 Temp2 = Temp1 & 0x3C0; /* Temp2[9:6]: HRS[9:6] */
482 Temp2 |= Tempax; /* Temp2[9:0]: HRE[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200483
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300484 Tempcx &= 0x3F; /* Tempcx[5:0]: HRS[5:0] */
485 if (Tempax < Tempcx) /* HRE < HRS */
486 Temp2 |= 0x40; /* Temp2 + 0x40 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200487
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300488 Temp2 &= 0xFF;
489 Tempax = (unsigned char) Temp2; /* Tempax: HRE[7:0] */
490 Tempax <<= 2; /* Tempax[7:2]: HRE[5:0] */
491 Tempdx >>= 6; /* Tempdx[7:6]->[1:0] HRS[9:8] */
492 Tempax |= Tempdx; /* HRE[5:0]HRS[9:8] */
493 /* SR2F D[7:2]->HRE, D[1:0]->HRS */
494 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
495 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200496
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300497 /* CR10 VRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200498 Tempax = XGI_CRT1Table[index].CR[10];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300499 Tempbx = Tempax; /* Tempbx: VRS */
500 Tempax &= 0x01; /* Tempax[0]: VRS[0] */
501 xgifb_reg_or(pVBInfo->P3c4, 0x33, Tempax); /* SR33[0]->VRS[0] */
502 /* CR7[2][7] VRE */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200503 Tempax = XGI_CRT1Table[index].CR[9];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300504 Tempcx = Tempbx >> 1; /* Tempcx[6:0]: VRS[7:1] */
505 Tempdx = Tempax & 0x04; /* Tempdx[2]: CR7[2] */
506 Tempdx <<= 5; /* Tempdx[7]: VRS[8] */
507 Tempcx |= Tempdx; /* Tempcx[7:0]: VRS[8:1] */
508 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempcx); /* SR34[8:1]->VRS */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200509
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300510 Temp1 = Tempdx; /* Temp1[7]: Tempdx[7] */
511 Temp1 <<= 1; /* Temp1[8]: VRS[8] */
512 Temp1 |= Tempbx; /* Temp1[8:0]: VRS[8:0] */
513 Tempax &= 0x80;
514 Temp2 = Tempax << 2; /* Temp2[9]: VRS[9] */
515 Temp1 |= Temp2; /* Temp1[9:0]: VRS[9:0] */
516 /* Tempax: SRA */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200517 Tempax = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300518 Tempax &= 0x08; /* Tempax[3]: VRS[3] */
519 Temp2 = Tempax;
520 Temp2 <<= 7; /* Temp2[10]: VRS[10] */
521 Temp1 |= Temp2; /* Temp1[10:0]: VRS[10:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200522
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300523 /* Tempax: CR11 VRE */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200524 Tempax = XGI_CRT1Table[index].CR[11];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300525 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
526 /* Tempbx: SRA */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200527 Tempbx = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300528 Tempbx &= 0x20; /* Tempbx[5]: VRE[5] */
529 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
530 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
531 Temp2 = Temp1 & 0x7E0; /* Temp2[10:5]: VRS[10:5] */
532 Temp2 |= Tempax; /* Temp2[10:5]: VRE[10:5] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200533
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300534 Temp3 = Temp1 & 0x1F; /* Temp3[4:0]: VRS[4:0] */
535 if (Tempax < Temp3) /* VRE < VRS */
536 Temp2 |= 0x20; /* VRE + 0x20 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200537
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300538 Temp2 &= 0xFF;
539 Tempax = (unsigned char) Temp2; /* Tempax: VRE[7:0] */
540 Tempax <<= 2; /* Tempax[7:0]; VRE[5:0]00 */
541 Temp1 &= 0x600; /* Temp1[10:9]: VRS[10:9] */
542 Temp1 >>= 9; /* Temp1[1:0]: VRS[10:9] */
543 Tempbx = (unsigned char) Temp1;
544 Tempax |= Tempbx; /* Tempax[7:0]: VRE[5:0]VRS[10:9] */
545 Tempax &= 0x7F;
546 /* SR3F D[7:2]->VRE D[1:0]->VRS */
547 xgifb_reg_set(pVBInfo->P3c4, 0x3F, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200548}
549
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800550static void XGI_SetXG27CRTC(unsigned short ModeNo,
551 unsigned short ModeIdIndex,
552 unsigned short RefreshRateTableIndex,
553 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200554{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300555 unsigned short index, Tempax, Tempbx, Tempcx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200556
Aaro Koskinena39325d2012-11-04 21:14:53 +0200557 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300558 /* Tempax: CR4 HRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200559 Tempax = XGI_CRT1Table[index].CR[3];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300560 Tempbx = Tempax; /* Tempbx: HRS[7:0] */
561 /* SR2E[7:0]->HRS */
562 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200563
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300564 /* SR0B */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200565 Tempax = XGI_CRT1Table[index].CR[5];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300566 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
567 Tempbx |= (Tempax << 2); /* Tempbx: HRS[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200568
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200569 Tempax = XGI_CRT1Table[index].CR[4]; /* CR5 HRE */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300570 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
571 Tempcx = Tempax; /* Tempcx: HRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200572
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200573 Tempax = XGI_CRT1Table[index].CR[6]; /* SRC */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300574 Tempax &= 0x04; /* Tempax[2]: HRE[5] */
575 Tempax <<= 3; /* Tempax[5]: HRE[5] */
576 Tempcx |= Tempax; /* Tempcx[5:0]: HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200577
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300578 Tempbx = Tempbx & 0x3C0; /* Tempbx[9:6]: HRS[9:6] */
579 Tempbx |= Tempcx; /* Tempbx: HRS[9:6]HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200580
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300581 /* Tempax: CR4 HRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200582 Tempax = XGI_CRT1Table[index].CR[3];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300583 Tempax &= 0x3F; /* Tempax: HRS[5:0] */
584 if (Tempcx <= Tempax) /* HRE[5:0] < HRS[5:0] */
585 Tempbx += 0x40; /* Tempbx= Tempbx + 0x40 : HRE[9:0]*/
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200586
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200587 Tempax = XGI_CRT1Table[index].CR[5]; /* SR0B */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300588 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
589 Tempax >>= 6; /* Tempax[1:0]: HRS[9:8]*/
590 Tempax |= ((Tempbx << 2) & 0xFF); /* Tempax[7:2]: HRE[5:0] */
591 /* SR2F [7:2][1:0]: HRE[5:0]HRS[9:8] */
592 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
593 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200594
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300595 /* CR10 VRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200596 Tempax = XGI_CRT1Table[index].CR[10];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300597 /* SR34[7:0]->VRS[7:0] */
598 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200599
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300600 Tempcx = Tempax; /* Tempcx <= VRS[7:0] */
601 /* CR7[7][2] VRS[9][8] */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200602 Tempax = XGI_CRT1Table[index].CR[9];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300603 Tempbx = Tempax; /* Tempbx <= CR07[7:0] */
604 Tempax = Tempax & 0x04; /* Tempax[2]: CR7[2]: VRS[8] */
605 Tempax >>= 2; /* Tempax[0]: VRS[8] */
606 /* SR35[0]: VRS[8] */
607 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x01, Tempax);
608 Tempcx |= (Tempax << 8); /* Tempcx <= VRS[8:0] */
609 Tempcx |= ((Tempbx & 0x80) << 2); /* Tempcx <= VRS[9:0] */
610 /* Tempax: SR0A */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200611 Tempax = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300612 Tempax &= 0x08; /* SR0A[3] VRS[10] */
613 Tempcx |= (Tempax << 7); /* Tempcx <= VRS[10:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200614
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300615 /* Tempax: CR11 VRE */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200616 Tempax = XGI_CRT1Table[index].CR[11];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300617 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
618 /* Tempbx: SR0A */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200619 Tempbx = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300620 Tempbx &= 0x20; /* Tempbx[5]: SR0A[5]: VRE[4] */
621 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
622 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
623 Tempbx = Tempcx; /* Tempbx: VRS[10:0] */
624 Tempbx &= 0x7E0; /* Tempbx[10:5]: VRS[10:5] */
625 Tempbx |= Tempax; /* Tempbx: VRS[10:5]VRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200626
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300627 if (Tempbx <= Tempcx) /* VRE <= VRS */
628 Tempbx |= 0x20; /* VRE + 0x20 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200629
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300630 /* Tempax: Tempax[7:0]; VRE[5:0]00 */
631 Tempax = (Tempbx << 2) & 0xFF;
632 /* SR3F[7:2]:VRE[5:0] */
633 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC, Tempax);
634 Tempax = Tempcx >> 8;
635 /* SR35[2:0]:VRS[10:8] */
636 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200637}
638
Aaro Koskinena2d08cf2011-11-27 23:03:08 +0200639static void XGI_SetXG27FPBits(struct vb_device_info *pVBInfo)
640{
641 unsigned char temp;
642
643 /* D[1:0] 01: 18bit, 00: dual 12, 10: single 24 */
644 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
645 temp = (temp & 3) << 6;
646 /* SR06[7]0: dual 12/1: single 24 [6] 18bit Dither <= 0 h/w recommend */
647 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0xc0, temp & 0x80);
648 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: 24bits */
649 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
650
651}
652
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300653static void xgifb_set_lcd(int chip_id,
654 struct vb_device_info *pVBInfo,
655 unsigned short RefreshRateTableIndex,
656 unsigned short ModeNo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200657{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300658 unsigned short Data, Temp;
Bill Pemberton82d6eb52010-06-17 13:10:46 -0400659 unsigned short XGI_P3cc;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200660
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530661 XGI_P3cc = pVBInfo->P3cc;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200662
Aaro Koskinen8104e322011-03-13 12:26:22 +0200663 xgifb_reg_set(pVBInfo->P3d4, 0x2E, 0x00);
664 xgifb_reg_set(pVBInfo->P3d4, 0x2F, 0x00);
665 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x00);
666 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x00);
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300667
668 if (chip_id == XG27) {
669 Temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
670 if ((Temp & 0x03) == 0) { /* dual 12 */
671 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x13);
672 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x13);
673 }
674 }
675
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300676 if (chip_id == XG27) {
677 XGI_SetXG27FPBits(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530678 } else {
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300679 Temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
680 if (Temp & 0x01) {
681 /* 18 bits FP */
682 xgifb_reg_or(pVBInfo->P3c4, 0x06, 0x40);
683 xgifb_reg_or(pVBInfo->P3c4, 0x09, 0x40);
684 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530685 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200686
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +0200687 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x01); /* Negative blank polarity */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200688
Aaro Koskinendc505562011-03-13 12:26:26 +0200689 xgifb_reg_and(pVBInfo->P3c4, 0x30, ~0x20); /* Hsync polarity */
690 xgifb_reg_and(pVBInfo->P3c4, 0x35, ~0x80); /* Vsync polarity */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200691
Aaro Koskinena39325d2012-11-04 21:14:53 +0200692 Data = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300693 if (Data & 0x4000)
694 /* Hsync polarity */
695 xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20);
696 if (Data & 0x8000)
697 /* Vsync polarity */
698 xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200699}
700
701/* --------------------------------------------------------------------- */
702/* Function : XGI_UpdateXG21CRTC */
703/* Input : */
704/* Output : CRT1 CRTC */
705/* Description : Modify CRT1 Hsync/Vsync to fix LCD mode timing */
706/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800707static void XGI_UpdateXG21CRTC(unsigned short ModeNo,
708 struct vb_device_info *pVBInfo,
709 unsigned short RefreshRateTableIndex)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200710{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300711 int index = -1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200712
Aaro Koskinendc505562011-03-13 12:26:26 +0200713 xgifb_reg_and(pVBInfo->P3d4, 0x11, 0x7F); /* Unlock CR0~7 */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300714 if (ModeNo == 0x2E &&
Aaro Koskinena39325d2012-11-04 21:14:53 +0200715 (XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC ==
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300716 RES640x480x60))
717 index = 12;
Aaro Koskinena39325d2012-11-04 21:14:53 +0200718 else if (ModeNo == 0x2E && (XGI330_RefIndex[RefreshRateTableIndex].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800719 Ext_CRT1CRTC == RES640x480x72))
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300720 index = 13;
721 else if (ModeNo == 0x2F)
722 index = 14;
723 else if (ModeNo == 0x50)
724 index = 15;
725 else if (ModeNo == 0x59)
726 index = 16;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200727
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530728 if (index != -1) {
Aaro Koskinen8104e322011-03-13 12:26:22 +0200729 xgifb_reg_set(pVBInfo->P3d4, 0x02,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200730 XGI_UpdateCRT1Table[index].CR02);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200731 xgifb_reg_set(pVBInfo->P3d4, 0x03,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200732 XGI_UpdateCRT1Table[index].CR03);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200733 xgifb_reg_set(pVBInfo->P3d4, 0x15,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200734 XGI_UpdateCRT1Table[index].CR15);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200735 xgifb_reg_set(pVBInfo->P3d4, 0x16,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200736 XGI_UpdateCRT1Table[index].CR16);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530737 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200738}
739
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200740static void XGI_SetCRT1DE(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530741 unsigned short ModeNo, unsigned short ModeIdIndex,
742 unsigned short RefreshRateTableIndex,
743 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200744{
Bill Pemberton82d6eb52010-06-17 13:10:46 -0400745 unsigned short resindex, tempax, tempbx, tempcx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200746
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530747 unsigned char data;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200748
Aaro Koskinenb3979922012-11-04 21:14:52 +0200749 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200750
Aaro Koskinenb3979922012-11-04 21:14:52 +0200751 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300752 tempax = pVBInfo->ModeResInfo[resindex].HTotal;
753 tempbx = pVBInfo->ModeResInfo[resindex].VTotal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200754
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530755 if (modeflag & HalfDCLK)
756 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200757
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300758 if (modeflag & HalfDCLK)
759 tempax = tempax << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200760
Aaro Koskinena39325d2012-11-04 21:14:53 +0200761 temp = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200762
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300763 if (temp & InterlaceMode)
764 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200765
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300766 if (modeflag & DoubleScanMode)
767 tempbx = tempbx << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200768
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530769 tempcx = 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200770
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530771 tempax /= tempcx;
772 tempax -= 1;
773 tempbx -= 1;
774 tempcx = tempax;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200775 temp = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
776 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530777 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200778 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
779 xgifb_reg_set(pVBInfo->P3d4, 0x01, (unsigned short) (tempcx & 0xff));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200780 xgifb_reg_and_or(pVBInfo->P3d4, 0x0b, ~0x0c,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530781 (unsigned short) ((tempcx & 0x0ff00) >> 10));
Aaro Koskinen8104e322011-03-13 12:26:22 +0200782 xgifb_reg_set(pVBInfo->P3d4, 0x12, (unsigned short) (tempbx & 0xff));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530783 tempax = 0;
784 tempbx = tempbx >> 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200785
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530786 if (tempbx & 0x01)
787 tempax |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200788
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530789 if (tempbx & 0x02)
790 tempax |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200791
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200792 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x42, tempax);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200793 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x07);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530794 data &= 0xFF;
795 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200796
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530797 if (tempbx & 0x04)
798 tempax |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200799
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200800 xgifb_reg_and_or(pVBInfo->P3d4, 0x0a, ~0x02, tempax);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200801 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200802}
803
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800804static void XGI_SetCRT1Offset(unsigned short ModeNo,
805 unsigned short ModeIdIndex,
806 unsigned short RefreshRateTableIndex,
807 struct xgi_hw_device_info *HwDeviceExtension,
808 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200809{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530810 unsigned short temp, ah, al, temp2, i, DisplayUnit;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200811
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530812 /* GetOffset */
Aaro Koskinenb3979922012-11-04 21:14:52 +0200813 temp = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeInfo;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530814 temp = temp >> 8;
815 temp = pVBInfo->ScreenOffset[temp];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200816
Aaro Koskinena39325d2012-11-04 21:14:53 +0200817 temp2 = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530818 temp2 &= InterlaceMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200819
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530820 if (temp2)
821 temp = temp << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200822
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530823 temp2 = pVBInfo->ModeType - ModeEGA;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200824
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530825 switch (temp2) {
826 case 0:
827 temp2 = 1;
828 break;
829 case 1:
830 temp2 = 2;
831 break;
832 case 2:
833 temp2 = 4;
834 break;
835 case 3:
836 temp2 = 4;
837 break;
838 case 4:
839 temp2 = 6;
840 break;
841 case 5:
842 temp2 = 8;
843 break;
844 default:
845 break;
846 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200847
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530848 if ((ModeNo >= 0x26) && (ModeNo <= 0x28))
849 temp = temp * temp2 + temp2 / 2;
850 else
851 temp *= temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200852
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530853 /* SetOffset */
854 DisplayUnit = temp;
855 temp2 = temp;
856 temp = temp >> 8; /* ah */
857 temp &= 0x0F;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200858 i = xgifb_reg_get(pVBInfo->P3c4, 0x0E);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530859 i &= 0xF0;
860 i |= temp;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200861 xgifb_reg_set(pVBInfo->P3c4, 0x0E, i);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200862
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530863 temp = (unsigned char) temp2;
864 temp &= 0xFF; /* al */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200865 xgifb_reg_set(pVBInfo->P3d4, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200866
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530867 /* SetDisplayUnit */
Aaro Koskinena39325d2012-11-04 21:14:53 +0200868 temp2 = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530869 temp2 &= InterlaceMode;
870 if (temp2)
871 DisplayUnit >>= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200872
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530873 DisplayUnit = DisplayUnit << 5;
874 ah = (DisplayUnit & 0xff00) >> 8;
875 al = DisplayUnit & 0x00ff;
876 if (al == 0)
877 ah += 1;
878 else
879 ah += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200880
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530881 if (HwDeviceExtension->jChipType >= XG20)
882 if ((ModeNo == 0x4A) | (ModeNo == 0x49))
883 ah -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200884
Aaro Koskinen8104e322011-03-13 12:26:22 +0200885 xgifb_reg_set(pVBInfo->P3c4, 0x10, ah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200886}
887
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200888static unsigned short XGI_GetVCLK2Ptr(unsigned short ModeNo,
889 unsigned short ModeIdIndex,
890 unsigned short RefreshRateTableIndex,
891 struct xgi_hw_device_info *HwDeviceExtension,
892 struct vb_device_info *pVBInfo)
893{
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200894 unsigned short CRT2Index, VCLKIndex;
895 unsigned short modeflag, resinfo;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200896
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300897 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +0200898 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
899 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinena39325d2012-11-04 21:14:53 +0200900 CRT2Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200901
902 if (pVBInfo->IF_DEF_LVDS == 0) {
903 CRT2Index = CRT2Index >> 6; /* for LCD */
Miguel Gómez3bcc2462012-07-06 12:40:53 +0200904 if (pVBInfo->VBInfo &
905 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) { /*301b*/
Peter Huewe255aabd2012-02-09 21:11:44 +0100906 if (pVBInfo->LCDResInfo != Panel_1024x768)
Miguel Gómez3bcc2462012-07-06 12:40:53 +0200907 /* LCDXlat2VCLK */
908 VCLKIndex = VCLK108_2_315 + 5;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200909 else
Peter Huewef477d3e2012-06-14 00:21:47 +0200910 VCLKIndex = VCLK65_315 + 2; /* LCDXlat1VCLK */
Peter Huewe599801f2012-02-09 21:11:45 +0100911 } else if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +0200912 if (pVBInfo->SetFlag & RPLLDIV2XO)
Peter Huewe95072592012-06-14 00:21:48 +0200913 VCLKIndex = TVCLKBASE_315_25 + HiTVVCLKDIV2;
Miguel Gómez3bcc2462012-07-06 12:40:53 +0200914 else
Peter Huewe95072592012-06-14 00:21:48 +0200915 VCLKIndex = TVCLKBASE_315_25 + HiTVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200916
Aaro Koskinen798b4da2011-11-27 23:03:20 +0200917 if (pVBInfo->SetFlag & TVSimuMode) {
918 if (modeflag & Charx8Dot) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +0200919 VCLKIndex = TVCLKBASE_315_25 +
920 HiTVSimuVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200921 } else {
Miguel Gómez3bcc2462012-07-06 12:40:53 +0200922 VCLKIndex = TVCLKBASE_315_25 +
923 HiTVTextVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200924 }
Aaro Koskinen798b4da2011-11-27 23:03:20 +0200925 }
926
927 /* 301lv */
Aaro Koskinen31fb40f2012-09-11 00:15:15 +0300928 if (pVBInfo->VBType & VB_SIS301LV) {
929 if (pVBInfo->SetFlag & RPLLDIV2XO)
Aaro Koskinen798b4da2011-11-27 23:03:20 +0200930 VCLKIndex = YPbPr525iVCLK_2;
931 else
932 VCLKIndex = YPbPr525iVCLK;
933 }
934 } else if (pVBInfo->VBInfo & SetCRT2ToTV) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +0200935 if (pVBInfo->SetFlag & RPLLDIV2XO)
Peter Huewe95072592012-06-14 00:21:48 +0200936 VCLKIndex = TVCLKBASE_315_25 + TVVCLKDIV2;
Miguel Gómez3bcc2462012-07-06 12:40:53 +0200937 else
Peter Huewe95072592012-06-14 00:21:48 +0200938 VCLKIndex = TVCLKBASE_315_25 + TVVCLK;
Aaro Koskinen798b4da2011-11-27 23:03:20 +0200939 } else { /* for CRT2 */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300940 /* di+Ext_CRTVCLK */
Aaro Koskinena39325d2012-11-04 21:14:53 +0200941 VCLKIndex = XGI330_RefIndex[RefreshRateTableIndex].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800942 Ext_CRTVCLK;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300943 VCLKIndex &= IndexMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200944 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300945 } else if ((pVBInfo->LCDResInfo == Panel_800x600) ||
946 (pVBInfo->LCDResInfo == Panel_320x480)) { /* LVDS */
947 VCLKIndex = VCLK40; /* LVDSXlat1VCLK */
948 } else {
949 VCLKIndex = VCLK65_315 + 2; /* LVDSXlat2VCLK, LVDSXlat3VCLK */
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200950 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200951
952 return VCLKIndex;
953}
954
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800955static void XGI_SetCRT1VCLK(unsigned short ModeNo,
956 unsigned short ModeIdIndex,
957 struct xgi_hw_device_info *HwDeviceExtension,
958 unsigned short RefreshRateTableIndex,
959 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200960{
Bill Pemberton108afbf2010-06-17 13:10:47 -0400961 unsigned char index, data;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530962 unsigned short vclkindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200963
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530964 if (pVBInfo->IF_DEF_LVDS == 1) {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200965 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200966 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200967 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
968 xgifb_reg_set(pVBInfo->P3c4, 0x2B,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530969 pVBInfo->VCLKData[index].SR2B);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200970 xgifb_reg_set(pVBInfo->P3c4, 0x2C,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530971 pVBInfo->VCLKData[index].SR2C);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200972 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Peter Huewe6896b942012-02-09 21:11:46 +0100973 } else if ((pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
974 | VB_SIS302LV | VB_XGI301C)) && (pVBInfo->VBInfo
Peter Huewea3d675c2012-02-09 21:11:47 +0100975 & XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530976 vclkindex = XGI_GetVCLK2Ptr(ModeNo, ModeIdIndex,
977 RefreshRateTableIndex, HwDeviceExtension,
978 pVBInfo);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200979 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200980 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530981 data = pVBInfo->VBVCLKData[vclkindex].Part4_A;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200982 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530983 data = pVBInfo->VBVCLKData[vclkindex].Part4_B;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200984 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
985 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530986 } else {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200987 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200988 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200989 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
990 xgifb_reg_set(pVBInfo->P3c4, 0x2B,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530991 pVBInfo->VCLKData[index].SR2B);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200992 xgifb_reg_set(pVBInfo->P3c4, 0x2C,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530993 pVBInfo->VCLKData[index].SR2C);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200994 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530995 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200996
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530997 if (HwDeviceExtension->jChipType >= XG20) {
Aaro Koskinenb3979922012-11-04 21:14:52 +0200998 if (XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag &
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800999 HalfDCLK) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001000 data = xgifb_reg_get(pVBInfo->P3c4, 0x2B);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001001 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +02001002 data = xgifb_reg_get(pVBInfo->P3c4, 0x2C);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301003 index = data;
1004 index &= 0xE0;
1005 data &= 0x1F;
1006 data = data << 1;
1007 data += 1;
1008 data |= index;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001009 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301010 }
1011 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001012}
1013
Aaro Koskinene85f2032011-11-27 23:03:07 +02001014static void XGI_SetXG21FPBits(struct vb_device_info *pVBInfo)
1015{
1016 unsigned char temp;
1017
1018 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37); /* D[0] 1: 18bit */
1019 temp = (temp & 1) << 6;
1020 /* SR06[6] 18bit Dither */
1021 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x40, temp);
1022 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: dual 12bits */
1023 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
1024
1025}
1026
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001027static void XGI_SetCRT1FIFO(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301028 struct xgi_hw_device_info *HwDeviceExtension,
1029 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001030{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301031 unsigned short data;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001032
Aaro Koskinen58839b02011-03-13 12:26:23 +02001033 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301034 data &= 0xfe;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001035 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data); /* diable auto-threshold */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001036
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001037 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0x34);
1038 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
1039 data &= 0xC0;
1040 xgifb_reg_set(pVBInfo->P3c4, 0x09, data | 0x30);
1041 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
1042 data |= 0x01;
1043 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001044
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301045 if (HwDeviceExtension->jChipType == XG21)
1046 XGI_SetXG21FPBits(pVBInfo); /* Fix SR9[7:6] can't read back */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001047}
1048
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001049static void XGI_SetVCLKState(struct xgi_hw_device_info *HwDeviceExtension,
1050 unsigned short ModeNo, unsigned short RefreshRateTableIndex,
1051 struct vb_device_info *pVBInfo)
1052{
1053 unsigned short data, data2 = 0;
1054 short VCLK;
1055
1056 unsigned char index;
1057
Aaro Koskinena39325d2012-11-04 21:14:53 +02001058 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001059 index &= IndexMask;
1060 VCLK = pVBInfo->VCLKData[index].CLOCK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001061
Aaro Koskinen58839b02011-03-13 12:26:23 +02001062 data = xgifb_reg_get(pVBInfo->P3c4, 0x32);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001063 data &= 0xf3;
1064 if (VCLK >= 200)
1065 data |= 0x0c; /* VCLK > 200 */
1066
1067 if (HwDeviceExtension->jChipType >= XG20)
1068 data &= ~0x04; /* 2 pixel mode */
1069
Aaro Koskinen8104e322011-03-13 12:26:22 +02001070 xgifb_reg_set(pVBInfo->P3c4, 0x32, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001071
1072 if (HwDeviceExtension->jChipType < XG20) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001073 data = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001074 data &= 0xE7;
1075 if (VCLK < 200)
1076 data |= 0x10;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001077 xgifb_reg_set(pVBInfo->P3c4, 0x1F, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001078 }
1079
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001080 data2 = 0x00;
1081
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001082 xgifb_reg_and_or(pVBInfo->P3c4, 0x07, 0xFC, data2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001083 if (HwDeviceExtension->jChipType >= XG27)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001084 xgifb_reg_and_or(pVBInfo->P3c4, 0x40, 0xFC, data2 & 0x03);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001085
1086}
1087
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001088static void XGI_SetCRT1ModeRegs(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301089 unsigned short ModeNo, unsigned short ModeIdIndex,
1090 unsigned short RefreshRateTableIndex,
1091 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001092{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301093 unsigned short data, data2, data3, infoflag = 0, modeflag, resindex,
1094 xres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001095
Aaro Koskinenb3979922012-11-04 21:14:52 +02001096 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02001097 infoflag = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001098
Aaro Koskinen58839b02011-03-13 12:26:23 +02001099 if (xgifb_reg_get(pVBInfo->P3d4, 0x31) & 0x01)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001100 xgifb_reg_and_or(pVBInfo->P3c4, 0x1F, 0x3F, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001101
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001102 data = infoflag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301103 data2 = 0;
Aaro Koskinen969f7f32012-04-07 01:14:03 +03001104 data2 |= 0x02;
1105 data3 = pVBInfo->ModeType - ModeVGA;
1106 data3 = data3 << 2;
1107 data2 |= data3;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301108 data &= InterlaceMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001109
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301110 if (data)
1111 data2 |= 0x20;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001112
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001113 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x3F, data2);
Aaro Koskinenb3979922012-11-04 21:14:52 +02001114 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001115 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001116
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301117 data = 0x0000;
1118 if (infoflag & InterlaceMode) {
1119 if (xres == 1024)
1120 data = 0x0035;
1121 else if (xres == 1280)
1122 data = 0x0048;
1123 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001124
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301125 data2 = data & 0x00FF;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001126 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFF, data2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301127 data2 = (data & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001128 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFC, data2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001129
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301130 if (modeflag & HalfDCLK)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001131 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xF7, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001132
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301133 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001134
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301135 if (modeflag & LineCompareOff)
1136 data2 |= 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001137
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001138 xgifb_reg_and_or(pVBInfo->P3c4, 0x0F, ~0x48, data2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301139 data = 0x60;
Aaro Koskinen969f7f32012-04-07 01:14:03 +03001140 data = data ^ 0x60;
1141 data = data ^ 0xA0;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001142 xgifb_reg_and_or(pVBInfo->P3c4, 0x21, 0x1F, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001143
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301144 XGI_SetVCLKState(HwDeviceExtension, ModeNo, RefreshRateTableIndex,
1145 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001146
Aaro Koskinen58839b02011-03-13 12:26:23 +02001147 data = xgifb_reg_get(pVBInfo->P3d4, 0x31);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001148
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301149 if (HwDeviceExtension->jChipType == XG27) {
1150 if (data & 0x40)
1151 data = 0x2c;
1152 else
1153 data = 0x6c;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001154 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02001155 xgifb_reg_or(pVBInfo->P3d4, 0x51, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301156 } else if (HwDeviceExtension->jChipType >= XG20) {
1157 if (data & 0x40)
1158 data = 0x33;
1159 else
1160 data = 0x73;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001161 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
1162 xgifb_reg_set(pVBInfo->P3d4, 0x51, 0x02);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301163 } else {
1164 if (data & 0x40)
1165 data = 0x2c;
1166 else
1167 data = 0x6c;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001168 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301169 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001170
1171}
1172
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001173static void XGI_WriteDAC(unsigned short dl,
1174 unsigned short ah,
1175 unsigned short al,
1176 unsigned short dh,
1177 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001178{
1179 unsigned short temp, bh, bl;
1180
1181 bh = ah;
1182 bl = al;
1183
1184 if (dl != 0) {
1185 temp = bh;
1186 bh = dh;
1187 dh = temp;
1188 if (dl == 1) {
1189 temp = bl;
1190 bl = dh;
1191 dh = temp;
1192 } else {
1193 temp = bl;
1194 bl = bh;
1195 bh = temp;
1196 }
1197 }
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001198 outb((unsigned short) dh, pVBInfo->P3c9);
1199 outb((unsigned short) bh, pVBInfo->P3c9);
1200 outb((unsigned short) bl, pVBInfo->P3c9);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001201}
1202
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001203static void XGI_LoadDAC(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301204 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001205{
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001206 unsigned short data, data2, i, k, m, n, o, si, di, bx, dl, al, ah, dh;
1207 const unsigned short *table = XGINew_VGA_DAC;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001208
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001209 outb(0xFF, pVBInfo->P3c6);
1210 outb(0x00, pVBInfo->P3c8);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001211
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001212 for (i = 0; i < 16; i++) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301213 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001214
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301215 for (k = 0; k < 3; k++) {
1216 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001217
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301218 if (data & 0x01)
1219 data2 = 0x2A;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001220
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301221 if (data & 0x02)
1222 data2 += 0x15;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001223
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001224 outb(data2, pVBInfo->P3c9);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301225 data = data >> 2;
1226 }
1227 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001228
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001229 for (i = 16; i < 32; i++) {
1230 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001231
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001232 for (k = 0; k < 3; k++)
1233 outb(data, pVBInfo->P3c9);
1234 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001235
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001236 si = 32;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001237
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001238 for (m = 0; m < 9; m++) {
1239 di = si;
1240 bx = si + 0x04;
1241 dl = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001242
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001243 for (n = 0; n < 3; n++) {
1244 for (o = 0; o < 5; o++) {
1245 dh = table[si];
1246 ah = table[di];
1247 al = table[bx];
1248 si++;
1249 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301250 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001251
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001252 si -= 2;
1253
1254 for (o = 0; o < 3; o++) {
1255 dh = table[bx];
1256 ah = table[di];
1257 al = table[si];
1258 si--;
1259 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1260 }
1261
1262 dl++;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301263 }
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001264
1265 si += 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301266 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001267}
1268
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001269static void XGI_GetLVDSResInfo(unsigned short ModeNo,
1270 unsigned short ModeIdIndex,
1271 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001272{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301273 unsigned short resindex, xres, yres, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001274
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001275 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02001276 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001277
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001278 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02001279 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001280
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001281 xres = pVBInfo->ModeResInfo[resindex].HTotal;
1282 yres = pVBInfo->ModeResInfo[resindex].VTotal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001283
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001284 if (modeflag & HalfDCLK)
1285 xres = xres << 1;
1286
1287 if (modeflag & DoubleScanMode)
1288 yres = yres << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001289
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301290 if (xres == 720)
1291 xres = 640;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001292
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301293 pVBInfo->VGAHDE = xres;
1294 pVBInfo->HDE = xres;
1295 pVBInfo->VGAVDE = yres;
1296 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001297}
1298
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001299static void const *XGI_GetLcdPtr(struct XGI330_LCDDataTablStruct const *table,
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001300 unsigned short ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001301 unsigned short ModeIdIndex,
1302 unsigned short RefreshRateTableIndex,
1303 struct vb_device_info *pVBInfo)
1304{
Aaro Koskinen6c27b372012-11-04 21:14:45 +02001305 unsigned short i, tempdx, tempbx, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001306
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001307 tempbx = 0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001308
Aaro Koskinenb3979922012-11-04 21:14:52 +02001309 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001310
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001311 i = 0;
1312
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001313 while (table[i].PANELID != 0xff) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001314 tempdx = pVBInfo->LCDResInfo;
1315 if (tempbx & 0x0080) { /* OEMUtil */
1316 tempbx &= (~0x0080);
1317 tempdx = pVBInfo->LCDTypeInfo;
1318 }
1319
1320 if (pVBInfo->LCDInfo & EnableScalingLCD)
1321 tempdx &= (~PanelResInfo);
1322
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001323 if (table[i].PANELID == tempdx) {
1324 tempbx = table[i].MASK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001325 tempdx = pVBInfo->LCDInfo;
1326
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001327 if (modeflag & HalfDCLK)
1328 tempdx |= SetLCDLowResolution;
1329
1330 tempbx &= tempdx;
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001331 if (tempbx == table[i].CAP)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001332 break;
1333 }
1334 i++;
1335 }
1336
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001337 return table[i].DATAPTR;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001338}
1339
Aaro Koskinen24572542012-09-11 00:15:21 +03001340static struct SiS_TVData const *XGI_GetTVPtr(unsigned short ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001341 unsigned short ModeIdIndex,
1342 unsigned short RefreshRateTableIndex,
1343 struct vb_device_info *pVBInfo)
1344{
Aaro Koskinen56d276c2012-09-11 00:15:19 +03001345 unsigned short i, tempdx, tempal, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001346
Aaro Koskinenb3979922012-11-04 21:14:52 +02001347 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02001348 tempal = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001349 tempal = tempal & 0x3f;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001350 tempdx = pVBInfo->TVInfo;
1351
1352 if (pVBInfo->VBInfo & SetInSlaveMode)
1353 tempdx = tempdx | SetTVLockMode;
1354
1355 if (modeflag & HalfDCLK)
1356 tempdx = tempdx | SetTVLowResolution;
1357
1358 i = 0;
1359
Aaro Koskinen6265ee42012-09-11 00:15:20 +03001360 while (XGI_TVDataTable[i].MASK != 0xffff) {
1361 if ((tempdx & XGI_TVDataTable[i].MASK) ==
1362 XGI_TVDataTable[i].CAP)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001363 break;
1364 i++;
1365 }
1366
Aaro Koskinen18ba8662012-09-11 00:15:22 +03001367 return &XGI_TVDataTable[i].DATAPTR[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001368}
1369
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001370static void XGI_GetLVDSData(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301371 unsigned short RefreshRateTableIndex,
1372 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001373{
Aaro Koskinen6008f872012-11-04 21:14:49 +02001374 struct SiS_LVDSData const *LCDPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001375
Aaro Koskinen6008f872012-11-04 21:14:49 +02001376 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
1377 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001378
Aaro Koskinen6008f872012-11-04 21:14:49 +02001379 LCDPtr = XGI_GetLcdPtr(XGI_EPLLCDDataPtr, ModeNo, ModeIdIndex,
1380 RefreshRateTableIndex, pVBInfo);
1381 pVBInfo->VGAHT = LCDPtr->VGAHT;
1382 pVBInfo->VGAVT = LCDPtr->VGAVT;
1383 pVBInfo->HT = LCDPtr->LCDHT;
1384 pVBInfo->VT = LCDPtr->LCDVT;
1385
1386 if (pVBInfo->LCDInfo & (SetLCDtoNonExpanding | EnableScalingLCD))
1387 return;
1388
1389 if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
1390 (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
1391 pVBInfo->HDE = 1024;
1392 pVBInfo->VDE = 768;
1393 } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
1394 (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
1395 pVBInfo->HDE = 1280;
1396 pVBInfo->VDE = 1024;
1397 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
1398 pVBInfo->HDE = 1400;
1399 pVBInfo->VDE = 1050;
1400 } else {
1401 pVBInfo->HDE = 1600;
1402 pVBInfo->VDE = 1200;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301403 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001404}
1405
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001406static void XGI_ModCRT1Regs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301407 unsigned short RefreshRateTableIndex,
1408 struct xgi_hw_device_info *HwDeviceExtension,
1409 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001410{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301411 unsigned char index;
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001412 unsigned short i;
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001413 struct XGI_LVDSCRT1HDataStruct const *LCDPtr = NULL;
1414 struct XGI_LVDSCRT1VDataStruct const *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001415
Aaro Koskinena39325d2012-11-04 21:14:53 +02001416 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301417 index = index & IndexMask;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001418
Peter Huewea3d675c2012-02-09 21:11:47 +01001419 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001420 LCDPtr = XGI_GetLcdPtr(xgifb_epllcd_crt1_h, ModeNo, ModeIdIndex,
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +03001421 RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001422
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001423 for (i = 0; i < 8; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +02001424 pVBInfo->TimingH.data[i] = LCDPtr[0].Reg[i];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301425 }
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001426
1427 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
1428
Peter Huewea3d675c2012-02-09 21:11:47 +01001429 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001430 LCDPtr1 = XGI_GetLcdPtr(xgifb_epllcd_crt1_v, ModeNo,
1431 ModeIdIndex, RefreshRateTableIndex,
1432 pVBInfo);
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001433 for (i = 0; i < 7; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +02001434 pVBInfo->TimingV.data[i] = LCDPtr1[0].Reg[i];
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001435 }
1436
1437 XGI_SetCRT1Timing_V(ModeIdIndex, ModeNo, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001438}
1439
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001440static unsigned short XGI_GetLCDCapPtr(struct vb_device_info *pVBInfo)
1441{
1442 unsigned char tempal, tempah, tempbl, i;
1443
Aaro Koskinen58839b02011-03-13 12:26:23 +02001444 tempah = xgifb_reg_get(pVBInfo->P3d4, 0x36);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001445 tempal = tempah & 0x0F;
1446 tempah = tempah & 0xF0;
1447 i = 0;
1448 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1449
1450 while (tempbl != 0xFF) {
1451 if (tempbl & 0x80) { /* OEMUtil */
1452 tempal = tempah;
1453 tempbl = tempbl & ~(0x80);
1454 }
1455
1456 if (tempal == tempbl)
1457 break;
1458
1459 i++;
1460
1461 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1462 }
1463
1464 return i;
1465}
1466
1467static unsigned short XGI_GetLCDCapPtr1(struct vb_device_info *pVBInfo)
1468{
1469 unsigned short tempah, tempal, tempbl, i;
1470
1471 tempal = pVBInfo->LCDResInfo;
1472 tempah = pVBInfo->LCDTypeInfo;
1473
1474 i = 0;
1475 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1476
1477 while (tempbl != 0xFF) {
1478 if ((tempbl & 0x80) && (tempbl != 0x80)) {
1479 tempal = tempah;
1480 tempbl &= ~0x80;
1481 }
1482
1483 if (tempal == tempbl)
1484 break;
1485
1486 i++;
1487 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1488 }
1489
1490 if (tempbl == 0xFF) {
Peter Huewe255aabd2012-02-09 21:11:44 +01001491 pVBInfo->LCDResInfo = Panel_1024x768;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001492 pVBInfo->LCDTypeInfo = 0;
1493 i = 0;
1494 }
1495
1496 return i;
1497}
1498
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001499static void XGI_GetLCDSync(unsigned short *HSyncWidth,
1500 unsigned short *VSyncWidth,
1501 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001502{
1503 unsigned short Index;
1504
1505 Index = XGI_GetLCDCapPtr(pVBInfo);
1506 *HSyncWidth = pVBInfo->LCDCapList[Index].LCD_HSyncWidth;
1507 *VSyncWidth = pVBInfo->LCDCapList[Index].LCD_VSyncWidth;
1508
1509 return;
1510}
1511
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001512static void XGI_SetLVDSRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301513 unsigned short RefreshRateTableIndex,
1514 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001515{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301516 unsigned short tempbx, tempax, tempcx, tempdx, push1, push2, modeflag;
1517 unsigned long temp, temp1, temp2, temp3, push3;
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001518 struct XGI_LCDDesStruct const *LCDPtr = NULL;
1519 struct XGI330_LCDDataDesStruct2 const *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001520
Aaro Koskinenb3979922012-11-04 21:14:52 +02001521 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinen66cface2011-08-31 21:46:13 +03001522 if (pVBInfo->LCDInfo & EnableScalingLCD)
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001523 LCDPtr1 = XGI_GetLcdPtr(XGI_EPLLCDDesDataPtr, ModeNo,
1524 ModeIdIndex, RefreshRateTableIndex,
1525 pVBInfo);
Aaro Koskinen66cface2011-08-31 21:46:13 +03001526 else
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001527 LCDPtr = XGI_GetLcdPtr(XGI_EPLLCDDesDataPtr, ModeNo,
1528 ModeIdIndex, RefreshRateTableIndex,
1529 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001530
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001531 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
1532 push1 = tempbx;
1533 push2 = tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001534
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001535 /* GetLCDResInfo */
Peter Huewe255aabd2012-02-09 21:11:44 +01001536 if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
1537 (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001538 tempax = 1024;
1539 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01001540 } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
1541 (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001542 tempax = 1280;
1543 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01001544 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001545 tempax = 1400;
1546 tempbx = 1050;
1547 } else {
1548 tempax = 1600;
1549 tempbx = 1200;
1550 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001551
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001552 if (pVBInfo->LCDInfo & SetLCDtoNonExpanding) {
1553 pVBInfo->HDE = tempax;
1554 pVBInfo->VDE = tempbx;
1555 pVBInfo->VGAHDE = tempax;
1556 pVBInfo->VGAVDE = tempbx;
1557 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001558
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001559 tempax = pVBInfo->HT;
1560
1561 if (pVBInfo->LCDInfo & EnableScalingLCD)
1562 tempbx = LCDPtr1->LCDHDES;
1563 else
1564 tempbx = LCDPtr->LCDHDES;
1565
1566 tempcx = pVBInfo->HDE;
1567 tempbx = tempbx & 0x0fff;
1568 tempcx += tempbx;
1569
1570 if (tempcx >= tempax)
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001571 tempcx -= tempax;
1572
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001573 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, tempbx & 0x07);
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001574
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001575 tempcx = tempcx >> 3;
1576 tempbx = tempbx >> 3;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001577
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001578 xgifb_reg_set(pVBInfo->Part1Port, 0x16,
1579 (unsigned short) (tempbx & 0xff));
1580 xgifb_reg_set(pVBInfo->Part1Port, 0x17,
1581 (unsigned short) (tempcx & 0xff));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001582
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001583 tempax = pVBInfo->HT;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001584
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001585 if (pVBInfo->LCDInfo & EnableScalingLCD)
1586 tempbx = LCDPtr1->LCDHRS;
1587 else
1588 tempbx = LCDPtr->LCDHRS;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001589
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001590 tempcx = push2;
1591
1592 if (pVBInfo->LCDInfo & EnableScalingLCD)
1593 tempcx = LCDPtr1->LCDHSync;
1594
1595 tempcx += tempbx;
1596
1597 if (tempcx >= tempax)
1598 tempcx -= tempax;
1599
1600 tempax = tempbx & 0x07;
1601 tempax = tempax >> 5;
1602 tempcx = tempcx >> 3;
1603 tempbx = tempbx >> 3;
1604
1605 tempcx &= 0x1f;
1606 tempax |= tempcx;
1607
1608 xgifb_reg_set(pVBInfo->Part1Port, 0x15, tempax);
1609 xgifb_reg_set(pVBInfo->Part1Port, 0x14,
1610 (unsigned short) (tempbx & 0xff));
1611
1612 tempax = pVBInfo->VT;
1613 if (pVBInfo->LCDInfo & EnableScalingLCD)
1614 tempbx = LCDPtr1->LCDVDES;
1615 else
1616 tempbx = LCDPtr->LCDVDES;
1617 tempcx = pVBInfo->VDE;
1618
1619 tempbx = tempbx & 0x0fff;
1620 tempcx += tempbx;
1621 if (tempcx >= tempax)
1622 tempcx -= tempax;
1623
1624 xgifb_reg_set(pVBInfo->Part1Port, 0x1b,
1625 (unsigned short) (tempbx & 0xff));
1626 xgifb_reg_set(pVBInfo->Part1Port, 0x1c,
1627 (unsigned short) (tempcx & 0xff));
1628
1629 tempbx = (tempbx >> 8) & 0x07;
1630 tempcx = (tempcx >> 8) & 0x07;
1631
1632 xgifb_reg_set(pVBInfo->Part1Port, 0x1d,
1633 (unsigned short) ((tempcx << 3)
1634 | tempbx));
1635
1636 tempax = pVBInfo->VT;
1637 if (pVBInfo->LCDInfo & EnableScalingLCD)
1638 tempbx = LCDPtr1->LCDVRS;
1639 else
1640 tempbx = LCDPtr->LCDVRS;
1641
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001642 tempcx = push1;
1643
1644 if (pVBInfo->LCDInfo & EnableScalingLCD)
1645 tempcx = LCDPtr1->LCDVSync;
1646
1647 tempcx += tempbx;
1648 if (tempcx >= tempax)
1649 tempcx -= tempax;
1650
1651 xgifb_reg_set(pVBInfo->Part1Port, 0x18,
1652 (unsigned short) (tempbx & 0xff));
1653 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, ~0x0f,
1654 (unsigned short) (tempcx & 0x0f));
1655
1656 tempax = ((tempbx >> 8) & 0x07) << 3;
1657
1658 tempbx = pVBInfo->VGAVDE;
1659 if (tempbx != pVBInfo->VDE)
1660 tempax |= 0x40;
1661
Peter Huewea3d675c2012-02-09 21:11:47 +01001662 if (pVBInfo->LCDInfo & XGI_EnableLVDSDDA)
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001663 tempax |= 0x40;
1664
1665 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1a, 0x07,
1666 tempax);
1667
1668 tempcx = pVBInfo->VGAVT;
1669 tempbx = pVBInfo->VDE;
1670 tempax = pVBInfo->VGAVDE;
1671 tempcx -= tempax;
1672
1673 temp = tempax; /* 0430 ylshieh */
1674 temp1 = (temp << 18) / tempbx;
1675
1676 tempdx = (unsigned short) ((temp << 18) % tempbx);
1677
1678 if (tempdx != 0)
1679 temp1 += 1;
1680
1681 temp2 = temp1;
1682 push3 = temp2;
1683
1684 xgifb_reg_set(pVBInfo->Part1Port, 0x37,
1685 (unsigned short) (temp2 & 0xff));
1686 xgifb_reg_set(pVBInfo->Part1Port, 0x36,
1687 (unsigned short) ((temp2 >> 8) & 0xff));
1688
1689 tempbx = (unsigned short) (temp2 >> 16);
1690 tempax = tempbx & 0x03;
1691
1692 tempbx = pVBInfo->VGAVDE;
1693 if (tempbx == pVBInfo->VDE)
1694 tempax |= 0x04;
1695
1696 xgifb_reg_set(pVBInfo->Part1Port, 0x35, tempax);
1697
1698 if (pVBInfo->VBType & VB_XGI301C) {
1699 temp2 = push3;
1700 xgifb_reg_set(pVBInfo->Part4Port,
1701 0x3c,
1702 (unsigned short) (temp2 & 0xff));
1703 xgifb_reg_set(pVBInfo->Part4Port,
1704 0x3b,
1705 (unsigned short) ((temp2 >> 8) &
1706 0xff));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001707 tempbx = (unsigned short) (temp2 >> 16);
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001708 xgifb_reg_and_or(pVBInfo->Part4Port, 0x3a,
1709 ~0xc0,
1710 (unsigned short) ((tempbx &
1711 0xff) << 6));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001712
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001713 tempcx = pVBInfo->VGAVDE;
1714 if (tempcx == pVBInfo->VDE)
1715 xgifb_reg_and_or(pVBInfo->Part4Port,
1716 0x30, ~0x0c, 0x00);
1717 else
1718 xgifb_reg_and_or(pVBInfo->Part4Port,
1719 0x30, ~0x0c, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301720 }
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001721
1722 tempcx = pVBInfo->VGAHDE;
1723 tempbx = pVBInfo->HDE;
1724
1725 temp1 = tempcx << 16;
1726
1727 tempax = (unsigned short) (temp1 / tempbx);
1728
1729 if ((tempbx & 0xffff) == (tempcx & 0xffff))
1730 tempax = 65535;
1731
1732 temp3 = tempax;
1733 temp1 = pVBInfo->VGAHDE << 16;
1734
1735 temp1 /= temp3;
1736 temp3 = temp3 << 16;
1737 temp1 -= 1;
1738
1739 temp3 = (temp3 & 0xffff0000) + (temp1 & 0xffff);
1740
1741 tempax = (unsigned short) (temp3 & 0xff);
1742 xgifb_reg_set(pVBInfo->Part1Port, 0x1f, tempax);
1743
1744 temp1 = pVBInfo->VGAVDE << 18;
1745 temp1 = temp1 / push3;
1746 tempbx = (unsigned short) (temp1 & 0xffff);
1747
Peter Huewe255aabd2012-02-09 21:11:44 +01001748 if (pVBInfo->LCDResInfo == Panel_1024x768)
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001749 tempbx -= 1;
1750
1751 tempax = ((tempbx >> 8) & 0xff) << 3;
1752 tempax |= (unsigned short) ((temp3 >> 8) & 0x07);
1753 xgifb_reg_set(pVBInfo->Part1Port, 0x20,
1754 (unsigned short) (tempax & 0xff));
1755 xgifb_reg_set(pVBInfo->Part1Port, 0x21,
1756 (unsigned short) (tempbx & 0xff));
1757
1758 temp3 = temp3 >> 16;
1759
1760 if (modeflag & HalfDCLK)
1761 temp3 = temp3 >> 1;
1762
1763 xgifb_reg_set(pVBInfo->Part1Port, 0x22,
1764 (unsigned short) ((temp3 >> 8) & 0xff));
1765 xgifb_reg_set(pVBInfo->Part1Port, 0x23,
1766 (unsigned short) (temp3 & 0xff));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001767}
1768
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001769/* --------------------------------------------------------------------- */
1770/* Function : XGI_GETLCDVCLKPtr */
1771/* Input : */
1772/* Output : al -> VCLK Index */
1773/* Description : */
1774/* --------------------------------------------------------------------- */
1775static void XGI_GetLCDVCLKPtr(unsigned char *di_0, unsigned char *di_1,
1776 struct vb_device_info *pVBInfo)
1777{
1778 unsigned short index;
1779
Peter Huewea3d675c2012-02-09 21:11:47 +01001780 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001781 index = XGI_GetLCDCapPtr1(pVBInfo);
1782
1783 if (pVBInfo->VBInfo & SetCRT2ToLCD) { /* LCDB */
1784 *di_0 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData1;
1785 *di_1 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData2;
1786 } else { /* LCDA */
1787 *di_0 = pVBInfo->LCDCapList[index].LCDA_VCLKData1;
1788 *di_1 = pVBInfo->LCDCapList[index].LCDA_VCLKData2;
1789 }
1790 }
1791 return;
1792}
1793
1794static unsigned char XGI_GetVCLKPtr(unsigned short RefreshRateTableIndex,
1795 unsigned short ModeNo, unsigned short ModeIdIndex,
1796 struct vb_device_info *pVBInfo)
1797{
1798
1799 unsigned short index, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001800 unsigned char tempal;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001801
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001802 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02001803 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001804
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001805 if ((pVBInfo->SetFlag & ProgrammingCRT2) &&
1806 (!(pVBInfo->LCDInfo & EnableScalingLCD))) { /* {LCDA/LCDB} */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001807 index = XGI_GetLCDCapPtr(pVBInfo);
1808 tempal = pVBInfo->LCDCapList[index].LCD_VCLK;
1809
Peter Huewea3d675c2012-02-09 21:11:47 +01001810 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001811 return tempal;
1812
1813 /* {TV} */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001814 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01001815 (VB_SIS301B |
1816 VB_SIS302B |
1817 VB_SIS301LV |
1818 VB_SIS302LV |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001819 VB_XGI301C)) {
Peter Huewe599801f2012-02-09 21:11:45 +01001820 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001821 tempal = TVCLKBASE_315 + HiTVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001822 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
Peter Hueweccc8cb22012-02-09 21:11:48 +01001823 tempal = TVCLKBASE_315 + HiTVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001824 if (pVBInfo->TVInfo & TVSimuMode) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001825 tempal = TVCLKBASE_315 + HiTVSimuVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001826 if (!(modeflag & Charx8Dot))
Miguel Gómez3bcc2462012-07-06 12:40:53 +02001827 tempal = TVCLKBASE_315 +
1828 HiTVTextVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001829
1830 }
1831 return tempal;
1832 }
1833
Peter Huewe599801f2012-02-09 21:11:45 +01001834 if (pVBInfo->TVInfo & TVSetYPbPr750p) {
Peter Huewea3d675c2012-02-09 21:11:47 +01001835 tempal = XGI_YPbPr750pVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001836 return tempal;
1837 }
1838
Peter Huewe599801f2012-02-09 21:11:45 +01001839 if (pVBInfo->TVInfo & TVSetYPbPr525p) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001840 tempal = YPbPr525pVCLK;
1841 return tempal;
1842 }
1843
1844 tempal = NTSC1024VCLK;
1845
1846 if (!(pVBInfo->TVInfo & NTSC1024x768)) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001847 tempal = TVCLKBASE_315 + TVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001848 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
Peter Hueweccc8cb22012-02-09 21:11:48 +01001849 tempal = TVCLKBASE_315 + TVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001850 }
1851
1852 if (pVBInfo->VBInfo & SetCRT2ToTV)
1853 return tempal;
1854 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001855 } /* {End of VB} */
1856
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02001857 tempal = (unsigned char) inb((pVBInfo->P3ca + 0x02));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001858 tempal = tempal >> 2;
1859 tempal &= 0x03;
1860
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001861 /* for Dot8 Scaling LCD */
1862 if ((pVBInfo->LCDInfo & EnableScalingLCD) && (modeflag & Charx8Dot))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001863 tempal = tempal ^ tempal; /* ; set to VCLK25MHz always */
1864
Aaro Koskinena39325d2012-11-04 21:14:53 +02001865 tempal = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001866 return tempal;
1867}
1868
1869static void XGI_GetVCLKLen(unsigned char tempal, unsigned char *di_0,
1870 unsigned char *di_1, struct vb_device_info *pVBInfo)
1871{
Peter Huewe6896b942012-02-09 21:11:46 +01001872 if (pVBInfo->VBType & (VB_SIS301 | VB_SIS301B | VB_SIS302B
1873 | VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +02001874 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) &&
1875 (pVBInfo->SetFlag & ProgrammingCRT2)) {
Aaro Koskinene8cb03d2012-09-11 00:15:31 +03001876 *di_0 = XGI_VBVCLKData[tempal].Part4_A;
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +03001877 *di_1 = XGI_VBVCLKData[tempal].Part4_B;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001878 }
1879 } else {
1880 *di_0 = XGI_VCLKData[tempal].SR2B;
1881 *di_1 = XGI_VCLKData[tempal].SR2C;
1882 }
1883}
1884
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001885static void XGI_SetCRT2ECLK(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301886 unsigned short RefreshRateTableIndex,
1887 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001888{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301889 unsigned char di_0, di_1, tempal;
1890 int i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001891
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301892 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
1893 pVBInfo);
1894 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
1895 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001896
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301897 for (i = 0; i < 4; i++) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001898 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, ~0x30,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301899 (unsigned short) (0x10 * i));
Peter Huewea3d675c2012-02-09 21:11:47 +01001900 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301901 && (!(pVBInfo->VBInfo & SetInSlaveMode))) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001902 xgifb_reg_set(pVBInfo->P3c4, 0x2e, di_0);
1903 xgifb_reg_set(pVBInfo->P3c4, 0x2f, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301904 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001905 xgifb_reg_set(pVBInfo->P3c4, 0x2b, di_0);
1906 xgifb_reg_set(pVBInfo->P3c4, 0x2c, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301907 }
1908 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001909}
1910
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001911static void XGI_UpdateModeInfo(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301912 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001913{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301914 unsigned short tempcl, tempch, temp, tempbl, tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001915
Peter Huewe6896b942012-02-09 21:11:46 +01001916 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
1917 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301918 tempcl = 0;
1919 tempch = 0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02001920 temp = xgifb_reg_get(pVBInfo->P3c4, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001921
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301922 if (!(temp & 0x20)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001923 temp = xgifb_reg_get(pVBInfo->P3d4, 0x17);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301924 if (temp & 0x80) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001925 temp = xgifb_reg_get(pVBInfo->P3d4, 0x53);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301926 if (!(temp & 0x40))
1927 tempcl |= ActiveCRT1;
1928 }
1929 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001930
Aaro Koskinen58839b02011-03-13 12:26:23 +02001931 temp = xgifb_reg_get(pVBInfo->Part1Port, 0x2e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301932 temp &= 0x0f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001933
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301934 if (!(temp == 0x08)) {
Miguel Gómez949eb0a2012-07-06 12:40:36 +02001935 /* Check ChannelA */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001936 tempax = xgifb_reg_get(pVBInfo->Part1Port, 0x13);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301937 if (tempax & 0x04)
1938 tempcl = tempcl | ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001939
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301940 temp &= 0x05;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001941
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301942 if (!(tempcl & ActiveLCD))
1943 if (temp == 0x01)
1944 tempcl |= ActiveCRT2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001945
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301946 if (temp == 0x04)
1947 tempcl |= ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001948
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301949 if (temp == 0x05) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001950 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001951
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301952 if (!(temp & 0x08))
1953 tempch |= ActiveAVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001954
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301955 if (!(temp & 0x04))
1956 tempch |= ActiveSVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001957
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301958 if (temp & 0x02)
1959 tempch |= ActiveSCART;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001960
Peter Huewe599801f2012-02-09 21:11:45 +01001961 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301962 if (temp & 0x01)
1963 tempch |= ActiveHiTV;
1964 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001965
Peter Huewe599801f2012-02-09 21:11:45 +01001966 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001967 temp = xgifb_reg_get(
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301968 pVBInfo->Part2Port,
1969 0x4d);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001970
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301971 if (temp & 0x10)
1972 tempch |= ActiveYPbPr;
1973 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001974
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301975 if (tempch != 0)
1976 tempcl |= ActiveTV;
1977 }
1978 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001979
Aaro Koskinen58839b02011-03-13 12:26:23 +02001980 temp = xgifb_reg_get(pVBInfo->P3d4, 0x3d);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301981 if (tempcl & ActiveLCD) {
1982 if ((pVBInfo->SetFlag & ReserveTVOption)) {
1983 if (temp & ActiveTV)
1984 tempcl |= ActiveTV;
1985 }
1986 }
1987 temp = tempcl;
Peter Huewea3d675c2012-02-09 21:11:47 +01001988 tempbl = ~XGI_ModeSwitchStatus;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001989 xgifb_reg_and_or(pVBInfo->P3d4, 0x3d, tempbl, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001990
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301991 if (!(pVBInfo->SetFlag & ReserveTVOption))
Aaro Koskinen8104e322011-03-13 12:26:22 +02001992 xgifb_reg_set(pVBInfo->P3d4, 0x3e, tempch);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301993 } else {
1994 return;
1995 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001996}
1997
Bill Pemberton80adad82010-06-17 13:10:51 -04001998void XGI_GetVBType(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001999{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302000 unsigned short flag, tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002001
Miguel Gómez7eec23a2012-07-06 12:40:47 +02002002 if (pVBInfo->IF_DEF_LVDS != 0)
2003 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002004
Miguel Gómez7eec23a2012-07-06 12:40:47 +02002005 tempbx = VB_SIS302B;
2006 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
2007 if (flag == 0x02)
2008 goto finish;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002009
Miguel Gómez7eec23a2012-07-06 12:40:47 +02002010 tempbx = VB_SIS301;
2011 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x01);
2012 if (flag < 0xB0)
2013 goto finish;
2014
2015 tempbx = VB_SIS301B;
2016 if (flag < 0xC0)
2017 goto bigger_than_0xB0;
2018
2019 tempbx = VB_XGI301C;
2020 if (flag < 0xD0)
2021 goto bigger_than_0xB0;
2022
2023 tempbx = VB_SIS301LV;
2024 if (flag < 0xE0)
2025 goto bigger_than_0xB0;
2026
2027 tempbx = VB_SIS302LV;
2028 tempah = xgifb_reg_get(pVBInfo->Part4Port, 0x39);
2029 if (tempah != 0xFF)
2030 tempbx = VB_XGI301C;
2031
2032bigger_than_0xB0:
2033 if (tempbx & (VB_SIS301B | VB_SIS302B)) {
2034 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x23);
2035 if (!(flag & 0x02))
2036 tempbx = tempbx | VB_NoLCD;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302037 }
Miguel Gómez7eec23a2012-07-06 12:40:47 +02002038
2039finish:
2040 pVBInfo->VBType = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002041}
2042
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02002043static void XGI_GetVBInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302044 struct xgi_hw_device_info *HwDeviceExtension,
2045 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002046{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302047 unsigned short tempax, push, tempbx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002048
Aaro Koskinenb3979922012-11-04 21:14:52 +02002049 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302050 pVBInfo->SetFlag = 0;
Peter Huewe6896b942012-02-09 21:11:46 +01002051 pVBInfo->ModeType = modeflag & ModeTypeMask;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302052 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002053
Miguel Gómezf9317352012-07-06 12:40:48 +02002054 if (!(pVBInfo->VBType & 0xFFFF))
2055 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002056
Miguel Gómezf9317352012-07-06 12:40:48 +02002057 /* Check Display Device */
2058 temp = xgifb_reg_get(pVBInfo->P3d4, 0x30);
2059 tempbx = tempbx | temp;
2060 temp = xgifb_reg_get(pVBInfo->P3d4, 0x31);
2061 push = temp;
2062 push = push << 8;
2063 tempax = temp << 8;
2064 tempbx = tempbx | tempax;
2065 temp = (SetCRT2ToDualEdge | SetCRT2ToYPbPr525750 | XGI_SetCRT2ToLCDA
2066 | SetInSlaveMode | DisableCRT2Display);
2067 temp = 0xFFFF ^ temp;
2068 tempbx &= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002069
Miguel Gómezf9317352012-07-06 12:40:48 +02002070 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002071
Aaro Koskinen4d8f5ca2012-09-11 00:15:17 +03002072 if (pVBInfo->IF_DEF_LVDS == 0) {
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03002073 if (pVBInfo->VBType &
2074 (VB_SIS302B |
2075 VB_SIS301LV |
2076 VB_SIS302LV |
2077 VB_XGI301C)) {
2078 if (temp & EnableDualEdge) {
2079 tempbx |= SetCRT2ToDualEdge;
2080 if (temp & SetToLCDA)
2081 tempbx |= XGI_SetCRT2ToLCDA;
Miguel Gómezf9317352012-07-06 12:40:48 +02002082 }
2083 }
2084 }
2085
2086 if (pVBInfo->IF_DEF_YPbPr == 1) {
2087 if (((pVBInfo->IF_DEF_LVDS == 0) &&
2088 ((pVBInfo->VBType & VB_SIS301LV) ||
2089 (pVBInfo->VBType & VB_SIS302LV) ||
2090 (pVBInfo->VBType & VB_XGI301C)))) {
2091 if (temp & SetYPbPr) {
2092 if (pVBInfo->IF_DEF_HiVision == 1) {
2093 /* shampoo add for new
2094 * scratch */
2095 temp = xgifb_reg_get(
2096 pVBInfo->P3d4,
2097 0x35);
2098 temp &= YPbPrMode;
2099 tempbx |= SetCRT2ToHiVision;
2100
2101 if (temp != YPbPrMode1080i) {
2102 tempbx &=
2103 (~SetCRT2ToHiVision);
2104 tempbx |=
2105 SetCRT2ToYPbPr525750;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302106 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302107 }
2108 }
2109 }
Miguel Gómezf9317352012-07-06 12:40:48 +02002110 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002111
Miguel Gómezf9317352012-07-06 12:40:48 +02002112 tempax = push; /* restore CR31 */
2113
2114 if (pVBInfo->IF_DEF_LVDS == 0) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302115 if (pVBInfo->IF_DEF_YPbPr == 1) {
Miguel Gómezf9317352012-07-06 12:40:48 +02002116 if (pVBInfo->IF_DEF_HiVision == 1)
2117 temp = 0x09FC;
2118 else
2119 temp = 0x097C;
Aaro Koskinend3ae5762012-09-11 00:15:27 +03002120 } else if (pVBInfo->IF_DEF_HiVision == 1) {
2121 temp = 0x01FC;
Miguel Gómezf9317352012-07-06 12:40:48 +02002122 } else {
Aaro Koskinend3ae5762012-09-11 00:15:27 +03002123 temp = 0x017C;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302124 }
Justin P. Mattock558f7582012-10-02 21:17:11 -07002125 } else { /* 3rd party chip */
Miguel Gómezf9317352012-07-06 12:40:48 +02002126 temp = SetCRT2ToLCD;
2127 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002128
Miguel Gómezf9317352012-07-06 12:40:48 +02002129 if (!(tempbx & temp)) {
2130 tempax |= DisableCRT2Display;
2131 tempbx = 0;
2132 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002133
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03002134 if (!(pVBInfo->VBType & VB_NoLCD)) {
2135 if (tempbx & XGI_SetCRT2ToLCDA) {
2136 if (tempbx & SetSimuScanMode)
2137 tempbx &= (~(SetCRT2ToLCD |
2138 SetCRT2ToRAMDAC |
2139 SwitchCRT2));
2140 else
2141 tempbx &= (~(SetCRT2ToLCD |
2142 SetCRT2ToRAMDAC |
2143 SetCRT2ToTV |
2144 SwitchCRT2));
Miguel Gómezf9317352012-07-06 12:40:48 +02002145 }
2146 }
2147
2148 /* shampoo add */
2149 /* for driver abnormal */
2150 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode))) {
2151 if (pVBInfo->IF_DEF_CRT2Monitor == 1) {
2152 if (tempbx & SetCRT2ToRAMDAC) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002153 tempbx &= (0xFF00 |
Miguel Gómezf9317352012-07-06 12:40:48 +02002154 SetCRT2ToRAMDAC |
Peter Huewe6896b942012-02-09 21:11:46 +01002155 SwitchCRT2 |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002156 SetSimuScanMode);
Peter Huewe599801f2012-02-09 21:11:45 +01002157 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302158 }
Miguel Gómezf9317352012-07-06 12:40:48 +02002159 } else {
2160 tempbx &= (~(SetCRT2ToRAMDAC |
2161 SetCRT2ToLCD |
2162 SetCRT2ToTV));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302163 }
Miguel Gómezf9317352012-07-06 12:40:48 +02002164 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002165
Miguel Gómezf9317352012-07-06 12:40:48 +02002166 if (!(pVBInfo->VBType & VB_NoLCD)) {
2167 if (tempbx & SetCRT2ToLCD) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002168 tempbx &= (0xFF00 |
Miguel Gómezf9317352012-07-06 12:40:48 +02002169 SetCRT2ToLCD |
Peter Huewe6896b942012-02-09 21:11:46 +01002170 SwitchCRT2 |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002171 SetSimuScanMode);
Peter Huewe599801f2012-02-09 21:11:45 +01002172 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302173 }
Miguel Gómezf9317352012-07-06 12:40:48 +02002174 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002175
Miguel Gómezf9317352012-07-06 12:40:48 +02002176 if (tempbx & SetCRT2ToSCART) {
2177 tempbx &= (0xFF00 |
2178 SetCRT2ToSCART |
2179 SwitchCRT2 |
2180 SetSimuScanMode);
2181 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
2182 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002183
Miguel Gómezf9317352012-07-06 12:40:48 +02002184 if (pVBInfo->IF_DEF_YPbPr == 1) {
2185 if (tempbx & SetCRT2ToYPbPr525750)
2186 tempbx &= (0xFF00 |
2187 SwitchCRT2 |
2188 SetSimuScanMode);
2189 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002190
Miguel Gómezf9317352012-07-06 12:40:48 +02002191 if (pVBInfo->IF_DEF_HiVision == 1) {
2192 if (tempbx & SetCRT2ToHiVision)
2193 tempbx &= (0xFF00 |
2194 SetCRT2ToHiVision |
2195 SwitchCRT2 |
2196 SetSimuScanMode);
2197 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002198
Miguel Gómezf9317352012-07-06 12:40:48 +02002199 if (tempax & DisableCRT2Display) { /* Set Display Device Info */
2200 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode)))
2201 tempbx = DisableCRT2Display;
2202 }
2203
2204 if (!(tempbx & DisableCRT2Display)) {
2205 if ((!(tempbx & DriverMode)) ||
2206 (!(modeflag & CRT2Mode))) {
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03002207 if (!(tempbx & XGI_SetCRT2ToLCDA))
2208 tempbx |= (SetInSlaveMode |
2209 SetSimuScanMode);
Miguel Gómezf9317352012-07-06 12:40:48 +02002210 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002211
Miguel Gómezf9317352012-07-06 12:40:48 +02002212 /* LCD+TV can't support in slave mode
2213 * (Force LCDA+TV->LCDB) */
2214 if ((tempbx & SetInSlaveMode) &&
2215 (tempbx & XGI_SetCRT2ToLCDA)) {
2216 tempbx ^= (SetCRT2ToLCD |
2217 XGI_SetCRT2ToLCDA |
2218 SetCRT2ToDualEdge);
2219 pVBInfo->SetFlag |= ReserveTVOption;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302220 }
2221 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002222
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302223 pVBInfo->VBInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002224}
2225
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02002226static void XGI_GetTVInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302227 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002228{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302229 unsigned short temp, tempbx = 0, resinfo = 0, modeflag, index1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002230
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302231 tempbx = 0;
2232 resinfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002233
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302234 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinenb3979922012-11-04 21:14:52 +02002235 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2236 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002237
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302238 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002239 temp = xgifb_reg_get(pVBInfo->P3d4, 0x35);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302240 tempbx = temp;
Peter Huewe599801f2012-02-09 21:11:45 +01002241 if (tempbx & TVSetPAL) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002242 tempbx &= (SetCHTVOverScan |
Peter Huewe599801f2012-02-09 21:11:45 +01002243 TVSetPALM |
2244 TVSetPALN |
2245 TVSetPAL);
2246 if (tempbx & TVSetPALM)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002247 /* set to NTSC if PAL-M */
Peter Huewe599801f2012-02-09 21:11:45 +01002248 tempbx &= ~TVSetPAL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302249 } else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002250 tempbx &= (SetCHTVOverScan |
Peter Huewe599801f2012-02-09 21:11:45 +01002251 TVSetNTSCJ |
2252 TVSetPAL);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302253 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002254
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302255 if (pVBInfo->IF_DEF_LVDS == 0) {
2256 if (pVBInfo->VBInfo & SetCRT2ToSCART)
Peter Huewe599801f2012-02-09 21:11:45 +01002257 tempbx |= TVSetPAL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302258 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002259
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302260 if (pVBInfo->IF_DEF_YPbPr == 1) {
Peter Huewe599801f2012-02-09 21:11:45 +01002261 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002262 index1 = xgifb_reg_get(pVBInfo->P3d4, 0x35);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302263 index1 &= YPbPrMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002264
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302265 if (index1 == YPbPrMode525i)
Peter Huewe599801f2012-02-09 21:11:45 +01002266 tempbx |= TVSetYPbPr525i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002267
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302268 if (index1 == YPbPrMode525p)
Peter Huewe599801f2012-02-09 21:11:45 +01002269 tempbx = tempbx | TVSetYPbPr525p;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302270 if (index1 == YPbPrMode750p)
Peter Huewe599801f2012-02-09 21:11:45 +01002271 tempbx = tempbx | TVSetYPbPr750p;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302272 }
2273 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002274
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302275 if (pVBInfo->IF_DEF_HiVision == 1) {
Peter Huewe599801f2012-02-09 21:11:45 +01002276 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
2277 tempbx = tempbx | TVSetHiVision | TVSetPAL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302278 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002279
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302280 if (pVBInfo->IF_DEF_LVDS == 0) { /* shampoo */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002281 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
2282 (!(pVBInfo->VBInfo & SetNotSimuMode)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302283 tempbx |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002284
Peter Huewe599801f2012-02-09 21:11:45 +01002285 if (!(tempbx & TVSetPAL) &&
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002286 (modeflag > 13) &&
2287 (resinfo == 8)) /* NTSC 1024x768, */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302288 tempbx |= NTSC1024x768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002289
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302290 tempbx |= RPLLDIV2XO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002291
Peter Huewe599801f2012-02-09 21:11:45 +01002292 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302293 if (pVBInfo->VBInfo & SetInSlaveMode)
2294 tempbx &= (~RPLLDIV2XO);
Aaro Koskinend3ae5762012-09-11 00:15:27 +03002295 } else if (tempbx &
2296 (TVSetYPbPr525p | TVSetYPbPr750p)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302297 tempbx &= (~RPLLDIV2XO);
Aaro Koskinend3ae5762012-09-11 00:15:27 +03002298 } else if (!(pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01002299 (VB_SIS301B |
2300 VB_SIS302B |
2301 VB_SIS301LV |
2302 VB_SIS302LV |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002303 VB_XGI301C))) {
Aaro Koskinend3ae5762012-09-11 00:15:27 +03002304 if (tempbx & TVSimuMode)
2305 tempbx &= (~RPLLDIV2XO);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302306 }
2307 }
2308 }
2309 pVBInfo->TVInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002310}
2311
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02002312static unsigned char XGI_GetLCDInfo(unsigned short ModeNo,
2313 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002314{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302315 unsigned short temp, tempax, tempbx, modeflag, resinfo = 0, LCDIdIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002316
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302317 pVBInfo->LCDResInfo = 0;
2318 pVBInfo->LCDTypeInfo = 0;
2319 pVBInfo->LCDInfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002320
Aaro Koskinenb3979922012-11-04 21:14:52 +02002321 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002322 /* si+Ext_ResInfo // */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002323 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinen58839b02011-03-13 12:26:23 +02002324 temp = xgifb_reg_get(pVBInfo->P3d4, 0x36); /* Get LCD Res.Info */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302325 tempbx = temp & 0x0F;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002326
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302327 if (tempbx == 0)
Peter Huewe255aabd2012-02-09 21:11:44 +01002328 tempbx = Panel_1024x768; /* default */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002329
Miguel Gómez949eb0a2012-07-06 12:40:36 +02002330 /* LCD75 */
Peter Huewe255aabd2012-02-09 21:11:44 +01002331 if ((tempbx == Panel_1024x768) || (tempbx == Panel_1280x1024)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302332 if (pVBInfo->VBInfo & DriverMode) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002333 tempax = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Peter Huewea3d675c2012-02-09 21:11:47 +01002334 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302335 tempax &= 0x0F;
2336 else
2337 tempax = tempax >> 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002338
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302339 if ((resinfo == 6) || (resinfo == 9)) {
2340 if (tempax >= 3)
2341 tempbx |= PanelRef75Hz;
2342 } else if ((resinfo == 7) || (resinfo == 8)) {
2343 if (tempax >= 4)
2344 tempbx |= PanelRef75Hz;
2345 }
2346 }
2347 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002348
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302349 pVBInfo->LCDResInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002350
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302351 /* End of LCD75 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002352
Peter Huewea3d675c2012-02-09 21:11:47 +01002353 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302354 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002355
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302356 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002357
Aaro Koskinen58839b02011-03-13 12:26:23 +02002358 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002359
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302360 temp &= (ScalingLCD | LCDNonExpanding | LCDSyncBit | SetPWDEnable);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002361
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302362 tempbx |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002363
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302364 LCDIdIndex = XGI_GetLCDCapPtr1(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002365
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302366 tempax = pVBInfo->LCDCapList[LCDIdIndex].LCD_Capability;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002367
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302368 if (pVBInfo->IF_DEF_LVDS == 0) { /* shampoo */
Peter Huewe6896b942012-02-09 21:11:46 +01002369 if (((pVBInfo->VBType & VB_SIS302LV) || (pVBInfo->VBType
Peter Huewea3d675c2012-02-09 21:11:47 +01002370 & VB_XGI301C)) && (tempax & XGI_LCDDualLink)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302371 tempbx |= SetLCDDualLink;
2372 }
2373 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002374
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302375 if (pVBInfo->IF_DEF_LVDS == 0) {
Peter Huewe255aabd2012-02-09 21:11:44 +01002376 if ((pVBInfo->LCDResInfo == Panel_1400x1050) && (pVBInfo->VBInfo
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002377 & SetCRT2ToLCD) && (resinfo == 9) &&
2378 (!(tempbx & EnableScalingLCD)))
Miguel Gómez3bcc2462012-07-06 12:40:53 +02002379 /*
2380 * set to center in 1280x1024 LCDB
2381 * for Panel_1400x1050
2382 */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002383 tempbx |= SetLCDtoNonExpanding;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302384 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002385
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302386 if (pVBInfo->VBInfo & SetInSlaveMode) {
2387 if (pVBInfo->VBInfo & SetNotSimuMode)
Peter Huewea3d675c2012-02-09 21:11:47 +01002388 tempbx |= XGI_LCDVESATiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302389 } else {
Peter Huewea3d675c2012-02-09 21:11:47 +01002390 tempbx |= XGI_LCDVESATiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302391 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002392
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302393 pVBInfo->LCDInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002394
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302395 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002396}
2397
Bill Pemberton108afbf2010-06-17 13:10:47 -04002398unsigned char XGI_SearchModeID(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302399 unsigned short *ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002400{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002401 for (*ModeIdIndex = 0;; (*ModeIdIndex)++) {
Aaro Koskinenb3979922012-11-04 21:14:52 +02002402 if (XGI330_EModeIDTable[*ModeIdIndex].Ext_ModeID == ModeNo)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002403 break;
Aaro Koskinenb3979922012-11-04 21:14:52 +02002404 if (XGI330_EModeIDTable[*ModeIdIndex].Ext_ModeID == 0xFF)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002405 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302406 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002407
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302408 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002409}
2410
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002411static unsigned char XG21GPIODataTransfer(unsigned char ujDate)
2412{
2413 unsigned char ujRet = 0;
2414 unsigned char i = 0;
2415
2416 for (i = 0; i < 8; i++) {
2417 ujRet = ujRet << 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002418 ujRet |= (ujDate >> i) & 1;
2419 }
2420
2421 return ujRet;
2422}
2423
2424/*----------------------------------------------------------------------------*/
2425/* output */
2426/* bl[5] : LVDS signal */
2427/* bl[1] : LVDS backlight */
2428/* bl[0] : LVDS VDD */
2429/*----------------------------------------------------------------------------*/
2430static unsigned char XGI_XG21GetPSCValue(struct vb_device_info *pVBInfo)
2431{
2432 unsigned char CR4A, temp;
2433
Aaro Koskinen58839b02011-03-13 12:26:23 +02002434 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02002435 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x23); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002436
Aaro Koskinen58839b02011-03-13 12:26:23 +02002437 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002438
2439 temp = XG21GPIODataTransfer(temp);
2440 temp &= 0x23;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002441 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002442 return temp;
2443}
2444
2445/*----------------------------------------------------------------------------*/
2446/* output */
2447/* bl[5] : LVDS signal */
2448/* bl[1] : LVDS backlight */
2449/* bl[0] : LVDS VDD */
2450/*----------------------------------------------------------------------------*/
2451static unsigned char XGI_XG27GetPSCValue(struct vb_device_info *pVBInfo)
2452{
2453 unsigned char CR4A, CRB4, temp;
2454
Aaro Koskinen58839b02011-03-13 12:26:23 +02002455 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02002456 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x0C); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002457
Aaro Koskinen58839b02011-03-13 12:26:23 +02002458 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002459
2460 temp &= 0x0C;
2461 temp >>= 2;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002462 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinen58839b02011-03-13 12:26:23 +02002463 CRB4 = xgifb_reg_get(pVBInfo->P3d4, 0xB4);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002464 temp |= ((CRB4 & 0x04) << 3);
2465 return temp;
2466}
2467
Aaro Koskinen0ebf5382011-11-27 23:03:09 +02002468/*----------------------------------------------------------------------------*/
2469/* input */
2470/* bl[5] : 1;LVDS signal on */
2471/* bl[1] : 1;LVDS backlight on */
2472/* bl[0] : 1:LVDS VDD on */
2473/* bh: 100000b : clear bit 5, to set bit5 */
2474/* 000010b : clear bit 1, to set bit1 */
2475/* 000001b : clear bit 0, to set bit0 */
2476/*----------------------------------------------------------------------------*/
2477static void XGI_XG21BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
2478 struct vb_device_info *pVBInfo)
2479{
2480 unsigned char CR4A, temp;
2481
2482 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
2483 tempbh &= 0x23;
2484 tempbl &= 0x23;
2485 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
2486
2487 if (tempbh & 0x20) {
2488 temp = (tempbl >> 4) & 0x02;
2489
2490 /* CR B4[1] */
2491 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
2492
2493 }
2494
2495 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
2496
2497 temp = XG21GPIODataTransfer(temp);
2498 temp &= ~tempbh;
2499 temp |= tempbl;
2500 xgifb_reg_set(pVBInfo->P3d4, 0x48, temp);
2501}
2502
Aaro Koskinen776115a2011-11-27 23:03:10 +02002503static void XGI_XG27BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
2504 struct vb_device_info *pVBInfo)
2505{
2506 unsigned char CR4A, temp;
2507 unsigned short tempbh0, tempbl0;
2508
2509 tempbh0 = tempbh;
2510 tempbl0 = tempbl;
2511 tempbh0 &= 0x20;
2512 tempbl0 &= 0x20;
2513 tempbh0 >>= 3;
2514 tempbl0 >>= 3;
2515
2516 if (tempbh & 0x20) {
2517 temp = (tempbl >> 4) & 0x02;
2518
2519 /* CR B4[1] */
2520 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
2521
2522 }
2523 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~tempbh0, tempbl0);
2524
2525 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
2526 tempbh &= 0x03;
2527 tempbl &= 0x03;
2528 tempbh <<= 2;
2529 tempbl <<= 2; /* GPIOC,GPIOD */
2530 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
2531 xgifb_reg_and_or(pVBInfo->P3d4, 0x48, ~tempbh, tempbl);
2532}
2533
Aaro Koskinenfab04b92011-12-06 00:10:45 +02002534static void XGI_DisplayOn(struct xgifb_video_info *xgifb_info,
2535 struct xgi_hw_device_info *pXGIHWDE,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302536 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002537{
2538
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002539 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302540 if (pXGIHWDE->jChipType == XG21) {
2541 if (pVBInfo->IF_DEF_LVDS == 1) {
2542 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002543 /* LVDS VDD on */
2544 XGI_XG21BLSignalVDD(0x01, 0x01, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002545 mdelay(xgifb_info->lvds_data.PSC_S2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302546 }
2547 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002548 /* LVDS signal on */
2549 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002550 mdelay(xgifb_info->lvds_data.PSC_S3);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002551 /* LVDS backlight on */
2552 XGI_XG21BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302553 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002554 /* DVO/DVI signal on */
2555 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302556 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002557
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302558 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002559
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302560 if (pXGIHWDE->jChipType == XG27) {
2561 if (pVBInfo->IF_DEF_LVDS == 1) {
2562 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002563 /* LVDS VDD on */
2564 XGI_XG27BLSignalVDD(0x01, 0x01, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002565 mdelay(xgifb_info->lvds_data.PSC_S2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302566 }
2567 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002568 /* LVDS signal on */
2569 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002570 mdelay(xgifb_info->lvds_data.PSC_S3);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002571 /* LVDS backlight on */
2572 XGI_XG27BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302573 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002574 /* DVO/DVI signal on */
2575 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302576 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002577
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302578 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002579}
2580
Aaro Koskinenfab04b92011-12-06 00:10:45 +02002581void XGI_DisplayOff(struct xgifb_video_info *xgifb_info,
2582 struct xgi_hw_device_info *pXGIHWDE,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302583 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002584{
2585
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302586 if (pXGIHWDE->jChipType == XG21) {
2587 if (pVBInfo->IF_DEF_LVDS == 1) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002588 /* LVDS backlight off */
2589 XGI_XG21BLSignalVDD(0x02, 0x00, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002590 mdelay(xgifb_info->lvds_data.PSC_S3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302591 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002592 /* DVO/DVI signal off */
2593 XGI_XG21BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302594 }
2595 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002596
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302597 if (pXGIHWDE->jChipType == XG27) {
2598 if ((XGI_XG27GetPSCValue(pVBInfo) & 0x2)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002599 /* LVDS backlight off */
2600 XGI_XG27BLSignalVDD(0x02, 0x00, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002601 mdelay(xgifb_info->lvds_data.PSC_S3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302602 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002603
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302604 if (pVBInfo->IF_DEF_LVDS == 0)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002605 /* DVO/DVI signal off */
2606 XGI_XG27BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302607 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002608
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002609 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x20);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002610}
2611
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002612static void XGI_WaitDisply(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002613{
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02002614 while ((inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302615 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002616
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02002617 while (!(inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302618 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002619}
2620
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002621static void XGI_AutoThreshold(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002622{
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002623 xgifb_reg_or(pVBInfo->Part1Port, 0x01, 0x40);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002624}
2625
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002626static void XGI_SaveCRT2Info(unsigned short ModeNo,
2627 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002628{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302629 unsigned short temp1, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002630
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002631 /* reserve CR34 for CRT1 Mode No */
2632 xgifb_reg_set(pVBInfo->P3d4, 0x34, ModeNo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302633 temp1 = (pVBInfo->VBInfo & SetInSlaveMode) >> 8;
2634 temp2 = ~(SetInSlaveMode >> 8);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002635 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, temp2, temp1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002636}
2637
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002638static void XGI_GetCRT2ResInfo(unsigned short ModeNo,
2639 unsigned short ModeIdIndex,
2640 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002641{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302642 unsigned short xres, yres, modeflag, resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002643
Aaro Koskinenb3979922012-11-04 21:14:52 +02002644 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002645 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
2646 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
2647 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002648 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002649
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002650 if (modeflag & HalfDCLK)
2651 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002652
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002653 if (modeflag & DoubleScanMode)
2654 yres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002655
Miguel Gómez3339db82012-07-06 12:40:49 +02002656 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
2657 goto exit;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002658
Miguel Gómez3339db82012-07-06 12:40:49 +02002659 if (pVBInfo->IF_DEF_LVDS == 0) {
2660 if (pVBInfo->LCDResInfo == Panel_1600x1200) {
2661 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
2662 if (yres == 1024)
2663 yres = 1056;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302664 }
2665 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002666
Miguel Gómez3339db82012-07-06 12:40:49 +02002667 if (pVBInfo->LCDResInfo == Panel_1280x1024) {
2668 if (yres == 400)
2669 yres = 405;
2670 else if (yres == 350)
2671 yres = 360;
2672
2673 if (pVBInfo->LCDInfo & XGI_LCDVESATiming) {
2674 if (yres == 360)
2675 yres = 375;
2676 }
2677 }
2678
2679 if (pVBInfo->LCDResInfo == Panel_1024x768) {
2680 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
2681 if (!(pVBInfo->LCDInfo & LCDNonExpanding)) {
2682 if (yres == 350)
2683 yres = 357;
2684 else if (yres == 400)
2685 yres = 420;
2686 else if (yres == 480)
2687 yres = 525;
2688 }
2689 }
2690 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302691 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002692
Miguel Gómez3339db82012-07-06 12:40:49 +02002693 if (xres == 720)
2694 xres = 640;
2695
2696exit:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302697 pVBInfo->VGAHDE = xres;
2698 pVBInfo->HDE = xres;
2699 pVBInfo->VGAVDE = yres;
2700 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002701}
2702
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002703static unsigned char XGI_IsLCDDualLink(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002704{
2705
Peter Huewea3d675c2012-02-09 21:11:47 +01002706 if ((pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) &&
Dan Carpentera65fd092011-01-04 09:02:27 +03002707 (pVBInfo->LCDInfo & SetLCDDualLink)) /* shampoo0129 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302708 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002709
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302710 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002711}
2712
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002713static void XGI_GetRAMDAC2DATA(unsigned short ModeNo,
2714 unsigned short ModeIdIndex,
2715 unsigned short RefreshRateTableIndex,
2716 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002717{
2718 unsigned short tempax, tempbx, temp1, temp2, modeflag = 0, tempcx,
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002719 CRT1Index;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002720
2721 pVBInfo->RVBHCMAX = 1;
2722 pVBInfo->RVBHCFACT = 1;
Aaro Koskinenb3979922012-11-04 21:14:52 +02002723 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02002724 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002725 CRT1Index &= IndexMask;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002726 temp1 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[0];
2727 temp2 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[5];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002728 tempax = (temp1 & 0xFF) | ((temp2 & 0x03) << 8);
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002729 tempbx = (unsigned short) XGI_CRT1Table[CRT1Index].CR[8];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002730 tempcx = (unsigned short)
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002731 XGI_CRT1Table[CRT1Index].CR[14] << 8;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002732 tempcx &= 0x0100;
2733 tempcx = tempcx << 2;
2734 tempbx |= tempcx;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002735 temp1 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[9];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002736
2737 if (temp1 & 0x01)
2738 tempbx |= 0x0100;
2739
2740 if (temp1 & 0x20)
2741 tempbx |= 0x0200;
2742 tempax += 5;
2743
2744 if (modeflag & Charx8Dot)
2745 tempax *= 8;
2746 else
2747 tempax *= 9;
2748
2749 pVBInfo->VGAHT = tempax;
2750 pVBInfo->HT = tempax;
2751 tempbx++;
2752 pVBInfo->VGAVT = tempbx;
2753 pVBInfo->VT = tempbx;
2754}
2755
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002756static void XGI_GetCRT2Data(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302757 unsigned short RefreshRateTableIndex,
2758 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002759{
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02002760 unsigned short tempax = 0, tempbx = 0, modeflag, resinfo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002761
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02002762 struct SiS_LCDData const *LCDPtr = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002763
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002764 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002765 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2766 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302767 pVBInfo->NewFlickerMode = 0;
2768 pVBInfo->RVBHRS = 50;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002769
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302770 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
2771 XGI_GetRAMDAC2DATA(ModeNo, ModeIdIndex, RefreshRateTableIndex,
2772 pVBInfo);
2773 return;
2774 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002775
Peter Huewea3d675c2012-02-09 21:11:47 +01002776 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02002777 LCDPtr = XGI_GetLcdPtr(XGI_LCDDataTable, ModeNo, ModeIdIndex,
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +03002778 RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002779
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302780 pVBInfo->RVBHCMAX = LCDPtr->RVBHCMAX;
2781 pVBInfo->RVBHCFACT = LCDPtr->RVBHCFACT;
2782 pVBInfo->VGAHT = LCDPtr->VGAHT;
2783 pVBInfo->VGAVT = LCDPtr->VGAVT;
2784 pVBInfo->HT = LCDPtr->LCDHT;
2785 pVBInfo->VT = LCDPtr->LCDVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002786
Peter Huewe255aabd2012-02-09 21:11:44 +01002787 if (pVBInfo->LCDResInfo == Panel_1024x768) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302788 tempax = 1024;
2789 tempbx = 768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002790
Peter Huewea3d675c2012-02-09 21:11:47 +01002791 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302792 if (pVBInfo->VGAVDE == 357)
2793 tempbx = 527;
2794 else if (pVBInfo->VGAVDE == 420)
2795 tempbx = 620;
2796 else if (pVBInfo->VGAVDE == 525)
2797 tempbx = 775;
2798 else if (pVBInfo->VGAVDE == 600)
2799 tempbx = 775;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302800 else
2801 tempbx = 768;
2802 } else
2803 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01002804 } else if (pVBInfo->LCDResInfo == Panel_1024x768x75) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302805 tempax = 1024;
2806 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01002807 } else if (pVBInfo->LCDResInfo == Panel_1280x1024) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302808 tempax = 1280;
2809 if (pVBInfo->VGAVDE == 360)
2810 tempbx = 768;
2811 else if (pVBInfo->VGAVDE == 375)
2812 tempbx = 800;
2813 else if (pVBInfo->VGAVDE == 405)
2814 tempbx = 864;
2815 else
2816 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01002817 } else if (pVBInfo->LCDResInfo == Panel_1280x1024x75) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302818 tempax = 1280;
2819 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01002820 } else if (pVBInfo->LCDResInfo == Panel_1280x960) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302821 tempax = 1280;
2822 if (pVBInfo->VGAVDE == 350)
2823 tempbx = 700;
2824 else if (pVBInfo->VGAVDE == 400)
2825 tempbx = 800;
2826 else if (pVBInfo->VGAVDE == 1024)
2827 tempbx = 960;
2828 else
2829 tempbx = 960;
Peter Huewe255aabd2012-02-09 21:11:44 +01002830 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302831 tempax = 1400;
2832 tempbx = 1050;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002833
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302834 if (pVBInfo->VGAVDE == 1024) {
2835 tempax = 1280;
2836 tempbx = 1024;
2837 }
Peter Huewe255aabd2012-02-09 21:11:44 +01002838 } else if (pVBInfo->LCDResInfo == Panel_1600x1200) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302839 tempax = 1600;
2840 tempbx = 1200; /* alan 10/14/2003 */
Peter Huewea3d675c2012-02-09 21:11:47 +01002841 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302842 if (pVBInfo->VGAVDE == 350)
2843 tempbx = 875;
2844 else if (pVBInfo->VGAVDE == 400)
2845 tempbx = 1000;
2846 }
2847 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002848
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302849 if (pVBInfo->LCDInfo & LCDNonExpanding) {
2850 tempax = pVBInfo->VGAHDE;
2851 tempbx = pVBInfo->VGAVDE;
2852 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002853
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302854 pVBInfo->HDE = tempax;
2855 pVBInfo->VDE = tempbx;
2856 return;
2857 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002858
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302859 if (pVBInfo->VBInfo & (SetCRT2ToTV)) {
Aaro Koskinen24572542012-09-11 00:15:21 +03002860 struct SiS_TVData const *TVPtr;
2861
2862 TVPtr = XGI_GetTVPtr(ModeNo, ModeIdIndex, RefreshRateTableIndex,
2863 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002864
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302865 pVBInfo->RVBHCMAX = TVPtr->RVBHCMAX;
2866 pVBInfo->RVBHCFACT = TVPtr->RVBHCFACT;
2867 pVBInfo->VGAHT = TVPtr->VGAHT;
2868 pVBInfo->VGAVT = TVPtr->VGAVT;
2869 pVBInfo->HDE = TVPtr->TVHDE;
2870 pVBInfo->VDE = TVPtr->TVVDE;
2871 pVBInfo->RVBHRS = TVPtr->RVBHRS;
2872 pVBInfo->NewFlickerMode = TVPtr->FlickerMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002873
Peter Huewe599801f2012-02-09 21:11:45 +01002874 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302875 if (resinfo == 0x08)
2876 pVBInfo->NewFlickerMode = 0x40;
2877 else if (resinfo == 0x09)
2878 pVBInfo->NewFlickerMode = 0x40;
2879 else if (resinfo == 0x12)
2880 pVBInfo->NewFlickerMode = 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002881
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302882 if (pVBInfo->VGAVDE == 350)
2883 pVBInfo->TVInfo |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002884
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302885 tempax = ExtHiTVHT;
2886 tempbx = ExtHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002887
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302888 if (pVBInfo->VBInfo & SetInSlaveMode) {
2889 if (pVBInfo->TVInfo & TVSimuMode) {
2890 tempax = StHiTVHT;
2891 tempbx = StHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002892
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302893 if (!(modeflag & Charx8Dot)) {
2894 tempax = StHiTextTVHT;
2895 tempbx = StHiTextTVVT;
2896 }
2897 }
2898 }
Peter Huewe599801f2012-02-09 21:11:45 +01002899 } else if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
2900 if (pVBInfo->TVInfo & TVSetYPbPr750p) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302901 tempax = YPbPrTV750pHT; /* Ext750pTVHT */
2902 tempbx = YPbPrTV750pVT; /* Ext750pTVVT */
2903 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002904
Peter Huewe599801f2012-02-09 21:11:45 +01002905 if (pVBInfo->TVInfo & TVSetYPbPr525p) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302906 tempax = YPbPrTV525pHT; /* Ext525pTVHT */
2907 tempbx = YPbPrTV525pVT; /* Ext525pTVVT */
Peter Huewe599801f2012-02-09 21:11:45 +01002908 } else if (pVBInfo->TVInfo & TVSetYPbPr525i) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302909 tempax = YPbPrTV525iHT; /* Ext525iTVHT */
2910 tempbx = YPbPrTV525iVT; /* Ext525iTVVT */
2911 if (pVBInfo->TVInfo & NTSC1024x768)
2912 tempax = NTSC1024x768HT;
2913 }
2914 } else {
2915 tempax = PALHT;
2916 tempbx = PALVT;
Peter Huewe599801f2012-02-09 21:11:45 +01002917 if (!(pVBInfo->TVInfo & TVSetPAL)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302918 tempax = NTSCHT;
2919 tempbx = NTSCVT;
2920 if (pVBInfo->TVInfo & NTSC1024x768)
2921 tempax = NTSC1024x768HT;
2922 }
2923 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002924
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302925 pVBInfo->HT = tempax;
2926 pVBInfo->VT = tempbx;
2927 return;
2928 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002929}
2930
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002931static void XGI_SetCRT2VCLK(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302932 unsigned short RefreshRateTableIndex,
2933 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002934{
Bill Pemberton108afbf2010-06-17 13:10:47 -04002935 unsigned char di_0, di_1, tempal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002936
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302937 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
2938 pVBInfo);
2939 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
2940 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002941
Peter Huewe6896b942012-02-09 21:11:46 +01002942 if (pVBInfo->VBType & VB_SIS301) { /* shampoo 0129 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302943 /* 301 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002944 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, 0x10);
2945 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
2946 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302947 } else { /* 301b/302b/301lv/302lv */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002948 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
2949 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302950 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002951
Aaro Koskinen8104e322011-03-13 12:26:22 +02002952 xgifb_reg_set(pVBInfo->Part4Port, 0x00, 0x12);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002953
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302954 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02002955 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x28);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302956 else
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02002957 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002958}
2959
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002960static unsigned short XGI_GetColorDepth(unsigned short ModeNo,
2961 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002962{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002963 unsigned short ColorDepth[6] = { 1, 2, 4, 4, 6, 8 };
2964 short index;
2965 unsigned short modeflag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302966
Aaro Koskinenb3979922012-11-04 21:14:52 +02002967 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Peter Huewe6896b942012-02-09 21:11:46 +01002968 index = (modeflag & ModeTypeMask) - ModeEGA;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302969
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002970 if (index < 0)
2971 index = 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302972
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002973 return ColorDepth[index];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302974}
2975
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002976static unsigned short XGI_GetOffset(unsigned short ModeNo,
2977 unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302978 unsigned short RefreshRateTableIndex,
2979 struct xgi_hw_device_info *HwDeviceExtension,
2980 struct vb_device_info *pVBInfo)
2981{
2982 unsigned short temp, colordepth, modeinfo, index, infoflag,
2983 ColorDepth[] = { 0x01, 0x02, 0x04 };
2984
Aaro Koskinenb3979922012-11-04 21:14:52 +02002985 modeinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeInfo;
Aaro Koskinena39325d2012-11-04 21:14:53 +02002986 infoflag = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302987
2988 index = (modeinfo >> 8) & 0xFF;
2989
2990 temp = pVBInfo->ScreenOffset[index];
2991
2992 if (infoflag & InterlaceMode)
2993 temp = temp << 1;
2994
2995 colordepth = XGI_GetColorDepth(ModeNo, ModeIdIndex, pVBInfo);
2996
2997 if ((ModeNo >= 0x7C) && (ModeNo <= 0x7E)) {
2998 temp = ModeNo - 0x7C;
2999 colordepth = ColorDepth[temp];
3000 temp = 0x6B;
3001 if (infoflag & InterlaceMode)
3002 temp = temp << 1;
3003 return temp * colordepth;
3004 } else {
3005 return temp * colordepth;
3006 }
3007}
3008
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003009static void XGI_SetCRT2Offset(unsigned short ModeNo,
3010 unsigned short ModeIdIndex,
3011 unsigned short RefreshRateTableIndex,
3012 struct xgi_hw_device_info *HwDeviceExtension,
3013 struct vb_device_info *pVBInfo)
3014{
3015 unsigned short offset;
3016 unsigned char temp;
3017
3018 if (pVBInfo->VBInfo & SetInSlaveMode)
3019 return;
3020
3021 offset = XGI_GetOffset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
3022 HwDeviceExtension, pVBInfo);
3023 temp = (unsigned char) (offset & 0xFF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003024 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003025 temp = (unsigned char) ((offset & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003026 xgifb_reg_set(pVBInfo->Part1Port, 0x09, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003027 temp = (unsigned char) (((offset >> 3) & 0xFF) + 1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003028 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003029}
3030
Randy Dunlap89229672010-08-10 08:46:44 -07003031static void XGI_SetCRT2FIFO(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003032{
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003033 /* threshold high ,disable auto threshold */
3034 xgifb_reg_set(pVBInfo->Part1Port, 0x01, 0x3B);
3035 /* threshold low default 04h */
3036 xgifb_reg_and_or(pVBInfo->Part1Port, 0x02, ~(0x3F), 0x04);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003037}
3038
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003039static void XGI_PreSetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303040 struct xgi_hw_device_info *HwDeviceExtension,
3041 unsigned short RefreshRateTableIndex,
3042 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003043{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303044 unsigned short tempcx = 0, CRT1Index = 0, resinfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003045
Aaro Koskinena39325d2012-11-04 21:14:53 +02003046 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003047 CRT1Index &= IndexMask;
Aaro Koskinenb3979922012-11-04 21:14:52 +02003048 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003049
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303050 XGI_SetCRT2Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
3051 HwDeviceExtension, pVBInfo);
3052 XGI_SetCRT2FIFO(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003053
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303054 for (tempcx = 4; tempcx < 7; tempcx++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02003055 xgifb_reg_set(pVBInfo->Part1Port, tempcx, 0x0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003056
Aaro Koskinen8104e322011-03-13 12:26:22 +02003057 xgifb_reg_set(pVBInfo->Part1Port, 0x50, 0x00);
3058 xgifb_reg_set(pVBInfo->Part1Port, 0x02, 0x44); /* temp 0206 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003059}
3060
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003061static void XGI_SetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303062 struct xgi_hw_device_info *HwDeviceExtension,
3063 unsigned short RefreshRateTableIndex,
3064 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003065{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303066 unsigned short temp = 0, tempax = 0, tempbx = 0, tempcx = 0,
3067 pushbx = 0, CRT1Index = 0, modeflag, resinfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003068
Aaro Koskinena39325d2012-11-04 21:14:53 +02003069 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003070 CRT1Index &= IndexMask;
Aaro Koskinenb3979922012-11-04 21:14:52 +02003071 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
3072 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003073
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303074 /* bainy change table name */
3075 if (modeflag & HalfDCLK) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003076 /* BTVGA2HT 0x08,0x09 */
3077 temp = (pVBInfo->VGAHT / 2 - 1) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003078 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303079 temp = (((pVBInfo->VGAHT / 2 - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003080 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003081 /* BTVGA2HDEE 0x0A,0x0C */
3082 temp = (pVBInfo->VGAHDE / 2 + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003083 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303084 tempcx = ((pVBInfo->VGAHT - pVBInfo->VGAHDE) / 2) >> 2;
3085 pushbx = pVBInfo->VGAHDE / 2 + 16;
3086 tempcx = tempcx >> 1;
3087 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
3088 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003089
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303090 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003091 tempbx = XGI_CRT1Table[CRT1Index].CR[4];
3092 tempbx |= ((XGI_CRT1Table[CRT1Index].CR[14] &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003093 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303094 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003095 tempcx = XGI_CRT1Table[CRT1Index].CR[5];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303096 tempcx &= 0x1F;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003097 temp = XGI_CRT1Table[CRT1Index].CR[15];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303098 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
3099 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
3100 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003101
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303102 tempbx += 4;
3103 tempcx += 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003104
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303105 if (tempcx > (pVBInfo->VGAHT / 2))
3106 tempcx = pVBInfo->VGAHT / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003107
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303108 temp = tempbx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003109
Aaro Koskinen8104e322011-03-13 12:26:22 +02003110 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303111 } else {
3112 temp = (pVBInfo->VGAHT - 1) & 0x0FF; /* BTVGA2HT 0x08,0x09 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003113 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303114 temp = (((pVBInfo->VGAHT - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003115 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003116 /* BTVGA2HDEE 0x0A,0x0C */
3117 temp = (pVBInfo->VGAHDE + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003118 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303119 tempcx = (pVBInfo->VGAHT - pVBInfo->VGAHDE) >> 2; /* cx */
3120 pushbx = pVBInfo->VGAHDE + 16;
3121 tempcx = tempcx >> 1;
3122 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
3123 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003124
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303125 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003126 tempbx = XGI_CRT1Table[CRT1Index].CR[3];
3127 tempbx |= ((XGI_CRT1Table[CRT1Index].CR[5] &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003128 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303129 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003130 tempcx = XGI_CRT1Table[CRT1Index].CR[4];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303131 tempcx &= 0x1F;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003132 temp = XGI_CRT1Table[CRT1Index].CR[6];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303133 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
3134 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
3135 tempbx += 16;
3136 tempcx += 16;
3137 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003138
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303139 if (tempcx > pVBInfo->VGAHT)
3140 tempcx = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003141
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303142 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003143 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303144 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003145
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303146 tempax = (tempax & 0x00FF) | (tempbx & 0xFF00);
3147 tempbx = pushbx;
3148 tempbx = (tempbx & 0x00FF) | ((tempbx & 0xFF00) << 4);
3149 tempax |= (tempbx & 0xFF00);
3150 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003151 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303152 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003153 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303154 tempcx = (pVBInfo->VGAVT - 1);
3155 temp = tempcx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003156
Aaro Koskinen8104e322011-03-13 12:26:22 +02003157 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303158 tempbx = pVBInfo->VGAVDE - 1;
3159 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003160 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303161 temp = ((tempbx & 0xFF00) << 3) >> 8;
3162 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003163 xgifb_reg_set(pVBInfo->Part1Port, 0x12, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003164
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303165 tempax = pVBInfo->VGAVDE;
3166 tempbx = pVBInfo->VGAVDE;
3167 tempcx = pVBInfo->VGAVT;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003168 /* BTVGA2VRS 0x10,0x11 */
3169 tempbx = (pVBInfo->VGAVT + pVBInfo->VGAVDE) >> 1;
3170 /* BTVGA2VRE 0x11 */
3171 tempcx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) >> 4) + tempbx + 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003172
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303173 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003174 tempbx = XGI_CRT1Table[CRT1Index].CR[10];
3175 temp = XGI_CRT1Table[CRT1Index].CR[9];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003176
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303177 if (temp & 0x04)
3178 tempbx |= 0x0100;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003179
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303180 if (temp & 0x080)
3181 tempbx |= 0x0200;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003182
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003183 temp = XGI_CRT1Table[CRT1Index].CR[14];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003184
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303185 if (temp & 0x08)
3186 tempbx |= 0x0400;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003187
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003188 temp = XGI_CRT1Table[CRT1Index].CR[11];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303189 tempcx = (tempcx & 0xFF00) | (temp & 0x00FF);
3190 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003191
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303192 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003193 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303194 temp = ((tempbx & 0xFF00) >> 8) << 4;
3195 temp = ((tempcx & 0x000F) | (temp));
Aaro Koskinen8104e322011-03-13 12:26:22 +02003196 xgifb_reg_set(pVBInfo->Part1Port, 0x11, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303197 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003198
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303199 if (modeflag & DoubleScanMode)
3200 tempax |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003201
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303202 if (modeflag & HalfDCLK)
3203 tempax |= 0x40;
3204
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003205 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2C, ~0x0C0, tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003206}
3207
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003208static unsigned short XGI_GetVGAHT2(struct vb_device_info *pVBInfo)
3209{
3210 unsigned long tempax, tempbx;
3211
3212 tempbx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) * pVBInfo->RVBHCMAX)
3213 & 0xFFFF;
3214 tempax = (pVBInfo->VT - pVBInfo->VDE) * pVBInfo->RVBHCFACT;
3215 tempax = (tempax * pVBInfo->HT) / tempbx;
3216
3217 return (unsigned short) tempax;
3218}
3219
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003220static void XGI_SetLockRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303221 struct xgi_hw_device_info *HwDeviceExtension,
3222 unsigned short RefreshRateTableIndex,
3223 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003224{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303225 unsigned short push1, push2, tempax, tempbx = 0, tempcx, temp, resinfo,
3226 modeflag, CRT1Index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003227
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003228 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02003229 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3230 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinena39325d2012-11-04 21:14:53 +02003231 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003232 CRT1Index &= IndexMask;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003233
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303234 if (!(pVBInfo->VBInfo & SetInSlaveMode))
3235 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003236
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303237 temp = 0xFF; /* set MAX HT */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003238 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303239 tempcx = 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003240
Peter Huewe6896b942012-02-09 21:11:46 +01003241 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303242 modeflag |= Charx8Dot;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003243
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303244 tempax = pVBInfo->VGAHDE; /* 0x04 Horizontal Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003245
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303246 if (modeflag & HalfDCLK)
3247 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003248
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303249 tempax = (tempax / tempcx) - 1;
3250 tempbx |= ((tempax & 0x00FF) << 8);
3251 temp = tempax & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003252 xgifb_reg_set(pVBInfo->Part1Port, 0x04, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003253
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303254 temp = (tempbx & 0xFF00) >> 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003255
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303256 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Peter Huewe6896b942012-02-09 21:11:46 +01003257 if (!(pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3258 | VB_SIS302LV | VB_XGI301C)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303259 temp += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003260
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03003261 if ((pVBInfo->VBInfo & SetCRT2ToHiVision) &&
3262 !(pVBInfo->VBType & VB_SIS301LV) && (resinfo == 7))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303263 temp -= 2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303264 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003265
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003266 /* 0x05 Horizontal Display Start */
3267 xgifb_reg_set(pVBInfo->Part1Port, 0x05, temp);
3268 /* 0x06 Horizontal Blank end */
3269 xgifb_reg_set(pVBInfo->Part1Port, 0x06, 0x03);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003270
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303271 if (!(pVBInfo->VBInfo & DisableCRT2Display)) { /* 030226 bainy */
3272 if (pVBInfo->VBInfo & SetCRT2ToTV)
3273 tempax = pVBInfo->VGAHT;
3274 else
3275 tempax = XGI_GetVGAHT2(pVBInfo);
3276 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003277
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303278 if (tempax >= pVBInfo->VGAHT)
3279 tempax = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003280
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303281 if (modeflag & HalfDCLK)
3282 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003283
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303284 tempax = (tempax / tempcx) - 5;
3285 tempcx = tempax; /* 20030401 0x07 horizontal Retrace Start */
Peter Huewe599801f2012-02-09 21:11:45 +01003286 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303287 temp = (tempbx & 0x00FF) - 1;
3288 if (!(modeflag & HalfDCLK)) {
3289 temp -= 6;
3290 if (pVBInfo->TVInfo & TVSimuMode) {
3291 temp -= 4;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003292 temp -= 10;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303293 }
3294 }
3295 } else {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303296 tempbx = (tempbx & 0xFF00) >> 8;
3297 tempcx = (tempcx + tempbx) >> 1;
3298 temp = (tempcx & 0x00FF) + 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003299
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303300 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3301 temp -= 1;
3302 if (!(modeflag & HalfDCLK)) {
3303 if ((modeflag & Charx8Dot)) {
3304 temp += 4;
3305 if (pVBInfo->VGAHDE >= 800)
3306 temp -= 6;
3307 }
3308 }
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003309 } else if (!(modeflag & HalfDCLK)) {
3310 temp -= 4;
Peter Huewe255aabd2012-02-09 21:11:44 +01003311 if (pVBInfo->LCDResInfo != Panel_1280x960 &&
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003312 pVBInfo->VGAHDE >= 800) {
3313 temp -= 7;
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003314 if (pVBInfo->VGAHDE >= 1280 &&
Peter Huewe255aabd2012-02-09 21:11:44 +01003315 pVBInfo->LCDResInfo != Panel_1280x960 &&
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003316 (pVBInfo->LCDInfo & LCDNonExpanding))
3317 temp += 28;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303318 }
3319 }
3320 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003321
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003322 /* 0x07 Horizontal Retrace Start */
3323 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
3324 /* 0x08 Horizontal Retrace End */
3325 xgifb_reg_set(pVBInfo->Part1Port, 0x08, 0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003326
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303327 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3328 if (pVBInfo->TVInfo & TVSimuMode) {
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003329 if (ModeNo == 0x50) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303330 if (pVBInfo->TVInfo & SetNTSCTV) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003331 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303332 0x07, 0x30);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003333 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303334 0x08, 0x03);
3335 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003336 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303337 0x07, 0x2f);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003338 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303339 0x08, 0x02);
3340 }
3341 }
3342 }
3343 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003344
Aaro Koskinen8104e322011-03-13 12:26:22 +02003345 xgifb_reg_set(pVBInfo->Part1Port, 0x18, 0x03); /* 0x18 SR0B */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003346 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0xF0, 0x00);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003347 xgifb_reg_set(pVBInfo->Part1Port, 0x09, 0xFF); /* 0x09 Set Max VT */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003348
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303349 tempbx = pVBInfo->VGAVT;
3350 push1 = tempbx;
3351 tempcx = 0x121;
3352 tempbx = pVBInfo->VGAVDE; /* 0x0E Virtical Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003353
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303354 if (tempbx == 357)
3355 tempbx = 350;
3356 if (tempbx == 360)
3357 tempbx = 350;
3358 if (tempbx == 375)
3359 tempbx = 350;
3360 if (tempbx == 405)
3361 tempbx = 400;
3362 if (tempbx == 525)
3363 tempbx = 480;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003364
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303365 push2 = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003366
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303367 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
Peter Huewe255aabd2012-02-09 21:11:44 +01003368 if (pVBInfo->LCDResInfo == Panel_1024x768) {
Peter Huewea3d675c2012-02-09 21:11:47 +01003369 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303370 if (tempbx == 350)
3371 tempbx += 5;
3372 if (tempbx == 480)
3373 tempbx += 5;
3374 }
3375 }
3376 }
3377 tempbx--;
3378 temp = tempbx & 0x00FF;
3379 tempbx--;
3380 temp = tempbx & 0x00FF;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003381 /* 0x10 vertical Blank Start */
3382 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303383 tempbx = push2;
3384 tempbx--;
3385 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003386 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003387
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303388 if (tempbx & 0x0100)
3389 tempcx |= 0x0002;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003390
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303391 tempax = 0x000B;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003392
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303393 if (modeflag & DoubleScanMode)
3394 tempax |= 0x08000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003395
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303396 if (tempbx & 0x0200)
3397 tempcx |= 0x0040;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003398
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303399 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003400 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003401
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303402 if (tempbx & 0x0400)
3403 tempcx |= 0x0600;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003404
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003405 /* 0x11 Vertival Blank End */
3406 xgifb_reg_set(pVBInfo->Part1Port, 0x11, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303407
3408 tempax = push1;
3409 tempax -= tempbx; /* 0x0C Vertical Retrace Start */
3410 tempax = tempax >> 2;
3411 push1 = tempax; /* push ax */
3412
3413 if (resinfo != 0x09) {
3414 tempax = tempax << 1;
3415 tempbx += tempax;
3416 }
3417
Peter Huewe599801f2012-02-09 21:11:45 +01003418 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Miguel Gómez470c5332012-07-06 12:40:50 +02003419 if ((pVBInfo->VBType & VB_SIS301LV) &&
3420 !(pVBInfo->TVInfo & TVSetHiVision)) {
3421 if ((pVBInfo->TVInfo & TVSimuMode) &&
3422 (pVBInfo->TVInfo & TVSetPAL)) {
3423 if (!(pVBInfo->VBType & VB_SIS301LV) ||
3424 !(pVBInfo->TVInfo &
3425 (TVSetYPbPr525p |
3426 TVSetYPbPr750p |
3427 TVSetHiVision)))
3428 tempbx += 40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303429 }
3430 } else {
3431 tempbx -= 10;
3432 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003433 } else if (pVBInfo->TVInfo & TVSimuMode) {
3434 if (pVBInfo->TVInfo & TVSetPAL) {
3435 if (pVBInfo->VBType & VB_SIS301LV) {
3436 if (!(pVBInfo->TVInfo &
3437 (TVSetYPbPr525p |
3438 TVSetYPbPr750p |
3439 TVSetHiVision)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303440 tempbx += 40;
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003441 } else {
3442 tempbx += 40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303443 }
3444 }
3445 }
3446 tempax = push1;
3447 tempax = tempax >> 2;
3448 tempax++;
3449 tempax += tempbx;
3450 push1 = tempax; /* push ax */
3451
Peter Huewe599801f2012-02-09 21:11:45 +01003452 if ((pVBInfo->TVInfo & TVSetPAL)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303453 if (tempbx <= 513) {
3454 if (tempax >= 513)
3455 tempbx = 513;
3456 }
3457 }
3458
3459 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003460 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303461 tempbx--;
3462 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003463 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303464
3465 if (tempbx & 0x0100)
3466 tempcx |= 0x0008;
3467
3468 if (tempbx & 0x0200)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003469 xgifb_reg_and_or(pVBInfo->Part1Port, 0x0B, 0x0FF, 0x20);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303470
3471 tempbx++;
3472
3473 if (tempbx & 0x0100)
3474 tempcx |= 0x0004;
3475
3476 if (tempbx & 0x0200)
3477 tempcx |= 0x0080;
3478
3479 if (tempbx & 0x0400)
3480 tempcx |= 0x0C00;
3481
3482 tempbx = push1; /* pop ax */
3483 temp = tempbx & 0x00FF;
3484 temp &= 0x0F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003485 /* 0x0D vertical Retrace End */
3486 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303487
3488 if (tempbx & 0x0010)
3489 tempcx |= 0x2000;
3490
3491 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003492 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp); /* 0x0A CR07 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303493 temp = (tempcx & 0x0FF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003494 xgifb_reg_set(pVBInfo->Part1Port, 0x17, temp); /* 0x17 SR0A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303495 tempax = modeflag;
3496 temp = (tempax & 0xFF00) >> 8;
3497
3498 temp = (temp >> 1) & 0x09;
3499
Peter Huewe6896b942012-02-09 21:11:46 +01003500 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303501 temp |= 0x01;
3502
Aaro Koskinen8104e322011-03-13 12:26:22 +02003503 xgifb_reg_set(pVBInfo->Part1Port, 0x16, temp); /* 0x16 SR01 */
3504 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, 0); /* 0x0F CR14 */
3505 xgifb_reg_set(pVBInfo->Part1Port, 0x12, 0); /* 0x12 CR17 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303506
3507 if (pVBInfo->LCDInfo & LCDRGB18Bit)
3508 temp = 0x80;
3509 else
3510 temp = 0x00;
3511
Aaro Koskinen8104e322011-03-13 12:26:22 +02003512 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, temp); /* 0x1A SR0E */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303513
3514 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003515}
3516
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003517static void XGI_SetGroup2(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303518 unsigned short RefreshRateTableIndex,
3519 struct xgi_hw_device_info *HwDeviceExtension,
3520 struct vb_device_info *pVBInfo)
3521{
3522 unsigned short i, j, tempax, tempbx, tempcx, temp, push1, push2,
3523 modeflag, resinfo, crt2crtc;
Aaro Koskinend21222d2012-09-11 00:15:29 +03003524 unsigned char const *TimingPoint;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303525
3526 unsigned long longtemp, tempeax, tempebx, temp2, tempecx;
3527
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003528 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02003529 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3530 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinena39325d2012-11-04 21:14:53 +02003531 crt2crtc = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303532
3533 tempax = 0;
3534
3535 if (!(pVBInfo->VBInfo & SetCRT2ToAVIDEO))
3536 tempax |= 0x0800;
3537
3538 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3539 tempax |= 0x0400;
3540
3541 if (pVBInfo->VBInfo & SetCRT2ToSCART)
3542 tempax |= 0x0200;
3543
Peter Huewe599801f2012-02-09 21:11:45 +01003544 if (!(pVBInfo->TVInfo & TVSetPAL))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303545 tempax |= 0x1000;
3546
Peter Huewe599801f2012-02-09 21:11:45 +01003547 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303548 tempax |= 0x0100;
3549
Peter Huewe599801f2012-02-09 21:11:45 +01003550 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303551 tempax &= 0xfe00;
3552
3553 tempax = (tempax & 0xff00) >> 8;
3554
Aaro Koskinen8104e322011-03-13 12:26:22 +02003555 xgifb_reg_set(pVBInfo->Part2Port, 0x0, tempax);
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003556 TimingPoint = XGI330_NTSCTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303557
Peter Huewe599801f2012-02-09 21:11:45 +01003558 if (pVBInfo->TVInfo & TVSetPAL)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003559 TimingPoint = XGI330_PALTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303560
Peter Huewe599801f2012-02-09 21:11:45 +01003561 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003562 TimingPoint = XGI330_HiTVExtTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303563
3564 if (pVBInfo->VBInfo & SetInSlaveMode)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003565 TimingPoint = XGI330_HiTVSt2Timing;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303566
3567 if (pVBInfo->SetFlag & TVSimuMode)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003568 TimingPoint = XGI330_HiTVSt1Timing;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303569
3570 if (!(modeflag & Charx8Dot))
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003571 TimingPoint = XGI330_HiTVTextTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303572 }
3573
Peter Huewe599801f2012-02-09 21:11:45 +01003574 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
3575 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003576 TimingPoint = XGI330_YPbPr525iTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303577
Peter Huewe599801f2012-02-09 21:11:45 +01003578 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003579 TimingPoint = XGI330_YPbPr525pTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303580
Peter Huewe599801f2012-02-09 21:11:45 +01003581 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003582 TimingPoint = XGI330_YPbPr750pTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303583 }
3584
3585 for (i = 0x01, j = 0; i <= 0x2D; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02003586 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303587
3588 for (i = 0x39; i <= 0x45; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003589 /* di->temp2[j] */
3590 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303591
3592 if (pVBInfo->VBInfo & SetCRT2ToTV)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003593 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303594
3595 temp = pVBInfo->NewFlickerMode;
3596 temp &= 0x80;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003597 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xFF, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303598
Peter Huewe599801f2012-02-09 21:11:45 +01003599 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303600 tempax = 950;
3601
Peter Huewe599801f2012-02-09 21:11:45 +01003602 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303603 tempax = 520;
3604 else
3605 tempax = 440;
3606
3607 if (pVBInfo->VDE <= tempax) {
3608 tempax -= pVBInfo->VDE;
3609 tempax = tempax >> 2;
3610 tempax = (tempax & 0x00FF) | ((tempax & 0x00FF) << 8);
3611 push1 = tempax;
3612 temp = (tempax & 0xFF00) >> 8;
3613 temp += (unsigned short) TimingPoint[0];
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 = 0x17; /* NTSC */
Peter Huewe599801f2012-02-09 21:11:45 +01003623 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303624 temp = 0x19; /* PAL */
3625 }
3626 }
3627 }
3628
Aaro Koskinen8104e322011-03-13 12:26:22 +02003629 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303630 tempax = push1;
3631 temp = (tempax & 0xFF00) >> 8;
3632 temp += TimingPoint[1];
3633
Peter Huewe6896b942012-02-09 21:11:46 +01003634 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3635 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303636 if ((pVBInfo->VBInfo & (SetCRT2ToAVIDEO
3637 | SetCRT2ToSVIDEO | SetCRT2ToSCART
Peter Huewe599801f2012-02-09 21:11:45 +01003638 | SetCRT2ToYPbPr525750))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303639 tempcx = pVBInfo->VGAHDE;
3640 if (tempcx >= 1024) {
3641 temp = 0x1D; /* NTSC */
Peter Huewe599801f2012-02-09 21:11:45 +01003642 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303643 temp = 0x52; /* PAL */
3644 }
3645 }
3646 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02003647 xgifb_reg_set(pVBInfo->Part2Port, 0x02, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303648 }
3649
3650 /* 301b */
3651 tempcx = pVBInfo->HT;
3652
3653 if (XGI_IsLCDDualLink(pVBInfo))
3654 tempcx = tempcx >> 1;
3655
3656 tempcx -= 2;
3657 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003658 xgifb_reg_set(pVBInfo->Part2Port, 0x1B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303659
3660 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003661 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303662
3663 tempcx = pVBInfo->HT >> 1;
3664 push1 = tempcx; /* push cx */
3665 tempcx += 7;
3666
Peter Huewe599801f2012-02-09 21:11:45 +01003667 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303668 tempcx -= 4;
3669
3670 temp = tempcx & 0x00FF;
3671 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003672 xgifb_reg_and_or(pVBInfo->Part2Port, 0x22, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303673
3674 tempbx = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
3675 tempbx += tempcx;
3676 push2 = tempbx;
3677 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003678 xgifb_reg_set(pVBInfo->Part2Port, 0x24, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303679 temp = (tempbx & 0xFF00) >> 8;
3680 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003681 xgifb_reg_and_or(pVBInfo->Part2Port, 0x25, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303682
3683 tempbx = push2;
3684 tempbx = tempbx + 8;
Peter Huewe599801f2012-02-09 21:11:45 +01003685 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303686 tempbx = tempbx - 4;
3687 tempcx = tempbx;
3688 }
3689
3690 temp = (tempbx & 0x00FF) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003691 xgifb_reg_and_or(pVBInfo->Part2Port, 0x29, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303692
3693 j += 2;
3694 tempcx += (TimingPoint[j] | ((TimingPoint[j + 1]) << 8));
3695 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003696 xgifb_reg_set(pVBInfo->Part2Port, 0x27, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303697 temp = ((tempcx & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003698 xgifb_reg_and_or(pVBInfo->Part2Port, 0x28, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303699
3700 tempcx += 8;
Peter Huewe599801f2012-02-09 21:11:45 +01003701 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303702 tempcx -= 4;
3703
3704 temp = tempcx & 0xFF;
3705 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003706 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2A, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303707
3708 tempcx = push1; /* pop cx */
3709 j += 2;
3710 temp = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
3711 tempcx -= temp;
3712 temp = tempcx & 0x00FF;
3713 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003714 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2D, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303715
3716 tempcx -= 11;
3717
3718 if (!(pVBInfo->VBInfo & SetCRT2ToTV)) {
3719 tempax = XGI_GetVGAHT2(pVBInfo);
3720 tempcx = tempax - 1;
3721 }
3722 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003723 xgifb_reg_set(pVBInfo->Part2Port, 0x2E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303724
3725 tempbx = pVBInfo->VDE;
3726
3727 if (pVBInfo->VGAVDE == 360)
3728 tempbx = 746;
3729 if (pVBInfo->VGAVDE == 375)
3730 tempbx = 746;
3731 if (pVBInfo->VGAVDE == 405)
3732 tempbx = 853;
3733
3734 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003735 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01003736 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003737 if (!(pVBInfo->TVInfo &
Peter Huewe599801f2012-02-09 21:11:45 +01003738 (TVSetYPbPr525p | TVSetYPbPr750p)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303739 tempbx = tempbx >> 1;
3740 } else
3741 tempbx = tempbx >> 1;
3742 }
3743
3744 tempbx -= 2;
3745 temp = tempbx & 0x00FF;
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 if (pVBInfo->VBInfo & SetInSlaveMode) {
3751 if (ModeNo == 0x2f)
3752 temp += 1;
3753 }
3754 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003755 } else if (pVBInfo->VBInfo & SetInSlaveMode) {
3756 if (ModeNo == 0x2f)
3757 temp += 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303758 }
3759 }
3760
Aaro Koskinen8104e322011-03-13 12:26:22 +02003761 xgifb_reg_set(pVBInfo->Part2Port, 0x2F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303762
3763 temp = (tempcx & 0xFF00) >> 8;
3764 temp |= ((tempbx & 0xFF00) >> 8) << 6;
3765
Peter Huewe599801f2012-02-09 21:11:45 +01003766 if (!(pVBInfo->VBInfo & SetCRT2ToHiVision)) {
Peter Huewe6896b942012-02-09 21:11:46 +01003767 if (pVBInfo->VBType & VB_SIS301LV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003768 if (pVBInfo->TVInfo & TVSetHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303769 temp |= 0x10;
3770
3771 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3772 temp |= 0x20;
3773 }
3774 } else {
3775 temp |= 0x10;
3776 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3777 temp |= 0x20;
3778 }
3779 }
3780
Aaro Koskinen8104e322011-03-13 12:26:22 +02003781 xgifb_reg_set(pVBInfo->Part2Port, 0x30, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303782
Peter Huewe6896b942012-02-09 21:11:46 +01003783 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3784 | VB_SIS302LV | VB_XGI301C)) { /* TV gatingno */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303785 tempbx = pVBInfo->VDE;
3786 tempcx = tempbx - 2;
3787
3788 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003789 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p
3790 | TVSetYPbPr750p)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303791 tempbx = tempbx >> 1;
3792 }
3793
Peter Huewe6896b942012-02-09 21:11:46 +01003794 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303795 temp = 0;
3796 if (tempcx & 0x0400)
3797 temp |= 0x20;
3798
3799 if (tempbx & 0x0400)
3800 temp |= 0x40;
3801
Aaro Koskinen8104e322011-03-13 12:26:22 +02003802 xgifb_reg_set(pVBInfo->Part4Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303803 }
3804
3805 temp = (((tempbx - 3) & 0x0300) >> 8) << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003806 xgifb_reg_set(pVBInfo->Part2Port, 0x46, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303807 temp = (tempbx - 3) & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003808 xgifb_reg_set(pVBInfo->Part2Port, 0x47, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303809 }
3810
3811 tempbx = tempbx & 0x00FF;
3812
3813 if (!(modeflag & HalfDCLK)) {
3814 tempcx = pVBInfo->VGAHDE;
3815 if (tempcx >= pVBInfo->HDE) {
3816 tempbx |= 0x2000;
3817 tempax &= 0x00FF;
3818 }
3819 }
3820
3821 tempcx = 0x0101;
3822
3823 if (pVBInfo->VBInfo & SetCRT2ToTV) { /*301b*/
3824 if (pVBInfo->VGAHDE >= 1024) {
3825 tempcx = 0x1920;
3826 if (pVBInfo->VGAHDE >= 1280) {
3827 tempcx = 0x1420;
3828 tempbx = tempbx & 0xDFFF;
3829 }
3830 }
3831 }
3832
3833 if (!(tempbx & 0x2000)) {
3834 if (modeflag & HalfDCLK)
3835 tempcx = (tempcx & 0xFF00) | ((tempcx & 0x00FF) << 1);
3836
3837 push1 = tempbx;
3838 tempeax = pVBInfo->VGAHDE;
3839 tempebx = (tempcx & 0xFF00) >> 8;
3840 longtemp = tempeax * tempebx;
3841 tempecx = tempcx & 0x00FF;
3842 longtemp = longtemp / tempecx;
3843
3844 /* 301b */
3845 tempecx = 8 * 1024;
3846
Peter Huewe6896b942012-02-09 21:11:46 +01003847 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3848 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303849 tempecx = tempecx * 8;
3850 }
3851
3852 longtemp = longtemp * tempecx;
3853 tempecx = pVBInfo->HDE;
3854 temp2 = longtemp % tempecx;
3855 tempeax = longtemp / tempecx;
3856 if (temp2 != 0)
3857 tempeax += 1;
3858
3859 tempax = (unsigned short) tempeax;
3860
3861 /* 301b */
Peter Huewe6896b942012-02-09 21:11:46 +01003862 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3863 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303864 tempcx = ((tempax & 0xFF00) >> 5) >> 8;
3865 }
3866 /* end 301b */
3867
3868 tempbx = push1;
3869 tempbx = (unsigned short) (((tempeax & 0x0000FF00) & 0x1F00)
3870 | (tempbx & 0x00FF));
3871 tempax = (unsigned short) (((tempeax & 0x000000FF) << 8)
3872 | (tempax & 0x00FF));
3873 temp = (tempax & 0xFF00) >> 8;
3874 } else {
3875 temp = (tempax & 0x00FF) >> 8;
3876 }
3877
Aaro Koskinen8104e322011-03-13 12:26:22 +02003878 xgifb_reg_set(pVBInfo->Part2Port, 0x44, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303879 temp = (tempbx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003880 xgifb_reg_and_or(pVBInfo->Part2Port, 0x45, ~0x03F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303881 temp = tempcx & 0x00FF;
3882
3883 if (tempbx & 0x2000)
3884 temp = 0;
3885
3886 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
3887 temp |= 0x18;
3888
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003889 xgifb_reg_and_or(pVBInfo->Part2Port, 0x46, ~0x1F, temp);
Peter Huewe599801f2012-02-09 21:11:45 +01003890 if (pVBInfo->TVInfo & TVSetPAL) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303891 tempbx = 0x0382;
3892 tempcx = 0x007e;
3893 } else {
3894 tempbx = 0x0369;
3895 tempcx = 0x0061;
3896 }
3897
3898 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003899 xgifb_reg_set(pVBInfo->Part2Port, 0x4b, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303900 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003901 xgifb_reg_set(pVBInfo->Part2Port, 0x4c, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303902
3903 temp = ((tempcx & 0xFF00) >> 8) & 0x03;
3904 temp = temp << 2;
3905 temp |= ((tempbx & 0xFF00) >> 8) & 0x03;
3906
Peter Huewe599801f2012-02-09 21:11:45 +01003907 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303908 temp |= 0x10;
3909
Peter Huewe599801f2012-02-09 21:11:45 +01003910 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303911 temp |= 0x20;
3912
Peter Huewe599801f2012-02-09 21:11:45 +01003913 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303914 temp |= 0x60;
3915 }
3916
Aaro Koskinen8104e322011-03-13 12:26:22 +02003917 xgifb_reg_set(pVBInfo->Part2Port, 0x4d, temp);
Aaro Koskinen58839b02011-03-13 12:26:23 +02003918 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x43); /* 301b change */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003919 xgifb_reg_set(pVBInfo->Part2Port, 0x43, (unsigned short) (temp - 3));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303920
Peter Huewe599801f2012-02-09 21:11:45 +01003921 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303922 if (pVBInfo->TVInfo & NTSC1024x768) {
3923 TimingPoint = XGI_NTSC1024AdjTime;
3924 for (i = 0x1c, j = 0; i <= 0x30; i++, j++) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003925 xgifb_reg_set(pVBInfo->Part2Port, i,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303926 TimingPoint[j]);
3927 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02003928 xgifb_reg_set(pVBInfo->Part2Port, 0x43, 0x72);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303929 }
3930 }
3931
Miguel Gómez949eb0a2012-07-06 12:40:36 +02003932 /* Modify for 301C PALM Support */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303933 if (pVBInfo->VBType & VB_XGI301C) {
Peter Huewe599801f2012-02-09 21:11:45 +01003934 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003935 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x08,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303936 0x08); /* PALM Mode */
3937 }
3938
Peter Huewe599801f2012-02-09 21:11:45 +01003939 if (pVBInfo->TVInfo & TVSetPALM) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003940 tempax = (unsigned char) xgifb_reg_get(pVBInfo->Part2Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303941 0x01);
3942 tempax--;
Aaro Koskinendc505562011-03-13 12:26:26 +02003943 xgifb_reg_and(pVBInfo->Part2Port, 0x01, tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303944
Aaro Koskinendc505562011-03-13 12:26:26 +02003945 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xEF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303946 }
3947
Peter Huewe599801f2012-02-09 21:11:45 +01003948 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303949 if (!(pVBInfo->VBInfo & SetInSlaveMode))
Aaro Koskinen8104e322011-03-13 12:26:22 +02003950 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303951 }
3952
3953 if (pVBInfo->VBInfo & SetCRT2ToTV)
3954 return;
3955}
3956
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003957static void XGI_SetLCDRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303958 struct xgi_hw_device_info *HwDeviceExtension,
3959 unsigned short RefreshRateTableIndex,
3960 struct vb_device_info *pVBInfo)
3961{
3962 unsigned short push1, push2, pushbx, tempax, tempbx, tempcx, temp,
3963 tempah, tempbh, tempch, resinfo, modeflag, CRT1Index;
3964
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02003965 struct XGI_LCDDesStruct const *LCDBDesPtr = NULL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303966
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003967 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02003968 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3969 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinena39325d2012-11-04 21:14:53 +02003970 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003971 CRT1Index &= IndexMask;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303972
3973 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
3974 return;
3975
3976 tempbx = pVBInfo->HDE; /* RHACTE=HDE-1 */
3977
3978 if (XGI_IsLCDDualLink(pVBInfo))
3979 tempbx = tempbx >> 1;
3980
3981 tempbx -= 1;
3982 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003983 xgifb_reg_set(pVBInfo->Part2Port, 0x2C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303984 temp = (tempbx & 0xFF00) >> 8;
3985 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003986 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2B, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303987 temp = 0x01;
3988
Aaro Koskinen8104e322011-03-13 12:26:22 +02003989 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303990 tempbx = pVBInfo->VDE; /* RTVACTEO=(VDE-1)&0xFF */
3991 push1 = tempbx;
3992 tempbx--;
3993 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003994 xgifb_reg_set(pVBInfo->Part2Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303995 temp = ((tempbx & 0xFF00) >> 8) & 0x07;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003996 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0C, ~0x07, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303997
3998 tempcx = pVBInfo->VT - 1;
3999 push2 = tempcx + 1;
4000 temp = tempcx & 0x00FF; /* RVTVT=VT-1 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004001 xgifb_reg_set(pVBInfo->Part2Port, 0x19, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304002 temp = (tempcx & 0xFF00) >> 8;
4003 temp = temp << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004004 xgifb_reg_set(pVBInfo->Part2Port, 0x1A, temp);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004005 xgifb_reg_and_or(pVBInfo->Part2Port, 0x09, 0xF0, 0x00);
4006 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xF0, 0x00);
4007 xgifb_reg_and_or(pVBInfo->Part2Port, 0x17, 0xFB, 0x00);
4008 xgifb_reg_and_or(pVBInfo->Part2Port, 0x18, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304009
Justin P. Mattock558f7582012-10-02 21:17:11 -07004010 /* Customized LCDB Does not add */
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02004011 if ((pVBInfo->VBType & VB_SIS301LV) || (pVBInfo->VBType & VB_SIS302LV))
4012 LCDBDesPtr = XGI_GetLcdPtr(xgifb_lcddldes, ModeNo, ModeIdIndex,
4013 RefreshRateTableIndex, pVBInfo);
4014 else
4015 LCDBDesPtr = XGI_GetLcdPtr(XGI_LCDDesDataTable, ModeNo,
4016 ModeIdIndex, RefreshRateTableIndex,
4017 pVBInfo);
4018
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304019 tempah = pVBInfo->LCDResInfo;
4020 tempah &= PanelResInfo;
4021
Peter Huewe255aabd2012-02-09 21:11:44 +01004022 if ((tempah == Panel_1024x768) || (tempah == Panel_1024x768x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304023 tempbx = 1024;
4024 tempcx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01004025 } else if ((tempah == Panel_1280x1024) ||
4026 (tempah == Panel_1280x1024x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304027 tempbx = 1280;
4028 tempcx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01004029 } else if (tempah == Panel_1400x1050) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304030 tempbx = 1400;
4031 tempcx = 1050;
4032 } else {
4033 tempbx = 1600;
4034 tempcx = 1200;
4035 }
4036
4037 if (pVBInfo->LCDInfo & EnableScalingLCD) {
4038 tempbx = pVBInfo->HDE;
4039 tempcx = pVBInfo->VDE;
4040 }
4041
4042 pushbx = tempbx;
4043 tempax = pVBInfo->VT;
4044 pVBInfo->LCDHDES = LCDBDesPtr->LCDHDES;
4045 pVBInfo->LCDHRS = LCDBDesPtr->LCDHRS;
4046 pVBInfo->LCDVDES = LCDBDesPtr->LCDVDES;
4047 pVBInfo->LCDVRS = LCDBDesPtr->LCDVRS;
4048 tempbx = pVBInfo->LCDVDES;
4049 tempcx += tempbx;
4050
4051 if (tempcx >= tempax)
4052 tempcx -= tempax; /* lcdvdes */
4053
4054 temp = tempbx & 0x00FF; /* RVEQ1EQ=lcdvdes */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004055 xgifb_reg_set(pVBInfo->Part2Port, 0x05, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304056 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004057 xgifb_reg_set(pVBInfo->Part2Port, 0x06, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304058 tempch = ((tempcx & 0xFF00) >> 8) & 0x07;
4059 tempbh = ((tempbx & 0xFF00) >> 8) & 0x07;
4060 tempah = tempch;
4061 tempah = tempah << 3;
4062 tempah |= tempbh;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004063 xgifb_reg_set(pVBInfo->Part2Port, 0x02, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304064
4065 /* getlcdsync() */
4066 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
4067 tempcx = tempbx;
4068 tempax = pVBInfo->VT;
4069 tempbx = pVBInfo->LCDVRS;
4070
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304071 tempcx += tempbx;
4072 if (tempcx >= tempax)
4073 tempcx -= tempax;
4074
4075 temp = tempbx & 0x00FF; /* RTVACTEE=lcdvrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004076 xgifb_reg_set(pVBInfo->Part2Port, 0x04, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304077 temp = (tempbx & 0xFF00) >> 8;
4078 temp = temp << 4;
4079 temp |= (tempcx & 0x000F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004080 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304081 tempcx = pushbx;
4082 tempax = pVBInfo->HT;
4083 tempbx = pVBInfo->LCDHDES;
4084 tempbx &= 0x0FFF;
4085
4086 if (XGI_IsLCDDualLink(pVBInfo)) {
4087 tempax = tempax >> 1;
4088 tempbx = tempbx >> 1;
4089 tempcx = tempcx >> 1;
4090 }
4091
Peter Huewe6896b942012-02-09 21:11:46 +01004092 if (pVBInfo->VBType & VB_SIS302LV)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304093 tempbx += 1;
4094
4095 if (pVBInfo->VBType & VB_XGI301C) /* tap4 */
4096 tempbx += 1;
4097
4098 tempcx += tempbx;
4099
4100 if (tempcx >= tempax)
4101 tempcx -= tempax;
4102
4103 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004104 xgifb_reg_set(pVBInfo->Part2Port, 0x1F, temp); /* RHBLKE=lcdhdes */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304105 temp = ((tempbx & 0xFF00) >> 8) << 4;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004106 xgifb_reg_set(pVBInfo->Part2Port, 0x20, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304107 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004108 xgifb_reg_set(pVBInfo->Part2Port, 0x23, temp); /* RHEQPLE=lcdhdee */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304109 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004110 xgifb_reg_set(pVBInfo->Part2Port, 0x25, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304111
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304112 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
4113 tempcx = tempax;
4114 tempax = pVBInfo->HT;
4115 tempbx = pVBInfo->LCDHRS;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304116 if (XGI_IsLCDDualLink(pVBInfo)) {
4117 tempax = tempax >> 1;
4118 tempbx = tempbx >> 1;
4119 tempcx = tempcx >> 1;
4120 }
4121
Peter Huewe6896b942012-02-09 21:11:46 +01004122 if (pVBInfo->VBType & VB_SIS302LV)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304123 tempbx += 1;
4124
4125 tempcx += tempbx;
4126
4127 if (tempcx >= tempax)
4128 tempcx -= tempax;
4129
4130 temp = tempbx & 0x00FF; /* RHBURSTS=lcdhrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004131 xgifb_reg_set(pVBInfo->Part2Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304132
4133 temp = (tempbx & 0xFF00) >> 8;
4134 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004135 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304136 temp = tempcx & 0x00FF; /* RHSYEXP2S=lcdhre */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004137 xgifb_reg_set(pVBInfo->Part2Port, 0x21, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304138
Peter Huewea3d675c2012-02-09 21:11:47 +01004139 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304140 if (pVBInfo->VGAVDE == 525) {
Peter Huewe6896b942012-02-09 21:11:46 +01004141 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
4142 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304143 | VB_XGI301C)) {
4144 temp = 0xC6;
4145 } else
4146 temp = 0xC4;
4147
Aaro Koskinen8104e322011-03-13 12:26:22 +02004148 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
4149 xgifb_reg_set(pVBInfo->Part2Port, 0x30, 0xB3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304150 }
4151
4152 if (pVBInfo->VGAVDE == 420) {
Peter Huewe6896b942012-02-09 21:11:46 +01004153 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
4154 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304155 | VB_XGI301C)) {
4156 temp = 0x4F;
4157 } else
4158 temp = 0x4E;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004159 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304160 }
4161 }
4162}
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004163
4164/* --------------------------------------------------------------------- */
4165/* Function : XGI_GetTap4Ptr */
4166/* Input : */
4167/* Output : di -> Tap4 Reg. Setting Pointer */
4168/* Description : */
4169/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004170static struct XGI301C_Tap4TimingStruct *XGI_GetTap4Ptr(unsigned short tempcx,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304171 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004172{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304173 unsigned short tempax, tempbx, i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004174
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304175 struct XGI301C_Tap4TimingStruct *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004176
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304177 if (tempcx == 0) {
4178 tempax = pVBInfo->VGAHDE;
4179 tempbx = pVBInfo->HDE;
4180 } else {
4181 tempax = pVBInfo->VGAVDE;
4182 tempbx = pVBInfo->VDE;
4183 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004184
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004185 if (tempax <= tempbx)
4186 return &xgifb_tap4_timing[0];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304187 else
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004188 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing; /* NTSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004189
Peter Huewe599801f2012-02-09 21:11:45 +01004190 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304191 Tap4TimingPtr = PALTap4Timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004192
Peter Huewe599801f2012-02-09 21:11:45 +01004193 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
4194 if ((pVBInfo->TVInfo & TVSetYPbPr525i) ||
4195 (pVBInfo->TVInfo & TVSetYPbPr525p))
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004196 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing;
Peter Huewe599801f2012-02-09 21:11:45 +01004197 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304198 Tap4TimingPtr = YPbPr750pTap4Timing;
4199 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004200
Peter Huewe599801f2012-02-09 21:11:45 +01004201 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004202 Tap4TimingPtr = xgifb_tap4_timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004203
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304204 i = 0;
4205 while (Tap4TimingPtr[i].DE != 0xFFFF) {
4206 if (Tap4TimingPtr[i].DE == tempax)
4207 break;
4208 i++;
4209 }
4210 return &Tap4TimingPtr[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004211}
4212
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004213static void XGI_SetTap4Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004214{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304215 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004216
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304217 struct XGI301C_Tap4TimingStruct *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004218
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304219 if (!(pVBInfo->VBType & VB_XGI301C))
4220 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004221
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304222 Tap4TimingPtr = XGI_GetTap4Ptr(0, pVBInfo); /* Set Horizontal Scaling */
4223 for (i = 0x80, j = 0; i <= 0xBF; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004224 xgifb_reg_set(pVBInfo->Part2Port, i, Tap4TimingPtr->Reg[j]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004225
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004226 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
Peter Huewe599801f2012-02-09 21:11:45 +01004227 (!(pVBInfo->VBInfo & SetCRT2ToHiVision))) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004228 /* Set Vertical Scaling */
4229 Tap4TimingPtr = XGI_GetTap4Ptr(1, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304230 for (i = 0xC0, j = 0; i < 0xFF; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004231 xgifb_reg_set(pVBInfo->Part2Port,
4232 i,
4233 Tap4TimingPtr->Reg[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304234 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004235
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004236 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
Peter Huewe599801f2012-02-09 21:11:45 +01004237 (!(pVBInfo->VBInfo & SetCRT2ToHiVision)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004238 /* Enable V.Scaling */
4239 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304240 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004241 /* Enable H.Scaling */
4242 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x10);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004243}
4244
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004245static void XGI_SetGroup3(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304246 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004247{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304248 unsigned short i;
Aaro Koskinend21222d2012-09-11 00:15:29 +03004249 unsigned char const *tempdi;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304250 unsigned short modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004251
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004252 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004253 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004254
Aaro Koskinen8104e322011-03-13 12:26:22 +02004255 xgifb_reg_set(pVBInfo->Part3Port, 0x00, 0x00);
Peter Huewe599801f2012-02-09 21:11:45 +01004256 if (pVBInfo->TVInfo & TVSetPAL) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004257 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
4258 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304259 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004260 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xF5);
4261 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xB7);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304262 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004263
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304264 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
4265 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004266
Peter Huewe599801f2012-02-09 21:11:45 +01004267 if (pVBInfo->TVInfo & TVSetPALM) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004268 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
4269 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
4270 xgifb_reg_set(pVBInfo->Part3Port, 0x3D, 0xA8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304271 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004272
Peter Huewe599801f2012-02-09 21:11:45 +01004273 if ((pVBInfo->VBInfo & SetCRT2ToHiVision) || (pVBInfo->VBInfo
4274 & SetCRT2ToYPbPr525750)) {
4275 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304276 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004277
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004278 tempdi = XGI330_HiTVGroup3Data;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304279 if (pVBInfo->SetFlag & TVSimuMode) {
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004280 tempdi = XGI330_HiTVGroup3Simu;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304281 if (!(modeflag & Charx8Dot))
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004282 tempdi = XGI330_HiTVGroup3Text;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304283 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004284
Peter Huewe599801f2012-02-09 21:11:45 +01004285 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004286 tempdi = XGI330_Ren525pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004287
Peter Huewe599801f2012-02-09 21:11:45 +01004288 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004289 tempdi = XGI330_Ren750pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004290
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304291 for (i = 0; i <= 0x3E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004292 xgifb_reg_set(pVBInfo->Part3Port, i, tempdi[i]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004293
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304294 if (pVBInfo->VBType & VB_XGI301C) { /* Marcovision */
Peter Huewe599801f2012-02-09 21:11:45 +01004295 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004296 xgifb_reg_set(pVBInfo->Part3Port, 0x28, 0x3f);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304297 }
4298 }
4299 return;
4300} /* {end of XGI_SetGroup3} */
4301
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004302static void XGI_SetGroup4(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304303 unsigned short RefreshRateTableIndex,
4304 struct xgi_hw_device_info *HwDeviceExtension,
4305 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004306{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304307 unsigned short tempax, tempcx, tempbx, modeflag, temp, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004308
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304309 unsigned long tempebx, tempeax, templong;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004310
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004311 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004312 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304313 temp = pVBInfo->RVBHCFACT;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004314 xgifb_reg_set(pVBInfo->Part4Port, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004315
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304316 tempbx = pVBInfo->RVBHCMAX;
4317 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004318 xgifb_reg_set(pVBInfo->Part4Port, 0x14, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304319 temp2 = ((tempbx & 0xFF00) >> 8) << 7;
4320 tempcx = pVBInfo->VGAHT - 1;
4321 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004322 xgifb_reg_set(pVBInfo->Part4Port, 0x16, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004323
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304324 temp = ((tempcx & 0xFF00) >> 8) << 3;
4325 temp2 |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004326
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304327 tempcx = pVBInfo->VGAVT - 1;
4328 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
4329 tempcx -= 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004330
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304331 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004332 xgifb_reg_set(pVBInfo->Part4Port, 0x17, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304333 temp = temp2 | ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004334 xgifb_reg_set(pVBInfo->Part4Port, 0x15, temp);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004335 xgifb_reg_or(pVBInfo->Part4Port, 0x0D, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304336 tempcx = pVBInfo->VBInfo;
4337 tempbx = pVBInfo->VGAHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004338
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304339 if (modeflag & HalfDCLK)
4340 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004341
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304342 if (XGI_IsLCDDualLink(pVBInfo))
4343 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004344
Peter Huewe599801f2012-02-09 21:11:45 +01004345 if (tempcx & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304346 temp = 0;
4347 if (tempbx <= 1024)
4348 temp = 0xA0;
4349 if (tempbx == 1280)
4350 temp = 0xC0;
4351 } else if (tempcx & SetCRT2ToTV) {
4352 temp = 0xA0;
4353 if (tempbx <= 800)
4354 temp = 0x80;
4355 } else {
4356 temp = 0x80;
4357 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4358 temp = 0;
4359 if (tempbx > 800)
4360 temp = 0x60;
4361 }
4362 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004363
Peter Huewe599801f2012-02-09 21:11:45 +01004364 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304365 temp = 0x00;
4366 if (pVBInfo->VGAHDE == 1280)
4367 temp = 0x40;
4368 if (pVBInfo->VGAHDE == 1024)
4369 temp = 0x20;
4370 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004371 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0E, ~0xEF, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004372
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304373 tempebx = pVBInfo->VDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004374
Peter Huewe599801f2012-02-09 21:11:45 +01004375 if (tempcx & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304376 if (!(temp & 0xE000))
4377 tempbx = tempbx >> 1;
4378 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004379
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304380 tempcx = pVBInfo->RVBHRS;
4381 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004382 xgifb_reg_set(pVBInfo->Part4Port, 0x18, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004383
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304384 tempeax = pVBInfo->VGAVDE;
4385 tempcx |= 0x04000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004386
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304387 if (tempeax <= tempebx) {
4388 tempcx = (tempcx & (~0x4000));
4389 tempeax = pVBInfo->VGAVDE;
4390 } else {
4391 tempeax -= tempebx;
4392 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004393
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304394 templong = (tempeax * 256 * 1024) % tempebx;
4395 tempeax = (tempeax * 256 * 1024) / tempebx;
4396 tempebx = tempeax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004397
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304398 if (templong != 0)
4399 tempebx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004400
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304401 temp = (unsigned short) (tempebx & 0x000000FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004402 xgifb_reg_set(pVBInfo->Part4Port, 0x1B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004403
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304404 temp = (unsigned short) ((tempebx & 0x0000FF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004405 xgifb_reg_set(pVBInfo->Part4Port, 0x1A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304406 tempbx = (unsigned short) (tempebx >> 16);
4407 temp = tempbx & 0x00FF;
4408 temp = temp << 4;
4409 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004410 xgifb_reg_set(pVBInfo->Part4Port, 0x19, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004411
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304412 /* 301b */
Peter Huewe6896b942012-02-09 21:11:46 +01004413 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4414 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304415 temp = 0x0028;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004416 xgifb_reg_set(pVBInfo->Part4Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304417 tempax = pVBInfo->VGAHDE;
4418 if (modeflag & HalfDCLK)
4419 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004420
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304421 if (XGI_IsLCDDualLink(pVBInfo))
4422 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004423
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304424 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4425 if (tempax > 800)
4426 tempax -= 800;
Aaro Koskinend3ae5762012-09-11 00:15:27 +03004427 } else if (pVBInfo->VGAHDE > 800) {
4428 if (pVBInfo->VGAHDE == 1024)
4429 tempax = (tempax * 25 / 32) - 1;
4430 else
4431 tempax = (tempax * 20 / 32) - 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304432 }
4433 tempax -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004434
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304435 temp = (tempax & 0xFF00) >> 8;
4436 temp = ((temp & 0x0003) << 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004437 xgifb_reg_set(pVBInfo->Part4Port, 0x1E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304438 temp = (tempax & 0x00FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004439 xgifb_reg_set(pVBInfo->Part4Port, 0x1D, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004440
Peter Huewe599801f2012-02-09 21:11:45 +01004441 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToHiVision)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304442 if (pVBInfo->VGAHDE > 800)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004443 xgifb_reg_or(pVBInfo->Part4Port, 0x1E, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004444
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304445 }
4446 temp = 0x0036;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004447
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304448 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4449 if (!(pVBInfo->TVInfo & (NTSC1024x768
Peter Huewe599801f2012-02-09 21:11:45 +01004450 | TVSetYPbPr525p | TVSetYPbPr750p
4451 | TVSetHiVision))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304452 temp |= 0x0001;
4453 if ((pVBInfo->VBInfo & SetInSlaveMode)
4454 && (!(pVBInfo->TVInfo
4455 & TVSimuMode)))
4456 temp &= (~0x0001);
4457 }
4458 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004459
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004460 xgifb_reg_and_or(pVBInfo->Part4Port, 0x1F, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304461 tempbx = pVBInfo->HT;
4462 if (XGI_IsLCDDualLink(pVBInfo))
4463 tempbx = tempbx >> 1;
4464 tempbx = (tempbx >> 1) - 2;
4465 temp = ((tempbx & 0x0700) >> 8) << 3;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004466 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304467 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004468 xgifb_reg_set(pVBInfo->Part4Port, 0x22, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304469 }
4470 /* end 301b */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004471
Aaro Koskinen8951dad2012-09-11 00:15:30 +03004472 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004473}
4474
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004475static void XGINew_EnableCRT2(struct vb_device_info *pVBInfo)
4476{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004477 xgifb_reg_and_or(pVBInfo->P3c4, 0x1E, 0xFF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004478}
4479
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004480static void XGI_SetGroup5(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304481 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004482{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304483 unsigned short Pindex, Pdata;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004484
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304485 Pindex = pVBInfo->Part5Port;
4486 Pdata = pVBInfo->Part5Port + 1;
4487 if (pVBInfo->ModeType == ModeVGA) {
4488 if (!(pVBInfo->VBInfo & (SetInSlaveMode | LoadDACFlag
Peter Huewe6896b942012-02-09 21:11:46 +01004489 | DisableCRT2Display))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304490 XGINew_EnableCRT2(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304491 }
4492 }
4493 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004494}
4495
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004496static void XGI_EnableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304497 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004498{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004499 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x40);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004500}
4501
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004502static void XGI_DisableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304503 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004504{
4505
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004506 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004507}
4508
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004509static unsigned char XGI_XG21CheckLVDSMode(struct xgifb_video_info *xgifb_info,
4510 unsigned short ModeNo, unsigned short ModeIdIndex,
4511 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004512{
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004513 unsigned short xres, yres, colordepth, modeflag, resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004514
Aaro Koskinenb3979922012-11-04 21:14:52 +02004515 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004516 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
4517 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
4518 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004519 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004520
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304521 if (!(modeflag & Charx8Dot)) {
4522 xres /= 9;
4523 xres *= 8;
4524 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004525
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004526 if ((ModeNo > 0x13) && (modeflag & HalfDCLK))
4527 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004528
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004529 if ((ModeNo > 0x13) && (modeflag & DoubleScanMode))
4530 yres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004531
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004532 if (xres > xgifb_info->lvds_data.LVDSHDE)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304533 return 0;
Bill Pembertondda08c52010-06-17 13:10:42 -04004534
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004535 if (yres > xgifb_info->lvds_data.LVDSVDE)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304536 return 0;
4537
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004538 if (xres != xgifb_info->lvds_data.LVDSHDE ||
4539 yres != xgifb_info->lvds_data.LVDSVDE) {
4540 colordepth = XGI_GetColorDepth(ModeNo, ModeIdIndex, pVBInfo);
4541 if (colordepth > 2)
4542 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304543 }
4544 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004545}
4546
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004547static void xgifb_set_lvds(struct xgifb_video_info *xgifb_info,
4548 int chip_id,
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004549 unsigned short ModeNo,
4550 unsigned short ModeIdIndex,
4551 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004552{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304553 unsigned char temp, Miscdata;
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004554 unsigned short xres, yres, modeflag, resindex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304555 unsigned short LVDSHT, LVDSHBS, LVDSHRS, LVDSHRE, LVDSHBE;
4556 unsigned short LVDSVT, LVDSVBS, LVDSVRS, LVDSVRE, LVDSVBE;
4557 unsigned short value;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004558
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004559 temp = (unsigned char) ((xgifb_info->lvds_data.LVDS_Capability &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004560 (LCDPolarity << 8)) >> 8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304561 temp &= LCDPolarity;
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004562 Miscdata = (unsigned char) inb(pVBInfo->P3cc);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004563
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004564 outb((Miscdata & 0x3F) | temp, pVBInfo->P3c2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004565
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004566 temp = xgifb_info->lvds_data.LVDS_Capability & LCDPolarity;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004567 /* SR35[7] FP VSync polarity */
4568 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x80, temp & 0x80);
4569 /* SR30[5] FP HSync polarity */
4570 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, ~0x20, (temp & 0x40) >> 1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004571
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004572 if (chip_id == XG27)
4573 XGI_SetXG27FPBits(pVBInfo);
4574 else
4575 XGI_SetXG21FPBits(pVBInfo);
4576
Aaro Koskinenb3979922012-11-04 21:14:52 +02004577 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004578 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
4579 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
4580 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004581 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004582
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304583 if (!(modeflag & Charx8Dot))
4584 xres = xres * 8 / 9;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004585
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004586 LVDSHT = xgifb_info->lvds_data.LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004587
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004588 LVDSHBS = xres + (xgifb_info->lvds_data.LVDSHDE - xres) / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004589
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304590 if (LVDSHBS > LVDSHT)
4591 LVDSHBS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004592
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004593 LVDSHRS = LVDSHBS + xgifb_info->lvds_data.LVDSHFP;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304594 if (LVDSHRS > LVDSHT)
4595 LVDSHRS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004596
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004597 LVDSHRE = LVDSHRS + xgifb_info->lvds_data.LVDSHSYNC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304598 if (LVDSHRE > LVDSHT)
4599 LVDSHRE -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004600
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004601 LVDSHBE = LVDSHBS + LVDSHT - xgifb_info->lvds_data.LVDSHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004602
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004603 LVDSVT = xgifb_info->lvds_data.LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004604
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004605 LVDSVBS = yres + (xgifb_info->lvds_data.LVDSVDE - yres) / 2;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004606 if (modeflag & DoubleScanMode)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304607 LVDSVBS += yres / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004608
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304609 if (LVDSVBS > LVDSVT)
4610 LVDSVBS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004611
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004612 LVDSVRS = LVDSVBS + xgifb_info->lvds_data.LVDSVFP;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304613 if (LVDSVRS > LVDSVT)
4614 LVDSVRS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004615
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004616 LVDSVRE = LVDSVRS + xgifb_info->lvds_data.LVDSVSYNC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304617 if (LVDSVRE > LVDSVT)
4618 LVDSVRE -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004619
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004620 LVDSVBE = LVDSVBS + LVDSVT - xgifb_info->lvds_data.LVDSVDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004621
Aaro Koskinen58839b02011-03-13 12:26:23 +02004622 temp = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004623 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp & 0x7f); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004624
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304625 if (!(modeflag & Charx8Dot))
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004626 xgifb_reg_or(pVBInfo->P3c4, 0x1, 0x1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004627
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304628 /* HT SR0B[1:0] CR00 */
4629 value = (LVDSHT >> 3) - 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004630 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004631 xgifb_reg_set(pVBInfo->P3d4, 0x0, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004632
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304633 /* HBS SR0B[5:4] CR02 */
4634 value = (LVDSHBS >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004635 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x30, (value & 0x300) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004636 xgifb_reg_set(pVBInfo->P3d4, 0x2, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004637
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304638 /* HBE SR0C[1:0] CR05[7] CR03[4:0] */
4639 value = (LVDSHBE >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004640 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x03, (value & 0xC0) >> 6);
4641 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x80, (value & 0x20) << 2);
4642 xgifb_reg_and_or(pVBInfo->P3d4, 0x03, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004643
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304644 /* HRS SR0B[7:6] CR04 */
4645 value = (LVDSHRS >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004646 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0xC0, (value & 0x300) >> 2);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004647 xgifb_reg_set(pVBInfo->P3d4, 0x4, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004648
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304649 /* Panel HRS SR2F[1:0] SR2E[7:0] */
4650 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004651 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004652 xgifb_reg_set(pVBInfo->P3c4, 0x2E, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004653
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304654 /* HRE SR0C[2] CR05[4:0] */
4655 value = (LVDSHRE >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004656 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x04, (value & 0x20) >> 3);
4657 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004658
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304659 /* Panel HRE SR2F[7:2] */
4660 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004661 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0xFC, value << 2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004662
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304663 /* VT SR0A[0] CR07[5][0] CR06 */
4664 value = LVDSVT - 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004665 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x01, (value & 0x400) >> 10);
4666 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x20, (value & 0x200) >> 4);
4667 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x01, (value & 0x100) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004668 xgifb_reg_set(pVBInfo->P3d4, 0x06, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004669
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304670 /* VBS SR0A[2] CR09[5] CR07[3] CR15 */
4671 value = LVDSVBS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004672 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x04, (value & 0x400) >> 8);
4673 xgifb_reg_and_or(pVBInfo->P3d4, 0x09, ~0x20, (value & 0x200) >> 4);
4674 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x08, (value & 0x100) >> 5);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004675 xgifb_reg_set(pVBInfo->P3d4, 0x15, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004676
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304677 /* VBE SR0A[4] CR16 */
4678 value = LVDSVBE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004679 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x10, (value & 0x100) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004680 xgifb_reg_set(pVBInfo->P3d4, 0x16, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004681
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304682 /* VRS SR0A[3] CR7[7][2] CR10 */
4683 value = LVDSVRS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004684 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x08, (value & 0x400) >> 7);
4685 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x80, (value & 0x200) >> 2);
4686 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x04, (value & 0x100) >> 6);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004687 xgifb_reg_set(pVBInfo->P3d4, 0x10, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004688
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004689 if (chip_id == XG27) {
4690 /* Panel VRS SR35[2:0] SR34[7:0] */
4691 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07,
4692 (value & 0x700) >> 8);
4693 xgifb_reg_set(pVBInfo->P3c4, 0x34, value & 0xFF);
4694 } else {
4695 /* Panel VRS SR3F[1:0] SR34[7:0] SR33[0] */
4696 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0x03,
4697 (value & 0x600) >> 9);
4698 xgifb_reg_set(pVBInfo->P3c4, 0x34, (value >> 1) & 0xFF);
4699 xgifb_reg_and_or(pVBInfo->P3d4, 0x33, ~0x01, value & 0x01);
4700 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004701
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304702 /* VRE SR0A[5] CR11[3:0] */
4703 value = LVDSVRE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004704 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x20, (value & 0x10) << 1);
4705 xgifb_reg_and_or(pVBInfo->P3d4, 0x11, ~0x0F, value & 0x0F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004706
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304707 /* Panel VRE SR3F[7:2] */
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004708 if (chip_id == XG27)
4709 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
4710 (value << 2) & 0xFC);
4711 else
4712 /* SR3F[7] has to be 0, h/w bug */
4713 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
4714 (value << 2) & 0x7C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004715
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304716 for (temp = 0, value = 0; temp < 3; temp++) {
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004717
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004718 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, value);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004719 xgifb_reg_set(pVBInfo->P3c4,
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004720 0x2B, xgifb_info->lvds_data.VCLKData1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004721 xgifb_reg_set(pVBInfo->P3c4,
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004722 0x2C, xgifb_info->lvds_data.VCLKData2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304723 value += 0x10;
4724 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004725
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304726 if (!(modeflag & Charx8Dot)) {
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004727 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004728 outb(0x13, pVBInfo->P3c0); /* set index */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004729 /* set data, panning = 0, shift left 1 dot*/
4730 outb(0x00, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004731
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004732 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004733 outb(0x20, pVBInfo->P3c0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304734
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004735 inb(pVBInfo->P3da); /* reset 3da */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304736 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004737
4738}
4739
4740/* --------------------------------------------------------------------- */
4741/* Function : XGI_IsLCDON */
4742/* Input : */
Bill Pembertondda08c52010-06-17 13:10:42 -04004743/* Output : 0 : Skip PSC Control */
4744/* 1: Disable PSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004745/* Description : */
4746/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004747static unsigned char XGI_IsLCDON(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004748{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304749 unsigned short tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004750
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304751 tempax = pVBInfo->VBInfo;
4752 if (tempax & SetCRT2ToDualEdge)
4753 return 0;
Peter Huewe6896b942012-02-09 21:11:46 +01004754 else if (tempax & (DisableCRT2Display | SwitchCRT2 | SetSimuScanMode))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304755 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004756
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304757 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004758}
4759
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004760/* --------------------------------------------------------------------- */
4761/* Function : XGI_DisableChISLCD */
4762/* Input : */
Bill Pembertondda08c52010-06-17 13:10:42 -04004763/* Output : 0 -> Not LCD Mode */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004764/* Description : */
4765/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004766static unsigned char XGI_DisableChISLCD(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004767{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304768 unsigned short tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004769
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304770 tempbx = pVBInfo->SetFlag & (DisableChA | DisableChB);
Aaro Koskinen58839b02011-03-13 12:26:23 +02004771 tempah = ~((unsigned short) xgifb_reg_get(pVBInfo->Part1Port, 0x2E));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004772
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304773 if (tempbx & (EnableChA | DisableChA)) {
4774 if (!(tempah & 0x08)) /* Chk LCDA Mode */
4775 return 0;
4776 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004777
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304778 if (!(tempbx & (EnableChB | DisableChB)))
4779 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004780
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304781 if (tempah & 0x01) /* Chk LCDB Mode */
4782 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004783
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304784 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004785}
4786
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004787/* --------------------------------------------------------------------- */
4788/* Function : XGI_EnableChISLCD */
4789/* Input : */
4790/* Output : 0 -> Not LCD mode */
4791/* Description : */
4792/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004793static unsigned char XGI_EnableChISLCD(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004794{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304795 unsigned short tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004796
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304797 tempbx = pVBInfo->SetFlag & (EnableChA | EnableChB);
Aaro Koskinen58839b02011-03-13 12:26:23 +02004798 tempah = ~((unsigned short) xgifb_reg_get(pVBInfo->Part1Port, 0x2E));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004799
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304800 if (tempbx & (EnableChA | DisableChA)) {
4801 if (!(tempah & 0x08)) /* Chk LCDA Mode */
4802 return 0;
4803 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004804
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304805 if (!(tempbx & (EnableChB | DisableChB)))
Bill Pembertondda08c52010-06-17 13:10:42 -04004806 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004807
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304808 if (tempah & 0x01) /* Chk LCDB Mode */
4809 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004810
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304811 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004812}
4813
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004814static void XGI_DisableBridge(struct xgifb_video_info *xgifb_info,
4815 struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304816 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004817{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02004818 unsigned short tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004819
Peter Huewe6896b942012-02-09 21:11:46 +01004820 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4821 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304822 tempah = 0x3F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004823 if (!(pVBInfo->VBInfo &
4824 (DisableCRT2Display | SetSimuScanMode))) {
Peter Huewea3d675c2012-02-09 21:11:47 +01004825 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304826 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
4827 tempah = 0x7F; /* Disable Channel A */
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004828 if (!(pVBInfo->VBInfo &
4829 XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004830 /* Disable Channel B */
4831 tempah = 0xBF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004832
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304833 if (pVBInfo->SetFlag & DisableChB)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004834 /* force to disable Cahnnel */
4835 tempah &= 0xBF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004836
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304837 if (pVBInfo->SetFlag & DisableChA)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004838 /* Force to disable Channel B */
4839 tempah &= 0x7F;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304840 }
4841 }
4842 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004843
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004844 /* disable part4_1f */
4845 xgifb_reg_and(pVBInfo->Part4Port, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004846
Peter Huewe6896b942012-02-09 21:11:46 +01004847 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004848 if (((pVBInfo->VBInfo &
4849 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
4850 || (XGI_DisableChISLCD(pVBInfo))
4851 || (XGI_IsLCDON(pVBInfo)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004852 /* LVDS Driver power down */
4853 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304854 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004855
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304856 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
Peter Huewea3d675c2012-02-09 21:11:47 +01004857 & (DisableCRT2Display | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304858 | SetSimuScanMode))) {
4859 if (pVBInfo->SetFlag & GatingCRT)
4860 XGI_EnableGatingCRT(HwDeviceExtension, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004861 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304862 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004863
Peter Huewea3d675c2012-02-09 21:11:47 +01004864 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304865 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
Peter Huewea3d675c2012-02-09 21:11:47 +01004866 & XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004867 /* Power down */
4868 xgifb_reg_and(pVBInfo->Part1Port, 0x1e, 0xdf);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304869 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004870
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004871 /* disable TV as primary VGA swap */
4872 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004873
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304874 if ((pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToDualEdge)))
Aaro Koskinendc505562011-03-13 12:26:26 +02004875 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004876
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004877 if ((pVBInfo->SetFlag & DisableChB) ||
4878 (pVBInfo->VBInfo &
4879 (DisableCRT2Display | SetSimuScanMode)) ||
Peter Huewea3d675c2012-02-09 21:11:47 +01004880 ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) &&
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004881 (pVBInfo->VBInfo &
4882 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004883 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004884
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004885 if ((pVBInfo->SetFlag & DisableChB) ||
4886 (pVBInfo->VBInfo &
4887 (DisableCRT2Display | SetSimuScanMode)) ||
Peter Huewea3d675c2012-02-09 21:11:47 +01004888 (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) ||
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004889 (pVBInfo->VBInfo &
4890 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))) {
4891 /* save Part1 index 0 */
4892 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
4893 /* BTDAC = 1, avoid VB reset */
4894 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x10);
4895 /* disable CRT2 */
4896 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
4897 /* restore Part1 index 0 */
4898 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304899 }
4900 } else { /* {301} */
4901 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004902 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
4903 /* Disable CRT2 */
4904 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
4905 /* Disable TV asPrimary VGA swap */
4906 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xDF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304907 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004908
Peter Huewea3d675c2012-02-09 21:11:47 +01004909 if (pVBInfo->VBInfo & (DisableCRT2Display | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304910 | SetSimuScanMode))
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004911 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304912 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004913}
4914
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004915/* --------------------------------------------------------------------- */
4916/* Function : XGI_GetTVPtrIndex */
4917/* Input : */
4918/* Output : */
4919/* Description : bx 0 : ExtNTSC */
4920/* 1 : StNTSC */
4921/* 2 : ExtPAL */
4922/* 3 : StPAL */
4923/* 4 : ExtHiTV */
4924/* 5 : StHiTV */
4925/* 6 : Ext525i */
4926/* 7 : St525i */
4927/* 8 : Ext525p */
4928/* 9 : St525p */
4929/* A : Ext750p */
4930/* B : St750p */
4931/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004932static unsigned short XGI_GetTVPtrIndex(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004933{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304934 unsigned short tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004935
Peter Huewe599801f2012-02-09 21:11:45 +01004936 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304937 tempbx = 2;
Peter Huewe599801f2012-02-09 21:11:45 +01004938 if (pVBInfo->TVInfo & TVSetHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304939 tempbx = 4;
Peter Huewe599801f2012-02-09 21:11:45 +01004940 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304941 tempbx = 6;
Peter Huewe599801f2012-02-09 21:11:45 +01004942 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304943 tempbx = 8;
Peter Huewe599801f2012-02-09 21:11:45 +01004944 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304945 tempbx = 10;
4946 if (pVBInfo->TVInfo & TVSimuMode)
4947 tempbx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004948
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304949 return tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004950}
4951
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004952/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004953/* Function : XGI_GetTVPtrIndex2 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004954/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004955/* Output : bx 0 : NTSC */
4956/* 1 : PAL */
4957/* 2 : PALM */
4958/* 3 : PALN */
4959/* 4 : NTSC1024x768 */
4960/* 5 : PAL-M 1024x768 */
4961/* 6-7: reserved */
4962/* cl 0 : YFilter1 */
4963/* 1 : YFilter2 */
4964/* ch 0 : 301A */
4965/* 1 : 301B/302B/301LV/302LV */
4966/* Description : */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004967/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004968static void XGI_GetTVPtrIndex2(unsigned short *tempbx, unsigned char *tempcl,
4969 unsigned char *tempch, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004970{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004971 *tempbx = 0;
4972 *tempcl = 0;
4973 *tempch = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004974
Peter Huewe599801f2012-02-09 21:11:45 +01004975 if (pVBInfo->TVInfo & TVSetPAL)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004976 *tempbx = 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004977
Peter Huewe599801f2012-02-09 21:11:45 +01004978 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004979 *tempbx = 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004980
Peter Huewe599801f2012-02-09 21:11:45 +01004981 if (pVBInfo->TVInfo & TVSetPALN)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004982 *tempbx = 3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004983
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004984 if (pVBInfo->TVInfo & NTSC1024x768) {
4985 *tempbx = 4;
Peter Huewe599801f2012-02-09 21:11:45 +01004986 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004987 *tempbx = 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304988 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004989
Peter Huewe6896b942012-02-09 21:11:46 +01004990 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4991 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004992 if ((!(pVBInfo->VBInfo & SetInSlaveMode)) || (pVBInfo->TVInfo
4993 & TVSimuMode)) {
4994 *tempbx += 8;
4995 *tempcl += 1;
4996 }
4997 }
4998
Peter Huewe6896b942012-02-09 21:11:46 +01004999 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5000 | VB_SIS302LV | VB_XGI301C))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005001 (*tempch)++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005002}
5003
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005004static void XGI_SetDelayComp(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005005{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305006 unsigned char tempah, tempbl, tempbh;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005007
Peter Huewe6896b942012-02-09 21:11:46 +01005008 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5009 | VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005010 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305011 | SetCRT2ToTV | SetCRT2ToRAMDAC)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305012 tempbh = 0;
Peter Huewe03f76fc2012-06-14 00:21:50 +02005013 tempbl = XGI301TVDelay;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005014
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305015 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5016 tempbl = tempbl >> 4;
Miguel Gómez3bcc2462012-07-06 12:40:53 +02005017 if (pVBInfo->VBInfo &
5018 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Peter Huewe03f76fc2012-06-14 00:21:50 +02005019 tempbh = XGI301LCDDelay;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005020
Peter Huewea3d675c2012-02-09 21:11:47 +01005021 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305022 tempbl = tempbh;
5023 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005024
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305025 tempbl &= 0x0F;
5026 tempbh &= 0xF0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02005027 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2D);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005028
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305029 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD
5030 | SetCRT2ToTV)) { /* Channel B */
5031 tempah &= 0xF0;
5032 tempah |= tempbl;
5033 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005034
Miguel Gómez3bcc2462012-07-06 12:40:53 +02005035 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
5036 /* Channel A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305037 tempah &= 0x0F;
5038 tempah |= tempbh;
5039 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02005040 xgifb_reg_set(pVBInfo->Part1Port, 0x2D, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305041 }
5042 } else if (pVBInfo->IF_DEF_LVDS == 1) {
5043 tempbl = 0;
5044 tempbh = 0;
5045 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
Peter Huewe03f76fc2012-06-14 00:21:50 +02005046 tempah = XGI301LCDDelay;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305047 tempah &= 0x0f;
5048 tempah = tempah << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005049 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2D, 0x0f,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305050 tempah);
5051 }
5052 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005053}
5054
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005055static void XGI_SetLCDCap_A(unsigned short tempcx,
5056 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005057{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305058 unsigned short temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005059
Aaro Koskinen58839b02011-03-13 12:26:23 +02005060 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005061
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305062 if (temp & LCDRGB18Bit) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005063 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005064 /* Enable Dither */
5065 (unsigned short) (0x20 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005066 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305067 } else {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005068 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305069 (unsigned short) (0x30 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005070 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305071 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005072}
5073
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005074/* --------------------------------------------------------------------- */
5075/* Function : XGI_SetLCDCap_B */
5076/* Input : cx -> LCD Capability */
5077/* Output : */
5078/* Description : */
5079/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005080static void XGI_SetLCDCap_B(unsigned short tempcx,
5081 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005082{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305083 if (tempcx & EnableLCD24bpp) /* 24bits */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005084 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305085 (unsigned short) (((tempcx & 0x00ff) >> 6)
5086 | 0x0c));
5087 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005088 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305089 (unsigned short) (((tempcx & 0x00ff) >> 6)
5090 | 0x18)); /* Enable Dither */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005091}
5092
Aaro Koskinen7f04ec32011-11-27 23:03:05 +02005093static void XGI_LongWait(struct vb_device_info *pVBInfo)
5094{
5095 unsigned short i;
5096
5097 i = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
5098
5099 if (!(i & 0xC0)) {
5100 for (i = 0; i < 0xFFFF; i++) {
5101 if (!(inb(pVBInfo->P3da) & 0x08))
5102 break;
5103 }
5104
5105 for (i = 0; i < 0xFFFF; i++) {
5106 if ((inb(pVBInfo->P3da) & 0x08))
5107 break;
5108 }
5109 }
5110}
5111
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005112static void SetSpectrum(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005113{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305114 unsigned short index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005115
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305116 index = XGI_GetLCDCapPtr(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005117
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005118 /* disable down spectrum D[4] */
5119 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x8F);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305120 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005121 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x20); /* reset spectrum */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305122 XGI_LongWait(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005123
Aaro Koskinen8104e322011-03-13 12:26:22 +02005124 xgifb_reg_set(pVBInfo->Part4Port, 0x31,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305125 pVBInfo->LCDCapList[index].Spectrum_31);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005126 xgifb_reg_set(pVBInfo->Part4Port, 0x32,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305127 pVBInfo->LCDCapList[index].Spectrum_32);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005128 xgifb_reg_set(pVBInfo->Part4Port, 0x33,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305129 pVBInfo->LCDCapList[index].Spectrum_33);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005130 xgifb_reg_set(pVBInfo->Part4Port, 0x34,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305131 pVBInfo->LCDCapList[index].Spectrum_34);
5132 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005133 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x40); /* enable spectrum */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005134}
5135
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005136static void XGI_SetLCDCap(struct vb_device_info *pVBInfo)
5137{
5138 unsigned short tempcx;
5139
5140 tempcx = pVBInfo->LCDCapList[XGI_GetLCDCapPtr(pVBInfo)].LCD_Capability;
5141
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005142 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01005143 (VB_SIS301B |
5144 VB_SIS302B |
5145 VB_SIS301LV |
5146 VB_SIS302LV |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005147 VB_XGI301C)) { /* 301LV/302LV only */
5148 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01005149 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005150 /* Set 301LV Capability */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005151 xgifb_reg_set(pVBInfo->Part4Port, 0x24,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005152 (unsigned char) (tempcx & 0x1F));
5153 }
5154 /* VB Driving */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005155 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005156 ~((EnableVBCLKDRVLOW | EnablePLLSPLOW) >> 8),
5157 (unsigned short) ((tempcx & (EnableVBCLKDRVLOW
5158 | EnablePLLSPLOW)) >> 8));
5159 }
5160
Peter Huewe6896b942012-02-09 21:11:46 +01005161 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5162 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005163 if (pVBInfo->VBInfo & SetCRT2ToLCD)
5164 XGI_SetLCDCap_B(tempcx, pVBInfo);
Peter Huewea3d675c2012-02-09 21:11:47 +01005165 else if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005166 XGI_SetLCDCap_A(tempcx, pVBInfo);
5167
Peter Huewe6896b942012-02-09 21:11:46 +01005168 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005169 if (tempcx & EnableSpectrum)
5170 SetSpectrum(pVBInfo);
5171 }
5172 } else {
5173 /* LVDS,CH7017 */
5174 XGI_SetLCDCap_A(tempcx, pVBInfo);
5175 }
5176}
5177
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005178/* --------------------------------------------------------------------- */
5179/* Function : XGI_SetAntiFlicker */
5180/* Input : */
5181/* Output : */
5182/* Description : Set TV Customized Param. */
5183/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005184static void XGI_SetAntiFlicker(unsigned short ModeNo,
5185 unsigned short ModeIdIndex,
5186 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005187{
Aaro Koskinen36ae0352012-04-07 01:14:08 +03005188 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005189
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305190 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005191
Peter Huewe599801f2012-02-09 21:11:45 +01005192 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305193 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005194
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305195 tempbx = XGI_GetTVPtrIndex(pVBInfo);
5196 tempbx &= 0xFE;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305197 tempah = TVAntiFlickList[tempbx];
5198 tempah = tempah << 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005199
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005200 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0x8F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005201}
5202
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005203static void XGI_SetEdgeEnhance(unsigned short ModeNo,
5204 unsigned short ModeIdIndex,
5205 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005206{
Aaro Koskinen354f49f2012-04-07 01:14:09 +03005207 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005208
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305209 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005210
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305211 tempbx = XGI_GetTVPtrIndex(pVBInfo);
5212 tempbx &= 0xFE;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305213 tempah = TVEdgeList[tempbx];
5214 tempah = tempah << 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005215
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005216 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005217}
5218
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005219static void XGI_SetPhaseIncr(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005220{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305221 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005222
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305223 unsigned char tempcl, tempch;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005224
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305225 unsigned long tempData;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005226
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305227 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
5228 tempData = TVPhaseList[tempbx];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005229
Aaro Koskinen8104e322011-03-13 12:26:22 +02005230 xgifb_reg_set(pVBInfo->Part2Port, 0x31, (unsigned short) (tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305231 & 0x000000FF));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005232 xgifb_reg_set(pVBInfo->Part2Port, 0x32, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305233 & 0x0000FF00) >> 8));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005234 xgifb_reg_set(pVBInfo->Part2Port, 0x33, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305235 & 0x00FF0000) >> 16));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005236 xgifb_reg_set(pVBInfo->Part2Port, 0x34, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305237 & 0xFF000000) >> 24));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005238}
5239
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005240static void XGI_SetYFilter(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305241 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005242{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305243 unsigned short tempbx, index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005244
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305245 unsigned char tempcl, tempch, tempal, *filterPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005246
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305247 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005248
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305249 switch (tempbx) {
5250 case 0x00:
5251 case 0x04:
5252 filterPtr = NTSCYFilter1;
5253 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005254
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305255 case 0x01:
5256 filterPtr = PALYFilter1;
5257 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005258
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305259 case 0x02:
5260 case 0x05:
5261 case 0x0D:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305262 case 0x03:
Aaro Koskinen2555e942011-08-31 21:46:06 +03005263 filterPtr = xgifb_palmn_yfilter1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305264 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005265
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305266 case 0x08:
5267 case 0x0C:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305268 case 0x0A:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305269 case 0x0B:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305270 case 0x09:
Aaro Koskinen80f86f82011-08-31 21:46:05 +03005271 filterPtr = xgifb_yfilter2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305272 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005273
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305274 default:
5275 return;
5276 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005277
Aaro Koskinenb3979922012-11-04 21:14:52 +02005278 tempal = XGI330_EModeIDTable[ModeIdIndex].VB_ExtTVYFilterIndex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305279 if (tempcl == 0)
5280 index = tempal * 4;
5281 else
5282 index = tempal * 7;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005283
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305284 if ((tempcl == 0) && (tempch == 1)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005285 xgifb_reg_set(pVBInfo->Part2Port, 0x35, 0);
5286 xgifb_reg_set(pVBInfo->Part2Port, 0x36, 0);
5287 xgifb_reg_set(pVBInfo->Part2Port, 0x37, 0);
5288 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305289 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005290 xgifb_reg_set(pVBInfo->Part2Port, 0x35, filterPtr[index++]);
5291 xgifb_reg_set(pVBInfo->Part2Port, 0x36, filterPtr[index++]);
5292 xgifb_reg_set(pVBInfo->Part2Port, 0x37, filterPtr[index++]);
5293 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305294 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005295
Peter Huewe6896b942012-02-09 21:11:46 +01005296 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5297 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005298 xgifb_reg_set(pVBInfo->Part2Port, 0x48, filterPtr[index++]);
5299 xgifb_reg_set(pVBInfo->Part2Port, 0x49, filterPtr[index++]);
5300 xgifb_reg_set(pVBInfo->Part2Port, 0x4A, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305301 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005302}
5303
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005304/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005305/* Function : XGI_OEM310Setting */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005306/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005307/* Output : */
5308/* Description : Customized Param. for 301 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005309/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005310static void XGI_OEM310Setting(unsigned short ModeNo,
5311 unsigned short ModeIdIndex,
5312 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005313{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005314 XGI_SetDelayComp(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005315
Peter Huewea3d675c2012-02-09 21:11:47 +01005316 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005317 XGI_SetLCDCap(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005318
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005319 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005320 XGI_SetPhaseIncr(pVBInfo);
5321 XGI_SetYFilter(ModeNo, ModeIdIndex, pVBInfo);
5322 XGI_SetAntiFlicker(ModeNo, ModeIdIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005323
Peter Huewe6896b942012-02-09 21:11:46 +01005324 if (pVBInfo->VBType & VB_SIS301)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005325 XGI_SetEdgeEnhance(ModeNo, ModeIdIndex, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305326 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005327}
5328
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005329/* --------------------------------------------------------------------- */
5330/* Function : XGI_SetCRT2ModeRegs */
5331/* Input : */
5332/* Output : */
5333/* Description : Origin code for crt2group */
5334/* --------------------------------------------------------------------- */
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02005335static void XGI_SetCRT2ModeRegs(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305336 struct xgi_hw_device_info *HwDeviceExtension,
5337 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005338{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305339 unsigned short tempbl;
5340 short tempcl;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005341
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305342 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005343
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305344 tempah = 0;
5345 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005346 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305347 tempah &= ~0x10; /* BTRAMDAC */
5348 tempah |= 0x40; /* BTRAM */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005349
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305350 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
5351 | SetCRT2ToLCD)) {
5352 tempah = 0x40; /* BTDRAM */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005353 tempcl = pVBInfo->ModeType;
5354 tempcl -= ModeVGA;
5355 if (tempcl >= 0) {
5356 /* BT Color */
5357 tempah = (0x008 >> tempcl);
5358 if (tempah == 0)
5359 tempah = 1;
5360 tempah |= 0x040;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305361 }
5362 if (pVBInfo->VBInfo & SetInSlaveMode)
5363 tempah ^= 0x50; /* BTDAC */
5364 }
5365 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005366
Aaro Koskinen8104e322011-03-13 12:26:22 +02005367 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305368 tempah = 0x08;
5369 tempbl = 0xf0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005370
Miguel Gómeze123e462012-07-06 12:40:52 +02005371 if (pVBInfo->VBInfo & DisableCRT2Display)
5372 goto reg_and_or;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005373
Miguel Gómeze123e462012-07-06 12:40:52 +02005374 tempah = 0x00;
5375 tempbl = 0xff;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005376
Miguel Gómeze123e462012-07-06 12:40:52 +02005377 if (!(pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV |
5378 SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
5379 goto reg_and_or;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005380
Miguel Gómeze123e462012-07-06 12:40:52 +02005381 if ((pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) &&
5382 (!(pVBInfo->VBInfo & SetSimuScanMode))) {
5383 tempbl &= 0xf7;
5384 tempah |= 0x01;
5385 goto reg_and_or;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305386 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005387
Miguel Gómeze123e462012-07-06 12:40:52 +02005388 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
5389 tempbl &= 0xf7;
5390 tempah |= 0x01;
5391 }
5392
5393 if (!(pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD)))
5394 goto reg_and_or;
5395
5396 tempbl &= 0xf8;
5397 tempah = 0x01;
5398
5399 if (!(pVBInfo->VBInfo & SetInSlaveMode))
5400 tempah |= 0x02;
5401
5402 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
5403 tempah = tempah ^ 0x05;
5404 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
5405 tempah = tempah ^ 0x01;
5406 }
5407
5408 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
5409 tempah |= 0x08;
5410
5411reg_and_or:
5412 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl, tempah);
5413
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305414 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD
Peter Huewea3d675c2012-02-09 21:11:47 +01005415 | XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305416 tempah &= (~0x08);
5417 if ((pVBInfo->ModeType == ModeVGA) && (!(pVBInfo->VBInfo
5418 & SetInSlaveMode))) {
5419 tempah |= 0x010;
5420 }
5421 tempah |= 0x080;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005422
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305423 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305424 tempah |= 0x020;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005425 if (pVBInfo->VBInfo & DriverMode)
5426 tempah = tempah ^ 0x20;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305427 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005428
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005429 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D, ~0x0BF, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305430 tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005431
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305432 if (pVBInfo->LCDInfo & SetLCDDualLink)
5433 tempah |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005434
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305435 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305436 if (pVBInfo->TVInfo & RPLLDIV2XO)
5437 tempah |= 0x40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305438 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005439
Peter Huewe255aabd2012-02-09 21:11:44 +01005440 if ((pVBInfo->LCDResInfo == Panel_1280x1024)
5441 || (pVBInfo->LCDResInfo == Panel_1280x1024x75))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305442 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005443
Peter Huewe255aabd2012-02-09 21:11:44 +01005444 if (pVBInfo->LCDResInfo == Panel_1280x960)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305445 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005446
Aaro Koskinen8104e322011-03-13 12:26:22 +02005447 xgifb_reg_set(pVBInfo->Part4Port, 0x0C, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305448 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005449
Peter Huewe6896b942012-02-09 21:11:46 +01005450 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5451 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305452 tempah = 0;
5453 tempbl = 0xfb;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005454
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305455 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
5456 tempbl = 0xff;
Peter Huewea3d675c2012-02-09 21:11:47 +01005457 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305458 tempah |= 0x04; /* shampoo 0129 */
5459 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005460
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005461 xgifb_reg_and_or(pVBInfo->Part1Port, 0x13, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305462 tempah = 0x00;
5463 tempbl = 0xcf;
5464 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5465 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5466 tempah |= 0x30;
5467 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005468
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005469 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2c, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305470 tempah = 0;
5471 tempbl = 0x3f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005472
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305473 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5474 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5475 tempah |= 0xc0;
5476 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005477 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305478 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005479
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305480 tempah = 0;
5481 tempbl = 0x7f;
Peter Huewea3d675c2012-02-09 21:11:47 +01005482 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305483 tempbl = 0xff;
5484 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
5485 tempah |= 0x80;
5486 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005487
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005488 xgifb_reg_and_or(pVBInfo->Part4Port, 0x23, tempbl, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005489
Peter Huewe6896b942012-02-09 21:11:46 +01005490 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305491 if (pVBInfo->LCDInfo & SetLCDDualLink) {
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005492 xgifb_reg_or(pVBInfo->Part4Port, 0x27, 0x20);
5493 xgifb_reg_or(pVBInfo->Part4Port, 0x34, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305494 }
5495 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005496}
5497
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005498
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305499void XGI_UnLockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
5500 struct vb_device_info *pVBInfo)
5501{
5502
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005503 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2f, 0xFF, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005504
5505}
5506
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305507void XGI_LockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
5508 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005509{
5510
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005511 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2F, 0xFE, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005512
5513}
5514
Bill Pemberton80adad82010-06-17 13:10:51 -04005515unsigned char XGI_BridgeIsOn(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005516{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305517 unsigned short flag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005518
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305519 if (pVBInfo->IF_DEF_LVDS == 1) {
5520 return 1;
5521 } else {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005522 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305523 if ((flag == 1) || (flag == 2))
5524 return 1; /* 301b */
5525 else
5526 return 0;
5527 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005528}
5529
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005530unsigned short XGI_GetRatePtrCRT2(struct xgi_hw_device_info *pXGIHWDE,
5531 unsigned short ModeNo, unsigned short ModeIdIndex,
5532 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005533{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005534 short LCDRefreshIndex[] = { 0x00, 0x00, 0x03, 0x01 },
5535 LCDARefreshIndex[] = { 0x00, 0x00, 0x03, 0x01, 0x01,
5536 0x01, 0x01 };
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005537
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005538 unsigned short RefreshRateTableIndex, i, modeflag, index, temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005539
Aaro Koskinenb3979922012-11-04 21:14:52 +02005540 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005541
Aaro Koskinen58839b02011-03-13 12:26:23 +02005542 index = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005543 index = index >> pVBInfo->SelectCRT2Rate;
5544 index &= 0x0F;
5545
5546 if (pVBInfo->LCDInfo & LCDNonExpanding)
5547 index = 0;
5548
5549 if (index > 0)
5550 index--;
5551
5552 if (pVBInfo->SetFlag & ProgrammingCRT2) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005553 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005554 if (pVBInfo->IF_DEF_LVDS == 0) {
Peter Huewe6896b942012-02-09 21:11:46 +01005555 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
5556 | VB_SIS301LV | VB_SIS302LV
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005557 | VB_XGI301C))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005558 /* 301b */
5559 temp = LCDARefreshIndex[
5560 pVBInfo->LCDResInfo & 0x0F];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005561 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005562 temp = LCDRefreshIndex[
5563 pVBInfo->LCDResInfo & 0x0F];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005564
5565 if (index > temp)
5566 index = temp;
5567 } else {
5568 index = 0;
5569 }
5570 }
5571 }
5572
Aaro Koskinenb3979922012-11-04 21:14:52 +02005573 RefreshRateTableIndex = XGI330_EModeIDTable[ModeIdIndex].REFindex;
Aaro Koskinena39325d2012-11-04 21:14:53 +02005574 ModeNo = XGI330_RefIndex[RefreshRateTableIndex].ModeID;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005575 if (pXGIHWDE->jChipType >= XG20) { /* for XG20, XG21, XG27 */
Aaro Koskinena39325d2012-11-04 21:14:53 +02005576 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 800) &&
5577 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 600)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005578 index++;
5579 }
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005580 /* do the similar adjustment like XGISearchCRT1Rate() */
Aaro Koskinena39325d2012-11-04 21:14:53 +02005581 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 1024) &&
5582 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 768)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005583 index++;
5584 }
Aaro Koskinena39325d2012-11-04 21:14:53 +02005585 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 1280) &&
5586 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 1024)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005587 index++;
5588 }
5589 }
5590
5591 i = 0;
5592 do {
Aaro Koskinena39325d2012-11-04 21:14:53 +02005593 if (XGI330_RefIndex[RefreshRateTableIndex + i].
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005594 ModeID != ModeNo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005595 break;
Aaro Koskinena39325d2012-11-04 21:14:53 +02005596 temp = XGI330_RefIndex[RefreshRateTableIndex + i].Ext_InfoFlag;
Peter Huewe6896b942012-02-09 21:11:46 +01005597 temp &= ModeTypeMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005598 if (temp < pVBInfo->ModeType)
5599 break;
5600 i++;
5601 index--;
5602
5603 } while (index != 0xFFFF);
5604 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
5605 if (pVBInfo->VBInfo & SetInSlaveMode) {
Aaro Koskinena39325d2012-11-04 21:14:53 +02005606 temp = XGI330_RefIndex[RefreshRateTableIndex + i - 1].
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005607 Ext_InfoFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005608 if (temp & InterlaceMode)
5609 i++;
5610 }
5611 }
5612 i--;
5613 if ((pVBInfo->SetFlag & ProgrammingCRT2)) {
5614 temp = XGI_AjustCRT2Rate(ModeNo, ModeIdIndex,
5615 RefreshRateTableIndex, &i, pVBInfo);
5616 }
Aaro Koskinen9a0b2952011-11-27 23:03:16 +02005617 return RefreshRateTableIndex + i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005618}
5619
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005620static void XGI_SetLCDAGroup(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305621 struct xgi_hw_device_info *HwDeviceExtension,
5622 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005623{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005624 unsigned short RefreshRateTableIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005625
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005626 pVBInfo->SetFlag |= ProgrammingCRT2;
5627 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5628 ModeIdIndex, pVBInfo);
5629 XGI_GetLVDSResInfo(ModeNo, ModeIdIndex, pVBInfo);
5630 XGI_GetLVDSData(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5631 XGI_ModCRT1Regs(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5632 HwDeviceExtension, pVBInfo);
5633 XGI_SetLVDSRegs(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5634 XGI_SetCRT2ECLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005635}
5636
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02005637static unsigned char XGI_SetCRT2Group301(unsigned short ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005638 struct xgi_hw_device_info *HwDeviceExtension,
5639 struct vb_device_info *pVBInfo)
5640{
5641 unsigned short tempbx, ModeIdIndex, RefreshRateTableIndex;
5642
5643 tempbx = pVBInfo->VBInfo;
5644 pVBInfo->SetFlag |= ProgrammingCRT2;
5645 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
5646 pVBInfo->SelectCRT2Rate = 4;
5647 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5648 ModeIdIndex, pVBInfo);
5649 XGI_SaveCRT2Info(ModeNo, pVBInfo);
5650 XGI_GetCRT2ResInfo(ModeNo, ModeIdIndex, pVBInfo);
5651 XGI_GetCRT2Data(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5652 XGI_PreSetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
5653 RefreshRateTableIndex, pVBInfo);
5654 XGI_SetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
5655 RefreshRateTableIndex, pVBInfo);
5656 XGI_SetLockRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
5657 RefreshRateTableIndex, pVBInfo);
5658 XGI_SetGroup2(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5659 HwDeviceExtension, pVBInfo);
5660 XGI_SetLCDRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
5661 RefreshRateTableIndex, pVBInfo);
5662 XGI_SetTap4Regs(pVBInfo);
5663 XGI_SetGroup3(ModeNo, ModeIdIndex, pVBInfo);
5664 XGI_SetGroup4(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5665 HwDeviceExtension, pVBInfo);
5666 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5667 XGI_SetGroup5(ModeNo, ModeIdIndex, pVBInfo);
5668 XGI_AutoThreshold(pVBInfo);
5669 return 1;
5670}
5671
5672void XGI_SenseCRT1(struct vb_device_info *pVBInfo)
5673{
5674 unsigned char CRTCData[17] = { 0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81,
5675 0x0B, 0x3E, 0xE9, 0x0B, 0xDF, 0xE7, 0x04, 0x00, 0x00,
5676 0x05, 0x00 };
5677
5678 unsigned char SR01 = 0, SR1F = 0, SR07 = 0, SR06 = 0;
5679
5680 unsigned char CR17, CR63, SR31;
5681 unsigned short temp;
5682 unsigned char DAC_TEST_PARMS[3] = { 0x0F, 0x0F, 0x0F };
5683
5684 int i;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005685 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005686
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005687 /* to fix XG42 single LCD sense to CRT+LCD */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005688 xgifb_reg_set(pVBInfo->P3d4, 0x57, 0x4A);
Aaro Koskinen58839b02011-03-13 12:26:23 +02005689 xgifb_reg_set(pVBInfo->P3d4, 0x53, (unsigned char) (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005690 pVBInfo->P3d4, 0x53) | 0x02));
5691
Aaro Koskinen58839b02011-03-13 12:26:23 +02005692 SR31 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x31);
5693 CR63 = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x63);
5694 SR01 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x01);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005695
Aaro Koskinen8104e322011-03-13 12:26:22 +02005696 xgifb_reg_set(pVBInfo->P3c4, 0x01, (unsigned char) (SR01 & 0xDF));
5697 xgifb_reg_set(pVBInfo->P3d4, 0x63, (unsigned char) (CR63 & 0xBF));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005698
Aaro Koskinen58839b02011-03-13 12:26:23 +02005699 CR17 = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x17);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005700 xgifb_reg_set(pVBInfo->P3d4, 0x17, (unsigned char) (CR17 | 0x80));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005701
Aaro Koskinen58839b02011-03-13 12:26:23 +02005702 SR1F = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005703 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) (SR1F | 0x04));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005704
Aaro Koskinen58839b02011-03-13 12:26:23 +02005705 SR07 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x07);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005706 xgifb_reg_set(pVBInfo->P3c4, 0x07, (unsigned char) (SR07 & 0xFB));
Aaro Koskinen58839b02011-03-13 12:26:23 +02005707 SR06 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x06);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005708 xgifb_reg_set(pVBInfo->P3c4, 0x06, (unsigned char) (SR06 & 0xC3));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005709
Aaro Koskinen8104e322011-03-13 12:26:22 +02005710 xgifb_reg_set(pVBInfo->P3d4, 0x11, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005711
5712 for (i = 0; i < 8; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005713 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) i, CRTCData[i]);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005714
5715 for (i = 8; i < 11; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005716 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 8),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005717 CRTCData[i]);
5718
5719 for (i = 11; i < 13; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005720 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 4),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005721 CRTCData[i]);
5722
5723 for (i = 13; i < 16; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005724 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i - 3),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005725 CRTCData[i]);
5726
Aaro Koskinen8104e322011-03-13 12:26:22 +02005727 xgifb_reg_set(pVBInfo->P3c4, 0x0E, (unsigned char) (CRTCData[16]
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005728 & 0xE0));
5729
Aaro Koskinen8104e322011-03-13 12:26:22 +02005730 xgifb_reg_set(pVBInfo->P3c4, 0x31, 0x00);
5731 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x1B);
5732 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE1);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005733
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005734 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005735
5736 for (i = 0; i < 256; i++) {
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005737 outb((unsigned char) DAC_TEST_PARMS[0], (pVBInfo->P3c8 + 1));
5738 outb((unsigned char) DAC_TEST_PARMS[1], (pVBInfo->P3c8 + 1));
5739 outb((unsigned char) DAC_TEST_PARMS[2], (pVBInfo->P3c8 + 1));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005740 }
5741
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005742 mdelay(1);
5743
5744 XGI_WaitDisply(pVBInfo);
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02005745 temp = inb(pVBInfo->P3c2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005746
5747 if (temp & 0x10)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005748 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005749 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005750 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005751
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005752 /* avoid display something, set BLACK DAC if not restore DAC */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005753 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005754
5755 for (i = 0; i < 256; i++) {
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005756 outb(0, (pVBInfo->P3c8 + 1));
5757 outb(0, (pVBInfo->P3c8 + 1));
5758 outb(0, (pVBInfo->P3c8 + 1));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005759 }
5760
Aaro Koskinen8104e322011-03-13 12:26:22 +02005761 xgifb_reg_set(pVBInfo->P3c4, 0x01, SR01);
5762 xgifb_reg_set(pVBInfo->P3d4, 0x63, CR63);
5763 xgifb_reg_set(pVBInfo->P3c4, 0x31, SR31);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005764
Aaro Koskinen58839b02011-03-13 12:26:23 +02005765 xgifb_reg_set(pVBInfo->P3d4, 0x53, (unsigned char) (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005766 pVBInfo->P3d4, 0x53) & 0xFD));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005767 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) SR1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005768}
5769
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005770static void XGI_EnableBridge(struct xgifb_video_info *xgifb_info,
5771 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005772 struct vb_device_info *pVBInfo)
5773{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02005774 unsigned short tempah;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005775
Peter Huewe6896b942012-02-09 21:11:46 +01005776 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5777 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005778 if (!(pVBInfo->SetFlag & DisableChA)) {
5779 if (pVBInfo->SetFlag & EnableChA) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005780 /* Power on */
5781 xgifb_reg_set(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinend3ae5762012-09-11 00:15:27 +03005782 } else if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
5783 /* Power on */
5784 xgifb_reg_set(pVBInfo->Part1Port,
5785 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005786 }
5787 }
5788
5789 if (!(pVBInfo->SetFlag & DisableChB)) {
5790 if ((pVBInfo->SetFlag & EnableChB) || (pVBInfo->VBInfo
5791 & (SetCRT2ToLCD | SetCRT2ToTV
5792 | SetCRT2ToRAMDAC))) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005793 tempah = (unsigned char) xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005794 pVBInfo->P3c4, 0x32);
5795 tempah &= 0xDF;
5796 if (pVBInfo->VBInfo & SetInSlaveMode) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005797 if (!(pVBInfo->VBInfo &
5798 SetCRT2ToRAMDAC))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005799 tempah |= 0x20;
5800 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02005801 xgifb_reg_set(pVBInfo->P3c4, 0x32, tempah);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005802 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005803
Aaro Koskinen58839b02011-03-13 12:26:23 +02005804 tempah = (unsigned char) xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005805 pVBInfo->Part1Port, 0x2E);
5806
5807 if (!(tempah & 0x80))
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005808 xgifb_reg_or(pVBInfo->Part1Port,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005809 0x2E, 0x80);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005810 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005811 }
5812 }
5813
5814 if ((pVBInfo->SetFlag & (EnableChA | EnableChB))
5815 || (!(pVBInfo->VBInfo & DisableCRT2Display))) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005816 xgifb_reg_and_or(pVBInfo->Part2Port, 0x00, ~0xE0,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005817 0x20); /* shampoo 0129 */
Peter Huewe6896b942012-02-09 21:11:46 +01005818 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005819 if (!XGI_DisableChISLCD(pVBInfo)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005820 if (XGI_EnableChISLCD(pVBInfo) ||
5821 (pVBInfo->VBInfo &
Peter Huewea3d675c2012-02-09 21:11:47 +01005822 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005823 /* LVDS PLL power on */
Aaro Koskinendc505562011-03-13 12:26:26 +02005824 xgifb_reg_and(
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005825 pVBInfo->Part4Port,
5826 0x2A,
5827 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005828 }
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005829 /* LVDS Driver power on */
5830 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005831 }
5832 }
5833
5834 tempah = 0x00;
5835
5836 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5837 tempah = 0xc0;
5838
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005839 if (!(pVBInfo->VBInfo & SetSimuScanMode) &&
5840 (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) &&
5841 (pVBInfo->VBInfo & SetCRT2ToDualEdge)) {
5842 tempah = tempah & 0x40;
5843 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
5844 tempah = tempah ^ 0xC0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005845
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005846 if (pVBInfo->SetFlag & DisableChB)
5847 tempah &= 0xBF;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005848
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005849 if (pVBInfo->SetFlag & DisableChA)
5850 tempah &= 0x7F;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005851
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005852 if (pVBInfo->SetFlag & EnableChB)
5853 tempah |= 0x40;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005854
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005855 if (pVBInfo->SetFlag & EnableChA)
5856 tempah |= 0x80;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005857 }
5858 }
5859
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005860 /* EnablePart4_1F */
5861 xgifb_reg_or(pVBInfo->Part4Port, 0x1F, tempah);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005862
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005863 if (!(pVBInfo->SetFlag & DisableChA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005864 if (!(pVBInfo->SetFlag & GatingCRT)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005865 XGI_DisableGatingCRT(HwDeviceExtension,
5866 pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005867 XGI_DisplayOn(xgifb_info, HwDeviceExtension,
5868 pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005869 }
5870 }
5871 } /* 301 */
5872 else { /* LVDS */
5873 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD
Peter Huewea3d675c2012-02-09 21:11:47 +01005874 | XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005875 /* enable CRT2 */
5876 xgifb_reg_or(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005877
Aaro Koskinen58839b02011-03-13 12:26:23 +02005878 tempah = (unsigned char) xgifb_reg_get(pVBInfo->Part1Port,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005879 0x2E);
5880 if (!(tempah & 0x80))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005881 xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005882
Aaro Koskinendc505562011-03-13 12:26:26 +02005883 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005884 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005885 } /* End of VB */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005886}
5887
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005888static void XGI_SetCRT1Group(struct xgifb_video_info *xgifb_info,
5889 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005890 unsigned short ModeNo, unsigned short ModeIdIndex,
5891 struct vb_device_info *pVBInfo)
5892{
Aaro Koskinena1579612012-04-07 01:14:05 +03005893 unsigned short RefreshRateTableIndex, temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005894
Aaro Koskinena1579612012-04-07 01:14:05 +03005895 XGI_SetSeqRegs(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinen3625c9a2012-11-04 21:14:51 +02005896 outb(XGI330_StandTable.MISC, pVBInfo->P3c2);
Aaro Koskinena1579612012-04-07 01:14:05 +03005897 XGI_SetCRTCRegs(HwDeviceExtension, pVBInfo);
5898 XGI_SetATTRegs(ModeNo, ModeIdIndex, pVBInfo);
5899 XGI_SetGRCRegs(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005900 XGI_ClearExt1Regs(pVBInfo);
5901
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005902 if (HwDeviceExtension->jChipType == XG27) {
5903 if (pVBInfo->IF_DEF_LVDS == 0)
5904 XGI_SetDefaultVCLK(pVBInfo);
5905 }
5906
5907 temp = ~ProgrammingCRT2;
5908 pVBInfo->SetFlag &= temp;
5909 pVBInfo->SelectCRT2Rate = 0;
5910
Peter Huewe6896b942012-02-09 21:11:46 +01005911 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5912 | VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005913 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005914 | SetInSlaveMode)) {
5915 pVBInfo->SetFlag |= ProgrammingCRT2;
5916 }
5917 }
5918
5919 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5920 ModeIdIndex, pVBInfo);
5921 if (RefreshRateTableIndex != 0xFFFF) {
5922 XGI_SetSync(RefreshRateTableIndex, pVBInfo);
5923 XGI_SetCRT1CRTC(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5924 pVBInfo, HwDeviceExtension);
5925 XGI_SetCRT1DE(HwDeviceExtension, ModeNo, ModeIdIndex,
5926 RefreshRateTableIndex, pVBInfo);
5927 XGI_SetCRT1Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5928 HwDeviceExtension, pVBInfo);
5929 XGI_SetCRT1VCLK(ModeNo, ModeIdIndex, HwDeviceExtension,
5930 RefreshRateTableIndex, pVBInfo);
5931 }
5932
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005933 if (HwDeviceExtension->jChipType >= XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005934 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005935 if (temp & 0xA0) {
5936
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005937 if (HwDeviceExtension->jChipType == XG27)
5938 XGI_SetXG27CRTC(ModeNo, ModeIdIndex,
5939 RefreshRateTableIndex, pVBInfo);
5940 else
5941 XGI_SetXG21CRTC(ModeNo, ModeIdIndex,
5942 RefreshRateTableIndex, pVBInfo);
5943
5944 XGI_UpdateXG21CRTC(ModeNo, pVBInfo,
5945 RefreshRateTableIndex);
5946
Aaro Koskinen105d8d02011-08-31 21:46:00 +03005947 xgifb_set_lcd(HwDeviceExtension->jChipType,
5948 pVBInfo, RefreshRateTableIndex, ModeNo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005949
Aaro Koskinen64db29f2011-08-31 21:46:01 +03005950 if (pVBInfo->IF_DEF_LVDS == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005951 xgifb_set_lvds(xgifb_info,
5952 HwDeviceExtension->jChipType,
Aaro Koskinen64db29f2011-08-31 21:46:01 +03005953 ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005954 }
5955 }
5956
5957 pVBInfo->SetFlag &= (~ProgrammingCRT2);
5958 XGI_SetCRT1FIFO(ModeNo, HwDeviceExtension, pVBInfo);
5959 XGI_SetCRT1ModeRegs(HwDeviceExtension, ModeNo, ModeIdIndex,
5960 RefreshRateTableIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005961 XGI_LoadDAC(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005962}
5963
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005964unsigned char XGISetModeNew(struct xgifb_video_info *xgifb_info,
5965 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005966 unsigned short ModeNo)
5967{
5968 unsigned short ModeIdIndex;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005969 struct vb_device_info VBINF;
5970 struct vb_device_info *pVBInfo = &VBINF;
Dmitry Eremin-Solenikov9a801f22012-03-19 21:50:13 +04005971 pVBInfo->BaseAddr = xgifb_info->vga_base;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005972 pVBInfo->IF_DEF_LVDS = 0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005973
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005974 if (HwDeviceExtension->jChipType >= XG20) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005975 pVBInfo->IF_DEF_YPbPr = 0;
5976 pVBInfo->IF_DEF_HiVision = 0;
5977 pVBInfo->IF_DEF_CRT2Monitor = 0;
5978 pVBInfo->VBType = 0; /*set VBType default 0*/
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005979 } else {
5980 pVBInfo->IF_DEF_YPbPr = 1;
5981 pVBInfo->IF_DEF_HiVision = 1;
Aaro Koskinen06587332011-03-13 12:26:10 +02005982 pVBInfo->IF_DEF_CRT2Monitor = 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005983 }
5984
5985 pVBInfo->P3c4 = pVBInfo->BaseAddr + 0x14;
5986 pVBInfo->P3d4 = pVBInfo->BaseAddr + 0x24;
5987 pVBInfo->P3c0 = pVBInfo->BaseAddr + 0x10;
5988 pVBInfo->P3ce = pVBInfo->BaseAddr + 0x1e;
5989 pVBInfo->P3c2 = pVBInfo->BaseAddr + 0x12;
5990 pVBInfo->P3cc = pVBInfo->BaseAddr + 0x1C;
5991 pVBInfo->P3ca = pVBInfo->BaseAddr + 0x1a;
5992 pVBInfo->P3c6 = pVBInfo->BaseAddr + 0x16;
5993 pVBInfo->P3c7 = pVBInfo->BaseAddr + 0x17;
5994 pVBInfo->P3c8 = pVBInfo->BaseAddr + 0x18;
5995 pVBInfo->P3c9 = pVBInfo->BaseAddr + 0x19;
5996 pVBInfo->P3da = pVBInfo->BaseAddr + 0x2A;
5997 pVBInfo->Part0Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_00;
Peter Huewe6896b942012-02-09 21:11:46 +01005998 pVBInfo->Part1Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_04;
5999 pVBInfo->Part2Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_10;
6000 pVBInfo->Part3Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_12;
6001 pVBInfo->Part4Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_14;
6002 pVBInfo->Part5Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_14 + 2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006003
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006004 /* for x86 Linux, XG21 LVDS */
6005 if (HwDeviceExtension->jChipType == XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02006006 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006007 pVBInfo->IF_DEF_LVDS = 1;
6008 }
6009 if (HwDeviceExtension->jChipType == XG27) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02006010 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0) {
6011 if (xgifb_reg_get(pVBInfo->P3d4, 0x30) & 0x20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006012 pVBInfo->IF_DEF_LVDS = 1;
6013 }
6014 }
6015
Miguel Gómez949eb0a2012-07-06 12:40:36 +02006016 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006017 XGI_GetVBType(pVBInfo);
6018
6019 InitTo330Pointer(HwDeviceExtension->jChipType, pVBInfo);
Aaro Koskinenef497f42011-11-27 23:03:21 +02006020 if (ModeNo & 0x80)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006021 ModeNo = ModeNo & 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +02006022 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006023
Miguel Gómez949eb0a2012-07-06 12:40:36 +02006024 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006025 XGI_UnLockCRT2(HwDeviceExtension, pVBInfo);
6026
6027 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
6028
Miguel Gómez949eb0a2012-07-06 12:40:36 +02006029 if (HwDeviceExtension->jChipType < XG20) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006030 XGI_GetVBInfo(ModeNo, ModeIdIndex, HwDeviceExtension, pVBInfo);
6031 XGI_GetTVInfo(ModeNo, ModeIdIndex, pVBInfo);
6032 XGI_GetLCDInfo(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006033 XGI_DisableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006034
Peter Huewea3d675c2012-02-09 21:11:47 +01006035 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA)) {
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006036 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006037 ModeIdIndex, pVBInfo);
6038
Peter Huewea3d675c2012-02-09 21:11:47 +01006039 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006040 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
6041 HwDeviceExtension, pVBInfo);
6042 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +03006043 } else if (!(pVBInfo->VBInfo & SwitchCRT2)) {
6044 XGI_SetCRT1Group(xgifb_info,
6045 HwDeviceExtension, ModeNo,
6046 ModeIdIndex, pVBInfo);
6047 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
6048 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
6049 HwDeviceExtension,
6050 pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006051 }
6052 }
6053
Peter Huewe6896b942012-02-09 21:11:46 +01006054 if (pVBInfo->VBInfo & (SetSimuScanMode | SwitchCRT2)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006055 switch (HwDeviceExtension->ujVBChipID) {
6056 case VB_CHIP_301:
6057 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
6058 pVBInfo); /*add for CRT2 */
6059 break;
6060
6061 case VB_CHIP_302:
6062 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
6063 pVBInfo); /*add for CRT2 */
6064 break;
6065
6066 default:
6067 break;
6068 }
6069 }
6070
6071 XGI_SetCRT2ModeRegs(ModeNo, HwDeviceExtension, pVBInfo);
6072 XGI_OEM310Setting(ModeNo, ModeIdIndex, pVBInfo); /*0212*/
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006073 XGI_EnableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006074 } /* !XG20 */
6075 else {
6076 if (pVBInfo->IF_DEF_LVDS == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006077 if (!XGI_XG21CheckLVDSMode(xgifb_info, ModeNo,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006078 ModeIdIndex,
6079 pVBInfo))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006080 return 0;
6081
Aaro Koskinenb3979922012-11-04 21:14:52 +02006082 pVBInfo->ModeType = XGI330_EModeIDTable[ModeIdIndex].
Peter Huewe6896b942012-02-09 21:11:46 +01006083 Ext_ModeFlag & ModeTypeMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006084
6085 pVBInfo->SetFlag = 0;
Aaro Koskinen83f76a92011-08-31 21:45:58 +03006086 pVBInfo->VBInfo = DisableCRT2Display;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006087
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006088 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006089
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006090 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
6091 ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006092
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006093 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006094 }
6095
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006096 XGI_UpdateModeInfo(HwDeviceExtension, pVBInfo);
6097
Miguel Gómez3bcc2462012-07-06 12:40:53 +02006098 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006099 XGI_LockCRT2(HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006100
6101 return 1;
6102}