/drivers/video/sis/init301.c

https://bitbucket.org/abioy/linux · C · 11260 lines · 9172 code · 1583 blank · 505 comment · 3574 complexity · f965b504f6b9a385cf8db7cb0d0906b8 MD5 · raw file

  1. /* $XFree86$ */
  2. /* $XdotOrg$ */
  3. /*
  4. * Mode initializing code (CRT2 section)
  5. * for SiS 300/305/540/630/730,
  6. * SiS 315/550/[M]650/651/[M]661[FGM]X/[M]74x[GX]/330/[M]76x[GX],
  7. * XGI V3XT/V5/V8, Z7
  8. * (Universal module for Linux kernel framebuffer and X.org/XFree86 4.x)
  9. *
  10. * Copyright (C) 2001-2005 by Thomas Winischhofer, Vienna, Austria
  11. *
  12. * If distributed as part of the Linux kernel, the following license terms
  13. * apply:
  14. *
  15. * * This program is free software; you can redistribute it and/or modify
  16. * * it under the terms of the GNU General Public License as published by
  17. * * the Free Software Foundation; either version 2 of the named License,
  18. * * or any later version.
  19. * *
  20. * * This program is distributed in the hope that it will be useful,
  21. * * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * * GNU General Public License for more details.
  24. * *
  25. * * You should have received a copy of the GNU General Public License
  26. * * along with this program; if not, write to the Free Software
  27. * * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
  28. *
  29. * Otherwise, the following license terms apply:
  30. *
  31. * * Redistribution and use in source and binary forms, with or without
  32. * * modification, are permitted provided that the following conditions
  33. * * are met:
  34. * * 1) Redistributions of source code must retain the above copyright
  35. * * notice, this list of conditions and the following disclaimer.
  36. * * 2) Redistributions in binary form must reproduce the above copyright
  37. * * notice, this list of conditions and the following disclaimer in the
  38. * * documentation and/or other materials provided with the distribution.
  39. * * 3) The name of the author may not be used to endorse or promote products
  40. * * derived from this software without specific prior written permission.
  41. * *
  42. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  43. * * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  44. * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  45. * * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  46. * * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  47. * * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  48. * * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  49. * * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  50. * * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  51. * * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  52. *
  53. * Author: Thomas Winischhofer <thomas@winischhofer.net>
  54. *
  55. * Formerly based on non-functional code-fragements for 300 series by SiS, Inc.
  56. * Used by permission.
  57. *
  58. */
  59. #ifdef HAVE_CONFIG_H
  60. #include "config.h"
  61. #endif
  62. #if 1
  63. #define SET_EMI /* 302LV/ELV: Set EMI values */
  64. #endif
  65. #if 1
  66. #define SET_PWD /* 301/302LV: Set PWD */
  67. #endif
  68. #define COMPAL_HACK /* Needed for Compal 1400x1050 (EMI) */
  69. #define COMPAQ_HACK /* Needed for Inventec/Compaq 1280x1024 (EMI) */
  70. #define ASUS_HACK /* Needed for Asus A2H 1024x768 (EMI) */
  71. #include "init301.h"
  72. #ifdef SIS300
  73. #include "oem300.h"
  74. #endif
  75. #ifdef SIS315H
  76. #include "oem310.h"
  77. #endif
  78. #define SiS_I2CDELAY 1000
  79. #define SiS_I2CDELAYSHORT 150
  80. static unsigned short SiS_GetBIOSLCDResInfo(struct SiS_Private *SiS_Pr);
  81. #ifdef SIS_LINUX_KERNEL
  82. static void SiS_SetCH70xx(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val);
  83. #endif
  84. /*********************************************/
  85. /* HELPER: Lock/Unlock CRT2 */
  86. /*********************************************/
  87. void
  88. SiS_UnLockCRT2(struct SiS_Private *SiS_Pr)
  89. {
  90. if(SiS_Pr->ChipType == XGI_20)
  91. return;
  92. else if(SiS_Pr->ChipType >= SIS_315H)
  93. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2f,0x01);
  94. else
  95. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x24,0x01);
  96. }
  97. #ifdef SIS_LINUX_KERNEL
  98. static
  99. #endif
  100. void
  101. SiS_LockCRT2(struct SiS_Private *SiS_Pr)
  102. {
  103. if(SiS_Pr->ChipType == XGI_20)
  104. return;
  105. else if(SiS_Pr->ChipType >= SIS_315H)
  106. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2F,0xFE);
  107. else
  108. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x24,0xFE);
  109. }
  110. /*********************************************/
  111. /* HELPER: Write SR11 */
  112. /*********************************************/
  113. static void
  114. SiS_SetRegSR11ANDOR(struct SiS_Private *SiS_Pr, unsigned short DataAND, unsigned short DataOR)
  115. {
  116. if(SiS_Pr->ChipType >= SIS_661) {
  117. DataAND &= 0x0f;
  118. DataOR &= 0x0f;
  119. }
  120. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x11,DataAND,DataOR);
  121. }
  122. /*********************************************/
  123. /* HELPER: Get Pointer to LCD structure */
  124. /*********************************************/
  125. #ifdef SIS315H
  126. static unsigned char *
  127. GetLCDStructPtr661(struct SiS_Private *SiS_Pr)
  128. {
  129. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  130. unsigned char *myptr = NULL;
  131. unsigned short romindex = 0, reg = 0, idx = 0;
  132. /* Use the BIOS tables only for LVDS panels; TMDS is unreliable
  133. * due to the variaty of panels the BIOS doesn't know about.
  134. * Exception: If the BIOS has better knowledge (such as in case
  135. * of machines with a 301C and a panel that does not support DDC)
  136. * use the BIOS data as well.
  137. */
  138. if((SiS_Pr->SiS_ROMNew) &&
  139. ((SiS_Pr->SiS_VBType & VB_SISLVDS) || (!SiS_Pr->PanelSelfDetected))) {
  140. if(SiS_Pr->ChipType < SIS_661) reg = 0x3c;
  141. else reg = 0x7d;
  142. idx = (SiS_GetReg(SiS_Pr->SiS_P3d4,reg) & 0x1f) * 26;
  143. if(idx < (8*26)) {
  144. myptr = (unsigned char *)&SiS_LCDStruct661[idx];
  145. }
  146. romindex = SISGETROMW(0x100);
  147. if(romindex) {
  148. romindex += idx;
  149. myptr = &ROMAddr[romindex];
  150. }
  151. }
  152. return myptr;
  153. }
  154. static unsigned short
  155. GetLCDStructPtr661_2(struct SiS_Private *SiS_Pr)
  156. {
  157. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  158. unsigned short romptr = 0;
  159. /* Use the BIOS tables only for LVDS panels; TMDS is unreliable
  160. * due to the variaty of panels the BIOS doesn't know about.
  161. * Exception: If the BIOS has better knowledge (such as in case
  162. * of machines with a 301C and a panel that does not support DDC)
  163. * use the BIOS data as well.
  164. */
  165. if((SiS_Pr->SiS_ROMNew) &&
  166. ((SiS_Pr->SiS_VBType & VB_SISLVDS) || (!SiS_Pr->PanelSelfDetected))) {
  167. romptr = SISGETROMW(0x102);
  168. romptr += ((SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4) * SiS_Pr->SiS661LCD2TableSize);
  169. }
  170. return romptr;
  171. }
  172. #endif
  173. /*********************************************/
  174. /* Adjust Rate for CRT2 */
  175. /*********************************************/
  176. static bool
  177. SiS_AdjustCRT2Rate(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  178. unsigned short RRTI, unsigned short *i)
  179. {
  180. unsigned short checkmask=0, modeid, infoflag;
  181. modeid = SiS_Pr->SiS_RefIndex[RRTI + (*i)].ModeID;
  182. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  183. if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) {
  184. checkmask |= SupportRAMDAC2;
  185. if(SiS_Pr->ChipType >= SIS_315H) {
  186. checkmask |= SupportRAMDAC2_135;
  187. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  188. checkmask |= SupportRAMDAC2_162;
  189. if(SiS_Pr->SiS_VBType & VB_SISRAMDAC202) {
  190. checkmask |= SupportRAMDAC2_202;
  191. }
  192. }
  193. }
  194. } else if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  195. checkmask |= SupportLCD;
  196. if(SiS_Pr->ChipType >= SIS_315H) {
  197. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  198. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  199. if(modeid == 0x2e) checkmask |= Support64048060Hz;
  200. }
  201. }
  202. }
  203. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  204. checkmask |= SupportHiVision;
  205. } else if(SiS_Pr->SiS_VBInfo & (SetCRT2ToYPbPr525750|SetCRT2ToAVIDEO|SetCRT2ToSVIDEO|SetCRT2ToSCART)) {
  206. checkmask |= SupportTV;
  207. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  208. checkmask |= SupportTV1024;
  209. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  210. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) {
  211. checkmask |= SupportYPbPr750p;
  212. }
  213. }
  214. }
  215. }
  216. } else { /* LVDS */
  217. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  218. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  219. checkmask |= SupportCHTV;
  220. }
  221. }
  222. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  223. checkmask |= SupportLCD;
  224. }
  225. }
  226. /* Look backwards in table for matching CRT2 mode */
  227. for(; SiS_Pr->SiS_RefIndex[RRTI + (*i)].ModeID == modeid; (*i)--) {
  228. infoflag = SiS_Pr->SiS_RefIndex[RRTI + (*i)].Ext_InfoFlag;
  229. if(infoflag & checkmask) return true;
  230. if((*i) == 0) break;
  231. }
  232. /* Look through the whole mode-section of the table from the beginning
  233. * for a matching CRT2 mode if no mode was found yet.
  234. */
  235. for((*i) = 0; ; (*i)++) {
  236. if(SiS_Pr->SiS_RefIndex[RRTI + (*i)].ModeID != modeid) break;
  237. infoflag = SiS_Pr->SiS_RefIndex[RRTI + (*i)].Ext_InfoFlag;
  238. if(infoflag & checkmask) return true;
  239. }
  240. return false;
  241. }
  242. /*********************************************/
  243. /* Get rate index */
  244. /*********************************************/
  245. unsigned short
  246. SiS_GetRatePtr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  247. {
  248. unsigned short RRTI,i,backup_i;
  249. unsigned short modeflag,index,temp,backupindex;
  250. static const unsigned short LCDRefreshIndex[] = {
  251. 0x00, 0x00, 0x01, 0x01,
  252. 0x01, 0x01, 0x01, 0x01,
  253. 0x01, 0x01, 0x01, 0x01,
  254. 0x01, 0x01, 0x01, 0x01,
  255. 0x00, 0x00, 0x00, 0x00
  256. };
  257. /* Do NOT check for UseCustomMode here, will skrew up FIFO */
  258. if(ModeNo == 0xfe) return 0;
  259. if(ModeNo <= 0x13) {
  260. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  261. } else {
  262. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  263. }
  264. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  265. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  266. if(modeflag & HalfDCLK) return 0;
  267. }
  268. }
  269. if(ModeNo < 0x14) return 0xFFFF;
  270. index = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x33) >> SiS_Pr->SiS_SelectCRT2Rate) & 0x0F;
  271. backupindex = index;
  272. if(index > 0) index--;
  273. if(SiS_Pr->SiS_SetFlag & ProgrammingCRT2) {
  274. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  275. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  276. if(SiS_Pr->SiS_VBType & VB_NoLCD) index = 0;
  277. else if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) index = backupindex = 0;
  278. }
  279. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  280. if(!(SiS_Pr->SiS_VBType & VB_NoLCD)) {
  281. temp = LCDRefreshIndex[SiS_GetBIOSLCDResInfo(SiS_Pr)];
  282. if(index > temp) index = temp;
  283. }
  284. }
  285. } else {
  286. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) index = 0;
  287. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  288. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) index = 0;
  289. }
  290. }
  291. }
  292. RRTI = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].REFindex;
  293. ModeNo = SiS_Pr->SiS_RefIndex[RRTI].ModeID;
  294. if(SiS_Pr->ChipType >= SIS_315H) {
  295. if(!(SiS_Pr->SiS_VBInfo & DriverMode)) {
  296. if( (SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_VESAID == 0x105) ||
  297. (SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_VESAID == 0x107) ) {
  298. if(backupindex <= 1) RRTI++;
  299. }
  300. }
  301. }
  302. i = 0;
  303. do {
  304. if(SiS_Pr->SiS_RefIndex[RRTI + i].ModeID != ModeNo) break;
  305. temp = SiS_Pr->SiS_RefIndex[RRTI + i].Ext_InfoFlag;
  306. temp &= ModeTypeMask;
  307. if(temp < SiS_Pr->SiS_ModeType) break;
  308. i++;
  309. index--;
  310. } while(index != 0xFFFF);
  311. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) {
  312. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  313. temp = SiS_Pr->SiS_RefIndex[RRTI + i - 1].Ext_InfoFlag;
  314. if(temp & InterlaceMode) i++;
  315. }
  316. }
  317. i--;
  318. if((SiS_Pr->SiS_SetFlag & ProgrammingCRT2) && (!(SiS_Pr->SiS_VBInfo & DisableCRT2Display))) {
  319. backup_i = i;
  320. if(!(SiS_AdjustCRT2Rate(SiS_Pr, ModeNo, ModeIdIndex, RRTI, &i))) {
  321. i = backup_i;
  322. }
  323. }
  324. return (RRTI + i);
  325. }
  326. /*********************************************/
  327. /* STORE CRT2 INFO in CR34 */
  328. /*********************************************/
  329. static void
  330. SiS_SaveCRT2Info(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
  331. {
  332. unsigned short temp1, temp2;
  333. /* Store CRT1 ModeNo in CR34 */
  334. SiS_SetReg(SiS_Pr->SiS_P3d4,0x34,ModeNo);
  335. temp1 = (SiS_Pr->SiS_VBInfo & SetInSlaveMode) >> 8;
  336. temp2 = ~(SetInSlaveMode >> 8);
  337. SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x31,temp2,temp1);
  338. }
  339. /*********************************************/
  340. /* HELPER: GET SOME DATA FROM BIOS ROM */
  341. /*********************************************/
  342. #ifdef SIS300
  343. static bool
  344. SiS_CR36BIOSWord23b(struct SiS_Private *SiS_Pr)
  345. {
  346. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  347. unsigned short temp,temp1;
  348. if(SiS_Pr->SiS_UseROM) {
  349. if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) {
  350. temp = 1 << ((SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4) & 0x0f);
  351. temp1 = SISGETROMW(0x23b);
  352. if(temp1 & temp) return true;
  353. }
  354. }
  355. return false;
  356. }
  357. static bool
  358. SiS_CR36BIOSWord23d(struct SiS_Private *SiS_Pr)
  359. {
  360. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  361. unsigned short temp,temp1;
  362. if(SiS_Pr->SiS_UseROM) {
  363. if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) {
  364. temp = 1 << ((SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4) & 0x0f);
  365. temp1 = SISGETROMW(0x23d);
  366. if(temp1 & temp) return true;
  367. }
  368. }
  369. return false;
  370. }
  371. #endif
  372. /*********************************************/
  373. /* HELPER: DELAY FUNCTIONS */
  374. /*********************************************/
  375. void
  376. SiS_DDC2Delay(struct SiS_Private *SiS_Pr, unsigned int delaytime)
  377. {
  378. while (delaytime-- > 0)
  379. SiS_GetReg(SiS_Pr->SiS_P3c4, 0x05);
  380. }
  381. #if defined(SIS300) || defined(SIS315H)
  382. static void
  383. SiS_GenericDelay(struct SiS_Private *SiS_Pr, unsigned short delay)
  384. {
  385. SiS_DDC2Delay(SiS_Pr, delay * 36);
  386. }
  387. #endif
  388. #ifdef SIS315H
  389. static void
  390. SiS_LongDelay(struct SiS_Private *SiS_Pr, unsigned short delay)
  391. {
  392. while(delay--) {
  393. SiS_GenericDelay(SiS_Pr, 6623);
  394. }
  395. }
  396. #endif
  397. #if defined(SIS300) || defined(SIS315H)
  398. static void
  399. SiS_ShortDelay(struct SiS_Private *SiS_Pr, unsigned short delay)
  400. {
  401. while(delay--) {
  402. SiS_GenericDelay(SiS_Pr, 66);
  403. }
  404. }
  405. #endif
  406. static void
  407. SiS_PanelDelay(struct SiS_Private *SiS_Pr, unsigned short DelayTime)
  408. {
  409. #if defined(SIS300) || defined(SIS315H)
  410. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  411. unsigned short PanelID, DelayIndex, Delay=0;
  412. #endif
  413. if(SiS_Pr->ChipType < SIS_315H) {
  414. #ifdef SIS300
  415. PanelID = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36);
  416. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  417. if(SiS_Pr->SiS_VBType & VB_SIS301) PanelID &= 0xf7;
  418. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x18) & 0x10)) PanelID = 0x12;
  419. }
  420. DelayIndex = PanelID >> 4;
  421. if((DelayTime >= 2) && ((PanelID & 0x0f) == 1)) {
  422. Delay = 3;
  423. } else {
  424. if(DelayTime >= 2) DelayTime -= 2;
  425. if(!(DelayTime & 0x01)) {
  426. Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[0];
  427. } else {
  428. Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[1];
  429. }
  430. if(SiS_Pr->SiS_UseROM) {
  431. if(ROMAddr[0x220] & 0x40) {
  432. if(!(DelayTime & 0x01)) Delay = (unsigned short)ROMAddr[0x225];
  433. else Delay = (unsigned short)ROMAddr[0x226];
  434. }
  435. }
  436. }
  437. SiS_ShortDelay(SiS_Pr, Delay);
  438. #endif /* SIS300 */
  439. } else {
  440. #ifdef SIS315H
  441. if((SiS_Pr->ChipType >= SIS_661) ||
  442. (SiS_Pr->ChipType <= SIS_315PRO) ||
  443. (SiS_Pr->ChipType == SIS_330) ||
  444. (SiS_Pr->SiS_ROMNew)) {
  445. if(!(DelayTime & 0x01)) {
  446. SiS_DDC2Delay(SiS_Pr, 0x1000);
  447. } else {
  448. SiS_DDC2Delay(SiS_Pr, 0x4000);
  449. }
  450. } else if((SiS_Pr->SiS_IF_DEF_LVDS == 1) /* ||
  451. (SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) ||
  452. (SiS_Pr->SiS_CustomT == CUT_CLEVO1400) */ ) { /* 315 series, LVDS; Special */
  453. if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
  454. PanelID = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36);
  455. if(SiS_Pr->SiS_CustomT == CUT_CLEVO1400) {
  456. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x1b) & 0x10)) PanelID = 0x12;
  457. }
  458. if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) {
  459. DelayIndex = PanelID & 0x0f;
  460. } else {
  461. DelayIndex = PanelID >> 4;
  462. }
  463. if((DelayTime >= 2) && ((PanelID & 0x0f) == 1)) {
  464. Delay = 3;
  465. } else {
  466. if(DelayTime >= 2) DelayTime -= 2;
  467. if(!(DelayTime & 0x01)) {
  468. Delay = SiS_Pr->SiS_PanelDelayTblLVDS[DelayIndex].timer[0];
  469. } else {
  470. Delay = SiS_Pr->SiS_PanelDelayTblLVDS[DelayIndex].timer[1];
  471. }
  472. if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
  473. if(ROMAddr[0x13c] & 0x40) {
  474. if(!(DelayTime & 0x01)) {
  475. Delay = (unsigned short)ROMAddr[0x17e];
  476. } else {
  477. Delay = (unsigned short)ROMAddr[0x17f];
  478. }
  479. }
  480. }
  481. }
  482. SiS_ShortDelay(SiS_Pr, Delay);
  483. }
  484. } else if(SiS_Pr->SiS_VBType & VB_SISVB) { /* 315 series, all bridges */
  485. DelayIndex = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4;
  486. if(!(DelayTime & 0x01)) {
  487. Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[0];
  488. } else {
  489. Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[1];
  490. }
  491. Delay <<= 8;
  492. SiS_DDC2Delay(SiS_Pr, Delay);
  493. }
  494. #endif /* SIS315H */
  495. }
  496. }
  497. #ifdef SIS315H
  498. static void
  499. SiS_PanelDelayLoop(struct SiS_Private *SiS_Pr, unsigned short DelayTime, unsigned short DelayLoop)
  500. {
  501. int i;
  502. for(i = 0; i < DelayLoop; i++) {
  503. SiS_PanelDelay(SiS_Pr, DelayTime);
  504. }
  505. }
  506. #endif
  507. /*********************************************/
  508. /* HELPER: WAIT-FOR-RETRACE FUNCTIONS */
  509. /*********************************************/
  510. void
  511. SiS_WaitRetrace1(struct SiS_Private *SiS_Pr)
  512. {
  513. unsigned short watchdog;
  514. if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x1f) & 0xc0) return;
  515. if(!(SiS_GetReg(SiS_Pr->SiS_P3d4,0x17) & 0x80)) return;
  516. watchdog = 65535;
  517. while((SiS_GetRegByte(SiS_Pr->SiS_P3da) & 0x08) && --watchdog);
  518. watchdog = 65535;
  519. while((!(SiS_GetRegByte(SiS_Pr->SiS_P3da) & 0x08)) && --watchdog);
  520. }
  521. #if defined(SIS300) || defined(SIS315H)
  522. static void
  523. SiS_WaitRetrace2(struct SiS_Private *SiS_Pr, unsigned short reg)
  524. {
  525. unsigned short watchdog;
  526. watchdog = 65535;
  527. while((SiS_GetReg(SiS_Pr->SiS_Part1Port,reg) & 0x02) && --watchdog);
  528. watchdog = 65535;
  529. while((!(SiS_GetReg(SiS_Pr->SiS_Part1Port,reg) & 0x02)) && --watchdog);
  530. }
  531. #endif
  532. static void
  533. SiS_WaitVBRetrace(struct SiS_Private *SiS_Pr)
  534. {
  535. if(SiS_Pr->ChipType < SIS_315H) {
  536. #ifdef SIS300
  537. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  538. if(!(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x20)) return;
  539. }
  540. if(!(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x80)) {
  541. SiS_WaitRetrace1(SiS_Pr);
  542. } else {
  543. SiS_WaitRetrace2(SiS_Pr, 0x25);
  544. }
  545. #endif
  546. } else {
  547. #ifdef SIS315H
  548. if(!(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x40)) {
  549. SiS_WaitRetrace1(SiS_Pr);
  550. } else {
  551. SiS_WaitRetrace2(SiS_Pr, 0x30);
  552. }
  553. #endif
  554. }
  555. }
  556. static void
  557. SiS_VBWait(struct SiS_Private *SiS_Pr)
  558. {
  559. unsigned short tempal,temp,i,j;
  560. temp = 0;
  561. for(i = 0; i < 3; i++) {
  562. for(j = 0; j < 100; j++) {
  563. tempal = SiS_GetRegByte(SiS_Pr->SiS_P3da);
  564. if(temp & 0x01) {
  565. if((tempal & 0x08)) continue;
  566. else break;
  567. } else {
  568. if(!(tempal & 0x08)) continue;
  569. else break;
  570. }
  571. }
  572. temp ^= 0x01;
  573. }
  574. }
  575. static void
  576. SiS_VBLongWait(struct SiS_Private *SiS_Pr)
  577. {
  578. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  579. SiS_VBWait(SiS_Pr);
  580. } else {
  581. SiS_WaitRetrace1(SiS_Pr);
  582. }
  583. }
  584. /*********************************************/
  585. /* HELPER: MISC */
  586. /*********************************************/
  587. #ifdef SIS300
  588. static bool
  589. SiS_Is301B(struct SiS_Private *SiS_Pr)
  590. {
  591. if(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x01) >= 0xb0) return true;
  592. return false;
  593. }
  594. #endif
  595. static bool
  596. SiS_CRT2IsLCD(struct SiS_Private *SiS_Pr)
  597. {
  598. if(SiS_Pr->ChipType == SIS_730) {
  599. if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x20) return true;
  600. }
  601. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x30) & 0x20) return true;
  602. return false;
  603. }
  604. bool
  605. SiS_IsDualEdge(struct SiS_Private *SiS_Pr)
  606. {
  607. #ifdef SIS315H
  608. if(SiS_Pr->ChipType >= SIS_315H) {
  609. if((SiS_Pr->ChipType != SIS_650) || (SiS_GetReg(SiS_Pr->SiS_P3d4,0x5f) & 0xf0)) {
  610. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x38) & EnableDualEdge) return true;
  611. }
  612. }
  613. #endif
  614. return false;
  615. }
  616. bool
  617. SiS_IsVAMode(struct SiS_Private *SiS_Pr)
  618. {
  619. #ifdef SIS315H
  620. unsigned short flag;
  621. if(SiS_Pr->ChipType >= SIS_315H) {
  622. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  623. if((flag & EnableDualEdge) && (flag & SetToLCDA)) return true;
  624. }
  625. #endif
  626. return false;
  627. }
  628. #ifdef SIS315H
  629. static bool
  630. SiS_IsVAorLCD(struct SiS_Private *SiS_Pr)
  631. {
  632. if(SiS_IsVAMode(SiS_Pr)) return true;
  633. if(SiS_CRT2IsLCD(SiS_Pr)) return true;
  634. return false;
  635. }
  636. #endif
  637. static bool
  638. SiS_IsDualLink(struct SiS_Private *SiS_Pr)
  639. {
  640. #ifdef SIS315H
  641. if(SiS_Pr->ChipType >= SIS_315H) {
  642. if((SiS_CRT2IsLCD(SiS_Pr)) ||
  643. (SiS_IsVAMode(SiS_Pr))) {
  644. if(SiS_Pr->SiS_LCDInfo & LCDDualLink) return true;
  645. }
  646. }
  647. #endif
  648. return false;
  649. }
  650. #ifdef SIS315H
  651. static bool
  652. SiS_TVEnabled(struct SiS_Private *SiS_Pr)
  653. {
  654. if((SiS_GetReg(SiS_Pr->SiS_Part2Port,0x00) & 0x0f) != 0x0c) return true;
  655. if(SiS_Pr->SiS_VBType & VB_SISYPBPR) {
  656. if(SiS_GetReg(SiS_Pr->SiS_Part2Port,0x4d) & 0x10) return true;
  657. }
  658. return false;
  659. }
  660. #endif
  661. #ifdef SIS315H
  662. static bool
  663. SiS_LCDAEnabled(struct SiS_Private *SiS_Pr)
  664. {
  665. if(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x13) & 0x04) return true;
  666. return false;
  667. }
  668. #endif
  669. #ifdef SIS315H
  670. static bool
  671. SiS_WeHaveBacklightCtrl(struct SiS_Private *SiS_Pr)
  672. {
  673. if((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->ChipType < SIS_661)) {
  674. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x79) & 0x10) return true;
  675. }
  676. return false;
  677. }
  678. #endif
  679. #ifdef SIS315H
  680. static bool
  681. SiS_IsNotM650orLater(struct SiS_Private *SiS_Pr)
  682. {
  683. unsigned short flag;
  684. if(SiS_Pr->ChipType == SIS_650) {
  685. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x5f) & 0xf0;
  686. /* Check for revision != A0 only */
  687. if((flag == 0xe0) || (flag == 0xc0) ||
  688. (flag == 0xb0) || (flag == 0x90)) return false;
  689. } else if(SiS_Pr->ChipType >= SIS_661) return false;
  690. return true;
  691. }
  692. #endif
  693. #ifdef SIS315H
  694. static bool
  695. SiS_IsYPbPr(struct SiS_Private *SiS_Pr)
  696. {
  697. if(SiS_Pr->ChipType >= SIS_315H) {
  698. /* YPrPb = 0x08 */
  699. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x38) & EnableCHYPbPr) return true;
  700. }
  701. return false;
  702. }
  703. #endif
  704. #ifdef SIS315H
  705. static bool
  706. SiS_IsChScart(struct SiS_Private *SiS_Pr)
  707. {
  708. if(SiS_Pr->ChipType >= SIS_315H) {
  709. /* Scart = 0x04 */
  710. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x38) & EnableCHScart) return true;
  711. }
  712. return false;
  713. }
  714. #endif
  715. #ifdef SIS315H
  716. static bool
  717. SiS_IsTVOrYPbPrOrScart(struct SiS_Private *SiS_Pr)
  718. {
  719. unsigned short flag;
  720. if(SiS_Pr->ChipType >= SIS_315H) {
  721. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  722. if(flag & SetCRT2ToTV) return true;
  723. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  724. if(flag & EnableCHYPbPr) return true; /* = YPrPb = 0x08 */
  725. if(flag & EnableCHScart) return true; /* = Scart = 0x04 - TW */
  726. } else {
  727. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  728. if(flag & SetCRT2ToTV) return true;
  729. }
  730. return false;
  731. }
  732. #endif
  733. #ifdef SIS315H
  734. static bool
  735. SiS_IsLCDOrLCDA(struct SiS_Private *SiS_Pr)
  736. {
  737. unsigned short flag;
  738. if(SiS_Pr->ChipType >= SIS_315H) {
  739. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  740. if(flag & SetCRT2ToLCD) return true;
  741. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  742. if(flag & SetToLCDA) return true;
  743. } else {
  744. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  745. if(flag & SetCRT2ToLCD) return true;
  746. }
  747. return false;
  748. }
  749. #endif
  750. static bool
  751. SiS_HaveBridge(struct SiS_Private *SiS_Pr)
  752. {
  753. unsigned short flag;
  754. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  755. return true;
  756. } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
  757. flag = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x00);
  758. if((flag == 1) || (flag == 2)) return true;
  759. }
  760. return false;
  761. }
  762. static bool
  763. SiS_BridgeIsEnabled(struct SiS_Private *SiS_Pr)
  764. {
  765. unsigned short flag;
  766. if(SiS_HaveBridge(SiS_Pr)) {
  767. flag = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00);
  768. if(SiS_Pr->ChipType < SIS_315H) {
  769. flag &= 0xa0;
  770. if((flag == 0x80) || (flag == 0x20)) return true;
  771. } else {
  772. flag &= 0x50;
  773. if((flag == 0x40) || (flag == 0x10)) return true;
  774. }
  775. }
  776. return false;
  777. }
  778. static bool
  779. SiS_BridgeInSlavemode(struct SiS_Private *SiS_Pr)
  780. {
  781. unsigned short flag1;
  782. flag1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x31);
  783. if(flag1 & (SetInSlaveMode >> 8)) return true;
  784. return false;
  785. }
  786. /*********************************************/
  787. /* GET VIDEO BRIDGE CONFIG INFO */
  788. /*********************************************/
  789. /* Setup general purpose IO for Chrontel communication */
  790. #ifdef SIS300
  791. void
  792. SiS_SetChrontelGPIO(struct SiS_Private *SiS_Pr, unsigned short myvbinfo)
  793. {
  794. unsigned int acpibase;
  795. unsigned short temp;
  796. if(!(SiS_Pr->SiS_ChSW)) return;
  797. #ifdef SIS_LINUX_KERNEL
  798. acpibase = sisfb_read_lpc_pci_dword(SiS_Pr, 0x74);
  799. #else
  800. acpibase = pciReadLong(0x00000800, 0x74);
  801. #endif
  802. acpibase &= 0xFFFF;
  803. if(!acpibase) return;
  804. temp = SiS_GetRegShort((acpibase + 0x3c)); /* ACPI register 0x3c: GP Event 1 I/O mode select */
  805. temp &= 0xFEFF;
  806. SiS_SetRegShort((acpibase + 0x3c), temp);
  807. temp = SiS_GetRegShort((acpibase + 0x3c));
  808. temp = SiS_GetRegShort((acpibase + 0x3a)); /* ACPI register 0x3a: GP Pin Level (low/high) */
  809. temp &= 0xFEFF;
  810. if(!(myvbinfo & SetCRT2ToTV)) temp |= 0x0100;
  811. SiS_SetRegShort((acpibase + 0x3a), temp);
  812. temp = SiS_GetRegShort((acpibase + 0x3a));
  813. }
  814. #endif
  815. void
  816. SiS_GetVBInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
  817. unsigned short ModeIdIndex, int checkcrt2mode)
  818. {
  819. unsigned short tempax, tempbx, temp;
  820. unsigned short modeflag, resinfo = 0;
  821. SiS_Pr->SiS_SetFlag = 0;
  822. modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
  823. SiS_Pr->SiS_ModeType = modeflag & ModeTypeMask;
  824. if((ModeNo > 0x13) && (!SiS_Pr->UseCustomMode)) {
  825. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  826. }
  827. tempbx = 0;
  828. if(SiS_HaveBridge(SiS_Pr)) {
  829. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  830. tempbx |= temp;
  831. tempax = SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) << 8;
  832. tempax &= (DriverMode | LoadDACFlag | SetNotSimuMode | SetPALTV);
  833. tempbx |= tempax;
  834. #ifdef SIS315H
  835. if(SiS_Pr->ChipType >= SIS_315H) {
  836. if(SiS_Pr->SiS_VBType & VB_SISLCDA) {
  837. if(ModeNo == 0x03) {
  838. /* Mode 0x03 is never in driver mode */
  839. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x31,0xbf);
  840. }
  841. if(!(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & (DriverMode >> 8))) {
  842. /* Reset LCDA setting if not driver mode */
  843. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x38,0xfc);
  844. }
  845. if(IS_SIS650) {
  846. if(SiS_Pr->SiS_UseLCDA) {
  847. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x5f) & 0xF0) {
  848. if((ModeNo <= 0x13) || (!(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & (DriverMode >> 8)))) {
  849. SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x38,(EnableDualEdge | SetToLCDA));
  850. }
  851. }
  852. }
  853. }
  854. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  855. if((temp & (EnableDualEdge | SetToLCDA)) == (EnableDualEdge | SetToLCDA)) {
  856. tempbx |= SetCRT2ToLCDA;
  857. }
  858. }
  859. if(SiS_Pr->ChipType >= SIS_661) { /* New CR layout */
  860. tempbx &= ~(SetCRT2ToYPbPr525750 | SetCRT2ToHiVision);
  861. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x38) & 0x04) {
  862. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35) & 0xe0;
  863. if(temp == 0x60) tempbx |= SetCRT2ToHiVision;
  864. else if(SiS_Pr->SiS_VBType & VB_SISYPBPR) {
  865. tempbx |= SetCRT2ToYPbPr525750;
  866. }
  867. }
  868. }
  869. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  870. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  871. if(temp & SetToLCDA) {
  872. tempbx |= SetCRT2ToLCDA;
  873. }
  874. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  875. if(temp & EnableCHYPbPr) {
  876. tempbx |= SetCRT2ToCHYPbPr;
  877. }
  878. }
  879. }
  880. }
  881. #endif /* SIS315H */
  882. if(!(SiS_Pr->SiS_VBType & VB_SISVGA2)) {
  883. tempbx &= ~(SetCRT2ToRAMDAC);
  884. }
  885. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  886. temp = SetCRT2ToSVIDEO |
  887. SetCRT2ToAVIDEO |
  888. SetCRT2ToSCART |
  889. SetCRT2ToLCDA |
  890. SetCRT2ToLCD |
  891. SetCRT2ToRAMDAC |
  892. SetCRT2ToHiVision |
  893. SetCRT2ToYPbPr525750;
  894. } else {
  895. if(SiS_Pr->ChipType >= SIS_315H) {
  896. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  897. temp = SetCRT2ToAVIDEO |
  898. SetCRT2ToSVIDEO |
  899. SetCRT2ToSCART |
  900. SetCRT2ToLCDA |
  901. SetCRT2ToLCD |
  902. SetCRT2ToCHYPbPr;
  903. } else {
  904. temp = SetCRT2ToLCDA |
  905. SetCRT2ToLCD;
  906. }
  907. } else {
  908. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  909. temp = SetCRT2ToTV | SetCRT2ToLCD;
  910. } else {
  911. temp = SetCRT2ToLCD;
  912. }
  913. }
  914. }
  915. if(!(tempbx & temp)) {
  916. tempax = DisableCRT2Display;
  917. tempbx = 0;
  918. }
  919. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  920. unsigned short clearmask = ( DriverMode |
  921. DisableCRT2Display |
  922. LoadDACFlag |
  923. SetNotSimuMode |
  924. SetInSlaveMode |
  925. SetPALTV |
  926. SwitchCRT2 |
  927. SetSimuScanMode );
  928. if(tempbx & SetCRT2ToLCDA) tempbx &= (clearmask | SetCRT2ToLCDA);
  929. if(tempbx & SetCRT2ToRAMDAC) tempbx &= (clearmask | SetCRT2ToRAMDAC);
  930. if(tempbx & SetCRT2ToLCD) tempbx &= (clearmask | SetCRT2ToLCD);
  931. if(tempbx & SetCRT2ToSCART) tempbx &= (clearmask | SetCRT2ToSCART);
  932. if(tempbx & SetCRT2ToHiVision) tempbx &= (clearmask | SetCRT2ToHiVision);
  933. if(tempbx & SetCRT2ToYPbPr525750) tempbx &= (clearmask | SetCRT2ToYPbPr525750);
  934. } else {
  935. if(SiS_Pr->ChipType >= SIS_315H) {
  936. if(tempbx & SetCRT2ToLCDA) {
  937. tempbx &= (0xFF00|SwitchCRT2|SetSimuScanMode);
  938. }
  939. }
  940. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  941. if(tempbx & SetCRT2ToTV) {
  942. tempbx &= (0xFF00|SetCRT2ToTV|SwitchCRT2|SetSimuScanMode);
  943. }
  944. }
  945. if(tempbx & SetCRT2ToLCD) {
  946. tempbx &= (0xFF00|SetCRT2ToLCD|SwitchCRT2|SetSimuScanMode);
  947. }
  948. if(SiS_Pr->ChipType >= SIS_315H) {
  949. if(tempbx & SetCRT2ToLCDA) {
  950. tempbx |= SetCRT2ToLCD;
  951. }
  952. }
  953. }
  954. if(tempax & DisableCRT2Display) {
  955. if(!(tempbx & (SwitchCRT2 | SetSimuScanMode))) {
  956. tempbx = SetSimuScanMode | DisableCRT2Display;
  957. }
  958. }
  959. if(!(tempbx & DriverMode)) tempbx |= SetSimuScanMode;
  960. /* LVDS/CHRONTEL (LCD/TV) and 301BDH (LCD) can only be slave in 8bpp modes */
  961. if(SiS_Pr->SiS_ModeType <= ModeVGA) {
  962. if( (SiS_Pr->SiS_IF_DEF_LVDS == 1) ||
  963. ((SiS_Pr->SiS_VBType & VB_NoLCD) && (tempbx & SetCRT2ToLCD)) ) {
  964. modeflag &= (~CRT2Mode);
  965. }
  966. }
  967. if(!(tempbx & SetSimuScanMode)) {
  968. if(tempbx & SwitchCRT2) {
  969. if((!(modeflag & CRT2Mode)) && (checkcrt2mode)) {
  970. if(resinfo != SIS_RI_1600x1200) {
  971. tempbx |= SetSimuScanMode;
  972. }
  973. }
  974. } else {
  975. if(SiS_BridgeIsEnabled(SiS_Pr)) {
  976. if(!(tempbx & DriverMode)) {
  977. if(SiS_BridgeInSlavemode(SiS_Pr)) {
  978. tempbx |= SetSimuScanMode;
  979. }
  980. }
  981. }
  982. }
  983. }
  984. if(!(tempbx & DisableCRT2Display)) {
  985. if(tempbx & DriverMode) {
  986. if(tempbx & SetSimuScanMode) {
  987. if((!(modeflag & CRT2Mode)) && (checkcrt2mode)) {
  988. if(resinfo != SIS_RI_1600x1200) {
  989. tempbx |= SetInSlaveMode;
  990. }
  991. }
  992. }
  993. } else {
  994. tempbx |= SetInSlaveMode;
  995. }
  996. }
  997. }
  998. SiS_Pr->SiS_VBInfo = tempbx;
  999. #ifdef SIS300
  1000. if(SiS_Pr->ChipType == SIS_630) {
  1001. SiS_SetChrontelGPIO(SiS_Pr, SiS_Pr->SiS_VBInfo);
  1002. }
  1003. #endif
  1004. #ifdef SIS_LINUX_KERNEL
  1005. #if 0
  1006. printk(KERN_DEBUG "sisfb: (init301: VBInfo= 0x%04x, SetFlag=0x%04x)\n",
  1007. SiS_Pr->SiS_VBInfo, SiS_Pr->SiS_SetFlag);
  1008. #endif
  1009. #endif
  1010. #ifdef SIS_XORG_XF86
  1011. #ifdef TWDEBUG
  1012. xf86DrvMsg(0, X_PROBED, "(init301: VBInfo=0x%04x, SetFlag=0x%04x)\n",
  1013. SiS_Pr->SiS_VBInfo, SiS_Pr->SiS_SetFlag);
  1014. #endif
  1015. #endif
  1016. }
  1017. /*********************************************/
  1018. /* DETERMINE YPbPr MODE */
  1019. /*********************************************/
  1020. void
  1021. SiS_SetYPbPr(struct SiS_Private *SiS_Pr)
  1022. {
  1023. unsigned char temp;
  1024. /* Note: This variable is only used on 30xLV systems.
  1025. * CR38 has a different meaning on LVDS/CH7019 systems.
  1026. * On 661 and later, these bits moved to CR35.
  1027. *
  1028. * On 301, 301B, only HiVision 1080i is supported.
  1029. * On 30xLV, 301C, only YPbPr 1080i is supported.
  1030. */
  1031. SiS_Pr->SiS_YPbPr = 0;
  1032. if(SiS_Pr->ChipType >= SIS_661) return;
  1033. if(SiS_Pr->SiS_VBType) {
  1034. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  1035. SiS_Pr->SiS_YPbPr = YPbPrHiVision;
  1036. }
  1037. }
  1038. if(SiS_Pr->ChipType >= SIS_315H) {
  1039. if(SiS_Pr->SiS_VBType & VB_SISYPBPR) {
  1040. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  1041. if(temp & 0x08) {
  1042. switch((temp >> 4)) {
  1043. case 0x00: SiS_Pr->SiS_YPbPr = YPbPr525i; break;
  1044. case 0x01: SiS_Pr->SiS_YPbPr = YPbPr525p; break;
  1045. case 0x02: SiS_Pr->SiS_YPbPr = YPbPr750p; break;
  1046. case 0x03: SiS_Pr->SiS_YPbPr = YPbPrHiVision; break;
  1047. }
  1048. }
  1049. }
  1050. }
  1051. }
  1052. /*********************************************/
  1053. /* DETERMINE TVMode flag */
  1054. /*********************************************/
  1055. void
  1056. SiS_SetTVMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  1057. {
  1058. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  1059. unsigned short temp, temp1, resinfo = 0, romindex = 0;
  1060. unsigned char OutputSelect = *SiS_Pr->pSiS_OutputSelect;
  1061. SiS_Pr->SiS_TVMode = 0;
  1062. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) return;
  1063. if(SiS_Pr->UseCustomMode) return;
  1064. if(ModeNo > 0x13) {
  1065. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  1066. }
  1067. if(SiS_Pr->ChipType < SIS_661) {
  1068. if(SiS_Pr->SiS_VBInfo & SetPALTV) SiS_Pr->SiS_TVMode |= TVSetPAL;
  1069. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  1070. temp = 0;
  1071. if((SiS_Pr->ChipType == SIS_630) ||
  1072. (SiS_Pr->ChipType == SIS_730)) {
  1073. temp = 0x35;
  1074. romindex = 0xfe;
  1075. } else if(SiS_Pr->ChipType >= SIS_315H) {
  1076. temp = 0x38;
  1077. if(SiS_Pr->ChipType < XGI_20) {
  1078. romindex = 0xf3;
  1079. if(SiS_Pr->ChipType >= SIS_330) romindex = 0x11b;
  1080. }
  1081. }
  1082. if(temp) {
  1083. if(romindex && SiS_Pr->SiS_UseROM && (!(SiS_Pr->SiS_ROMNew))) {
  1084. OutputSelect = ROMAddr[romindex];
  1085. if(!(OutputSelect & EnablePALMN)) {
  1086. SiS_SetRegAND(SiS_Pr->SiS_P3d4,temp,0x3F);
  1087. }
  1088. }
  1089. temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,temp);
  1090. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  1091. if(temp1 & EnablePALM) { /* 0x40 */
  1092. SiS_Pr->SiS_TVMode |= TVSetPALM;
  1093. SiS_Pr->SiS_TVMode &= ~TVSetPAL;
  1094. } else if(temp1 & EnablePALN) { /* 0x80 */
  1095. SiS_Pr->SiS_TVMode |= TVSetPALN;
  1096. }
  1097. } else {
  1098. if(temp1 & EnableNTSCJ) { /* 0x40 */
  1099. SiS_Pr->SiS_TVMode |= TVSetNTSCJ;
  1100. }
  1101. }
  1102. }
  1103. /* Translate HiVision/YPbPr to our new flags */
  1104. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  1105. if(SiS_Pr->SiS_YPbPr == YPbPr750p) SiS_Pr->SiS_TVMode |= TVSetYPbPr750p;
  1106. else if(SiS_Pr->SiS_YPbPr == YPbPr525p) SiS_Pr->SiS_TVMode |= TVSetYPbPr525p;
  1107. else if(SiS_Pr->SiS_YPbPr == YPbPrHiVision) SiS_Pr->SiS_TVMode |= TVSetHiVision;
  1108. else SiS_Pr->SiS_TVMode |= TVSetYPbPr525i;
  1109. if(SiS_Pr->SiS_TVMode & (TVSetYPbPr750p | TVSetYPbPr525p | TVSetYPbPr525i)) {
  1110. SiS_Pr->SiS_VBInfo &= ~SetCRT2ToHiVision;
  1111. SiS_Pr->SiS_VBInfo |= SetCRT2ToYPbPr525750;
  1112. } else if(SiS_Pr->SiS_TVMode & TVSetHiVision) {
  1113. SiS_Pr->SiS_TVMode |= TVSetPAL;
  1114. }
  1115. }
  1116. } else if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  1117. if(SiS_Pr->SiS_CHOverScan) {
  1118. if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) {
  1119. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35);
  1120. if((temp & TVOverScan) || (SiS_Pr->SiS_CHOverScan == 1)) {
  1121. SiS_Pr->SiS_TVMode |= TVSetCHOverScan;
  1122. }
  1123. } else if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  1124. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x79);
  1125. if((temp & 0x80) || (SiS_Pr->SiS_CHOverScan == 1)) {
  1126. SiS_Pr->SiS_TVMode |= TVSetCHOverScan;
  1127. }
  1128. }
  1129. if(SiS_Pr->SiS_CHSOverScan) {
  1130. SiS_Pr->SiS_TVMode |= TVSetCHOverScan;
  1131. }
  1132. }
  1133. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  1134. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  1135. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  1136. if(temp & EnablePALM) SiS_Pr->SiS_TVMode |= TVSetPALM;
  1137. else if(temp & EnablePALN) SiS_Pr->SiS_TVMode |= TVSetPALN;
  1138. } else {
  1139. if(temp & EnableNTSCJ) {
  1140. SiS_Pr->SiS_TVMode |= TVSetNTSCJ;
  1141. }
  1142. }
  1143. }
  1144. }
  1145. } else { /* 661 and later */
  1146. temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35);
  1147. if(temp1 & 0x01) {
  1148. SiS_Pr->SiS_TVMode |= TVSetPAL;
  1149. if(temp1 & 0x08) {
  1150. SiS_Pr->SiS_TVMode |= TVSetPALN;
  1151. } else if(temp1 & 0x04) {
  1152. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  1153. SiS_Pr->SiS_TVMode &= ~TVSetPAL;
  1154. }
  1155. SiS_Pr->SiS_TVMode |= TVSetPALM;
  1156. }
  1157. } else {
  1158. if(temp1 & 0x02) {
  1159. SiS_Pr->SiS_TVMode |= TVSetNTSCJ;
  1160. }
  1161. }
  1162. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  1163. if(SiS_Pr->SiS_CHOverScan) {
  1164. if((temp1 & 0x10) || (SiS_Pr->SiS_CHOverScan == 1)) {
  1165. SiS_Pr->SiS_TVMode |= TVSetCHOverScan;
  1166. }
  1167. }
  1168. }
  1169. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  1170. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  1171. temp1 &= 0xe0;
  1172. if(temp1 == 0x00) SiS_Pr->SiS_TVMode |= TVSetYPbPr525i;
  1173. else if(temp1 == 0x20) SiS_Pr->SiS_TVMode |= TVSetYPbPr525p;
  1174. else if(temp1 == 0x40) SiS_Pr->SiS_TVMode |= TVSetYPbPr750p;
  1175. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  1176. SiS_Pr->SiS_TVMode |= (TVSetHiVision | TVSetPAL);
  1177. }
  1178. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToYPbPr525750 | SetCRT2ToHiVision)) {
  1179. if(resinfo == SIS_RI_800x480 || resinfo == SIS_RI_1024x576 || resinfo == SIS_RI_1280x720) {
  1180. SiS_Pr->SiS_TVMode |= TVAspect169;
  1181. } else {
  1182. temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x39);
  1183. if(temp1 & 0x02) {
  1184. if(SiS_Pr->SiS_TVMode & (TVSetYPbPr750p | TVSetHiVision)) {
  1185. SiS_Pr->SiS_TVMode |= TVAspect169;
  1186. } else {
  1187. SiS_Pr->SiS_TVMode |= TVAspect43LB;
  1188. }
  1189. } else {
  1190. SiS_Pr->SiS_TVMode |= TVAspect43;
  1191. }
  1192. }
  1193. }
  1194. }
  1195. }
  1196. if(SiS_Pr->SiS_VBInfo & SetCRT2ToSCART) SiS_Pr->SiS_TVMode |= TVSetPAL;
  1197. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  1198. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  1199. SiS_Pr->SiS_TVMode |= TVSetPAL;
  1200. SiS_Pr->SiS_TVMode &= ~(TVSetPALM | TVSetPALN | TVSetNTSCJ);
  1201. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  1202. if(SiS_Pr->SiS_TVMode & (TVSetYPbPr525i | TVSetYPbPr525p | TVSetYPbPr750p)) {
  1203. SiS_Pr->SiS_TVMode &= ~(TVSetPAL | TVSetNTSCJ | TVSetPALM | TVSetPALN);
  1204. }
  1205. }
  1206. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  1207. if(!(SiS_Pr->SiS_VBInfo & SetNotSimuMode)) {
  1208. SiS_Pr->SiS_TVMode |= TVSetTVSimuMode;
  1209. }
  1210. }
  1211. if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) {
  1212. if(resinfo == SIS_RI_1024x768) {
  1213. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) {
  1214. SiS_Pr->SiS_TVMode |= TVSet525p1024;
  1215. } else if(!(SiS_Pr->SiS_TVMode & (TVSetHiVision | TVSetYPbPr750p))) {
  1216. SiS_Pr->SiS_TVMode |= TVSetNTSC1024;
  1217. }
  1218. }
  1219. }
  1220. SiS_Pr->SiS_TVMode |= TVRPLLDIV2XO;
  1221. if((SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) &&
  1222. (SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  1223. SiS_Pr->SiS_TVMode &= ~TVRPLLDIV2XO;
  1224. } else if(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p)) {
  1225. SiS_Pr->SiS_TVMode &= ~TVRPLLDIV2XO;
  1226. } else if(!(SiS_Pr->SiS_VBType & VB_SIS30xBLV)) {
  1227. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) {
  1228. SiS_Pr->SiS_TVMode &= ~TVRPLLDIV2XO;
  1229. }
  1230. }
  1231. }
  1232. SiS_Pr->SiS_VBInfo &= ~SetPALTV;
  1233. #ifdef SIS_XORG_XF86
  1234. #ifdef TWDEBUG
  1235. xf86DrvMsg(0, X_INFO, "(init301: TVMode %x, VBInfo %x)\n", SiS_Pr->SiS_TVMode, SiS_Pr->SiS_VBInfo);
  1236. #endif
  1237. #endif
  1238. }
  1239. /*********************************************/
  1240. /* GET LCD INFO */
  1241. /*********************************************/
  1242. static unsigned short
  1243. SiS_GetBIOSLCDResInfo(struct SiS_Private *SiS_Pr)
  1244. {
  1245. unsigned short temp = SiS_Pr->SiS_LCDResInfo;
  1246. /* Translate my LCDResInfo to BIOS value */
  1247. switch(temp) {
  1248. case Panel_1280x768_2: temp = Panel_1280x768; break;
  1249. case Panel_1280x800_2: temp = Panel_1280x800; break;
  1250. case Panel_1280x854: temp = Panel661_1280x854; break;
  1251. }
  1252. return temp;
  1253. }
  1254. static void
  1255. SiS_GetLCDInfoBIOS(struct SiS_Private *SiS_Pr)
  1256. {
  1257. #ifdef SIS315H
  1258. unsigned char *ROMAddr;
  1259. unsigned short temp;
  1260. #ifdef SIS_XORG_XF86
  1261. #ifdef TWDEBUG
  1262. xf86DrvMsg(0, X_INFO, "Paneldata driver: [%d %d] [H %d %d] [V %d %d] [C %d 0x%02x 0x%02x]\n",
  1263. SiS_Pr->PanelHT, SiS_Pr->PanelVT,
  1264. SiS_Pr->PanelHRS, SiS_Pr->PanelHRE,
  1265. SiS_Pr->PanelVRS, SiS_Pr->PanelVRE,
  1266. SiS_Pr->SiS_VBVCLKData[SiS_Pr->PanelVCLKIdx315].CLOCK,
  1267. SiS_Pr->SiS_VBVCLKData[SiS_Pr->PanelVCLKIdx315].Part4_A,
  1268. SiS_Pr->SiS_VBVCLKData[SiS_Pr->PanelVCLKIdx315].Part4_B);
  1269. #endif
  1270. #endif
  1271. if((ROMAddr = GetLCDStructPtr661(SiS_Pr))) {
  1272. if((temp = SISGETROMW(6)) != SiS_Pr->PanelHT) {
  1273. SiS_Pr->SiS_NeedRomModeData = true;
  1274. SiS_Pr->PanelHT = temp;
  1275. }
  1276. if((temp = SISGETROMW(8)) != SiS_Pr->PanelVT) {
  1277. SiS_Pr->SiS_NeedRomModeData = true;
  1278. SiS_Pr->PanelVT = temp;
  1279. }
  1280. SiS_Pr->PanelHRS = SISGETROMW(10);
  1281. SiS_Pr->PanelHRE = SISGETROMW(12);
  1282. SiS_Pr->PanelVRS = SISGETROMW(14);
  1283. SiS_Pr->PanelVRE = SISGETROMW(16);
  1284. SiS_Pr->PanelVCLKIdx315 = VCLK_CUSTOM_315;
  1285. SiS_Pr->SiS_VCLKData[VCLK_CUSTOM_315].CLOCK =
  1286. SiS_Pr->SiS_VBVCLKData[VCLK_CUSTOM_315].CLOCK = (unsigned short)((unsigned char)ROMAddr[18]);
  1287. SiS_Pr->SiS_VCLKData[VCLK_CUSTOM_315].SR2B =
  1288. SiS_Pr->SiS_VBVCLKData[VCLK_CUSTOM_315].Part4_A = ROMAddr[19];
  1289. SiS_Pr->SiS_VCLKData[VCLK_CUSTOM_315].SR2C =
  1290. SiS_Pr->SiS_VBVCLKData[VCLK_CUSTOM_315].Part4_B = ROMAddr[20];
  1291. #ifdef SIS_XORG_XF86
  1292. #ifdef TWDEBUG
  1293. xf86DrvMsg(0, X_INFO, "Paneldata BIOS: [%d %d] [H %d %d] [V %d %d] [C %d 0x%02x 0x%02x]\n",
  1294. SiS_Pr->PanelHT, SiS_Pr->PanelVT,
  1295. SiS_Pr->PanelHRS, SiS_Pr->PanelHRE,
  1296. SiS_Pr->PanelVRS, SiS_Pr->PanelVRE,
  1297. SiS_Pr->SiS_VBVCLKData[SiS_Pr->PanelVCLKIdx315].CLOCK,
  1298. SiS_Pr->SiS_VBVCLKData[SiS_Pr->PanelVCLKIdx315].Part4_A,
  1299. SiS_Pr->SiS_VBVCLKData[SiS_Pr->PanelVCLKIdx315].Part4_B);
  1300. #endif
  1301. #endif
  1302. }
  1303. #endif
  1304. }
  1305. static void
  1306. SiS_CheckScaling(struct SiS_Private *SiS_Pr, unsigned short resinfo,
  1307. const unsigned char *nonscalingmodes)
  1308. {
  1309. int i = 0;
  1310. while(nonscalingmodes[i] != 0xff) {
  1311. if(nonscalingmodes[i++] == resinfo) {
  1312. if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) ||
  1313. (SiS_Pr->UsePanelScaler == -1)) {
  1314. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1315. }
  1316. break;
  1317. }
  1318. }
  1319. }
  1320. void
  1321. SiS_GetLCDResInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  1322. {
  1323. unsigned short temp,modeflag,resinfo=0,modexres=0,modeyres=0;
  1324. bool panelcanscale = false;
  1325. #ifdef SIS300
  1326. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  1327. static const unsigned char SiS300SeriesLCDRes[] =
  1328. { 0, 1, 2, 3, 7, 4, 5, 8,
  1329. 0, 0, 10, 0, 0, 0, 0, 15 };
  1330. #endif
  1331. #ifdef SIS315H
  1332. unsigned char *myptr = NULL;
  1333. #endif
  1334. SiS_Pr->SiS_LCDResInfo = 0;
  1335. SiS_Pr->SiS_LCDTypeInfo = 0;
  1336. SiS_Pr->SiS_LCDInfo = 0;
  1337. SiS_Pr->PanelHRS = 999; /* HSync start */
  1338. SiS_Pr->PanelHRE = 999; /* HSync end */
  1339. SiS_Pr->PanelVRS = 999; /* VSync start */
  1340. SiS_Pr->PanelVRE = 999; /* VSync end */
  1341. SiS_Pr->SiS_NeedRomModeData = false;
  1342. /* Alternative 1600x1200@60 timing for 1600x1200 LCDA */
  1343. SiS_Pr->Alternate1600x1200 = false;
  1344. if(!(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA))) return;
  1345. modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
  1346. if((ModeNo > 0x13) && (!SiS_Pr->UseCustomMode)) {
  1347. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  1348. modexres = SiS_Pr->SiS_ModeResInfo[resinfo].HTotal;
  1349. modeyres = SiS_Pr->SiS_ModeResInfo[resinfo].VTotal;
  1350. }
  1351. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36);
  1352. /* For broken BIOSes: Assume 1024x768 */
  1353. if(temp == 0) temp = 0x02;
  1354. if((SiS_Pr->ChipType >= SIS_661) || (SiS_Pr->SiS_ROMNew)) {
  1355. SiS_Pr->SiS_LCDTypeInfo = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x39) & 0x7c) >> 2;
  1356. } else if((SiS_Pr->ChipType < SIS_315H) || (SiS_Pr->ChipType >= SIS_661)) {
  1357. SiS_Pr->SiS_LCDTypeInfo = temp >> 4;
  1358. } else {
  1359. SiS_Pr->SiS_LCDTypeInfo = (temp & 0x0F) - 1;
  1360. }
  1361. temp &= 0x0f;
  1362. #ifdef SIS300
  1363. if(SiS_Pr->ChipType < SIS_315H) {
  1364. /* Very old BIOSes only know 7 sizes (NetVista 2179, 1.01g) */
  1365. if(SiS_Pr->SiS_VBType & VB_SIS301) {
  1366. if(temp < 0x0f) temp &= 0x07;
  1367. }
  1368. /* Translate 300 series LCDRes to 315 series for unified usage */
  1369. temp = SiS300SeriesLCDRes[temp];
  1370. }
  1371. #endif
  1372. /* Translate to our internal types */
  1373. #ifdef SIS315H
  1374. if(SiS_Pr->ChipType == SIS_550) {
  1375. if (temp == Panel310_1152x768) temp = Panel_320x240_2; /* Verified working */
  1376. else if(temp == Panel310_320x240_2) temp = Panel_320x240_2;
  1377. else if(temp == Panel310_320x240_3) temp = Panel_320x240_3;
  1378. } else if(SiS_Pr->ChipType >= SIS_661) {
  1379. if(temp == Panel661_1280x854) temp = Panel_1280x854;
  1380. }
  1381. #endif
  1382. if(SiS_Pr->SiS_VBType & VB_SISLVDS) { /* SiS LVDS */
  1383. if(temp == Panel310_1280x768) {
  1384. temp = Panel_1280x768_2;
  1385. }
  1386. if(SiS_Pr->SiS_ROMNew) {
  1387. if(temp == Panel661_1280x800) {
  1388. temp = Panel_1280x800_2;
  1389. }
  1390. }
  1391. }
  1392. SiS_Pr->SiS_LCDResInfo = temp;
  1393. #ifdef SIS300
  1394. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  1395. if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) {
  1396. SiS_Pr->SiS_LCDResInfo = Panel_Barco1366;
  1397. } else if(SiS_Pr->SiS_CustomT == CUT_PANEL848) {
  1398. SiS_Pr->SiS_LCDResInfo = Panel_848x480;
  1399. } else if(SiS_Pr->SiS_CustomT == CUT_PANEL856) {
  1400. SiS_Pr->SiS_LCDResInfo = Panel_856x480;
  1401. }
  1402. }
  1403. #endif
  1404. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  1405. if(SiS_Pr->SiS_LCDResInfo < SiS_Pr->SiS_PanelMin301)
  1406. SiS_Pr->SiS_LCDResInfo = SiS_Pr->SiS_PanelMin301;
  1407. } else {
  1408. if(SiS_Pr->SiS_LCDResInfo < SiS_Pr->SiS_PanelMinLVDS)
  1409. SiS_Pr->SiS_LCDResInfo = SiS_Pr->SiS_PanelMinLVDS;
  1410. }
  1411. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x37);
  1412. SiS_Pr->SiS_LCDInfo = temp & ~0x000e;
  1413. /* Need temp below! */
  1414. /* These must/can't scale no matter what */
  1415. switch(SiS_Pr->SiS_LCDResInfo) {
  1416. case Panel_320x240_1:
  1417. case Panel_320x240_2:
  1418. case Panel_320x240_3:
  1419. case Panel_1280x960:
  1420. SiS_Pr->SiS_LCDInfo &= ~DontExpandLCD;
  1421. break;
  1422. case Panel_640x480:
  1423. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1424. }
  1425. panelcanscale = (bool)(SiS_Pr->SiS_LCDInfo & DontExpandLCD);
  1426. if(!SiS_Pr->UsePanelScaler) SiS_Pr->SiS_LCDInfo &= ~DontExpandLCD;
  1427. else if(SiS_Pr->UsePanelScaler == 1) SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1428. /* Dual link, Pass 1:1 BIOS default, etc. */
  1429. #ifdef SIS315H
  1430. if(SiS_Pr->ChipType >= SIS_661) {
  1431. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  1432. if(temp & 0x08) SiS_Pr->SiS_LCDInfo |= LCDPass11;
  1433. }
  1434. if(SiS_Pr->SiS_VBType & VB_SISDUALLINK) {
  1435. if(SiS_Pr->SiS_ROMNew) {
  1436. if(temp & 0x02) SiS_Pr->SiS_LCDInfo |= LCDDualLink;
  1437. } else if((myptr = GetLCDStructPtr661(SiS_Pr))) {
  1438. if(myptr[2] & 0x01) SiS_Pr->SiS_LCDInfo |= LCDDualLink;
  1439. }
  1440. }
  1441. } else if(SiS_Pr->ChipType >= SIS_315H) {
  1442. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  1443. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x39) & 0x01) SiS_Pr->SiS_LCDInfo |= LCDPass11;
  1444. }
  1445. if((SiS_Pr->SiS_ROMNew) && (!(SiS_Pr->PanelSelfDetected))) {
  1446. SiS_Pr->SiS_LCDInfo &= ~(LCDRGB18Bit);
  1447. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35);
  1448. if(temp & 0x01) SiS_Pr->SiS_LCDInfo |= LCDRGB18Bit;
  1449. if(SiS_Pr->SiS_VBType & VB_SISDUALLINK) {
  1450. if(temp & 0x02) SiS_Pr->SiS_LCDInfo |= LCDDualLink;
  1451. }
  1452. } else if(!(SiS_Pr->SiS_ROMNew)) {
  1453. if(SiS_Pr->SiS_VBType & VB_SISDUALLINK) {
  1454. if((SiS_Pr->SiS_CustomT == CUT_CLEVO1024) &&
  1455. (SiS_Pr->SiS_LCDResInfo == Panel_1024x768)) {
  1456. SiS_Pr->SiS_LCDInfo |= LCDDualLink;
  1457. }
  1458. if((SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) ||
  1459. (SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) ||
  1460. (SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) ||
  1461. (SiS_Pr->SiS_LCDResInfo == Panel_1680x1050)) {
  1462. SiS_Pr->SiS_LCDInfo |= LCDDualLink;
  1463. }
  1464. }
  1465. }
  1466. }
  1467. #endif
  1468. /* Pass 1:1 */
  1469. if((SiS_Pr->SiS_IF_DEF_LVDS == 1) || (SiS_Pr->SiS_VBType & VB_NoLCD)) {
  1470. /* Always center screen on LVDS (if scaling is disabled) */
  1471. SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  1472. } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
  1473. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  1474. /* Always center screen on SiS LVDS (if scaling is disabled) */
  1475. SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  1476. } else {
  1477. /* By default, pass 1:1 on SiS TMDS (if scaling is supported) */
  1478. if(panelcanscale) SiS_Pr->SiS_LCDInfo |= LCDPass11;
  1479. if(SiS_Pr->CenterScreen == 1) SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  1480. }
  1481. }
  1482. SiS_Pr->PanelVCLKIdx300 = VCLK65_300;
  1483. SiS_Pr->PanelVCLKIdx315 = VCLK108_2_315;
  1484. switch(SiS_Pr->SiS_LCDResInfo) {
  1485. case Panel_320x240_1:
  1486. case Panel_320x240_2:
  1487. case Panel_320x240_3: SiS_Pr->PanelXRes = 640; SiS_Pr->PanelYRes = 480;
  1488. SiS_Pr->PanelVRS = 24; SiS_Pr->PanelVRE = 3;
  1489. SiS_Pr->PanelVCLKIdx300 = VCLK28;
  1490. SiS_Pr->PanelVCLKIdx315 = VCLK28;
  1491. break;
  1492. case Panel_640x480: SiS_Pr->PanelXRes = 640; SiS_Pr->PanelYRes = 480;
  1493. SiS_Pr->PanelVRE = 3;
  1494. SiS_Pr->PanelVCLKIdx300 = VCLK28;
  1495. SiS_Pr->PanelVCLKIdx315 = VCLK28;
  1496. break;
  1497. case Panel_800x600: SiS_Pr->PanelXRes = 800; SiS_Pr->PanelYRes = 600;
  1498. SiS_Pr->PanelHT = 1056; SiS_Pr->PanelVT = 628;
  1499. SiS_Pr->PanelHRS = 40; SiS_Pr->PanelHRE = 128;
  1500. SiS_Pr->PanelVRS = 1; SiS_Pr->PanelVRE = 4;
  1501. SiS_Pr->PanelVCLKIdx300 = VCLK40;
  1502. SiS_Pr->PanelVCLKIdx315 = VCLK40;
  1503. break;
  1504. case Panel_1024x600: SiS_Pr->PanelXRes = 1024; SiS_Pr->PanelYRes = 600;
  1505. SiS_Pr->PanelHT = 1344; SiS_Pr->PanelVT = 800;
  1506. SiS_Pr->PanelHRS = 24; SiS_Pr->PanelHRE = 136;
  1507. SiS_Pr->PanelVRS = 2 /* 88 */ ; SiS_Pr->PanelVRE = 6;
  1508. SiS_Pr->PanelVCLKIdx300 = VCLK65_300;
  1509. SiS_Pr->PanelVCLKIdx315 = VCLK65_315;
  1510. break;
  1511. case Panel_1024x768: SiS_Pr->PanelXRes = 1024; SiS_Pr->PanelYRes = 768;
  1512. SiS_Pr->PanelHT = 1344; SiS_Pr->PanelVT = 806;
  1513. SiS_Pr->PanelHRS = 24; SiS_Pr->PanelHRE = 136;
  1514. SiS_Pr->PanelVRS = 3; SiS_Pr->PanelVRE = 6;
  1515. if(SiS_Pr->ChipType < SIS_315H) {
  1516. SiS_Pr->PanelHRS = 23;
  1517. SiS_Pr->PanelVRE = 5;
  1518. }
  1519. SiS_Pr->PanelVCLKIdx300 = VCLK65_300;
  1520. SiS_Pr->PanelVCLKIdx315 = VCLK65_315;
  1521. SiS_GetLCDInfoBIOS(SiS_Pr);
  1522. break;
  1523. case Panel_1152x768: SiS_Pr->PanelXRes = 1152; SiS_Pr->PanelYRes = 768;
  1524. SiS_Pr->PanelHT = 1344; SiS_Pr->PanelVT = 806;
  1525. SiS_Pr->PanelHRS = 24; SiS_Pr->PanelHRE = 136;
  1526. SiS_Pr->PanelVRS = 3; SiS_Pr->PanelVRE = 6;
  1527. if(SiS_Pr->ChipType < SIS_315H) {
  1528. SiS_Pr->PanelHRS = 23;
  1529. SiS_Pr->PanelVRE = 5;
  1530. }
  1531. SiS_Pr->PanelVCLKIdx300 = VCLK65_300;
  1532. SiS_Pr->PanelVCLKIdx315 = VCLK65_315;
  1533. break;
  1534. case Panel_1152x864: SiS_Pr->PanelXRes = 1152; SiS_Pr->PanelYRes = 864;
  1535. break;
  1536. case Panel_1280x720: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 720;
  1537. SiS_Pr->PanelHT = 1650; SiS_Pr->PanelVT = 750;
  1538. SiS_Pr->PanelHRS = 110; SiS_Pr->PanelHRE = 40;
  1539. SiS_Pr->PanelVRS = 5; SiS_Pr->PanelVRE = 5;
  1540. SiS_Pr->PanelVCLKIdx315 = VCLK_1280x720;
  1541. /* Data above for TMDS (projector); get from BIOS for LVDS */
  1542. SiS_GetLCDInfoBIOS(SiS_Pr);
  1543. break;
  1544. case Panel_1280x768: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 768;
  1545. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  1546. SiS_Pr->PanelHT = 1408; SiS_Pr->PanelVT = 806;
  1547. SiS_Pr->PanelVCLKIdx300 = VCLK81_300; /* ? */
  1548. SiS_Pr->PanelVCLKIdx315 = VCLK81_315; /* ? */
  1549. } else {
  1550. SiS_Pr->PanelHT = 1688; SiS_Pr->PanelVT = 802;
  1551. SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRS = 112;
  1552. SiS_Pr->PanelVRS = 3; SiS_Pr->PanelVRE = 6;
  1553. SiS_Pr->PanelVCLKIdx300 = VCLK81_300;
  1554. SiS_Pr->PanelVCLKIdx315 = VCLK81_315;
  1555. }
  1556. break;
  1557. case Panel_1280x768_2: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 768;
  1558. SiS_Pr->PanelHT = 1660; SiS_Pr->PanelVT = 806;
  1559. SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 112;
  1560. SiS_Pr->PanelVRS = 3; SiS_Pr->PanelVRE = 6;
  1561. SiS_Pr->PanelVCLKIdx315 = VCLK_1280x768_2;
  1562. SiS_GetLCDInfoBIOS(SiS_Pr);
  1563. break;
  1564. case Panel_1280x800: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 800;
  1565. SiS_Pr->PanelHT = 1408; SiS_Pr->PanelVT = 816;
  1566. SiS_Pr->PanelHRS = 21; SiS_Pr->PanelHRE = 24;
  1567. SiS_Pr->PanelVRS = 4; SiS_Pr->PanelVRE = 3;
  1568. SiS_Pr->PanelVCLKIdx315 = VCLK_1280x800_315;
  1569. SiS_GetLCDInfoBIOS(SiS_Pr);
  1570. break;
  1571. case Panel_1280x800_2: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 800;
  1572. SiS_Pr->PanelHT = 1552; SiS_Pr->PanelVT = 812;
  1573. SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 112;
  1574. SiS_Pr->PanelVRS = 4; SiS_Pr->PanelVRE = 3;
  1575. SiS_Pr->PanelVCLKIdx315 = VCLK_1280x800_315_2;
  1576. SiS_GetLCDInfoBIOS(SiS_Pr);
  1577. break;
  1578. case Panel_1280x854: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 854;
  1579. SiS_Pr->PanelHT = 1664; SiS_Pr->PanelVT = 861;
  1580. SiS_Pr->PanelHRS = 16; SiS_Pr->PanelHRE = 112;
  1581. SiS_Pr->PanelVRS = 1; SiS_Pr->PanelVRE = 3;
  1582. SiS_Pr->PanelVCLKIdx315 = VCLK_1280x854;
  1583. SiS_GetLCDInfoBIOS(SiS_Pr);
  1584. break;
  1585. case Panel_1280x960: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 960;
  1586. SiS_Pr->PanelHT = 1800; SiS_Pr->PanelVT = 1000;
  1587. SiS_Pr->PanelVCLKIdx300 = VCLK108_3_300;
  1588. SiS_Pr->PanelVCLKIdx315 = VCLK108_3_315;
  1589. if(resinfo == SIS_RI_1280x1024) {
  1590. SiS_Pr->PanelVCLKIdx300 = VCLK100_300;
  1591. SiS_Pr->PanelVCLKIdx315 = VCLK100_315;
  1592. }
  1593. break;
  1594. case Panel_1280x1024: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 1024;
  1595. SiS_Pr->PanelHT = 1688; SiS_Pr->PanelVT = 1066;
  1596. SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 112;
  1597. SiS_Pr->PanelVRS = 1; SiS_Pr->PanelVRE = 3;
  1598. SiS_Pr->PanelVCLKIdx300 = VCLK108_3_300;
  1599. SiS_Pr->PanelVCLKIdx315 = VCLK108_2_315;
  1600. SiS_GetLCDInfoBIOS(SiS_Pr);
  1601. break;
  1602. case Panel_1400x1050: SiS_Pr->PanelXRes = 1400; SiS_Pr->PanelYRes = 1050;
  1603. SiS_Pr->PanelHT = 1688; SiS_Pr->PanelVT = 1066;
  1604. SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 112;
  1605. SiS_Pr->PanelVRS = 1; SiS_Pr->PanelVRE = 3;
  1606. SiS_Pr->PanelVCLKIdx315 = VCLK108_2_315;
  1607. SiS_GetLCDInfoBIOS(SiS_Pr);
  1608. break;
  1609. case Panel_1600x1200: SiS_Pr->PanelXRes = 1600; SiS_Pr->PanelYRes = 1200;
  1610. SiS_Pr->PanelHT = 2160; SiS_Pr->PanelVT = 1250;
  1611. SiS_Pr->PanelHRS = 64; SiS_Pr->PanelHRE = 192;
  1612. SiS_Pr->PanelVRS = 1; SiS_Pr->PanelVRE = 3;
  1613. SiS_Pr->PanelVCLKIdx315 = VCLK162_315;
  1614. if(SiS_Pr->SiS_VBType & VB_SISTMDSLCDA) {
  1615. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  1616. SiS_Pr->PanelHT = 1760; SiS_Pr->PanelVT = 1235;
  1617. SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 32;
  1618. SiS_Pr->PanelVRS = 2; SiS_Pr->PanelVRE = 4;
  1619. SiS_Pr->PanelVCLKIdx315 = VCLK130_315;
  1620. SiS_Pr->Alternate1600x1200 = true;
  1621. }
  1622. } else if(SiS_Pr->SiS_IF_DEF_LVDS) {
  1623. SiS_Pr->PanelHT = 2048; SiS_Pr->PanelVT = 1320;
  1624. SiS_Pr->PanelHRS = SiS_Pr->PanelHRE = 999;
  1625. SiS_Pr->PanelVRS = SiS_Pr->PanelVRE = 999;
  1626. }
  1627. SiS_GetLCDInfoBIOS(SiS_Pr);
  1628. break;
  1629. case Panel_1680x1050: SiS_Pr->PanelXRes = 1680; SiS_Pr->PanelYRes = 1050;
  1630. SiS_Pr->PanelHT = 1900; SiS_Pr->PanelVT = 1066;
  1631. SiS_Pr->PanelHRS = 26; SiS_Pr->PanelHRE = 76;
  1632. SiS_Pr->PanelVRS = 3; SiS_Pr->PanelVRE = 6;
  1633. SiS_Pr->PanelVCLKIdx315 = VCLK121_315;
  1634. SiS_GetLCDInfoBIOS(SiS_Pr);
  1635. break;
  1636. case Panel_Barco1366: SiS_Pr->PanelXRes = 1360; SiS_Pr->PanelYRes = 1024;
  1637. SiS_Pr->PanelHT = 1688; SiS_Pr->PanelVT = 1066;
  1638. break;
  1639. case Panel_848x480: SiS_Pr->PanelXRes = 848; SiS_Pr->PanelYRes = 480;
  1640. SiS_Pr->PanelHT = 1088; SiS_Pr->PanelVT = 525;
  1641. break;
  1642. case Panel_856x480: SiS_Pr->PanelXRes = 856; SiS_Pr->PanelYRes = 480;
  1643. SiS_Pr->PanelHT = 1088; SiS_Pr->PanelVT = 525;
  1644. break;
  1645. case Panel_Custom: SiS_Pr->PanelXRes = SiS_Pr->CP_MaxX;
  1646. SiS_Pr->PanelYRes = SiS_Pr->CP_MaxY;
  1647. SiS_Pr->PanelHT = SiS_Pr->CHTotal;
  1648. SiS_Pr->PanelVT = SiS_Pr->CVTotal;
  1649. if(SiS_Pr->CP_PreferredIndex != -1) {
  1650. SiS_Pr->PanelXRes = SiS_Pr->CP_HDisplay[SiS_Pr->CP_PreferredIndex];
  1651. SiS_Pr->PanelYRes = SiS_Pr->CP_VDisplay[SiS_Pr->CP_PreferredIndex];
  1652. SiS_Pr->PanelHT = SiS_Pr->CP_HTotal[SiS_Pr->CP_PreferredIndex];
  1653. SiS_Pr->PanelVT = SiS_Pr->CP_VTotal[SiS_Pr->CP_PreferredIndex];
  1654. SiS_Pr->PanelHRS = SiS_Pr->CP_HSyncStart[SiS_Pr->CP_PreferredIndex];
  1655. SiS_Pr->PanelHRE = SiS_Pr->CP_HSyncEnd[SiS_Pr->CP_PreferredIndex];
  1656. SiS_Pr->PanelVRS = SiS_Pr->CP_VSyncStart[SiS_Pr->CP_PreferredIndex];
  1657. SiS_Pr->PanelVRE = SiS_Pr->CP_VSyncEnd[SiS_Pr->CP_PreferredIndex];
  1658. SiS_Pr->PanelHRS -= SiS_Pr->PanelXRes;
  1659. SiS_Pr->PanelHRE -= SiS_Pr->PanelHRS;
  1660. SiS_Pr->PanelVRS -= SiS_Pr->PanelYRes;
  1661. SiS_Pr->PanelVRE -= SiS_Pr->PanelVRS;
  1662. if(SiS_Pr->CP_PrefClock) {
  1663. int idx;
  1664. SiS_Pr->PanelVCLKIdx315 = VCLK_CUSTOM_315;
  1665. SiS_Pr->PanelVCLKIdx300 = VCLK_CUSTOM_300;
  1666. if(SiS_Pr->ChipType < SIS_315H) idx = VCLK_CUSTOM_300;
  1667. else idx = VCLK_CUSTOM_315;
  1668. SiS_Pr->SiS_VCLKData[idx].CLOCK =
  1669. SiS_Pr->SiS_VBVCLKData[idx].CLOCK = SiS_Pr->CP_PrefClock;
  1670. SiS_Pr->SiS_VCLKData[idx].SR2B =
  1671. SiS_Pr->SiS_VBVCLKData[idx].Part4_A = SiS_Pr->CP_PrefSR2B;
  1672. SiS_Pr->SiS_VCLKData[idx].SR2C =
  1673. SiS_Pr->SiS_VBVCLKData[idx].Part4_B = SiS_Pr->CP_PrefSR2C;
  1674. }
  1675. }
  1676. break;
  1677. default: SiS_Pr->PanelXRes = 1024; SiS_Pr->PanelYRes = 768;
  1678. SiS_Pr->PanelHT = 1344; SiS_Pr->PanelVT = 806;
  1679. break;
  1680. }
  1681. /* Special cases */
  1682. if( (SiS_Pr->SiS_IF_DEF_FSTN) ||
  1683. (SiS_Pr->SiS_IF_DEF_DSTN) ||
  1684. (SiS_Pr->SiS_CustomT == CUT_BARCO1366) ||
  1685. (SiS_Pr->SiS_CustomT == CUT_BARCO1024) ||
  1686. (SiS_Pr->SiS_CustomT == CUT_PANEL848) ||
  1687. (SiS_Pr->SiS_CustomT == CUT_PANEL856) ) {
  1688. SiS_Pr->PanelHRS = 999;
  1689. SiS_Pr->PanelHRE = 999;
  1690. }
  1691. if( (SiS_Pr->SiS_CustomT == CUT_BARCO1366) ||
  1692. (SiS_Pr->SiS_CustomT == CUT_BARCO1024) ||
  1693. (SiS_Pr->SiS_CustomT == CUT_PANEL848) ||
  1694. (SiS_Pr->SiS_CustomT == CUT_PANEL856) ) {
  1695. SiS_Pr->PanelVRS = 999;
  1696. SiS_Pr->PanelVRE = 999;
  1697. }
  1698. /* DontExpand overrule */
  1699. if((SiS_Pr->SiS_VBType & VB_SISVB) && (!(SiS_Pr->SiS_VBType & VB_NoLCD))) {
  1700. if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && (modeflag & NoSupportLCDScale)) {
  1701. /* No scaling for this mode on any panel (LCD=CRT2)*/
  1702. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1703. }
  1704. switch(SiS_Pr->SiS_LCDResInfo) {
  1705. case Panel_Custom:
  1706. case Panel_1152x864:
  1707. case Panel_1280x768: /* TMDS only */
  1708. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1709. break;
  1710. case Panel_800x600: {
  1711. static const unsigned char nonscalingmodes[] = {
  1712. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, 0xff
  1713. };
  1714. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1715. break;
  1716. }
  1717. case Panel_1024x768: {
  1718. static const unsigned char nonscalingmodes[] = {
  1719. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1720. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1721. 0xff
  1722. };
  1723. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1724. break;
  1725. }
  1726. case Panel_1280x720: {
  1727. static const unsigned char nonscalingmodes[] = {
  1728. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1729. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1730. 0xff
  1731. };
  1732. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1733. if(SiS_Pr->PanelHT == 1650) {
  1734. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1735. }
  1736. break;
  1737. }
  1738. case Panel_1280x768_2: { /* LVDS only */
  1739. static const unsigned char nonscalingmodes[] = {
  1740. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1741. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1742. SIS_RI_1152x768,0xff
  1743. };
  1744. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1745. switch(resinfo) {
  1746. case SIS_RI_1280x720: if(SiS_Pr->UsePanelScaler == -1) {
  1747. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1748. }
  1749. break;
  1750. }
  1751. break;
  1752. }
  1753. case Panel_1280x800: { /* SiS TMDS special (Averatec 6200 series) */
  1754. static const unsigned char nonscalingmodes[] = {
  1755. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1756. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1757. SIS_RI_1152x768,SIS_RI_1280x720,SIS_RI_1280x768,0xff
  1758. };
  1759. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1760. break;
  1761. }
  1762. case Panel_1280x800_2: { /* SiS LVDS */
  1763. static const unsigned char nonscalingmodes[] = {
  1764. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1765. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1766. SIS_RI_1152x768,0xff
  1767. };
  1768. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1769. switch(resinfo) {
  1770. case SIS_RI_1280x720:
  1771. case SIS_RI_1280x768: if(SiS_Pr->UsePanelScaler == -1) {
  1772. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1773. }
  1774. break;
  1775. }
  1776. break;
  1777. }
  1778. case Panel_1280x854: { /* SiS LVDS */
  1779. static const unsigned char nonscalingmodes[] = {
  1780. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1781. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1782. SIS_RI_1152x768,0xff
  1783. };
  1784. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1785. switch(resinfo) {
  1786. case SIS_RI_1280x720:
  1787. case SIS_RI_1280x768:
  1788. case SIS_RI_1280x800: if(SiS_Pr->UsePanelScaler == -1) {
  1789. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1790. }
  1791. break;
  1792. }
  1793. break;
  1794. }
  1795. case Panel_1280x960: {
  1796. static const unsigned char nonscalingmodes[] = {
  1797. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1798. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1799. SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x720,SIS_RI_1280x768,SIS_RI_1280x800,
  1800. SIS_RI_1280x854,0xff
  1801. };
  1802. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1803. break;
  1804. }
  1805. case Panel_1280x1024: {
  1806. static const unsigned char nonscalingmodes[] = {
  1807. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1808. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1809. SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x720,SIS_RI_1280x768,SIS_RI_1280x800,
  1810. SIS_RI_1280x854,SIS_RI_1280x960,0xff
  1811. };
  1812. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1813. break;
  1814. }
  1815. case Panel_1400x1050: {
  1816. static const unsigned char nonscalingmodes[] = {
  1817. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1818. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1819. SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x768,SIS_RI_1280x800,SIS_RI_1280x854,
  1820. SIS_RI_1280x960,0xff
  1821. };
  1822. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1823. switch(resinfo) {
  1824. case SIS_RI_1280x720: if(SiS_Pr->UsePanelScaler == -1) {
  1825. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1826. }
  1827. break;
  1828. case SIS_RI_1280x1024: SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1829. break;
  1830. }
  1831. break;
  1832. }
  1833. case Panel_1600x1200: {
  1834. static const unsigned char nonscalingmodes[] = {
  1835. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1836. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1837. SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x720,SIS_RI_1280x768,SIS_RI_1280x800,
  1838. SIS_RI_1280x854,SIS_RI_1280x960,SIS_RI_1360x768,SIS_RI_1360x1024,0xff
  1839. };
  1840. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1841. break;
  1842. }
  1843. case Panel_1680x1050: {
  1844. static const unsigned char nonscalingmodes[] = {
  1845. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1846. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1847. SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x854,SIS_RI_1280x960,SIS_RI_1360x768,
  1848. SIS_RI_1360x1024,0xff
  1849. };
  1850. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1851. break;
  1852. }
  1853. }
  1854. }
  1855. #ifdef SIS300
  1856. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  1857. if(SiS_Pr->SiS_CustomT == CUT_PANEL848 || SiS_Pr->SiS_CustomT == CUT_PANEL856) {
  1858. SiS_Pr->SiS_LCDInfo = 0x80 | 0x40 | 0x20; /* neg h/v sync, RGB24(D0 = 0) */
  1859. }
  1860. }
  1861. if(SiS_Pr->ChipType < SIS_315H) {
  1862. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  1863. if(SiS_Pr->SiS_UseROM) {
  1864. if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) {
  1865. if(!(ROMAddr[0x235] & 0x02)) {
  1866. SiS_Pr->SiS_LCDInfo &= (~DontExpandLCD);
  1867. }
  1868. }
  1869. }
  1870. } else if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  1871. if((SiS_Pr->SiS_SetFlag & SetDOSMode) && ((ModeNo == 0x03) || (ModeNo == 0x10))) {
  1872. SiS_Pr->SiS_LCDInfo &= (~DontExpandLCD);
  1873. }
  1874. }
  1875. }
  1876. #endif
  1877. /* Special cases */
  1878. if(modexres == SiS_Pr->PanelXRes && modeyres == SiS_Pr->PanelYRes) {
  1879. SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  1880. }
  1881. if(SiS_Pr->SiS_IF_DEF_TRUMPION) {
  1882. SiS_Pr->SiS_LCDInfo |= (DontExpandLCD | LCDPass11);
  1883. }
  1884. switch(SiS_Pr->SiS_LCDResInfo) {
  1885. case Panel_640x480:
  1886. SiS_Pr->SiS_LCDInfo |= (DontExpandLCD | LCDPass11);
  1887. break;
  1888. case Panel_1280x800:
  1889. /* Don't pass 1:1 by default (TMDS special) */
  1890. if(SiS_Pr->CenterScreen == -1) SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  1891. break;
  1892. case Panel_1280x960:
  1893. SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  1894. break;
  1895. case Panel_Custom:
  1896. if((!SiS_Pr->CP_PrefClock) ||
  1897. (modexres > SiS_Pr->PanelXRes) || (modeyres > SiS_Pr->PanelYRes)) {
  1898. SiS_Pr->SiS_LCDInfo |= LCDPass11;
  1899. }
  1900. break;
  1901. }
  1902. if((SiS_Pr->UseCustomMode) || (SiS_Pr->SiS_CustomT == CUT_UNKNOWNLCD)) {
  1903. SiS_Pr->SiS_LCDInfo |= (DontExpandLCD | LCDPass11);
  1904. }
  1905. /* (In)validate LCDPass11 flag */
  1906. if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
  1907. SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  1908. }
  1909. /* LVDS DDA */
  1910. if(!((SiS_Pr->ChipType < SIS_315H) && (SiS_Pr->SiS_SetFlag & SetDOSMode))) {
  1911. if((SiS_Pr->SiS_IF_DEF_LVDS == 1) || (SiS_Pr->SiS_VBType & VB_NoLCD)) {
  1912. if(SiS_Pr->SiS_IF_DEF_TRUMPION == 0) {
  1913. if(ModeNo == 0x12) {
  1914. if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
  1915. SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
  1916. }
  1917. } else if(ModeNo > 0x13) {
  1918. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x600) {
  1919. if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
  1920. if((resinfo == SIS_RI_800x600) || (resinfo == SIS_RI_400x300)) {
  1921. SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
  1922. }
  1923. }
  1924. }
  1925. }
  1926. }
  1927. }
  1928. if(modeflag & HalfDCLK) {
  1929. if(SiS_Pr->SiS_IF_DEF_TRUMPION == 1) {
  1930. SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
  1931. } else if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  1932. SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
  1933. } else if(SiS_Pr->SiS_LCDResInfo == Panel_640x480) {
  1934. SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
  1935. } else if(ModeNo > 0x13) {
  1936. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  1937. if(resinfo == SIS_RI_512x384) SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
  1938. } else if(SiS_Pr->SiS_LCDResInfo == Panel_800x600) {
  1939. if(resinfo == SIS_RI_400x300) SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
  1940. }
  1941. }
  1942. }
  1943. }
  1944. /* VESA timing */
  1945. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  1946. if(SiS_Pr->SiS_VBInfo & SetNotSimuMode) {
  1947. SiS_Pr->SiS_SetFlag |= LCDVESATiming;
  1948. }
  1949. } else {
  1950. SiS_Pr->SiS_SetFlag |= LCDVESATiming;
  1951. }
  1952. #ifdef SIS_LINUX_KERNEL
  1953. #if 0
  1954. printk(KERN_DEBUG "sisfb: (LCDInfo=0x%04x LCDResInfo=0x%02x LCDTypeInfo=0x%02x)\n",
  1955. SiS_Pr->SiS_LCDInfo, SiS_Pr->SiS_LCDResInfo, SiS_Pr->SiS_LCDTypeInfo);
  1956. #endif
  1957. #endif
  1958. #ifdef SIS_XORG_XF86
  1959. xf86DrvMsgVerb(0, X_PROBED, 4,
  1960. "(init301: LCDInfo=0x%04x LCDResInfo=0x%02x LCDTypeInfo=0x%02x SetFlag=0x%04x)\n",
  1961. SiS_Pr->SiS_LCDInfo, SiS_Pr->SiS_LCDResInfo, SiS_Pr->SiS_LCDTypeInfo, SiS_Pr->SiS_SetFlag);
  1962. #endif
  1963. }
  1964. /*********************************************/
  1965. /* GET VCLK */
  1966. /*********************************************/
  1967. unsigned short
  1968. SiS_GetVCLK2Ptr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  1969. unsigned short RefreshRateTableIndex)
  1970. {
  1971. unsigned short CRT2Index, VCLKIndex = 0, VCLKIndexGEN = 0, VCLKIndexGENCRT = 0;
  1972. unsigned short modeflag, resinfo, tempbx;
  1973. const unsigned char *CHTVVCLKPtr = NULL;
  1974. if(ModeNo <= 0x13) {
  1975. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  1976. resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
  1977. CRT2Index = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  1978. VCLKIndexGEN = (SiS_GetRegByte((SiS_Pr->SiS_P3ca+0x02)) >> 2) & 0x03;
  1979. VCLKIndexGENCRT = VCLKIndexGEN;
  1980. } else {
  1981. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  1982. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  1983. CRT2Index = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  1984. VCLKIndexGEN = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
  1985. VCLKIndexGENCRT = SiS_GetRefCRTVCLK(SiS_Pr, RefreshRateTableIndex,
  1986. (SiS_Pr->SiS_SetFlag & ProgrammingCRT2) ? SiS_Pr->SiS_UseWideCRT2 : SiS_Pr->SiS_UseWide);
  1987. }
  1988. if(SiS_Pr->SiS_VBType & VB_SISVB) { /* 30x/B/LV */
  1989. if(SiS_Pr->SiS_SetFlag & ProgrammingCRT2) {
  1990. CRT2Index >>= 6;
  1991. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { /* LCD */
  1992. if(SiS_Pr->ChipType < SIS_315H) {
  1993. VCLKIndex = SiS_Pr->PanelVCLKIdx300;
  1994. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  1995. VCLKIndex = VCLKIndexGEN;
  1996. }
  1997. } else {
  1998. VCLKIndex = SiS_Pr->PanelVCLKIdx315;
  1999. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  2000. switch(resinfo) {
  2001. /* Correct those whose IndexGEN doesn't match VBVCLK array */
  2002. case SIS_RI_720x480: VCLKIndex = VCLK_720x480; break;
  2003. case SIS_RI_720x576: VCLKIndex = VCLK_720x576; break;
  2004. case SIS_RI_768x576: VCLKIndex = VCLK_768x576; break;
  2005. case SIS_RI_848x480: VCLKIndex = VCLK_848x480; break;
  2006. case SIS_RI_856x480: VCLKIndex = VCLK_856x480; break;
  2007. case SIS_RI_800x480: VCLKIndex = VCLK_800x480; break;
  2008. case SIS_RI_1024x576: VCLKIndex = VCLK_1024x576; break;
  2009. case SIS_RI_1152x864: VCLKIndex = VCLK_1152x864; break;
  2010. case SIS_RI_1280x720: VCLKIndex = VCLK_1280x720; break;
  2011. case SIS_RI_1360x768: VCLKIndex = VCLK_1360x768; break;
  2012. default: VCLKIndex = VCLKIndexGEN;
  2013. }
  2014. if(ModeNo <= 0x13) {
  2015. if(SiS_Pr->ChipType <= SIS_315PRO) {
  2016. if(SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC == 1) VCLKIndex = 0x42;
  2017. } else {
  2018. if(SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC == 1) VCLKIndex = 0x00;
  2019. }
  2020. }
  2021. if(SiS_Pr->ChipType <= SIS_315PRO) {
  2022. if(VCLKIndex == 0) VCLKIndex = 0x41;
  2023. if(VCLKIndex == 1) VCLKIndex = 0x43;
  2024. if(VCLKIndex == 4) VCLKIndex = 0x44;
  2025. }
  2026. }
  2027. }
  2028. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { /* TV */
  2029. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  2030. if(SiS_Pr->SiS_TVMode & TVRPLLDIV2XO) VCLKIndex = HiTVVCLKDIV2;
  2031. else VCLKIndex = HiTVVCLK;
  2032. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) VCLKIndex = HiTVSimuVCLK;
  2033. } else if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) VCLKIndex = YPbPr750pVCLK;
  2034. else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) VCLKIndex = TVVCLKDIV2;
  2035. else if(SiS_Pr->SiS_TVMode & TVRPLLDIV2XO) VCLKIndex = TVVCLKDIV2;
  2036. else VCLKIndex = TVVCLK;
  2037. if(SiS_Pr->ChipType < SIS_315H) VCLKIndex += TVCLKBASE_300;
  2038. else VCLKIndex += TVCLKBASE_315;
  2039. } else { /* VGA2 */
  2040. VCLKIndex = VCLKIndexGENCRT;
  2041. if(SiS_Pr->ChipType < SIS_315H) {
  2042. if(ModeNo > 0x13) {
  2043. if( (SiS_Pr->ChipType == SIS_630) &&
  2044. (SiS_Pr->ChipRevision >= 0x30)) {
  2045. if(VCLKIndex == 0x14) VCLKIndex = 0x34;
  2046. }
  2047. /* Better VGA2 clock for 1280x1024@75 */
  2048. if(VCLKIndex == 0x17) VCLKIndex = 0x45;
  2049. }
  2050. }
  2051. }
  2052. } else { /* If not programming CRT2 */
  2053. VCLKIndex = VCLKIndexGENCRT;
  2054. if(SiS_Pr->ChipType < SIS_315H) {
  2055. if(ModeNo > 0x13) {
  2056. if( (SiS_Pr->ChipType != SIS_630) &&
  2057. (SiS_Pr->ChipType != SIS_300) ) {
  2058. if(VCLKIndex == 0x1b) VCLKIndex = 0x48;
  2059. }
  2060. }
  2061. }
  2062. }
  2063. } else { /* LVDS */
  2064. VCLKIndex = CRT2Index;
  2065. if(SiS_Pr->SiS_SetFlag & ProgrammingCRT2) {
  2066. if( (SiS_Pr->SiS_IF_DEF_CH70xx != 0) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV) ) {
  2067. VCLKIndex &= 0x1f;
  2068. tempbx = 0;
  2069. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx += 1;
  2070. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  2071. tempbx += 2;
  2072. if(SiS_Pr->SiS_ModeType > ModeVGA) {
  2073. if(SiS_Pr->SiS_CHSOverScan) tempbx = 8;
  2074. }
  2075. if(SiS_Pr->SiS_TVMode & TVSetPALM) {
  2076. tempbx = 4;
  2077. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx += 1;
  2078. } else if(SiS_Pr->SiS_TVMode & TVSetPALN) {
  2079. tempbx = 6;
  2080. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx += 1;
  2081. }
  2082. }
  2083. switch(tempbx) {
  2084. case 0: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKUNTSC; break;
  2085. case 1: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKONTSC; break;
  2086. case 2: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKUPAL; break;
  2087. case 3: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKOPAL; break;
  2088. case 4: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKUPALM; break;
  2089. case 5: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKOPALM; break;
  2090. case 6: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKUPALN; break;
  2091. case 7: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKOPALN; break;
  2092. case 8: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKSOPAL; break;
  2093. default: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKOPAL; break;
  2094. }
  2095. VCLKIndex = CHTVVCLKPtr[VCLKIndex];
  2096. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  2097. if(SiS_Pr->ChipType < SIS_315H) {
  2098. VCLKIndex = SiS_Pr->PanelVCLKIdx300;
  2099. } else {
  2100. VCLKIndex = SiS_Pr->PanelVCLKIdx315;
  2101. }
  2102. #ifdef SIS300
  2103. /* Special Timing: Barco iQ Pro R series */
  2104. if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) VCLKIndex = 0x44;
  2105. /* Special Timing: 848x480 and 856x480 parallel lvds panels */
  2106. if(SiS_Pr->SiS_CustomT == CUT_PANEL848 || SiS_Pr->SiS_CustomT == CUT_PANEL856) {
  2107. if(SiS_Pr->ChipType < SIS_315H) {
  2108. VCLKIndex = VCLK34_300;
  2109. /* if(resinfo == SIS_RI_1360x768) VCLKIndex = ?; */
  2110. } else {
  2111. VCLKIndex = VCLK34_315;
  2112. /* if(resinfo == SIS_RI_1360x768) VCLKIndex = ?; */
  2113. }
  2114. }
  2115. #endif
  2116. } else {
  2117. VCLKIndex = VCLKIndexGENCRT;
  2118. if(SiS_Pr->ChipType < SIS_315H) {
  2119. if(ModeNo > 0x13) {
  2120. if( (SiS_Pr->ChipType == SIS_630) &&
  2121. (SiS_Pr->ChipRevision >= 0x30) ) {
  2122. if(VCLKIndex == 0x14) VCLKIndex = 0x2e;
  2123. }
  2124. }
  2125. }
  2126. }
  2127. } else { /* if not programming CRT2 */
  2128. VCLKIndex = VCLKIndexGENCRT;
  2129. if(SiS_Pr->ChipType < SIS_315H) {
  2130. if(ModeNo > 0x13) {
  2131. if( (SiS_Pr->ChipType != SIS_630) &&
  2132. (SiS_Pr->ChipType != SIS_300) ) {
  2133. if(VCLKIndex == 0x1b) VCLKIndex = 0x48;
  2134. }
  2135. #if 0
  2136. if(SiS_Pr->ChipType == SIS_730) {
  2137. if(VCLKIndex == 0x0b) VCLKIndex = 0x40; /* 1024x768-70 */
  2138. if(VCLKIndex == 0x0d) VCLKIndex = 0x41; /* 1024x768-75 */
  2139. }
  2140. #endif
  2141. }
  2142. }
  2143. }
  2144. }
  2145. #ifdef SIS_XORG_XF86
  2146. #ifdef TWDEBUG
  2147. xf86DrvMsg(0, X_INFO, "VCLKIndex %d (0x%x)\n", VCLKIndex, VCLKIndex);
  2148. #endif
  2149. #endif
  2150. return VCLKIndex;
  2151. }
  2152. /*********************************************/
  2153. /* SET CRT2 MODE TYPE REGISTERS */
  2154. /*********************************************/
  2155. static void
  2156. SiS_SetCRT2ModeRegs(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  2157. {
  2158. unsigned short i, j, modeflag, tempah=0;
  2159. short tempcl;
  2160. #if defined(SIS300) || defined(SIS315H)
  2161. unsigned short tempbl;
  2162. #endif
  2163. #ifdef SIS315H
  2164. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  2165. unsigned short tempah2, tempbl2;
  2166. #endif
  2167. modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
  2168. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  2169. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x00,0xAF,0x40);
  2170. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2E,0xF7);
  2171. } else {
  2172. for(i=0,j=4; i<3; i++,j++) SiS_SetReg(SiS_Pr->SiS_Part1Port,j,0);
  2173. if(SiS_Pr->ChipType >= SIS_315H) {
  2174. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x02,0x7F);
  2175. }
  2176. tempcl = SiS_Pr->SiS_ModeType;
  2177. if(SiS_Pr->ChipType < SIS_315H) {
  2178. #ifdef SIS300 /* ---- 300 series ---- */
  2179. /* For 301BDH: (with LCD via LVDS) */
  2180. if(SiS_Pr->SiS_VBType & VB_NoLCD) {
  2181. tempbl = SiS_GetReg(SiS_Pr->SiS_P3c4,0x32);
  2182. tempbl &= 0xef;
  2183. tempbl |= 0x02;
  2184. if((SiS_Pr->SiS_VBInfo & SetCRT2ToTV) || (SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) {
  2185. tempbl |= 0x10;
  2186. tempbl &= 0xfd;
  2187. }
  2188. SiS_SetReg(SiS_Pr->SiS_P3c4,0x32,tempbl);
  2189. }
  2190. if(ModeNo > 0x13) {
  2191. tempcl -= ModeVGA;
  2192. if(tempcl >= 0) {
  2193. tempah = ((0x10 >> tempcl) | 0x80);
  2194. }
  2195. } else tempah = 0x80;
  2196. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) tempah ^= 0xA0;
  2197. #endif /* SIS300 */
  2198. } else {
  2199. #ifdef SIS315H /* ------- 315/330 series ------ */
  2200. if(ModeNo > 0x13) {
  2201. tempcl -= ModeVGA;
  2202. if(tempcl >= 0) {
  2203. tempah = (0x08 >> tempcl);
  2204. if (tempah == 0) tempah = 1;
  2205. tempah |= 0x40;
  2206. }
  2207. } else tempah = 0x40;
  2208. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) tempah ^= 0x50;
  2209. #endif /* SIS315H */
  2210. }
  2211. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 0;
  2212. if(SiS_Pr->ChipType < SIS_315H) {
  2213. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,tempah);
  2214. } else {
  2215. #ifdef SIS315H
  2216. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  2217. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x00,0xa0,tempah);
  2218. } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
  2219. if(IS_SIS740) {
  2220. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,tempah);
  2221. } else {
  2222. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x00,0xa0,tempah);
  2223. }
  2224. }
  2225. #endif
  2226. }
  2227. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  2228. tempah = 0x01;
  2229. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  2230. tempah |= 0x02;
  2231. }
  2232. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) {
  2233. tempah ^= 0x05;
  2234. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) {
  2235. tempah ^= 0x01;
  2236. }
  2237. }
  2238. if(SiS_Pr->ChipType < SIS_315H) {
  2239. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 0;
  2240. tempah = (tempah << 5) & 0xFF;
  2241. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x01,tempah);
  2242. tempah = (tempah >> 5) & 0xFF;
  2243. } else {
  2244. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 0x08;
  2245. else if(!(SiS_IsDualEdge(SiS_Pr))) tempah |= 0x08;
  2246. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2E,0xF0,tempah);
  2247. tempah &= ~0x08;
  2248. }
  2249. if((SiS_Pr->SiS_ModeType == ModeVGA) && (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode))) {
  2250. tempah |= 0x10;
  2251. }
  2252. tempah |= 0x80;
  2253. if(SiS_Pr->SiS_VBType & VB_SIS301) {
  2254. if(SiS_Pr->PanelXRes < 1280 && SiS_Pr->PanelYRes < 960) tempah &= ~0x80;
  2255. }
  2256. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  2257. if(!(SiS_Pr->SiS_TVMode & (TVSetYPbPr750p | TVSetYPbPr525p))) {
  2258. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  2259. tempah |= 0x20;
  2260. }
  2261. }
  2262. }
  2263. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x0D,0x40,tempah);
  2264. tempah = 0x80;
  2265. if(SiS_Pr->SiS_VBType & VB_SIS301) {
  2266. if(SiS_Pr->PanelXRes < 1280 && SiS_Pr->PanelYRes < 960) tempah = 0;
  2267. }
  2268. if(SiS_IsDualLink(SiS_Pr)) tempah |= 0x40;
  2269. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  2270. if(SiS_Pr->SiS_TVMode & TVRPLLDIV2XO) {
  2271. tempah |= 0x40;
  2272. }
  2273. }
  2274. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0C,tempah);
  2275. } else { /* LVDS */
  2276. if(SiS_Pr->ChipType >= SIS_315H) {
  2277. #ifdef SIS315H
  2278. /* LVDS can only be slave in 8bpp modes */
  2279. tempah = 0x80;
  2280. if((modeflag & CRT2Mode) && (SiS_Pr->SiS_ModeType > ModeVGA)) {
  2281. if(SiS_Pr->SiS_VBInfo & DriverMode) {
  2282. tempah |= 0x02;
  2283. }
  2284. }
  2285. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) tempah |= 0x02;
  2286. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) tempah ^= 0x01;
  2287. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 1;
  2288. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2e,0xF0,tempah);
  2289. #endif
  2290. } else {
  2291. #ifdef SIS300
  2292. tempah = 0;
  2293. if( (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) && (SiS_Pr->SiS_ModeType > ModeVGA) ) {
  2294. tempah |= 0x02;
  2295. }
  2296. tempah <<= 5;
  2297. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 0;
  2298. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x01,tempah);
  2299. #endif
  2300. }
  2301. }
  2302. } /* LCDA */
  2303. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  2304. if(SiS_Pr->ChipType >= SIS_315H) {
  2305. #ifdef SIS315H
  2306. /* unsigned char bridgerev = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x01); */
  2307. /* The following is nearly unpreditable and varies from machine
  2308. * to machine. Especially the 301DH seems to be a real trouble
  2309. * maker. Some BIOSes simply set the registers (like in the
  2310. * NoLCD-if-statements here), some set them according to the
  2311. * LCDA stuff. It is very likely that some machines are not
  2312. * treated correctly in the following, very case-orientated
  2313. * code. What do I do then...?
  2314. */
  2315. /* 740 variants match for 30xB, 301B-DH, 30xLV */
  2316. if(!(IS_SIS740)) {
  2317. tempah = 0x04; /* For all bridges */
  2318. tempbl = 0xfb;
  2319. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  2320. tempah = 0x00;
  2321. if(SiS_IsDualEdge(SiS_Pr)) {
  2322. tempbl = 0xff;
  2323. }
  2324. }
  2325. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,tempbl,tempah);
  2326. }
  2327. /* The following two are responsible for eventually wrong colors
  2328. * in TV output. The DH (VB_NoLCD) conditions are unknown; the
  2329. * b0 was found in some 651 machine (Pim; P4_23=0xe5); the b1 version
  2330. * in a 650 box (Jake). What is the criteria?
  2331. * Addendum: Another combination 651+301B-DH(b1) (Rapo) needs same
  2332. * treatment like the 651+301B-DH(b0) case. Seems more to be the
  2333. * chipset than the bridge revision.
  2334. */
  2335. if((IS_SIS740) || (SiS_Pr->ChipType >= SIS_661) || (SiS_Pr->SiS_ROMNew)) {
  2336. tempah = 0x30;
  2337. tempbl = 0xc0;
  2338. if((SiS_Pr->SiS_VBInfo & DisableCRT2Display) ||
  2339. ((SiS_Pr->SiS_ROMNew) && (!(ROMAddr[0x5b] & 0x04)))) {
  2340. tempah = 0x00;
  2341. tempbl = 0x00;
  2342. }
  2343. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2c,0xcf,tempah);
  2344. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x21,0x3f,tempbl);
  2345. } else if(SiS_Pr->SiS_VBType & VB_SIS301) {
  2346. /* Fixes "TV-blue-bug" on 315+301 */
  2347. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2c,0xcf); /* For 301 */
  2348. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x21,0x3f);
  2349. } else if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  2350. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2c,0x30); /* For 30xLV */
  2351. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x21,0xc0);
  2352. } else if(SiS_Pr->SiS_VBType & VB_NoLCD) { /* For 301B-DH */
  2353. tempah = 0x30; tempah2 = 0xc0;
  2354. tempbl = 0xcf; tempbl2 = 0x3f;
  2355. if(SiS_Pr->SiS_TVBlue == 0) {
  2356. tempah = tempah2 = 0x00;
  2357. } else if(SiS_Pr->SiS_TVBlue == -1) {
  2358. /* Set on 651/M650, clear on 315/650 */
  2359. if(!(IS_SIS65x)) /* (bridgerev != 0xb0) */ {
  2360. tempah = tempah2 = 0x00;
  2361. }
  2362. }
  2363. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2c,tempbl,tempah);
  2364. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x21,tempbl2,tempah2);
  2365. } else {
  2366. tempah = 0x30; tempah2 = 0xc0; /* For 30xB, 301C */
  2367. tempbl = 0xcf; tempbl2 = 0x3f;
  2368. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  2369. tempah = tempah2 = 0x00;
  2370. if(SiS_IsDualEdge(SiS_Pr)) {
  2371. tempbl = tempbl2 = 0xff;
  2372. }
  2373. }
  2374. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2c,tempbl,tempah);
  2375. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x21,tempbl2,tempah2);
  2376. }
  2377. if(IS_SIS740) {
  2378. tempah = 0x80;
  2379. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 0x00;
  2380. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x23,0x7f,tempah);
  2381. } else {
  2382. tempah = 0x00;
  2383. tempbl = 0x7f;
  2384. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  2385. tempbl = 0xff;
  2386. if(!(SiS_IsDualEdge(SiS_Pr))) tempah = 0x80;
  2387. }
  2388. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x23,tempbl,tempah);
  2389. }
  2390. #endif /* SIS315H */
  2391. } else if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  2392. #ifdef SIS300
  2393. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x21,0x3f);
  2394. if((SiS_Pr->SiS_VBInfo & DisableCRT2Display) ||
  2395. ((SiS_Pr->SiS_VBType & VB_NoLCD) &&
  2396. (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD))) {
  2397. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x23,0x7F);
  2398. } else {
  2399. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x23,0x80);
  2400. }
  2401. #endif
  2402. }
  2403. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  2404. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x0D,0x80);
  2405. if(SiS_Pr->SiS_VBType & VB_SIS30xCLV) {
  2406. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x3A,0xC0);
  2407. }
  2408. }
  2409. } else { /* LVDS */
  2410. #ifdef SIS315H
  2411. if(SiS_Pr->ChipType >= SIS_315H) {
  2412. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  2413. tempah = 0x04;
  2414. tempbl = 0xfb;
  2415. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  2416. tempah = 0x00;
  2417. if(SiS_IsDualEdge(SiS_Pr)) tempbl = 0xff;
  2418. }
  2419. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,tempbl,tempah);
  2420. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) {
  2421. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xfb);
  2422. }
  2423. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2c,0x30);
  2424. } else if(SiS_Pr->ChipType == SIS_550) {
  2425. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xfb);
  2426. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2c,0x30);
  2427. }
  2428. }
  2429. #endif
  2430. }
  2431. }
  2432. /*********************************************/
  2433. /* GET RESOLUTION DATA */
  2434. /*********************************************/
  2435. unsigned short
  2436. SiS_GetResInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  2437. {
  2438. if(ModeNo <= 0x13)
  2439. return ((unsigned short)SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo);
  2440. else
  2441. return ((unsigned short)SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO);
  2442. }
  2443. static void
  2444. SiS_GetCRT2ResInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  2445. {
  2446. unsigned short xres, yres, modeflag=0, resindex;
  2447. if(SiS_Pr->UseCustomMode) {
  2448. xres = SiS_Pr->CHDisplay;
  2449. if(SiS_Pr->CModeFlag & HalfDCLK) xres <<= 1;
  2450. SiS_Pr->SiS_VGAHDE = SiS_Pr->SiS_HDE = xres;
  2451. /* DoubleScanMode-check done in CheckCalcCustomMode()! */
  2452. SiS_Pr->SiS_VGAVDE = SiS_Pr->SiS_VDE = SiS_Pr->CVDisplay;
  2453. return;
  2454. }
  2455. resindex = SiS_GetResInfo(SiS_Pr,ModeNo,ModeIdIndex);
  2456. if(ModeNo <= 0x13) {
  2457. xres = SiS_Pr->SiS_StResInfo[resindex].HTotal;
  2458. yres = SiS_Pr->SiS_StResInfo[resindex].VTotal;
  2459. } else {
  2460. xres = SiS_Pr->SiS_ModeResInfo[resindex].HTotal;
  2461. yres = SiS_Pr->SiS_ModeResInfo[resindex].VTotal;
  2462. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  2463. }
  2464. if(!SiS_Pr->SiS_IF_DEF_DSTN && !SiS_Pr->SiS_IF_DEF_FSTN) {
  2465. if((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->SiS_IF_DEF_LVDS == 1)) {
  2466. if((ModeNo != 0x03) && (SiS_Pr->SiS_SetFlag & SetDOSMode)) {
  2467. if(yres == 350) yres = 400;
  2468. }
  2469. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x3a) & 0x01) {
  2470. if(ModeNo == 0x12) yres = 400;
  2471. }
  2472. }
  2473. if(modeflag & HalfDCLK) xres <<= 1;
  2474. if(modeflag & DoubleScanMode) yres <<= 1;
  2475. }
  2476. if((SiS_Pr->SiS_VBType & VB_SISVB) && (!(SiS_Pr->SiS_VBType & VB_NoLCD))) {
  2477. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  2478. switch(SiS_Pr->SiS_LCDResInfo) {
  2479. case Panel_1024x768:
  2480. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
  2481. if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
  2482. if(yres == 350) yres = 357;
  2483. if(yres == 400) yres = 420;
  2484. if(yres == 480) yres = 525;
  2485. }
  2486. }
  2487. break;
  2488. case Panel_1280x1024:
  2489. if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
  2490. /* BIOS bug - does this regardless of scaling */
  2491. if(yres == 400) yres = 405;
  2492. }
  2493. if(yres == 350) yres = 360;
  2494. if(SiS_Pr->SiS_SetFlag & LCDVESATiming) {
  2495. if(yres == 360) yres = 375;
  2496. }
  2497. break;
  2498. case Panel_1600x1200:
  2499. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
  2500. if(yres == 1024) yres = 1056;
  2501. }
  2502. break;
  2503. }
  2504. }
  2505. } else {
  2506. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  2507. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToHiVision)) {
  2508. if(xres == 720) xres = 640;
  2509. }
  2510. } else if(xres == 720) xres = 640;
  2511. if(SiS_Pr->SiS_SetFlag & SetDOSMode) {
  2512. yres = 400;
  2513. if(SiS_Pr->ChipType >= SIS_315H) {
  2514. if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x17) & 0x80) yres = 480;
  2515. } else {
  2516. if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x80) yres = 480;
  2517. }
  2518. if(SiS_Pr->SiS_IF_DEF_DSTN || SiS_Pr->SiS_IF_DEF_FSTN) yres = 480;
  2519. }
  2520. }
  2521. SiS_Pr->SiS_VGAHDE = SiS_Pr->SiS_HDE = xres;
  2522. SiS_Pr->SiS_VGAVDE = SiS_Pr->SiS_VDE = yres;
  2523. }
  2524. /*********************************************/
  2525. /* GET CRT2 TIMING DATA */
  2526. /*********************************************/
  2527. static void
  2528. SiS_GetCRT2Ptr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  2529. unsigned short RefreshRateTableIndex, unsigned short *CRT2Index,
  2530. unsigned short *ResIndex)
  2531. {
  2532. unsigned short tempbx=0, tempal=0, resinfo=0;
  2533. if(ModeNo <= 0x13) {
  2534. tempal = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  2535. } else {
  2536. tempal = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  2537. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  2538. }
  2539. if((SiS_Pr->SiS_VBType & VB_SISVB) && (SiS_Pr->SiS_IF_DEF_LVDS == 0)) {
  2540. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { /* LCD */
  2541. tempbx = SiS_Pr->SiS_LCDResInfo;
  2542. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) tempbx += 32;
  2543. /* patch index */
  2544. if(SiS_Pr->SiS_LCDResInfo == Panel_1680x1050) {
  2545. if (resinfo == SIS_RI_1280x800) tempal = 9;
  2546. else if(resinfo == SIS_RI_1400x1050) tempal = 11;
  2547. } else if((SiS_Pr->SiS_LCDResInfo == Panel_1280x800) ||
  2548. (SiS_Pr->SiS_LCDResInfo == Panel_1280x800_2) ||
  2549. (SiS_Pr->SiS_LCDResInfo == Panel_1280x854)) {
  2550. if (resinfo == SIS_RI_1280x768) tempal = 9;
  2551. }
  2552. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  2553. /* Pass 1:1 only (center-screen handled outside) */
  2554. /* This is never called for the panel's native resolution */
  2555. /* since Pass1:1 will not be set in this case */
  2556. tempbx = 100;
  2557. if(ModeNo >= 0x13) {
  2558. tempal = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC_NS;
  2559. }
  2560. }
  2561. #ifdef SIS315H
  2562. if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) {
  2563. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) {
  2564. if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
  2565. tempbx = 200;
  2566. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) tempbx++;
  2567. }
  2568. }
  2569. }
  2570. #endif
  2571. } else { /* TV */
  2572. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  2573. /* if(SiS_Pr->SiS_VGAVDE > 480) SiS_Pr->SiS_TVMode &= (~TVSetTVSimuMode); */
  2574. tempbx = 2;
  2575. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  2576. tempbx = 13;
  2577. if(!(SiS_Pr->SiS_TVMode & TVSetTVSimuMode)) tempbx = 14;
  2578. }
  2579. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  2580. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) tempbx = 7;
  2581. else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) tempbx = 6;
  2582. else tempbx = 5;
  2583. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) tempbx += 5;
  2584. } else {
  2585. if(SiS_Pr->SiS_TVMode & TVSetPAL) tempbx = 3;
  2586. else tempbx = 4;
  2587. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) tempbx += 5;
  2588. }
  2589. }
  2590. tempal &= 0x3F;
  2591. if(ModeNo > 0x13) {
  2592. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoHiVision) {
  2593. switch(resinfo) {
  2594. case SIS_RI_720x480:
  2595. tempal = 6;
  2596. if(SiS_Pr->SiS_TVMode & (TVSetPAL | TVSetPALN)) tempal = 9;
  2597. break;
  2598. case SIS_RI_720x576:
  2599. case SIS_RI_768x576:
  2600. case SIS_RI_1024x576: /* Not in NTSC or YPBPR mode (except 1080i)! */
  2601. tempal = 6;
  2602. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  2603. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) tempal = 8;
  2604. }
  2605. break;
  2606. case SIS_RI_800x480:
  2607. tempal = 4;
  2608. break;
  2609. case SIS_RI_512x384:
  2610. case SIS_RI_1024x768:
  2611. tempal = 7;
  2612. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  2613. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) tempal = 8;
  2614. }
  2615. break;
  2616. case SIS_RI_1280x720:
  2617. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  2618. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) tempal = 9;
  2619. }
  2620. break;
  2621. }
  2622. }
  2623. }
  2624. *CRT2Index = tempbx;
  2625. *ResIndex = tempal;
  2626. } else { /* LVDS, 301B-DH (if running on LCD) */
  2627. tempbx = 0;
  2628. if((SiS_Pr->SiS_IF_DEF_CH70xx) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
  2629. tempbx = 90;
  2630. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  2631. tempbx = 92;
  2632. if(SiS_Pr->SiS_ModeType > ModeVGA) {
  2633. if(SiS_Pr->SiS_CHSOverScan) tempbx = 99;
  2634. }
  2635. if(SiS_Pr->SiS_TVMode & TVSetPALM) tempbx = 94;
  2636. else if(SiS_Pr->SiS_TVMode & TVSetPALN) tempbx = 96;
  2637. }
  2638. if(tempbx != 99) {
  2639. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx++;
  2640. }
  2641. } else {
  2642. switch(SiS_Pr->SiS_LCDResInfo) {
  2643. case Panel_640x480: tempbx = 12; break;
  2644. case Panel_320x240_1: tempbx = 10; break;
  2645. case Panel_320x240_2:
  2646. case Panel_320x240_3: tempbx = 14; break;
  2647. case Panel_800x600: tempbx = 16; break;
  2648. case Panel_1024x600: tempbx = 18; break;
  2649. case Panel_1152x768:
  2650. case Panel_1024x768: tempbx = 20; break;
  2651. case Panel_1280x768: tempbx = 22; break;
  2652. case Panel_1280x1024: tempbx = 24; break;
  2653. case Panel_1400x1050: tempbx = 26; break;
  2654. case Panel_1600x1200: tempbx = 28; break;
  2655. #ifdef SIS300
  2656. case Panel_Barco1366: tempbx = 80; break;
  2657. #endif
  2658. }
  2659. switch(SiS_Pr->SiS_LCDResInfo) {
  2660. case Panel_320x240_1:
  2661. case Panel_320x240_2:
  2662. case Panel_320x240_3:
  2663. case Panel_640x480:
  2664. break;
  2665. default:
  2666. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++;
  2667. }
  2668. if(SiS_Pr->SiS_LCDInfo & LCDPass11) tempbx = 30;
  2669. #ifdef SIS300
  2670. if(SiS_Pr->SiS_CustomT == CUT_BARCO1024) {
  2671. tempbx = 82;
  2672. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++;
  2673. } else if(SiS_Pr->SiS_CustomT == CUT_PANEL848 || SiS_Pr->SiS_CustomT == CUT_PANEL856) {
  2674. tempbx = 84;
  2675. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++;
  2676. }
  2677. #endif
  2678. }
  2679. (*CRT2Index) = tempbx;
  2680. (*ResIndex) = tempal & 0x1F;
  2681. }
  2682. }
  2683. static void
  2684. SiS_GetRAMDAC2DATA(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  2685. unsigned short RefreshRateTableIndex)
  2686. {
  2687. unsigned short tempax=0, tempbx=0, index, dotclock;
  2688. unsigned short temp1=0, modeflag=0, tempcx=0;
  2689. SiS_Pr->SiS_RVBHCMAX = 1;
  2690. SiS_Pr->SiS_RVBHCFACT = 1;
  2691. if(ModeNo <= 0x13) {
  2692. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  2693. index = SiS_GetModePtr(SiS_Pr,ModeNo,ModeIdIndex);
  2694. tempax = SiS_Pr->SiS_StandTable[index].CRTC[0];
  2695. tempbx = SiS_Pr->SiS_StandTable[index].CRTC[6];
  2696. temp1 = SiS_Pr->SiS_StandTable[index].CRTC[7];
  2697. dotclock = (modeflag & Charx8Dot) ? 8 : 9;
  2698. } else {
  2699. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  2700. index = SiS_GetRefCRT1CRTC(SiS_Pr, RefreshRateTableIndex, SiS_Pr->SiS_UseWideCRT2);
  2701. tempax = SiS_Pr->SiS_CRT1Table[index].CR[0];
  2702. tempax |= (SiS_Pr->SiS_CRT1Table[index].CR[14] << 8);
  2703. tempax &= 0x03FF;
  2704. tempbx = SiS_Pr->SiS_CRT1Table[index].CR[6];
  2705. tempcx = SiS_Pr->SiS_CRT1Table[index].CR[13] << 8;
  2706. tempcx &= 0x0100;
  2707. tempcx <<= 2;
  2708. tempbx |= tempcx;
  2709. temp1 = SiS_Pr->SiS_CRT1Table[index].CR[7];
  2710. dotclock = 8;
  2711. }
  2712. if(temp1 & 0x01) tempbx |= 0x0100;
  2713. if(temp1 & 0x20) tempbx |= 0x0200;
  2714. tempax += 5;
  2715. tempax *= dotclock;
  2716. if(modeflag & HalfDCLK) tempax <<= 1;
  2717. tempbx++;
  2718. SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_HT = tempax;
  2719. SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_VT = tempbx;
  2720. }
  2721. static void
  2722. SiS_CalcPanelLinkTiming(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
  2723. unsigned short ModeIdIndex, unsigned short RefreshRateTableIndex)
  2724. {
  2725. unsigned short ResIndex;
  2726. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  2727. if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
  2728. if(SiS_Pr->UseCustomMode) {
  2729. ResIndex = SiS_Pr->CHTotal;
  2730. if(SiS_Pr->CModeFlag & HalfDCLK) ResIndex <<= 1;
  2731. SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_HT = ResIndex;
  2732. SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_VT = SiS_Pr->CVTotal;
  2733. } else {
  2734. if(ModeNo < 0x13) {
  2735. ResIndex = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  2736. } else {
  2737. ResIndex = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC_NS;
  2738. }
  2739. if(ResIndex == 0x09) {
  2740. if(SiS_Pr->Alternate1600x1200) ResIndex = 0x20; /* 1600x1200 LCDA */
  2741. else if(SiS_Pr->SiS_IF_DEF_LVDS == 1) ResIndex = 0x21; /* 1600x1200 LVDS */
  2742. }
  2743. SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_NoScaleData[ResIndex].VGAHT;
  2744. SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_NoScaleData[ResIndex].VGAVT;
  2745. SiS_Pr->SiS_HT = SiS_Pr->SiS_NoScaleData[ResIndex].LCDHT;
  2746. SiS_Pr->SiS_VT = SiS_Pr->SiS_NoScaleData[ResIndex].LCDVT;
  2747. }
  2748. } else {
  2749. SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_HT = SiS_Pr->PanelHT;
  2750. SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_VT = SiS_Pr->PanelVT;
  2751. }
  2752. } else {
  2753. /* This handles custom modes and custom panels */
  2754. SiS_Pr->SiS_HDE = SiS_Pr->PanelXRes;
  2755. SiS_Pr->SiS_VDE = SiS_Pr->PanelYRes;
  2756. SiS_Pr->SiS_HT = SiS_Pr->PanelHT;
  2757. SiS_Pr->SiS_VT = SiS_Pr->PanelVT;
  2758. SiS_Pr->SiS_VGAHT = SiS_Pr->PanelHT - (SiS_Pr->PanelXRes - SiS_Pr->SiS_VGAHDE);
  2759. SiS_Pr->SiS_VGAVT = SiS_Pr->PanelVT - (SiS_Pr->PanelYRes - SiS_Pr->SiS_VGAVDE);
  2760. }
  2761. }
  2762. static void
  2763. SiS_GetCRT2DataLVDS(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  2764. unsigned short RefreshRateTableIndex)
  2765. {
  2766. unsigned short CRT2Index, ResIndex, backup;
  2767. const struct SiS_LVDSData *LVDSData = NULL;
  2768. SiS_GetCRT2ResInfo(SiS_Pr, ModeNo, ModeIdIndex);
  2769. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  2770. SiS_Pr->SiS_RVBHCMAX = 1;
  2771. SiS_Pr->SiS_RVBHCFACT = 1;
  2772. SiS_Pr->SiS_NewFlickerMode = 0;
  2773. SiS_Pr->SiS_RVBHRS = 50;
  2774. SiS_Pr->SiS_RY1COE = 0;
  2775. SiS_Pr->SiS_RY2COE = 0;
  2776. SiS_Pr->SiS_RY3COE = 0;
  2777. SiS_Pr->SiS_RY4COE = 0;
  2778. SiS_Pr->SiS_RVBHRS2 = 0;
  2779. }
  2780. if((SiS_Pr->SiS_VBType & VB_SISVB) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  2781. #ifdef SIS315H
  2782. SiS_CalcPanelLinkTiming(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  2783. SiS_CalcLCDACRT1Timing(SiS_Pr, ModeNo, ModeIdIndex);
  2784. #endif
  2785. } else {
  2786. /* 301BDH needs LVDS Data */
  2787. backup = SiS_Pr->SiS_IF_DEF_LVDS;
  2788. if((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) {
  2789. SiS_Pr->SiS_IF_DEF_LVDS = 1;
  2790. }
  2791. SiS_GetCRT2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex,
  2792. &CRT2Index, &ResIndex);
  2793. SiS_Pr->SiS_IF_DEF_LVDS = backup;
  2794. switch(CRT2Index) {
  2795. case 10: LVDSData = SiS_Pr->SiS_LVDS320x240Data_1; break;
  2796. case 14: LVDSData = SiS_Pr->SiS_LVDS320x240Data_2; break;
  2797. case 12: LVDSData = SiS_Pr->SiS_LVDS640x480Data_1; break;
  2798. case 16: LVDSData = SiS_Pr->SiS_LVDS800x600Data_1; break;
  2799. case 18: LVDSData = SiS_Pr->SiS_LVDS1024x600Data_1; break;
  2800. case 20: LVDSData = SiS_Pr->SiS_LVDS1024x768Data_1; break;
  2801. #ifdef SIS300
  2802. case 80: LVDSData = SiS_Pr->SiS_LVDSBARCO1366Data_1; break;
  2803. case 81: LVDSData = SiS_Pr->SiS_LVDSBARCO1366Data_2; break;
  2804. case 82: LVDSData = SiS_Pr->SiS_LVDSBARCO1024Data_1; break;
  2805. case 84: LVDSData = SiS_Pr->SiS_LVDS848x480Data_1; break;
  2806. case 85: LVDSData = SiS_Pr->SiS_LVDS848x480Data_2; break;
  2807. #endif
  2808. case 90: LVDSData = SiS_Pr->SiS_CHTVUNTSCData; break;
  2809. case 91: LVDSData = SiS_Pr->SiS_CHTVONTSCData; break;
  2810. case 92: LVDSData = SiS_Pr->SiS_CHTVUPALData; break;
  2811. case 93: LVDSData = SiS_Pr->SiS_CHTVOPALData; break;
  2812. case 94: LVDSData = SiS_Pr->SiS_CHTVUPALMData; break;
  2813. case 95: LVDSData = SiS_Pr->SiS_CHTVOPALMData; break;
  2814. case 96: LVDSData = SiS_Pr->SiS_CHTVUPALNData; break;
  2815. case 97: LVDSData = SiS_Pr->SiS_CHTVOPALNData; break;
  2816. case 99: LVDSData = SiS_Pr->SiS_CHTVSOPALData; break;
  2817. }
  2818. if(LVDSData) {
  2819. SiS_Pr->SiS_VGAHT = (LVDSData+ResIndex)->VGAHT;
  2820. SiS_Pr->SiS_VGAVT = (LVDSData+ResIndex)->VGAVT;
  2821. SiS_Pr->SiS_HT = (LVDSData+ResIndex)->LCDHT;
  2822. SiS_Pr->SiS_VT = (LVDSData+ResIndex)->LCDVT;
  2823. } else {
  2824. SiS_CalcPanelLinkTiming(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  2825. }
  2826. if( (!(SiS_Pr->SiS_VBType & VB_SISVB)) &&
  2827. (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) &&
  2828. (!(SiS_Pr->SiS_LCDInfo & LCDPass11)) ) {
  2829. if( (!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) ||
  2830. (SiS_Pr->SiS_SetFlag & SetDOSMode) ) {
  2831. SiS_Pr->SiS_HDE = SiS_Pr->PanelXRes;
  2832. SiS_Pr->SiS_VDE = SiS_Pr->PanelYRes;
  2833. #ifdef SIS300
  2834. if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) {
  2835. if(ResIndex < 0x08) {
  2836. SiS_Pr->SiS_HDE = 1280;
  2837. SiS_Pr->SiS_VDE = 1024;
  2838. }
  2839. }
  2840. #endif
  2841. }
  2842. }
  2843. }
  2844. }
  2845. static void
  2846. SiS_GetCRT2Data301(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  2847. unsigned short RefreshRateTableIndex)
  2848. {
  2849. unsigned char *ROMAddr = NULL;
  2850. unsigned short tempax, tempbx, modeflag, romptr=0;
  2851. unsigned short resinfo, CRT2Index, ResIndex;
  2852. const struct SiS_LCDData *LCDPtr = NULL;
  2853. const struct SiS_TVData *TVPtr = NULL;
  2854. #ifdef SIS315H
  2855. short resinfo661;
  2856. #endif
  2857. if(ModeNo <= 0x13) {
  2858. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  2859. resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
  2860. } else if(SiS_Pr->UseCustomMode) {
  2861. modeflag = SiS_Pr->CModeFlag;
  2862. resinfo = 0;
  2863. } else {
  2864. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  2865. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  2866. #ifdef SIS315H
  2867. resinfo661 = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].ROMMODEIDX661;
  2868. if( (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) &&
  2869. (SiS_Pr->SiS_SetFlag & LCDVESATiming) &&
  2870. (resinfo661 >= 0) &&
  2871. (SiS_Pr->SiS_NeedRomModeData) ) {
  2872. if((ROMAddr = GetLCDStructPtr661(SiS_Pr))) {
  2873. if((romptr = (SISGETROMW(21)))) {
  2874. romptr += (resinfo661 * 10);
  2875. ROMAddr = SiS_Pr->VirtualRomBase;
  2876. }
  2877. }
  2878. }
  2879. #endif
  2880. }
  2881. SiS_Pr->SiS_NewFlickerMode = 0;
  2882. SiS_Pr->SiS_RVBHRS = 50;
  2883. SiS_Pr->SiS_RY1COE = 0;
  2884. SiS_Pr->SiS_RY2COE = 0;
  2885. SiS_Pr->SiS_RY3COE = 0;
  2886. SiS_Pr->SiS_RY4COE = 0;
  2887. SiS_Pr->SiS_RVBHRS2 = 0;
  2888. SiS_GetCRT2ResInfo(SiS_Pr,ModeNo,ModeIdIndex);
  2889. if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) {
  2890. if(SiS_Pr->UseCustomMode) {
  2891. SiS_Pr->SiS_RVBHCMAX = 1;
  2892. SiS_Pr->SiS_RVBHCFACT = 1;
  2893. SiS_Pr->SiS_HDE = SiS_Pr->SiS_VGAHDE;
  2894. SiS_Pr->SiS_VDE = SiS_Pr->SiS_VGAVDE;
  2895. tempax = SiS_Pr->CHTotal;
  2896. if(modeflag & HalfDCLK) tempax <<= 1;
  2897. SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_HT = tempax;
  2898. SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_VT = SiS_Pr->CVTotal;
  2899. } else {
  2900. SiS_GetRAMDAC2DATA(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  2901. }
  2902. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  2903. SiS_GetCRT2Ptr(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex,
  2904. &CRT2Index,&ResIndex);
  2905. switch(CRT2Index) {
  2906. case 2: TVPtr = SiS_Pr->SiS_ExtHiTVData; break;
  2907. case 3: TVPtr = SiS_Pr->SiS_ExtPALData; break;
  2908. case 4: TVPtr = SiS_Pr->SiS_ExtNTSCData; break;
  2909. case 5: TVPtr = SiS_Pr->SiS_Ext525iData; break;
  2910. case 6: TVPtr = SiS_Pr->SiS_Ext525pData; break;
  2911. case 7: TVPtr = SiS_Pr->SiS_Ext750pData; break;
  2912. case 8: TVPtr = SiS_Pr->SiS_StPALData; break;
  2913. case 9: TVPtr = SiS_Pr->SiS_StNTSCData; break;
  2914. case 10: TVPtr = SiS_Pr->SiS_St525iData; break;
  2915. case 11: TVPtr = SiS_Pr->SiS_St525pData; break;
  2916. case 12: TVPtr = SiS_Pr->SiS_St750pData; break;
  2917. case 13: TVPtr = SiS_Pr->SiS_St1HiTVData; break;
  2918. case 14: TVPtr = SiS_Pr->SiS_St2HiTVData; break;
  2919. default: TVPtr = SiS_Pr->SiS_StPALData; break;
  2920. }
  2921. SiS_Pr->SiS_RVBHCMAX = (TVPtr+ResIndex)->RVBHCMAX;
  2922. SiS_Pr->SiS_RVBHCFACT = (TVPtr+ResIndex)->RVBHCFACT;
  2923. SiS_Pr->SiS_VGAHT = (TVPtr+ResIndex)->VGAHT;
  2924. SiS_Pr->SiS_VGAVT = (TVPtr+ResIndex)->VGAVT;
  2925. SiS_Pr->SiS_HDE = (TVPtr+ResIndex)->TVHDE;
  2926. SiS_Pr->SiS_VDE = (TVPtr+ResIndex)->TVVDE;
  2927. SiS_Pr->SiS_RVBHRS2 = (TVPtr+ResIndex)->RVBHRS2 & 0x0fff;
  2928. if(modeflag & HalfDCLK) {
  2929. SiS_Pr->SiS_RVBHRS = (TVPtr+ResIndex)->HALFRVBHRS;
  2930. if(SiS_Pr->SiS_RVBHRS2) {
  2931. SiS_Pr->SiS_RVBHRS2 = ((SiS_Pr->SiS_RVBHRS2 + 3) >> 1) - 3;
  2932. tempax = ((TVPtr+ResIndex)->RVBHRS2 >> 12) & 0x07;
  2933. if((TVPtr+ResIndex)->RVBHRS2 & 0x8000) SiS_Pr->SiS_RVBHRS2 -= tempax;
  2934. else SiS_Pr->SiS_RVBHRS2 += tempax;
  2935. }
  2936. } else {
  2937. SiS_Pr->SiS_RVBHRS = (TVPtr+ResIndex)->RVBHRS;
  2938. }
  2939. SiS_Pr->SiS_NewFlickerMode = ((TVPtr+ResIndex)->FlickerMode) << 7;
  2940. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  2941. if((resinfo == SIS_RI_960x600) ||
  2942. (resinfo == SIS_RI_1024x768) ||
  2943. (resinfo == SIS_RI_1280x1024) ||
  2944. (resinfo == SIS_RI_1280x720)) {
  2945. SiS_Pr->SiS_NewFlickerMode = 0x40;
  2946. }
  2947. if(SiS_Pr->SiS_VGAVDE == 350) SiS_Pr->SiS_TVMode |= TVSetTVSimuMode;
  2948. SiS_Pr->SiS_HT = ExtHiTVHT;
  2949. SiS_Pr->SiS_VT = ExtHiTVVT;
  2950. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  2951. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) {
  2952. SiS_Pr->SiS_HT = StHiTVHT;
  2953. SiS_Pr->SiS_VT = StHiTVVT;
  2954. }
  2955. }
  2956. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  2957. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) {
  2958. SiS_Pr->SiS_HT = 1650;
  2959. SiS_Pr->SiS_VT = 750;
  2960. } else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) {
  2961. SiS_Pr->SiS_HT = NTSCHT;
  2962. if(SiS_Pr->SiS_TVMode & TVSet525p1024) SiS_Pr->SiS_HT = NTSC2HT;
  2963. SiS_Pr->SiS_VT = NTSCVT;
  2964. } else {
  2965. SiS_Pr->SiS_HT = NTSCHT;
  2966. if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) SiS_Pr->SiS_HT = NTSC2HT;
  2967. SiS_Pr->SiS_VT = NTSCVT;
  2968. }
  2969. } else {
  2970. SiS_Pr->SiS_RY1COE = (TVPtr+ResIndex)->RY1COE;
  2971. SiS_Pr->SiS_RY2COE = (TVPtr+ResIndex)->RY2COE;
  2972. SiS_Pr->SiS_RY3COE = (TVPtr+ResIndex)->RY3COE;
  2973. SiS_Pr->SiS_RY4COE = (TVPtr+ResIndex)->RY4COE;
  2974. if(modeflag & HalfDCLK) {
  2975. SiS_Pr->SiS_RY1COE = 0x00;
  2976. SiS_Pr->SiS_RY2COE = 0xf4;
  2977. SiS_Pr->SiS_RY3COE = 0x10;
  2978. SiS_Pr->SiS_RY4COE = 0x38;
  2979. }
  2980. if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) {
  2981. SiS_Pr->SiS_HT = NTSCHT;
  2982. if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) SiS_Pr->SiS_HT = NTSC2HT;
  2983. SiS_Pr->SiS_VT = NTSCVT;
  2984. } else {
  2985. SiS_Pr->SiS_HT = PALHT;
  2986. SiS_Pr->SiS_VT = PALVT;
  2987. }
  2988. }
  2989. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  2990. SiS_Pr->SiS_RVBHCMAX = 1;
  2991. SiS_Pr->SiS_RVBHCFACT = 1;
  2992. if(SiS_Pr->UseCustomMode) {
  2993. SiS_Pr->SiS_HDE = SiS_Pr->SiS_VGAHDE;
  2994. SiS_Pr->SiS_VDE = SiS_Pr->SiS_VGAVDE;
  2995. tempax = SiS_Pr->CHTotal;
  2996. if(modeflag & HalfDCLK) tempax <<= 1;
  2997. SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_HT = tempax;
  2998. SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_VT = SiS_Pr->CVTotal;
  2999. } else {
  3000. bool gotit = false;
  3001. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
  3002. SiS_Pr->SiS_VGAHT = SiS_Pr->PanelHT;
  3003. SiS_Pr->SiS_VGAVT = SiS_Pr->PanelVT;
  3004. SiS_Pr->SiS_HT = SiS_Pr->PanelHT;
  3005. SiS_Pr->SiS_VT = SiS_Pr->PanelVT;
  3006. gotit = true;
  3007. } else if( (!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) && (romptr) && (ROMAddr) ) {
  3008. #ifdef SIS315H
  3009. SiS_Pr->SiS_RVBHCMAX = ROMAddr[romptr];
  3010. SiS_Pr->SiS_RVBHCFACT = ROMAddr[romptr+1];
  3011. SiS_Pr->SiS_VGAHT = ROMAddr[romptr+2] | ((ROMAddr[romptr+3] & 0x0f) << 8);
  3012. SiS_Pr->SiS_VGAVT = (ROMAddr[romptr+4] << 4) | ((ROMAddr[romptr+3] & 0xf0) >> 4);
  3013. SiS_Pr->SiS_HT = ROMAddr[romptr+5] | ((ROMAddr[romptr+6] & 0x0f) << 8);
  3014. SiS_Pr->SiS_VT = (ROMAddr[romptr+7] << 4) | ((ROMAddr[romptr+6] & 0xf0) >> 4);
  3015. SiS_Pr->SiS_RVBHRS2 = ROMAddr[romptr+8] | ((ROMAddr[romptr+9] & 0x0f) << 8);
  3016. if((SiS_Pr->SiS_RVBHRS2) && (modeflag & HalfDCLK)) {
  3017. SiS_Pr->SiS_RVBHRS2 = ((SiS_Pr->SiS_RVBHRS2 + 3) >> 1) - 3;
  3018. tempax = (ROMAddr[romptr+9] >> 4) & 0x07;
  3019. if(ROMAddr[romptr+9] & 0x80) SiS_Pr->SiS_RVBHRS2 -= tempax;
  3020. else SiS_Pr->SiS_RVBHRS2 += tempax;
  3021. }
  3022. if(SiS_Pr->SiS_VGAHT) gotit = true;
  3023. else {
  3024. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  3025. SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  3026. SiS_Pr->SiS_RVBHCMAX = 1;
  3027. SiS_Pr->SiS_RVBHCFACT = 1;
  3028. SiS_Pr->SiS_VGAHT = SiS_Pr->PanelHT;
  3029. SiS_Pr->SiS_VGAVT = SiS_Pr->PanelVT;
  3030. SiS_Pr->SiS_HT = SiS_Pr->PanelHT;
  3031. SiS_Pr->SiS_VT = SiS_Pr->PanelVT;
  3032. SiS_Pr->SiS_RVBHRS2 = 0;
  3033. gotit = true;
  3034. }
  3035. #endif
  3036. }
  3037. if(!gotit) {
  3038. SiS_GetCRT2Ptr(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex,
  3039. &CRT2Index,&ResIndex);
  3040. switch(CRT2Index) {
  3041. case Panel_1024x768 : LCDPtr = SiS_Pr->SiS_ExtLCD1024x768Data; break;
  3042. case Panel_1024x768 + 32: LCDPtr = SiS_Pr->SiS_St2LCD1024x768Data; break;
  3043. case Panel_1280x720 :
  3044. case Panel_1280x720 + 32: LCDPtr = SiS_Pr->SiS_LCD1280x720Data; break;
  3045. case Panel_1280x768_2 : LCDPtr = SiS_Pr->SiS_ExtLCD1280x768_2Data; break;
  3046. case Panel_1280x768_2+ 32: LCDPtr = SiS_Pr->SiS_StLCD1280x768_2Data; break;
  3047. case Panel_1280x800 :
  3048. case Panel_1280x800 + 32: LCDPtr = SiS_Pr->SiS_LCD1280x800Data; break;
  3049. case Panel_1280x800_2 :
  3050. case Panel_1280x800_2+ 32: LCDPtr = SiS_Pr->SiS_LCD1280x800_2Data; break;
  3051. case Panel_1280x854 :
  3052. case Panel_1280x854 + 32: LCDPtr = SiS_Pr->SiS_LCD1280x854Data; break;
  3053. case Panel_1280x960 :
  3054. case Panel_1280x960 + 32: LCDPtr = SiS_Pr->SiS_LCD1280x960Data; break;
  3055. case Panel_1280x1024 : LCDPtr = SiS_Pr->SiS_ExtLCD1280x1024Data; break;
  3056. case Panel_1280x1024 + 32: LCDPtr = SiS_Pr->SiS_St2LCD1280x1024Data; break;
  3057. case Panel_1400x1050 : LCDPtr = SiS_Pr->SiS_ExtLCD1400x1050Data; break;
  3058. case Panel_1400x1050 + 32: LCDPtr = SiS_Pr->SiS_StLCD1400x1050Data; break;
  3059. case Panel_1600x1200 : LCDPtr = SiS_Pr->SiS_ExtLCD1600x1200Data; break;
  3060. case Panel_1600x1200 + 32: LCDPtr = SiS_Pr->SiS_StLCD1600x1200Data; break;
  3061. case Panel_1680x1050 :
  3062. case Panel_1680x1050 + 32: LCDPtr = SiS_Pr->SiS_LCD1680x1050Data; break;
  3063. case 100 : LCDPtr = SiS_Pr->SiS_NoScaleData; break;
  3064. #ifdef SIS315H
  3065. case 200 : LCDPtr = SiS310_ExtCompaq1280x1024Data; break;
  3066. case 201 : LCDPtr = SiS_Pr->SiS_St2LCD1280x1024Data; break;
  3067. #endif
  3068. default : LCDPtr = SiS_Pr->SiS_ExtLCD1024x768Data; break;
  3069. }
  3070. #ifdef SIS_XORG_XF86
  3071. #ifdef TWDEBUG
  3072. xf86DrvMsg(0, X_INFO, "GetCRT2Data: Index %d ResIndex %d\n", CRT2Index, ResIndex);
  3073. #endif
  3074. #endif
  3075. SiS_Pr->SiS_RVBHCMAX = (LCDPtr+ResIndex)->RVBHCMAX;
  3076. SiS_Pr->SiS_RVBHCFACT = (LCDPtr+ResIndex)->RVBHCFACT;
  3077. SiS_Pr->SiS_VGAHT = (LCDPtr+ResIndex)->VGAHT;
  3078. SiS_Pr->SiS_VGAVT = (LCDPtr+ResIndex)->VGAVT;
  3079. SiS_Pr->SiS_HT = (LCDPtr+ResIndex)->LCDHT;
  3080. SiS_Pr->SiS_VT = (LCDPtr+ResIndex)->LCDVT;
  3081. }
  3082. tempax = SiS_Pr->PanelXRes;
  3083. tempbx = SiS_Pr->PanelYRes;
  3084. switch(SiS_Pr->SiS_LCDResInfo) {
  3085. case Panel_1024x768:
  3086. if(SiS_Pr->SiS_SetFlag & LCDVESATiming) {
  3087. if(SiS_Pr->ChipType < SIS_315H) {
  3088. if (SiS_Pr->SiS_VGAVDE == 350) tempbx = 560;
  3089. else if(SiS_Pr->SiS_VGAVDE == 400) tempbx = 640;
  3090. }
  3091. } else {
  3092. if (SiS_Pr->SiS_VGAVDE == 357) tempbx = 527;
  3093. else if(SiS_Pr->SiS_VGAVDE == 420) tempbx = 620;
  3094. else if(SiS_Pr->SiS_VGAVDE == 525) tempbx = 775;
  3095. else if(SiS_Pr->SiS_VGAVDE == 600) tempbx = 775;
  3096. else if(SiS_Pr->SiS_VGAVDE == 350) tempbx = 560;
  3097. else if(SiS_Pr->SiS_VGAVDE == 400) tempbx = 640;
  3098. }
  3099. break;
  3100. case Panel_1280x960:
  3101. if (SiS_Pr->SiS_VGAVDE == 350) tempbx = 700;
  3102. else if(SiS_Pr->SiS_VGAVDE == 400) tempbx = 800;
  3103. else if(SiS_Pr->SiS_VGAVDE == 1024) tempbx = 960;
  3104. break;
  3105. case Panel_1280x1024:
  3106. if (SiS_Pr->SiS_VGAVDE == 360) tempbx = 768;
  3107. else if(SiS_Pr->SiS_VGAVDE == 375) tempbx = 800;
  3108. else if(SiS_Pr->SiS_VGAVDE == 405) tempbx = 864;
  3109. break;
  3110. case Panel_1600x1200:
  3111. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
  3112. if (SiS_Pr->SiS_VGAVDE == 350) tempbx = 875;
  3113. else if(SiS_Pr->SiS_VGAVDE == 400) tempbx = 1000;
  3114. }
  3115. break;
  3116. }
  3117. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  3118. tempax = SiS_Pr->SiS_VGAHDE;
  3119. tempbx = SiS_Pr->SiS_VGAVDE;
  3120. }
  3121. SiS_Pr->SiS_HDE = tempax;
  3122. SiS_Pr->SiS_VDE = tempbx;
  3123. }
  3124. }
  3125. }
  3126. static void
  3127. SiS_GetCRT2Data(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  3128. unsigned short RefreshRateTableIndex)
  3129. {
  3130. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  3131. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  3132. SiS_GetCRT2DataLVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  3133. } else {
  3134. if((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) {
  3135. /* Need LVDS Data for LCD on 301B-DH */
  3136. SiS_GetCRT2DataLVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  3137. } else {
  3138. SiS_GetCRT2Data301(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  3139. }
  3140. }
  3141. } else {
  3142. SiS_GetCRT2DataLVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  3143. }
  3144. }
  3145. /*********************************************/
  3146. /* GET LVDS DES (SKEW) DATA */
  3147. /*********************************************/
  3148. static const struct SiS_LVDSDes *
  3149. SiS_GetLVDSDesPtr(struct SiS_Private *SiS_Pr)
  3150. {
  3151. const struct SiS_LVDSDes *PanelDesPtr = NULL;
  3152. #ifdef SIS300
  3153. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  3154. if(SiS_Pr->ChipType < SIS_315H) {
  3155. if(SiS_Pr->SiS_LCDTypeInfo == 4) {
  3156. if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) {
  3157. PanelDesPtr = SiS_Pr->SiS_PanelType04_1a;
  3158. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  3159. PanelDesPtr = SiS_Pr->SiS_PanelType04_2a;
  3160. }
  3161. } else if(SiS_Pr->SiS_CustomT == CUT_BARCO1024) {
  3162. PanelDesPtr = SiS_Pr->SiS_PanelType04_1b;
  3163. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  3164. PanelDesPtr = SiS_Pr->SiS_PanelType04_2b;
  3165. }
  3166. }
  3167. }
  3168. }
  3169. }
  3170. #endif
  3171. return PanelDesPtr;
  3172. }
  3173. static void
  3174. SiS_GetLVDSDesData(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  3175. unsigned short RefreshRateTableIndex)
  3176. {
  3177. unsigned short modeflag, ResIndex;
  3178. const struct SiS_LVDSDes *PanelDesPtr = NULL;
  3179. SiS_Pr->SiS_LCDHDES = 0;
  3180. SiS_Pr->SiS_LCDVDES = 0;
  3181. /* Some special cases */
  3182. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  3183. /* Trumpion */
  3184. if(SiS_Pr->SiS_IF_DEF_TRUMPION) {
  3185. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  3186. if(SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) {
  3187. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3188. }
  3189. }
  3190. return;
  3191. }
  3192. /* 640x480 on LVDS */
  3193. if(SiS_Pr->ChipType < SIS_315H) {
  3194. if(SiS_Pr->SiS_LCDResInfo == Panel_640x480 && SiS_Pr->SiS_LCDTypeInfo == 3) {
  3195. SiS_Pr->SiS_LCDHDES = 8;
  3196. if (SiS_Pr->SiS_VGAVDE >= 480) SiS_Pr->SiS_LCDVDES = 512;
  3197. else if(SiS_Pr->SiS_VGAVDE >= 400) SiS_Pr->SiS_LCDVDES = 436;
  3198. else if(SiS_Pr->SiS_VGAVDE >= 350) SiS_Pr->SiS_LCDVDES = 440;
  3199. return;
  3200. }
  3201. }
  3202. } /* LCD */
  3203. if( (SiS_Pr->UseCustomMode) ||
  3204. (SiS_Pr->SiS_LCDResInfo == Panel_Custom) ||
  3205. (SiS_Pr->SiS_CustomT == CUT_PANEL848) ||
  3206. (SiS_Pr->SiS_CustomT == CUT_PANEL856) ||
  3207. (SiS_Pr->SiS_LCDInfo & LCDPass11) ) {
  3208. return;
  3209. }
  3210. if(ModeNo <= 0x13) ResIndex = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  3211. else ResIndex = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  3212. if((SiS_Pr->SiS_VBType & VB_SIS30xBLV) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  3213. #ifdef SIS315H
  3214. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  3215. /* non-pass 1:1 only, see above */
  3216. if(SiS_Pr->SiS_VGAHDE != SiS_Pr->PanelXRes) {
  3217. SiS_Pr->SiS_LCDHDES = SiS_Pr->SiS_HT - ((SiS_Pr->PanelXRes - SiS_Pr->SiS_VGAHDE) / 2);
  3218. }
  3219. if(SiS_Pr->SiS_VGAVDE != SiS_Pr->PanelYRes) {
  3220. SiS_Pr->SiS_LCDVDES = SiS_Pr->SiS_VT - ((SiS_Pr->PanelYRes - SiS_Pr->SiS_VGAVDE) / 2);
  3221. }
  3222. }
  3223. if(SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) {
  3224. switch(SiS_Pr->SiS_CustomT) {
  3225. case CUT_UNIWILL1024:
  3226. case CUT_UNIWILL10242:
  3227. case CUT_CLEVO1400:
  3228. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  3229. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3230. }
  3231. break;
  3232. }
  3233. switch(SiS_Pr->SiS_LCDResInfo) {
  3234. case Panel_1280x1024:
  3235. if(SiS_Pr->SiS_CustomT != CUT_COMPAQ1280) {
  3236. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3237. }
  3238. break;
  3239. case Panel_1280x800: /* Verified for Averatec 6240 */
  3240. case Panel_1280x800_2: /* Verified for Asus A4L */
  3241. case Panel_1280x854: /* Not verified yet FIXME */
  3242. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3243. break;
  3244. }
  3245. }
  3246. #endif
  3247. } else {
  3248. if((SiS_Pr->SiS_IF_DEF_CH70xx != 0) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
  3249. if((SiS_Pr->SiS_TVMode & TVSetPAL) && (!(SiS_Pr->SiS_TVMode & TVSetPALM))) {
  3250. if(ResIndex <= 3) SiS_Pr->SiS_LCDHDES = 256;
  3251. }
  3252. } else if((PanelDesPtr = SiS_GetLVDSDesPtr(SiS_Pr))) {
  3253. SiS_Pr->SiS_LCDHDES = (PanelDesPtr+ResIndex)->LCDHDES;
  3254. SiS_Pr->SiS_LCDVDES = (PanelDesPtr+ResIndex)->LCDVDES;
  3255. } else if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  3256. if(SiS_Pr->SiS_VGAHDE != SiS_Pr->PanelXRes) {
  3257. SiS_Pr->SiS_LCDHDES = SiS_Pr->SiS_HT - ((SiS_Pr->PanelXRes - SiS_Pr->SiS_VGAHDE) / 2);
  3258. }
  3259. if(SiS_Pr->SiS_VGAVDE != SiS_Pr->PanelYRes) {
  3260. SiS_Pr->SiS_LCDVDES = SiS_Pr->SiS_VT - ((SiS_Pr->PanelYRes - SiS_Pr->SiS_VGAVDE) / 2);
  3261. } else {
  3262. if(SiS_Pr->ChipType < SIS_315H) {
  3263. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3264. } else {
  3265. switch(SiS_Pr->SiS_LCDResInfo) {
  3266. case Panel_800x600:
  3267. case Panel_1024x768:
  3268. case Panel_1280x1024:
  3269. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT;
  3270. break;
  3271. case Panel_1400x1050:
  3272. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3273. break;
  3274. }
  3275. }
  3276. }
  3277. } else {
  3278. if(SiS_Pr->ChipType < SIS_315H) {
  3279. #ifdef SIS300
  3280. switch(SiS_Pr->SiS_LCDResInfo) {
  3281. case Panel_800x600:
  3282. if(SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) {
  3283. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3284. } else {
  3285. SiS_Pr->SiS_LCDHDES = SiS_Pr->PanelHT + 3;
  3286. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT;
  3287. if(SiS_Pr->SiS_VGAVDE == 400) SiS_Pr->SiS_LCDVDES -= 2;
  3288. else SiS_Pr->SiS_LCDVDES -= 4;
  3289. }
  3290. break;
  3291. case Panel_1024x768:
  3292. if(SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) {
  3293. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3294. } else {
  3295. SiS_Pr->SiS_LCDHDES = SiS_Pr->PanelHT - 1;
  3296. if(SiS_Pr->SiS_VGAVDE <= 400) SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 8;
  3297. if(SiS_Pr->SiS_VGAVDE <= 350) SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 12;
  3298. }
  3299. break;
  3300. case Panel_1024x600:
  3301. default:
  3302. if( (SiS_Pr->SiS_VGAHDE == SiS_Pr->PanelXRes) &&
  3303. (SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) ) {
  3304. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3305. } else {
  3306. SiS_Pr->SiS_LCDHDES = SiS_Pr->PanelHT - 1;
  3307. }
  3308. break;
  3309. }
  3310. switch(SiS_Pr->SiS_LCDTypeInfo) {
  3311. case 1:
  3312. SiS_Pr->SiS_LCDHDES = SiS_Pr->SiS_LCDVDES = 0;
  3313. break;
  3314. case 3: /* 640x480 only? */
  3315. SiS_Pr->SiS_LCDHDES = 8;
  3316. if (SiS_Pr->SiS_VGAVDE >= 480) SiS_Pr->SiS_LCDVDES = 512;
  3317. else if(SiS_Pr->SiS_VGAVDE >= 400) SiS_Pr->SiS_LCDVDES = 436;
  3318. else if(SiS_Pr->SiS_VGAVDE >= 350) SiS_Pr->SiS_LCDVDES = 440;
  3319. break;
  3320. }
  3321. #endif
  3322. } else {
  3323. #ifdef SIS315H
  3324. switch(SiS_Pr->SiS_LCDResInfo) {
  3325. case Panel_1024x768:
  3326. case Panel_1280x1024:
  3327. if(SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) {
  3328. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3329. }
  3330. break;
  3331. case Panel_320x240_1:
  3332. case Panel_320x240_2:
  3333. case Panel_320x240_3:
  3334. SiS_Pr->SiS_LCDVDES = 524;
  3335. break;
  3336. }
  3337. #endif
  3338. }
  3339. }
  3340. if((ModeNo <= 0x13) && (SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
  3341. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  3342. if((SiS_Pr->SiS_VBType & VB_SIS30xBLV) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  3343. if(!(modeflag & HalfDCLK)) SiS_Pr->SiS_LCDHDES = 632;
  3344. } else if(!(SiS_Pr->SiS_SetFlag & SetDOSMode)) {
  3345. if(SiS_Pr->SiS_LCDResInfo != Panel_1280x1024) {
  3346. if(SiS_Pr->SiS_LCDResInfo >= Panel_1024x768) {
  3347. if(SiS_Pr->ChipType < SIS_315H) {
  3348. if(!(modeflag & HalfDCLK)) SiS_Pr->SiS_LCDHDES = 320;
  3349. } else {
  3350. #ifdef SIS315H
  3351. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) SiS_Pr->SiS_LCDHDES = 480;
  3352. if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) SiS_Pr->SiS_LCDHDES = 804;
  3353. if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) SiS_Pr->SiS_LCDHDES = 704;
  3354. if(!(modeflag & HalfDCLK)) {
  3355. SiS_Pr->SiS_LCDHDES = 320;
  3356. if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) SiS_Pr->SiS_LCDHDES = 632;
  3357. if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) SiS_Pr->SiS_LCDHDES = 542;
  3358. }
  3359. #endif
  3360. }
  3361. }
  3362. }
  3363. }
  3364. }
  3365. }
  3366. }
  3367. /*********************************************/
  3368. /* DISABLE VIDEO BRIDGE */
  3369. /*********************************************/
  3370. #ifdef SIS315H
  3371. static int
  3372. SiS_HandlePWD(struct SiS_Private *SiS_Pr)
  3373. {
  3374. int ret = 0;
  3375. #ifdef SET_PWD
  3376. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  3377. unsigned short romptr = GetLCDStructPtr661_2(SiS_Pr);
  3378. unsigned char drivermode = SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & 0x40;
  3379. unsigned short temp;
  3380. if( (SiS_Pr->SiS_VBType & VB_SISPWD) &&
  3381. (romptr) &&
  3382. (SiS_Pr->SiS_PWDOffset) ) {
  3383. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2b,ROMAddr[romptr + SiS_Pr->SiS_PWDOffset + 0]);
  3384. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2c,ROMAddr[romptr + SiS_Pr->SiS_PWDOffset + 1]);
  3385. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2d,ROMAddr[romptr + SiS_Pr->SiS_PWDOffset + 2]);
  3386. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2e,ROMAddr[romptr + SiS_Pr->SiS_PWDOffset + 3]);
  3387. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2f,ROMAddr[romptr + SiS_Pr->SiS_PWDOffset + 4]);
  3388. temp = 0x00;
  3389. if((ROMAddr[romptr + 2] & (0x06 << 1)) && !drivermode) {
  3390. temp = 0x80;
  3391. ret = 1;
  3392. }
  3393. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x27,0x7f,temp);
  3394. #ifdef SIS_XORG_XF86
  3395. #ifdef TWDEBUG
  3396. xf86DrvMsg(0, 0, "Setting PWD %x\n", temp);
  3397. #endif
  3398. #endif
  3399. }
  3400. #endif
  3401. return ret;
  3402. }
  3403. #endif
  3404. /* NEVER use any variables (VBInfo), this will be called
  3405. * from outside the context of modeswitch!
  3406. * MUST call getVBType before calling this
  3407. */
  3408. void
  3409. SiS_DisableBridge(struct SiS_Private *SiS_Pr)
  3410. {
  3411. #ifdef SIS315H
  3412. unsigned short tempah, pushax=0, modenum;
  3413. #endif
  3414. unsigned short temp=0;
  3415. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  3416. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) { /* ===== For 30xB/C/LV ===== */
  3417. if(SiS_Pr->ChipType < SIS_315H) {
  3418. #ifdef SIS300 /* 300 series */
  3419. if(!(SiS_CR36BIOSWord23b(SiS_Pr))) {
  3420. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3421. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFE);
  3422. } else {
  3423. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x08);
  3424. }
  3425. SiS_PanelDelay(SiS_Pr, 3);
  3426. }
  3427. if(SiS_Is301B(SiS_Pr)) {
  3428. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1f,0x3f);
  3429. SiS_ShortDelay(SiS_Pr,1);
  3430. }
  3431. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xDF);
  3432. SiS_DisplayOff(SiS_Pr);
  3433. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF);
  3434. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF);
  3435. SiS_UnLockCRT2(SiS_Pr);
  3436. if(!(SiS_Pr->SiS_VBType & VB_SISLVDS)) {
  3437. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x01,0x80);
  3438. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x02,0x40);
  3439. }
  3440. if( (!(SiS_CRT2IsLCD(SiS_Pr))) ||
  3441. (!(SiS_CR36BIOSWord23d(SiS_Pr))) ) {
  3442. SiS_PanelDelay(SiS_Pr, 2);
  3443. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3444. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFD);
  3445. } else {
  3446. SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x04);
  3447. }
  3448. }
  3449. #endif /* SIS300 */
  3450. } else {
  3451. #ifdef SIS315H /* 315 series */
  3452. int didpwd = 0;
  3453. bool custom1 = (SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) ||
  3454. (SiS_Pr->SiS_CustomT == CUT_CLEVO1400);
  3455. modenum = SiS_GetReg(SiS_Pr->SiS_P3d4,0x34) & 0x7f;
  3456. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3457. #ifdef SET_EMI
  3458. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  3459. if(SiS_Pr->SiS_CustomT != CUT_CLEVO1400) {
  3460. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
  3461. }
  3462. }
  3463. #endif
  3464. didpwd = SiS_HandlePWD(SiS_Pr);
  3465. if( (modenum <= 0x13) ||
  3466. (SiS_IsVAMode(SiS_Pr)) ||
  3467. (!(SiS_IsDualEdge(SiS_Pr))) ) {
  3468. if(!didpwd) {
  3469. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xfe);
  3470. if(custom1) SiS_PanelDelay(SiS_Pr, 3);
  3471. } else {
  3472. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xfc);
  3473. }
  3474. }
  3475. if(!custom1) {
  3476. SiS_DDC2Delay(SiS_Pr,0xff00);
  3477. SiS_DDC2Delay(SiS_Pr,0xe000);
  3478. SiS_SetRegByte(SiS_Pr->SiS_P3c6,0x00);
  3479. pushax = SiS_GetReg(SiS_Pr->SiS_P3c4,0x06);
  3480. if(IS_SIS740) {
  3481. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x06,0xE3);
  3482. }
  3483. SiS_PanelDelay(SiS_Pr, 3);
  3484. }
  3485. }
  3486. if(!(SiS_IsNotM650orLater(SiS_Pr))) {
  3487. /* if(SiS_Pr->ChipType < SIS_340) {*/
  3488. tempah = 0xef;
  3489. if(SiS_IsVAMode(SiS_Pr)) tempah = 0xf7;
  3490. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x4c,tempah);
  3491. /*}*/
  3492. }
  3493. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3494. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1F,~0x10);
  3495. }
  3496. tempah = 0x3f;
  3497. if(SiS_IsDualEdge(SiS_Pr)) {
  3498. tempah = 0x7f;
  3499. if(!(SiS_IsVAMode(SiS_Pr))) tempah = 0xbf;
  3500. }
  3501. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1F,tempah);
  3502. if((SiS_IsVAMode(SiS_Pr)) ||
  3503. ((SiS_Pr->SiS_VBType & VB_SISLVDS) && (modenum <= 0x13))) {
  3504. SiS_DisplayOff(SiS_Pr);
  3505. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3506. SiS_PanelDelay(SiS_Pr, 2);
  3507. }
  3508. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF);
  3509. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1E,0xDF);
  3510. }
  3511. if((!(SiS_IsVAMode(SiS_Pr))) ||
  3512. ((SiS_Pr->SiS_VBType & VB_SISLVDS) && (modenum <= 0x13))) {
  3513. if(!(SiS_IsDualEdge(SiS_Pr))) {
  3514. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xdf);
  3515. SiS_DisplayOff(SiS_Pr);
  3516. }
  3517. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x80);
  3518. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3519. SiS_PanelDelay(SiS_Pr, 2);
  3520. }
  3521. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF);
  3522. temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00);
  3523. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x10);
  3524. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF);
  3525. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,temp);
  3526. }
  3527. if(SiS_IsNotM650orLater(SiS_Pr)) {
  3528. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0x7f);
  3529. }
  3530. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3531. if( (!(SiS_IsVAMode(SiS_Pr))) &&
  3532. (!(SiS_CRT2IsLCD(SiS_Pr))) &&
  3533. (!(SiS_IsDualEdge(SiS_Pr))) ) {
  3534. if(custom1) SiS_PanelDelay(SiS_Pr, 2);
  3535. if(!didpwd) {
  3536. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFD);
  3537. }
  3538. if(custom1) SiS_PanelDelay(SiS_Pr, 4);
  3539. }
  3540. if(!custom1) {
  3541. SiS_SetReg(SiS_Pr->SiS_P3c4,0x06,pushax);
  3542. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  3543. if(SiS_IsVAorLCD(SiS_Pr)) {
  3544. SiS_PanelDelayLoop(SiS_Pr, 3, 20);
  3545. }
  3546. }
  3547. }
  3548. }
  3549. #endif /* SIS315H */
  3550. }
  3551. } else { /* ============ For 301 ================ */
  3552. if(SiS_Pr->ChipType < SIS_315H) {
  3553. #ifdef SIS300
  3554. if(!(SiS_CR36BIOSWord23b(SiS_Pr))) {
  3555. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x08);
  3556. SiS_PanelDelay(SiS_Pr, 3);
  3557. }
  3558. #endif
  3559. }
  3560. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xDF); /* disable VB */
  3561. SiS_DisplayOff(SiS_Pr);
  3562. if(SiS_Pr->ChipType >= SIS_315H) {
  3563. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x80);
  3564. }
  3565. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF); /* disable lock mode */
  3566. if(SiS_Pr->ChipType >= SIS_315H) {
  3567. temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00);
  3568. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x10);
  3569. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);
  3570. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,temp);
  3571. } else {
  3572. #ifdef SIS300
  3573. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF); /* disable CRT2 */
  3574. if( (!(SiS_CRT2IsLCD(SiS_Pr))) ||
  3575. (!(SiS_CR36BIOSWord23d(SiS_Pr))) ) {
  3576. SiS_PanelDelay(SiS_Pr, 2);
  3577. SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x04);
  3578. }
  3579. #endif
  3580. }
  3581. }
  3582. } else { /* ============ For LVDS =============*/
  3583. if(SiS_Pr->ChipType < SIS_315H) {
  3584. #ifdef SIS300 /* 300 series */
  3585. if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) {
  3586. SiS_SetCH700x(SiS_Pr,0x0E,0x09);
  3587. }
  3588. if(SiS_Pr->ChipType == SIS_730) {
  3589. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x11) & 0x08)) {
  3590. SiS_WaitVBRetrace(SiS_Pr);
  3591. }
  3592. if(!(SiS_CR36BIOSWord23b(SiS_Pr))) {
  3593. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x08);
  3594. SiS_PanelDelay(SiS_Pr, 3);
  3595. }
  3596. } else {
  3597. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x11) & 0x08)) {
  3598. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x40)) {
  3599. if(!(SiS_CR36BIOSWord23b(SiS_Pr))) {
  3600. SiS_WaitVBRetrace(SiS_Pr);
  3601. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x06) & 0x1c)) {
  3602. SiS_DisplayOff(SiS_Pr);
  3603. }
  3604. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x08);
  3605. SiS_PanelDelay(SiS_Pr, 3);
  3606. }
  3607. }
  3608. }
  3609. }
  3610. SiS_DisplayOff(SiS_Pr);
  3611. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF);
  3612. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF);
  3613. SiS_UnLockCRT2(SiS_Pr);
  3614. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x01,0x80);
  3615. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x02,0x40);
  3616. if( (!(SiS_CRT2IsLCD(SiS_Pr))) ||
  3617. (!(SiS_CR36BIOSWord23d(SiS_Pr))) ) {
  3618. SiS_PanelDelay(SiS_Pr, 2);
  3619. SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x04);
  3620. }
  3621. #endif /* SIS300 */
  3622. } else {
  3623. #ifdef SIS315H /* 315 series */
  3624. if(!(SiS_IsNotM650orLater(SiS_Pr))) {
  3625. /*if(SiS_Pr->ChipType < SIS_340) { */ /* XGI needs this */
  3626. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x4c,~0x18);
  3627. /* } */
  3628. }
  3629. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  3630. if(SiS_Pr->ChipType == SIS_740) {
  3631. temp = SiS_GetCH701x(SiS_Pr,0x61);
  3632. if(temp < 1) {
  3633. SiS_SetCH701x(SiS_Pr,0x76,0xac);
  3634. SiS_SetCH701x(SiS_Pr,0x66,0x00);
  3635. }
  3636. if( (!(SiS_IsDualEdge(SiS_Pr))) ||
  3637. (SiS_IsTVOrYPbPrOrScart(SiS_Pr)) ) {
  3638. SiS_SetCH701x(SiS_Pr,0x49,0x3e);
  3639. }
  3640. }
  3641. if( (!(SiS_IsDualEdge(SiS_Pr))) ||
  3642. (SiS_IsVAMode(SiS_Pr)) ) {
  3643. SiS_Chrontel701xBLOff(SiS_Pr);
  3644. SiS_Chrontel701xOff(SiS_Pr);
  3645. }
  3646. if(SiS_Pr->ChipType != SIS_740) {
  3647. if( (!(SiS_IsDualEdge(SiS_Pr))) ||
  3648. (SiS_IsTVOrYPbPrOrScart(SiS_Pr)) ) {
  3649. SiS_SetCH701x(SiS_Pr,0x49,0x01);
  3650. }
  3651. }
  3652. }
  3653. if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
  3654. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x08);
  3655. SiS_PanelDelay(SiS_Pr, 3);
  3656. }
  3657. if( (SiS_Pr->SiS_IF_DEF_CH70xx == 0) ||
  3658. (!(SiS_IsDualEdge(SiS_Pr))) ||
  3659. (!(SiS_IsTVOrYPbPrOrScart(SiS_Pr))) ) {
  3660. SiS_DisplayOff(SiS_Pr);
  3661. }
  3662. if( (SiS_Pr->SiS_IF_DEF_CH70xx == 0) ||
  3663. (!(SiS_IsDualEdge(SiS_Pr))) ||
  3664. (!(SiS_IsVAMode(SiS_Pr))) ) {
  3665. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x80);
  3666. }
  3667. if(SiS_Pr->ChipType == SIS_740) {
  3668. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0x7f);
  3669. }
  3670. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF);
  3671. if( (SiS_Pr->SiS_IF_DEF_CH70xx == 0) ||
  3672. (!(SiS_IsDualEdge(SiS_Pr))) ||
  3673. (!(SiS_IsVAMode(SiS_Pr))) ) {
  3674. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF);
  3675. }
  3676. if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
  3677. if(SiS_CRT2IsLCD(SiS_Pr)) {
  3678. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xdf);
  3679. if(SiS_Pr->ChipType == SIS_550) {
  3680. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xbf);
  3681. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xef);
  3682. }
  3683. }
  3684. } else {
  3685. if(SiS_Pr->ChipType == SIS_740) {
  3686. if(SiS_IsLCDOrLCDA(SiS_Pr)) {
  3687. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xdf);
  3688. }
  3689. } else if(SiS_IsVAMode(SiS_Pr)) {
  3690. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xdf);
  3691. }
  3692. }
  3693. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  3694. if(SiS_IsDualEdge(SiS_Pr)) {
  3695. /* SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xff); */
  3696. } else {
  3697. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xfb);
  3698. }
  3699. }
  3700. SiS_UnLockCRT2(SiS_Pr);
  3701. if(SiS_Pr->ChipType == SIS_550) {
  3702. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x01,0x80); /* DirectDVD PAL?*/
  3703. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x02,0x40); /* VB clock / 4 ? */
  3704. } else if( (SiS_Pr->SiS_IF_DEF_CH70xx == 0) ||
  3705. (!(SiS_IsDualEdge(SiS_Pr))) ||
  3706. (!(SiS_IsVAMode(SiS_Pr))) ) {
  3707. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0xf7);
  3708. }
  3709. if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
  3710. if(SiS_CRT2IsLCD(SiS_Pr)) {
  3711. if(!(SiS_WeHaveBacklightCtrl(SiS_Pr))) {
  3712. SiS_PanelDelay(SiS_Pr, 2);
  3713. SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x04);
  3714. }
  3715. }
  3716. }
  3717. #endif /* SIS315H */
  3718. } /* 315 series */
  3719. } /* LVDS */
  3720. }
  3721. /*********************************************/
  3722. /* ENABLE VIDEO BRIDGE */
  3723. /*********************************************/
  3724. /* NEVER use any variables (VBInfo), this will be called
  3725. * from outside the context of a mode switch!
  3726. * MUST call getVBType before calling this
  3727. */
  3728. #ifdef SIS_LINUX_KERNEL
  3729. static
  3730. #endif
  3731. void
  3732. SiS_EnableBridge(struct SiS_Private *SiS_Pr)
  3733. {
  3734. unsigned short temp=0, tempah;
  3735. #ifdef SIS315H
  3736. unsigned short temp1, pushax=0;
  3737. bool delaylong = false;
  3738. #endif
  3739. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  3740. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) { /* ====== For 301B et al ====== */
  3741. if(SiS_Pr->ChipType < SIS_315H) {
  3742. #ifdef SIS300 /* 300 series */
  3743. if(SiS_CRT2IsLCD(SiS_Pr)) {
  3744. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3745. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x02);
  3746. } else if(SiS_Pr->SiS_VBType & VB_NoLCD) {
  3747. SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x00);
  3748. }
  3749. if(SiS_Pr->SiS_VBType & (VB_SISLVDS | VB_NoLCD)) {
  3750. if(!(SiS_CR36BIOSWord23d(SiS_Pr))) {
  3751. SiS_PanelDelay(SiS_Pr, 0);
  3752. }
  3753. }
  3754. }
  3755. if((SiS_Pr->SiS_VBType & VB_NoLCD) &&
  3756. (SiS_CRT2IsLCD(SiS_Pr))) {
  3757. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20); /* Enable CRT2 */
  3758. SiS_DisplayOn(SiS_Pr);
  3759. SiS_UnLockCRT2(SiS_Pr);
  3760. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x02,0xBF);
  3761. if(SiS_BridgeInSlavemode(SiS_Pr)) {
  3762. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x01,0x1F);
  3763. } else {
  3764. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x01,0x1F,0x40);
  3765. }
  3766. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x40)) {
  3767. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x16) & 0x10)) {
  3768. if(!(SiS_CR36BIOSWord23b(SiS_Pr))) {
  3769. SiS_PanelDelay(SiS_Pr, 1);
  3770. }
  3771. SiS_WaitVBRetrace(SiS_Pr);
  3772. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x00);
  3773. }
  3774. }
  3775. } else {
  3776. temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x32) & 0xDF; /* lock mode */
  3777. if(SiS_BridgeInSlavemode(SiS_Pr)) {
  3778. tempah = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  3779. if(!(tempah & SetCRT2ToRAMDAC)) temp |= 0x20;
  3780. }
  3781. SiS_SetReg(SiS_Pr->SiS_P3c4,0x32,temp);
  3782. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);
  3783. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x00,0x1F,0x20); /* enable VB processor */
  3784. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x1F,0xC0);
  3785. SiS_DisplayOn(SiS_Pr);
  3786. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3787. if(SiS_CRT2IsLCD(SiS_Pr)) {
  3788. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x16) & 0x10)) {
  3789. if(!(SiS_CR36BIOSWord23b(SiS_Pr))) {
  3790. SiS_PanelDelay(SiS_Pr, 1);
  3791. }
  3792. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x01);
  3793. }
  3794. }
  3795. }
  3796. }
  3797. #endif /* SIS300 */
  3798. } else {
  3799. #ifdef SIS315H /* 315 series */
  3800. #ifdef SET_EMI
  3801. unsigned char r30=0, r31=0, r32=0, r33=0, cr36=0;
  3802. int didpwd = 0;
  3803. /* unsigned short emidelay=0; */
  3804. #endif
  3805. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3806. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1f,0xef);
  3807. #ifdef SET_EMI
  3808. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  3809. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
  3810. }
  3811. #endif
  3812. }
  3813. if(!(SiS_IsNotM650orLater(SiS_Pr))) {
  3814. /*if(SiS_Pr->ChipType < SIS_340) { */
  3815. tempah = 0x10;
  3816. if(SiS_LCDAEnabled(SiS_Pr)) {
  3817. if(SiS_TVEnabled(SiS_Pr)) tempah = 0x18;
  3818. else tempah = 0x08;
  3819. }
  3820. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x4c,tempah);
  3821. /*}*/
  3822. }
  3823. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3824. SiS_SetRegByte(SiS_Pr->SiS_P3c6,0x00);
  3825. SiS_DisplayOff(SiS_Pr);
  3826. pushax = SiS_GetReg(SiS_Pr->SiS_P3c4,0x06);
  3827. if(IS_SIS740) {
  3828. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x06,0xE3);
  3829. }
  3830. didpwd = SiS_HandlePWD(SiS_Pr);
  3831. if(SiS_IsVAorLCD(SiS_Pr)) {
  3832. if(!didpwd) {
  3833. if(!(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x26) & 0x02)) {
  3834. SiS_PanelDelayLoop(SiS_Pr, 3, 2);
  3835. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x02);
  3836. SiS_PanelDelayLoop(SiS_Pr, 3, 2);
  3837. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  3838. SiS_GenericDelay(SiS_Pr, 17664);
  3839. }
  3840. }
  3841. } else {
  3842. SiS_PanelDelayLoop(SiS_Pr, 3, 2);
  3843. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  3844. SiS_GenericDelay(SiS_Pr, 17664);
  3845. }
  3846. }
  3847. }
  3848. if(!(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & 0x40)) {
  3849. SiS_PanelDelayLoop(SiS_Pr, 3, 10);
  3850. delaylong = true;
  3851. }
  3852. }
  3853. if(!(SiS_IsVAMode(SiS_Pr))) {
  3854. temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x32) & 0xDF;
  3855. if(SiS_BridgeInSlavemode(SiS_Pr)) {
  3856. tempah = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  3857. if(!(tempah & SetCRT2ToRAMDAC)) {
  3858. if(!(SiS_LCDAEnabled(SiS_Pr))) temp |= 0x20;
  3859. }
  3860. }
  3861. SiS_SetReg(SiS_Pr->SiS_P3c4,0x32,temp);
  3862. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20); /* enable CRT2 */
  3863. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0x7f);
  3864. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2e,0x80);
  3865. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3866. SiS_PanelDelay(SiS_Pr, 2);
  3867. }
  3868. } else {
  3869. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1e,0x20);
  3870. }
  3871. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x00,0x1f,0x20);
  3872. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2e,0x80);
  3873. if(SiS_Pr->SiS_VBType & VB_SISPOWER) {
  3874. if( (SiS_LCDAEnabled(SiS_Pr)) ||
  3875. (SiS_CRT2IsLCD(SiS_Pr)) ) {
  3876. /* Enable "LVDS PLL power on" (even on 301C) */
  3877. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x2a,0x7f);
  3878. /* Enable "LVDS Driver Power on" (even on 301C) */
  3879. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x7f);
  3880. }
  3881. }
  3882. tempah = 0xc0;
  3883. if(SiS_IsDualEdge(SiS_Pr)) {
  3884. tempah = 0x80;
  3885. if(!(SiS_IsVAMode(SiS_Pr))) tempah = 0x40;
  3886. }
  3887. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x1F,tempah);
  3888. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3889. SiS_PanelDelay(SiS_Pr, 2);
  3890. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x1f,0x10);
  3891. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2e,0x80);
  3892. if(SiS_Pr->SiS_CustomT != CUT_CLEVO1400) {
  3893. #ifdef SET_EMI
  3894. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  3895. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
  3896. SiS_GenericDelay(SiS_Pr, 2048);
  3897. }
  3898. #endif
  3899. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x27,0x0c);
  3900. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  3901. #ifdef SET_EMI
  3902. cr36 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36);
  3903. if(SiS_Pr->SiS_ROMNew) {
  3904. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  3905. unsigned short romptr = GetLCDStructPtr661_2(SiS_Pr);
  3906. if(romptr) {
  3907. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x30,0x20); /* Reset */
  3908. SiS_Pr->EMI_30 = 0;
  3909. SiS_Pr->EMI_31 = ROMAddr[romptr + SiS_Pr->SiS_EMIOffset + 0];
  3910. SiS_Pr->EMI_32 = ROMAddr[romptr + SiS_Pr->SiS_EMIOffset + 1];
  3911. SiS_Pr->EMI_33 = ROMAddr[romptr + SiS_Pr->SiS_EMIOffset + 2];
  3912. if(ROMAddr[romptr + 1] & 0x10) SiS_Pr->EMI_30 = 0x40;
  3913. /* emidelay = SISGETROMW((romptr + 0x22)); */
  3914. SiS_Pr->HaveEMI = SiS_Pr->HaveEMILCD = SiS_Pr->OverruleEMI = true;
  3915. }
  3916. }
  3917. /* (P4_30|0x40) */
  3918. /* Compal 1400x1050: 0x05, 0x60, 0x00 YES (1.10.7w; CR36=69) */
  3919. /* Compal 1400x1050: 0x0d, 0x70, 0x40 YES (1.10.7x; CR36=69) */
  3920. /* Acer 1280x1024: 0x12, 0xd0, 0x6b NO (1.10.9k; CR36=73) */
  3921. /* Compaq 1280x1024: 0x0d, 0x70, 0x6b YES (1.12.04b; CR36=03) */
  3922. /* Clevo 1024x768: 0x05, 0x60, 0x33 NO (1.10.8e; CR36=12, DL!) */
  3923. /* Clevo 1024x768: 0x0d, 0x70, 0x40 (if type == 3) YES (1.10.8y; CR36=?2) */
  3924. /* Clevo 1024x768: 0x05, 0x60, 0x33 (if type != 3) YES (1.10.8y; CR36=?2) */
  3925. /* Asus 1024x768: ? ? (1.10.8o; CR36=?2) */
  3926. /* Asus 1024x768: 0x08, 0x10, 0x3c (problematic) YES (1.10.8q; CR36=22) */
  3927. if(SiS_Pr->HaveEMI) {
  3928. r30 = SiS_Pr->EMI_30; r31 = SiS_Pr->EMI_31;
  3929. r32 = SiS_Pr->EMI_32; r33 = SiS_Pr->EMI_33;
  3930. } else {
  3931. r30 = 0;
  3932. }
  3933. /* EMI_30 is read at driver start; however, the BIOS sets this
  3934. * (if it is used) only if the LCD is in use. In case we caught
  3935. * the machine while on TV output, this bit is not set and we
  3936. * don't know if it should be set - hence our detection is wrong.
  3937. * Work-around this here:
  3938. */
  3939. if((!SiS_Pr->HaveEMI) || (!SiS_Pr->HaveEMILCD)) {
  3940. switch((cr36 & 0x0f)) {
  3941. case 2:
  3942. r30 |= 0x40;
  3943. if(SiS_Pr->SiS_CustomT == CUT_CLEVO1024) r30 &= ~0x40;
  3944. if(!SiS_Pr->HaveEMI) {
  3945. r31 = 0x05; r32 = 0x60; r33 = 0x33;
  3946. if((cr36 & 0xf0) == 0x30) {
  3947. r31 = 0x0d; r32 = 0x70; r33 = 0x40;
  3948. }
  3949. }
  3950. break;
  3951. case 3: /* 1280x1024 */
  3952. if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) r30 |= 0x40;
  3953. if(!SiS_Pr->HaveEMI) {
  3954. r31 = 0x12; r32 = 0xd0; r33 = 0x6b;
  3955. if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) {
  3956. r31 = 0x0d; r32 = 0x70; r33 = 0x6b;
  3957. }
  3958. }
  3959. break;
  3960. case 9: /* 1400x1050 */
  3961. r30 |= 0x40;
  3962. if(!SiS_Pr->HaveEMI) {
  3963. r31 = 0x05; r32 = 0x60; r33 = 0x00;
  3964. if(SiS_Pr->SiS_CustomT == CUT_COMPAL1400_2) {
  3965. r31 = 0x0d; r32 = 0x70; r33 = 0x40; /* BIOS values */
  3966. }
  3967. }
  3968. break;
  3969. case 11: /* 1600x1200 - unknown */
  3970. r30 |= 0x40;
  3971. if(!SiS_Pr->HaveEMI) {
  3972. r31 = 0x05; r32 = 0x60; r33 = 0x00;
  3973. }
  3974. }
  3975. }
  3976. /* BIOS values don't work so well sometimes */
  3977. if(!SiS_Pr->OverruleEMI) {
  3978. #ifdef COMPAL_HACK
  3979. if(SiS_Pr->SiS_CustomT == CUT_COMPAL1400_2) {
  3980. if((cr36 & 0x0f) == 0x09) {
  3981. r30 = 0x60; r31 = 0x05; r32 = 0x60; r33 = 0x00;
  3982. }
  3983. }
  3984. #endif
  3985. #ifdef COMPAQ_HACK
  3986. if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) {
  3987. if((cr36 & 0x0f) == 0x03) {
  3988. r30 = 0x20; r31 = 0x12; r32 = 0xd0; r33 = 0x6b;
  3989. }
  3990. }
  3991. #endif
  3992. #ifdef ASUS_HACK
  3993. if(SiS_Pr->SiS_CustomT == CUT_ASUSA2H_2) {
  3994. if((cr36 & 0x0f) == 0x02) {
  3995. /* r30 = 0x60; r31 = 0x05; r32 = 0x60; r33 = 0x33; */ /* rev 2 */
  3996. /* r30 = 0x20; r31 = 0x05; r32 = 0x60; r33 = 0x33; */ /* rev 3 */
  3997. /* r30 = 0x60; r31 = 0x0d; r32 = 0x70; r33 = 0x40; */ /* rev 4 */
  3998. /* r30 = 0x20; r31 = 0x0d; r32 = 0x70; r33 = 0x40; */ /* rev 5 */
  3999. }
  4000. }
  4001. #endif
  4002. }
  4003. if(!(SiS_Pr->OverruleEMI && (!r30) && (!r31) && (!r32) && (!r33))) {
  4004. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x30,0x20); /* Reset */
  4005. SiS_GenericDelay(SiS_Pr, 2048);
  4006. }
  4007. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x31,r31);
  4008. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x32,r32);
  4009. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x33,r33);
  4010. #endif /* SET_EMI */
  4011. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x34,0x10);
  4012. #ifdef SET_EMI
  4013. if( (SiS_LCDAEnabled(SiS_Pr)) ||
  4014. (SiS_CRT2IsLCD(SiS_Pr)) ) {
  4015. if(r30 & 0x40) {
  4016. /*SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x2a,0x80);*/
  4017. SiS_PanelDelayLoop(SiS_Pr, 3, 5);
  4018. if(delaylong) {
  4019. SiS_PanelDelayLoop(SiS_Pr, 3, 5);
  4020. delaylong = false;
  4021. }
  4022. SiS_WaitVBRetrace(SiS_Pr);
  4023. SiS_WaitVBRetrace(SiS_Pr);
  4024. if(SiS_Pr->SiS_CustomT == CUT_ASUSA2H_2) {
  4025. SiS_GenericDelay(SiS_Pr, 1280);
  4026. }
  4027. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x30,0x40); /* Enable */
  4028. /*SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x2a,0x7f);*/
  4029. }
  4030. }
  4031. #endif
  4032. }
  4033. }
  4034. if(!(SiS_WeHaveBacklightCtrl(SiS_Pr))) {
  4035. if(SiS_IsVAorLCD(SiS_Pr)) {
  4036. SiS_PanelDelayLoop(SiS_Pr, 3, 10);
  4037. if(delaylong) {
  4038. SiS_PanelDelayLoop(SiS_Pr, 3, 10);
  4039. }
  4040. SiS_WaitVBRetrace(SiS_Pr);
  4041. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  4042. SiS_GenericDelay(SiS_Pr, 2048);
  4043. SiS_WaitVBRetrace(SiS_Pr);
  4044. }
  4045. if(!didpwd) {
  4046. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x01);
  4047. } else {
  4048. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x03);
  4049. }
  4050. }
  4051. }
  4052. SiS_SetReg(SiS_Pr->SiS_P3c4,0x06,pushax);
  4053. SiS_DisplayOn(SiS_Pr);
  4054. SiS_SetRegByte(SiS_Pr->SiS_P3c6,0xff);
  4055. }
  4056. if(!(SiS_WeHaveBacklightCtrl(SiS_Pr))) {
  4057. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x00,0x7f);
  4058. }
  4059. #endif /* SIS315H */
  4060. }
  4061. } else { /* ============ For 301 ================ */
  4062. if(SiS_Pr->ChipType < SIS_315H) {
  4063. if(SiS_CRT2IsLCD(SiS_Pr)) {
  4064. SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x00);
  4065. SiS_PanelDelay(SiS_Pr, 0);
  4066. }
  4067. }
  4068. temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x32) & 0xDF; /* lock mode */
  4069. if(SiS_BridgeInSlavemode(SiS_Pr)) {
  4070. tempah = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  4071. if(!(tempah & SetCRT2ToRAMDAC)) temp |= 0x20;
  4072. }
  4073. SiS_SetReg(SiS_Pr->SiS_P3c4,0x32,temp);
  4074. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20); /* enable CRT2 */
  4075. if(SiS_Pr->ChipType >= SIS_315H) {
  4076. temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x2E);
  4077. if(!(temp & 0x80)) {
  4078. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2E,0x80); /* BVBDOENABLE=1 */
  4079. }
  4080. }
  4081. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x00,0x1F,0x20); /* enable VB processor */
  4082. SiS_VBLongWait(SiS_Pr);
  4083. SiS_DisplayOn(SiS_Pr);
  4084. if(SiS_Pr->ChipType >= SIS_315H) {
  4085. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x00,0x7f);
  4086. }
  4087. SiS_VBLongWait(SiS_Pr);
  4088. if(SiS_Pr->ChipType < SIS_315H) {
  4089. if(SiS_CRT2IsLCD(SiS_Pr)) {
  4090. SiS_PanelDelay(SiS_Pr, 1);
  4091. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x00);
  4092. }
  4093. }
  4094. }
  4095. } else { /* =================== For LVDS ================== */
  4096. if(SiS_Pr->ChipType < SIS_315H) {
  4097. #ifdef SIS300 /* 300 series */
  4098. if(SiS_CRT2IsLCD(SiS_Pr)) {
  4099. if(SiS_Pr->ChipType == SIS_730) {
  4100. SiS_PanelDelay(SiS_Pr, 1);
  4101. SiS_PanelDelay(SiS_Pr, 1);
  4102. SiS_PanelDelay(SiS_Pr, 1);
  4103. }
  4104. SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x00);
  4105. if(!(SiS_CR36BIOSWord23d(SiS_Pr))) {
  4106. SiS_PanelDelay(SiS_Pr, 0);
  4107. }
  4108. }
  4109. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);
  4110. SiS_DisplayOn(SiS_Pr);
  4111. SiS_UnLockCRT2(SiS_Pr);
  4112. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x02,0xBF);
  4113. if(SiS_BridgeInSlavemode(SiS_Pr)) {
  4114. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x01,0x1F);
  4115. } else {
  4116. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x01,0x1F,0x40);
  4117. }
  4118. if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) {
  4119. if(!(SiS_CRT2IsLCD(SiS_Pr))) {
  4120. SiS_WaitVBRetrace(SiS_Pr);
  4121. SiS_SetCH700x(SiS_Pr,0x0E,0x0B);
  4122. }
  4123. }
  4124. if(SiS_CRT2IsLCD(SiS_Pr)) {
  4125. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x40)) {
  4126. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x16) & 0x10)) {
  4127. if(!(SiS_CR36BIOSWord23b(SiS_Pr))) {
  4128. SiS_PanelDelay(SiS_Pr, 1);
  4129. SiS_PanelDelay(SiS_Pr, 1);
  4130. }
  4131. SiS_WaitVBRetrace(SiS_Pr);
  4132. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x00);
  4133. }
  4134. }
  4135. }
  4136. #endif /* SIS300 */
  4137. } else {
  4138. #ifdef SIS315H /* 315 series */
  4139. if(!(SiS_IsNotM650orLater(SiS_Pr))) {
  4140. /*if(SiS_Pr->ChipType < SIS_340) {*/ /* XGI needs this */
  4141. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x4c,0x18);
  4142. /*}*/
  4143. }
  4144. if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
  4145. if(SiS_CRT2IsLCD(SiS_Pr)) {
  4146. SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x00);
  4147. SiS_PanelDelay(SiS_Pr, 0);
  4148. }
  4149. }
  4150. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);
  4151. SiS_UnLockCRT2(SiS_Pr);
  4152. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0xf7);
  4153. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  4154. temp = SiS_GetCH701x(SiS_Pr,0x66);
  4155. temp &= 0x20;
  4156. SiS_Chrontel701xBLOff(SiS_Pr);
  4157. }
  4158. if(SiS_Pr->ChipType != SIS_550) {
  4159. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0x7f);
  4160. }
  4161. if(SiS_Pr->ChipType == SIS_740) {
  4162. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  4163. if(SiS_IsLCDOrLCDA(SiS_Pr)) {
  4164. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x20);
  4165. }
  4166. }
  4167. }
  4168. temp1 = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x2E);
  4169. if(!(temp1 & 0x80)) {
  4170. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2E,0x80);
  4171. }
  4172. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  4173. if(temp) {
  4174. SiS_Chrontel701xBLOn(SiS_Pr);
  4175. }
  4176. }
  4177. if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
  4178. if(SiS_CRT2IsLCD(SiS_Pr)) {
  4179. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x20);
  4180. if(SiS_Pr->ChipType == SIS_550) {
  4181. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x40);
  4182. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x10);
  4183. }
  4184. }
  4185. } else if(SiS_IsVAMode(SiS_Pr)) {
  4186. if(SiS_Pr->ChipType != SIS_740) {
  4187. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x20);
  4188. }
  4189. }
  4190. if(!(SiS_WeHaveBacklightCtrl(SiS_Pr))) {
  4191. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x00,0x7f);
  4192. }
  4193. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  4194. if(SiS_IsTVOrYPbPrOrScart(SiS_Pr)) {
  4195. SiS_Chrontel701xOn(SiS_Pr);
  4196. }
  4197. if( (SiS_IsVAMode(SiS_Pr)) ||
  4198. (SiS_IsLCDOrLCDA(SiS_Pr)) ) {
  4199. SiS_ChrontelDoSomething1(SiS_Pr);
  4200. }
  4201. }
  4202. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  4203. if(!(SiS_WeHaveBacklightCtrl(SiS_Pr))) {
  4204. if( (SiS_IsVAMode(SiS_Pr)) ||
  4205. (SiS_IsLCDOrLCDA(SiS_Pr)) ) {
  4206. SiS_Chrontel701xBLOn(SiS_Pr);
  4207. SiS_ChrontelInitTVVSync(SiS_Pr);
  4208. }
  4209. }
  4210. } else if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
  4211. if(!(SiS_WeHaveBacklightCtrl(SiS_Pr))) {
  4212. if(SiS_CRT2IsLCD(SiS_Pr)) {
  4213. SiS_PanelDelay(SiS_Pr, 1);
  4214. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x00);
  4215. }
  4216. }
  4217. }
  4218. #endif /* SIS315H */
  4219. } /* 310 series */
  4220. } /* LVDS */
  4221. }
  4222. /*********************************************/
  4223. /* SET PART 1 REGISTER GROUP */
  4224. /*********************************************/
  4225. /* Set CRT2 OFFSET / PITCH */
  4226. static void
  4227. SiS_SetCRT2Offset(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  4228. unsigned short RRTI)
  4229. {
  4230. unsigned short offset;
  4231. unsigned char temp;
  4232. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) return;
  4233. offset = SiS_GetOffset(SiS_Pr,ModeNo,ModeIdIndex,RRTI);
  4234. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x07,(offset & 0xFF));
  4235. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x09,(offset >> 8));
  4236. temp = (unsigned char)(((offset >> 3) & 0xFF) + 1);
  4237. if(offset & 0x07) temp++;
  4238. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x03,temp);
  4239. }
  4240. /* Set CRT2 sync and PanelLink mode */
  4241. static void
  4242. SiS_SetCRT2Sync(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short RefreshRateTableIndex)
  4243. {
  4244. unsigned short tempah=0, tempbl, infoflag;
  4245. tempbl = 0xC0;
  4246. if(SiS_Pr->UseCustomMode) {
  4247. infoflag = SiS_Pr->CInfoFlag;
  4248. } else {
  4249. infoflag = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
  4250. }
  4251. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { /* LVDS */
  4252. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  4253. tempah = 0;
  4254. } else if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && (SiS_Pr->SiS_LCDInfo & LCDSync)) {
  4255. tempah = SiS_Pr->SiS_LCDInfo;
  4256. } else tempah = infoflag >> 8;
  4257. tempah &= 0xC0;
  4258. tempah |= 0x20;
  4259. if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10;
  4260. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  4261. if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) ||
  4262. (SiS_Pr->SiS_CustomT == CUT_BARCO1024)) {
  4263. tempah |= 0xf0;
  4264. }
  4265. if( (SiS_Pr->SiS_IF_DEF_FSTN) ||
  4266. (SiS_Pr->SiS_IF_DEF_DSTN) ||
  4267. (SiS_Pr->SiS_IF_DEF_TRUMPION) ||
  4268. (SiS_Pr->SiS_CustomT == CUT_PANEL848) ||
  4269. (SiS_Pr->SiS_CustomT == CUT_PANEL856) ) {
  4270. tempah |= 0x30;
  4271. }
  4272. if( (SiS_Pr->SiS_IF_DEF_FSTN) ||
  4273. (SiS_Pr->SiS_IF_DEF_DSTN) ) {
  4274. tempah &= ~0xc0;
  4275. }
  4276. }
  4277. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  4278. if(SiS_Pr->ChipType >= SIS_315H) {
  4279. tempah >>= 3;
  4280. tempah &= 0x18;
  4281. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,0xE7,tempah);
  4282. /* Don't care about 12/18/24 bit mode - TV is via VGA, not PL */
  4283. } else {
  4284. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,0xe0);
  4285. }
  4286. } else {
  4287. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah);
  4288. }
  4289. } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
  4290. if(SiS_Pr->ChipType < SIS_315H) {
  4291. #ifdef SIS300 /* ---- 300 series --- */
  4292. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) { /* 630 - 301B(-DH) */
  4293. tempah = infoflag >> 8;
  4294. tempbl = 0;
  4295. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  4296. if(SiS_Pr->SiS_LCDInfo & LCDSync) {
  4297. tempah = SiS_Pr->SiS_LCDInfo;
  4298. tempbl = (tempah >> 6) & 0x03;
  4299. }
  4300. }
  4301. tempah &= 0xC0;
  4302. tempah |= 0x20;
  4303. if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10;
  4304. tempah |= 0xc0;
  4305. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah);
  4306. if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && (!(SiS_Pr->SiS_VBType & VB_NoLCD))) {
  4307. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1a,0xf0,tempbl);
  4308. }
  4309. } else { /* 630 - 301 */
  4310. tempah = ((infoflag >> 8) & 0xc0) | 0x20;
  4311. if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10;
  4312. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah);
  4313. }
  4314. #endif /* SIS300 */
  4315. } else {
  4316. #ifdef SIS315H /* ------- 315 series ------ */
  4317. if(SiS_Pr->SiS_VBType & VB_SISLVDS) { /* 315 - LVDS */
  4318. tempbl = 0;
  4319. if((SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) &&
  4320. (SiS_Pr->SiS_LCDResInfo == Panel_1280x1024)) {
  4321. tempah = infoflag >> 8;
  4322. if(SiS_Pr->SiS_LCDInfo & LCDSync) {
  4323. tempbl = ((SiS_Pr->SiS_LCDInfo & 0xc0) >> 6);
  4324. }
  4325. } else if((SiS_Pr->SiS_CustomT == CUT_CLEVO1400) &&
  4326. (SiS_Pr->SiS_LCDResInfo == Panel_1400x1050)) {
  4327. tempah = infoflag >> 8;
  4328. tempbl = 0x03;
  4329. } else {
  4330. tempah = SiS_GetReg(SiS_Pr->SiS_P3d4,0x37);
  4331. tempbl = (tempah >> 6) & 0x03;
  4332. tempbl |= 0x08;
  4333. if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempbl |= 0x04;
  4334. }
  4335. tempah &= 0xC0;
  4336. tempah |= 0x20;
  4337. if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10;
  4338. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) tempah |= 0xc0;
  4339. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah);
  4340. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  4341. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  4342. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1a,0xf0,tempbl);
  4343. }
  4344. }
  4345. } else { /* 315 - TMDS */
  4346. tempah = tempbl = infoflag >> 8;
  4347. if(!SiS_Pr->UseCustomMode) {
  4348. tempbl = 0;
  4349. if((SiS_Pr->SiS_VBType & VB_SIS30xC) && (SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) {
  4350. if(ModeNo <= 0x13) {
  4351. tempah = SiS_GetRegByte((SiS_Pr->SiS_P3ca+0x02));
  4352. }
  4353. }
  4354. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4355. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  4356. if(SiS_Pr->SiS_LCDInfo & LCDSync) {
  4357. tempah = SiS_Pr->SiS_LCDInfo;
  4358. tempbl = (tempah >> 6) & 0x03;
  4359. }
  4360. }
  4361. }
  4362. }
  4363. tempah &= 0xC0;
  4364. tempah |= 0x20;
  4365. if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10;
  4366. if(SiS_Pr->SiS_VBType & VB_NoLCD) {
  4367. /* Imitate BIOS bug */
  4368. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) tempah |= 0xc0;
  4369. }
  4370. if((SiS_Pr->SiS_VBType & VB_SIS30xC) && (SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) {
  4371. tempah >>= 3;
  4372. tempah &= 0x18;
  4373. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,0xe7,tempah);
  4374. } else {
  4375. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah);
  4376. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  4377. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  4378. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1a,0xf0,tempbl);
  4379. }
  4380. }
  4381. }
  4382. }
  4383. #endif /* SIS315H */
  4384. }
  4385. }
  4386. }
  4387. /* Set CRT2 FIFO on 300/540/630/730 */
  4388. #ifdef SIS300
  4389. static void
  4390. SiS_SetCRT2FIFO_300(struct SiS_Private *SiS_Pr,unsigned short ModeNo)
  4391. {
  4392. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  4393. unsigned short temp, index, modeidindex, refreshratetableindex;
  4394. unsigned short VCLK = 0, MCLK, colorth = 0, data2 = 0;
  4395. unsigned short tempbx, tempcl, CRT1ModeNo, CRT2ModeNo, SelectRate_backup;
  4396. unsigned int data, pci50, pciA0;
  4397. static const unsigned char colortharray[] = {
  4398. 1, 1, 2, 2, 3, 4
  4399. };
  4400. SelectRate_backup = SiS_Pr->SiS_SelectCRT2Rate;
  4401. if(!SiS_Pr->CRT1UsesCustomMode) {
  4402. CRT1ModeNo = SiS_Pr->SiS_CRT1Mode; /* get CRT1 ModeNo */
  4403. SiS_SearchModeID(SiS_Pr, &CRT1ModeNo, &modeidindex);
  4404. SiS_Pr->SiS_SetFlag &= (~ProgrammingCRT2);
  4405. SiS_Pr->SiS_SelectCRT2Rate = 0;
  4406. refreshratetableindex = SiS_GetRatePtr(SiS_Pr, CRT1ModeNo, modeidindex);
  4407. if(CRT1ModeNo >= 0x13) {
  4408. /* Get VCLK */
  4409. index = SiS_GetRefCRTVCLK(SiS_Pr, refreshratetableindex, SiS_Pr->SiS_UseWide);
  4410. VCLK = SiS_Pr->SiS_VCLKData[index].CLOCK;
  4411. /* Get colordepth */
  4412. colorth = SiS_GetColorDepth(SiS_Pr,CRT1ModeNo,modeidindex) >> 1;
  4413. if(!colorth) colorth++;
  4414. }
  4415. } else {
  4416. CRT1ModeNo = 0xfe;
  4417. /* Get VCLK */
  4418. VCLK = SiS_Pr->CSRClock_CRT1;
  4419. /* Get color depth */
  4420. colorth = colortharray[((SiS_Pr->CModeFlag_CRT1 & ModeTypeMask) - 2)];
  4421. }
  4422. if(CRT1ModeNo >= 0x13) {
  4423. /* Get MCLK */
  4424. if(SiS_Pr->ChipType == SIS_300) {
  4425. index = SiS_GetReg(SiS_Pr->SiS_P3c4,0x3A);
  4426. } else {
  4427. index = SiS_GetReg(SiS_Pr->SiS_P3c4,0x1A);
  4428. }
  4429. index &= 0x07;
  4430. MCLK = SiS_Pr->SiS_MCLKData_0[index].CLOCK;
  4431. temp = ((SiS_GetReg(SiS_Pr->SiS_P3c4,0x14) >> 6) & 0x03) << 1;
  4432. if(!temp) temp++;
  4433. temp <<= 2;
  4434. data2 = temp - ((colorth * VCLK) / MCLK);
  4435. temp = (28 * 16) % data2;
  4436. data2 = (28 * 16) / data2;
  4437. if(temp) data2++;
  4438. if(SiS_Pr->ChipType == SIS_300) {
  4439. SiS_GetFIFOThresholdIndex300(SiS_Pr, &tempbx, &tempcl);
  4440. data = SiS_GetFIFOThresholdB300(tempbx, tempcl);
  4441. } else {
  4442. #ifdef SIS_LINUX_KERNEL
  4443. pci50 = sisfb_read_nbridge_pci_dword(SiS_Pr, 0x50);
  4444. pciA0 = sisfb_read_nbridge_pci_dword(SiS_Pr, 0xa0);
  4445. #else
  4446. pci50 = pciReadLong(0x00000000, 0x50);
  4447. pciA0 = pciReadLong(0x00000000, 0xA0);
  4448. #endif
  4449. if(SiS_Pr->ChipType == SIS_730) {
  4450. index = (unsigned short)(((pciA0 >> 28) & 0x0f) * 3);
  4451. index += (unsigned short)(((pci50 >> 9)) & 0x03);
  4452. /* BIOS BUG (2.04.5d, 2.04.6a use ah here, which is unset!) */
  4453. index = 0; /* -- do it like the BIOS anyway... */
  4454. } else {
  4455. pci50 >>= 24;
  4456. pciA0 >>= 24;
  4457. index = (pci50 >> 1) & 0x07;
  4458. if(pci50 & 0x01) index += 6;
  4459. if(!(pciA0 & 0x01)) index += 24;
  4460. if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x14) & 0x80) index += 12;
  4461. }
  4462. data = SiS_GetLatencyFactor630(SiS_Pr, index) + 15;
  4463. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x14) & 0x80)) data += 5;
  4464. }
  4465. data += data2; /* CRT1 Request Period */
  4466. SiS_Pr->SiS_SetFlag |= ProgrammingCRT2;
  4467. SiS_Pr->SiS_SelectCRT2Rate = SelectRate_backup;
  4468. if(!SiS_Pr->UseCustomMode) {
  4469. CRT2ModeNo = ModeNo;
  4470. SiS_SearchModeID(SiS_Pr, &CRT2ModeNo, &modeidindex);
  4471. refreshratetableindex = SiS_GetRatePtr(SiS_Pr, CRT2ModeNo, modeidindex);
  4472. /* Get VCLK */
  4473. index = SiS_GetVCLK2Ptr(SiS_Pr, CRT2ModeNo, modeidindex, refreshratetableindex);
  4474. VCLK = SiS_Pr->SiS_VCLKData[index].CLOCK;
  4475. if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) || (SiS_Pr->SiS_CustomT == CUT_BARCO1024)) {
  4476. if(SiS_Pr->SiS_UseROM) {
  4477. if(ROMAddr[0x220] & 0x01) {
  4478. VCLK = ROMAddr[0x229] | (ROMAddr[0x22a] << 8);
  4479. }
  4480. }
  4481. }
  4482. } else {
  4483. /* Get VCLK */
  4484. CRT2ModeNo = 0xfe;
  4485. VCLK = SiS_Pr->CSRClock;
  4486. }
  4487. /* Get colordepth */
  4488. colorth = SiS_GetColorDepth(SiS_Pr,CRT2ModeNo,modeidindex) >> 1;
  4489. if(!colorth) colorth++;
  4490. data = data * VCLK * colorth;
  4491. temp = data % (MCLK << 4);
  4492. data = data / (MCLK << 4);
  4493. if(temp) data++;
  4494. if(data < 6) data = 6;
  4495. else if(data > 0x14) data = 0x14;
  4496. if(SiS_Pr->ChipType == SIS_300) {
  4497. temp = 0x16;
  4498. if((data <= 0x0f) || (SiS_Pr->SiS_LCDResInfo == Panel_1280x1024))
  4499. temp = 0x13;
  4500. } else {
  4501. temp = 0x16;
  4502. if(( (SiS_Pr->ChipType == SIS_630) ||
  4503. (SiS_Pr->ChipType == SIS_730) ) &&
  4504. (SiS_Pr->ChipRevision >= 0x30))
  4505. temp = 0x1b;
  4506. }
  4507. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x01,0xe0,temp);
  4508. if((SiS_Pr->ChipType == SIS_630) &&
  4509. (SiS_Pr->ChipRevision >= 0x30)) {
  4510. if(data > 0x13) data = 0x13;
  4511. }
  4512. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x02,0xe0,data);
  4513. } else { /* If mode <= 0x13, we just restore everything */
  4514. SiS_Pr->SiS_SetFlag |= ProgrammingCRT2;
  4515. SiS_Pr->SiS_SelectCRT2Rate = SelectRate_backup;
  4516. }
  4517. }
  4518. #endif
  4519. /* Set CRT2 FIFO on 315/330 series */
  4520. #ifdef SIS315H
  4521. static void
  4522. SiS_SetCRT2FIFO_310(struct SiS_Private *SiS_Pr)
  4523. {
  4524. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x01,0x3B);
  4525. if( (SiS_Pr->ChipType == SIS_760) &&
  4526. (SiS_Pr->SiS_SysFlags & SF_760LFB) &&
  4527. (SiS_Pr->SiS_ModeType == Mode32Bpp) &&
  4528. (SiS_Pr->SiS_VGAHDE >= 1280) &&
  4529. (SiS_Pr->SiS_VGAVDE >= 1024) ) {
  4530. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2f,0x03);
  4531. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x01,0x3b);
  4532. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x4d,0xc0);
  4533. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2f,0x01);
  4534. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x4d,0xc0);
  4535. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x02,0x6e);
  4536. } else {
  4537. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x02,~0x3f,0x04);
  4538. }
  4539. }
  4540. #endif
  4541. static unsigned short
  4542. SiS_GetVGAHT2(struct SiS_Private *SiS_Pr)
  4543. {
  4544. unsigned int tempax,tempbx;
  4545. tempbx = (SiS_Pr->SiS_VGAVT - SiS_Pr->SiS_VGAVDE) * SiS_Pr->SiS_RVBHCMAX;
  4546. tempax = (SiS_Pr->SiS_VT - SiS_Pr->SiS_VDE) * SiS_Pr->SiS_RVBHCFACT;
  4547. tempax = (tempax * SiS_Pr->SiS_HT) / tempbx;
  4548. return (unsigned short)tempax;
  4549. }
  4550. /* Set Part 1 / SiS bridge slave mode */
  4551. static void
  4552. SiS_SetGroup1_301(struct SiS_Private *SiS_Pr, unsigned short ModeNo,unsigned short ModeIdIndex,
  4553. unsigned short RefreshRateTableIndex)
  4554. {
  4555. unsigned short temp, modeflag, i, j, xres=0, VGAVDE;
  4556. static const unsigned short CRTranslation[] = {
  4557. /* CR0 CR1 CR2 CR3 CR4 CR5 CR6 CR7 */
  4558. 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a,
  4559. /* CR8 CR9 SR0A SR0B SR0C SR0D SR0E CR0F */
  4560. 0x00, 0x0b, 0x17, 0x18, 0x19, 0x00, 0x1a, 0x00,
  4561. /* CR10 CR11 CR12 CR13 CR14 CR15 CR16 CR17 */
  4562. 0x0c, 0x0d, 0x0e, 0x00, 0x0f, 0x10, 0x11, 0x00
  4563. };
  4564. if(ModeNo <= 0x13) {
  4565. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  4566. } else if(SiS_Pr->UseCustomMode) {
  4567. modeflag = SiS_Pr->CModeFlag;
  4568. xres = SiS_Pr->CHDisplay;
  4569. } else {
  4570. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  4571. xres = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].XRes;
  4572. }
  4573. /* The following is only done if bridge is in slave mode: */
  4574. if(SiS_Pr->ChipType >= SIS_315H) {
  4575. if(xres >= 1600) { /* BIOS: == 1600 */
  4576. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x31,0x04);
  4577. }
  4578. }
  4579. SiS_Pr->CHTotal = 8224; /* Max HT, 0x2020, results in 0x3ff in registers */
  4580. SiS_Pr->CHDisplay = SiS_Pr->SiS_VGAHDE;
  4581. if(modeflag & HalfDCLK) SiS_Pr->CHDisplay >>= 1;
  4582. SiS_Pr->CHBlankStart = SiS_Pr->CHDisplay;
  4583. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  4584. SiS_Pr->CHBlankStart += 16;
  4585. }
  4586. SiS_Pr->CHBlankEnd = 32;
  4587. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  4588. if(xres == 1600) SiS_Pr->CHBlankEnd += 80;
  4589. }
  4590. temp = SiS_Pr->SiS_VGAHT - 96;
  4591. if(!(modeflag & HalfDCLK)) temp -= 32;
  4592. if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
  4593. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x04);
  4594. temp |= ((SiS_GetReg(SiS_Pr->SiS_P3c4,0x0b) & 0xc0) << 2);
  4595. temp -= 3;
  4596. temp <<= 3;
  4597. } else {
  4598. if(SiS_Pr->SiS_RVBHRS2) temp = SiS_Pr->SiS_RVBHRS2;
  4599. }
  4600. SiS_Pr->CHSyncStart = temp;
  4601. SiS_Pr->CHSyncEnd = 0xffe8; /* results in 0x2000 in registers */
  4602. SiS_Pr->CVTotal = 2049; /* Max VT, 0x0801, results in 0x7ff in registers */
  4603. VGAVDE = SiS_Pr->SiS_VGAVDE;
  4604. if (VGAVDE == 357) VGAVDE = 350;
  4605. else if(VGAVDE == 360) VGAVDE = 350;
  4606. else if(VGAVDE == 375) VGAVDE = 350;
  4607. else if(VGAVDE == 405) VGAVDE = 400;
  4608. else if(VGAVDE == 420) VGAVDE = 400;
  4609. else if(VGAVDE == 525) VGAVDE = 480;
  4610. else if(VGAVDE == 1056) VGAVDE = 1024;
  4611. SiS_Pr->CVDisplay = VGAVDE;
  4612. SiS_Pr->CVBlankStart = SiS_Pr->CVDisplay;
  4613. SiS_Pr->CVBlankEnd = 1;
  4614. if(ModeNo == 0x3c) SiS_Pr->CVBlankEnd = 226;
  4615. temp = (SiS_Pr->SiS_VGAVT - VGAVDE) >> 1;
  4616. SiS_Pr->CVSyncStart = VGAVDE + temp;
  4617. temp >>= 3;
  4618. SiS_Pr->CVSyncEnd = SiS_Pr->CVSyncStart + temp;
  4619. SiS_CalcCRRegisters(SiS_Pr, 0);
  4620. SiS_Pr->CCRT1CRTC[16] &= ~0xE0;
  4621. for(i = 0; i <= 7; i++) {
  4622. SiS_SetReg(SiS_Pr->SiS_Part1Port,CRTranslation[i],SiS_Pr->CCRT1CRTC[i]);
  4623. }
  4624. for(i = 0x10, j = 8; i <= 0x12; i++, j++) {
  4625. SiS_SetReg(SiS_Pr->SiS_Part1Port,CRTranslation[i],SiS_Pr->CCRT1CRTC[j]);
  4626. }
  4627. for(i = 0x15, j = 11; i <= 0x16; i++, j++) {
  4628. SiS_SetReg(SiS_Pr->SiS_Part1Port,CRTranslation[i],SiS_Pr->CCRT1CRTC[j]);
  4629. }
  4630. for(i = 0x0a, j = 13; i <= 0x0c; i++, j++) {
  4631. SiS_SetReg(SiS_Pr->SiS_Part1Port,CRTranslation[i],SiS_Pr->CCRT1CRTC[j]);
  4632. }
  4633. temp = SiS_Pr->CCRT1CRTC[16] & 0xE0;
  4634. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,CRTranslation[0x0E],0x1F,temp);
  4635. temp = (SiS_Pr->CCRT1CRTC[16] & 0x01) << 5;
  4636. if(modeflag & DoubleScanMode) temp |= 0x80;
  4637. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,CRTranslation[0x09],0x5F,temp);
  4638. temp = 0;
  4639. temp |= (SiS_GetReg(SiS_Pr->SiS_P3c4,0x01) & 0x01);
  4640. if(modeflag & HalfDCLK) temp |= 0x08;
  4641. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x16,temp); /* SR01: HalfDCLK[3], 8/9 div dotclock[0] */
  4642. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0F,0x00); /* CR14: (text mode: underline location) */
  4643. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x12,0x00); /* CR17: n/a */
  4644. temp = 0;
  4645. if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) {
  4646. temp = (SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x01) << 7;
  4647. }
  4648. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1A,temp); /* SR0E, dither[7] */
  4649. temp = SiS_GetRegByte((SiS_Pr->SiS_P3ca+0x02));
  4650. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,temp); /* ? */
  4651. #ifdef SIS_XORG_XF86
  4652. #ifdef TWDEBUG
  4653. xf86DrvMsg(0, X_INFO, "%d %d %d %d %d %d %d %d (%d %d %d %d)\n",
  4654. SiS_Pr->CHDisplay, SiS_Pr->CHSyncStart, SiS_Pr->CHSyncEnd, SiS_Pr->CHTotal,
  4655. SiS_Pr->CVDisplay, SiS_Pr->CVSyncStart, SiS_Pr->CVSyncEnd, SiS_Pr->CVTotal,
  4656. SiS_Pr->CHBlankStart, SiS_Pr->CHBlankEnd, SiS_Pr->CVBlankStart, SiS_Pr->CVBlankEnd);
  4657. xf86DrvMsg(0, X_INFO, " {{0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,\n",
  4658. SiS_Pr->CCRT1CRTC[0], SiS_Pr->CCRT1CRTC[1],
  4659. SiS_Pr->CCRT1CRTC[2], SiS_Pr->CCRT1CRTC[3],
  4660. SiS_Pr->CCRT1CRTC[4], SiS_Pr->CCRT1CRTC[5],
  4661. SiS_Pr->CCRT1CRTC[6], SiS_Pr->CCRT1CRTC[7]);
  4662. xf86DrvMsg(0, X_INFO, " 0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,\n",
  4663. SiS_Pr->CCRT1CRTC[8], SiS_Pr->CCRT1CRTC[9],
  4664. SiS_Pr->CCRT1CRTC[10], SiS_Pr->CCRT1CRTC[11],
  4665. SiS_Pr->CCRT1CRTC[12], SiS_Pr->CCRT1CRTC[13],
  4666. SiS_Pr->CCRT1CRTC[14], SiS_Pr->CCRT1CRTC[15]);
  4667. xf86DrvMsg(0, X_INFO, " 0x%02x}},\n", SiS_Pr->CCRT1CRTC[16]);
  4668. #endif
  4669. #endif
  4670. }
  4671. /* Setup panel link
  4672. * This is used for LVDS, LCDA and Chrontel TV output
  4673. * 300/LVDS+TV, 300/301B-DH, 315/LVDS+TV, 315/LCDA
  4674. */
  4675. static void
  4676. SiS_SetGroup1_LVDS(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  4677. unsigned short RefreshRateTableIndex)
  4678. {
  4679. unsigned short modeflag, resinfo = 0;
  4680. unsigned short push2, tempax, tempbx, tempcx, temp;
  4681. unsigned int tempeax = 0, tempebx, tempecx, tempvcfact = 0;
  4682. bool islvds = false, issis = false, chkdclkfirst = false;
  4683. #ifdef SIS300
  4684. unsigned short crt2crtc = 0;
  4685. #endif
  4686. #ifdef SIS315H
  4687. unsigned short pushcx;
  4688. #endif
  4689. if(ModeNo <= 0x13) {
  4690. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  4691. resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
  4692. #ifdef SIS300
  4693. crt2crtc = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  4694. #endif
  4695. } else if(SiS_Pr->UseCustomMode) {
  4696. modeflag = SiS_Pr->CModeFlag;
  4697. } else {
  4698. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  4699. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  4700. #ifdef SIS300
  4701. crt2crtc = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  4702. #endif
  4703. }
  4704. /* is lvds if really LVDS, or 301B-DH with external LVDS transmitter */
  4705. if((SiS_Pr->SiS_IF_DEF_LVDS == 1) || (SiS_Pr->SiS_VBType & VB_NoLCD)) {
  4706. islvds = true;
  4707. }
  4708. /* is really sis if sis bridge, but not 301B-DH */
  4709. if((SiS_Pr->SiS_VBType & VB_SISVB) && (!(SiS_Pr->SiS_VBType & VB_NoLCD))) {
  4710. issis = true;
  4711. }
  4712. if((SiS_Pr->ChipType >= SIS_315H) && (islvds) && (!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA))) {
  4713. if((!SiS_Pr->SiS_IF_DEF_FSTN) && (!SiS_Pr->SiS_IF_DEF_DSTN)) {
  4714. chkdclkfirst = true;
  4715. }
  4716. }
  4717. #ifdef SIS315H
  4718. if((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  4719. if(IS_SIS330) {
  4720. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x10);
  4721. } else if(IS_SIS740) {
  4722. if(islvds) {
  4723. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,0xfb,0x04);
  4724. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x03);
  4725. } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
  4726. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x10);
  4727. }
  4728. } else {
  4729. if(islvds) {
  4730. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,0xfb,0x04);
  4731. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x00);
  4732. } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
  4733. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2D,0x0f);
  4734. if(SiS_Pr->SiS_VBType & VB_SIS30xC) {
  4735. if((SiS_Pr->SiS_LCDResInfo == Panel_1024x768) ||
  4736. (SiS_Pr->SiS_LCDResInfo == Panel_1280x1024)) {
  4737. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x20);
  4738. }
  4739. }
  4740. }
  4741. }
  4742. }
  4743. #endif
  4744. /* Horizontal */
  4745. tempax = SiS_Pr->SiS_LCDHDES;
  4746. if(islvds) {
  4747. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4748. if(!SiS_Pr->SiS_IF_DEF_FSTN && !SiS_Pr->SiS_IF_DEF_DSTN) {
  4749. if((SiS_Pr->SiS_LCDResInfo == Panel_640x480) &&
  4750. (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode))) {
  4751. tempax -= 8;
  4752. }
  4753. }
  4754. }
  4755. }
  4756. temp = (tempax & 0x0007);
  4757. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1A,temp); /* BPLHDESKEW[2:0] */
  4758. temp = (tempax >> 3) & 0x00FF;
  4759. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x16,temp); /* BPLHDESKEW[10:3] */
  4760. tempbx = SiS_Pr->SiS_HDE;
  4761. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4762. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  4763. tempbx = SiS_Pr->PanelXRes;
  4764. }
  4765. if((SiS_Pr->SiS_LCDResInfo == Panel_320x240_1) ||
  4766. (SiS_Pr->SiS_LCDResInfo == Panel_320x240_2) ||
  4767. (SiS_Pr->SiS_LCDResInfo == Panel_320x240_3)) {
  4768. tempbx >>= 1;
  4769. }
  4770. }
  4771. tempax += tempbx;
  4772. if(tempax >= SiS_Pr->SiS_HT) tempax -= SiS_Pr->SiS_HT;
  4773. temp = tempax;
  4774. if(temp & 0x07) temp += 8;
  4775. temp >>= 3;
  4776. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x17,temp); /* BPLHDEE */
  4777. tempcx = (SiS_Pr->SiS_HT - tempbx) >> 2;
  4778. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4779. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  4780. if(SiS_Pr->PanelHRS != 999) tempcx = SiS_Pr->PanelHRS;
  4781. }
  4782. }
  4783. tempcx += tempax;
  4784. if(tempcx >= SiS_Pr->SiS_HT) tempcx -= SiS_Pr->SiS_HT;
  4785. temp = (tempcx >> 3) & 0x00FF;
  4786. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4787. if(SiS_Pr->SiS_IF_DEF_TRUMPION) {
  4788. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  4789. switch(ModeNo) {
  4790. case 0x04:
  4791. case 0x05:
  4792. case 0x0d: temp = 0x56; break;
  4793. case 0x10: temp = 0x60; break;
  4794. case 0x13: temp = 0x5f; break;
  4795. case 0x40:
  4796. case 0x41:
  4797. case 0x4f:
  4798. case 0x43:
  4799. case 0x44:
  4800. case 0x62:
  4801. case 0x56:
  4802. case 0x53:
  4803. case 0x5d:
  4804. case 0x5e: temp = 0x54; break;
  4805. }
  4806. }
  4807. }
  4808. }
  4809. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x14,temp); /* BPLHRS */
  4810. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4811. temp += 2;
  4812. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  4813. temp += 8;
  4814. if(SiS_Pr->PanelHRE != 999) {
  4815. temp = tempcx + SiS_Pr->PanelHRE;
  4816. if(temp >= SiS_Pr->SiS_HT) temp -= SiS_Pr->SiS_HT;
  4817. temp >>= 3;
  4818. }
  4819. }
  4820. } else {
  4821. temp += 10;
  4822. }
  4823. temp &= 0x1F;
  4824. temp |= ((tempcx & 0x07) << 5);
  4825. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x15,temp); /* BPLHRE */
  4826. /* Vertical */
  4827. tempax = SiS_Pr->SiS_VGAVDE;
  4828. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4829. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  4830. tempax = SiS_Pr->PanelYRes;
  4831. }
  4832. }
  4833. tempbx = SiS_Pr->SiS_LCDVDES + tempax;
  4834. if(tempbx >= SiS_Pr->SiS_VT) tempbx -= SiS_Pr->SiS_VT;
  4835. push2 = tempbx;
  4836. tempcx = SiS_Pr->SiS_VGAVT - SiS_Pr->SiS_VGAVDE;
  4837. if(SiS_Pr->ChipType < SIS_315H) {
  4838. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4839. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  4840. tempcx = SiS_Pr->SiS_VGAVT - SiS_Pr->PanelYRes;
  4841. }
  4842. }
  4843. }
  4844. if(islvds) tempcx >>= 1;
  4845. else tempcx >>= 2;
  4846. if( (SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) &&
  4847. (!(SiS_Pr->SiS_LCDInfo & LCDPass11)) &&
  4848. (SiS_Pr->PanelVRS != 999) ) {
  4849. tempcx = SiS_Pr->PanelVRS;
  4850. tempbx += tempcx;
  4851. if(issis) tempbx++;
  4852. } else {
  4853. tempbx += tempcx;
  4854. if(SiS_Pr->ChipType < SIS_315H) tempbx++;
  4855. else if(issis) tempbx++;
  4856. }
  4857. if(tempbx >= SiS_Pr->SiS_VT) tempbx -= SiS_Pr->SiS_VT;
  4858. temp = tempbx & 0x00FF;
  4859. if(SiS_Pr->SiS_IF_DEF_TRUMPION) {
  4860. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  4861. if(ModeNo == 0x10) temp = 0xa9;
  4862. }
  4863. }
  4864. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,temp); /* BPLVRS */
  4865. tempcx >>= 3;
  4866. tempcx++;
  4867. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4868. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  4869. if(SiS_Pr->PanelVRE != 999) tempcx = SiS_Pr->PanelVRE;
  4870. }
  4871. }
  4872. tempcx += tempbx;
  4873. temp = tempcx & 0x000F;
  4874. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0xF0,temp); /* BPLVRE */
  4875. temp = ((tempbx >> 8) & 0x07) << 3;
  4876. if(SiS_Pr->SiS_IF_DEF_FSTN || SiS_Pr->SiS_IF_DEF_DSTN) {
  4877. if(SiS_Pr->SiS_HDE != 640) {
  4878. if(SiS_Pr->SiS_VGAVDE != SiS_Pr->SiS_VDE) temp |= 0x40;
  4879. }
  4880. } else if(SiS_Pr->SiS_VGAVDE != SiS_Pr->SiS_VDE) temp |= 0x40;
  4881. if(SiS_Pr->SiS_SetFlag & EnableLVDSDDA) temp |= 0x40;
  4882. tempbx = 0x87;
  4883. if((SiS_Pr->ChipType >= SIS_315H) ||
  4884. (SiS_Pr->ChipRevision >= 0x30)) {
  4885. tempbx = 0x07;
  4886. if((SiS_Pr->SiS_IF_DEF_CH70xx == 1) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
  4887. if(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x03) temp |= 0x80;
  4888. }
  4889. /* Chrontel 701x operates in 24bit mode (8-8-8, 2x12bit multiplexed) via VGA2 */
  4890. if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) {
  4891. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  4892. if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x06) & 0x10) temp |= 0x80;
  4893. } else {
  4894. if(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x01) temp |= 0x80;
  4895. }
  4896. }
  4897. }
  4898. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x1A,tempbx,temp);
  4899. tempbx = push2; /* BPLVDEE */
  4900. tempcx = SiS_Pr->SiS_LCDVDES; /* BPLVDES */
  4901. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4902. switch(SiS_Pr->SiS_LCDResInfo) {
  4903. case Panel_640x480:
  4904. tempbx = SiS_Pr->SiS_VGAVDE - 1;
  4905. tempcx = SiS_Pr->SiS_VGAVDE;
  4906. break;
  4907. case Panel_800x600:
  4908. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  4909. if(resinfo == SIS_RI_800x600) tempcx++;
  4910. }
  4911. break;
  4912. case Panel_1024x600:
  4913. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  4914. if(resinfo == SIS_RI_1024x600) tempcx++;
  4915. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  4916. if(resinfo == SIS_RI_800x600) tempcx++;
  4917. }
  4918. }
  4919. break;
  4920. case Panel_1024x768:
  4921. if(SiS_Pr->ChipType < SIS_315H) {
  4922. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  4923. if(resinfo == SIS_RI_1024x768) tempcx++;
  4924. }
  4925. }
  4926. break;
  4927. }
  4928. }
  4929. temp = ((tempbx >> 8) & 0x07) << 3;
  4930. temp |= ((tempcx >> 8) & 0x07);
  4931. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1D,temp);
  4932. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1C,tempbx);
  4933. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1B,tempcx);
  4934. /* Vertical scaling */
  4935. if(SiS_Pr->ChipType < SIS_315H) {
  4936. #ifdef SIS300 /* 300 series */
  4937. tempeax = SiS_Pr->SiS_VGAVDE << 6;
  4938. temp = (tempeax % (unsigned int)SiS_Pr->SiS_VDE);
  4939. tempeax = tempeax / (unsigned int)SiS_Pr->SiS_VDE;
  4940. if(temp) tempeax++;
  4941. if(SiS_Pr->SiS_SetFlag & EnableLVDSDDA) tempeax = 0x3F;
  4942. temp = (unsigned short)(tempeax & 0x00FF);
  4943. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1E,temp); /* BPLVCFACT */
  4944. tempvcfact = temp;
  4945. #endif /* SIS300 */
  4946. } else {
  4947. #ifdef SIS315H /* 315 series */
  4948. tempeax = SiS_Pr->SiS_VGAVDE << 18;
  4949. tempebx = SiS_Pr->SiS_VDE;
  4950. temp = (tempeax % tempebx);
  4951. tempeax = tempeax / tempebx;
  4952. if(temp) tempeax++;
  4953. tempvcfact = tempeax;
  4954. temp = (unsigned short)(tempeax & 0x00FF);
  4955. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x37,temp);
  4956. temp = (unsigned short)((tempeax & 0x00FF00) >> 8);
  4957. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x36,temp);
  4958. temp = (unsigned short)((tempeax & 0x00030000) >> 16);
  4959. if(SiS_Pr->SiS_VDE == SiS_Pr->SiS_VGAVDE) temp |= 0x04;
  4960. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x35,temp);
  4961. if(SiS_Pr->SiS_VBType & VB_SISPART4SCALER) {
  4962. temp = (unsigned short)(tempeax & 0x00FF);
  4963. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x3c,temp);
  4964. temp = (unsigned short)((tempeax & 0x00FF00) >> 8);
  4965. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x3b,temp);
  4966. temp = (unsigned short)(((tempeax & 0x00030000) >> 16) << 6);
  4967. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x3a,0x3f,temp);
  4968. temp = 0;
  4969. if(SiS_Pr->SiS_VDE != SiS_Pr->SiS_VGAVDE) temp |= 0x08;
  4970. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x30,0xf3,temp);
  4971. }
  4972. #endif
  4973. }
  4974. /* Horizontal scaling */
  4975. tempeax = SiS_Pr->SiS_VGAHDE; /* 1f = ( (VGAHDE * 65536) / ( (VGAHDE * 65536) / HDE ) ) - 1*/
  4976. if(chkdclkfirst) {
  4977. if(modeflag & HalfDCLK) tempeax >>= 1;
  4978. }
  4979. tempebx = tempeax << 16;
  4980. if(SiS_Pr->SiS_HDE == tempeax) {
  4981. tempecx = 0xFFFF;
  4982. } else {
  4983. tempecx = tempebx / SiS_Pr->SiS_HDE;
  4984. if(SiS_Pr->ChipType >= SIS_315H) {
  4985. if(tempebx % SiS_Pr->SiS_HDE) tempecx++;
  4986. }
  4987. }
  4988. if(SiS_Pr->ChipType >= SIS_315H) {
  4989. tempeax = (tempebx / tempecx) - 1;
  4990. } else {
  4991. tempeax = ((SiS_Pr->SiS_VGAHT << 16) / tempecx) - 1;
  4992. }
  4993. tempecx = (tempecx << 16) | (tempeax & 0xFFFF);
  4994. temp = (unsigned short)(tempecx & 0x00FF);
  4995. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1F,temp);
  4996. if(SiS_Pr->ChipType >= SIS_315H) {
  4997. tempeax = (SiS_Pr->SiS_VGAVDE << 18) / tempvcfact;
  4998. tempbx = (unsigned short)(tempeax & 0xFFFF);
  4999. } else {
  5000. tempeax = SiS_Pr->SiS_VGAVDE << 6;
  5001. tempbx = tempvcfact & 0x3f;
  5002. if(tempbx == 0) tempbx = 64;
  5003. tempeax /= tempbx;
  5004. tempbx = (unsigned short)(tempeax & 0xFFFF);
  5005. }
  5006. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) tempbx--;
  5007. if(SiS_Pr->SiS_SetFlag & EnableLVDSDDA) {
  5008. if((!SiS_Pr->SiS_IF_DEF_FSTN) && (!SiS_Pr->SiS_IF_DEF_DSTN)) tempbx = 1;
  5009. else if(SiS_Pr->SiS_LCDResInfo != Panel_640x480) tempbx = 1;
  5010. }
  5011. temp = ((tempbx >> 8) & 0x07) << 3;
  5012. temp = temp | ((tempecx >> 8) & 0x07);
  5013. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x20,temp);
  5014. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x21,tempbx);
  5015. tempecx >>= 16; /* BPLHCFACT */
  5016. if(!chkdclkfirst) {
  5017. if(modeflag & HalfDCLK) tempecx >>= 1;
  5018. }
  5019. temp = (unsigned short)((tempecx & 0xFF00) >> 8);
  5020. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x22,temp);
  5021. temp = (unsigned short)(tempecx & 0x00FF);
  5022. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x23,temp);
  5023. #ifdef SIS315H
  5024. if(SiS_Pr->ChipType >= SIS_315H) {
  5025. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  5026. if((islvds) || (SiS_Pr->SiS_VBInfo & VB_SISLVDS)) {
  5027. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1e,0x20);
  5028. }
  5029. } else {
  5030. if(islvds) {
  5031. if(SiS_Pr->ChipType == SIS_740) {
  5032. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1e,0x03);
  5033. } else {
  5034. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1e,0x23);
  5035. }
  5036. }
  5037. }
  5038. }
  5039. #endif
  5040. #ifdef SIS300
  5041. if(SiS_Pr->SiS_IF_DEF_TRUMPION) {
  5042. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  5043. unsigned char *trumpdata;
  5044. int i, j = crt2crtc;
  5045. unsigned char TrumpMode13[4] = { 0x01, 0x10, 0x2c, 0x00 };
  5046. unsigned char TrumpMode10_1[4] = { 0x01, 0x10, 0x27, 0x00 };
  5047. unsigned char TrumpMode10_2[4] = { 0x01, 0x16, 0x10, 0x00 };
  5048. if(SiS_Pr->SiS_UseROM) {
  5049. trumpdata = &ROMAddr[0x8001 + (j * 80)];
  5050. } else {
  5051. if(SiS_Pr->SiS_LCDTypeInfo == 0x0e) j += 7;
  5052. trumpdata = &SiS300_TrumpionData[j][0];
  5053. }
  5054. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x02,0xbf);
  5055. for(i=0; i<5; i++) {
  5056. SiS_SetTrumpionBlock(SiS_Pr, trumpdata);
  5057. }
  5058. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  5059. if(ModeNo == 0x13) {
  5060. for(i=0; i<4; i++) {
  5061. SiS_SetTrumpionBlock(SiS_Pr, &TrumpMode13[0]);
  5062. }
  5063. } else if(ModeNo == 0x10) {
  5064. for(i=0; i<4; i++) {
  5065. SiS_SetTrumpionBlock(SiS_Pr, &TrumpMode10_1[0]);
  5066. SiS_SetTrumpionBlock(SiS_Pr, &TrumpMode10_2[0]);
  5067. }
  5068. }
  5069. }
  5070. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x02,0x40);
  5071. }
  5072. #endif
  5073. #ifdef SIS315H
  5074. if(SiS_Pr->SiS_IF_DEF_FSTN || SiS_Pr->SiS_IF_DEF_DSTN) {
  5075. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x25,0x00);
  5076. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x26,0x00);
  5077. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x27,0x00);
  5078. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x28,0x87);
  5079. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x29,0x5A);
  5080. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2A,0x4B);
  5081. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x44,~0x07,0x03);
  5082. tempax = SiS_Pr->SiS_HDE; /* Blps = lcdhdee(lcdhdes+HDE) + 64 */
  5083. if(SiS_Pr->SiS_LCDResInfo == Panel_320x240_1 ||
  5084. SiS_Pr->SiS_LCDResInfo == Panel_320x240_2 ||
  5085. SiS_Pr->SiS_LCDResInfo == Panel_320x240_3) tempax >>= 1;
  5086. tempax += 64;
  5087. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x38,tempax & 0xff);
  5088. temp = (tempax >> 8) << 3;
  5089. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x35,~0x078,temp);
  5090. tempax += 32; /* Blpe = lBlps+32 */
  5091. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x39,tempax & 0xff);
  5092. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3A,0x00); /* Bflml = 0 */
  5093. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x3C,~0x007);
  5094. tempax = SiS_Pr->SiS_VDE;
  5095. if(SiS_Pr->SiS_LCDResInfo == Panel_320x240_1 ||
  5096. SiS_Pr->SiS_LCDResInfo == Panel_320x240_2 ||
  5097. SiS_Pr->SiS_LCDResInfo == Panel_320x240_3) tempax >>= 1;
  5098. tempax >>= 1;
  5099. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3B,tempax & 0xff);
  5100. temp = (tempax >> 8) << 3;
  5101. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x3C,~0x038,temp);
  5102. tempeax = SiS_Pr->SiS_HDE;
  5103. if(SiS_Pr->SiS_LCDResInfo == Panel_320x240_1 ||
  5104. SiS_Pr->SiS_LCDResInfo == Panel_320x240_2 ||
  5105. SiS_Pr->SiS_LCDResInfo == Panel_320x240_3) tempeax >>= 1;
  5106. tempeax <<= 2; /* BDxFIFOSTOP = (HDE*4)/128 */
  5107. temp = tempeax & 0x7f;
  5108. tempeax >>= 7;
  5109. if(temp) tempeax++;
  5110. temp = tempeax & 0x3f;
  5111. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x45,temp);
  5112. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3F,0x00); /* BDxWadrst0 */
  5113. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3E,0x00);
  5114. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3D,0x10);
  5115. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x3C,~0x040);
  5116. tempax = SiS_Pr->SiS_HDE;
  5117. if(SiS_Pr->SiS_LCDResInfo == Panel_320x240_1 ||
  5118. SiS_Pr->SiS_LCDResInfo == Panel_320x240_2 ||
  5119. SiS_Pr->SiS_LCDResInfo == Panel_320x240_3) tempax >>= 1;
  5120. tempax >>= 4; /* BDxWadroff = HDE*4/8/8 */
  5121. pushcx = tempax;
  5122. temp = tempax & 0x00FF;
  5123. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x43,temp);
  5124. temp = ((tempax & 0xFF00) >> 8) << 3;
  5125. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x44,~0x0F8,temp);
  5126. tempax = SiS_Pr->SiS_VDE; /* BDxWadrst1 = BDxWadrst0 + BDxWadroff * VDE */
  5127. if(SiS_Pr->SiS_LCDResInfo == Panel_320x240_1 ||
  5128. SiS_Pr->SiS_LCDResInfo == Panel_320x240_2 ||
  5129. SiS_Pr->SiS_LCDResInfo == Panel_320x240_3) tempax >>= 1;
  5130. tempeax = tempax * pushcx;
  5131. temp = tempeax & 0xFF;
  5132. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x42,temp);
  5133. temp = (tempeax & 0xFF00) >> 8;
  5134. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x41,temp);
  5135. temp = ((tempeax & 0xFF0000) >> 16) | 0x10;
  5136. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x40,temp);
  5137. temp = ((tempeax & 0x01000000) >> 24) << 7;
  5138. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x3C,~0x080,temp);
  5139. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2F,0x03);
  5140. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x03,0x50);
  5141. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x04,0x00);
  5142. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2F,0x01);
  5143. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x19,0x38);
  5144. if(SiS_Pr->SiS_IF_DEF_FSTN) {
  5145. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2b,0x02);
  5146. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2c,0x00);
  5147. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2d,0x00);
  5148. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x35,0x0c);
  5149. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x36,0x00);
  5150. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x37,0x00);
  5151. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x38,0x80);
  5152. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x39,0xA0);
  5153. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3a,0x00);
  5154. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3b,0xf0);
  5155. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3c,0x00);
  5156. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3d,0x10);
  5157. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3e,0x00);
  5158. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3f,0x00);
  5159. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x40,0x10);
  5160. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x41,0x25);
  5161. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x42,0x80);
  5162. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x43,0x14);
  5163. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x44,0x03);
  5164. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x45,0x0a);
  5165. }
  5166. }
  5167. #endif /* SIS315H */
  5168. }
  5169. /* Set Part 1 */
  5170. static void
  5171. SiS_SetGroup1(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  5172. unsigned short RefreshRateTableIndex)
  5173. {
  5174. #if defined(SIS300) || defined(SIS315H)
  5175. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  5176. #endif
  5177. unsigned short temp=0, tempax=0, tempbx=0, tempcx=0, bridgeadd=0;
  5178. unsigned short pushbx=0, CRT1Index=0, modeflag, resinfo=0;
  5179. #ifdef SIS315H
  5180. unsigned short tempbl=0;
  5181. #endif
  5182. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  5183. SiS_SetGroup1_LVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  5184. return;
  5185. }
  5186. if(ModeNo <= 0x13) {
  5187. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  5188. } else if(SiS_Pr->UseCustomMode) {
  5189. modeflag = SiS_Pr->CModeFlag;
  5190. } else {
  5191. CRT1Index = SiS_GetRefCRT1CRTC(SiS_Pr, RefreshRateTableIndex, SiS_Pr->SiS_UseWideCRT2);
  5192. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  5193. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  5194. }
  5195. SiS_SetCRT2Offset(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  5196. if( ! ((SiS_Pr->ChipType >= SIS_315H) &&
  5197. (SiS_Pr->SiS_IF_DEF_LVDS == 1) &&
  5198. (SiS_Pr->SiS_VBInfo & SetInSlaveMode)) ) {
  5199. if(SiS_Pr->ChipType < SIS_315H ) {
  5200. #ifdef SIS300
  5201. SiS_SetCRT2FIFO_300(SiS_Pr, ModeNo);
  5202. #endif
  5203. } else {
  5204. #ifdef SIS315H
  5205. SiS_SetCRT2FIFO_310(SiS_Pr);
  5206. #endif
  5207. }
  5208. /* 1. Horizontal setup */
  5209. if(SiS_Pr->ChipType < SIS_315H ) {
  5210. #ifdef SIS300 /* ------------- 300 series --------------*/
  5211. temp = (SiS_Pr->SiS_VGAHT - 1) & 0x0FF; /* BTVGA2HT 0x08,0x09 */
  5212. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x08,temp); /* CRT2 Horizontal Total */
  5213. temp = (((SiS_Pr->SiS_VGAHT - 1) & 0xFF00) >> 8) << 4;
  5214. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x09,0x0f,temp); /* CRT2 Horizontal Total Overflow [7:4] */
  5215. temp = (SiS_Pr->SiS_VGAHDE + 12) & 0x0FF; /* BTVGA2HDEE 0x0A,0x0C */
  5216. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0A,temp); /* CRT2 Horizontal Display Enable End */
  5217. pushbx = SiS_Pr->SiS_VGAHDE + 12; /* bx BTVGA2HRS 0x0B,0x0C */
  5218. tempcx = (SiS_Pr->SiS_VGAHT - SiS_Pr->SiS_VGAHDE) >> 2;
  5219. tempbx = pushbx + tempcx;
  5220. tempcx <<= 1;
  5221. tempcx += tempbx;
  5222. bridgeadd = 12;
  5223. #endif /* SIS300 */
  5224. } else {
  5225. #ifdef SIS315H /* ------------------- 315/330 series --------------- */
  5226. tempcx = SiS_Pr->SiS_VGAHT; /* BTVGA2HT 0x08,0x09 */
  5227. if(modeflag & HalfDCLK) {
  5228. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  5229. tempcx >>= 1;
  5230. } else {
  5231. tempax = SiS_Pr->SiS_VGAHDE >> 1;
  5232. tempcx = SiS_Pr->SiS_HT - SiS_Pr->SiS_HDE + tempax;
  5233. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  5234. tempcx = SiS_Pr->SiS_HT - tempax;
  5235. }
  5236. }
  5237. }
  5238. tempcx--;
  5239. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x08,tempcx); /* CRT2 Horizontal Total */
  5240. temp = (tempcx >> 4) & 0xF0;
  5241. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x09,0x0F,temp); /* CRT2 Horizontal Total Overflow [7:4] */
  5242. tempcx = SiS_Pr->SiS_VGAHT; /* BTVGA2HDEE 0x0A,0x0C */
  5243. tempbx = SiS_Pr->SiS_VGAHDE;
  5244. tempcx -= tempbx;
  5245. tempcx >>= 2;
  5246. if(modeflag & HalfDCLK) {
  5247. tempbx >>= 1;
  5248. tempcx >>= 1;
  5249. }
  5250. tempbx += 16;
  5251. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0A,tempbx); /* CRT2 Horizontal Display Enable End */
  5252. pushbx = tempbx;
  5253. tempcx >>= 1;
  5254. tempbx += tempcx;
  5255. tempcx += tempbx;
  5256. bridgeadd = 16;
  5257. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  5258. if(SiS_Pr->ChipType >= SIS_661) {
  5259. if((SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) ||
  5260. (SiS_Pr->SiS_LCDResInfo == Panel_1280x1024)) {
  5261. if(resinfo == SIS_RI_1280x1024) {
  5262. tempcx = (tempcx & 0xff00) | 0x30;
  5263. } else if(resinfo == SIS_RI_1600x1200) {
  5264. tempcx = (tempcx & 0xff00) | 0xff;
  5265. }
  5266. }
  5267. }
  5268. }
  5269. #endif /* SIS315H */
  5270. } /* 315/330 series */
  5271. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  5272. if(SiS_Pr->UseCustomMode) {
  5273. tempbx = SiS_Pr->CHSyncStart + bridgeadd;
  5274. tempcx = SiS_Pr->CHSyncEnd + bridgeadd;
  5275. tempax = SiS_Pr->SiS_VGAHT;
  5276. if(modeflag & HalfDCLK) tempax >>= 1;
  5277. tempax--;
  5278. if(tempcx > tempax) tempcx = tempax;
  5279. }
  5280. if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) {
  5281. unsigned char cr4, cr14, cr5, cr15;
  5282. if(SiS_Pr->UseCustomMode) {
  5283. cr4 = SiS_Pr->CCRT1CRTC[4];
  5284. cr14 = SiS_Pr->CCRT1CRTC[14];
  5285. cr5 = SiS_Pr->CCRT1CRTC[5];
  5286. cr15 = SiS_Pr->CCRT1CRTC[15];
  5287. } else {
  5288. cr4 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[4];
  5289. cr14 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[14];
  5290. cr5 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[5];
  5291. cr15 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[15];
  5292. }
  5293. tempbx = ((cr4 | ((cr14 & 0xC0) << 2)) - 3) << 3; /* (VGAHRS-3)*8 */
  5294. tempcx = (((cr5 & 0x1f) | ((cr15 & 0x04) << (5-2))) - 3) << 3; /* (VGAHRE-3)*8 */
  5295. tempcx &= 0x00FF;
  5296. tempcx |= (tempbx & 0xFF00);
  5297. tempbx += bridgeadd;
  5298. tempcx += bridgeadd;
  5299. tempax = SiS_Pr->SiS_VGAHT;
  5300. if(modeflag & HalfDCLK) tempax >>= 1;
  5301. tempax--;
  5302. if(tempcx > tempax) tempcx = tempax;
  5303. }
  5304. if(SiS_Pr->SiS_TVMode & (TVSetNTSC1024 | TVSet525p1024)) {
  5305. tempbx = 1040;
  5306. tempcx = 1044; /* HWCursor bug! */
  5307. }
  5308. }
  5309. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0B,tempbx); /* CRT2 Horizontal Retrace Start */
  5310. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0D,tempcx); /* CRT2 Horizontal Retrace End */
  5311. temp = ((tempbx >> 8) & 0x0F) | ((pushbx >> 4) & 0xF0);
  5312. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0C,temp); /* Overflow */
  5313. /* 2. Vertical setup */
  5314. tempcx = SiS_Pr->SiS_VGAVT - 1;
  5315. temp = tempcx & 0x00FF;
  5316. if(SiS_Pr->ChipType < SIS_661) {
  5317. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  5318. if(SiS_Pr->ChipType < SIS_315H) {
  5319. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  5320. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToSVIDEO | SetCRT2ToAVIDEO)) {
  5321. temp--;
  5322. }
  5323. }
  5324. } else {
  5325. temp--;
  5326. }
  5327. } else if(SiS_Pr->ChipType >= SIS_315H) {
  5328. temp--;
  5329. }
  5330. }
  5331. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0E,temp); /* CRT2 Vertical Total */
  5332. tempbx = SiS_Pr->SiS_VGAVDE - 1;
  5333. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0F,tempbx); /* CRT2 Vertical Display Enable End */
  5334. temp = ((tempbx >> 5) & 0x38) | ((tempcx >> 8) & 0x07);
  5335. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x12,temp); /* Overflow */
  5336. if((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->ChipType < SIS_661)) {
  5337. tempbx++;
  5338. tempax = tempbx;
  5339. tempcx++;
  5340. tempcx -= tempax;
  5341. tempcx >>= 2;
  5342. tempbx += tempcx;
  5343. if(tempcx < 4) tempcx = 4;
  5344. tempcx >>= 2;
  5345. tempcx += tempbx;
  5346. tempcx++;
  5347. } else {
  5348. tempbx = (SiS_Pr->SiS_VGAVT + SiS_Pr->SiS_VGAVDE) >> 1; /* BTVGA2VRS 0x10,0x11 */
  5349. tempcx = ((SiS_Pr->SiS_VGAVT - SiS_Pr->SiS_VGAVDE) >> 4) + tempbx + 1; /* BTVGA2VRE 0x11 */
  5350. }
  5351. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  5352. if(SiS_Pr->UseCustomMode) {
  5353. tempbx = SiS_Pr->CVSyncStart;
  5354. tempcx = SiS_Pr->CVSyncEnd;
  5355. }
  5356. if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) {
  5357. unsigned char cr8, cr7, cr13;
  5358. if(SiS_Pr->UseCustomMode) {
  5359. cr8 = SiS_Pr->CCRT1CRTC[8];
  5360. cr7 = SiS_Pr->CCRT1CRTC[7];
  5361. cr13 = SiS_Pr->CCRT1CRTC[13];
  5362. tempcx = SiS_Pr->CCRT1CRTC[9];
  5363. } else {
  5364. cr8 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[8];
  5365. cr7 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[7];
  5366. cr13 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[13];
  5367. tempcx = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[9];
  5368. }
  5369. tempbx = cr8;
  5370. if(cr7 & 0x04) tempbx |= 0x0100;
  5371. if(cr7 & 0x80) tempbx |= 0x0200;
  5372. if(cr13 & 0x08) tempbx |= 0x0400;
  5373. }
  5374. }
  5375. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x10,tempbx); /* CRT2 Vertical Retrace Start */
  5376. temp = ((tempbx >> 4) & 0x70) | (tempcx & 0x0F);
  5377. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x11,temp); /* CRT2 Vert. Retrace End; Overflow */
  5378. /* 3. Panel delay compensation */
  5379. if(SiS_Pr->ChipType < SIS_315H) {
  5380. #ifdef SIS300 /* ---------- 300 series -------------- */
  5381. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  5382. temp = 0x20;
  5383. if(SiS_Pr->ChipType == SIS_300) {
  5384. temp = 0x10;
  5385. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) temp = 0x2c;
  5386. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) temp = 0x20;
  5387. }
  5388. if(SiS_Pr->SiS_VBType & VB_SIS301) {
  5389. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) temp = 0x20;
  5390. }
  5391. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x960) temp = 0x24;
  5392. if(SiS_Pr->SiS_LCDResInfo == Panel_Custom) temp = 0x2c;
  5393. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) temp = 0x08;
  5394. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  5395. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) temp = 0x2c;
  5396. else temp = 0x20;
  5397. }
  5398. if(SiS_Pr->SiS_UseROM) {
  5399. if(ROMAddr[0x220] & 0x80) {
  5400. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoYPbPrHiVision)
  5401. temp = ROMAddr[0x221];
  5402. else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision)
  5403. temp = ROMAddr[0x222];
  5404. else if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024)
  5405. temp = ROMAddr[0x223];
  5406. else
  5407. temp = ROMAddr[0x224];
  5408. }
  5409. }
  5410. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  5411. if(SiS_Pr->PDC != -1) temp = SiS_Pr->PDC;
  5412. }
  5413. } else {
  5414. temp = 0x20;
  5415. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
  5416. if(SiS_Pr->SiS_LCDResInfo == Panel_640x480) temp = 0x04;
  5417. }
  5418. if(SiS_Pr->SiS_UseROM) {
  5419. if(ROMAddr[0x220] & 0x80) {
  5420. temp = ROMAddr[0x220];
  5421. }
  5422. }
  5423. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  5424. if(SiS_Pr->PDC != -1) temp = SiS_Pr->PDC;
  5425. }
  5426. }
  5427. temp &= 0x3c;
  5428. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,~0x3C,temp); /* Panel Link Delay Compensation; (Software Command Reset; Power Saving) */
  5429. #endif /* SIS300 */
  5430. } else {
  5431. #ifdef SIS315H /* --------------- 315/330 series ---------------*/
  5432. if(SiS_Pr->ChipType < SIS_661) {
  5433. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  5434. if(SiS_Pr->ChipType == SIS_740) temp = 0x03;
  5435. else temp = 0x00;
  5436. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) temp = 0x0a;
  5437. tempbl = 0xF0;
  5438. if(SiS_Pr->ChipType == SIS_650) {
  5439. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  5440. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) tempbl = 0x0F;
  5441. }
  5442. }
  5443. if(SiS_Pr->SiS_IF_DEF_DSTN || SiS_Pr->SiS_IF_DEF_FSTN) {
  5444. temp = 0x08;
  5445. tempbl = 0;
  5446. if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
  5447. if(ROMAddr[0x13c] & 0x80) tempbl = 0xf0;
  5448. }
  5449. }
  5450. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,tempbl,temp); /* Panel Link Delay Compensation */
  5451. }
  5452. } /* < 661 */
  5453. tempax = 0;
  5454. if(modeflag & DoubleScanMode) tempax |= 0x80;
  5455. if(modeflag & HalfDCLK) tempax |= 0x40;
  5456. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2C,0x3f,tempax);
  5457. #endif /* SIS315H */
  5458. }
  5459. } /* Slavemode */
  5460. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  5461. if((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) {
  5462. /* For 301BDH with LCD, we set up the Panel Link */
  5463. SiS_SetGroup1_LVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  5464. } else if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  5465. SiS_SetGroup1_301(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  5466. }
  5467. } else {
  5468. if(SiS_Pr->ChipType < SIS_315H) {
  5469. SiS_SetGroup1_LVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  5470. } else {
  5471. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  5472. if((!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) || (SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  5473. SiS_SetGroup1_LVDS(SiS_Pr, ModeNo,ModeIdIndex,RefreshRateTableIndex);
  5474. }
  5475. } else {
  5476. SiS_SetGroup1_LVDS(SiS_Pr, ModeNo,ModeIdIndex,RefreshRateTableIndex);
  5477. }
  5478. }
  5479. }
  5480. }
  5481. /*********************************************/
  5482. /* SET PART 2 REGISTER GROUP */
  5483. /*********************************************/
  5484. #ifdef SIS315H
  5485. static unsigned char *
  5486. SiS_GetGroup2CLVXPtr(struct SiS_Private *SiS_Pr, int tabletype)
  5487. {
  5488. const unsigned char *tableptr = NULL;
  5489. unsigned short a, b, p = 0;
  5490. a = SiS_Pr->SiS_VGAHDE;
  5491. b = SiS_Pr->SiS_HDE;
  5492. if(tabletype) {
  5493. a = SiS_Pr->SiS_VGAVDE;
  5494. b = SiS_Pr->SiS_VDE;
  5495. }
  5496. if(a < b) {
  5497. tableptr = SiS_Part2CLVX_1;
  5498. } else if(a == b) {
  5499. tableptr = SiS_Part2CLVX_2;
  5500. } else {
  5501. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  5502. tableptr = SiS_Part2CLVX_4;
  5503. } else {
  5504. tableptr = SiS_Part2CLVX_3;
  5505. }
  5506. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  5507. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525i) tableptr = SiS_Part2CLVX_3;
  5508. else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) tableptr = SiS_Part2CLVX_3;
  5509. else tableptr = SiS_Part2CLVX_5;
  5510. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  5511. tableptr = SiS_Part2CLVX_6;
  5512. }
  5513. do {
  5514. if((tableptr[p] | tableptr[p+1] << 8) == a) break;
  5515. p += 0x42;
  5516. } while((tableptr[p] | tableptr[p+1] << 8) != 0xffff);
  5517. if((tableptr[p] | tableptr[p+1] << 8) == 0xffff) p -= 0x42;
  5518. }
  5519. p += 2;
  5520. return ((unsigned char *)&tableptr[p]);
  5521. }
  5522. static void
  5523. SiS_SetGroup2_C_ELV(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  5524. unsigned short RefreshRateTableIndex)
  5525. {
  5526. unsigned char *tableptr;
  5527. unsigned char temp;
  5528. int i, j;
  5529. if(!(SiS_Pr->SiS_VBType & VB_SISTAP4SCALER)) return;
  5530. tableptr = SiS_GetGroup2CLVXPtr(SiS_Pr, 0);
  5531. for(i = 0x80, j = 0; i <= 0xbf; i++, j++) {
  5532. SiS_SetReg(SiS_Pr->SiS_Part2Port, i, tableptr[j]);
  5533. }
  5534. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  5535. tableptr = SiS_GetGroup2CLVXPtr(SiS_Pr, 1);
  5536. for(i = 0xc0, j = 0; i <= 0xff; i++, j++) {
  5537. SiS_SetReg(SiS_Pr->SiS_Part2Port, i, tableptr[j]);
  5538. }
  5539. }
  5540. temp = 0x10;
  5541. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) temp |= 0x04;
  5542. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x4e,0xeb,temp);
  5543. }
  5544. static bool
  5545. SiS_GetCRT2Part2Ptr(struct SiS_Private *SiS_Pr,unsigned short ModeNo,unsigned short ModeIdIndex,
  5546. unsigned short RefreshRateTableIndex,unsigned short *CRT2Index,
  5547. unsigned short *ResIndex)
  5548. {
  5549. if(SiS_Pr->ChipType < SIS_315H) return false;
  5550. if(ModeNo <= 0x13)
  5551. (*ResIndex) = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  5552. else
  5553. (*ResIndex) = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  5554. (*ResIndex) &= 0x3f;
  5555. (*CRT2Index) = 0;
  5556. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  5557. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
  5558. (*CRT2Index) = 200;
  5559. }
  5560. }
  5561. if(SiS_Pr->SiS_CustomT == CUT_ASUSA2H_2) {
  5562. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  5563. if(SiS_Pr->SiS_SetFlag & LCDVESATiming) (*CRT2Index) = 206;
  5564. }
  5565. }
  5566. return (((*CRT2Index) != 0));
  5567. }
  5568. #endif
  5569. #ifdef SIS300
  5570. static void
  5571. SiS_Group2LCDSpecial(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short crt2crtc)
  5572. {
  5573. unsigned short tempcx;
  5574. static const unsigned char atable[] = {
  5575. 0xc3,0x9e,0xc3,0x9e,0x02,0x02,0x02,
  5576. 0xab,0x87,0xab,0x9e,0xe7,0x02,0x02
  5577. };
  5578. if(!SiS_Pr->UseCustomMode) {
  5579. if( ( ( (SiS_Pr->ChipType == SIS_630) ||
  5580. (SiS_Pr->ChipType == SIS_730) ) &&
  5581. (SiS_Pr->ChipRevision > 2) ) &&
  5582. (SiS_Pr->SiS_LCDResInfo == Panel_1024x768) &&
  5583. (!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) &&
  5584. (!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) ) {
  5585. if(ModeNo == 0x13) {
  5586. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,0xB9);
  5587. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x05,0xCC);
  5588. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x06,0xA6);
  5589. } else if((crt2crtc & 0x3F) == 4) {
  5590. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x2B);
  5591. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x13);
  5592. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,0xE5);
  5593. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x05,0x08);
  5594. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x06,0xE2);
  5595. }
  5596. }
  5597. if(SiS_Pr->ChipType < SIS_315H) {
  5598. if(SiS_Pr->SiS_LCDTypeInfo == 0x0c) {
  5599. crt2crtc &= 0x1f;
  5600. tempcx = 0;
  5601. if(!(SiS_Pr->SiS_VBInfo & SetNotSimuMode)) {
  5602. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  5603. tempcx += 7;
  5604. }
  5605. }
  5606. tempcx += crt2crtc;
  5607. if(crt2crtc >= 4) {
  5608. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x06,0xff);
  5609. }
  5610. if(!(SiS_Pr->SiS_VBInfo & SetNotSimuMode)) {
  5611. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  5612. if(crt2crtc == 4) {
  5613. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x28);
  5614. }
  5615. }
  5616. }
  5617. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x18);
  5618. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,atable[tempcx]);
  5619. }
  5620. }
  5621. }
  5622. }
  5623. /* For ECS A907. Highly preliminary. */
  5624. static void
  5625. SiS_Set300Part2Regs(struct SiS_Private *SiS_Pr, unsigned short ModeIdIndex, unsigned short RefreshRateTableIndex,
  5626. unsigned short ModeNo)
  5627. {
  5628. const struct SiS_Part2PortTbl *CRT2Part2Ptr = NULL;
  5629. unsigned short crt2crtc, resindex;
  5630. int i, j;
  5631. if(SiS_Pr->ChipType != SIS_300) return;
  5632. if(!(SiS_Pr->SiS_VBType & VB_SIS30xBLV)) return;
  5633. if(SiS_Pr->UseCustomMode) return;
  5634. if(ModeNo <= 0x13) {
  5635. crt2crtc = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  5636. } else {
  5637. crt2crtc = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  5638. }
  5639. resindex = crt2crtc & 0x3F;
  5640. if(SiS_Pr->SiS_SetFlag & LCDVESATiming) CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1024x768_1;
  5641. else CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1024x768_2;
  5642. /* The BIOS code (1.16.51,56) is obviously a fragment! */
  5643. if(ModeNo > 0x13) {
  5644. CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1024x768_1;
  5645. resindex = 4;
  5646. }
  5647. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x01,0x80,(CRT2Part2Ptr+resindex)->CR[0]);
  5648. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x02,0x80,(CRT2Part2Ptr+resindex)->CR[1]);
  5649. for(i = 2, j = 0x04; j <= 0x06; i++, j++ ) {
  5650. SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]);
  5651. }
  5652. for(j = 0x1c; j <= 0x1d; i++, j++ ) {
  5653. SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]);
  5654. }
  5655. for(j = 0x1f; j <= 0x21; i++, j++ ) {
  5656. SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]);
  5657. }
  5658. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x23,(CRT2Part2Ptr+resindex)->CR[10]);
  5659. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x25,0x0f,(CRT2Part2Ptr+resindex)->CR[11]);
  5660. }
  5661. #endif
  5662. static void
  5663. SiS_SetTVSpecial(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
  5664. {
  5665. if(!(SiS_Pr->SiS_VBType & VB_SIS30xBLV)) return;
  5666. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoHiVision)) return;
  5667. if(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p)) return;
  5668. if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) {
  5669. if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) {
  5670. const unsigned char specialtv[] = {
  5671. 0xa7,0x07,0xf2,0x6e,0x17,0x8b,0x73,0x53,
  5672. 0x13,0x40,0x34,0xf4,0x63,0xbb,0xcc,0x7a,
  5673. 0x58,0xe4,0x73,0xda,0x13
  5674. };
  5675. int i, j;
  5676. for(i = 0x1c, j = 0; i <= 0x30; i++, j++) {
  5677. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,specialtv[j]);
  5678. }
  5679. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x43,0x72);
  5680. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750)) {
  5681. if(SiS_Pr->SiS_TVMode & TVSetPALM) {
  5682. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x14);
  5683. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x1b);
  5684. } else {
  5685. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x14); /* 15 */
  5686. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x1a); /* 1b */
  5687. }
  5688. }
  5689. }
  5690. } else {
  5691. if((ModeNo == 0x38) || (ModeNo == 0x4a) || (ModeNo == 0x64) ||
  5692. (ModeNo == 0x52) || (ModeNo == 0x58) || (ModeNo == 0x5c)) {
  5693. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x1b); /* 21 */
  5694. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x54); /* 5a */
  5695. } else {
  5696. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x1a); /* 21 */
  5697. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x53); /* 5a */
  5698. }
  5699. }
  5700. }
  5701. static void
  5702. SiS_SetGroup2_Tail(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
  5703. {
  5704. unsigned short temp;
  5705. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
  5706. if(SiS_Pr->SiS_VGAVDE == 525) {
  5707. temp = 0xc3;
  5708. if(SiS_Pr->SiS_ModeType <= ModeVGA) {
  5709. temp++;
  5710. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) temp += 2;
  5711. }
  5712. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2f,temp);
  5713. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x30,0xb3);
  5714. } else if(SiS_Pr->SiS_VGAVDE == 420) {
  5715. temp = 0x4d;
  5716. if(SiS_Pr->SiS_ModeType <= ModeVGA) {
  5717. temp++;
  5718. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) temp++;
  5719. }
  5720. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2f,temp);
  5721. }
  5722. }
  5723. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  5724. if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) {
  5725. if(SiS_Pr->SiS_VBType & VB_SIS30xB) {
  5726. SiS_SetRegOR(SiS_Pr->SiS_Part2Port,0x1a,0x03);
  5727. /* Not always for LV, see SetGrp2 */
  5728. }
  5729. temp = 1;
  5730. if(ModeNo <= 0x13) temp = 3;
  5731. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x0b,temp);
  5732. }
  5733. #if 0
  5734. /* 651+301C, for 1280x768 - do I really need that? */
  5735. if((SiS_Pr->SiS_PanelXRes == 1280) && (SiS_Pr->SiS_PanelYRes == 768)) {
  5736. if(SiS_Pr->SiS_VBInfo & SetSimuScanMode) {
  5737. if(((SiS_Pr->SiS_HDE == 640) && (SiS_Pr->SiS_VDE == 480)) ||
  5738. ((SiS_Pr->SiS_HDE == 320) && (SiS_Pr->SiS_VDE == 240))) {
  5739. SiS_SetReg(SiS_Part2Port,0x01,0x2b);
  5740. SiS_SetReg(SiS_Part2Port,0x02,0x13);
  5741. SiS_SetReg(SiS_Part2Port,0x04,0xe5);
  5742. SiS_SetReg(SiS_Part2Port,0x05,0x08);
  5743. SiS_SetReg(SiS_Part2Port,0x06,0xe2);
  5744. SiS_SetReg(SiS_Part2Port,0x1c,0x21);
  5745. SiS_SetReg(SiS_Part2Port,0x1d,0x45);
  5746. SiS_SetReg(SiS_Part2Port,0x1f,0x0b);
  5747. SiS_SetReg(SiS_Part2Port,0x20,0x00);
  5748. SiS_SetReg(SiS_Part2Port,0x21,0xa9);
  5749. SiS_SetReg(SiS_Part2Port,0x23,0x0b);
  5750. SiS_SetReg(SiS_Part2Port,0x25,0x04);
  5751. }
  5752. }
  5753. }
  5754. #endif
  5755. }
  5756. }
  5757. static void
  5758. SiS_SetGroup2(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  5759. unsigned short RefreshRateTableIndex)
  5760. {
  5761. unsigned short i, j, tempax, tempbx, tempcx, tempch, tempcl, temp;
  5762. unsigned short push2, modeflag, crt2crtc, bridgeoffset;
  5763. unsigned int longtemp, PhaseIndex;
  5764. bool newtvphase;
  5765. const unsigned char *TimingPoint;
  5766. #ifdef SIS315H
  5767. unsigned short resindex, CRT2Index;
  5768. const struct SiS_Part2PortTbl *CRT2Part2Ptr = NULL;
  5769. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) return;
  5770. #endif
  5771. if(ModeNo <= 0x13) {
  5772. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  5773. crt2crtc = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  5774. } else if(SiS_Pr->UseCustomMode) {
  5775. modeflag = SiS_Pr->CModeFlag;
  5776. crt2crtc = 0;
  5777. } else {
  5778. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  5779. crt2crtc = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  5780. }
  5781. temp = 0;
  5782. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToAVIDEO)) temp |= 0x08;
  5783. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToSVIDEO)) temp |= 0x04;
  5784. if(SiS_Pr->SiS_VBInfo & SetCRT2ToSCART) temp |= 0x02;
  5785. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) temp |= 0x01;
  5786. if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) temp |= 0x10;
  5787. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x00,temp);
  5788. PhaseIndex = 0x01; /* SiS_PALPhase */
  5789. TimingPoint = SiS_Pr->SiS_PALTiming;
  5790. newtvphase = false;
  5791. if( (SiS_Pr->SiS_VBType & VB_SIS30xBLV) &&
  5792. ( (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) ||
  5793. (SiS_Pr->SiS_TVMode & TVSetTVSimuMode) ) ) {
  5794. newtvphase = true;
  5795. }
  5796. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  5797. TimingPoint = SiS_Pr->SiS_HiTVExtTiming;
  5798. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  5799. TimingPoint = SiS_Pr->SiS_HiTVSt2Timing;
  5800. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) {
  5801. TimingPoint = SiS_Pr->SiS_HiTVSt1Timing;
  5802. }
  5803. }
  5804. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  5805. i = 0;
  5806. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) i = 2;
  5807. else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) i = 1;
  5808. TimingPoint = &SiS_YPbPrTable[i][0];
  5809. PhaseIndex = 0x00; /* SiS_NTSCPhase */
  5810. } else if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  5811. if(newtvphase) PhaseIndex = 0x09; /* SiS_PALPhase2 */
  5812. } else {
  5813. TimingPoint = SiS_Pr->SiS_NTSCTiming;
  5814. PhaseIndex = (SiS_Pr->SiS_TVMode & TVSetNTSCJ) ? 0x01 : 0x00; /* SiS_PALPhase : SiS_NTSCPhase */
  5815. if(newtvphase) PhaseIndex += 8; /* SiS_PALPhase2 : SiS_NTSCPhase2 */
  5816. }
  5817. if(SiS_Pr->SiS_TVMode & (TVSetPALM | TVSetPALN)) {
  5818. PhaseIndex = (SiS_Pr->SiS_TVMode & TVSetPALM) ? 0x02 : 0x03; /* SiS_PALMPhase : SiS_PALNPhase */
  5819. if(newtvphase) PhaseIndex += 8; /* SiS_PALMPhase2 : SiS_PALNPhase2 */
  5820. }
  5821. if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) {
  5822. if(SiS_Pr->SiS_TVMode & TVSetPALM) {
  5823. PhaseIndex = 0x05; /* SiS_SpecialPhaseM */
  5824. } else if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) {
  5825. PhaseIndex = 0x11; /* SiS_SpecialPhaseJ */
  5826. } else {
  5827. PhaseIndex = 0x10; /* SiS_SpecialPhase */
  5828. }
  5829. }
  5830. for(i = 0x31, j = 0; i <= 0x34; i++, j++) {
  5831. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS_TVPhase[(PhaseIndex * 4) + j]);
  5832. }
  5833. for(i = 0x01, j = 0; i <= 0x2D; i++, j++) {
  5834. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,TimingPoint[j]);
  5835. }
  5836. for(i = 0x39; i <= 0x45; i++, j++) {
  5837. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,TimingPoint[j]);
  5838. }
  5839. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  5840. if(SiS_Pr->SiS_ModeType != ModeText) {
  5841. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x3A,0x1F);
  5842. }
  5843. }
  5844. SiS_SetRegOR(SiS_Pr->SiS_Part2Port,0x0A,SiS_Pr->SiS_NewFlickerMode);
  5845. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x35,SiS_Pr->SiS_RY1COE);
  5846. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x36,SiS_Pr->SiS_RY2COE);
  5847. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x37,SiS_Pr->SiS_RY3COE);
  5848. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x38,SiS_Pr->SiS_RY4COE);
  5849. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) tempax = 950;
  5850. else if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) tempax = 680;
  5851. else if(SiS_Pr->SiS_TVMode & TVSetPAL) tempax = 520;
  5852. else tempax = 440; /* NTSC, YPbPr 525 */
  5853. if( ((SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) && (SiS_Pr->SiS_VDE <= tempax)) ||
  5854. ( (SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoHiVision) &&
  5855. ((SiS_Pr->SiS_VGAHDE == 1024) || (SiS_Pr->SiS_VDE <= tempax)) ) ) {
  5856. tempax -= SiS_Pr->SiS_VDE;
  5857. tempax >>= 1;
  5858. if(!(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p))) {
  5859. tempax >>= 1;
  5860. }
  5861. tempax &= 0x00ff;
  5862. temp = tempax + (unsigned short)TimingPoint[0];
  5863. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,temp);
  5864. temp = tempax + (unsigned short)TimingPoint[1];
  5865. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,temp);
  5866. if((SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoYPbPrHiVision) && (SiS_Pr->SiS_VGAHDE >= 1024)) {
  5867. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  5868. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x1b);
  5869. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x54);
  5870. } else {
  5871. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x17);
  5872. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x1d);
  5873. }
  5874. }
  5875. }
  5876. tempcx = SiS_Pr->SiS_HT;
  5877. if(SiS_IsDualLink(SiS_Pr)) tempcx >>= 1;
  5878. tempcx--;
  5879. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) tempcx--;
  5880. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x1B,tempcx);
  5881. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1D,0xF0,((tempcx >> 8) & 0x0f));
  5882. tempcx = SiS_Pr->SiS_HT >> 1;
  5883. if(SiS_IsDualLink(SiS_Pr)) tempcx >>= 1;
  5884. tempcx += 7;
  5885. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) tempcx -= 4;
  5886. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x22,0x0F,((tempcx << 4) & 0xf0));
  5887. tempbx = TimingPoint[j] | (TimingPoint[j+1] << 8);
  5888. tempbx += tempcx;
  5889. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x24,tempbx);
  5890. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x25,0x0F,((tempbx >> 4) & 0xf0));
  5891. tempbx += 8;
  5892. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  5893. tempbx -= 4;
  5894. tempcx = tempbx;
  5895. }
  5896. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x29,0x0F,((tempbx << 4) & 0xf0));
  5897. j += 2;
  5898. tempcx += (TimingPoint[j] | (TimingPoint[j+1] << 8));
  5899. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x27,tempcx);
  5900. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x28,0x0F,((tempcx >> 4) & 0xf0));
  5901. tempcx += 8;
  5902. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) tempcx -= 4;
  5903. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2A,0x0F,((tempcx << 4) & 0xf0));
  5904. tempcx = SiS_Pr->SiS_HT >> 1;
  5905. if(SiS_IsDualLink(SiS_Pr)) tempcx >>= 1;
  5906. j += 2;
  5907. tempcx -= (TimingPoint[j] | ((TimingPoint[j+1]) << 8));
  5908. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2D,0x0F,((tempcx << 4) & 0xf0));
  5909. tempcx -= 11;
  5910. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
  5911. tempcx = SiS_GetVGAHT2(SiS_Pr) - 1;
  5912. }
  5913. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2E,tempcx);
  5914. tempbx = SiS_Pr->SiS_VDE;
  5915. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  5916. if(SiS_Pr->SiS_VGAVDE == 360) tempbx = 746;
  5917. if(SiS_Pr->SiS_VGAVDE == 375) tempbx = 746;
  5918. if(SiS_Pr->SiS_VGAVDE == 405) tempbx = 853;
  5919. } else if( (SiS_Pr->SiS_VBInfo & SetCRT2ToTV) &&
  5920. (!(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p|TVSetYPbPr750p))) ) {
  5921. tempbx >>= 1;
  5922. if(SiS_Pr->ChipType >= SIS_315H) {
  5923. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) {
  5924. if((ModeNo <= 0x13) && (crt2crtc == 1)) tempbx++;
  5925. } else if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  5926. if(SiS_Pr->SiS_ModeType <= ModeVGA) {
  5927. if(crt2crtc == 4) tempbx++;
  5928. }
  5929. }
  5930. }
  5931. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  5932. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  5933. if((ModeNo == 0x2f) || (ModeNo == 0x5d) || (ModeNo == 0x5e)) tempbx++;
  5934. }
  5935. if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) {
  5936. if(ModeNo == 0x03) tempbx++; /* From 1.10.7w - doesn't make sense */
  5937. }
  5938. }
  5939. }
  5940. tempbx -= 2;
  5941. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2F,tempbx);
  5942. temp = (tempcx >> 8) & 0x0F;
  5943. temp |= ((tempbx >> 2) & 0xC0);
  5944. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToSVIDEO | SetCRT2ToAVIDEO)) {
  5945. temp |= 0x10;
  5946. if(SiS_Pr->SiS_VBInfo & SetCRT2ToAVIDEO) temp |= 0x20;
  5947. }
  5948. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x30,temp);
  5949. if(SiS_Pr->SiS_VBType & VB_SISPART4OVERFLOW) {
  5950. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x10,0xdf,((tempbx & 0x0400) >> 5));
  5951. }
  5952. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  5953. tempbx = SiS_Pr->SiS_VDE;
  5954. if( (SiS_Pr->SiS_VBInfo & SetCRT2ToTV) &&
  5955. (!(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p))) ) {
  5956. tempbx >>= 1;
  5957. }
  5958. tempbx -= 3;
  5959. temp = ((tempbx >> 3) & 0x60) | 0x18;
  5960. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x46,temp);
  5961. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x47,tempbx);
  5962. if(SiS_Pr->SiS_VBType & VB_SISPART4OVERFLOW) {
  5963. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x10,0xbf,((tempbx & 0x0400) >> 4));
  5964. }
  5965. }
  5966. tempbx = 0;
  5967. if(!(modeflag & HalfDCLK)) {
  5968. if(SiS_Pr->SiS_VGAHDE >= SiS_Pr->SiS_HDE) {
  5969. tempax = 0;
  5970. tempbx |= 0x20;
  5971. }
  5972. }
  5973. tempch = tempcl = 0x01;
  5974. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  5975. if(SiS_Pr->SiS_VGAHDE >= 960) {
  5976. if((!(modeflag & HalfDCLK)) || (SiS_Pr->ChipType < SIS_315H)) {
  5977. tempcl = 0x20;
  5978. if(SiS_Pr->SiS_VGAHDE >= 1280) {
  5979. tempch = 20;
  5980. tempbx &= ~0x20;
  5981. } else if(SiS_Pr->SiS_VGAHDE >= 1024) {
  5982. tempch = 25;
  5983. } else {
  5984. tempch = 25; /* OK */
  5985. }
  5986. }
  5987. }
  5988. }
  5989. if(!(tempbx & 0x20)) {
  5990. if(modeflag & HalfDCLK) tempcl <<= 1;
  5991. longtemp = ((SiS_Pr->SiS_VGAHDE * tempch) / tempcl) << 13;
  5992. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) longtemp <<= 3;
  5993. tempax = longtemp / SiS_Pr->SiS_HDE;
  5994. if(longtemp % SiS_Pr->SiS_HDE) tempax++;
  5995. tempbx |= ((tempax >> 8) & 0x1F);
  5996. tempcx = tempax >> 13;
  5997. }
  5998. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x44,tempax);
  5999. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x45,0xC0,tempbx);
  6000. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  6001. tempcx &= 0x07;
  6002. if(tempbx & 0x20) tempcx = 0;
  6003. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x46,0xF8,tempcx);
  6004. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  6005. tempbx = 0x0382;
  6006. tempcx = 0x007e;
  6007. } else {
  6008. tempbx = 0x0369;
  6009. tempcx = 0x0061;
  6010. }
  6011. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x4B,tempbx);
  6012. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x4C,tempcx);
  6013. temp = (tempcx & 0x0300) >> 6;
  6014. temp |= ((tempbx >> 8) & 0x03);
  6015. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  6016. temp |= 0x10;
  6017. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) temp |= 0x20;
  6018. else if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) temp |= 0x40;
  6019. }
  6020. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x4D,temp);
  6021. temp = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x43);
  6022. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x43,(temp - 3));
  6023. SiS_SetTVSpecial(SiS_Pr, ModeNo);
  6024. if(SiS_Pr->SiS_VBType & VB_SIS30xCLV) {
  6025. temp = 0;
  6026. if(SiS_Pr->SiS_TVMode & TVSetPALM) temp = 8;
  6027. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x4e,0xf7,temp);
  6028. }
  6029. }
  6030. if(SiS_Pr->SiS_TVMode & TVSetPALM) {
  6031. if(!(SiS_Pr->SiS_TVMode & TVSetNTSC1024)) {
  6032. temp = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x01);
  6033. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,(temp - 1));
  6034. }
  6035. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xEF);
  6036. }
  6037. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  6038. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  6039. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x0B,0x00);
  6040. }
  6041. }
  6042. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) return;
  6043. /* From here: Part2 LCD setup */
  6044. tempbx = SiS_Pr->SiS_HDE;
  6045. if(SiS_IsDualLink(SiS_Pr)) tempbx >>= 1;
  6046. tempbx--; /* RHACTE = HDE - 1 */
  6047. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2C,tempbx);
  6048. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2B,0x0F,((tempbx >> 4) & 0xf0));
  6049. temp = 0x01;
  6050. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) {
  6051. if(SiS_Pr->SiS_ModeType == ModeEGA) {
  6052. if(SiS_Pr->SiS_VGAHDE >= 1024) {
  6053. temp = 0x02;
  6054. if(SiS_Pr->SiS_SetFlag & LCDVESATiming) {
  6055. temp = 0x01;
  6056. }
  6057. }
  6058. }
  6059. }
  6060. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x0B,temp);
  6061. tempbx = SiS_Pr->SiS_VDE - 1;
  6062. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x03,tempbx);
  6063. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x0C,0xF8,((tempbx >> 8) & 0x07));
  6064. tempcx = SiS_Pr->SiS_VT - 1;
  6065. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x19,tempcx);
  6066. temp = (tempcx >> 3) & 0xE0;
  6067. if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) {
  6068. /* Enable dithering; only do this for 32bpp mode */
  6069. if(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x01) {
  6070. temp |= 0x10;
  6071. }
  6072. }
  6073. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1A,0x0f,temp);
  6074. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x09,0xF0);
  6075. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x0A,0xF0);
  6076. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x17,0xFB);
  6077. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x18,0xDF);
  6078. #ifdef SIS315H
  6079. if(SiS_GetCRT2Part2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex,
  6080. &CRT2Index, &resindex)) {
  6081. switch(CRT2Index) {
  6082. case 206: CRT2Part2Ptr = SiS310_CRT2Part2_Asus1024x768_3; break;
  6083. default:
  6084. case 200: CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1024x768_1; break;
  6085. }
  6086. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x01,0x80,(CRT2Part2Ptr+resindex)->CR[0]);
  6087. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x02,0x80,(CRT2Part2Ptr+resindex)->CR[1]);
  6088. for(i = 2, j = 0x04; j <= 0x06; i++, j++ ) {
  6089. SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]);
  6090. }
  6091. for(j = 0x1c; j <= 0x1d; i++, j++ ) {
  6092. SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]);
  6093. }
  6094. for(j = 0x1f; j <= 0x21; i++, j++ ) {
  6095. SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]);
  6096. }
  6097. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x23,(CRT2Part2Ptr+resindex)->CR[10]);
  6098. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x25,0x0f,(CRT2Part2Ptr+resindex)->CR[11]);
  6099. SiS_SetGroup2_Tail(SiS_Pr, ModeNo);
  6100. } else {
  6101. #endif
  6102. /* Checked for 1024x768, 1280x1024, 1400x1050, 1600x1200 */
  6103. /* Clevo dual-link 1024x768 */
  6104. /* Compaq 1280x1024 has HT 1696 sometimes (calculation OK, if given HT is correct) */
  6105. /* Acer: OK, but uses different setting for VESA timing at 640/800/1024 and 640x400 */
  6106. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  6107. if((SiS_Pr->SiS_LCDInfo & LCDPass11) || (SiS_Pr->PanelYRes == SiS_Pr->SiS_VDE)) {
  6108. tempbx = SiS_Pr->SiS_VDE - 1;
  6109. tempcx = SiS_Pr->SiS_VT - 1;
  6110. } else {
  6111. tempbx = SiS_Pr->SiS_VDE + ((SiS_Pr->PanelYRes - SiS_Pr->SiS_VDE) / 2);
  6112. tempcx = SiS_Pr->SiS_VT - ((SiS_Pr->PanelYRes - SiS_Pr->SiS_VDE) / 2);
  6113. }
  6114. } else {
  6115. tempbx = SiS_Pr->PanelYRes;
  6116. tempcx = SiS_Pr->SiS_VT;
  6117. tempax = 1;
  6118. if(SiS_Pr->PanelYRes != SiS_Pr->SiS_VDE) {
  6119. tempax = SiS_Pr->PanelYRes;
  6120. /* if(SiS_Pr->SiS_VGAVDE == 525) tempax += 0x3c; */ /* 651+301C */
  6121. if(SiS_Pr->PanelYRes < SiS_Pr->SiS_VDE) {
  6122. tempax = tempcx = 0;
  6123. } else {
  6124. tempax -= SiS_Pr->SiS_VDE;
  6125. }
  6126. tempax >>= 1;
  6127. }
  6128. tempcx -= tempax; /* lcdvdes */
  6129. tempbx -= tempax; /* lcdvdee */
  6130. }
  6131. /* Non-expanding: lcdvdes = tempcx = VT-1; lcdvdee = tempbx = VDE-1 */
  6132. #ifdef SIS_XORG_XF86
  6133. #ifdef TWDEBUG
  6134. xf86DrvMsg(0, X_INFO, "lcdvdes 0x%x lcdvdee 0x%x\n", tempcx, tempbx);
  6135. #endif
  6136. #endif
  6137. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x05,tempcx); /* lcdvdes */
  6138. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x06,tempbx); /* lcdvdee */
  6139. temp = (tempbx >> 5) & 0x38;
  6140. temp |= ((tempcx >> 8) & 0x07);
  6141. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,temp);
  6142. tempax = SiS_Pr->SiS_VDE;
  6143. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
  6144. tempax = SiS_Pr->PanelYRes;
  6145. }
  6146. tempcx = (SiS_Pr->SiS_VT - tempax) >> 4;
  6147. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
  6148. if(SiS_Pr->PanelYRes != SiS_Pr->SiS_VDE) {
  6149. tempcx = (SiS_Pr->SiS_VT - tempax) / 10;
  6150. }
  6151. }
  6152. tempbx = ((SiS_Pr->SiS_VT + SiS_Pr->SiS_VDE) >> 1) - 1;
  6153. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  6154. if(SiS_Pr->PanelYRes != SiS_Pr->SiS_VDE) {
  6155. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) { /* ? */
  6156. tempax = SiS_Pr->SiS_VT - SiS_Pr->PanelYRes;
  6157. if(tempax % 4) { tempax >>= 2; tempax++; }
  6158. else { tempax >>= 2; }
  6159. tempbx -= (tempax - 1);
  6160. } else {
  6161. tempbx -= 10;
  6162. if(tempbx <= SiS_Pr->SiS_VDE) tempbx = SiS_Pr->SiS_VDE + 1;
  6163. }
  6164. }
  6165. }
  6166. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  6167. tempbx++;
  6168. if((!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) || (crt2crtc == 6)) {
  6169. if(SiS_Pr->SiS_SetFlag & LCDVESATiming) {
  6170. tempbx = 770;
  6171. tempcx = 3;
  6172. }
  6173. }
  6174. }
  6175. /* non-expanding: lcdvrs = ((VT + VDE) / 2) - 10 */
  6176. if(SiS_Pr->UseCustomMode) {
  6177. tempbx = SiS_Pr->CVSyncStart;
  6178. }
  6179. #ifdef SIS_XORG_XF86
  6180. #ifdef TWDEBUG
  6181. xf86DrvMsg(0, X_INFO, "lcdvrs 0x%x\n", tempbx);
  6182. #endif
  6183. #endif
  6184. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,tempbx); /* lcdvrs */
  6185. temp = (tempbx >> 4) & 0xF0;
  6186. tempbx += (tempcx + 1);
  6187. temp |= (tempbx & 0x0F);
  6188. if(SiS_Pr->UseCustomMode) {
  6189. temp &= 0xf0;
  6190. temp |= (SiS_Pr->CVSyncEnd & 0x0f);
  6191. }
  6192. #ifdef SIS_XORG_XF86
  6193. #ifdef TWDEBUG
  6194. xf86DrvMsg(0, X_INFO, "lcdvre[3:0] 0x%x\n", (temp & 0x0f));
  6195. #endif
  6196. #endif
  6197. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,temp);
  6198. #ifdef SIS300
  6199. SiS_Group2LCDSpecial(SiS_Pr, ModeNo, crt2crtc);
  6200. #endif
  6201. bridgeoffset = 7;
  6202. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) bridgeoffset += 2;
  6203. if(SiS_Pr->SiS_VBType & VB_SIS30xCLV) bridgeoffset += 2; /* OK for Averatec 1280x800 (301C) */
  6204. if(SiS_IsDualLink(SiS_Pr)) bridgeoffset++;
  6205. else if(SiS_Pr->SiS_VBType & VB_SIS302LV) bridgeoffset++; /* OK for Asus A4L 1280x800 */
  6206. /* Higher bridgeoffset shifts to the LEFT */
  6207. temp = 0;
  6208. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
  6209. if(SiS_Pr->PanelXRes != SiS_Pr->SiS_HDE) {
  6210. temp = SiS_Pr->SiS_HT - ((SiS_Pr->PanelXRes - SiS_Pr->SiS_HDE) / 2);
  6211. if(SiS_IsDualLink(SiS_Pr)) temp >>= 1;
  6212. }
  6213. }
  6214. temp += bridgeoffset;
  6215. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x1F,temp); /* lcdhdes */
  6216. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x20,0x0F,((temp >> 4) & 0xf0));
  6217. tempcx = SiS_Pr->SiS_HT;
  6218. tempax = tempbx = SiS_Pr->SiS_HDE;
  6219. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
  6220. if(SiS_Pr->PanelXRes != SiS_Pr->SiS_HDE) {
  6221. tempax = SiS_Pr->PanelXRes;
  6222. tempbx = SiS_Pr->PanelXRes - ((SiS_Pr->PanelXRes - SiS_Pr->SiS_HDE) / 2);
  6223. }
  6224. }
  6225. if(SiS_IsDualLink(SiS_Pr)) {
  6226. tempcx >>= 1;
  6227. tempbx >>= 1;
  6228. tempax >>= 1;
  6229. }
  6230. #ifdef SIS_XORG_XF86
  6231. #ifdef TWDEBUG
  6232. xf86DrvMsg(0, X_INFO, "lcdhdee 0x%x\n", tempbx);
  6233. #endif
  6234. #endif
  6235. tempbx += bridgeoffset;
  6236. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x23,tempbx); /* lcdhdee */
  6237. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x25,0xF0,((tempbx >> 8) & 0x0f));
  6238. tempcx = (tempcx - tempax) >> 2;
  6239. tempbx += tempcx;
  6240. push2 = tempbx;
  6241. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) {
  6242. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  6243. if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
  6244. if(SiS_Pr->SiS_HDE == 1280) tempbx = (tempbx & 0xff00) | 0x47;
  6245. }
  6246. }
  6247. }
  6248. if(SiS_Pr->UseCustomMode) {
  6249. tempbx = SiS_Pr->CHSyncStart;
  6250. if(modeflag & HalfDCLK) tempbx <<= 1;
  6251. if(SiS_IsDualLink(SiS_Pr)) tempbx >>= 1;
  6252. tempbx += bridgeoffset;
  6253. }
  6254. #ifdef SIS_XORG_XF86
  6255. #ifdef TWDEBUG
  6256. xf86DrvMsg(0, X_INFO, "lcdhrs 0x%x\n", tempbx);
  6257. #endif
  6258. #endif
  6259. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x1C,tempbx); /* lcdhrs */
  6260. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1D,0x0F,((tempbx >> 4) & 0xf0));
  6261. tempbx = push2;
  6262. tempcx <<= 1;
  6263. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
  6264. if(SiS_Pr->PanelXRes != SiS_Pr->SiS_HDE) tempcx >>= 2;
  6265. }
  6266. tempbx += tempcx;
  6267. if(SiS_Pr->UseCustomMode) {
  6268. tempbx = SiS_Pr->CHSyncEnd;
  6269. if(modeflag & HalfDCLK) tempbx <<= 1;
  6270. if(SiS_IsDualLink(SiS_Pr)) tempbx >>= 1;
  6271. tempbx += bridgeoffset;
  6272. }
  6273. #ifdef SIS_XORG_XF86
  6274. #ifdef TWDEBUG
  6275. xf86DrvMsg(0, X_INFO, "lcdhre 0x%x\n", tempbx);
  6276. #endif
  6277. #endif
  6278. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x21,tempbx); /* lcdhre */
  6279. SiS_SetGroup2_Tail(SiS_Pr, ModeNo);
  6280. #ifdef SIS300
  6281. SiS_Set300Part2Regs(SiS_Pr, ModeIdIndex, RefreshRateTableIndex, ModeNo);
  6282. #endif
  6283. #ifdef SIS315H
  6284. } /* CRT2-LCD from table */
  6285. #endif
  6286. }
  6287. /*********************************************/
  6288. /* SET PART 3 REGISTER GROUP */
  6289. /*********************************************/
  6290. static void
  6291. SiS_SetGroup3(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  6292. {
  6293. unsigned short i;
  6294. const unsigned char *tempdi;
  6295. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) return;
  6296. #ifndef SIS_CP
  6297. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x00,0x00);
  6298. #else
  6299. SIS_CP_INIT301_CP
  6300. #endif
  6301. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  6302. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x13,0xFA);
  6303. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x14,0xC8);
  6304. } else {
  6305. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x13,0xF5);
  6306. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x14,0xB7);
  6307. }
  6308. if(SiS_Pr->SiS_TVMode & TVSetPALM) {
  6309. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x13,0xFA);
  6310. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x14,0xC8);
  6311. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x3D,0xA8);
  6312. }
  6313. tempdi = NULL;
  6314. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  6315. tempdi = SiS_Pr->SiS_HiTVGroup3Data;
  6316. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) {
  6317. tempdi = SiS_Pr->SiS_HiTVGroup3Simu;
  6318. }
  6319. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  6320. if(!(SiS_Pr->SiS_TVMode & TVSetYPbPr525i)) {
  6321. tempdi = SiS_HiTVGroup3_1;
  6322. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) tempdi = SiS_HiTVGroup3_2;
  6323. }
  6324. }
  6325. if(tempdi) {
  6326. for(i=0; i<=0x3E; i++) {
  6327. SiS_SetReg(SiS_Pr->SiS_Part3Port,i,tempdi[i]);
  6328. }
  6329. if(SiS_Pr->SiS_VBType & VB_SIS30xCLV) {
  6330. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) {
  6331. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x28,0x3f);
  6332. }
  6333. }
  6334. }
  6335. #ifdef SIS_CP
  6336. SIS_CP_INIT301_CP2
  6337. #endif
  6338. }
  6339. /*********************************************/
  6340. /* SET PART 4 REGISTER GROUP */
  6341. /*********************************************/
  6342. #ifdef SIS315H
  6343. #if 0
  6344. static void
  6345. SiS_ShiftXPos(struct SiS_Private *SiS_Pr, int shift)
  6346. {
  6347. unsigned short temp, temp1, temp2;
  6348. temp1 = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x1f);
  6349. temp2 = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x20);
  6350. temp = (unsigned short)((int)((temp1 | ((temp2 & 0xf0) << 4))) + shift);
  6351. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x1f,temp);
  6352. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x20,0x0f,((temp >> 4) & 0xf0));
  6353. temp = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x2b) & 0x0f;
  6354. temp = (unsigned short)((int)(temp) + shift);
  6355. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2b,0xf0,(temp & 0x0f));
  6356. temp1 = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x43);
  6357. temp2 = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x42);
  6358. temp = (unsigned short)((int)((temp1 | ((temp2 & 0xf0) << 4))) + shift);
  6359. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x43,temp);
  6360. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x42,0x0f,((temp >> 4) & 0xf0));
  6361. }
  6362. #endif
  6363. static void
  6364. SiS_SetGroup4_C_ELV(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  6365. {
  6366. unsigned short temp, temp1, resinfo = 0;
  6367. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  6368. if(!(SiS_Pr->SiS_VBType & VB_SIS30xCLV)) return;
  6369. if(!(SiS_Pr->SiS_VBInfo & (SetCRT2ToHiVision | SetCRT2ToYPbPr525750))) return;
  6370. if(SiS_Pr->ChipType >= XGI_20) return;
  6371. if((SiS_Pr->ChipType >= SIS_661) && (SiS_Pr->SiS_ROMNew)) {
  6372. if(!(ROMAddr[0x61] & 0x04)) return;
  6373. }
  6374. if(ModeNo > 0x13) {
  6375. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  6376. }
  6377. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x3a,0x08);
  6378. temp = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x3a);
  6379. if(!(temp & 0x01)) {
  6380. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x3a,0xdf);
  6381. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x25,0xfc);
  6382. if((SiS_Pr->ChipType < SIS_661) && (!(SiS_Pr->SiS_ROMNew))) {
  6383. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x25,0xf8);
  6384. }
  6385. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x0f,0xfb);
  6386. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) temp = 0x0000;
  6387. else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) temp = 0x0002;
  6388. else if(SiS_Pr->SiS_TVMode & TVSetHiVision) temp = 0x0400;
  6389. else temp = 0x0402;
  6390. if((SiS_Pr->ChipType >= SIS_661) || (SiS_Pr->SiS_ROMNew)) {
  6391. temp1 = 0;
  6392. if(SiS_Pr->SiS_TVMode & TVAspect43) temp1 = 4;
  6393. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x0f,0xfb,temp1);
  6394. if(SiS_Pr->SiS_TVMode & TVAspect43LB) temp |= 0x01;
  6395. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x26,0x7c,(temp & 0xff));
  6396. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x3a,0xfb,(temp >> 8));
  6397. if(ModeNo > 0x13) {
  6398. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x39,0xfd);
  6399. }
  6400. } else {
  6401. temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x3b) & 0x03;
  6402. if(temp1 == 0x01) temp |= 0x01;
  6403. if(temp1 == 0x03) temp |= 0x04; /* ? why not 0x10? */
  6404. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x26,0xf8,(temp & 0xff));
  6405. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x3a,0xfb,(temp >> 8));
  6406. if(ModeNo > 0x13) {
  6407. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x3b,0xfd);
  6408. }
  6409. }
  6410. #if 0
  6411. if(SiS_Pr->ChipType >= SIS_661) { /* ? */
  6412. if(SiS_Pr->SiS_TVMode & TVAspect43) {
  6413. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) {
  6414. if(resinfo == SIS_RI_1024x768) {
  6415. SiS_ShiftXPos(SiS_Pr, 97);
  6416. } else {
  6417. SiS_ShiftXPos(SiS_Pr, 111);
  6418. }
  6419. } else if(SiS_Pr->SiS_TVMode & TVSetHiVision) {
  6420. SiS_ShiftXPos(SiS_Pr, 136);
  6421. }
  6422. }
  6423. }
  6424. #endif
  6425. }
  6426. }
  6427. #endif
  6428. static void
  6429. SiS_SetCRT2VCLK(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  6430. unsigned short RefreshRateTableIndex)
  6431. {
  6432. unsigned short vclkindex, temp, reg1, reg2;
  6433. if(SiS_Pr->UseCustomMode) {
  6434. reg1 = SiS_Pr->CSR2B;
  6435. reg2 = SiS_Pr->CSR2C;
  6436. } else {
  6437. vclkindex = SiS_GetVCLK2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  6438. reg1 = SiS_Pr->SiS_VBVCLKData[vclkindex].Part4_A;
  6439. reg2 = SiS_Pr->SiS_VBVCLKData[vclkindex].Part4_B;
  6440. }
  6441. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  6442. if(SiS_Pr->SiS_TVMode & (TVSetNTSC1024 | TVSet525p1024)) {
  6443. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0a,0x57);
  6444. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0b,0x46);
  6445. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1f,0xf6);
  6446. } else {
  6447. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0a,reg1);
  6448. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0b,reg2);
  6449. }
  6450. } else {
  6451. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0a,0x01);
  6452. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0b,reg2);
  6453. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0a,reg1);
  6454. }
  6455. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x12,0x00);
  6456. temp = 0x08;
  6457. if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) temp |= 0x20;
  6458. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x12,temp);
  6459. }
  6460. static void
  6461. SiS_SetDualLinkEtc(struct SiS_Private *SiS_Pr)
  6462. {
  6463. if(SiS_Pr->ChipType >= SIS_315H) {
  6464. if(SiS_Pr->SiS_VBType & VB_SISDUALLINK) {
  6465. if((SiS_CRT2IsLCD(SiS_Pr)) ||
  6466. (SiS_IsVAMode(SiS_Pr))) {
  6467. if(SiS_Pr->SiS_LCDInfo & LCDDualLink) {
  6468. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x27,0x2c);
  6469. } else {
  6470. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x27,~0x20);
  6471. }
  6472. }
  6473. }
  6474. }
  6475. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  6476. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2a,0x00);
  6477. #ifdef SET_EMI
  6478. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
  6479. #endif
  6480. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x34,0x10);
  6481. }
  6482. }
  6483. static void
  6484. SiS_SetGroup4(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  6485. unsigned short RefreshRateTableIndex)
  6486. {
  6487. unsigned short tempax, tempcx, tempbx, modeflag, temp, resinfo;
  6488. unsigned int tempebx, tempeax, templong;
  6489. if(ModeNo <= 0x13) {
  6490. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  6491. resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
  6492. } else if(SiS_Pr->UseCustomMode) {
  6493. modeflag = SiS_Pr->CModeFlag;
  6494. resinfo = 0;
  6495. } else {
  6496. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  6497. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  6498. }
  6499. if(SiS_Pr->ChipType >= SIS_315H) {
  6500. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  6501. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  6502. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x24,0x0e);
  6503. }
  6504. }
  6505. }
  6506. if(SiS_Pr->SiS_VBType & (VB_SIS30xCLV | VB_SIS302LV)) {
  6507. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  6508. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x10,0x9f);
  6509. }
  6510. }
  6511. if(SiS_Pr->ChipType >= SIS_315H) {
  6512. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  6513. SiS_SetDualLinkEtc(SiS_Pr);
  6514. return;
  6515. }
  6516. }
  6517. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x13,SiS_Pr->SiS_RVBHCFACT);
  6518. tempbx = SiS_Pr->SiS_RVBHCMAX;
  6519. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x14,tempbx);
  6520. temp = (tempbx >> 1) & 0x80;
  6521. tempcx = SiS_Pr->SiS_VGAHT - 1;
  6522. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x16,tempcx);
  6523. temp |= ((tempcx >> 5) & 0x78);
  6524. tempcx = SiS_Pr->SiS_VGAVT - 1;
  6525. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) tempcx -= 5;
  6526. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x17,tempcx);
  6527. temp |= ((tempcx >> 8) & 0x07);
  6528. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x15,temp);
  6529. tempbx = SiS_Pr->SiS_VGAHDE;
  6530. if(modeflag & HalfDCLK) tempbx >>= 1;
  6531. if(SiS_IsDualLink(SiS_Pr)) tempbx >>= 1;
  6532. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  6533. temp = 0;
  6534. if(tempbx > 800) temp = 0x60;
  6535. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  6536. temp = 0;
  6537. if(tempbx > 1024) temp = 0xC0;
  6538. else if(tempbx >= 960) temp = 0xA0;
  6539. } else if(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p)) {
  6540. temp = 0;
  6541. if(tempbx >= 1280) temp = 0x40;
  6542. else if(tempbx >= 1024) temp = 0x20;
  6543. } else {
  6544. temp = 0x80;
  6545. if(tempbx >= 1024) temp = 0xA0;
  6546. }
  6547. temp |= SiS_Pr->Init_P4_0E;
  6548. if(SiS_Pr->SiS_VBType & VB_SIS301) {
  6549. if(SiS_Pr->SiS_LCDResInfo != Panel_1280x1024) {
  6550. temp &= 0xf0;
  6551. temp |= 0x0A;
  6552. }
  6553. }
  6554. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x0E,0x10,temp);
  6555. tempeax = SiS_Pr->SiS_VGAVDE;
  6556. tempebx = SiS_Pr->SiS_VDE;
  6557. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  6558. if(!(temp & 0xE0)) tempebx >>=1;
  6559. }
  6560. tempcx = SiS_Pr->SiS_RVBHRS;
  6561. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x18,tempcx);
  6562. tempcx >>= 8;
  6563. tempcx |= 0x40;
  6564. if(tempeax <= tempebx) {
  6565. tempcx ^= 0x40;
  6566. } else {
  6567. tempeax -= tempebx;
  6568. }
  6569. tempeax *= (256 * 1024);
  6570. templong = tempeax % tempebx;
  6571. tempeax /= tempebx;
  6572. if(templong) tempeax++;
  6573. temp = (unsigned short)(tempeax & 0x000000FF);
  6574. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1B,temp);
  6575. temp = (unsigned short)((tempeax & 0x0000FF00) >> 8);
  6576. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1A,temp);
  6577. temp = (unsigned short)((tempeax >> 12) & 0x70); /* sic! */
  6578. temp |= (tempcx & 0x4F);
  6579. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x19,temp);
  6580. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  6581. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1C,0x28);
  6582. /* Calc Linebuffer max address and set/clear decimode */
  6583. tempbx = 0;
  6584. if(SiS_Pr->SiS_TVMode & (TVSetHiVision | TVSetYPbPr750p)) tempbx = 0x08;
  6585. tempax = SiS_Pr->SiS_VGAHDE;
  6586. if(modeflag & HalfDCLK) tempax >>= 1;
  6587. if(SiS_IsDualLink(SiS_Pr)) tempax >>= 1;
  6588. if(tempax > 800) {
  6589. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  6590. tempax -= 800;
  6591. } else {
  6592. tempbx = 0x08;
  6593. if(tempax == 960) tempax *= 25; /* Correct */
  6594. else if(tempax == 1024) tempax *= 25;
  6595. else tempax *= 20;
  6596. temp = tempax % 32;
  6597. tempax /= 32;
  6598. if(temp) tempax++;
  6599. tempax++;
  6600. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  6601. if(resinfo == SIS_RI_1024x768 ||
  6602. resinfo == SIS_RI_1024x576 ||
  6603. resinfo == SIS_RI_1280x1024 ||
  6604. resinfo == SIS_RI_1280x720) {
  6605. /* Otherwise white line or garbage at right edge */
  6606. tempax = (tempax & 0xff00) | 0x20;
  6607. }
  6608. }
  6609. }
  6610. }
  6611. tempax--;
  6612. temp = ((tempax >> 4) & 0x30) | tempbx;
  6613. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1D,tempax);
  6614. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1E,temp);
  6615. temp = 0x0036; tempbx = 0xD0;
  6616. if((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->SiS_VBType & VB_SISLVDS)) {
  6617. temp = 0x0026; tempbx = 0xC0; /* See En/DisableBridge() */
  6618. }
  6619. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  6620. if(!(SiS_Pr->SiS_TVMode & (TVSetNTSC1024 | TVSetHiVision | TVSetYPbPr750p | TVSetYPbPr525p))) {
  6621. temp |= 0x01;
  6622. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  6623. if(!(SiS_Pr->SiS_TVMode & TVSetTVSimuMode)) {
  6624. temp &= ~0x01;
  6625. }
  6626. }
  6627. }
  6628. }
  6629. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x1F,tempbx,temp);
  6630. tempbx = SiS_Pr->SiS_HT >> 1;
  6631. if(SiS_IsDualLink(SiS_Pr)) tempbx >>= 1;
  6632. tempbx -= 2;
  6633. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x22,tempbx);
  6634. temp = (tempbx >> 5) & 0x38;
  6635. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x21,0xC0,temp);
  6636. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  6637. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  6638. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x24,0x0e);
  6639. /* LCD-too-dark-error-source, see FinalizeLCD() */
  6640. }
  6641. }
  6642. SiS_SetDualLinkEtc(SiS_Pr);
  6643. } /* 301B */
  6644. SiS_SetCRT2VCLK(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  6645. }
  6646. /*********************************************/
  6647. /* SET PART 5 REGISTER GROUP */
  6648. /*********************************************/
  6649. static void
  6650. SiS_SetGroup5(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  6651. {
  6652. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) return;
  6653. if(SiS_Pr->SiS_ModeType == ModeVGA) {
  6654. if(!(SiS_Pr->SiS_VBInfo & (SetInSlaveMode | LoadDACFlag))) {
  6655. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);
  6656. SiS_LoadDAC(SiS_Pr, ModeNo, ModeIdIndex);
  6657. }
  6658. }
  6659. }
  6660. /*********************************************/
  6661. /* MODIFY CRT1 GROUP FOR SLAVE MODE */
  6662. /*********************************************/
  6663. static bool
  6664. SiS_GetLVDSCRT1Ptr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  6665. unsigned short RefreshRateTableIndex, unsigned short *ResIndex,
  6666. unsigned short *DisplayType)
  6667. {
  6668. unsigned short modeflag = 0;
  6669. bool checkhd = true;
  6670. /* Pass 1:1 not supported here */
  6671. if(ModeNo <= 0x13) {
  6672. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  6673. (*ResIndex) = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  6674. } else {
  6675. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  6676. (*ResIndex) = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  6677. }
  6678. (*ResIndex) &= 0x3F;
  6679. if((SiS_Pr->SiS_IF_DEF_CH70xx) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
  6680. (*DisplayType) = 80;
  6681. if((SiS_Pr->SiS_TVMode & TVSetPAL) && (!(SiS_Pr->SiS_TVMode & TVSetPALM))) {
  6682. (*DisplayType) = 82;
  6683. if(SiS_Pr->SiS_ModeType > ModeVGA) {
  6684. if(SiS_Pr->SiS_CHSOverScan) (*DisplayType) = 84;
  6685. }
  6686. }
  6687. if((*DisplayType) != 84) {
  6688. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) (*DisplayType)++;
  6689. }
  6690. } else {
  6691. (*DisplayType = 0);
  6692. switch(SiS_Pr->SiS_LCDResInfo) {
  6693. case Panel_320x240_1: (*DisplayType) = 50;
  6694. checkhd = false;
  6695. break;
  6696. case Panel_320x240_2: (*DisplayType) = 14;
  6697. break;
  6698. case Panel_320x240_3: (*DisplayType) = 18;
  6699. break;
  6700. case Panel_640x480: (*DisplayType) = 10;
  6701. break;
  6702. case Panel_1024x600: (*DisplayType) = 26;
  6703. break;
  6704. default: return true;
  6705. }
  6706. if(checkhd) {
  6707. if(modeflag & HalfDCLK) (*DisplayType)++;
  6708. }
  6709. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x600) {
  6710. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) (*DisplayType) += 2;
  6711. }
  6712. }
  6713. return true;
  6714. }
  6715. static void
  6716. SiS_ModCRT1CRTC(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  6717. unsigned short RefreshRateTableIndex)
  6718. {
  6719. unsigned short tempah, i, modeflag, j, ResIndex, DisplayType;
  6720. const struct SiS_LVDSCRT1Data *LVDSCRT1Ptr=NULL;
  6721. static const unsigned short CRIdx[] = {
  6722. 0x00, 0x02, 0x03, 0x04, 0x05, 0x06,
  6723. 0x07, 0x10, 0x11, 0x15, 0x16
  6724. };
  6725. if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) ||
  6726. (SiS_Pr->SiS_CustomT == CUT_BARCO1024) ||
  6727. (SiS_Pr->SiS_CustomT == CUT_PANEL848) ||
  6728. (SiS_Pr->SiS_CustomT == CUT_PANEL856) )
  6729. return;
  6730. if(SiS_Pr->SiS_IF_DEF_LVDS) {
  6731. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  6732. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) return;
  6733. }
  6734. } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
  6735. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) return;
  6736. } else return;
  6737. if(SiS_Pr->SiS_LCDInfo & LCDPass11) return;
  6738. if(SiS_Pr->ChipType < SIS_315H) {
  6739. if(SiS_Pr->SiS_SetFlag & SetDOSMode) return;
  6740. }
  6741. if(!(SiS_GetLVDSCRT1Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex,
  6742. &ResIndex, &DisplayType))) {
  6743. return;
  6744. }
  6745. switch(DisplayType) {
  6746. case 50: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1320x240_1; break; /* xSTN */
  6747. case 14: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1320x240_2; break; /* xSTN */
  6748. case 15: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1320x240_2_H; break; /* xSTN */
  6749. case 18: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1320x240_3; break; /* xSTN */
  6750. case 19: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1320x240_3_H; break; /* xSTN */
  6751. case 10: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1640x480_1; break;
  6752. case 11: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1640x480_1_H; break;
  6753. #if 0 /* Works better with calculated numbers */
  6754. case 26: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x600_1; break;
  6755. case 27: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x600_1_H; break;
  6756. case 28: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x600_2; break;
  6757. case 29: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x600_2_H; break;
  6758. #endif
  6759. case 80: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1UNTSC; break;
  6760. case 81: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1ONTSC; break;
  6761. case 82: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1UPAL; break;
  6762. case 83: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1OPAL; break;
  6763. case 84: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1SOPAL; break;
  6764. }
  6765. if(LVDSCRT1Ptr) {
  6766. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x11,0x7f);
  6767. for(i = 0; i <= 10; i++) {
  6768. tempah = (LVDSCRT1Ptr + ResIndex)->CR[i];
  6769. SiS_SetReg(SiS_Pr->SiS_P3d4,CRIdx[i],tempah);
  6770. }
  6771. for(i = 0x0A, j = 11; i <= 0x0C; i++, j++) {
  6772. tempah = (LVDSCRT1Ptr + ResIndex)->CR[j];
  6773. SiS_SetReg(SiS_Pr->SiS_P3c4,i,tempah);
  6774. }
  6775. tempah = (LVDSCRT1Ptr + ResIndex)->CR[14] & 0xE0;
  6776. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0E,0x1f,tempah);
  6777. if(ModeNo <= 0x13) modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  6778. else modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  6779. tempah = ((LVDSCRT1Ptr + ResIndex)->CR[14] & 0x01) << 5;
  6780. if(modeflag & DoubleScanMode) tempah |= 0x80;
  6781. SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x09,~0x020,tempah);
  6782. } else {
  6783. SiS_CalcLCDACRT1Timing(SiS_Pr, ModeNo, ModeIdIndex);
  6784. }
  6785. }
  6786. /*********************************************/
  6787. /* SET CRT2 ECLK */
  6788. /*********************************************/
  6789. static void
  6790. SiS_SetCRT2ECLK(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  6791. unsigned short RefreshRateTableIndex)
  6792. {
  6793. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  6794. unsigned short clkbase, vclkindex = 0;
  6795. unsigned char sr2b, sr2c;
  6796. if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
  6797. SiS_Pr->SiS_SetFlag &= (~ProgrammingCRT2);
  6798. if(SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK == 2) {
  6799. RefreshRateTableIndex--;
  6800. }
  6801. vclkindex = SiS_GetVCLK2Ptr(SiS_Pr, ModeNo, ModeIdIndex,
  6802. RefreshRateTableIndex);
  6803. SiS_Pr->SiS_SetFlag |= ProgrammingCRT2;
  6804. } else {
  6805. vclkindex = SiS_GetVCLK2Ptr(SiS_Pr, ModeNo, ModeIdIndex,
  6806. RefreshRateTableIndex);
  6807. }
  6808. sr2b = SiS_Pr->SiS_VCLKData[vclkindex].SR2B;
  6809. sr2c = SiS_Pr->SiS_VCLKData[vclkindex].SR2C;
  6810. if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) || (SiS_Pr->SiS_CustomT == CUT_BARCO1024)) {
  6811. if(SiS_Pr->SiS_UseROM) {
  6812. if(ROMAddr[0x220] & 0x01) {
  6813. sr2b = ROMAddr[0x227];
  6814. sr2c = ROMAddr[0x228];
  6815. }
  6816. }
  6817. }
  6818. clkbase = 0x02B;
  6819. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  6820. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  6821. clkbase += 3;
  6822. }
  6823. }
  6824. SiS_SetReg(SiS_Pr->SiS_P3c4,0x31,0x20);
  6825. SiS_SetReg(SiS_Pr->SiS_P3c4,clkbase,sr2b);
  6826. SiS_SetReg(SiS_Pr->SiS_P3c4,clkbase+1,sr2c);
  6827. SiS_SetReg(SiS_Pr->SiS_P3c4,0x31,0x10);
  6828. SiS_SetReg(SiS_Pr->SiS_P3c4,clkbase,sr2b);
  6829. SiS_SetReg(SiS_Pr->SiS_P3c4,clkbase+1,sr2c);
  6830. SiS_SetReg(SiS_Pr->SiS_P3c4,0x31,0x00);
  6831. SiS_SetReg(SiS_Pr->SiS_P3c4,clkbase,sr2b);
  6832. SiS_SetReg(SiS_Pr->SiS_P3c4,clkbase+1,sr2c);
  6833. }
  6834. /*********************************************/
  6835. /* SET UP CHRONTEL CHIPS */
  6836. /*********************************************/
  6837. static void
  6838. SiS_SetCHTVReg(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  6839. unsigned short RefreshRateTableIndex)
  6840. {
  6841. unsigned short TVType, resindex;
  6842. const struct SiS_CHTVRegData *CHTVRegData = NULL;
  6843. if(ModeNo <= 0x13)
  6844. resindex = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  6845. else
  6846. resindex = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  6847. resindex &= 0x3F;
  6848. TVType = 0;
  6849. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) TVType += 1;
  6850. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  6851. TVType += 2;
  6852. if(SiS_Pr->SiS_ModeType > ModeVGA) {
  6853. if(SiS_Pr->SiS_CHSOverScan) TVType = 8;
  6854. }
  6855. if(SiS_Pr->SiS_TVMode & TVSetPALM) {
  6856. TVType = 4;
  6857. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) TVType += 1;
  6858. } else if(SiS_Pr->SiS_TVMode & TVSetPALN) {
  6859. TVType = 6;
  6860. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) TVType += 1;
  6861. }
  6862. }
  6863. switch(TVType) {
  6864. case 0: CHTVRegData = SiS_Pr->SiS_CHTVReg_UNTSC; break;
  6865. case 1: CHTVRegData = SiS_Pr->SiS_CHTVReg_ONTSC; break;
  6866. case 2: CHTVRegData = SiS_Pr->SiS_CHTVReg_UPAL; break;
  6867. case 3: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPAL; break;
  6868. case 4: CHTVRegData = SiS_Pr->SiS_CHTVReg_UPALM; break;
  6869. case 5: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPALM; break;
  6870. case 6: CHTVRegData = SiS_Pr->SiS_CHTVReg_UPALN; break;
  6871. case 7: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPALN; break;
  6872. case 8: CHTVRegData = SiS_Pr->SiS_CHTVReg_SOPAL; break;
  6873. default: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPAL; break;
  6874. }
  6875. if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) {
  6876. #ifdef SIS300
  6877. /* Chrontel 7005 - I assume that it does not come with a 315 series chip */
  6878. /* We don't support modes >800x600 */
  6879. if (resindex > 5) return;
  6880. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  6881. SiS_SetCH700x(SiS_Pr,0x04,0x43); /* 0x40=76uA (PAL); 0x03=15bit non-multi RGB*/
  6882. SiS_SetCH700x(SiS_Pr,0x09,0x69); /* Black level for PAL (105)*/
  6883. } else {
  6884. SiS_SetCH700x(SiS_Pr,0x04,0x03); /* upper nibble=71uA (NTSC), 0x03=15bit non-multi RGB*/
  6885. SiS_SetCH700x(SiS_Pr,0x09,0x71); /* Black level for NTSC (113)*/
  6886. }
  6887. SiS_SetCH700x(SiS_Pr,0x00,CHTVRegData[resindex].Reg[0]); /* Mode register */
  6888. SiS_SetCH700x(SiS_Pr,0x07,CHTVRegData[resindex].Reg[1]); /* Start active video register */
  6889. SiS_SetCH700x(SiS_Pr,0x08,CHTVRegData[resindex].Reg[2]); /* Position overflow register */
  6890. SiS_SetCH700x(SiS_Pr,0x0a,CHTVRegData[resindex].Reg[3]); /* Horiz Position register */
  6891. SiS_SetCH700x(SiS_Pr,0x0b,CHTVRegData[resindex].Reg[4]); /* Vertical Position register */
  6892. /* Set minimum flicker filter for Luma channel (SR1-0=00),
  6893. minimum text enhancement (S3-2=10),
  6894. maximum flicker filter for Chroma channel (S5-4=10)
  6895. =00101000=0x28 (When reading, S1-0->S3-2, and S3-2->S1-0!)
  6896. */
  6897. SiS_SetCH700x(SiS_Pr,0x01,0x28);
  6898. /* Set video bandwidth
  6899. High bandwidth Luma composite video filter(S0=1)
  6900. low bandwidth Luma S-video filter (S2-1=00)
  6901. disable peak filter in S-video channel (S3=0)
  6902. high bandwidth Chroma Filter (S5-4=11)
  6903. =00110001=0x31
  6904. */
  6905. SiS_SetCH700x(SiS_Pr,0x03,0xb1); /* old: 3103 */
  6906. /* Register 0x3D does not exist in non-macrovision register map
  6907. (Maybe this is a macrovision register?)
  6908. */
  6909. #ifndef SIS_CP
  6910. SiS_SetCH70xx(SiS_Pr,0x3d,0x00);
  6911. #endif
  6912. /* Register 0x10 only contains 1 writable bit (S0) for sensing,
  6913. all other bits a read-only. Macrovision?
  6914. */
  6915. SiS_SetCH70xxANDOR(SiS_Pr,0x10,0x00,0x1F);
  6916. /* Register 0x11 only contains 3 writable bits (S0-S2) for
  6917. contrast enhancement (set to 010 -> gain 1 Yout = 17/16*(Yin-30) )
  6918. */
  6919. SiS_SetCH70xxANDOR(SiS_Pr,0x11,0x02,0xF8);
  6920. /* Clear DSEN
  6921. */
  6922. SiS_SetCH70xxANDOR(SiS_Pr,0x1c,0x00,0xEF);
  6923. if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) { /* ---- NTSC ---- */
  6924. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) {
  6925. if(resindex == 0x04) { /* 640x480 overscan: Mode 16 */
  6926. SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x00,0xEF); /* loop filter off */
  6927. SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x01,0xFE); /* ACIV on, no need to set FSCI */
  6928. } else if(resindex == 0x05) { /* 800x600 overscan: Mode 23 */
  6929. SiS_SetCH70xxANDOR(SiS_Pr,0x18,0x01,0xF0); /* 0x18-0x1f: FSCI 469,762,048 */
  6930. SiS_SetCH70xxANDOR(SiS_Pr,0x19,0x0C,0xF0);
  6931. SiS_SetCH70xxANDOR(SiS_Pr,0x1a,0x00,0xF0);
  6932. SiS_SetCH70xxANDOR(SiS_Pr,0x1b,0x00,0xF0);
  6933. SiS_SetCH70xxANDOR(SiS_Pr,0x1c,0x00,0xF0);
  6934. SiS_SetCH70xxANDOR(SiS_Pr,0x1d,0x00,0xF0);
  6935. SiS_SetCH70xxANDOR(SiS_Pr,0x1e,0x00,0xF0);
  6936. SiS_SetCH70xxANDOR(SiS_Pr,0x1f,0x00,0xF0);
  6937. SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x01,0xEF); /* Loop filter on for mode 23 */
  6938. SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x00,0xFE); /* ACIV off, need to set FSCI */
  6939. }
  6940. } else {
  6941. if(resindex == 0x04) { /* ----- 640x480 underscan; Mode 17 */
  6942. SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x00,0xEF); /* loop filter off */
  6943. SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x01,0xFE);
  6944. } else if(resindex == 0x05) { /* ----- 800x600 underscan: Mode 24 */
  6945. #if 0
  6946. SiS_SetCH70xxANDOR(SiS_Pr,0x18,0x01,0xF0); /* (FSCI was 0x1f1c71c7 - this is for mode 22) */
  6947. SiS_SetCH70xxANDOR(SiS_Pr,0x19,0x09,0xF0); /* FSCI for mode 24 is 428,554,851 */
  6948. SiS_SetCH70xxANDOR(SiS_Pr,0x1a,0x08,0xF0); /* 198b3a63 */
  6949. SiS_SetCH70xxANDOR(SiS_Pr,0x1b,0x0b,0xF0);
  6950. SiS_SetCH70xxANDOR(SiS_Pr,0x1c,0x04,0xF0);
  6951. SiS_SetCH70xxANDOR(SiS_Pr,0x1d,0x01,0xF0);
  6952. SiS_SetCH70xxANDOR(SiS_Pr,0x1e,0x06,0xF0);
  6953. SiS_SetCH70xxANDOR(SiS_Pr,0x1f,0x05,0xF0);
  6954. SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x00,0xEF); /* loop filter off for mode 24 */
  6955. SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x00,0xFE); * ACIV off, need to set FSCI */
  6956. #endif /* All alternatives wrong (datasheet wrong?), don't use FSCI */
  6957. SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x00,0xEF); /* loop filter off */
  6958. SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x01,0xFE);
  6959. }
  6960. }
  6961. } else { /* ---- PAL ---- */
  6962. /* We don't play around with FSCI in PAL mode */
  6963. if(resindex == 0x04) {
  6964. SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x00,0xEF); /* loop filter off */
  6965. SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x01,0xFE); /* ACIV on */
  6966. } else {
  6967. SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x00,0xEF); /* loop filter off */
  6968. SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x01,0xFE); /* ACIV on */
  6969. }
  6970. }
  6971. #endif /* 300 */
  6972. } else {
  6973. /* Chrontel 7019 - assumed that it does not come with a 300 series chip */
  6974. #ifdef SIS315H
  6975. unsigned short temp;
  6976. /* We don't support modes >1024x768 */
  6977. if (resindex > 6) return;
  6978. temp = CHTVRegData[resindex].Reg[0];
  6979. if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) temp |= 0x10;
  6980. SiS_SetCH701x(SiS_Pr,0x00,temp);
  6981. SiS_SetCH701x(SiS_Pr,0x01,CHTVRegData[resindex].Reg[1]);
  6982. SiS_SetCH701x(SiS_Pr,0x02,CHTVRegData[resindex].Reg[2]);
  6983. SiS_SetCH701x(SiS_Pr,0x04,CHTVRegData[resindex].Reg[3]);
  6984. SiS_SetCH701x(SiS_Pr,0x03,CHTVRegData[resindex].Reg[4]);
  6985. SiS_SetCH701x(SiS_Pr,0x05,CHTVRegData[resindex].Reg[5]);
  6986. SiS_SetCH701x(SiS_Pr,0x06,CHTVRegData[resindex].Reg[6]);
  6987. temp = CHTVRegData[resindex].Reg[7];
  6988. if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) temp = 0x66;
  6989. SiS_SetCH701x(SiS_Pr,0x07,temp);
  6990. SiS_SetCH701x(SiS_Pr,0x08,CHTVRegData[resindex].Reg[8]);
  6991. SiS_SetCH701x(SiS_Pr,0x15,CHTVRegData[resindex].Reg[9]);
  6992. SiS_SetCH701x(SiS_Pr,0x1f,CHTVRegData[resindex].Reg[10]);
  6993. SiS_SetCH701x(SiS_Pr,0x0c,CHTVRegData[resindex].Reg[11]);
  6994. SiS_SetCH701x(SiS_Pr,0x0d,CHTVRegData[resindex].Reg[12]);
  6995. SiS_SetCH701x(SiS_Pr,0x0e,CHTVRegData[resindex].Reg[13]);
  6996. SiS_SetCH701x(SiS_Pr,0x0f,CHTVRegData[resindex].Reg[14]);
  6997. SiS_SetCH701x(SiS_Pr,0x10,CHTVRegData[resindex].Reg[15]);
  6998. temp = SiS_GetCH701x(SiS_Pr,0x21) & ~0x02;
  6999. /* D1 should be set for PAL, PAL-N and NTSC-J,
  7000. but I won't do that for PAL unless somebody
  7001. tells me to do so. Since the BIOS uses
  7002. non-default CIV values and blacklevels,
  7003. this might be compensated anyway.
  7004. */
  7005. if(SiS_Pr->SiS_TVMode & (TVSetPALN | TVSetNTSCJ)) temp |= 0x02;
  7006. SiS_SetCH701x(SiS_Pr,0x21,temp);
  7007. #endif /* 315 */
  7008. }
  7009. #ifdef SIS_CP
  7010. SIS_CP_INIT301_CP3
  7011. #endif
  7012. }
  7013. #ifdef SIS315H /* ----------- 315 series only ---------- */
  7014. void
  7015. SiS_Chrontel701xBLOn(struct SiS_Private *SiS_Pr)
  7016. {
  7017. unsigned short temp;
  7018. /* Enable Chrontel 7019 LCD panel backlight */
  7019. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  7020. if(SiS_Pr->ChipType == SIS_740) {
  7021. SiS_SetCH701x(SiS_Pr,0x66,0x65);
  7022. } else {
  7023. temp = SiS_GetCH701x(SiS_Pr,0x66);
  7024. temp |= 0x20;
  7025. SiS_SetCH701x(SiS_Pr,0x66,temp);
  7026. }
  7027. }
  7028. }
  7029. void
  7030. SiS_Chrontel701xBLOff(struct SiS_Private *SiS_Pr)
  7031. {
  7032. unsigned short temp;
  7033. /* Disable Chrontel 7019 LCD panel backlight */
  7034. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  7035. temp = SiS_GetCH701x(SiS_Pr,0x66);
  7036. temp &= 0xDF;
  7037. SiS_SetCH701x(SiS_Pr,0x66,temp);
  7038. }
  7039. }
  7040. static void
  7041. SiS_ChrontelPowerSequencing(struct SiS_Private *SiS_Pr)
  7042. {
  7043. static const unsigned char regtable[] = { 0x67, 0x68, 0x69, 0x6a, 0x6b };
  7044. static const unsigned char table1024_740[] = { 0x01, 0x02, 0x01, 0x01, 0x01 };
  7045. static const unsigned char table1400_740[] = { 0x01, 0x6e, 0x01, 0x01, 0x01 };
  7046. static const unsigned char asus1024_740[] = { 0x19, 0x6e, 0x01, 0x19, 0x09 };
  7047. static const unsigned char asus1400_740[] = { 0x19, 0x6e, 0x01, 0x19, 0x09 };
  7048. static const unsigned char table1024_650[] = { 0x01, 0x02, 0x01, 0x01, 0x02 };
  7049. static const unsigned char table1400_650[] = { 0x01, 0x02, 0x01, 0x01, 0x02 };
  7050. const unsigned char *tableptr = NULL;
  7051. int i;
  7052. /* Set up Power up/down timing */
  7053. if(SiS_Pr->ChipType == SIS_740) {
  7054. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  7055. if(SiS_Pr->SiS_CustomT == CUT_ASUSL3000D) tableptr = asus1024_740;
  7056. else tableptr = table1024_740;
  7057. } else if((SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) ||
  7058. (SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) ||
  7059. (SiS_Pr->SiS_LCDResInfo == Panel_1600x1200)) {
  7060. if(SiS_Pr->SiS_CustomT == CUT_ASUSL3000D) tableptr = asus1400_740;
  7061. else tableptr = table1400_740;
  7062. } else return;
  7063. } else {
  7064. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  7065. tableptr = table1024_650;
  7066. } else if((SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) ||
  7067. (SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) ||
  7068. (SiS_Pr->SiS_LCDResInfo == Panel_1600x1200)) {
  7069. tableptr = table1400_650;
  7070. } else return;
  7071. }
  7072. for(i=0; i<5; i++) {
  7073. SiS_SetCH701x(SiS_Pr, regtable[i], tableptr[i]);
  7074. }
  7075. }
  7076. static void
  7077. SiS_SetCH701xForLCD(struct SiS_Private *SiS_Pr)
  7078. {
  7079. const unsigned char *tableptr = NULL;
  7080. unsigned short tempbh;
  7081. int i;
  7082. static const unsigned char regtable[] = {
  7083. 0x1c, 0x5f, 0x64, 0x6f, 0x70, 0x71,
  7084. 0x72, 0x73, 0x74, 0x76, 0x78, 0x7d, 0x66
  7085. };
  7086. static const unsigned char table1024_740[] = {
  7087. 0x60, 0x02, 0x00, 0x07, 0x40, 0xed,
  7088. 0xa3, 0xc8, 0xc7, 0xac, 0xe0, 0x02, 0x44
  7089. };
  7090. static const unsigned char table1280_740[] = {
  7091. 0x60, 0x03, 0x11, 0x00, 0x40, 0xe3,
  7092. 0xad, 0xdb, 0xf6, 0xac, 0xe0, 0x02, 0x44
  7093. };
  7094. static const unsigned char table1400_740[] = {
  7095. 0x60, 0x03, 0x11, 0x00, 0x40, 0xe3,
  7096. 0xad, 0xdb, 0xf6, 0xac, 0xe0, 0x02, 0x44
  7097. };
  7098. static const unsigned char table1600_740[] = {
  7099. 0x60, 0x04, 0x11, 0x00, 0x40, 0xe3,
  7100. 0xad, 0xde, 0xf6, 0xac, 0x60, 0x1a, 0x44
  7101. };
  7102. static const unsigned char table1024_650[] = {
  7103. 0x60, 0x02, 0x00, 0x07, 0x40, 0xed,
  7104. 0xa3, 0xc8, 0xc7, 0xac, 0x60, 0x02
  7105. };
  7106. static const unsigned char table1280_650[] = {
  7107. 0x60, 0x03, 0x11, 0x00, 0x40, 0xe3,
  7108. 0xad, 0xdb, 0xf6, 0xac, 0xe0, 0x02
  7109. };
  7110. static const unsigned char table1400_650[] = {
  7111. 0x60, 0x03, 0x11, 0x00, 0x40, 0xef,
  7112. 0xad, 0xdb, 0xf6, 0xac, 0x60, 0x02
  7113. };
  7114. static const unsigned char table1600_650[] = {
  7115. 0x60, 0x04, 0x11, 0x00, 0x40, 0xe3,
  7116. 0xad, 0xde, 0xf6, 0xac, 0x60, 0x1a
  7117. };
  7118. if(SiS_Pr->ChipType == SIS_740) {
  7119. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) tableptr = table1024_740;
  7120. else if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) tableptr = table1280_740;
  7121. else if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) tableptr = table1400_740;
  7122. else if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) tableptr = table1600_740;
  7123. else return;
  7124. } else {
  7125. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) tableptr = table1024_650;
  7126. else if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) tableptr = table1280_650;
  7127. else if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) tableptr = table1400_650;
  7128. else if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) tableptr = table1600_650;
  7129. else return;
  7130. }
  7131. tempbh = SiS_GetCH701x(SiS_Pr,0x74);
  7132. if((tempbh == 0xf6) || (tempbh == 0xc7)) {
  7133. tempbh = SiS_GetCH701x(SiS_Pr,0x73);
  7134. if(tempbh == 0xc8) {
  7135. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) return;
  7136. } else if(tempbh == 0xdb) {
  7137. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) return;
  7138. if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) return;
  7139. } else if(tempbh == 0xde) {
  7140. if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) return;
  7141. }
  7142. }
  7143. if(SiS_Pr->ChipType == SIS_740) tempbh = 0x0d;
  7144. else tempbh = 0x0c;
  7145. for(i = 0; i < tempbh; i++) {
  7146. SiS_SetCH701x(SiS_Pr, regtable[i], tableptr[i]);
  7147. }
  7148. SiS_ChrontelPowerSequencing(SiS_Pr);
  7149. tempbh = SiS_GetCH701x(SiS_Pr,0x1e);
  7150. tempbh |= 0xc0;
  7151. SiS_SetCH701x(SiS_Pr,0x1e,tempbh);
  7152. if(SiS_Pr->ChipType == SIS_740) {
  7153. tempbh = SiS_GetCH701x(SiS_Pr,0x1c);
  7154. tempbh &= 0xfb;
  7155. SiS_SetCH701x(SiS_Pr,0x1c,tempbh);
  7156. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2d,0x03);
  7157. tempbh = SiS_GetCH701x(SiS_Pr,0x64);
  7158. tempbh |= 0x40;
  7159. SiS_SetCH701x(SiS_Pr,0x64,tempbh);
  7160. tempbh = SiS_GetCH701x(SiS_Pr,0x03);
  7161. tempbh &= 0x3f;
  7162. SiS_SetCH701x(SiS_Pr,0x03,tempbh);
  7163. }
  7164. }
  7165. static void
  7166. SiS_ChrontelResetVSync(struct SiS_Private *SiS_Pr)
  7167. {
  7168. unsigned char temp, temp1;
  7169. temp1 = SiS_GetCH701x(SiS_Pr,0x49);
  7170. SiS_SetCH701x(SiS_Pr,0x49,0x3e);
  7171. temp = SiS_GetCH701x(SiS_Pr,0x47);
  7172. temp &= 0x7f; /* Use external VSYNC */
  7173. SiS_SetCH701x(SiS_Pr,0x47,temp);
  7174. SiS_LongDelay(SiS_Pr, 3);
  7175. temp = SiS_GetCH701x(SiS_Pr,0x47);
  7176. temp |= 0x80; /* Use internal VSYNC */
  7177. SiS_SetCH701x(SiS_Pr,0x47,temp);
  7178. SiS_SetCH701x(SiS_Pr,0x49,temp1);
  7179. }
  7180. static void
  7181. SiS_Chrontel701xOn(struct SiS_Private *SiS_Pr)
  7182. {
  7183. unsigned short temp;
  7184. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  7185. if(SiS_Pr->ChipType == SIS_740) {
  7186. temp = SiS_GetCH701x(SiS_Pr,0x1c);
  7187. temp |= 0x04; /* Invert XCLK phase */
  7188. SiS_SetCH701x(SiS_Pr,0x1c,temp);
  7189. }
  7190. if(SiS_IsYPbPr(SiS_Pr)) {
  7191. temp = SiS_GetCH701x(SiS_Pr,0x01);
  7192. temp &= 0x3f;
  7193. temp |= 0x80; /* Enable YPrPb (HDTV) */
  7194. SiS_SetCH701x(SiS_Pr,0x01,temp);
  7195. }
  7196. if(SiS_IsChScart(SiS_Pr)) {
  7197. temp = SiS_GetCH701x(SiS_Pr,0x01);
  7198. temp &= 0x3f;
  7199. temp |= 0xc0; /* Enable SCART + CVBS */
  7200. SiS_SetCH701x(SiS_Pr,0x01,temp);
  7201. }
  7202. if(SiS_Pr->ChipType == SIS_740) {
  7203. SiS_ChrontelResetVSync(SiS_Pr);
  7204. SiS_SetCH701x(SiS_Pr,0x49,0x20); /* Enable TV path */
  7205. } else {
  7206. SiS_SetCH701x(SiS_Pr,0x49,0x20); /* Enable TV path */
  7207. temp = SiS_GetCH701x(SiS_Pr,0x49);
  7208. if(SiS_IsYPbPr(SiS_Pr)) {
  7209. temp = SiS_GetCH701x(SiS_Pr,0x73);
  7210. temp |= 0x60;
  7211. SiS_SetCH701x(SiS_Pr,0x73,temp);
  7212. }
  7213. temp = SiS_GetCH701x(SiS_Pr,0x47);
  7214. temp &= 0x7f;
  7215. SiS_SetCH701x(SiS_Pr,0x47,temp);
  7216. SiS_LongDelay(SiS_Pr, 2);
  7217. temp = SiS_GetCH701x(SiS_Pr,0x47);
  7218. temp |= 0x80;
  7219. SiS_SetCH701x(SiS_Pr,0x47,temp);
  7220. }
  7221. }
  7222. }
  7223. static void
  7224. SiS_Chrontel701xOff(struct SiS_Private *SiS_Pr)
  7225. {
  7226. unsigned short temp;
  7227. /* Complete power down of LVDS */
  7228. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  7229. if(SiS_Pr->ChipType == SIS_740) {
  7230. SiS_LongDelay(SiS_Pr, 1);
  7231. SiS_GenericDelay(SiS_Pr, 5887);
  7232. SiS_SetCH701x(SiS_Pr,0x76,0xac);
  7233. SiS_SetCH701x(SiS_Pr,0x66,0x00);
  7234. } else {
  7235. SiS_LongDelay(SiS_Pr, 2);
  7236. temp = SiS_GetCH701x(SiS_Pr,0x76);
  7237. temp &= 0xfc;
  7238. SiS_SetCH701x(SiS_Pr,0x76,temp);
  7239. SiS_SetCH701x(SiS_Pr,0x66,0x00);
  7240. }
  7241. }
  7242. }
  7243. static void
  7244. SiS_ChrontelResetDB(struct SiS_Private *SiS_Pr)
  7245. {
  7246. unsigned short temp;
  7247. if(SiS_Pr->ChipType == SIS_740) {
  7248. temp = SiS_GetCH701x(SiS_Pr,0x4a); /* Version ID */
  7249. temp &= 0x01;
  7250. if(!temp) {
  7251. if(SiS_WeHaveBacklightCtrl(SiS_Pr)) {
  7252. temp = SiS_GetCH701x(SiS_Pr,0x49);
  7253. SiS_SetCH701x(SiS_Pr,0x49,0x3e);
  7254. }
  7255. /* Reset Chrontel 7019 datapath */
  7256. SiS_SetCH701x(SiS_Pr,0x48,0x10);
  7257. SiS_LongDelay(SiS_Pr, 1);
  7258. SiS_SetCH701x(SiS_Pr,0x48,0x18);
  7259. if(SiS_WeHaveBacklightCtrl(SiS_Pr)) {
  7260. SiS_ChrontelResetVSync(SiS_Pr);
  7261. SiS_SetCH701x(SiS_Pr,0x49,temp);
  7262. }
  7263. } else {
  7264. /* Clear/set/clear GPIO */
  7265. temp = SiS_GetCH701x(SiS_Pr,0x5c);
  7266. temp &= 0xef;
  7267. SiS_SetCH701x(SiS_Pr,0x5c,temp);
  7268. temp = SiS_GetCH701x(SiS_Pr,0x5c);
  7269. temp |= 0x10;
  7270. SiS_SetCH701x(SiS_Pr,0x5c,temp);
  7271. temp = SiS_GetCH701x(SiS_Pr,0x5c);
  7272. temp &= 0xef;
  7273. SiS_SetCH701x(SiS_Pr,0x5c,temp);
  7274. temp = SiS_GetCH701x(SiS_Pr,0x61);
  7275. if(!temp) {
  7276. SiS_SetCH701xForLCD(SiS_Pr);
  7277. }
  7278. }
  7279. } else { /* 650 */
  7280. /* Reset Chrontel 7019 datapath */
  7281. SiS_SetCH701x(SiS_Pr,0x48,0x10);
  7282. SiS_LongDelay(SiS_Pr, 1);
  7283. SiS_SetCH701x(SiS_Pr,0x48,0x18);
  7284. }
  7285. }
  7286. static void
  7287. SiS_ChrontelInitTVVSync(struct SiS_Private *SiS_Pr)
  7288. {
  7289. unsigned short temp;
  7290. if(SiS_Pr->ChipType == SIS_740) {
  7291. if(SiS_WeHaveBacklightCtrl(SiS_Pr)) {
  7292. SiS_ChrontelResetVSync(SiS_Pr);
  7293. }
  7294. } else {
  7295. SiS_SetCH701x(SiS_Pr,0x76,0xaf); /* Power up LVDS block */
  7296. temp = SiS_GetCH701x(SiS_Pr,0x49);
  7297. temp &= 1;
  7298. if(temp != 1) { /* TV block powered? (0 = yes, 1 = no) */
  7299. temp = SiS_GetCH701x(SiS_Pr,0x47);
  7300. temp &= 0x70;
  7301. SiS_SetCH701x(SiS_Pr,0x47,temp); /* enable VSYNC */
  7302. SiS_LongDelay(SiS_Pr, 3);
  7303. temp = SiS_GetCH701x(SiS_Pr,0x47);
  7304. temp |= 0x80;
  7305. SiS_SetCH701x(SiS_Pr,0x47,temp); /* disable VSYNC */
  7306. }
  7307. }
  7308. }
  7309. static void
  7310. SiS_ChrontelDoSomething3(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
  7311. {
  7312. unsigned short temp,temp1;
  7313. if(SiS_Pr->ChipType == SIS_740) {
  7314. temp = SiS_GetCH701x(SiS_Pr,0x61);
  7315. if(temp < 1) {
  7316. temp++;
  7317. SiS_SetCH701x(SiS_Pr,0x61,temp);
  7318. }
  7319. SiS_SetCH701x(SiS_Pr,0x66,0x45); /* Panel power on */
  7320. SiS_SetCH701x(SiS_Pr,0x76,0xaf); /* All power on */
  7321. SiS_LongDelay(SiS_Pr, 1);
  7322. SiS_GenericDelay(SiS_Pr, 5887);
  7323. } else { /* 650 */
  7324. temp1 = 0;
  7325. temp = SiS_GetCH701x(SiS_Pr,0x61);
  7326. if(temp < 2) {
  7327. temp++;
  7328. SiS_SetCH701x(SiS_Pr,0x61,temp);
  7329. temp1 = 1;
  7330. }
  7331. SiS_SetCH701x(SiS_Pr,0x76,0xac);
  7332. temp = SiS_GetCH701x(SiS_Pr,0x66);
  7333. temp |= 0x5f;
  7334. SiS_SetCH701x(SiS_Pr,0x66,temp);
  7335. if(ModeNo > 0x13) {
  7336. if(SiS_WeHaveBacklightCtrl(SiS_Pr)) {
  7337. SiS_GenericDelay(SiS_Pr, 1023);
  7338. } else {
  7339. SiS_GenericDelay(SiS_Pr, 767);
  7340. }
  7341. } else {
  7342. if(!temp1)
  7343. SiS_GenericDelay(SiS_Pr, 767);
  7344. }
  7345. temp = SiS_GetCH701x(SiS_Pr,0x76);
  7346. temp |= 0x03;
  7347. SiS_SetCH701x(SiS_Pr,0x76,temp);
  7348. temp = SiS_GetCH701x(SiS_Pr,0x66);
  7349. temp &= 0x7f;
  7350. SiS_SetCH701x(SiS_Pr,0x66,temp);
  7351. SiS_LongDelay(SiS_Pr, 1);
  7352. }
  7353. }
  7354. static void
  7355. SiS_ChrontelDoSomething2(struct SiS_Private *SiS_Pr)
  7356. {
  7357. unsigned short temp;
  7358. SiS_LongDelay(SiS_Pr, 1);
  7359. do {
  7360. temp = SiS_GetCH701x(SiS_Pr,0x66);
  7361. temp &= 0x04; /* PLL stable? -> bail out */
  7362. if(temp == 0x04) break;
  7363. if(SiS_Pr->ChipType == SIS_740) {
  7364. /* Power down LVDS output, PLL normal operation */
  7365. SiS_SetCH701x(SiS_Pr,0x76,0xac);
  7366. }
  7367. SiS_SetCH701xForLCD(SiS_Pr);
  7368. temp = SiS_GetCH701x(SiS_Pr,0x76);
  7369. temp &= 0xfb; /* Reset PLL */
  7370. SiS_SetCH701x(SiS_Pr,0x76,temp);
  7371. SiS_LongDelay(SiS_Pr, 2);
  7372. temp = SiS_GetCH701x(SiS_Pr,0x76);
  7373. temp |= 0x04; /* PLL normal operation */
  7374. SiS_SetCH701x(SiS_Pr,0x76,temp);
  7375. if(SiS_Pr->ChipType == SIS_740) {
  7376. SiS_SetCH701x(SiS_Pr,0x78,0xe0); /* PLL loop filter */
  7377. } else {
  7378. SiS_SetCH701x(SiS_Pr,0x78,0x60);
  7379. }
  7380. SiS_LongDelay(SiS_Pr, 2);
  7381. } while(0);
  7382. SiS_SetCH701x(SiS_Pr,0x77,0x00); /* MV? */
  7383. }
  7384. static void
  7385. SiS_ChrontelDoSomething1(struct SiS_Private *SiS_Pr)
  7386. {
  7387. unsigned short temp;
  7388. temp = SiS_GetCH701x(SiS_Pr,0x03);
  7389. temp |= 0x80; /* Set datapath 1 to TV */
  7390. temp &= 0xbf; /* Set datapath 2 to LVDS */
  7391. SiS_SetCH701x(SiS_Pr,0x03,temp);
  7392. if(SiS_Pr->ChipType == SIS_740) {
  7393. temp = SiS_GetCH701x(SiS_Pr,0x1c);
  7394. temp &= 0xfb; /* Normal XCLK phase */
  7395. SiS_SetCH701x(SiS_Pr,0x1c,temp);
  7396. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2d,0x03);
  7397. temp = SiS_GetCH701x(SiS_Pr,0x64);
  7398. temp |= 0x40; /* ? Bit not defined */
  7399. SiS_SetCH701x(SiS_Pr,0x64,temp);
  7400. temp = SiS_GetCH701x(SiS_Pr,0x03);
  7401. temp &= 0x3f; /* D1 input to both LVDS and TV */
  7402. SiS_SetCH701x(SiS_Pr,0x03,temp);
  7403. if(SiS_Pr->SiS_CustomT == CUT_ASUSL3000D) {
  7404. SiS_SetCH701x(SiS_Pr,0x63,0x40); /* LVDS off */
  7405. SiS_LongDelay(SiS_Pr, 1);
  7406. SiS_SetCH701x(SiS_Pr,0x63,0x00); /* LVDS on */
  7407. SiS_ChrontelResetDB(SiS_Pr);
  7408. SiS_ChrontelDoSomething2(SiS_Pr);
  7409. SiS_ChrontelDoSomething3(SiS_Pr, 0);
  7410. } else {
  7411. temp = SiS_GetCH701x(SiS_Pr,0x66);
  7412. if(temp != 0x45) {
  7413. SiS_ChrontelResetDB(SiS_Pr);
  7414. SiS_ChrontelDoSomething2(SiS_Pr);
  7415. SiS_ChrontelDoSomething3(SiS_Pr, 0);
  7416. }
  7417. }
  7418. } else { /* 650 */
  7419. SiS_ChrontelResetDB(SiS_Pr);
  7420. SiS_ChrontelDoSomething2(SiS_Pr);
  7421. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x34);
  7422. SiS_ChrontelDoSomething3(SiS_Pr,temp);
  7423. SiS_SetCH701x(SiS_Pr,0x76,0xaf); /* All power on, LVDS normal operation */
  7424. }
  7425. }
  7426. #endif /* 315 series */
  7427. /*********************************************/
  7428. /* MAIN: SET CRT2 REGISTER GROUP */
  7429. /*********************************************/
  7430. bool
  7431. SiS_SetCRT2Group(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
  7432. {
  7433. #ifdef SIS300
  7434. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  7435. #endif
  7436. unsigned short ModeIdIndex, RefreshRateTableIndex;
  7437. SiS_Pr->SiS_SetFlag |= ProgrammingCRT2;
  7438. if(!SiS_Pr->UseCustomMode) {
  7439. SiS_SearchModeID(SiS_Pr, &ModeNo, &ModeIdIndex);
  7440. } else {
  7441. ModeIdIndex = 0;
  7442. }
  7443. /* Used for shifting CR33 */
  7444. SiS_Pr->SiS_SelectCRT2Rate = 4;
  7445. SiS_UnLockCRT2(SiS_Pr);
  7446. RefreshRateTableIndex = SiS_GetRatePtr(SiS_Pr, ModeNo, ModeIdIndex);
  7447. SiS_SaveCRT2Info(SiS_Pr,ModeNo);
  7448. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7449. SiS_DisableBridge(SiS_Pr);
  7450. if((SiS_Pr->SiS_IF_DEF_LVDS == 1) && (SiS_Pr->ChipType == SIS_730)) {
  7451. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,0x80);
  7452. }
  7453. SiS_SetCRT2ModeRegs(SiS_Pr, ModeNo, ModeIdIndex);
  7454. }
  7455. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) {
  7456. SiS_LockCRT2(SiS_Pr);
  7457. SiS_DisplayOn(SiS_Pr);
  7458. return true;
  7459. }
  7460. SiS_GetCRT2Data(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7461. /* Set up Panel Link for LVDS and LCDA */
  7462. SiS_Pr->SiS_LCDHDES = SiS_Pr->SiS_LCDVDES = 0;
  7463. if( (SiS_Pr->SiS_IF_DEF_LVDS == 1) ||
  7464. ((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) ||
  7465. ((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->SiS_VBType & VB_SIS30xBLV)) ) {
  7466. SiS_GetLVDSDesData(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7467. }
  7468. #ifdef SIS_XORG_XF86
  7469. #ifdef TWDEBUG
  7470. xf86DrvMsg(0, X_INFO, "(init301: LCDHDES 0x%03x LCDVDES 0x%03x)\n", SiS_Pr->SiS_LCDHDES, SiS_Pr->SiS_LCDVDES);
  7471. xf86DrvMsg(0, X_INFO, "(init301: HDE 0x%03x VDE 0x%03x)\n", SiS_Pr->SiS_HDE, SiS_Pr->SiS_VDE);
  7472. xf86DrvMsg(0, X_INFO, "(init301: VGAHDE 0x%03x VGAVDE 0x%03x)\n", SiS_Pr->SiS_VGAHDE, SiS_Pr->SiS_VGAVDE);
  7473. xf86DrvMsg(0, X_INFO, "(init301: HT 0x%03x VT 0x%03x)\n", SiS_Pr->SiS_HT, SiS_Pr->SiS_VT);
  7474. xf86DrvMsg(0, X_INFO, "(init301: VGAHT 0x%03x VGAVT 0x%03x)\n", SiS_Pr->SiS_VGAHT, SiS_Pr->SiS_VGAVT);
  7475. #endif
  7476. #endif
  7477. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7478. SiS_SetGroup1(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7479. }
  7480. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  7481. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7482. SiS_SetGroup2(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7483. #ifdef SIS315H
  7484. SiS_SetGroup2_C_ELV(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7485. #endif
  7486. SiS_SetGroup3(SiS_Pr, ModeNo, ModeIdIndex);
  7487. SiS_SetGroup4(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7488. #ifdef SIS315H
  7489. SiS_SetGroup4_C_ELV(SiS_Pr, ModeNo, ModeIdIndex);
  7490. #endif
  7491. SiS_SetGroup5(SiS_Pr, ModeNo, ModeIdIndex);
  7492. SiS_SetCRT2Sync(SiS_Pr, ModeNo, RefreshRateTableIndex);
  7493. /* For 301BDH (Panel link initialization): */
  7494. if((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) {
  7495. if(!((SiS_Pr->SiS_SetFlag & SetDOSMode) && ((ModeNo == 0x03) || (ModeNo == 0x10)))) {
  7496. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  7497. SiS_ModCRT1CRTC(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7498. }
  7499. }
  7500. SiS_SetCRT2ECLK(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7501. }
  7502. }
  7503. } else {
  7504. SiS_SetCRT2Sync(SiS_Pr, ModeNo, RefreshRateTableIndex);
  7505. SiS_ModCRT1CRTC(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex);
  7506. SiS_SetCRT2ECLK(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex);
  7507. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7508. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  7509. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  7510. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  7511. #ifdef SIS315H
  7512. SiS_SetCH701xForLCD(SiS_Pr);
  7513. #endif
  7514. }
  7515. }
  7516. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  7517. SiS_SetCHTVReg(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex);
  7518. }
  7519. }
  7520. }
  7521. }
  7522. #ifdef SIS300
  7523. if(SiS_Pr->ChipType < SIS_315H) {
  7524. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7525. if(SiS_Pr->SiS_UseOEM) {
  7526. if((SiS_Pr->SiS_UseROM) && (SiS_Pr->SiS_UseOEM == -1)) {
  7527. if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) {
  7528. SiS_OEM300Setting(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7529. }
  7530. } else {
  7531. SiS_OEM300Setting(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7532. }
  7533. }
  7534. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  7535. if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) ||
  7536. (SiS_Pr->SiS_CustomT == CUT_BARCO1024)) {
  7537. SetOEMLCDData2(SiS_Pr, ModeNo, ModeIdIndex,RefreshRateTableIndex);
  7538. }
  7539. SiS_DisplayOn(SiS_Pr);
  7540. }
  7541. }
  7542. }
  7543. #endif
  7544. #ifdef SIS315H
  7545. if(SiS_Pr->ChipType >= SIS_315H) {
  7546. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7547. if(SiS_Pr->ChipType < SIS_661) {
  7548. SiS_FinalizeLCD(SiS_Pr, ModeNo, ModeIdIndex);
  7549. SiS_OEM310Setting(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7550. } else {
  7551. SiS_OEM661Setting(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7552. }
  7553. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x01,0x40);
  7554. }
  7555. }
  7556. #endif
  7557. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7558. SiS_EnableBridge(SiS_Pr);
  7559. }
  7560. SiS_DisplayOn(SiS_Pr);
  7561. if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) {
  7562. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  7563. /* Disable LCD panel when using TV */
  7564. SiS_SetRegSR11ANDOR(SiS_Pr,0xFF,0x0C);
  7565. } else {
  7566. /* Disable TV when using LCD */
  7567. SiS_SetCH70xxANDOR(SiS_Pr,0x0e,0x01,0xf8);
  7568. }
  7569. }
  7570. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7571. SiS_LockCRT2(SiS_Pr);
  7572. }
  7573. return true;
  7574. }
  7575. /*********************************************/
  7576. /* ENABLE/DISABLE LCD BACKLIGHT (SIS) */
  7577. /*********************************************/
  7578. void
  7579. SiS_SiS30xBLOn(struct SiS_Private *SiS_Pr)
  7580. {
  7581. /* Switch on LCD backlight on SiS30xLV */
  7582. SiS_DDC2Delay(SiS_Pr,0xff00);
  7583. if(!(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x26) & 0x02)) {
  7584. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x02);
  7585. SiS_WaitVBRetrace(SiS_Pr);
  7586. }
  7587. if(!(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x26) & 0x01)) {
  7588. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x01);
  7589. }
  7590. }
  7591. void
  7592. SiS_SiS30xBLOff(struct SiS_Private *SiS_Pr)
  7593. {
  7594. /* Switch off LCD backlight on SiS30xLV */
  7595. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFE);
  7596. SiS_DDC2Delay(SiS_Pr,0xff00);
  7597. }
  7598. /*********************************************/
  7599. /* DDC RELATED FUNCTIONS */
  7600. /*********************************************/
  7601. static void
  7602. SiS_SetupDDCN(struct SiS_Private *SiS_Pr)
  7603. {
  7604. SiS_Pr->SiS_DDC_NData = ~SiS_Pr->SiS_DDC_Data;
  7605. SiS_Pr->SiS_DDC_NClk = ~SiS_Pr->SiS_DDC_Clk;
  7606. if((SiS_Pr->SiS_DDC_Index == 0x11) && (SiS_Pr->SiS_SensibleSR11)) {
  7607. SiS_Pr->SiS_DDC_NData &= 0x0f;
  7608. SiS_Pr->SiS_DDC_NClk &= 0x0f;
  7609. }
  7610. }
  7611. #ifdef SIS300
  7612. static unsigned char *
  7613. SiS_SetTrumpBlockLoop(struct SiS_Private *SiS_Pr, unsigned char *dataptr)
  7614. {
  7615. int i, j, num;
  7616. unsigned short tempah,temp;
  7617. unsigned char *mydataptr;
  7618. for(i=0; i<20; i++) { /* Do 20 attempts to write */
  7619. mydataptr = dataptr;
  7620. num = *mydataptr++;
  7621. if(!num) return mydataptr;
  7622. if(i) {
  7623. SiS_SetStop(SiS_Pr);
  7624. SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT * 2);
  7625. }
  7626. if(SiS_SetStart(SiS_Pr)) continue; /* Set start condition */
  7627. tempah = SiS_Pr->SiS_DDC_DeviceAddr;
  7628. temp = SiS_WriteDDC2Data(SiS_Pr,tempah); /* Write DAB (S0=0=write) */
  7629. if(temp) continue; /* (ERROR: no ack) */
  7630. tempah = *mydataptr++;
  7631. temp = SiS_WriteDDC2Data(SiS_Pr,tempah); /* Write register number */
  7632. if(temp) continue; /* (ERROR: no ack) */
  7633. for(j=0; j<num; j++) {
  7634. tempah = *mydataptr++;
  7635. temp = SiS_WriteDDC2Data(SiS_Pr,tempah);/* Write DAB (S0=0=write) */
  7636. if(temp) break;
  7637. }
  7638. if(temp) continue;
  7639. if(SiS_SetStop(SiS_Pr)) continue;
  7640. return mydataptr;
  7641. }
  7642. return NULL;
  7643. }
  7644. static bool
  7645. SiS_SetTrumpionBlock(struct SiS_Private *SiS_Pr, unsigned char *dataptr)
  7646. {
  7647. SiS_Pr->SiS_DDC_DeviceAddr = 0xF0; /* DAB (Device Address Byte) */
  7648. SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */
  7649. SiS_Pr->SiS_DDC_Data = 0x02; /* Bitmask in IndexReg for Data */
  7650. SiS_Pr->SiS_DDC_Clk = 0x01; /* Bitmask in IndexReg for Clk */
  7651. SiS_SetupDDCN(SiS_Pr);
  7652. SiS_SetSwitchDDC2(SiS_Pr);
  7653. while(*dataptr) {
  7654. dataptr = SiS_SetTrumpBlockLoop(SiS_Pr, dataptr);
  7655. if(!dataptr) return false;
  7656. }
  7657. #ifdef SIS_XORG_XF86
  7658. #ifdef TWDEBUG
  7659. xf86DrvMsg(0, X_INFO, "Trumpion block success\n");
  7660. #endif
  7661. #endif
  7662. return true;
  7663. }
  7664. #endif
  7665. /* The Chrontel 700x is connected to the 630/730 via
  7666. * the 630/730's DDC/I2C port.
  7667. *
  7668. * On 630(S)T chipset, the index changed from 0x11 to
  7669. * 0x0a, possibly for working around the DDC problems
  7670. */
  7671. static bool
  7672. SiS_SetChReg(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val, unsigned short myor)
  7673. {
  7674. unsigned short temp, i;
  7675. for(i=0; i<20; i++) { /* Do 20 attempts to write */
  7676. if(i) {
  7677. SiS_SetStop(SiS_Pr);
  7678. SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT * 4);
  7679. }
  7680. if(SiS_SetStart(SiS_Pr)) continue; /* Set start condition */
  7681. temp = SiS_WriteDDC2Data(SiS_Pr, SiS_Pr->SiS_DDC_DeviceAddr); /* Write DAB (S0=0=write) */
  7682. if(temp) continue; /* (ERROR: no ack) */
  7683. temp = SiS_WriteDDC2Data(SiS_Pr, (reg | myor)); /* Write RAB (700x: set bit 7, see datasheet) */
  7684. if(temp) continue; /* (ERROR: no ack) */
  7685. temp = SiS_WriteDDC2Data(SiS_Pr, val); /* Write data */
  7686. if(temp) continue; /* (ERROR: no ack) */
  7687. if(SiS_SetStop(SiS_Pr)) continue; /* Set stop condition */
  7688. SiS_Pr->SiS_ChrontelInit = 1;
  7689. return true;
  7690. }
  7691. return false;
  7692. }
  7693. /* Write to Chrontel 700x */
  7694. void
  7695. SiS_SetCH700x(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val)
  7696. {
  7697. SiS_Pr->SiS_DDC_DeviceAddr = 0xEA; /* DAB (Device Address Byte) */
  7698. SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT);
  7699. if(!(SiS_Pr->SiS_ChrontelInit)) {
  7700. SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */
  7701. SiS_Pr->SiS_DDC_Data = 0x02; /* Bitmask in IndexReg for Data */
  7702. SiS_Pr->SiS_DDC_Clk = 0x01; /* Bitmask in IndexReg for Clk */
  7703. SiS_SetupDDCN(SiS_Pr);
  7704. }
  7705. if( (!(SiS_SetChReg(SiS_Pr, reg, val, 0x80))) &&
  7706. (!(SiS_Pr->SiS_ChrontelInit)) ) {
  7707. SiS_Pr->SiS_DDC_Index = 0x0a;
  7708. SiS_Pr->SiS_DDC_Data = 0x80;
  7709. SiS_Pr->SiS_DDC_Clk = 0x40;
  7710. SiS_SetupDDCN(SiS_Pr);
  7711. SiS_SetChReg(SiS_Pr, reg, val, 0x80);
  7712. }
  7713. }
  7714. /* Write to Chrontel 701x */
  7715. /* Parameter is [Data (S15-S8) | Register no (S7-S0)] */
  7716. void
  7717. SiS_SetCH701x(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val)
  7718. {
  7719. SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */
  7720. SiS_Pr->SiS_DDC_Data = 0x08; /* Bitmask in IndexReg for Data */
  7721. SiS_Pr->SiS_DDC_Clk = 0x04; /* Bitmask in IndexReg for Clk */
  7722. SiS_SetupDDCN(SiS_Pr);
  7723. SiS_Pr->SiS_DDC_DeviceAddr = 0xEA; /* DAB (Device Address Byte) */
  7724. SiS_SetChReg(SiS_Pr, reg, val, 0);
  7725. }
  7726. #ifdef SIS_LINUX_KERNEL
  7727. static
  7728. #endif
  7729. void
  7730. SiS_SetCH70xx(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val)
  7731. {
  7732. if(SiS_Pr->SiS_IF_DEF_CH70xx == 1)
  7733. SiS_SetCH700x(SiS_Pr, reg, val);
  7734. else
  7735. SiS_SetCH701x(SiS_Pr, reg, val);
  7736. }
  7737. static unsigned short
  7738. SiS_GetChReg(struct SiS_Private *SiS_Pr, unsigned short myor)
  7739. {
  7740. unsigned short tempah, temp, i;
  7741. for(i=0; i<20; i++) { /* Do 20 attempts to read */
  7742. if(i) {
  7743. SiS_SetStop(SiS_Pr);
  7744. SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT * 4);
  7745. }
  7746. if(SiS_SetStart(SiS_Pr)) continue; /* Set start condition */
  7747. temp = SiS_WriteDDC2Data(SiS_Pr,SiS_Pr->SiS_DDC_DeviceAddr); /* Write DAB (S0=0=write) */
  7748. if(temp) continue; /* (ERROR: no ack) */
  7749. temp = SiS_WriteDDC2Data(SiS_Pr,SiS_Pr->SiS_DDC_ReadAddr | myor); /* Write RAB (700x: | 0x80) */
  7750. if(temp) continue; /* (ERROR: no ack) */
  7751. if (SiS_SetStart(SiS_Pr)) continue; /* Re-start */
  7752. temp = SiS_WriteDDC2Data(SiS_Pr,SiS_Pr->SiS_DDC_DeviceAddr | 0x01);/* DAB (S0=1=read) */
  7753. if(temp) continue; /* (ERROR: no ack) */
  7754. tempah = SiS_ReadDDC2Data(SiS_Pr); /* Read byte */
  7755. if(SiS_SetStop(SiS_Pr)) continue; /* Stop condition */
  7756. SiS_Pr->SiS_ChrontelInit = 1;
  7757. return tempah;
  7758. }
  7759. return 0xFFFF;
  7760. }
  7761. /* Read from Chrontel 700x */
  7762. /* Parameter is [Register no (S7-S0)] */
  7763. unsigned short
  7764. SiS_GetCH700x(struct SiS_Private *SiS_Pr, unsigned short tempbx)
  7765. {
  7766. unsigned short result;
  7767. SiS_Pr->SiS_DDC_DeviceAddr = 0xEA; /* DAB */
  7768. SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT);
  7769. if(!(SiS_Pr->SiS_ChrontelInit)) {
  7770. SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */
  7771. SiS_Pr->SiS_DDC_Data = 0x02; /* Bitmask in IndexReg for Data */
  7772. SiS_Pr->SiS_DDC_Clk = 0x01; /* Bitmask in IndexReg for Clk */
  7773. SiS_SetupDDCN(SiS_Pr);
  7774. }
  7775. SiS_Pr->SiS_DDC_ReadAddr = tempbx;
  7776. if( ((result = SiS_GetChReg(SiS_Pr,0x80)) == 0xFFFF) &&
  7777. (!SiS_Pr->SiS_ChrontelInit) ) {
  7778. SiS_Pr->SiS_DDC_Index = 0x0a;
  7779. SiS_Pr->SiS_DDC_Data = 0x80;
  7780. SiS_Pr->SiS_DDC_Clk = 0x40;
  7781. SiS_SetupDDCN(SiS_Pr);
  7782. result = SiS_GetChReg(SiS_Pr,0x80);
  7783. }
  7784. return result;
  7785. }
  7786. /* Read from Chrontel 701x */
  7787. /* Parameter is [Register no (S7-S0)] */
  7788. unsigned short
  7789. SiS_GetCH701x(struct SiS_Private *SiS_Pr, unsigned short tempbx)
  7790. {
  7791. SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */
  7792. SiS_Pr->SiS_DDC_Data = 0x08; /* Bitmask in IndexReg for Data */
  7793. SiS_Pr->SiS_DDC_Clk = 0x04; /* Bitmask in IndexReg for Clk */
  7794. SiS_SetupDDCN(SiS_Pr);
  7795. SiS_Pr->SiS_DDC_DeviceAddr = 0xEA; /* DAB */
  7796. SiS_Pr->SiS_DDC_ReadAddr = tempbx;
  7797. return SiS_GetChReg(SiS_Pr,0);
  7798. }
  7799. /* Read from Chrontel 70xx */
  7800. /* Parameter is [Register no (S7-S0)] */
  7801. #ifdef SIS_LINUX_KERNEL
  7802. static
  7803. #endif
  7804. unsigned short
  7805. SiS_GetCH70xx(struct SiS_Private *SiS_Pr, unsigned short tempbx)
  7806. {
  7807. if(SiS_Pr->SiS_IF_DEF_CH70xx == 1)
  7808. return SiS_GetCH700x(SiS_Pr, tempbx);
  7809. else
  7810. return SiS_GetCH701x(SiS_Pr, tempbx);
  7811. }
  7812. void
  7813. SiS_SetCH70xxANDOR(struct SiS_Private *SiS_Pr, unsigned short reg,
  7814. unsigned char myor, unsigned short myand)
  7815. {
  7816. unsigned short tempbl;
  7817. tempbl = (SiS_GetCH70xx(SiS_Pr, (reg & 0xFF)) & myand) | myor;
  7818. SiS_SetCH70xx(SiS_Pr, reg, tempbl);
  7819. }
  7820. /* Our own DDC functions */
  7821. #ifndef SIS_XORG_XF86
  7822. static
  7823. #endif
  7824. unsigned short
  7825. SiS_InitDDCRegs(struct SiS_Private *SiS_Pr, unsigned int VBFlags, int VGAEngine,
  7826. unsigned short adaptnum, unsigned short DDCdatatype, bool checkcr32,
  7827. unsigned int VBFlags2)
  7828. {
  7829. unsigned char ddcdtype[] = { 0xa0, 0xa0, 0xa0, 0xa2, 0xa6 };
  7830. unsigned char flag, cr32;
  7831. unsigned short temp = 0, myadaptnum = adaptnum;
  7832. if(adaptnum != 0) {
  7833. if(!(VBFlags2 & VB2_SISTMDSBRIDGE)) return 0xFFFF;
  7834. if((VBFlags2 & VB2_30xBDH) && (adaptnum == 1)) return 0xFFFF;
  7835. }
  7836. /* adapternum for SiS bridges: 0 = CRT1, 1 = LCD, 2 = VGA2 */
  7837. SiS_Pr->SiS_ChrontelInit = 0; /* force re-detection! */
  7838. SiS_Pr->SiS_DDC_SecAddr = 0;
  7839. SiS_Pr->SiS_DDC_DeviceAddr = ddcdtype[DDCdatatype];
  7840. SiS_Pr->SiS_DDC_Port = SiS_Pr->SiS_P3c4;
  7841. SiS_Pr->SiS_DDC_Index = 0x11;
  7842. flag = 0xff;
  7843. cr32 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x32);
  7844. #if 0
  7845. if(VBFlags2 & VB2_SISBRIDGE) {
  7846. if(myadaptnum == 0) {
  7847. if(!(cr32 & 0x20)) {
  7848. myadaptnum = 2;
  7849. if(!(cr32 & 0x10)) {
  7850. myadaptnum = 1;
  7851. if(!(cr32 & 0x08)) {
  7852. myadaptnum = 0;
  7853. }
  7854. }
  7855. }
  7856. }
  7857. }
  7858. #endif
  7859. if(VGAEngine == SIS_300_VGA) { /* 300 series */
  7860. if(myadaptnum != 0) {
  7861. flag = 0;
  7862. if(VBFlags2 & VB2_SISBRIDGE) {
  7863. SiS_Pr->SiS_DDC_Port = SiS_Pr->SiS_Part4Port;
  7864. SiS_Pr->SiS_DDC_Index = 0x0f;
  7865. }
  7866. }
  7867. if(!(VBFlags2 & VB2_301)) {
  7868. if((cr32 & 0x80) && (checkcr32)) {
  7869. if(myadaptnum >= 1) {
  7870. if(!(cr32 & 0x08)) {
  7871. myadaptnum = 1;
  7872. if(!(cr32 & 0x10)) return 0xFFFF;
  7873. }
  7874. }
  7875. }
  7876. }
  7877. temp = 4 - (myadaptnum * 2);
  7878. if(flag) temp = 0;
  7879. } else { /* 315/330 series */
  7880. /* here we simplify: 0 = CRT1, 1 = CRT2 (VGA, LCD) */
  7881. if(VBFlags2 & VB2_SISBRIDGE) {
  7882. if(myadaptnum == 2) {
  7883. myadaptnum = 1;
  7884. }
  7885. }
  7886. if(myadaptnum == 1) {
  7887. flag = 0;
  7888. if(VBFlags2 & VB2_SISBRIDGE) {
  7889. SiS_Pr->SiS_DDC_Port = SiS_Pr->SiS_Part4Port;
  7890. SiS_Pr->SiS_DDC_Index = 0x0f;
  7891. }
  7892. }
  7893. if((cr32 & 0x80) && (checkcr32)) {
  7894. if(myadaptnum >= 1) {
  7895. if(!(cr32 & 0x08)) {
  7896. myadaptnum = 1;
  7897. if(!(cr32 & 0x10)) return 0xFFFF;
  7898. }
  7899. }
  7900. }
  7901. temp = myadaptnum;
  7902. if(myadaptnum == 1) {
  7903. temp = 0;
  7904. if(VBFlags2 & VB2_LVDS) flag = 0xff;
  7905. }
  7906. if(flag) temp = 0;
  7907. }
  7908. SiS_Pr->SiS_DDC_Data = 0x02 << temp;
  7909. SiS_Pr->SiS_DDC_Clk = 0x01 << temp;
  7910. SiS_SetupDDCN(SiS_Pr);
  7911. #ifdef SIS_XORG_XF86
  7912. #ifdef TWDEBUG
  7913. xf86DrvMsg(0, X_INFO, "DDC Port %x Index %x Shift %d\n",
  7914. SiS_Pr->SiS_DDC_Port, SiS_Pr->SiS_DDC_Index, temp);
  7915. #endif
  7916. #endif
  7917. return 0;
  7918. }
  7919. static unsigned short
  7920. SiS_WriteDABDDC(struct SiS_Private *SiS_Pr)
  7921. {
  7922. if(SiS_SetStart(SiS_Pr)) return 0xFFFF;
  7923. if(SiS_WriteDDC2Data(SiS_Pr, SiS_Pr->SiS_DDC_DeviceAddr)) {
  7924. return 0xFFFF;
  7925. }
  7926. if(SiS_WriteDDC2Data(SiS_Pr, SiS_Pr->SiS_DDC_SecAddr)) {
  7927. return 0xFFFF;
  7928. }
  7929. return 0;
  7930. }
  7931. static unsigned short
  7932. SiS_PrepareReadDDC(struct SiS_Private *SiS_Pr)
  7933. {
  7934. if(SiS_SetStart(SiS_Pr)) return 0xFFFF;
  7935. if(SiS_WriteDDC2Data(SiS_Pr, (SiS_Pr->SiS_DDC_DeviceAddr | 0x01))) {
  7936. return 0xFFFF;
  7937. }
  7938. return 0;
  7939. }
  7940. static unsigned short
  7941. SiS_PrepareDDC(struct SiS_Private *SiS_Pr)
  7942. {
  7943. if(SiS_WriteDABDDC(SiS_Pr)) SiS_WriteDABDDC(SiS_Pr);
  7944. if(SiS_PrepareReadDDC(SiS_Pr)) return (SiS_PrepareReadDDC(SiS_Pr));
  7945. return 0;
  7946. }
  7947. static void
  7948. SiS_SendACK(struct SiS_Private *SiS_Pr, unsigned short yesno)
  7949. {
  7950. SiS_SetSCLKLow(SiS_Pr);
  7951. if(yesno) {
  7952. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  7953. SiS_Pr->SiS_DDC_Index,
  7954. SiS_Pr->SiS_DDC_NData,
  7955. SiS_Pr->SiS_DDC_Data);
  7956. } else {
  7957. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  7958. SiS_Pr->SiS_DDC_Index,
  7959. SiS_Pr->SiS_DDC_NData,
  7960. 0);
  7961. }
  7962. SiS_SetSCLKHigh(SiS_Pr);
  7963. }
  7964. static unsigned short
  7965. SiS_DoProbeDDC(struct SiS_Private *SiS_Pr)
  7966. {
  7967. unsigned char mask, value;
  7968. unsigned short temp, ret=0;
  7969. bool failed = false;
  7970. SiS_SetSwitchDDC2(SiS_Pr);
  7971. if(SiS_PrepareDDC(SiS_Pr)) {
  7972. SiS_SetStop(SiS_Pr);
  7973. #ifdef SIS_XORG_XF86
  7974. #ifdef TWDEBUG
  7975. xf86DrvMsg(0, X_INFO, "Probe: Prepare failed\n");
  7976. #endif
  7977. #endif
  7978. return 0xFFFF;
  7979. }
  7980. mask = 0xf0;
  7981. value = 0x20;
  7982. if(SiS_Pr->SiS_DDC_DeviceAddr == 0xa0) {
  7983. temp = (unsigned char)SiS_ReadDDC2Data(SiS_Pr);
  7984. SiS_SendACK(SiS_Pr, 0);
  7985. if(temp == 0) {
  7986. mask = 0xff;
  7987. value = 0xff;
  7988. } else {
  7989. failed = true;
  7990. ret = 0xFFFF;
  7991. #ifdef SIS_XORG_XF86
  7992. #ifdef TWDEBUG
  7993. xf86DrvMsg(0, X_INFO, "Probe: Read 1 failed\n");
  7994. #endif
  7995. #endif
  7996. }
  7997. }
  7998. if(!failed) {
  7999. temp = (unsigned char)SiS_ReadDDC2Data(SiS_Pr);
  8000. SiS_SendACK(SiS_Pr, 1);
  8001. temp &= mask;
  8002. if(temp == value) ret = 0;
  8003. else {
  8004. ret = 0xFFFF;
  8005. #ifdef SIS_XORG_XF86
  8006. #ifdef TWDEBUG
  8007. xf86DrvMsg(0, X_INFO, "Probe: Read 2 failed\n");
  8008. #endif
  8009. #endif
  8010. if(SiS_Pr->SiS_DDC_DeviceAddr == 0xa0) {
  8011. if(temp == 0x30) ret = 0;
  8012. }
  8013. }
  8014. }
  8015. SiS_SetStop(SiS_Pr);
  8016. return ret;
  8017. }
  8018. #ifndef SIS_XORG_XF86
  8019. static
  8020. #endif
  8021. unsigned short
  8022. SiS_ProbeDDC(struct SiS_Private *SiS_Pr)
  8023. {
  8024. unsigned short flag;
  8025. flag = 0x180;
  8026. SiS_Pr->SiS_DDC_DeviceAddr = 0xa0;
  8027. if(!(SiS_DoProbeDDC(SiS_Pr))) flag |= 0x02;
  8028. SiS_Pr->SiS_DDC_DeviceAddr = 0xa2;
  8029. if(!(SiS_DoProbeDDC(SiS_Pr))) flag |= 0x08;
  8030. SiS_Pr->SiS_DDC_DeviceAddr = 0xa6;
  8031. if(!(SiS_DoProbeDDC(SiS_Pr))) flag |= 0x10;
  8032. if(!(flag & 0x1a)) flag = 0;
  8033. return flag;
  8034. }
  8035. #ifndef SIS_XORG_XF86
  8036. static
  8037. #endif
  8038. unsigned short
  8039. SiS_ReadDDC(struct SiS_Private *SiS_Pr, unsigned short DDCdatatype, unsigned char *buffer)
  8040. {
  8041. unsigned short flag, length, i;
  8042. unsigned char chksum,gotcha;
  8043. if(DDCdatatype > 4) return 0xFFFF;
  8044. flag = 0;
  8045. SiS_SetSwitchDDC2(SiS_Pr);
  8046. if(!(SiS_PrepareDDC(SiS_Pr))) {
  8047. length = 127;
  8048. if(DDCdatatype != 1) length = 255;
  8049. chksum = 0;
  8050. gotcha = 0;
  8051. for(i=0; i<length; i++) {
  8052. buffer[i] = (unsigned char)SiS_ReadDDC2Data(SiS_Pr);
  8053. chksum += buffer[i];
  8054. gotcha |= buffer[i];
  8055. SiS_SendACK(SiS_Pr, 0);
  8056. }
  8057. buffer[i] = (unsigned char)SiS_ReadDDC2Data(SiS_Pr);
  8058. chksum += buffer[i];
  8059. SiS_SendACK(SiS_Pr, 1);
  8060. if(gotcha) flag = (unsigned short)chksum;
  8061. else flag = 0xFFFF;
  8062. } else {
  8063. flag = 0xFFFF;
  8064. }
  8065. SiS_SetStop(SiS_Pr);
  8066. return flag;
  8067. }
  8068. /* Our private DDC functions
  8069. It complies somewhat with the corresponding VESA function
  8070. in arguments and return values.
  8071. Since this is probably called before the mode is changed,
  8072. we use our pre-detected pSiS-values instead of SiS_Pr as
  8073. regards chipset and video bridge type.
  8074. Arguments:
  8075. adaptnum: 0=CRT1(analog), 1=CRT2/LCD(digital), 2=CRT2/VGA2(analog)
  8076. CRT2 DDC is only supported on SiS301, 301B, 301C, 302B.
  8077. LCDA is CRT1, but DDC is read from CRT2 port.
  8078. DDCdatatype: 0=Probe, 1=EDID, 2=EDID+VDIF, 3=EDID V2 (P&D), 4=EDID V2 (FPDI-2)
  8079. buffer: ptr to 256 data bytes which will be filled with read data.
  8080. Returns 0xFFFF if error, otherwise
  8081. if DDCdatatype > 0: Returns 0 if reading OK (included a correct checksum)
  8082. if DDCdatatype = 0: Returns supported DDC modes
  8083. */
  8084. unsigned short
  8085. SiS_HandleDDC(struct SiS_Private *SiS_Pr, unsigned int VBFlags, int VGAEngine,
  8086. unsigned short adaptnum, unsigned short DDCdatatype, unsigned char *buffer,
  8087. unsigned int VBFlags2)
  8088. {
  8089. unsigned char sr1f, cr17=1;
  8090. unsigned short result;
  8091. if(adaptnum > 2)
  8092. return 0xFFFF;
  8093. if(DDCdatatype > 4)
  8094. return 0xFFFF;
  8095. if((!(VBFlags2 & VB2_VIDEOBRIDGE)) && (adaptnum > 0))
  8096. return 0xFFFF;
  8097. if(SiS_InitDDCRegs(SiS_Pr, VBFlags, VGAEngine, adaptnum, DDCdatatype, false, VBFlags2) == 0xFFFF)
  8098. return 0xFFFF;
  8099. sr1f = SiS_GetReg(SiS_Pr->SiS_P3c4,0x1f);
  8100. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x1f,0x3f,0x04);
  8101. if(VGAEngine == SIS_300_VGA) {
  8102. cr17 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x17) & 0x80;
  8103. if(!cr17) {
  8104. SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x17,0x80);
  8105. SiS_SetReg(SiS_Pr->SiS_P3c4,0x00,0x01);
  8106. SiS_SetReg(SiS_Pr->SiS_P3c4,0x00,0x03);
  8107. }
  8108. }
  8109. if((sr1f) || (!cr17)) {
  8110. SiS_WaitRetrace1(SiS_Pr);
  8111. SiS_WaitRetrace1(SiS_Pr);
  8112. SiS_WaitRetrace1(SiS_Pr);
  8113. SiS_WaitRetrace1(SiS_Pr);
  8114. }
  8115. if(DDCdatatype == 0) {
  8116. result = SiS_ProbeDDC(SiS_Pr);
  8117. } else {
  8118. result = SiS_ReadDDC(SiS_Pr, DDCdatatype, buffer);
  8119. if((!result) && (DDCdatatype == 1)) {
  8120. if((buffer[0] == 0x00) && (buffer[1] == 0xff) &&
  8121. (buffer[2] == 0xff) && (buffer[3] == 0xff) &&
  8122. (buffer[4] == 0xff) && (buffer[5] == 0xff) &&
  8123. (buffer[6] == 0xff) && (buffer[7] == 0x00) &&
  8124. (buffer[0x12] == 1)) {
  8125. if(!SiS_Pr->DDCPortMixup) {
  8126. if(adaptnum == 1) {
  8127. if(!(buffer[0x14] & 0x80)) result = 0xFFFE;
  8128. } else {
  8129. if(buffer[0x14] & 0x80) result = 0xFFFE;
  8130. }
  8131. }
  8132. }
  8133. }
  8134. }
  8135. SiS_SetReg(SiS_Pr->SiS_P3c4,0x1f,sr1f);
  8136. if(VGAEngine == SIS_300_VGA) {
  8137. SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x17,0x7f,cr17);
  8138. }
  8139. return result;
  8140. }
  8141. /* Generic I2C functions for Chrontel & DDC --------- */
  8142. static void
  8143. SiS_SetSwitchDDC2(struct SiS_Private *SiS_Pr)
  8144. {
  8145. SiS_SetSCLKHigh(SiS_Pr);
  8146. SiS_WaitRetrace1(SiS_Pr);
  8147. SiS_SetSCLKLow(SiS_Pr);
  8148. SiS_WaitRetrace1(SiS_Pr);
  8149. }
  8150. unsigned short
  8151. SiS_ReadDDC1Bit(struct SiS_Private *SiS_Pr)
  8152. {
  8153. SiS_WaitRetrace1(SiS_Pr);
  8154. return ((SiS_GetReg(SiS_Pr->SiS_P3c4,0x11) & 0x02) >> 1);
  8155. }
  8156. /* Set I2C start condition */
  8157. /* This is done by a SD high-to-low transition while SC is high */
  8158. static unsigned short
  8159. SiS_SetStart(struct SiS_Private *SiS_Pr)
  8160. {
  8161. if(SiS_SetSCLKLow(SiS_Pr)) return 0xFFFF; /* (SC->low) */
  8162. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8163. SiS_Pr->SiS_DDC_Index,
  8164. SiS_Pr->SiS_DDC_NData,
  8165. SiS_Pr->SiS_DDC_Data); /* SD->high */
  8166. if(SiS_SetSCLKHigh(SiS_Pr)) return 0xFFFF; /* SC->high */
  8167. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8168. SiS_Pr->SiS_DDC_Index,
  8169. SiS_Pr->SiS_DDC_NData,
  8170. 0x00); /* SD->low = start condition */
  8171. if(SiS_SetSCLKHigh(SiS_Pr)) return 0xFFFF; /* (SC->low) */
  8172. return 0;
  8173. }
  8174. /* Set I2C stop condition */
  8175. /* This is done by a SD low-to-high transition while SC is high */
  8176. static unsigned short
  8177. SiS_SetStop(struct SiS_Private *SiS_Pr)
  8178. {
  8179. if(SiS_SetSCLKLow(SiS_Pr)) return 0xFFFF; /* (SC->low) */
  8180. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8181. SiS_Pr->SiS_DDC_Index,
  8182. SiS_Pr->SiS_DDC_NData,
  8183. 0x00); /* SD->low */
  8184. if(SiS_SetSCLKHigh(SiS_Pr)) return 0xFFFF; /* SC->high */
  8185. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8186. SiS_Pr->SiS_DDC_Index,
  8187. SiS_Pr->SiS_DDC_NData,
  8188. SiS_Pr->SiS_DDC_Data); /* SD->high = stop condition */
  8189. if(SiS_SetSCLKHigh(SiS_Pr)) return 0xFFFF; /* (SC->high) */
  8190. return 0;
  8191. }
  8192. /* Write 8 bits of data */
  8193. static unsigned short
  8194. SiS_WriteDDC2Data(struct SiS_Private *SiS_Pr, unsigned short tempax)
  8195. {
  8196. unsigned short i,flag,temp;
  8197. flag = 0x80;
  8198. for(i = 0; i < 8; i++) {
  8199. SiS_SetSCLKLow(SiS_Pr); /* SC->low */
  8200. if(tempax & flag) {
  8201. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8202. SiS_Pr->SiS_DDC_Index,
  8203. SiS_Pr->SiS_DDC_NData,
  8204. SiS_Pr->SiS_DDC_Data); /* Write bit (1) to SD */
  8205. } else {
  8206. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8207. SiS_Pr->SiS_DDC_Index,
  8208. SiS_Pr->SiS_DDC_NData,
  8209. 0x00); /* Write bit (0) to SD */
  8210. }
  8211. SiS_SetSCLKHigh(SiS_Pr); /* SC->high */
  8212. flag >>= 1;
  8213. }
  8214. temp = SiS_CheckACK(SiS_Pr); /* Check acknowledge */
  8215. return temp;
  8216. }
  8217. static unsigned short
  8218. SiS_ReadDDC2Data(struct SiS_Private *SiS_Pr)
  8219. {
  8220. unsigned short i, temp, getdata;
  8221. getdata = 0;
  8222. for(i = 0; i < 8; i++) {
  8223. getdata <<= 1;
  8224. SiS_SetSCLKLow(SiS_Pr);
  8225. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8226. SiS_Pr->SiS_DDC_Index,
  8227. SiS_Pr->SiS_DDC_NData,
  8228. SiS_Pr->SiS_DDC_Data);
  8229. SiS_SetSCLKHigh(SiS_Pr);
  8230. temp = SiS_GetReg(SiS_Pr->SiS_DDC_Port,SiS_Pr->SiS_DDC_Index);
  8231. if(temp & SiS_Pr->SiS_DDC_Data) getdata |= 0x01;
  8232. }
  8233. return getdata;
  8234. }
  8235. static unsigned short
  8236. SiS_SetSCLKLow(struct SiS_Private *SiS_Pr)
  8237. {
  8238. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8239. SiS_Pr->SiS_DDC_Index,
  8240. SiS_Pr->SiS_DDC_NClk,
  8241. 0x00); /* SetSCLKLow() */
  8242. SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT);
  8243. return 0;
  8244. }
  8245. static unsigned short
  8246. SiS_SetSCLKHigh(struct SiS_Private *SiS_Pr)
  8247. {
  8248. unsigned short temp, watchdog=1000;
  8249. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8250. SiS_Pr->SiS_DDC_Index,
  8251. SiS_Pr->SiS_DDC_NClk,
  8252. SiS_Pr->SiS_DDC_Clk); /* SetSCLKHigh() */
  8253. do {
  8254. temp = SiS_GetReg(SiS_Pr->SiS_DDC_Port,SiS_Pr->SiS_DDC_Index);
  8255. } while((!(temp & SiS_Pr->SiS_DDC_Clk)) && --watchdog);
  8256. if (!watchdog) {
  8257. #ifdef SIS_XORG_XF86
  8258. #ifdef TWDEBUG
  8259. xf86DrvMsg(0, X_INFO, "SetClkHigh failed\n");
  8260. #endif
  8261. #endif
  8262. return 0xFFFF;
  8263. }
  8264. SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT);
  8265. return 0;
  8266. }
  8267. /* Check I2C acknowledge */
  8268. /* Returns 0 if ack ok, non-0 if ack not ok */
  8269. static unsigned short
  8270. SiS_CheckACK(struct SiS_Private *SiS_Pr)
  8271. {
  8272. unsigned short tempah;
  8273. SiS_SetSCLKLow(SiS_Pr); /* (SC->low) */
  8274. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8275. SiS_Pr->SiS_DDC_Index,
  8276. SiS_Pr->SiS_DDC_NData,
  8277. SiS_Pr->SiS_DDC_Data); /* (SD->high) */
  8278. SiS_SetSCLKHigh(SiS_Pr); /* SC->high = clock impulse for ack */
  8279. tempah = SiS_GetReg(SiS_Pr->SiS_DDC_Port,SiS_Pr->SiS_DDC_Index); /* Read SD */
  8280. SiS_SetSCLKLow(SiS_Pr); /* SC->low = end of clock impulse */
  8281. if(tempah & SiS_Pr->SiS_DDC_Data) return 1; /* Ack OK if bit = 0 */
  8282. return 0;
  8283. }
  8284. /* End of I2C functions ----------------------- */
  8285. /* =============== SiS 315/330 O.E.M. ================= */
  8286. #ifdef SIS315H
  8287. static unsigned short
  8288. GetRAMDACromptr(struct SiS_Private *SiS_Pr)
  8289. {
  8290. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  8291. unsigned short romptr;
  8292. if(SiS_Pr->ChipType < SIS_330) {
  8293. romptr = SISGETROMW(0x128);
  8294. if(SiS_Pr->SiS_VBType & VB_SIS30xB)
  8295. romptr = SISGETROMW(0x12a);
  8296. } else {
  8297. romptr = SISGETROMW(0x1a8);
  8298. if(SiS_Pr->SiS_VBType & VB_SIS30xB)
  8299. romptr = SISGETROMW(0x1aa);
  8300. }
  8301. return romptr;
  8302. }
  8303. static unsigned short
  8304. GetLCDromptr(struct SiS_Private *SiS_Pr)
  8305. {
  8306. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  8307. unsigned short romptr;
  8308. if(SiS_Pr->ChipType < SIS_330) {
  8309. romptr = SISGETROMW(0x120);
  8310. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV)
  8311. romptr = SISGETROMW(0x122);
  8312. } else {
  8313. romptr = SISGETROMW(0x1a0);
  8314. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV)
  8315. romptr = SISGETROMW(0x1a2);
  8316. }
  8317. return romptr;
  8318. }
  8319. static unsigned short
  8320. GetTVromptr(struct SiS_Private *SiS_Pr)
  8321. {
  8322. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  8323. unsigned short romptr;
  8324. if(SiS_Pr->ChipType < SIS_330) {
  8325. romptr = SISGETROMW(0x114);
  8326. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV)
  8327. romptr = SISGETROMW(0x11a);
  8328. } else {
  8329. romptr = SISGETROMW(0x194);
  8330. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV)
  8331. romptr = SISGETROMW(0x19a);
  8332. }
  8333. return romptr;
  8334. }
  8335. static unsigned short
  8336. GetLCDPtrIndexBIOS(struct SiS_Private *SiS_Pr)
  8337. {
  8338. unsigned short index;
  8339. if((IS_SIS650) && (SiS_Pr->SiS_VBType & VB_SISLVDS)) {
  8340. if(!(SiS_IsNotM650orLater(SiS_Pr))) {
  8341. if((index = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) & 0xf0)) {
  8342. index >>= 4;
  8343. index *= 3;
  8344. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) index += 2;
  8345. else if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) index++;
  8346. return index;
  8347. }
  8348. }
  8349. }
  8350. index = SiS_GetBIOSLCDResInfo(SiS_Pr) & 0x0F;
  8351. if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) index -= 5;
  8352. if(SiS_Pr->SiS_VBType & VB_SIS301C) { /* 1.15.20 and later (not VB specific) */
  8353. if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) index -= 5;
  8354. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x768) index -= 5;
  8355. } else {
  8356. if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) index -= 6;
  8357. }
  8358. index--;
  8359. index *= 3;
  8360. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) index += 2;
  8361. else if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) index++;
  8362. return index;
  8363. }
  8364. static unsigned short
  8365. GetLCDPtrIndex(struct SiS_Private *SiS_Pr)
  8366. {
  8367. unsigned short index;
  8368. index = ((SiS_GetBIOSLCDResInfo(SiS_Pr) & 0x0F) - 1) * 3;
  8369. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) index += 2;
  8370. else if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) index++;
  8371. return index;
  8372. }
  8373. static unsigned short
  8374. GetTVPtrIndex(struct SiS_Private *SiS_Pr)
  8375. {
  8376. unsigned short index;
  8377. index = 0;
  8378. if(SiS_Pr->SiS_TVMode & TVSetPAL) index = 1;
  8379. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) index = 2;
  8380. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) index = 0;
  8381. index <<= 1;
  8382. if((SiS_Pr->SiS_VBInfo & SetInSlaveMode) &&
  8383. (SiS_Pr->SiS_TVMode & TVSetTVSimuMode)) {
  8384. index++;
  8385. }
  8386. return index;
  8387. }
  8388. static unsigned int
  8389. GetOEMTVPtr661_2_GEN(struct SiS_Private *SiS_Pr, int addme)
  8390. {
  8391. unsigned short index = 0, temp = 0;
  8392. if(SiS_Pr->SiS_TVMode & TVSetPAL) index = 1;
  8393. if(SiS_Pr->SiS_TVMode & TVSetPALM) index = 2;
  8394. if(SiS_Pr->SiS_TVMode & TVSetPALN) index = 3;
  8395. if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) index = 6;
  8396. if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) {
  8397. index = 4;
  8398. if(SiS_Pr->SiS_TVMode & TVSetPALM) index++;
  8399. if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) index = 7;
  8400. }
  8401. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  8402. if((!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) ||
  8403. (SiS_Pr->SiS_TVMode & TVSetTVSimuMode)) {
  8404. index += addme;
  8405. temp++;
  8406. }
  8407. temp += 0x0100;
  8408. }
  8409. return (unsigned int)(index | (temp << 16));
  8410. }
  8411. static unsigned int
  8412. GetOEMTVPtr661_2_OLD(struct SiS_Private *SiS_Pr)
  8413. {
  8414. return (GetOEMTVPtr661_2_GEN(SiS_Pr, 8));
  8415. }
  8416. #if 0
  8417. static unsigned int
  8418. GetOEMTVPtr661_2_NEW(struct SiS_Private *SiS_Pr)
  8419. {
  8420. return (GetOEMTVPtr661_2_GEN(SiS_Pr, 6));
  8421. }
  8422. #endif
  8423. static int
  8424. GetOEMTVPtr661(struct SiS_Private *SiS_Pr)
  8425. {
  8426. int index = 0;
  8427. if(SiS_Pr->SiS_TVMode & TVSetPAL) index = 2;
  8428. if(SiS_Pr->SiS_ROMNew) {
  8429. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525i) index = 4;
  8430. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) index = 6;
  8431. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) index = 8;
  8432. if(SiS_Pr->SiS_TVMode & TVSetHiVision) index = 10;
  8433. } else {
  8434. if(SiS_Pr->SiS_TVMode & TVSetHiVision) index = 4;
  8435. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525i) index = 6;
  8436. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) index = 8;
  8437. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) index = 10;
  8438. }
  8439. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) index++;
  8440. return index;
  8441. }
  8442. static void
  8443. SetDelayComp(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
  8444. {
  8445. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  8446. unsigned short delay=0,index,myindex,temp,romptr=0;
  8447. bool dochiptest = true;
  8448. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  8449. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x20,0xbf);
  8450. } else {
  8451. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x35,0x7f);
  8452. }
  8453. /* Find delay (from ROM, internal tables, PCI subsystem) */
  8454. if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) { /* ------------ VGA */
  8455. if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
  8456. romptr = GetRAMDACromptr(SiS_Pr);
  8457. }
  8458. if(romptr) delay = ROMAddr[romptr];
  8459. else {
  8460. delay = 0x04;
  8461. if(SiS_Pr->SiS_VBType & VB_SIS30xB) {
  8462. if(IS_SIS650) {
  8463. delay = 0x0a;
  8464. } else if(IS_SIS740) {
  8465. delay = 0x00;
  8466. } else if(SiS_Pr->ChipType < SIS_330) {
  8467. delay = 0x0c;
  8468. } else {
  8469. delay = 0x0c;
  8470. }
  8471. } else if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  8472. delay = 0x00;
  8473. }
  8474. }
  8475. } else if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD|SetCRT2ToLCDA)) { /* ---------- LCD/LCDA */
  8476. bool gotitfrompci = false;
  8477. /* Could we detect a PDC for LCD or did we get a user-defined? If yes, use it */
  8478. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  8479. if(SiS_Pr->PDC != -1) {
  8480. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0xf0,((SiS_Pr->PDC >> 1) & 0x0f));
  8481. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x35,0x7f,((SiS_Pr->PDC & 0x01) << 7));
  8482. return;
  8483. }
  8484. } else {
  8485. if(SiS_Pr->PDCA != -1) {
  8486. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0x0f,((SiS_Pr->PDCA << 3) & 0xf0));
  8487. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x20,0xbf,((SiS_Pr->PDCA & 0x01) << 6));
  8488. return;
  8489. }
  8490. }
  8491. /* Custom Panel? */
  8492. if(SiS_Pr->SiS_LCDResInfo == Panel_Custom) {
  8493. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  8494. delay = 0x00;
  8495. if((SiS_Pr->PanelXRes <= 1280) && (SiS_Pr->PanelYRes <= 1024)) {
  8496. delay = 0x20;
  8497. }
  8498. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0x0f,delay);
  8499. } else {
  8500. delay = 0x0c;
  8501. if(SiS_Pr->SiS_VBType & VB_SIS301C) {
  8502. delay = 0x03;
  8503. if((SiS_Pr->PanelXRes > 1280) && (SiS_Pr->PanelYRes > 1024)) {
  8504. delay = 0x00;
  8505. }
  8506. } else if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  8507. if(IS_SIS740) delay = 0x01;
  8508. else delay = 0x03;
  8509. }
  8510. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0xf0,delay);
  8511. }
  8512. return;
  8513. }
  8514. /* This is a piece of typical SiS crap: They code the OEM LCD
  8515. * delay into the code, at no defined place in the BIOS.
  8516. * We now have to start doing a PCI subsystem check here.
  8517. */
  8518. switch(SiS_Pr->SiS_CustomT) {
  8519. case CUT_COMPAQ1280:
  8520. case CUT_COMPAQ12802:
  8521. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) {
  8522. gotitfrompci = true;
  8523. dochiptest = false;
  8524. delay = 0x03;
  8525. }
  8526. break;
  8527. case CUT_CLEVO1400:
  8528. case CUT_CLEVO14002:
  8529. gotitfrompci = true;
  8530. dochiptest = false;
  8531. delay = 0x02;
  8532. break;
  8533. case CUT_CLEVO1024:
  8534. case CUT_CLEVO10242:
  8535. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  8536. gotitfrompci = true;
  8537. dochiptest = false;
  8538. delay = 0x33;
  8539. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2D,delay);
  8540. delay &= 0x0f;
  8541. }
  8542. break;
  8543. }
  8544. /* Could we find it through the PCI ID? If no, use ROM or table */
  8545. if(!gotitfrompci) {
  8546. index = GetLCDPtrIndexBIOS(SiS_Pr);
  8547. myindex = GetLCDPtrIndex(SiS_Pr);
  8548. if(IS_SIS650 && (SiS_Pr->SiS_VBType & VB_SISLVDS)) {
  8549. if(SiS_IsNotM650orLater(SiS_Pr)) {
  8550. if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
  8551. /* Always use the second pointer on 650; some BIOSes */
  8552. /* still carry old 301 data at the first location */
  8553. /* romptr = SISGETROMW(0x120); */
  8554. /* if(SiS_Pr->SiS_VBType & VB_SIS302LV) */
  8555. romptr = SISGETROMW(0x122);
  8556. if(!romptr) return;
  8557. delay = ROMAddr[(romptr + index)];
  8558. } else {
  8559. delay = SiS310_LCDDelayCompensation_650301LV[myindex];
  8560. }
  8561. } else {
  8562. delay = SiS310_LCDDelayCompensation_651301LV[myindex];
  8563. if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV))
  8564. delay = SiS310_LCDDelayCompensation_651302LV[myindex];
  8565. }
  8566. } else if(SiS_Pr->SiS_UseROM &&
  8567. (!(SiS_Pr->SiS_ROMNew)) &&
  8568. (SiS_Pr->SiS_LCDResInfo != Panel_1280x1024) &&
  8569. (SiS_Pr->SiS_LCDResInfo != Panel_1280x768) &&
  8570. (SiS_Pr->SiS_LCDResInfo != Panel_1280x960) &&
  8571. (SiS_Pr->SiS_LCDResInfo != Panel_1600x1200) &&
  8572. ((romptr = GetLCDromptr(SiS_Pr)))) {
  8573. /* Data for 1280x1024 wrong in 301B BIOS */
  8574. /* Data for 1600x1200 wrong in 301C BIOS */
  8575. delay = ROMAddr[(romptr + index)];
  8576. } else if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  8577. if(IS_SIS740) delay = 0x03;
  8578. else delay = 0x00;
  8579. } else {
  8580. delay = SiS310_LCDDelayCompensation_301[myindex];
  8581. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  8582. if(IS_SIS740) delay = 0x01;
  8583. else if(SiS_Pr->ChipType <= SIS_315PRO) delay = SiS310_LCDDelayCompensation_3xx301LV[myindex];
  8584. else delay = SiS310_LCDDelayCompensation_650301LV[myindex];
  8585. } else if(SiS_Pr->SiS_VBType & VB_SIS301C) {
  8586. if(IS_SIS740) delay = 0x01; /* ? */
  8587. else delay = 0x03;
  8588. if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) delay = 0x00; /* experience */
  8589. } else if(SiS_Pr->SiS_VBType & VB_SIS30xB) {
  8590. if(IS_SIS740) delay = 0x01;
  8591. else delay = SiS310_LCDDelayCompensation_3xx301B[myindex];
  8592. }
  8593. }
  8594. } /* got it from PCI */
  8595. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  8596. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,0x0F,((delay << 4) & 0xf0));
  8597. dochiptest = false;
  8598. }
  8599. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { /* ------------ TV */
  8600. index = GetTVPtrIndex(SiS_Pr);
  8601. if(IS_SIS650 && (SiS_Pr->SiS_VBType & VB_SISLVDS)) {
  8602. if(SiS_IsNotM650orLater(SiS_Pr)) {
  8603. if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
  8604. /* Always use the second pointer on 650; some BIOSes */
  8605. /* still carry old 301 data at the first location */
  8606. /* romptr = SISGETROMW(0x114); */
  8607. /* if(SiS_Pr->SiS_VBType & VB_SIS302LV) */
  8608. romptr = SISGETROMW(0x11a);
  8609. if(!romptr) return;
  8610. delay = ROMAddr[romptr + index];
  8611. } else {
  8612. delay = SiS310_TVDelayCompensation_301B[index];
  8613. }
  8614. } else {
  8615. switch(SiS_Pr->SiS_CustomT) {
  8616. case CUT_COMPAQ1280:
  8617. case CUT_COMPAQ12802:
  8618. case CUT_CLEVO1400:
  8619. case CUT_CLEVO14002:
  8620. delay = 0x02;
  8621. dochiptest = false;
  8622. break;
  8623. case CUT_CLEVO1024:
  8624. case CUT_CLEVO10242:
  8625. delay = 0x03;
  8626. dochiptest = false;
  8627. break;
  8628. default:
  8629. delay = SiS310_TVDelayCompensation_651301LV[index];
  8630. if(SiS_Pr->SiS_VBType & VB_SIS302LV) {
  8631. delay = SiS310_TVDelayCompensation_651302LV[index];
  8632. }
  8633. }
  8634. }
  8635. } else if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
  8636. romptr = GetTVromptr(SiS_Pr);
  8637. if(!romptr) return;
  8638. delay = ROMAddr[romptr + index];
  8639. } else if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  8640. delay = SiS310_TVDelayCompensation_LVDS[index];
  8641. } else {
  8642. delay = SiS310_TVDelayCompensation_301[index];
  8643. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  8644. if(IS_SIS740) {
  8645. delay = SiS310_TVDelayCompensation_740301B[index];
  8646. /* LV: use 301 data? BIOS bug? */
  8647. } else {
  8648. delay = SiS310_TVDelayCompensation_301B[index];
  8649. if(SiS_Pr->SiS_VBType & VB_SIS301C) delay = 0x02;
  8650. }
  8651. }
  8652. }
  8653. if(SiS_LCDAEnabled(SiS_Pr)) {
  8654. delay &= 0x0f;
  8655. dochiptest = false;
  8656. }
  8657. } else return;
  8658. /* Write delay */
  8659. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  8660. if(IS_SIS650 && (SiS_Pr->SiS_VBType & VB_SISLVDS) && dochiptest) {
  8661. temp = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) & 0xf0) >> 4;
  8662. if(temp == 8) { /* 1400x1050 BIOS (COMPAL) */
  8663. delay &= 0x0f;
  8664. delay |= 0xb0;
  8665. } else if(temp == 6) {
  8666. delay &= 0x0f;
  8667. delay |= 0xc0;
  8668. } else if(temp > 7) { /* 1280x1024 BIOS (which one?) */
  8669. delay = 0x35;
  8670. }
  8671. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2D,delay);
  8672. } else {
  8673. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,0xF0,delay);
  8674. }
  8675. } else { /* LVDS */
  8676. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  8677. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,0xF0,delay);
  8678. } else {
  8679. if(IS_SIS650 && (SiS_Pr->SiS_IF_DEF_CH70xx != 0)) {
  8680. delay <<= 4;
  8681. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,0x0F,delay);
  8682. } else {
  8683. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,0xF0,delay);
  8684. }
  8685. }
  8686. }
  8687. }
  8688. static void
  8689. SetAntiFlicker(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  8690. {
  8691. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  8692. unsigned short index,temp,temp1,romptr=0;
  8693. if(SiS_Pr->SiS_TVMode & (TVSetYPbPr750p|TVSetYPbPr525p)) return;
  8694. if(ModeNo<=0x13)
  8695. index = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].VB_StTVFlickerIndex;
  8696. else
  8697. index = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].VB_ExtTVFlickerIndex;
  8698. temp = GetTVPtrIndex(SiS_Pr);
  8699. temp >>= 1; /* 0: NTSC/YPbPr, 1: PAL, 2: HiTV */
  8700. temp1 = temp;
  8701. if(SiS_Pr->SiS_UseROM && (!(SiS_Pr->SiS_ROMNew))) {
  8702. if(SiS_Pr->ChipType >= SIS_661) {
  8703. temp1 = GetOEMTVPtr661(SiS_Pr);
  8704. temp1 >>= 1;
  8705. romptr = SISGETROMW(0x260);
  8706. if(SiS_Pr->ChipType >= SIS_760) {
  8707. romptr = SISGETROMW(0x360);
  8708. }
  8709. } else if(SiS_Pr->ChipType >= SIS_330) {
  8710. romptr = SISGETROMW(0x192);
  8711. } else {
  8712. romptr = SISGETROMW(0x112);
  8713. }
  8714. }
  8715. if(romptr) {
  8716. temp1 <<= 1;
  8717. temp = ROMAddr[romptr + temp1 + index];
  8718. } else {
  8719. temp = SiS310_TVAntiFlick1[temp][index];
  8720. }
  8721. temp <<= 4;
  8722. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x0A,0x8f,temp); /* index 0A D[6:4] */
  8723. }
  8724. static void
  8725. SetEdgeEnhance(struct SiS_Private *SiS_Pr, unsigned short ModeNo,unsigned short ModeIdIndex)
  8726. {
  8727. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  8728. unsigned short index,temp,temp1,romptr=0;
  8729. temp = temp1 = GetTVPtrIndex(SiS_Pr) >> 1; /* 0: NTSC/YPbPr, 1: PAL, 2: HiTV */
  8730. if(ModeNo <= 0x13)
  8731. index = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].VB_StTVEdgeIndex;
  8732. else
  8733. index = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].VB_ExtTVEdgeIndex;
  8734. if(SiS_Pr->SiS_UseROM && (!(SiS_Pr->SiS_ROMNew))) {
  8735. if(SiS_Pr->ChipType >= SIS_661) {
  8736. romptr = SISGETROMW(0x26c);
  8737. if(SiS_Pr->ChipType >= SIS_760) {
  8738. romptr = SISGETROMW(0x36c);
  8739. }
  8740. temp1 = GetOEMTVPtr661(SiS_Pr);
  8741. temp1 >>= 1;
  8742. } else if(SiS_Pr->ChipType >= SIS_330) {
  8743. romptr = SISGETROMW(0x1a4);
  8744. } else {
  8745. romptr = SISGETROMW(0x124);
  8746. }
  8747. }
  8748. if(romptr) {
  8749. temp1 <<= 1;
  8750. temp = ROMAddr[romptr + temp1 + index];
  8751. } else {
  8752. temp = SiS310_TVEdge1[temp][index];
  8753. }
  8754. temp <<= 5;
  8755. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x3A,0x1F,temp); /* index 0A D[7:5] */
  8756. }
  8757. static void
  8758. SetYFilter(struct SiS_Private *SiS_Pr, unsigned short ModeNo,unsigned short ModeIdIndex)
  8759. {
  8760. unsigned short index, temp, i, j;
  8761. if(ModeNo <= 0x13) {
  8762. index = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].VB_StTVYFilterIndex;
  8763. } else {
  8764. index = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].VB_ExtTVYFilterIndex;
  8765. }
  8766. temp = GetTVPtrIndex(SiS_Pr) >> 1; /* 0: NTSC/YPbPr, 1: PAL, 2: HiTV */
  8767. if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) temp = 1; /* NTSC-J uses PAL */
  8768. else if(SiS_Pr->SiS_TVMode & TVSetPALM) temp = 3; /* PAL-M */
  8769. else if(SiS_Pr->SiS_TVMode & TVSetPALN) temp = 4; /* PAL-N */
  8770. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) temp = 1; /* HiVision uses PAL */
  8771. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  8772. for(i=0x35, j=0; i<=0x38; i++, j++) {
  8773. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVYFilter2[temp][index][j]);
  8774. }
  8775. for(i=0x48; i<=0x4A; i++, j++) {
  8776. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVYFilter2[temp][index][j]);
  8777. }
  8778. } else {
  8779. for(i=0x35, j=0; i<=0x38; i++, j++) {
  8780. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVYFilter1[temp][index][j]);
  8781. }
  8782. }
  8783. }
  8784. static void
  8785. SetPhaseIncr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  8786. {
  8787. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  8788. unsigned short index,temp,i,j,resinfo,romptr=0;
  8789. unsigned int lindex;
  8790. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) return;
  8791. /* NTSC-J data not in BIOS, and already set in SetGroup2 */
  8792. if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) return;
  8793. if((SiS_Pr->ChipType >= SIS_661) || SiS_Pr->SiS_ROMNew) {
  8794. lindex = GetOEMTVPtr661_2_OLD(SiS_Pr) & 0xffff;
  8795. lindex <<= 2;
  8796. for(j=0, i=0x31; i<=0x34; i++, j++) {
  8797. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS_TVPhase[lindex + j]);
  8798. }
  8799. return;
  8800. }
  8801. /* PAL-M, PAL-N not in BIOS, and already set in SetGroup2 */
  8802. if(SiS_Pr->SiS_TVMode & (TVSetPALM | TVSetPALN)) return;
  8803. if(ModeNo<=0x13) {
  8804. resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
  8805. } else {
  8806. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  8807. }
  8808. temp = GetTVPtrIndex(SiS_Pr);
  8809. /* 0: NTSC Graphics, 1: NTSC Text, 2: PAL Graphics,
  8810. * 3: PAL Text, 4: HiTV Graphics 5: HiTV Text
  8811. */
  8812. if(SiS_Pr->SiS_UseROM) {
  8813. romptr = SISGETROMW(0x116);
  8814. if(SiS_Pr->ChipType >= SIS_330) {
  8815. romptr = SISGETROMW(0x196);
  8816. }
  8817. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  8818. romptr = SISGETROMW(0x11c);
  8819. if(SiS_Pr->ChipType >= SIS_330) {
  8820. romptr = SISGETROMW(0x19c);
  8821. }
  8822. if((SiS_Pr->SiS_VBInfo & SetInSlaveMode) && (!(SiS_Pr->SiS_TVMode & TVSetTVSimuMode))) {
  8823. romptr = SISGETROMW(0x116);
  8824. if(SiS_Pr->ChipType >= SIS_330) {
  8825. romptr = SISGETROMW(0x196);
  8826. }
  8827. }
  8828. }
  8829. }
  8830. if(romptr) {
  8831. romptr += (temp << 2);
  8832. for(j=0, i=0x31; i<=0x34; i++, j++) {
  8833. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,ROMAddr[romptr + j]);
  8834. }
  8835. } else {
  8836. index = temp % 2;
  8837. temp >>= 1; /* 0:NTSC, 1:PAL, 2:HiTV */
  8838. for(j=0, i=0x31; i<=0x34; i++, j++) {
  8839. if(!(SiS_Pr->SiS_VBType & VB_SIS30xBLV))
  8840. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVPhaseIncr1[temp][index][j]);
  8841. else if((!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) || (SiS_Pr->SiS_TVMode & TVSetTVSimuMode))
  8842. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVPhaseIncr2[temp][index][j]);
  8843. else
  8844. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVPhaseIncr1[temp][index][j]);
  8845. }
  8846. }
  8847. if((SiS_Pr->SiS_VBType & VB_SIS30xBLV) && (!(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision))) {
  8848. if((!(SiS_Pr->SiS_TVMode & (TVSetPAL | TVSetYPbPr525p | TVSetYPbPr750p))) && (ModeNo > 0x13)) {
  8849. if((resinfo == SIS_RI_640x480) ||
  8850. (resinfo == SIS_RI_800x600)) {
  8851. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x31,0x21);
  8852. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x32,0xf0);
  8853. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x33,0xf5);
  8854. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x34,0x7f);
  8855. } else if(resinfo == SIS_RI_1024x768) {
  8856. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x31,0x1e);
  8857. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x32,0x8b);
  8858. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x33,0xfb);
  8859. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x34,0x7b);
  8860. }
  8861. }
  8862. }
  8863. }
  8864. static void
  8865. SetDelayComp661(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
  8866. unsigned short ModeIdIndex, unsigned short RTI)
  8867. {
  8868. unsigned short delay = 0, romptr = 0, index, lcdpdcindex;
  8869. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  8870. if(!(SiS_Pr->SiS_VBInfo & (SetCRT2ToTV | SetCRT2ToLCD | SetCRT2ToLCDA | SetCRT2ToRAMDAC)))
  8871. return;
  8872. /* 1. New ROM: VGA2 and LCD/LCDA-Pass1:1 */
  8873. /* (If a custom mode is used, Pass1:1 is always set; hence we do this:) */
  8874. if(SiS_Pr->SiS_ROMNew) {
  8875. if((SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) ||
  8876. ((SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) &&
  8877. (SiS_Pr->SiS_LCDInfo & LCDPass11))) {
  8878. index = 25;
  8879. if(SiS_Pr->UseCustomMode) {
  8880. index = SiS_Pr->CSRClock;
  8881. } else if(ModeNo > 0x13) {
  8882. index = SiS_GetVCLK2Ptr(SiS_Pr,ModeNo,ModeIdIndex,RTI);
  8883. index = SiS_Pr->SiS_VCLKData[index].CLOCK;
  8884. }
  8885. if(index < 25) index = 25;
  8886. index = ((index / 25) - 1) << 1;
  8887. if((ROMAddr[0x5b] & 0x80) || (SiS_Pr->SiS_VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD))) {
  8888. index++;
  8889. }
  8890. romptr = SISGETROMW(0x104);
  8891. delay = ROMAddr[romptr + index];
  8892. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD)) {
  8893. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0xf0,((delay >> 1) & 0x0f));
  8894. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x35,0x7f,((delay & 0x01) << 7));
  8895. } else {
  8896. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0x0f,((delay << 3) & 0xf0));
  8897. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x20,0xbf,((delay & 0x01) << 6));
  8898. }
  8899. return;
  8900. }
  8901. }
  8902. /* 2. Old ROM: VGA2 and LCD/LCDA-Pass 1:1 */
  8903. if(SiS_Pr->UseCustomMode) delay = 0x04;
  8904. else if(ModeNo <= 0x13) delay = 0x04;
  8905. else delay = (SiS_Pr->SiS_RefIndex[RTI].Ext_PDC >> 4);
  8906. delay |= (delay << 8);
  8907. if(SiS_Pr->ChipType >= XGI_20) {
  8908. delay = 0x0606;
  8909. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  8910. delay = 0x0404;
  8911. if(SiS_Pr->SiS_XGIROM) {
  8912. index = GetTVPtrIndex(SiS_Pr);
  8913. if((romptr = SISGETROMW(0x35e))) {
  8914. delay = (ROMAddr[romptr + index] & 0x0f) << 1;
  8915. delay |= (delay << 8);
  8916. }
  8917. }
  8918. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  8919. if(SiS_Pr->ChipType == XGI_40 && SiS_Pr->ChipRevision == 0x02) {
  8920. delay -= 0x0404;
  8921. }
  8922. }
  8923. }
  8924. } else if(SiS_Pr->ChipType >= SIS_340) {
  8925. delay = 0x0606;
  8926. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  8927. delay = 0x0404;
  8928. }
  8929. /* TODO (eventually) */
  8930. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  8931. /* 3. TV */
  8932. index = GetOEMTVPtr661(SiS_Pr);
  8933. if(SiS_Pr->SiS_ROMNew) {
  8934. romptr = SISGETROMW(0x106);
  8935. if(SiS_Pr->SiS_VBType & VB_UMC) romptr += 12;
  8936. delay = ROMAddr[romptr + index];
  8937. } else {
  8938. delay = 0x04;
  8939. if(index > 3) delay = 0;
  8940. }
  8941. } else if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  8942. /* 4. LCD, LCDA (for new ROM only LV and non-Pass 1:1) */
  8943. if( (SiS_Pr->SiS_LCDResInfo != Panel_Custom) &&
  8944. ((romptr = GetLCDStructPtr661_2(SiS_Pr))) ) {
  8945. lcdpdcindex = (SiS_Pr->SiS_VBType & VB_UMC) ? 14 : 12;
  8946. /* For LVDS (and sometimes TMDS), the BIOS must know about the correct value */
  8947. delay = ROMAddr[romptr + lcdpdcindex + 1]; /* LCD */
  8948. delay |= (ROMAddr[romptr + lcdpdcindex] << 8); /* LCDA */
  8949. } else {
  8950. /* TMDS: Set our own, since BIOS has no idea */
  8951. /* (This is done on >=661 only, since <661 is calling this only for LVDS) */
  8952. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  8953. switch(SiS_Pr->SiS_LCDResInfo) {
  8954. case Panel_1024x768: delay = 0x0008; break;
  8955. case Panel_1280x720: delay = 0x0004; break;
  8956. case Panel_1280x768:
  8957. case Panel_1280x768_2:delay = 0x0004; break;
  8958. case Panel_1280x800:
  8959. case Panel_1280x800_2:delay = 0x0004; break; /* Verified for 1280x800 */
  8960. case Panel_1280x854: delay = 0x0004; break; /* FIXME */
  8961. case Panel_1280x1024: delay = 0x1e04; break;
  8962. case Panel_1400x1050: delay = 0x0004; break;
  8963. case Panel_1600x1200: delay = 0x0400; break;
  8964. case Panel_1680x1050: delay = 0x0e04; break;
  8965. default:
  8966. if((SiS_Pr->PanelXRes <= 1024) && (SiS_Pr->PanelYRes <= 768)) {
  8967. delay = 0x0008;
  8968. } else if((SiS_Pr->PanelXRes == 1280) && (SiS_Pr->PanelYRes == 1024)) {
  8969. delay = 0x1e04;
  8970. } else if((SiS_Pr->PanelXRes <= 1400) && (SiS_Pr->PanelYRes <= 1050)) {
  8971. delay = 0x0004;
  8972. } else if((SiS_Pr->PanelXRes <= 1600) && (SiS_Pr->PanelYRes <= 1200)) {
  8973. delay = 0x0400;
  8974. } else
  8975. delay = 0x0e04;
  8976. break;
  8977. }
  8978. }
  8979. /* Override by detected or user-set values */
  8980. /* (but only if, for some reason, we can't read value from BIOS) */
  8981. if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && (SiS_Pr->PDC != -1)) {
  8982. delay = SiS_Pr->PDC & 0x1f;
  8983. }
  8984. if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) && (SiS_Pr->PDCA != -1)) {
  8985. delay = (SiS_Pr->PDCA & 0x1f) << 8;
  8986. }
  8987. }
  8988. }
  8989. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  8990. delay >>= 8;
  8991. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0x0f,((delay << 3) & 0xf0));
  8992. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x20,0xbf,((delay & 0x01) << 6));
  8993. } else {
  8994. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0xf0,((delay >> 1) & 0x0f));
  8995. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x35,0x7f,((delay & 0x01) << 7));
  8996. }
  8997. }
  8998. static void
  8999. SetCRT2SyncDither661(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short RTI)
  9000. {
  9001. unsigned short infoflag;
  9002. unsigned char temp;
  9003. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  9004. if(ModeNo <= 0x13) {
  9005. infoflag = SiS_GetRegByte(SiS_Pr->SiS_P3ca+2);
  9006. } else if(SiS_Pr->UseCustomMode) {
  9007. infoflag = SiS_Pr->CInfoFlag;
  9008. } else {
  9009. infoflag = SiS_Pr->SiS_RefIndex[RTI].Ext_InfoFlag;
  9010. }
  9011. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  9012. infoflag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x37); /* No longer check D5 */
  9013. }
  9014. infoflag &= 0xc0;
  9015. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  9016. temp = (infoflag >> 6) | 0x0c;
  9017. if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) {
  9018. temp ^= 0x04;
  9019. if(SiS_Pr->SiS_ModeType >= Mode24Bpp) temp |= 0x10;
  9020. }
  9021. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1a,0xe0,temp);
  9022. } else {
  9023. temp = 0x30;
  9024. if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) temp = 0x20;
  9025. temp |= infoflag;
  9026. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0f,temp);
  9027. temp = 0;
  9028. if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) {
  9029. if(SiS_Pr->SiS_ModeType >= Mode24Bpp) temp |= 0x80;
  9030. }
  9031. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x1a,0x7f,temp);
  9032. }
  9033. }
  9034. }
  9035. static void
  9036. SetPanelParms661(struct SiS_Private *SiS_Pr)
  9037. {
  9038. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  9039. unsigned short romptr, temp1, temp2;
  9040. if(SiS_Pr->SiS_VBType & (VB_SISLVDS | VB_SIS30xC)) {
  9041. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x24,0x0f);
  9042. }
  9043. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  9044. if(SiS_Pr->LVDSHL != -1) {
  9045. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,0xfc,SiS_Pr->LVDSHL);
  9046. }
  9047. }
  9048. if(SiS_Pr->SiS_ROMNew) {
  9049. if((romptr = GetLCDStructPtr661_2(SiS_Pr))) {
  9050. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  9051. temp1 = (ROMAddr[romptr] & 0x03) | 0x0c;
  9052. temp2 = 0xfc;
  9053. if(SiS_Pr->LVDSHL != -1) {
  9054. temp1 &= 0xfc;
  9055. temp2 = 0xf3;
  9056. }
  9057. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,temp2,temp1);
  9058. }
  9059. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  9060. temp1 = (ROMAddr[romptr + 1] & 0x80) >> 1;
  9061. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x0d,0xbf,temp1);
  9062. }
  9063. }
  9064. }
  9065. }
  9066. static void
  9067. SiS_OEM310Setting(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex, unsigned short RRTI)
  9068. {
  9069. if((SiS_Pr->SiS_ROMNew) && (SiS_Pr->SiS_VBType & VB_SISLVDS)) {
  9070. SetDelayComp661(SiS_Pr, ModeNo, ModeIdIndex, RRTI);
  9071. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  9072. SetCRT2SyncDither661(SiS_Pr, ModeNo, RRTI);
  9073. SetPanelParms661(SiS_Pr);
  9074. }
  9075. } else {
  9076. SetDelayComp(SiS_Pr,ModeNo);
  9077. }
  9078. if((SiS_Pr->SiS_VBType & VB_SISVB) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
  9079. SetAntiFlicker(SiS_Pr,ModeNo,ModeIdIndex);
  9080. SetPhaseIncr(SiS_Pr,ModeNo,ModeIdIndex);
  9081. SetYFilter(SiS_Pr,ModeNo,ModeIdIndex);
  9082. if(SiS_Pr->SiS_VBType & VB_SIS301) {
  9083. SetEdgeEnhance(SiS_Pr,ModeNo,ModeIdIndex);
  9084. }
  9085. }
  9086. }
  9087. static void
  9088. SiS_OEM661Setting(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
  9089. unsigned short ModeIdIndex, unsigned short RRTI)
  9090. {
  9091. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  9092. SetDelayComp661(SiS_Pr, ModeNo, ModeIdIndex, RRTI);
  9093. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  9094. SetCRT2SyncDither661(SiS_Pr, ModeNo, RRTI);
  9095. SetPanelParms661(SiS_Pr);
  9096. }
  9097. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  9098. SetPhaseIncr(SiS_Pr, ModeNo, ModeIdIndex);
  9099. SetYFilter(SiS_Pr, ModeNo, ModeIdIndex);
  9100. SetAntiFlicker(SiS_Pr, ModeNo, ModeIdIndex);
  9101. if(SiS_Pr->SiS_VBType & VB_SIS301) {
  9102. SetEdgeEnhance(SiS_Pr, ModeNo, ModeIdIndex);
  9103. }
  9104. }
  9105. }
  9106. }
  9107. /* FinalizeLCD
  9108. * This finalizes some CRT2 registers for the very panel used.
  9109. * If we have a backup if these registers, we use it; otherwise
  9110. * we set the register according to most BIOSes. However, this
  9111. * function looks quite different in every BIOS, so you better
  9112. * pray that we have a backup...
  9113. */
  9114. static void
  9115. SiS_FinalizeLCD(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  9116. {
  9117. unsigned short tempcl,tempch,tempbl,tempbh,tempbx,tempax,temp;
  9118. unsigned short resinfo,modeflag;
  9119. if(!(SiS_Pr->SiS_VBType & VB_SISLVDS)) return;
  9120. if(SiS_Pr->SiS_ROMNew) return;
  9121. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  9122. if(SiS_Pr->LVDSHL != -1) {
  9123. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,0xfc,SiS_Pr->LVDSHL);
  9124. }
  9125. }
  9126. if(SiS_Pr->SiS_LCDResInfo == Panel_Custom) return;
  9127. if(SiS_Pr->UseCustomMode) return;
  9128. switch(SiS_Pr->SiS_CustomT) {
  9129. case CUT_COMPAQ1280:
  9130. case CUT_COMPAQ12802:
  9131. case CUT_CLEVO1400:
  9132. case CUT_CLEVO14002:
  9133. return;
  9134. }
  9135. if(ModeNo <= 0x13) {
  9136. resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
  9137. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  9138. } else {
  9139. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  9140. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  9141. }
  9142. if(IS_SIS650) {
  9143. if(!(SiS_GetReg(SiS_Pr->SiS_P3d4, 0x5f) & 0xf0)) {
  9144. if(SiS_Pr->SiS_CustomT == CUT_CLEVO1024) {
  9145. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1e,0x02);
  9146. } else {
  9147. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1e,0x03);
  9148. }
  9149. }
  9150. }
  9151. if(SiS_Pr->SiS_CustomT == CUT_CLEVO1024) {
  9152. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  9153. /* Maybe all panels? */
  9154. if(SiS_Pr->LVDSHL == -1) {
  9155. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,0xfc,0x01);
  9156. }
  9157. return;
  9158. }
  9159. }
  9160. if(SiS_Pr->SiS_CustomT == CUT_CLEVO10242) {
  9161. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  9162. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  9163. if(SiS_Pr->LVDSHL == -1) {
  9164. /* Maybe all panels? */
  9165. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,0xfc,0x01);
  9166. }
  9167. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  9168. tempch = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4;
  9169. if(tempch == 3) {
  9170. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x02);
  9171. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,0x25);
  9172. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1c,0x00);
  9173. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1d,0x1b);
  9174. }
  9175. }
  9176. return;
  9177. }
  9178. }
  9179. }
  9180. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  9181. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  9182. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  9183. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2a,0x00);
  9184. #ifdef SET_EMI
  9185. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
  9186. #endif
  9187. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x34,0x10);
  9188. }
  9189. } else if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) {
  9190. if(SiS_Pr->LVDSHL == -1) {
  9191. /* Maybe ACER only? */
  9192. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,0xfc,0x01);
  9193. }
  9194. }
  9195. tempch = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4;
  9196. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  9197. if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) {
  9198. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1f,0x76);
  9199. } else if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  9200. if(tempch == 0x03) {
  9201. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x02);
  9202. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,0x25);
  9203. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1c,0x00);
  9204. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1d,0x1b);
  9205. }
  9206. if(SiS_Pr->Backup && (SiS_Pr->Backup_Mode == ModeNo)) {
  9207. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x14,SiS_Pr->Backup_14);
  9208. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x15,SiS_Pr->Backup_15);
  9209. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x16,SiS_Pr->Backup_16);
  9210. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x17,SiS_Pr->Backup_17);
  9211. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,SiS_Pr->Backup_18);
  9212. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x19,SiS_Pr->Backup_19);
  9213. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1a,SiS_Pr->Backup_1a);
  9214. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,SiS_Pr->Backup_1b);
  9215. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1c,SiS_Pr->Backup_1c);
  9216. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1d,SiS_Pr->Backup_1d);
  9217. } else if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) { /* 1.10.8w */
  9218. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x14,0x90);
  9219. if(ModeNo <= 0x13) {
  9220. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x11);
  9221. if((resinfo == 0) || (resinfo == 2)) return;
  9222. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x18);
  9223. if((resinfo == 1) || (resinfo == 3)) return;
  9224. }
  9225. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x02);
  9226. if((ModeNo > 0x13) && (resinfo == SIS_RI_1024x768)) {
  9227. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x02); /* 1.10.7u */
  9228. #if 0
  9229. tempbx = 806; /* 0x326 */ /* other older BIOSes */
  9230. tempbx--;
  9231. temp = tempbx & 0xff;
  9232. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,temp);
  9233. temp = (tempbx >> 8) & 0x03;
  9234. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x1d,0xf8,temp);
  9235. #endif
  9236. }
  9237. } else if(ModeNo <= 0x13) {
  9238. if(ModeNo <= 1) {
  9239. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x70);
  9240. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x19,0xff);
  9241. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,0x48);
  9242. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1d,0x12);
  9243. }
  9244. if(!(modeflag & HalfDCLK)) {
  9245. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x14,0x20);
  9246. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x15,0x1a);
  9247. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x16,0x28);
  9248. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x17,0x00);
  9249. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x4c);
  9250. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x19,0xdc);
  9251. if(ModeNo == 0x12) {
  9252. switch(tempch) {
  9253. case 0:
  9254. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x95);
  9255. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x19,0xdc);
  9256. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1a,0x10);
  9257. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,0x95);
  9258. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1c,0x48);
  9259. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1d,0x12);
  9260. break;
  9261. case 2:
  9262. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x95);
  9263. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,0x48);
  9264. break;
  9265. case 3:
  9266. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,0x95);
  9267. break;
  9268. }
  9269. }
  9270. }
  9271. }
  9272. }
  9273. } else {
  9274. tempcl = tempbh = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x01);
  9275. tempcl &= 0x0f;
  9276. tempbh &= 0x70;
  9277. tempbh >>= 4;
  9278. tempbl = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x04);
  9279. tempbx = (tempbh << 8) | tempbl;
  9280. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  9281. if((resinfo == SIS_RI_1024x768) || (!(SiS_Pr->SiS_LCDInfo & DontExpandLCD))) {
  9282. if(SiS_Pr->SiS_SetFlag & LCDVESATiming) {
  9283. tempbx = 770;
  9284. } else {
  9285. if(tempbx > 770) tempbx = 770;
  9286. if(SiS_Pr->SiS_VGAVDE < 600) {
  9287. tempax = 768 - SiS_Pr->SiS_VGAVDE;
  9288. tempax >>= 4; /* 1.10.7w; 1.10.6s: 3; */
  9289. if(SiS_Pr->SiS_VGAVDE <= 480) tempax >>= 4; /* 1.10.7w; 1.10.6s: < 480; >>=1; */
  9290. tempbx -= tempax;
  9291. }
  9292. }
  9293. } else return;
  9294. }
  9295. temp = tempbx & 0xff;
  9296. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,temp);
  9297. temp = ((tempbx & 0xff00) >> 4) | tempcl;
  9298. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x01,0x80,temp);
  9299. }
  9300. }
  9301. }
  9302. #endif
  9303. /* ================= SiS 300 O.E.M. ================== */
  9304. #ifdef SIS300
  9305. static void
  9306. SetOEMLCDData2(struct SiS_Private *SiS_Pr, unsigned short ModeNo,unsigned short ModeIdIndex,
  9307. unsigned short RefTabIndex)
  9308. {
  9309. unsigned short crt2crtc=0, modeflag, myindex=0;
  9310. unsigned char temp;
  9311. int i;
  9312. if(ModeNo <= 0x13) {
  9313. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  9314. crt2crtc = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  9315. } else {
  9316. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  9317. crt2crtc = SiS_Pr->SiS_RefIndex[RefTabIndex].Ext_CRT2CRTC;
  9318. }
  9319. crt2crtc &= 0x3f;
  9320. if(SiS_Pr->SiS_CustomT == CUT_BARCO1024) {
  9321. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xdf);
  9322. }
  9323. if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) {
  9324. if(modeflag & HalfDCLK) myindex = 1;
  9325. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  9326. for(i=0; i<7; i++) {
  9327. if(barco_p1[myindex][crt2crtc][i][0]) {
  9328. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,
  9329. barco_p1[myindex][crt2crtc][i][0],
  9330. barco_p1[myindex][crt2crtc][i][2],
  9331. barco_p1[myindex][crt2crtc][i][1]);
  9332. }
  9333. }
  9334. }
  9335. temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00);
  9336. if(temp & 0x80) {
  9337. temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x18);
  9338. temp++;
  9339. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,temp);
  9340. }
  9341. }
  9342. }
  9343. static unsigned short
  9344. GetOEMLCDPtr(struct SiS_Private *SiS_Pr, int Flag)
  9345. {
  9346. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  9347. unsigned short tempbx=0,romptr=0;
  9348. static const unsigned char customtable300[] = {
  9349. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  9350. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
  9351. };
  9352. static const unsigned char customtable630[] = {
  9353. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  9354. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
  9355. };
  9356. if(SiS_Pr->ChipType == SIS_300) {
  9357. tempbx = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) & 0x0f;
  9358. if(SiS_Pr->SiS_VBType & VB_SIS301) tempbx &= 0x07;
  9359. tempbx -= 2;
  9360. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) tempbx += 4;
  9361. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  9362. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx += 3;
  9363. }
  9364. if(SiS_Pr->SiS_UseROM) {
  9365. if(ROMAddr[0x235] & 0x80) {
  9366. tempbx = SiS_Pr->SiS_LCDTypeInfo;
  9367. if(Flag) {
  9368. romptr = SISGETROMW(0x255);
  9369. if(romptr) tempbx = ROMAddr[romptr + SiS_Pr->SiS_LCDTypeInfo];
  9370. else tempbx = customtable300[SiS_Pr->SiS_LCDTypeInfo];
  9371. if(tempbx == 0xFF) return 0xFFFF;
  9372. }
  9373. tempbx <<= 1;
  9374. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) tempbx++;
  9375. }
  9376. }
  9377. } else {
  9378. if(Flag) {
  9379. if(SiS_Pr->SiS_UseROM) {
  9380. romptr = SISGETROMW(0x255);
  9381. if(romptr) tempbx = ROMAddr[romptr + SiS_Pr->SiS_LCDTypeInfo];
  9382. else tempbx = 0xff;
  9383. } else {
  9384. tempbx = customtable630[SiS_Pr->SiS_LCDTypeInfo];
  9385. }
  9386. if(tempbx == 0xFF) return 0xFFFF;
  9387. tempbx <<= 2;
  9388. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) tempbx += 2;
  9389. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++;
  9390. return tempbx;
  9391. }
  9392. tempbx = SiS_Pr->SiS_LCDTypeInfo << 2;
  9393. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) tempbx += 2;
  9394. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++;
  9395. }
  9396. return tempbx;
  9397. }
  9398. static void
  9399. SetOEMLCDDelay(struct SiS_Private *SiS_Pr, unsigned short ModeNo,unsigned short ModeIdIndex)
  9400. {
  9401. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  9402. unsigned short index,temp,romptr=0;
  9403. if(SiS_Pr->SiS_LCDResInfo == Panel_Custom) return;
  9404. if(SiS_Pr->SiS_UseROM) {
  9405. if(!(ROMAddr[0x237] & 0x01)) return;
  9406. if(!(ROMAddr[0x237] & 0x02)) return;
  9407. romptr = SISGETROMW(0x24b);
  9408. }
  9409. /* The Panel Compensation Delay should be set according to tables
  9410. * here. Unfortunately, various BIOS versions don't care about
  9411. * a uniform way using eg. ROM byte 0x220, but use different
  9412. * hard coded delays (0x04, 0x20, 0x18) in SetGroup1().
  9413. * Thus we don't set this if the user selected a custom pdc or if
  9414. * we otherwise detected a valid pdc.
  9415. */
  9416. if(SiS_Pr->PDC != -1) return;
  9417. temp = GetOEMLCDPtr(SiS_Pr, 0);
  9418. if(SiS_Pr->UseCustomMode)
  9419. index = 0;
  9420. else
  9421. index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].VB_LCDDelayIndex;
  9422. if(SiS_Pr->ChipType != SIS_300) {
  9423. if(romptr) {
  9424. romptr += (temp * 2);
  9425. romptr = SISGETROMW(romptr);
  9426. romptr += index;
  9427. temp = ROMAddr[romptr];
  9428. } else {
  9429. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  9430. temp = SiS300_OEMLCDDelay2[temp][index];
  9431. } else {
  9432. temp = SiS300_OEMLCDDelay3[temp][index];
  9433. }
  9434. }
  9435. } else {
  9436. if(SiS_Pr->SiS_UseROM && (ROMAddr[0x235] & 0x80)) {
  9437. if(romptr) {
  9438. romptr += (temp * 2);
  9439. romptr = SISGETROMW(romptr);
  9440. romptr += index;
  9441. temp = ROMAddr[romptr];
  9442. } else {
  9443. temp = SiS300_OEMLCDDelay5[temp][index];
  9444. }
  9445. } else {
  9446. if(SiS_Pr->SiS_UseROM) {
  9447. romptr = ROMAddr[0x249] | (ROMAddr[0x24a] << 8);
  9448. if(romptr) {
  9449. romptr += (temp * 2);
  9450. romptr = SISGETROMW(romptr);
  9451. romptr += index;
  9452. temp = ROMAddr[romptr];
  9453. } else {
  9454. temp = SiS300_OEMLCDDelay4[temp][index];
  9455. }
  9456. } else {
  9457. temp = SiS300_OEMLCDDelay4[temp][index];
  9458. }
  9459. }
  9460. }
  9461. temp &= 0x3c;
  9462. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,~0x3C,temp); /* index 0A D[6:4] */
  9463. }
  9464. static void
  9465. SetOEMLCDData(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  9466. {
  9467. #if 0 /* Unfinished; Data table missing */
  9468. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  9469. unsigned short index,temp;
  9470. if((SiS_Pr->SiS_UseROM) {
  9471. if(!(ROMAddr[0x237] & 0x01)) return;
  9472. if(!(ROMAddr[0x237] & 0x04)) return;
  9473. /* No rom pointer in BIOS header! */
  9474. }
  9475. temp = GetOEMLCDPtr(SiS_Pr, 1);
  9476. if(temp == 0xFFFF) return;
  9477. index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex]._VB_LCDHIndex;
  9478. for(i=0x14, j=0; i<=0x17; i++, j++) {
  9479. SiS_SetReg(SiS_Pr->SiS_Part1Port,i,SiS300_LCDHData[temp][index][j]);
  9480. }
  9481. SiS_SetRegANDOR(SiS_SiS_Part1Port,0x1a, 0xf8, (SiS300_LCDHData[temp][index][j] & 0x07));
  9482. index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex]._VB_LCDVIndex;
  9483. SiS_SetReg(SiS_SiS_Part1Port,0x18, SiS300_LCDVData[temp][index][0]);
  9484. SiS_SetRegANDOR(SiS_SiS_Part1Port,0x19, 0xF0, SiS300_LCDVData[temp][index][1]);
  9485. SiS_SetRegANDOR(SiS_SiS_Part1Port,0x1A, 0xC7, (SiS300_LCDVData[temp][index][2] & 0x38));
  9486. for(i=0x1b, j=3; i<=0x1d; i++, j++) {
  9487. SiS_SetReg(SiS_Pr->SiS_Part1Port,i,SiS300_LCDVData[temp][index][j]);
  9488. }
  9489. #endif
  9490. }
  9491. static unsigned short
  9492. GetOEMTVPtr(struct SiS_Private *SiS_Pr)
  9493. {
  9494. unsigned short index;
  9495. index = 0;
  9496. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) index += 4;
  9497. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  9498. if(SiS_Pr->SiS_VBInfo & SetCRT2ToSCART) index += 2;
  9499. else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) index += 3;
  9500. else if(SiS_Pr->SiS_TVMode & TVSetPAL) index += 1;
  9501. } else {
  9502. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) index += 2;
  9503. if(SiS_Pr->SiS_TVMode & TVSetPAL) index += 1;
  9504. }
  9505. return index;
  9506. }
  9507. static void
  9508. SetOEMTVDelay(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  9509. {
  9510. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  9511. unsigned short index,temp,romptr=0;
  9512. if(SiS_Pr->SiS_UseROM) {
  9513. if(!(ROMAddr[0x238] & 0x01)) return;
  9514. if(!(ROMAddr[0x238] & 0x02)) return;
  9515. romptr = SISGETROMW(0x241);
  9516. }
  9517. temp = GetOEMTVPtr(SiS_Pr);
  9518. index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].VB_TVDelayIndex;
  9519. if(romptr) {
  9520. romptr += (temp * 2);
  9521. romptr = SISGETROMW(romptr);
  9522. romptr += index;
  9523. temp = ROMAddr[romptr];
  9524. } else {
  9525. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  9526. temp = SiS300_OEMTVDelay301[temp][index];
  9527. } else {
  9528. temp = SiS300_OEMTVDelayLVDS[temp][index];
  9529. }
  9530. }
  9531. temp &= 0x3c;
  9532. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,~0x3C,temp);
  9533. }
  9534. static void
  9535. SetOEMAntiFlicker(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  9536. {
  9537. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  9538. unsigned short index,temp,romptr=0;
  9539. if(SiS_Pr->SiS_UseROM) {
  9540. if(!(ROMAddr[0x238] & 0x01)) return;
  9541. if(!(ROMAddr[0x238] & 0x04)) return;
  9542. romptr = SISGETROMW(0x243);
  9543. }
  9544. temp = GetOEMTVPtr(SiS_Pr);
  9545. index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].VB_TVFlickerIndex;
  9546. if(romptr) {
  9547. romptr += (temp * 2);
  9548. romptr = SISGETROMW(romptr);
  9549. romptr += index;
  9550. temp = ROMAddr[romptr];
  9551. } else {
  9552. temp = SiS300_OEMTVFlicker[temp][index];
  9553. }
  9554. temp &= 0x70;
  9555. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x0A,0x8F,temp);
  9556. }
  9557. static void
  9558. SetOEMPhaseIncr(struct SiS_Private *SiS_Pr, unsigned short ModeNo,unsigned short ModeIdIndex)
  9559. {
  9560. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  9561. unsigned short index,i,j,temp,romptr=0;
  9562. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) return;
  9563. if(SiS_Pr->SiS_TVMode & (TVSetNTSC1024 | TVSetNTSCJ | TVSetPALM | TVSetPALN)) return;
  9564. if(SiS_Pr->SiS_UseROM) {
  9565. if(!(ROMAddr[0x238] & 0x01)) return;
  9566. if(!(ROMAddr[0x238] & 0x08)) return;
  9567. romptr = SISGETROMW(0x245);
  9568. }
  9569. temp = GetOEMTVPtr(SiS_Pr);
  9570. index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].VB_TVPhaseIndex;
  9571. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  9572. for(i=0x31, j=0; i<=0x34; i++, j++) {
  9573. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS300_Phase2[temp][index][j]);
  9574. }
  9575. } else {
  9576. if(romptr) {
  9577. romptr += (temp * 2);
  9578. romptr = SISGETROMW(romptr);
  9579. romptr += (index * 4);
  9580. for(i=0x31, j=0; i<=0x34; i++, j++) {
  9581. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,ROMAddr[romptr + j]);
  9582. }
  9583. } else {
  9584. for(i=0x31, j=0; i<=0x34; i++, j++) {
  9585. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS300_Phase1[temp][index][j]);
  9586. }
  9587. }
  9588. }
  9589. }
  9590. static void
  9591. SetOEMYFilter(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  9592. {
  9593. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  9594. unsigned short index,temp,i,j,romptr=0;
  9595. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToSCART | SetCRT2ToHiVision | SetCRT2ToYPbPr525750)) return;
  9596. if(SiS_Pr->SiS_UseROM) {
  9597. if(!(ROMAddr[0x238] & 0x01)) return;
  9598. if(!(ROMAddr[0x238] & 0x10)) return;
  9599. romptr = SISGETROMW(0x247);
  9600. }
  9601. temp = GetOEMTVPtr(SiS_Pr);
  9602. if(SiS_Pr->SiS_TVMode & TVSetPALM) temp = 8;
  9603. else if(SiS_Pr->SiS_TVMode & TVSetPALN) temp = 9;
  9604. /* NTSCJ uses NTSC filters */
  9605. index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].VB_TVYFilterIndex;
  9606. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  9607. for(i=0x35, j=0; i<=0x38; i++, j++) {
  9608. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS300_Filter2[temp][index][j]);
  9609. }
  9610. for(i=0x48; i<=0x4A; i++, j++) {
  9611. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS300_Filter2[temp][index][j]);
  9612. }
  9613. } else {
  9614. if((romptr) && (!(SiS_Pr->SiS_TVMode & (TVSetPALM|TVSetPALN)))) {
  9615. romptr += (temp * 2);
  9616. romptr = SISGETROMW(romptr);
  9617. romptr += (index * 4);
  9618. for(i=0x35, j=0; i<=0x38; i++, j++) {
  9619. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,ROMAddr[romptr + j]);
  9620. }
  9621. } else {
  9622. for(i=0x35, j=0; i<=0x38; i++, j++) {
  9623. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS300_Filter1[temp][index][j]);
  9624. }
  9625. }
  9626. }
  9627. }
  9628. static unsigned short
  9629. SiS_SearchVBModeID(struct SiS_Private *SiS_Pr, unsigned short *ModeNo)
  9630. {
  9631. unsigned short ModeIdIndex;
  9632. unsigned char VGAINFO = SiS_Pr->SiS_VGAINFO;
  9633. if(*ModeNo <= 5) *ModeNo |= 1;
  9634. for(ModeIdIndex=0; ; ModeIdIndex++) {
  9635. if(SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].ModeID == *ModeNo) break;
  9636. if(SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].ModeID == 0xFF) return 0;
  9637. }
  9638. if(*ModeNo != 0x07) {
  9639. if(*ModeNo > 0x03) return ModeIdIndex;
  9640. if(VGAINFO & 0x80) return ModeIdIndex;
  9641. ModeIdIndex++;
  9642. }
  9643. if(VGAINFO & 0x10) ModeIdIndex++; /* 400 lines */
  9644. /* else 350 lines */
  9645. return ModeIdIndex;
  9646. }
  9647. static void
  9648. SiS_OEM300Setting(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  9649. unsigned short RefTableIndex)
  9650. {
  9651. unsigned short OEMModeIdIndex = 0;
  9652. if(!SiS_Pr->UseCustomMode) {
  9653. OEMModeIdIndex = SiS_SearchVBModeID(SiS_Pr,&ModeNo);
  9654. if(!(OEMModeIdIndex)) return;
  9655. }
  9656. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  9657. SetOEMLCDDelay(SiS_Pr, ModeNo, OEMModeIdIndex);
  9658. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  9659. SetOEMLCDData(SiS_Pr, ModeNo, OEMModeIdIndex);
  9660. }
  9661. }
  9662. if(SiS_Pr->UseCustomMode) return;
  9663. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  9664. SetOEMTVDelay(SiS_Pr, ModeNo,OEMModeIdIndex);
  9665. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  9666. SetOEMAntiFlicker(SiS_Pr, ModeNo, OEMModeIdIndex);
  9667. SetOEMPhaseIncr(SiS_Pr, ModeNo, OEMModeIdIndex);
  9668. SetOEMYFilter(SiS_Pr, ModeNo, OEMModeIdIndex);
  9669. }
  9670. }
  9671. }
  9672. #endif