init.c 106 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656
  1. /* $XFree86$ */
  2. /* $XdotOrg$ */
  3. /*
  4. * Mode initializing code (CRT1 section) for
  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 Volari 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. #include "init.h"
  59. #ifdef CONFIG_FB_SIS_300
  60. #include "300vtbl.h"
  61. #endif
  62. #ifdef CONFIG_FB_SIS_315
  63. #include "310vtbl.h"
  64. #endif
  65. #if defined(ALLOC_PRAGMA)
  66. #pragma alloc_text(PAGE,SiSSetMode)
  67. #endif
  68. /*********************************************/
  69. /* POINTER INITIALIZATION */
  70. /*********************************************/
  71. #if defined(CONFIG_FB_SIS_300) || defined(CONFIG_FB_SIS_315)
  72. static void
  73. InitCommonPointer(struct SiS_Private *SiS_Pr)
  74. {
  75. SiS_Pr->SiS_SModeIDTable = SiS_SModeIDTable;
  76. SiS_Pr->SiS_StResInfo = SiS_StResInfo;
  77. SiS_Pr->SiS_ModeResInfo = SiS_ModeResInfo;
  78. SiS_Pr->SiS_StandTable = SiS_StandTable;
  79. SiS_Pr->SiS_NTSCTiming = SiS_NTSCTiming;
  80. SiS_Pr->SiS_PALTiming = SiS_PALTiming;
  81. SiS_Pr->SiS_HiTVSt1Timing = SiS_HiTVSt1Timing;
  82. SiS_Pr->SiS_HiTVSt2Timing = SiS_HiTVSt2Timing;
  83. SiS_Pr->SiS_HiTVExtTiming = SiS_HiTVExtTiming;
  84. SiS_Pr->SiS_HiTVGroup3Data = SiS_HiTVGroup3Data;
  85. SiS_Pr->SiS_HiTVGroup3Simu = SiS_HiTVGroup3Simu;
  86. #if 0
  87. SiS_Pr->SiS_HiTVTextTiming = SiS_HiTVTextTiming;
  88. SiS_Pr->SiS_HiTVGroup3Text = SiS_HiTVGroup3Text;
  89. #endif
  90. SiS_Pr->SiS_StPALData = SiS_StPALData;
  91. SiS_Pr->SiS_ExtPALData = SiS_ExtPALData;
  92. SiS_Pr->SiS_StNTSCData = SiS_StNTSCData;
  93. SiS_Pr->SiS_ExtNTSCData = SiS_ExtNTSCData;
  94. SiS_Pr->SiS_St1HiTVData = SiS_StHiTVData;
  95. SiS_Pr->SiS_St2HiTVData = SiS_St2HiTVData;
  96. SiS_Pr->SiS_ExtHiTVData = SiS_ExtHiTVData;
  97. SiS_Pr->SiS_St525iData = SiS_StNTSCData;
  98. SiS_Pr->SiS_St525pData = SiS_St525pData;
  99. SiS_Pr->SiS_St750pData = SiS_St750pData;
  100. SiS_Pr->SiS_Ext525iData = SiS_ExtNTSCData;
  101. SiS_Pr->SiS_Ext525pData = SiS_ExtNTSCData;
  102. SiS_Pr->SiS_Ext750pData = SiS_Ext750pData;
  103. SiS_Pr->pSiS_OutputSelect = &SiS_OutputSelect;
  104. SiS_Pr->pSiS_SoftSetting = &SiS_SoftSetting;
  105. SiS_Pr->SiS_LCD1280x720Data = SiS_LCD1280x720Data;
  106. SiS_Pr->SiS_StLCD1280x768_2Data = SiS_StLCD1280x768_2Data;
  107. SiS_Pr->SiS_ExtLCD1280x768_2Data = SiS_ExtLCD1280x768_2Data;
  108. SiS_Pr->SiS_LCD1280x800Data = SiS_LCD1280x800Data;
  109. SiS_Pr->SiS_LCD1280x800_2Data = SiS_LCD1280x800_2Data;
  110. SiS_Pr->SiS_LCD1280x854Data = SiS_LCD1280x854Data;
  111. SiS_Pr->SiS_LCD1280x960Data = SiS_LCD1280x960Data;
  112. SiS_Pr->SiS_StLCD1400x1050Data = SiS_StLCD1400x1050Data;
  113. SiS_Pr->SiS_ExtLCD1400x1050Data = SiS_ExtLCD1400x1050Data;
  114. SiS_Pr->SiS_LCD1680x1050Data = SiS_LCD1680x1050Data;
  115. SiS_Pr->SiS_StLCD1600x1200Data = SiS_StLCD1600x1200Data;
  116. SiS_Pr->SiS_ExtLCD1600x1200Data = SiS_ExtLCD1600x1200Data;
  117. SiS_Pr->SiS_NoScaleData = SiS_NoScaleData;
  118. SiS_Pr->SiS_LVDS320x240Data_1 = SiS_LVDS320x240Data_1;
  119. SiS_Pr->SiS_LVDS320x240Data_2 = SiS_LVDS320x240Data_2;
  120. SiS_Pr->SiS_LVDS640x480Data_1 = SiS_LVDS640x480Data_1;
  121. SiS_Pr->SiS_LVDS800x600Data_1 = SiS_LVDS800x600Data_1;
  122. SiS_Pr->SiS_LVDS1024x600Data_1 = SiS_LVDS1024x600Data_1;
  123. SiS_Pr->SiS_LVDS1024x768Data_1 = SiS_LVDS1024x768Data_1;
  124. SiS_Pr->SiS_LVDSCRT1320x240_1 = SiS_LVDSCRT1320x240_1;
  125. SiS_Pr->SiS_LVDSCRT1320x240_2 = SiS_LVDSCRT1320x240_2;
  126. SiS_Pr->SiS_LVDSCRT1320x240_2_H = SiS_LVDSCRT1320x240_2_H;
  127. SiS_Pr->SiS_LVDSCRT1320x240_3 = SiS_LVDSCRT1320x240_3;
  128. SiS_Pr->SiS_LVDSCRT1320x240_3_H = SiS_LVDSCRT1320x240_3_H;
  129. SiS_Pr->SiS_LVDSCRT1640x480_1 = SiS_LVDSCRT1640x480_1;
  130. SiS_Pr->SiS_LVDSCRT1640x480_1_H = SiS_LVDSCRT1640x480_1_H;
  131. #if 0
  132. SiS_Pr->SiS_LVDSCRT11024x600_1 = SiS_LVDSCRT11024x600_1;
  133. SiS_Pr->SiS_LVDSCRT11024x600_1_H = SiS_LVDSCRT11024x600_1_H;
  134. SiS_Pr->SiS_LVDSCRT11024x600_2 = SiS_LVDSCRT11024x600_2;
  135. SiS_Pr->SiS_LVDSCRT11024x600_2_H = SiS_LVDSCRT11024x600_2_H;
  136. #endif
  137. SiS_Pr->SiS_CHTVUNTSCData = SiS_CHTVUNTSCData;
  138. SiS_Pr->SiS_CHTVONTSCData = SiS_CHTVONTSCData;
  139. SiS_Pr->SiS_PanelMinLVDS = Panel_800x600; /* lowest value LVDS/LCDA */
  140. SiS_Pr->SiS_PanelMin301 = Panel_1024x768; /* lowest value 301 */
  141. }
  142. #endif
  143. #ifdef CONFIG_FB_SIS_300
  144. static void
  145. InitTo300Pointer(struct SiS_Private *SiS_Pr)
  146. {
  147. InitCommonPointer(SiS_Pr);
  148. SiS_Pr->SiS_VBModeIDTable = SiS300_VBModeIDTable;
  149. SiS_Pr->SiS_EModeIDTable = SiS300_EModeIDTable;
  150. SiS_Pr->SiS_RefIndex = SiS300_RefIndex;
  151. SiS_Pr->SiS_CRT1Table = SiS300_CRT1Table;
  152. if(SiS_Pr->ChipType == SIS_300) {
  153. SiS_Pr->SiS_MCLKData_0 = SiS300_MCLKData_300; /* 300 */
  154. } else {
  155. SiS_Pr->SiS_MCLKData_0 = SiS300_MCLKData_630; /* 630, 730 */
  156. }
  157. SiS_Pr->SiS_VCLKData = SiS300_VCLKData;
  158. SiS_Pr->SiS_VBVCLKData = (struct SiS_VBVCLKData *)SiS300_VCLKData;
  159. SiS_Pr->SiS_SR15 = SiS300_SR15;
  160. SiS_Pr->SiS_PanelDelayTbl = SiS300_PanelDelayTbl;
  161. SiS_Pr->SiS_PanelDelayTblLVDS = SiS300_PanelDelayTbl;
  162. SiS_Pr->SiS_ExtLCD1024x768Data = SiS300_ExtLCD1024x768Data;
  163. SiS_Pr->SiS_St2LCD1024x768Data = SiS300_St2LCD1024x768Data;
  164. SiS_Pr->SiS_ExtLCD1280x1024Data = SiS300_ExtLCD1280x1024Data;
  165. SiS_Pr->SiS_St2LCD1280x1024Data = SiS300_St2LCD1280x1024Data;
  166. SiS_Pr->SiS_CRT2Part2_1024x768_1 = SiS300_CRT2Part2_1024x768_1;
  167. SiS_Pr->SiS_CRT2Part2_1024x768_2 = SiS300_CRT2Part2_1024x768_2;
  168. SiS_Pr->SiS_CRT2Part2_1024x768_3 = SiS300_CRT2Part2_1024x768_3;
  169. SiS_Pr->SiS_CHTVUPALData = SiS300_CHTVUPALData;
  170. SiS_Pr->SiS_CHTVOPALData = SiS300_CHTVOPALData;
  171. SiS_Pr->SiS_CHTVUPALMData = SiS_CHTVUNTSCData; /* not supported on 300 series */
  172. SiS_Pr->SiS_CHTVOPALMData = SiS_CHTVONTSCData; /* not supported on 300 series */
  173. SiS_Pr->SiS_CHTVUPALNData = SiS300_CHTVUPALData; /* not supported on 300 series */
  174. SiS_Pr->SiS_CHTVOPALNData = SiS300_CHTVOPALData; /* not supported on 300 series */
  175. SiS_Pr->SiS_CHTVSOPALData = SiS300_CHTVSOPALData;
  176. SiS_Pr->SiS_LVDS848x480Data_1 = SiS300_LVDS848x480Data_1;
  177. SiS_Pr->SiS_LVDS848x480Data_2 = SiS300_LVDS848x480Data_2;
  178. SiS_Pr->SiS_LVDSBARCO1024Data_1 = SiS300_LVDSBARCO1024Data_1;
  179. SiS_Pr->SiS_LVDSBARCO1366Data_1 = SiS300_LVDSBARCO1366Data_1;
  180. SiS_Pr->SiS_LVDSBARCO1366Data_2 = SiS300_LVDSBARCO1366Data_2;
  181. SiS_Pr->SiS_PanelType04_1a = SiS300_PanelType04_1a;
  182. SiS_Pr->SiS_PanelType04_2a = SiS300_PanelType04_2a;
  183. SiS_Pr->SiS_PanelType04_1b = SiS300_PanelType04_1b;
  184. SiS_Pr->SiS_PanelType04_2b = SiS300_PanelType04_2b;
  185. SiS_Pr->SiS_CHTVCRT1UNTSC = SiS300_CHTVCRT1UNTSC;
  186. SiS_Pr->SiS_CHTVCRT1ONTSC = SiS300_CHTVCRT1ONTSC;
  187. SiS_Pr->SiS_CHTVCRT1UPAL = SiS300_CHTVCRT1UPAL;
  188. SiS_Pr->SiS_CHTVCRT1OPAL = SiS300_CHTVCRT1OPAL;
  189. SiS_Pr->SiS_CHTVCRT1SOPAL = SiS300_CHTVCRT1SOPAL;
  190. SiS_Pr->SiS_CHTVReg_UNTSC = SiS300_CHTVReg_UNTSC;
  191. SiS_Pr->SiS_CHTVReg_ONTSC = SiS300_CHTVReg_ONTSC;
  192. SiS_Pr->SiS_CHTVReg_UPAL = SiS300_CHTVReg_UPAL;
  193. SiS_Pr->SiS_CHTVReg_OPAL = SiS300_CHTVReg_OPAL;
  194. SiS_Pr->SiS_CHTVReg_UPALM = SiS300_CHTVReg_UNTSC; /* not supported on 300 series */
  195. SiS_Pr->SiS_CHTVReg_OPALM = SiS300_CHTVReg_ONTSC; /* not supported on 300 series */
  196. SiS_Pr->SiS_CHTVReg_UPALN = SiS300_CHTVReg_UPAL; /* not supported on 300 series */
  197. SiS_Pr->SiS_CHTVReg_OPALN = SiS300_CHTVReg_OPAL; /* not supported on 300 series */
  198. SiS_Pr->SiS_CHTVReg_SOPAL = SiS300_CHTVReg_SOPAL;
  199. SiS_Pr->SiS_CHTVVCLKUNTSC = SiS300_CHTVVCLKUNTSC;
  200. SiS_Pr->SiS_CHTVVCLKONTSC = SiS300_CHTVVCLKONTSC;
  201. SiS_Pr->SiS_CHTVVCLKUPAL = SiS300_CHTVVCLKUPAL;
  202. SiS_Pr->SiS_CHTVVCLKOPAL = SiS300_CHTVVCLKOPAL;
  203. SiS_Pr->SiS_CHTVVCLKUPALM = SiS300_CHTVVCLKUNTSC; /* not supported on 300 series */
  204. SiS_Pr->SiS_CHTVVCLKOPALM = SiS300_CHTVVCLKONTSC; /* not supported on 300 series */
  205. SiS_Pr->SiS_CHTVVCLKUPALN = SiS300_CHTVVCLKUPAL; /* not supported on 300 series */
  206. SiS_Pr->SiS_CHTVVCLKOPALN = SiS300_CHTVVCLKOPAL; /* not supported on 300 series */
  207. SiS_Pr->SiS_CHTVVCLKSOPAL = SiS300_CHTVVCLKSOPAL;
  208. }
  209. #endif
  210. #ifdef CONFIG_FB_SIS_315
  211. static void
  212. InitTo310Pointer(struct SiS_Private *SiS_Pr)
  213. {
  214. InitCommonPointer(SiS_Pr);
  215. SiS_Pr->SiS_EModeIDTable = SiS310_EModeIDTable;
  216. SiS_Pr->SiS_RefIndex = SiS310_RefIndex;
  217. SiS_Pr->SiS_CRT1Table = SiS310_CRT1Table;
  218. if(SiS_Pr->ChipType >= SIS_340) {
  219. SiS_Pr->SiS_MCLKData_0 = SiS310_MCLKData_0_340; /* 340 + XGI */
  220. } else if(SiS_Pr->ChipType >= SIS_761) {
  221. SiS_Pr->SiS_MCLKData_0 = SiS310_MCLKData_0_761; /* 761 - preliminary */
  222. } else if(SiS_Pr->ChipType >= SIS_760) {
  223. SiS_Pr->SiS_MCLKData_0 = SiS310_MCLKData_0_760; /* 760 */
  224. } else if(SiS_Pr->ChipType >= SIS_661) {
  225. SiS_Pr->SiS_MCLKData_0 = SiS310_MCLKData_0_660; /* 661/741 */
  226. } else if(SiS_Pr->ChipType == SIS_330) {
  227. SiS_Pr->SiS_MCLKData_0 = SiS310_MCLKData_0_330; /* 330 */
  228. } else if(SiS_Pr->ChipType > SIS_315PRO) {
  229. SiS_Pr->SiS_MCLKData_0 = SiS310_MCLKData_0_650; /* 550, 650, 740 */
  230. } else {
  231. SiS_Pr->SiS_MCLKData_0 = SiS310_MCLKData_0_315; /* 315 */
  232. }
  233. if(SiS_Pr->ChipType >= SIS_340) {
  234. SiS_Pr->SiS_MCLKData_1 = SiS310_MCLKData_1_340;
  235. } else {
  236. SiS_Pr->SiS_MCLKData_1 = SiS310_MCLKData_1;
  237. }
  238. SiS_Pr->SiS_VCLKData = SiS310_VCLKData;
  239. SiS_Pr->SiS_VBVCLKData = SiS310_VBVCLKData;
  240. SiS_Pr->SiS_SR15 = SiS310_SR15;
  241. SiS_Pr->SiS_PanelDelayTbl = SiS310_PanelDelayTbl;
  242. SiS_Pr->SiS_PanelDelayTblLVDS = SiS310_PanelDelayTblLVDS;
  243. SiS_Pr->SiS_St2LCD1024x768Data = SiS310_St2LCD1024x768Data;
  244. SiS_Pr->SiS_ExtLCD1024x768Data = SiS310_ExtLCD1024x768Data;
  245. SiS_Pr->SiS_St2LCD1280x1024Data = SiS310_St2LCD1280x1024Data;
  246. SiS_Pr->SiS_ExtLCD1280x1024Data = SiS310_ExtLCD1280x1024Data;
  247. SiS_Pr->SiS_CRT2Part2_1024x768_1 = SiS310_CRT2Part2_1024x768_1;
  248. SiS_Pr->SiS_CHTVUPALData = SiS310_CHTVUPALData;
  249. SiS_Pr->SiS_CHTVOPALData = SiS310_CHTVOPALData;
  250. SiS_Pr->SiS_CHTVUPALMData = SiS310_CHTVUPALMData;
  251. SiS_Pr->SiS_CHTVOPALMData = SiS310_CHTVOPALMData;
  252. SiS_Pr->SiS_CHTVUPALNData = SiS310_CHTVUPALNData;
  253. SiS_Pr->SiS_CHTVOPALNData = SiS310_CHTVOPALNData;
  254. SiS_Pr->SiS_CHTVSOPALData = SiS310_CHTVSOPALData;
  255. SiS_Pr->SiS_CHTVCRT1UNTSC = SiS310_CHTVCRT1UNTSC;
  256. SiS_Pr->SiS_CHTVCRT1ONTSC = SiS310_CHTVCRT1ONTSC;
  257. SiS_Pr->SiS_CHTVCRT1UPAL = SiS310_CHTVCRT1UPAL;
  258. SiS_Pr->SiS_CHTVCRT1OPAL = SiS310_CHTVCRT1OPAL;
  259. SiS_Pr->SiS_CHTVCRT1SOPAL = SiS310_CHTVCRT1OPAL;
  260. SiS_Pr->SiS_CHTVReg_UNTSC = SiS310_CHTVReg_UNTSC;
  261. SiS_Pr->SiS_CHTVReg_ONTSC = SiS310_CHTVReg_ONTSC;
  262. SiS_Pr->SiS_CHTVReg_UPAL = SiS310_CHTVReg_UPAL;
  263. SiS_Pr->SiS_CHTVReg_OPAL = SiS310_CHTVReg_OPAL;
  264. SiS_Pr->SiS_CHTVReg_UPALM = SiS310_CHTVReg_UPALM;
  265. SiS_Pr->SiS_CHTVReg_OPALM = SiS310_CHTVReg_OPALM;
  266. SiS_Pr->SiS_CHTVReg_UPALN = SiS310_CHTVReg_UPALN;
  267. SiS_Pr->SiS_CHTVReg_OPALN = SiS310_CHTVReg_OPALN;
  268. SiS_Pr->SiS_CHTVReg_SOPAL = SiS310_CHTVReg_OPAL;
  269. SiS_Pr->SiS_CHTVVCLKUNTSC = SiS310_CHTVVCLKUNTSC;
  270. SiS_Pr->SiS_CHTVVCLKONTSC = SiS310_CHTVVCLKONTSC;
  271. SiS_Pr->SiS_CHTVVCLKUPAL = SiS310_CHTVVCLKUPAL;
  272. SiS_Pr->SiS_CHTVVCLKOPAL = SiS310_CHTVVCLKOPAL;
  273. SiS_Pr->SiS_CHTVVCLKUPALM = SiS310_CHTVVCLKUPALM;
  274. SiS_Pr->SiS_CHTVVCLKOPALM = SiS310_CHTVVCLKOPALM;
  275. SiS_Pr->SiS_CHTVVCLKUPALN = SiS310_CHTVVCLKUPALN;
  276. SiS_Pr->SiS_CHTVVCLKOPALN = SiS310_CHTVVCLKOPALN;
  277. SiS_Pr->SiS_CHTVVCLKSOPAL = SiS310_CHTVVCLKOPAL;
  278. }
  279. #endif
  280. bool
  281. SiSInitPtr(struct SiS_Private *SiS_Pr)
  282. {
  283. if(SiS_Pr->ChipType < SIS_315H) {
  284. #ifdef CONFIG_FB_SIS_300
  285. InitTo300Pointer(SiS_Pr);
  286. #else
  287. return false;
  288. #endif
  289. } else {
  290. #ifdef CONFIG_FB_SIS_315
  291. InitTo310Pointer(SiS_Pr);
  292. #else
  293. return false;
  294. #endif
  295. }
  296. return true;
  297. }
  298. /*********************************************/
  299. /* HELPER: Get ModeID */
  300. /*********************************************/
  301. static
  302. unsigned short
  303. SiS_GetModeID(int VGAEngine, unsigned int VBFlags, int HDisplay, int VDisplay,
  304. int Depth, bool FSTN, int LCDwidth, int LCDheight)
  305. {
  306. unsigned short ModeIndex = 0;
  307. switch(HDisplay)
  308. {
  309. case 320:
  310. if(VDisplay == 200) ModeIndex = ModeIndex_320x200[Depth];
  311. else if(VDisplay == 240) {
  312. if((VBFlags & CRT2_LCD) && (FSTN))
  313. ModeIndex = ModeIndex_320x240_FSTN[Depth];
  314. else
  315. ModeIndex = ModeIndex_320x240[Depth];
  316. }
  317. break;
  318. case 400:
  319. if((!(VBFlags & CRT1_LCDA)) || ((LCDwidth >= 800) && (LCDwidth >= 600))) {
  320. if(VDisplay == 300) ModeIndex = ModeIndex_400x300[Depth];
  321. }
  322. break;
  323. case 512:
  324. if((!(VBFlags & CRT1_LCDA)) || ((LCDwidth >= 1024) && (LCDwidth >= 768))) {
  325. if(VDisplay == 384) ModeIndex = ModeIndex_512x384[Depth];
  326. }
  327. break;
  328. case 640:
  329. if(VDisplay == 480) ModeIndex = ModeIndex_640x480[Depth];
  330. else if(VDisplay == 400) ModeIndex = ModeIndex_640x400[Depth];
  331. break;
  332. case 720:
  333. if(VDisplay == 480) ModeIndex = ModeIndex_720x480[Depth];
  334. else if(VDisplay == 576) ModeIndex = ModeIndex_720x576[Depth];
  335. break;
  336. case 768:
  337. if(VDisplay == 576) ModeIndex = ModeIndex_768x576[Depth];
  338. break;
  339. case 800:
  340. if(VDisplay == 600) ModeIndex = ModeIndex_800x600[Depth];
  341. else if(VDisplay == 480) ModeIndex = ModeIndex_800x480[Depth];
  342. break;
  343. case 848:
  344. if(VDisplay == 480) ModeIndex = ModeIndex_848x480[Depth];
  345. break;
  346. case 856:
  347. if(VDisplay == 480) ModeIndex = ModeIndex_856x480[Depth];
  348. break;
  349. case 960:
  350. if(VGAEngine == SIS_315_VGA) {
  351. if(VDisplay == 540) ModeIndex = ModeIndex_960x540[Depth];
  352. else if(VDisplay == 600) ModeIndex = ModeIndex_960x600[Depth];
  353. }
  354. break;
  355. case 1024:
  356. if(VDisplay == 576) ModeIndex = ModeIndex_1024x576[Depth];
  357. else if(VDisplay == 768) ModeIndex = ModeIndex_1024x768[Depth];
  358. else if(VGAEngine == SIS_300_VGA) {
  359. if(VDisplay == 600) ModeIndex = ModeIndex_1024x600[Depth];
  360. }
  361. break;
  362. case 1152:
  363. if(VDisplay == 864) ModeIndex = ModeIndex_1152x864[Depth];
  364. if(VGAEngine == SIS_300_VGA) {
  365. if(VDisplay == 768) ModeIndex = ModeIndex_1152x768[Depth];
  366. }
  367. break;
  368. case 1280:
  369. switch(VDisplay) {
  370. case 720:
  371. ModeIndex = ModeIndex_1280x720[Depth];
  372. break;
  373. case 768:
  374. if(VGAEngine == SIS_300_VGA) {
  375. ModeIndex = ModeIndex_300_1280x768[Depth];
  376. } else {
  377. ModeIndex = ModeIndex_310_1280x768[Depth];
  378. }
  379. break;
  380. case 800:
  381. if(VGAEngine == SIS_315_VGA) {
  382. ModeIndex = ModeIndex_1280x800[Depth];
  383. }
  384. break;
  385. case 854:
  386. if(VGAEngine == SIS_315_VGA) {
  387. ModeIndex = ModeIndex_1280x854[Depth];
  388. }
  389. break;
  390. case 960:
  391. ModeIndex = ModeIndex_1280x960[Depth];
  392. break;
  393. case 1024:
  394. ModeIndex = ModeIndex_1280x1024[Depth];
  395. break;
  396. }
  397. break;
  398. case 1360:
  399. if(VDisplay == 768) ModeIndex = ModeIndex_1360x768[Depth];
  400. if(VGAEngine == SIS_300_VGA) {
  401. if(VDisplay == 1024) ModeIndex = ModeIndex_300_1360x1024[Depth];
  402. }
  403. break;
  404. case 1400:
  405. if(VGAEngine == SIS_315_VGA) {
  406. if(VDisplay == 1050) {
  407. ModeIndex = ModeIndex_1400x1050[Depth];
  408. }
  409. }
  410. break;
  411. case 1600:
  412. if(VDisplay == 1200) ModeIndex = ModeIndex_1600x1200[Depth];
  413. break;
  414. case 1680:
  415. if(VGAEngine == SIS_315_VGA) {
  416. if(VDisplay == 1050) ModeIndex = ModeIndex_1680x1050[Depth];
  417. }
  418. break;
  419. case 1920:
  420. if(VDisplay == 1440) ModeIndex = ModeIndex_1920x1440[Depth];
  421. else if(VGAEngine == SIS_315_VGA) {
  422. if(VDisplay == 1080) ModeIndex = ModeIndex_1920x1080[Depth];
  423. }
  424. break;
  425. case 2048:
  426. if(VDisplay == 1536) {
  427. if(VGAEngine == SIS_300_VGA) {
  428. ModeIndex = ModeIndex_300_2048x1536[Depth];
  429. } else {
  430. ModeIndex = ModeIndex_310_2048x1536[Depth];
  431. }
  432. }
  433. break;
  434. }
  435. return ModeIndex;
  436. }
  437. unsigned short
  438. SiS_GetModeID_LCD(int VGAEngine, unsigned int VBFlags, int HDisplay, int VDisplay,
  439. int Depth, bool FSTN, unsigned short CustomT, int LCDwidth, int LCDheight,
  440. unsigned int VBFlags2)
  441. {
  442. unsigned short ModeIndex = 0;
  443. if(VBFlags2 & (VB2_LVDS | VB2_30xBDH)) {
  444. switch(HDisplay)
  445. {
  446. case 320:
  447. if((CustomT != CUT_PANEL848) && (CustomT != CUT_PANEL856)) {
  448. if(VDisplay == 200) {
  449. if(!FSTN) ModeIndex = ModeIndex_320x200[Depth];
  450. } else if(VDisplay == 240) {
  451. if(!FSTN) ModeIndex = ModeIndex_320x240[Depth];
  452. else if(VGAEngine == SIS_315_VGA) {
  453. ModeIndex = ModeIndex_320x240_FSTN[Depth];
  454. }
  455. }
  456. }
  457. break;
  458. case 400:
  459. if((CustomT != CUT_PANEL848) && (CustomT != CUT_PANEL856)) {
  460. if(!((VGAEngine == SIS_300_VGA) && (VBFlags2 & VB2_TRUMPION))) {
  461. if(VDisplay == 300) ModeIndex = ModeIndex_400x300[Depth];
  462. }
  463. }
  464. break;
  465. case 512:
  466. if((CustomT != CUT_PANEL848) && (CustomT != CUT_PANEL856)) {
  467. if(!((VGAEngine == SIS_300_VGA) && (VBFlags2 & VB2_TRUMPION))) {
  468. if(LCDwidth >= 1024 && LCDwidth != 1152 && LCDheight >= 768) {
  469. if(VDisplay == 384) {
  470. ModeIndex = ModeIndex_512x384[Depth];
  471. }
  472. }
  473. }
  474. }
  475. break;
  476. case 640:
  477. if(VDisplay == 480) ModeIndex = ModeIndex_640x480[Depth];
  478. else if(VDisplay == 400) {
  479. if((CustomT != CUT_PANEL848) && (CustomT != CUT_PANEL856))
  480. ModeIndex = ModeIndex_640x400[Depth];
  481. }
  482. break;
  483. case 800:
  484. if(VDisplay == 600) ModeIndex = ModeIndex_800x600[Depth];
  485. break;
  486. case 848:
  487. if(CustomT == CUT_PANEL848) {
  488. if(VDisplay == 480) ModeIndex = ModeIndex_848x480[Depth];
  489. }
  490. break;
  491. case 856:
  492. if(CustomT == CUT_PANEL856) {
  493. if(VDisplay == 480) ModeIndex = ModeIndex_856x480[Depth];
  494. }
  495. break;
  496. case 1024:
  497. if(VDisplay == 768) ModeIndex = ModeIndex_1024x768[Depth];
  498. else if(VGAEngine == SIS_300_VGA) {
  499. if((VDisplay == 600) && (LCDheight == 600)) {
  500. ModeIndex = ModeIndex_1024x600[Depth];
  501. }
  502. }
  503. break;
  504. case 1152:
  505. if(VGAEngine == SIS_300_VGA) {
  506. if((VDisplay == 768) && (LCDheight == 768)) {
  507. ModeIndex = ModeIndex_1152x768[Depth];
  508. }
  509. }
  510. break;
  511. case 1280:
  512. if(VDisplay == 1024) ModeIndex = ModeIndex_1280x1024[Depth];
  513. else if(VGAEngine == SIS_315_VGA) {
  514. if((VDisplay == 768) && (LCDheight == 768)) {
  515. ModeIndex = ModeIndex_310_1280x768[Depth];
  516. }
  517. }
  518. break;
  519. case 1360:
  520. if(VGAEngine == SIS_300_VGA) {
  521. if(CustomT == CUT_BARCO1366) {
  522. if(VDisplay == 1024) ModeIndex = ModeIndex_300_1360x1024[Depth];
  523. }
  524. }
  525. if(CustomT == CUT_PANEL848) {
  526. if(VDisplay == 768) ModeIndex = ModeIndex_1360x768[Depth];
  527. }
  528. break;
  529. case 1400:
  530. if(VGAEngine == SIS_315_VGA) {
  531. if(VDisplay == 1050) ModeIndex = ModeIndex_1400x1050[Depth];
  532. }
  533. break;
  534. case 1600:
  535. if(VGAEngine == SIS_315_VGA) {
  536. if(VDisplay == 1200) ModeIndex = ModeIndex_1600x1200[Depth];
  537. }
  538. break;
  539. }
  540. } else if(VBFlags2 & VB2_SISBRIDGE) {
  541. switch(HDisplay)
  542. {
  543. case 320:
  544. if(VDisplay == 200) ModeIndex = ModeIndex_320x200[Depth];
  545. else if(VDisplay == 240) ModeIndex = ModeIndex_320x240[Depth];
  546. break;
  547. case 400:
  548. if(LCDwidth >= 800 && LCDheight >= 600) {
  549. if(VDisplay == 300) ModeIndex = ModeIndex_400x300[Depth];
  550. }
  551. break;
  552. case 512:
  553. if(LCDwidth >= 1024 && LCDheight >= 768 && LCDwidth != 1152) {
  554. if(VDisplay == 384) ModeIndex = ModeIndex_512x384[Depth];
  555. }
  556. break;
  557. case 640:
  558. if(VDisplay == 480) ModeIndex = ModeIndex_640x480[Depth];
  559. else if(VDisplay == 400) ModeIndex = ModeIndex_640x400[Depth];
  560. break;
  561. case 720:
  562. if(VGAEngine == SIS_315_VGA) {
  563. if(VDisplay == 480) ModeIndex = ModeIndex_720x480[Depth];
  564. else if(VDisplay == 576) ModeIndex = ModeIndex_720x576[Depth];
  565. }
  566. break;
  567. case 768:
  568. if(VGAEngine == SIS_315_VGA) {
  569. if(VDisplay == 576) ModeIndex = ModeIndex_768x576[Depth];
  570. }
  571. break;
  572. case 800:
  573. if(VDisplay == 600) ModeIndex = ModeIndex_800x600[Depth];
  574. if(VGAEngine == SIS_315_VGA) {
  575. if(VDisplay == 480) ModeIndex = ModeIndex_800x480[Depth];
  576. }
  577. break;
  578. case 848:
  579. if(VGAEngine == SIS_315_VGA) {
  580. if(VDisplay == 480) ModeIndex = ModeIndex_848x480[Depth];
  581. }
  582. break;
  583. case 856:
  584. if(VGAEngine == SIS_315_VGA) {
  585. if(VDisplay == 480) ModeIndex = ModeIndex_856x480[Depth];
  586. }
  587. break;
  588. case 960:
  589. if(VGAEngine == SIS_315_VGA) {
  590. if(VDisplay == 540) ModeIndex = ModeIndex_960x540[Depth];
  591. else if(VDisplay == 600) ModeIndex = ModeIndex_960x600[Depth];
  592. }
  593. break;
  594. case 1024:
  595. if(VDisplay == 768) ModeIndex = ModeIndex_1024x768[Depth];
  596. if(VGAEngine == SIS_315_VGA) {
  597. if(VDisplay == 576) ModeIndex = ModeIndex_1024x576[Depth];
  598. }
  599. break;
  600. case 1152:
  601. if(VGAEngine == SIS_315_VGA) {
  602. if(VDisplay == 864) ModeIndex = ModeIndex_1152x864[Depth];
  603. }
  604. break;
  605. case 1280:
  606. switch(VDisplay) {
  607. case 720:
  608. ModeIndex = ModeIndex_1280x720[Depth];
  609. break;
  610. case 768:
  611. if(VGAEngine == SIS_300_VGA) {
  612. ModeIndex = ModeIndex_300_1280x768[Depth];
  613. } else {
  614. ModeIndex = ModeIndex_310_1280x768[Depth];
  615. }
  616. break;
  617. case 800:
  618. if(VGAEngine == SIS_315_VGA) {
  619. ModeIndex = ModeIndex_1280x800[Depth];
  620. }
  621. break;
  622. case 854:
  623. if(VGAEngine == SIS_315_VGA) {
  624. ModeIndex = ModeIndex_1280x854[Depth];
  625. }
  626. break;
  627. case 960:
  628. ModeIndex = ModeIndex_1280x960[Depth];
  629. break;
  630. case 1024:
  631. ModeIndex = ModeIndex_1280x1024[Depth];
  632. break;
  633. }
  634. break;
  635. case 1360:
  636. if(VGAEngine == SIS_315_VGA) { /* OVER1280 only? */
  637. if(VDisplay == 768) ModeIndex = ModeIndex_1360x768[Depth];
  638. }
  639. break;
  640. case 1400:
  641. if(VGAEngine == SIS_315_VGA) {
  642. if(VBFlags2 & VB2_LCDOVER1280BRIDGE) {
  643. if(VDisplay == 1050) ModeIndex = ModeIndex_1400x1050[Depth];
  644. }
  645. }
  646. break;
  647. case 1600:
  648. if(VGAEngine == SIS_315_VGA) {
  649. if(VBFlags2 & VB2_LCDOVER1280BRIDGE) {
  650. if(VDisplay == 1200) ModeIndex = ModeIndex_1600x1200[Depth];
  651. }
  652. }
  653. break;
  654. #ifndef VB_FORBID_CRT2LCD_OVER_1600
  655. case 1680:
  656. if(VGAEngine == SIS_315_VGA) {
  657. if(VBFlags2 & VB2_LCDOVER1280BRIDGE) {
  658. if(VDisplay == 1050) ModeIndex = ModeIndex_1680x1050[Depth];
  659. }
  660. }
  661. break;
  662. case 1920:
  663. if(VGAEngine == SIS_315_VGA) {
  664. if(VBFlags2 & VB2_LCDOVER1600BRIDGE) {
  665. if(VDisplay == 1440) ModeIndex = ModeIndex_1920x1440[Depth];
  666. }
  667. }
  668. break;
  669. case 2048:
  670. if(VGAEngine == SIS_315_VGA) {
  671. if(VBFlags2 & VB2_LCDOVER1600BRIDGE) {
  672. if(VDisplay == 1536) ModeIndex = ModeIndex_310_2048x1536[Depth];
  673. }
  674. }
  675. break;
  676. #endif
  677. }
  678. }
  679. return ModeIndex;
  680. }
  681. unsigned short
  682. SiS_GetModeID_TV(int VGAEngine, unsigned int VBFlags, int HDisplay, int VDisplay, int Depth,
  683. unsigned int VBFlags2)
  684. {
  685. unsigned short ModeIndex = 0;
  686. if(VBFlags2 & VB2_CHRONTEL) {
  687. switch(HDisplay)
  688. {
  689. case 512:
  690. if(VGAEngine == SIS_315_VGA) {
  691. if(VDisplay == 384) ModeIndex = ModeIndex_512x384[Depth];
  692. }
  693. break;
  694. case 640:
  695. if(VDisplay == 480) ModeIndex = ModeIndex_640x480[Depth];
  696. else if(VDisplay == 400) ModeIndex = ModeIndex_640x400[Depth];
  697. break;
  698. case 800:
  699. if(VDisplay == 600) ModeIndex = ModeIndex_800x600[Depth];
  700. break;
  701. case 1024:
  702. if(VGAEngine == SIS_315_VGA) {
  703. if(VDisplay == 768) ModeIndex = ModeIndex_1024x768[Depth];
  704. }
  705. break;
  706. }
  707. } else if(VBFlags2 & VB2_SISTVBRIDGE) {
  708. switch(HDisplay)
  709. {
  710. case 320:
  711. if(VDisplay == 200) ModeIndex = ModeIndex_320x200[Depth];
  712. else if(VDisplay == 240) ModeIndex = ModeIndex_320x240[Depth];
  713. break;
  714. case 400:
  715. if(VDisplay == 300) ModeIndex = ModeIndex_400x300[Depth];
  716. break;
  717. case 512:
  718. if( ((VBFlags & TV_YPBPR) && (VBFlags & (TV_YPBPR750P | TV_YPBPR1080I))) ||
  719. (VBFlags & TV_HIVISION) ||
  720. ((!(VBFlags & (TV_YPBPR | TV_PALM))) && (VBFlags & TV_PAL)) ) {
  721. if(VDisplay == 384) ModeIndex = ModeIndex_512x384[Depth];
  722. }
  723. break;
  724. case 640:
  725. if(VDisplay == 480) ModeIndex = ModeIndex_640x480[Depth];
  726. else if(VDisplay == 400) ModeIndex = ModeIndex_640x400[Depth];
  727. break;
  728. case 720:
  729. if((!(VBFlags & TV_HIVISION)) && (!((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR1080I)))) {
  730. if(VDisplay == 480) {
  731. ModeIndex = ModeIndex_720x480[Depth];
  732. } else if(VDisplay == 576) {
  733. if( ((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR750P)) ||
  734. ((!(VBFlags & (TV_YPBPR | TV_PALM))) && (VBFlags & TV_PAL)) )
  735. ModeIndex = ModeIndex_720x576[Depth];
  736. }
  737. }
  738. break;
  739. case 768:
  740. if((!(VBFlags & TV_HIVISION)) && (!((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR1080I)))) {
  741. if( ((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR750P)) ||
  742. ((!(VBFlags & (TV_YPBPR | TV_PALM))) && (VBFlags & TV_PAL)) ) {
  743. if(VDisplay == 576) ModeIndex = ModeIndex_768x576[Depth];
  744. }
  745. }
  746. break;
  747. case 800:
  748. if(VDisplay == 600) ModeIndex = ModeIndex_800x600[Depth];
  749. else if(VDisplay == 480) {
  750. if(!((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR750P))) {
  751. ModeIndex = ModeIndex_800x480[Depth];
  752. }
  753. }
  754. break;
  755. case 960:
  756. if(VGAEngine == SIS_315_VGA) {
  757. if(VDisplay == 600) {
  758. if((VBFlags & TV_HIVISION) || ((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR1080I))) {
  759. ModeIndex = ModeIndex_960x600[Depth];
  760. }
  761. }
  762. }
  763. break;
  764. case 1024:
  765. if(VDisplay == 768) {
  766. if(VBFlags2 & VB2_30xBLV) {
  767. ModeIndex = ModeIndex_1024x768[Depth];
  768. }
  769. } else if(VDisplay == 576) {
  770. if( (VBFlags & TV_HIVISION) ||
  771. ((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR1080I)) ||
  772. ((VBFlags2 & VB2_30xBLV) &&
  773. ((!(VBFlags & (TV_YPBPR | TV_PALM))) && (VBFlags & TV_PAL))) ) {
  774. ModeIndex = ModeIndex_1024x576[Depth];
  775. }
  776. }
  777. break;
  778. case 1280:
  779. if(VDisplay == 720) {
  780. if((VBFlags & TV_HIVISION) ||
  781. ((VBFlags & TV_YPBPR) && (VBFlags & (TV_YPBPR1080I | TV_YPBPR750P)))) {
  782. ModeIndex = ModeIndex_1280x720[Depth];
  783. }
  784. } else if(VDisplay == 1024) {
  785. if((VBFlags & TV_HIVISION) ||
  786. ((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR1080I))) {
  787. ModeIndex = ModeIndex_1280x1024[Depth];
  788. }
  789. }
  790. break;
  791. }
  792. }
  793. return ModeIndex;
  794. }
  795. unsigned short
  796. SiS_GetModeID_VGA2(int VGAEngine, unsigned int VBFlags, int HDisplay, int VDisplay, int Depth,
  797. unsigned int VBFlags2)
  798. {
  799. if(!(VBFlags2 & VB2_SISVGA2BRIDGE)) return 0;
  800. if(HDisplay >= 1920) return 0;
  801. switch(HDisplay)
  802. {
  803. case 1600:
  804. if(VDisplay == 1200) {
  805. if(VGAEngine != SIS_315_VGA) return 0;
  806. if(!(VBFlags2 & VB2_30xB)) return 0;
  807. }
  808. break;
  809. case 1680:
  810. if(VDisplay == 1050) {
  811. if(VGAEngine != SIS_315_VGA) return 0;
  812. if(!(VBFlags2 & VB2_30xB)) return 0;
  813. }
  814. break;
  815. }
  816. return SiS_GetModeID(VGAEngine, 0, HDisplay, VDisplay, Depth, false, 0, 0);
  817. }
  818. /*********************************************/
  819. /* HELPER: SetReg, GetReg */
  820. /*********************************************/
  821. void
  822. SiS_SetReg(SISIOADDRESS port, u8 index, u8 data)
  823. {
  824. outb(index, port);
  825. outb(data, port + 1);
  826. }
  827. void
  828. SiS_SetRegByte(SISIOADDRESS port, u8 data)
  829. {
  830. outb(data, port);
  831. }
  832. void
  833. SiS_SetRegShort(SISIOADDRESS port, u16 data)
  834. {
  835. outw(data, port);
  836. }
  837. void
  838. SiS_SetRegLong(SISIOADDRESS port, u32 data)
  839. {
  840. outl(data, port);
  841. }
  842. u8
  843. SiS_GetReg(SISIOADDRESS port, u8 index)
  844. {
  845. outb(index, port);
  846. return inb(port + 1);
  847. }
  848. u8
  849. SiS_GetRegByte(SISIOADDRESS port)
  850. {
  851. return inb(port);
  852. }
  853. u16
  854. SiS_GetRegShort(SISIOADDRESS port)
  855. {
  856. return inw(port);
  857. }
  858. u32
  859. SiS_GetRegLong(SISIOADDRESS port)
  860. {
  861. return inl(port);
  862. }
  863. void
  864. SiS_SetRegANDOR(SISIOADDRESS Port, u8 Index, u8 DataAND, u8 DataOR)
  865. {
  866. u8 temp;
  867. temp = SiS_GetReg(Port, Index);
  868. temp = (temp & (DataAND)) | DataOR;
  869. SiS_SetReg(Port, Index, temp);
  870. }
  871. void
  872. SiS_SetRegAND(SISIOADDRESS Port, u8 Index, u8 DataAND)
  873. {
  874. u8 temp;
  875. temp = SiS_GetReg(Port, Index);
  876. temp &= DataAND;
  877. SiS_SetReg(Port, Index, temp);
  878. }
  879. void
  880. SiS_SetRegOR(SISIOADDRESS Port, u8 Index, u8 DataOR)
  881. {
  882. u8 temp;
  883. temp = SiS_GetReg(Port, Index);
  884. temp |= DataOR;
  885. SiS_SetReg(Port, Index, temp);
  886. }
  887. /*********************************************/
  888. /* HELPER: DisplayOn, DisplayOff */
  889. /*********************************************/
  890. void
  891. SiS_DisplayOn(struct SiS_Private *SiS_Pr)
  892. {
  893. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x01,0xDF);
  894. }
  895. void
  896. SiS_DisplayOff(struct SiS_Private *SiS_Pr)
  897. {
  898. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x01,0x20);
  899. }
  900. /*********************************************/
  901. /* HELPER: Init Port Addresses */
  902. /*********************************************/
  903. void
  904. SiSRegInit(struct SiS_Private *SiS_Pr, SISIOADDRESS BaseAddr)
  905. {
  906. SiS_Pr->SiS_P3c4 = BaseAddr + 0x14;
  907. SiS_Pr->SiS_P3d4 = BaseAddr + 0x24;
  908. SiS_Pr->SiS_P3c0 = BaseAddr + 0x10;
  909. SiS_Pr->SiS_P3ce = BaseAddr + 0x1e;
  910. SiS_Pr->SiS_P3c2 = BaseAddr + 0x12;
  911. SiS_Pr->SiS_P3ca = BaseAddr + 0x1a;
  912. SiS_Pr->SiS_P3c6 = BaseAddr + 0x16;
  913. SiS_Pr->SiS_P3c7 = BaseAddr + 0x17;
  914. SiS_Pr->SiS_P3c8 = BaseAddr + 0x18;
  915. SiS_Pr->SiS_P3c9 = BaseAddr + 0x19;
  916. SiS_Pr->SiS_P3cb = BaseAddr + 0x1b;
  917. SiS_Pr->SiS_P3cc = BaseAddr + 0x1c;
  918. SiS_Pr->SiS_P3cd = BaseAddr + 0x1d;
  919. SiS_Pr->SiS_P3da = BaseAddr + 0x2a;
  920. SiS_Pr->SiS_Part1Port = BaseAddr + SIS_CRT2_PORT_04;
  921. SiS_Pr->SiS_Part2Port = BaseAddr + SIS_CRT2_PORT_10;
  922. SiS_Pr->SiS_Part3Port = BaseAddr + SIS_CRT2_PORT_12;
  923. SiS_Pr->SiS_Part4Port = BaseAddr + SIS_CRT2_PORT_14;
  924. SiS_Pr->SiS_Part5Port = BaseAddr + SIS_CRT2_PORT_14 + 2;
  925. SiS_Pr->SiS_DDC_Port = BaseAddr + 0x14;
  926. SiS_Pr->SiS_VidCapt = BaseAddr + SIS_VIDEO_CAPTURE;
  927. SiS_Pr->SiS_VidPlay = BaseAddr + SIS_VIDEO_PLAYBACK;
  928. }
  929. /*********************************************/
  930. /* HELPER: GetSysFlags */
  931. /*********************************************/
  932. static void
  933. SiS_GetSysFlags(struct SiS_Private *SiS_Pr)
  934. {
  935. unsigned char cr5f, temp1, temp2;
  936. /* 661 and newer: NEVER write non-zero to SR11[7:4] */
  937. /* (SR11 is used for DDC and in enable/disablebridge) */
  938. SiS_Pr->SiS_SensibleSR11 = false;
  939. SiS_Pr->SiS_MyCR63 = 0x63;
  940. if(SiS_Pr->ChipType >= SIS_330) {
  941. SiS_Pr->SiS_MyCR63 = 0x53;
  942. if(SiS_Pr->ChipType >= SIS_661) {
  943. SiS_Pr->SiS_SensibleSR11 = true;
  944. }
  945. }
  946. /* You should use the macros, not these flags directly */
  947. SiS_Pr->SiS_SysFlags = 0;
  948. if(SiS_Pr->ChipType == SIS_650) {
  949. cr5f = SiS_GetReg(SiS_Pr->SiS_P3d4,0x5f) & 0xf0;
  950. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x5c,0x07);
  951. temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x5c) & 0xf8;
  952. SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x5c,0xf8);
  953. temp2 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x5c) & 0xf8;
  954. if((!temp1) || (temp2)) {
  955. switch(cr5f) {
  956. case 0x80:
  957. case 0x90:
  958. case 0xc0:
  959. SiS_Pr->SiS_SysFlags |= SF_IsM650;
  960. break;
  961. case 0xa0:
  962. case 0xb0:
  963. case 0xe0:
  964. SiS_Pr->SiS_SysFlags |= SF_Is651;
  965. break;
  966. }
  967. } else {
  968. switch(cr5f) {
  969. case 0x90:
  970. temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x5c) & 0xf8;
  971. switch(temp1) {
  972. case 0x00: SiS_Pr->SiS_SysFlags |= SF_IsM652; break;
  973. case 0x40: SiS_Pr->SiS_SysFlags |= SF_IsM653; break;
  974. default: SiS_Pr->SiS_SysFlags |= SF_IsM650; break;
  975. }
  976. break;
  977. case 0xb0:
  978. SiS_Pr->SiS_SysFlags |= SF_Is652;
  979. break;
  980. default:
  981. SiS_Pr->SiS_SysFlags |= SF_IsM650;
  982. break;
  983. }
  984. }
  985. }
  986. if(SiS_Pr->ChipType >= SIS_760 && SiS_Pr->ChipType <= SIS_761) {
  987. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x78) & 0x30) {
  988. SiS_Pr->SiS_SysFlags |= SF_760LFB;
  989. }
  990. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x79) & 0xf0) {
  991. SiS_Pr->SiS_SysFlags |= SF_760UMA;
  992. }
  993. }
  994. }
  995. /*********************************************/
  996. /* HELPER: Init PCI & Engines */
  997. /*********************************************/
  998. static void
  999. SiSInitPCIetc(struct SiS_Private *SiS_Pr)
  1000. {
  1001. switch(SiS_Pr->ChipType) {
  1002. #ifdef CONFIG_FB_SIS_300
  1003. case SIS_300:
  1004. case SIS_540:
  1005. case SIS_630:
  1006. case SIS_730:
  1007. /* Set - PCI LINEAR ADDRESSING ENABLE (0x80)
  1008. * - RELOCATED VGA IO ENABLED (0x20)
  1009. * - MMIO ENABLED (0x01)
  1010. * Leave other bits untouched.
  1011. */
  1012. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x20,0xa1);
  1013. /* - Enable 2D (0x40)
  1014. * - Enable 3D (0x02)
  1015. * - Enable 3D Vertex command fetch (0x10) ?
  1016. * - Enable 3D command parser (0x08) ?
  1017. */
  1018. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x5A);
  1019. break;
  1020. #endif
  1021. #ifdef CONFIG_FB_SIS_315
  1022. case SIS_315H:
  1023. case SIS_315:
  1024. case SIS_315PRO:
  1025. case SIS_650:
  1026. case SIS_740:
  1027. case SIS_330:
  1028. case SIS_661:
  1029. case SIS_741:
  1030. case SIS_660:
  1031. case SIS_760:
  1032. case SIS_761:
  1033. case SIS_340:
  1034. case XGI_40:
  1035. /* See above */
  1036. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x20,0xa1);
  1037. /* - Enable 3D G/L transformation engine (0x80)
  1038. * - Enable 2D (0x40)
  1039. * - Enable 3D vertex command fetch (0x10)
  1040. * - Enable 3D command parser (0x08)
  1041. * - Enable 3D (0x02)
  1042. */
  1043. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0xDA);
  1044. break;
  1045. case XGI_20:
  1046. case SIS_550:
  1047. /* See above */
  1048. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x20,0xa1);
  1049. /* No 3D engine ! */
  1050. /* - Enable 2D (0x40)
  1051. * - disable 3D
  1052. */
  1053. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x1E,0x60,0x40);
  1054. break;
  1055. #endif
  1056. default:
  1057. break;
  1058. }
  1059. }
  1060. /*********************************************/
  1061. /* HELPER: SetLVDSetc */
  1062. /*********************************************/
  1063. static
  1064. void
  1065. SiSSetLVDSetc(struct SiS_Private *SiS_Pr)
  1066. {
  1067. unsigned short temp;
  1068. SiS_Pr->SiS_IF_DEF_LVDS = 0;
  1069. SiS_Pr->SiS_IF_DEF_TRUMPION = 0;
  1070. SiS_Pr->SiS_IF_DEF_CH70xx = 0;
  1071. SiS_Pr->SiS_IF_DEF_CONEX = 0;
  1072. SiS_Pr->SiS_ChrontelInit = 0;
  1073. if(SiS_Pr->ChipType == XGI_20) return;
  1074. /* Check for SiS30x first */
  1075. temp = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x00);
  1076. if((temp == 1) || (temp == 2)) return;
  1077. switch(SiS_Pr->ChipType) {
  1078. #ifdef CONFIG_FB_SIS_300
  1079. case SIS_540:
  1080. case SIS_630:
  1081. case SIS_730:
  1082. temp = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x37) & 0x0e) >> 1;
  1083. if((temp >= 2) && (temp <= 5)) SiS_Pr->SiS_IF_DEF_LVDS = 1;
  1084. if(temp == 3) SiS_Pr->SiS_IF_DEF_TRUMPION = 1;
  1085. if((temp == 4) || (temp == 5)) {
  1086. /* Save power status (and error check) - UNUSED */
  1087. SiS_Pr->SiS_Backup70xx = SiS_GetCH700x(SiS_Pr, 0x0e);
  1088. SiS_Pr->SiS_IF_DEF_CH70xx = 1;
  1089. }
  1090. break;
  1091. #endif
  1092. #ifdef CONFIG_FB_SIS_315
  1093. case SIS_550:
  1094. case SIS_650:
  1095. case SIS_740:
  1096. case SIS_330:
  1097. temp = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x37) & 0x0e) >> 1;
  1098. if((temp >= 2) && (temp <= 3)) SiS_Pr->SiS_IF_DEF_LVDS = 1;
  1099. if(temp == 3) SiS_Pr->SiS_IF_DEF_CH70xx = 2;
  1100. break;
  1101. case SIS_661:
  1102. case SIS_741:
  1103. case SIS_660:
  1104. case SIS_760:
  1105. case SIS_761:
  1106. case SIS_340:
  1107. case XGI_20:
  1108. case XGI_40:
  1109. temp = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x38) & 0xe0) >> 5;
  1110. if((temp >= 2) && (temp <= 3)) SiS_Pr->SiS_IF_DEF_LVDS = 1;
  1111. if(temp == 3) SiS_Pr->SiS_IF_DEF_CH70xx = 2;
  1112. if(temp == 4) SiS_Pr->SiS_IF_DEF_CONEX = 1; /* Not yet supported */
  1113. break;
  1114. #endif
  1115. default:
  1116. break;
  1117. }
  1118. }
  1119. /*********************************************/
  1120. /* HELPER: Enable DSTN/FSTN */
  1121. /*********************************************/
  1122. void
  1123. SiS_SetEnableDstn(struct SiS_Private *SiS_Pr, int enable)
  1124. {
  1125. SiS_Pr->SiS_IF_DEF_DSTN = enable ? 1 : 0;
  1126. }
  1127. void
  1128. SiS_SetEnableFstn(struct SiS_Private *SiS_Pr, int enable)
  1129. {
  1130. SiS_Pr->SiS_IF_DEF_FSTN = enable ? 1 : 0;
  1131. }
  1132. /*********************************************/
  1133. /* HELPER: Get modeflag */
  1134. /*********************************************/
  1135. unsigned short
  1136. SiS_GetModeFlag(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
  1137. unsigned short ModeIdIndex)
  1138. {
  1139. if(SiS_Pr->UseCustomMode) {
  1140. return SiS_Pr->CModeFlag;
  1141. } else if(ModeNo <= 0x13) {
  1142. return SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  1143. } else {
  1144. return SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  1145. }
  1146. }
  1147. /*********************************************/
  1148. /* HELPER: Determine ROM usage */
  1149. /*********************************************/
  1150. bool
  1151. SiSDetermineROMLayout661(struct SiS_Private *SiS_Pr)
  1152. {
  1153. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  1154. unsigned short romversoffs, romvmaj = 1, romvmin = 0;
  1155. if(SiS_Pr->ChipType >= XGI_20) {
  1156. /* XGI ROMs don't qualify */
  1157. return false;
  1158. } else if(SiS_Pr->ChipType >= SIS_761) {
  1159. /* I very much assume 761, 340 and newer will use new layout */
  1160. return true;
  1161. } else if(SiS_Pr->ChipType >= SIS_661) {
  1162. if((ROMAddr[0x1a] == 'N') &&
  1163. (ROMAddr[0x1b] == 'e') &&
  1164. (ROMAddr[0x1c] == 'w') &&
  1165. (ROMAddr[0x1d] == 'V')) {
  1166. return true;
  1167. }
  1168. romversoffs = ROMAddr[0x16] | (ROMAddr[0x17] << 8);
  1169. if(romversoffs) {
  1170. if((ROMAddr[romversoffs+1] == '.') || (ROMAddr[romversoffs+4] == '.')) {
  1171. romvmaj = ROMAddr[romversoffs] - '0';
  1172. romvmin = ((ROMAddr[romversoffs+2] -'0') * 10) + (ROMAddr[romversoffs+3] - '0');
  1173. }
  1174. }
  1175. if((romvmaj != 0) || (romvmin >= 92)) {
  1176. return true;
  1177. }
  1178. } else if(IS_SIS650740) {
  1179. if((ROMAddr[0x1a] == 'N') &&
  1180. (ROMAddr[0x1b] == 'e') &&
  1181. (ROMAddr[0x1c] == 'w') &&
  1182. (ROMAddr[0x1d] == 'V')) {
  1183. return true;
  1184. }
  1185. }
  1186. return false;
  1187. }
  1188. static void
  1189. SiSDetermineROMUsage(struct SiS_Private *SiS_Pr)
  1190. {
  1191. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  1192. unsigned short romptr = 0;
  1193. SiS_Pr->SiS_UseROM = false;
  1194. SiS_Pr->SiS_ROMNew = false;
  1195. SiS_Pr->SiS_PWDOffset = 0;
  1196. if(SiS_Pr->ChipType >= XGI_20) return;
  1197. if((ROMAddr) && (SiS_Pr->UseROM)) {
  1198. if(SiS_Pr->ChipType == SIS_300) {
  1199. /* 300: We check if the code starts below 0x220 by
  1200. * checking the jmp instruction at the beginning
  1201. * of the BIOS image.
  1202. */
  1203. if((ROMAddr[3] == 0xe9) && ((ROMAddr[5] << 8) | ROMAddr[4]) > 0x21a)
  1204. SiS_Pr->SiS_UseROM = true;
  1205. } else if(SiS_Pr->ChipType < SIS_315H) {
  1206. /* Sony's VAIO BIOS 1.09 follows the standard, so perhaps
  1207. * the others do as well
  1208. */
  1209. SiS_Pr->SiS_UseROM = true;
  1210. } else {
  1211. /* 315/330 series stick to the standard(s) */
  1212. SiS_Pr->SiS_UseROM = true;
  1213. if((SiS_Pr->SiS_ROMNew = SiSDetermineROMLayout661(SiS_Pr))) {
  1214. SiS_Pr->SiS_EMIOffset = 14;
  1215. SiS_Pr->SiS_PWDOffset = 17;
  1216. SiS_Pr->SiS661LCD2TableSize = 36;
  1217. /* Find out about LCD data table entry size */
  1218. if((romptr = SISGETROMW(0x0102))) {
  1219. if(ROMAddr[romptr + (32 * 16)] == 0xff)
  1220. SiS_Pr->SiS661LCD2TableSize = 32;
  1221. else if(ROMAddr[romptr + (34 * 16)] == 0xff)
  1222. SiS_Pr->SiS661LCD2TableSize = 34;
  1223. else if(ROMAddr[romptr + (36 * 16)] == 0xff) /* 0.94, 2.05.00+ */
  1224. SiS_Pr->SiS661LCD2TableSize = 36;
  1225. else if( (ROMAddr[romptr + (38 * 16)] == 0xff) || /* 2.00.00 - 2.02.00 */
  1226. (ROMAddr[0x6F] & 0x01) ) { /* 2.03.00 - <2.05.00 */
  1227. SiS_Pr->SiS661LCD2TableSize = 38; /* UMC data layout abandoned at 2.05.00 */
  1228. SiS_Pr->SiS_EMIOffset = 16;
  1229. SiS_Pr->SiS_PWDOffset = 19;
  1230. }
  1231. }
  1232. }
  1233. }
  1234. }
  1235. }
  1236. /*********************************************/
  1237. /* HELPER: SET SEGMENT REGISTERS */
  1238. /*********************************************/
  1239. static void
  1240. SiS_SetSegRegLower(struct SiS_Private *SiS_Pr, unsigned short value)
  1241. {
  1242. unsigned short temp;
  1243. value &= 0x00ff;
  1244. temp = SiS_GetRegByte(SiS_Pr->SiS_P3cb) & 0xf0;
  1245. temp |= (value >> 4);
  1246. SiS_SetRegByte(SiS_Pr->SiS_P3cb, temp);
  1247. temp = SiS_GetRegByte(SiS_Pr->SiS_P3cd) & 0xf0;
  1248. temp |= (value & 0x0f);
  1249. SiS_SetRegByte(SiS_Pr->SiS_P3cd, temp);
  1250. }
  1251. static void
  1252. SiS_SetSegRegUpper(struct SiS_Private *SiS_Pr, unsigned short value)
  1253. {
  1254. unsigned short temp;
  1255. value &= 0x00ff;
  1256. temp = SiS_GetRegByte(SiS_Pr->SiS_P3cb) & 0x0f;
  1257. temp |= (value & 0xf0);
  1258. SiS_SetRegByte(SiS_Pr->SiS_P3cb, temp);
  1259. temp = SiS_GetRegByte(SiS_Pr->SiS_P3cd) & 0x0f;
  1260. temp |= (value << 4);
  1261. SiS_SetRegByte(SiS_Pr->SiS_P3cd, temp);
  1262. }
  1263. static void
  1264. SiS_SetSegmentReg(struct SiS_Private *SiS_Pr, unsigned short value)
  1265. {
  1266. SiS_SetSegRegLower(SiS_Pr, value);
  1267. SiS_SetSegRegUpper(SiS_Pr, value);
  1268. }
  1269. static void
  1270. SiS_ResetSegmentReg(struct SiS_Private *SiS_Pr)
  1271. {
  1272. SiS_SetSegmentReg(SiS_Pr, 0);
  1273. }
  1274. static void
  1275. SiS_SetSegmentRegOver(struct SiS_Private *SiS_Pr, unsigned short value)
  1276. {
  1277. unsigned short temp = value >> 8;
  1278. temp &= 0x07;
  1279. temp |= (temp << 4);
  1280. SiS_SetReg(SiS_Pr->SiS_P3c4,0x1d,temp);
  1281. SiS_SetSegmentReg(SiS_Pr, value);
  1282. }
  1283. static void
  1284. SiS_ResetSegmentRegOver(struct SiS_Private *SiS_Pr)
  1285. {
  1286. SiS_SetSegmentRegOver(SiS_Pr, 0);
  1287. }
  1288. static void
  1289. SiS_ResetSegmentRegisters(struct SiS_Private *SiS_Pr)
  1290. {
  1291. if((IS_SIS65x) || (SiS_Pr->ChipType >= SIS_661)) {
  1292. SiS_ResetSegmentReg(SiS_Pr);
  1293. SiS_ResetSegmentRegOver(SiS_Pr);
  1294. }
  1295. }
  1296. /*********************************************/
  1297. /* HELPER: GetVBType */
  1298. /*********************************************/
  1299. static
  1300. void
  1301. SiS_GetVBType(struct SiS_Private *SiS_Pr)
  1302. {
  1303. unsigned short flag = 0, rev = 0, nolcd = 0;
  1304. unsigned short p4_0f, p4_25, p4_27;
  1305. SiS_Pr->SiS_VBType = 0;
  1306. if((SiS_Pr->SiS_IF_DEF_LVDS) || (SiS_Pr->SiS_IF_DEF_CONEX))
  1307. return;
  1308. if(SiS_Pr->ChipType == XGI_20)
  1309. return;
  1310. flag = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x00);
  1311. if(flag > 3)
  1312. return;
  1313. rev = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x01);
  1314. if(flag >= 2) {
  1315. SiS_Pr->SiS_VBType = VB_SIS302B;
  1316. } else if(flag == 1) {
  1317. if(rev >= 0xC0) {
  1318. SiS_Pr->SiS_VBType = VB_SIS301C;
  1319. } else if(rev >= 0xB0) {
  1320. SiS_Pr->SiS_VBType = VB_SIS301B;
  1321. /* Check if 30xB DH version (no LCD support, use Panel Link instead) */
  1322. nolcd = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x23);
  1323. if(!(nolcd & 0x02)) SiS_Pr->SiS_VBType |= VB_NoLCD;
  1324. } else {
  1325. SiS_Pr->SiS_VBType = VB_SIS301;
  1326. }
  1327. }
  1328. if(SiS_Pr->SiS_VBType & (VB_SIS301B | VB_SIS301C | VB_SIS302B)) {
  1329. if(rev >= 0xE0) {
  1330. flag = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x39);
  1331. if(flag == 0xff) SiS_Pr->SiS_VBType = VB_SIS302LV;
  1332. else SiS_Pr->SiS_VBType = VB_SIS301C; /* VB_SIS302ELV; */
  1333. } else if(rev >= 0xD0) {
  1334. SiS_Pr->SiS_VBType = VB_SIS301LV;
  1335. }
  1336. }
  1337. if(SiS_Pr->SiS_VBType & (VB_SIS301C | VB_SIS301LV | VB_SIS302LV | VB_SIS302ELV)) {
  1338. p4_0f = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x0f);
  1339. p4_25 = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x25);
  1340. p4_27 = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x27);
  1341. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x0f,0x7f);
  1342. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x25,0x08);
  1343. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x27,0xfd);
  1344. if(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x26) & 0x08) {
  1345. SiS_Pr->SiS_VBType |= VB_UMC;
  1346. }
  1347. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x27,p4_27);
  1348. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x25,p4_25);
  1349. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0f,p4_0f);
  1350. }
  1351. }
  1352. /*********************************************/
  1353. /* HELPER: Check RAM size */
  1354. /*********************************************/
  1355. static bool
  1356. SiS_CheckMemorySize(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
  1357. unsigned short ModeIdIndex)
  1358. {
  1359. unsigned short AdapterMemSize = SiS_Pr->VideoMemorySize / (1024*1024);
  1360. unsigned short modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
  1361. unsigned short memorysize = ((modeflag & MemoryInfoFlag) >> MemorySizeShift) + 1;
  1362. if(!AdapterMemSize) return true;
  1363. if(AdapterMemSize < memorysize) return false;
  1364. return true;
  1365. }
  1366. /*********************************************/
  1367. /* HELPER: Get DRAM type */
  1368. /*********************************************/
  1369. #ifdef CONFIG_FB_SIS_315
  1370. static unsigned char
  1371. SiS_Get310DRAMType(struct SiS_Private *SiS_Pr)
  1372. {
  1373. unsigned char data;
  1374. if((*SiS_Pr->pSiS_SoftSetting) & SoftDRAMType) {
  1375. data = (*SiS_Pr->pSiS_SoftSetting) & 0x03;
  1376. } else {
  1377. if(SiS_Pr->ChipType >= XGI_20) {
  1378. /* Do I need this? SR17 seems to be zero anyway... */
  1379. data = 0;
  1380. } else if(SiS_Pr->ChipType >= SIS_340) {
  1381. /* TODO */
  1382. data = 0;
  1383. } else if(SiS_Pr->ChipType >= SIS_661) {
  1384. if(SiS_Pr->SiS_ROMNew) {
  1385. data = ((SiS_GetReg(SiS_Pr->SiS_P3d4,0x78) & 0xc0) >> 6);
  1386. } else {
  1387. data = SiS_GetReg(SiS_Pr->SiS_P3d4,0x78) & 0x07;
  1388. }
  1389. } else if(IS_SIS550650740) {
  1390. data = SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x07;
  1391. } else { /* 315, 330 */
  1392. data = SiS_GetReg(SiS_Pr->SiS_P3c4,0x3a) & 0x03;
  1393. if(SiS_Pr->ChipType == SIS_330) {
  1394. if(data > 1) {
  1395. switch(SiS_GetReg(SiS_Pr->SiS_P3d4,0x5f) & 0x30) {
  1396. case 0x00: data = 1; break;
  1397. case 0x10: data = 3; break;
  1398. case 0x20: data = 3; break;
  1399. case 0x30: data = 2; break;
  1400. }
  1401. } else {
  1402. data = 0;
  1403. }
  1404. }
  1405. }
  1406. }
  1407. return data;
  1408. }
  1409. static unsigned short
  1410. SiS_GetMCLK(struct SiS_Private *SiS_Pr)
  1411. {
  1412. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  1413. unsigned short index;
  1414. index = SiS_Get310DRAMType(SiS_Pr);
  1415. if(SiS_Pr->ChipType >= SIS_661) {
  1416. if(SiS_Pr->SiS_ROMNew) {
  1417. return((unsigned short)(SISGETROMW((0x90 + (index * 5) + 3))));
  1418. }
  1419. return(SiS_Pr->SiS_MCLKData_0[index].CLOCK);
  1420. } else if(index >= 4) {
  1421. return(SiS_Pr->SiS_MCLKData_1[index - 4].CLOCK);
  1422. } else {
  1423. return(SiS_Pr->SiS_MCLKData_0[index].CLOCK);
  1424. }
  1425. }
  1426. #endif
  1427. /*********************************************/
  1428. /* HELPER: ClearBuffer */
  1429. /*********************************************/
  1430. static void
  1431. SiS_ClearBuffer(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
  1432. {
  1433. unsigned char SISIOMEMTYPE *memaddr = SiS_Pr->VideoMemoryAddress;
  1434. unsigned int memsize = SiS_Pr->VideoMemorySize;
  1435. unsigned short SISIOMEMTYPE *pBuffer;
  1436. int i;
  1437. if(!memaddr || !memsize) return;
  1438. if(SiS_Pr->SiS_ModeType >= ModeEGA) {
  1439. if(ModeNo > 0x13) {
  1440. memset_io(memaddr, 0, memsize);
  1441. } else {
  1442. pBuffer = (unsigned short SISIOMEMTYPE *)memaddr;
  1443. for(i = 0; i < 0x4000; i++) writew(0x0000, &pBuffer[i]);
  1444. }
  1445. } else if(SiS_Pr->SiS_ModeType < ModeCGA) {
  1446. pBuffer = (unsigned short SISIOMEMTYPE *)memaddr;
  1447. for(i = 0; i < 0x4000; i++) writew(0x0720, &pBuffer[i]);
  1448. } else {
  1449. memset_io(memaddr, 0, 0x8000);
  1450. }
  1451. }
  1452. /*********************************************/
  1453. /* HELPER: SearchModeID */
  1454. /*********************************************/
  1455. bool
  1456. SiS_SearchModeID(struct SiS_Private *SiS_Pr, unsigned short *ModeNo,
  1457. unsigned short *ModeIdIndex)
  1458. {
  1459. unsigned char VGAINFO = SiS_Pr->SiS_VGAINFO;
  1460. if((*ModeNo) <= 0x13) {
  1461. if((*ModeNo) <= 0x05) (*ModeNo) |= 0x01;
  1462. for((*ModeIdIndex) = 0; ;(*ModeIdIndex)++) {
  1463. if(SiS_Pr->SiS_SModeIDTable[(*ModeIdIndex)].St_ModeID == (*ModeNo)) break;
  1464. if(SiS_Pr->SiS_SModeIDTable[(*ModeIdIndex)].St_ModeID == 0xFF) return false;
  1465. }
  1466. if((*ModeNo) == 0x07) {
  1467. if(VGAINFO & 0x10) (*ModeIdIndex)++; /* 400 lines */
  1468. /* else 350 lines */
  1469. }
  1470. if((*ModeNo) <= 0x03) {
  1471. if(!(VGAINFO & 0x80)) (*ModeIdIndex)++;
  1472. if(VGAINFO & 0x10) (*ModeIdIndex)++; /* 400 lines */
  1473. /* else 350 lines */
  1474. }
  1475. /* else 200 lines */
  1476. } else {
  1477. for((*ModeIdIndex) = 0; ;(*ModeIdIndex)++) {
  1478. if(SiS_Pr->SiS_EModeIDTable[(*ModeIdIndex)].Ext_ModeID == (*ModeNo)) break;
  1479. if(SiS_Pr->SiS_EModeIDTable[(*ModeIdIndex)].Ext_ModeID == 0xFF) return false;
  1480. }
  1481. }
  1482. return true;
  1483. }
  1484. /*********************************************/
  1485. /* HELPER: GetModePtr */
  1486. /*********************************************/
  1487. unsigned short
  1488. SiS_GetModePtr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  1489. {
  1490. unsigned short index;
  1491. if(ModeNo <= 0x13) {
  1492. index = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_StTableIndex;
  1493. } else {
  1494. if(SiS_Pr->SiS_ModeType <= ModeEGA) index = 0x1B;
  1495. else index = 0x0F;
  1496. }
  1497. return index;
  1498. }
  1499. /*********************************************/
  1500. /* HELPERS: Get some indices */
  1501. /*********************************************/
  1502. unsigned short
  1503. SiS_GetRefCRTVCLK(struct SiS_Private *SiS_Pr, unsigned short Index, int UseWide)
  1504. {
  1505. if(SiS_Pr->SiS_RefIndex[Index].Ext_InfoFlag & HaveWideTiming) {
  1506. if(UseWide == 1) {
  1507. return SiS_Pr->SiS_RefIndex[Index].Ext_CRTVCLK_WIDE;
  1508. } else {
  1509. return SiS_Pr->SiS_RefIndex[Index].Ext_CRTVCLK_NORM;
  1510. }
  1511. } else {
  1512. return SiS_Pr->SiS_RefIndex[Index].Ext_CRTVCLK;
  1513. }
  1514. }
  1515. unsigned short
  1516. SiS_GetRefCRT1CRTC(struct SiS_Private *SiS_Pr, unsigned short Index, int UseWide)
  1517. {
  1518. if(SiS_Pr->SiS_RefIndex[Index].Ext_InfoFlag & HaveWideTiming) {
  1519. if(UseWide == 1) {
  1520. return SiS_Pr->SiS_RefIndex[Index].Ext_CRT1CRTC_WIDE;
  1521. } else {
  1522. return SiS_Pr->SiS_RefIndex[Index].Ext_CRT1CRTC_NORM;
  1523. }
  1524. } else {
  1525. return SiS_Pr->SiS_RefIndex[Index].Ext_CRT1CRTC;
  1526. }
  1527. }
  1528. /*********************************************/
  1529. /* HELPER: LowModeTests */
  1530. /*********************************************/
  1531. static bool
  1532. SiS_DoLowModeTest(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
  1533. {
  1534. unsigned short temp, temp1, temp2;
  1535. if((ModeNo != 0x03) && (ModeNo != 0x10) && (ModeNo != 0x12))
  1536. return true;
  1537. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x11);
  1538. SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x11,0x80);
  1539. temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x00);
  1540. SiS_SetReg(SiS_Pr->SiS_P3d4,0x00,0x55);
  1541. temp2 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x00);
  1542. SiS_SetReg(SiS_Pr->SiS_P3d4,0x00,temp1);
  1543. SiS_SetReg(SiS_Pr->SiS_P3d4,0x11,temp);
  1544. if((SiS_Pr->ChipType >= SIS_315H) ||
  1545. (SiS_Pr->ChipType == SIS_300)) {
  1546. if(temp2 == 0x55) return false;
  1547. else return true;
  1548. } else {
  1549. if(temp2 != 0x55) return true;
  1550. else {
  1551. SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x35,0x01);
  1552. return false;
  1553. }
  1554. }
  1555. }
  1556. static void
  1557. SiS_SetLowModeTest(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
  1558. {
  1559. if(SiS_DoLowModeTest(SiS_Pr, ModeNo)) {
  1560. SiS_Pr->SiS_SetFlag |= LowModeTests;
  1561. }
  1562. }
  1563. /*********************************************/
  1564. /* HELPER: OPEN/CLOSE CRT1 CRTC */
  1565. /*********************************************/
  1566. static void
  1567. SiS_OpenCRTC(struct SiS_Private *SiS_Pr)
  1568. {
  1569. if(IS_SIS650) {
  1570. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x51,0x1f);
  1571. if(IS_SIS651) SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x51,0x20);
  1572. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x56,0xe7);
  1573. } else if(IS_SIS661741660760) {
  1574. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x61,0xf7);
  1575. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x51,0x1f);
  1576. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x56,0xe7);
  1577. if(!SiS_Pr->SiS_ROMNew) {
  1578. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x3a,0xef);
  1579. }
  1580. }
  1581. }
  1582. static void
  1583. SiS_CloseCRTC(struct SiS_Private *SiS_Pr)
  1584. {
  1585. #if 0 /* This locks some CRTC registers. We don't want that. */
  1586. unsigned short temp1 = 0, temp2 = 0;
  1587. if(IS_SIS661741660760) {
  1588. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  1589. temp1 = 0xa0; temp2 = 0x08;
  1590. }
  1591. SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x51,0x1f,temp1);
  1592. SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x56,0xe7,temp2);
  1593. }
  1594. #endif
  1595. }
  1596. static void
  1597. SiS_HandleCRT1(struct SiS_Private *SiS_Pr)
  1598. {
  1599. /* Enable CRT1 gating */
  1600. SiS_SetRegAND(SiS_Pr->SiS_P3d4,SiS_Pr->SiS_MyCR63,0xbf);
  1601. #if 0
  1602. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x15) & 0x01)) {
  1603. if((SiS_GetReg(SiS_Pr->SiS_P3c4,0x15) & 0x0a) ||
  1604. (SiS_GetReg(SiS_Pr->SiS_P3c4,0x16) & 0x01)) {
  1605. SiS_SetRegOR(SiS_Pr->SiS_P3d4,SiS_Pr->SiS_MyCR63,0x40);
  1606. }
  1607. }
  1608. #endif
  1609. }
  1610. /*********************************************/
  1611. /* HELPER: GetColorDepth */
  1612. /*********************************************/
  1613. unsigned short
  1614. SiS_GetColorDepth(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
  1615. unsigned short ModeIdIndex)
  1616. {
  1617. static const unsigned short ColorDepth[6] = { 1, 2, 4, 4, 6, 8 };
  1618. unsigned short modeflag;
  1619. short index;
  1620. /* Do NOT check UseCustomMode, will skrew up FIFO */
  1621. if(ModeNo == 0xfe) {
  1622. modeflag = SiS_Pr->CModeFlag;
  1623. } else if(ModeNo <= 0x13) {
  1624. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  1625. } else {
  1626. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  1627. }
  1628. index = (modeflag & ModeTypeMask) - ModeEGA;
  1629. if(index < 0) index = 0;
  1630. return ColorDepth[index];
  1631. }
  1632. /*********************************************/
  1633. /* HELPER: GetOffset */
  1634. /*********************************************/
  1635. unsigned short
  1636. SiS_GetOffset(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
  1637. unsigned short ModeIdIndex, unsigned short RRTI)
  1638. {
  1639. unsigned short xres, temp, colordepth, infoflag;
  1640. if(SiS_Pr->UseCustomMode) {
  1641. infoflag = SiS_Pr->CInfoFlag;
  1642. xres = SiS_Pr->CHDisplay;
  1643. } else {
  1644. infoflag = SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag;
  1645. xres = SiS_Pr->SiS_RefIndex[RRTI].XRes;
  1646. }
  1647. colordepth = SiS_GetColorDepth(SiS_Pr, ModeNo, ModeIdIndex);
  1648. temp = xres / 16;
  1649. if(infoflag & InterlaceMode) temp <<= 1;
  1650. temp *= colordepth;
  1651. if(xres % 16) temp += (colordepth >> 1);
  1652. return temp;
  1653. }
  1654. /*********************************************/
  1655. /* SEQ */
  1656. /*********************************************/
  1657. static void
  1658. SiS_SetSeqRegs(struct SiS_Private *SiS_Pr, unsigned short StandTableIndex)
  1659. {
  1660. unsigned char SRdata;
  1661. int i;
  1662. SiS_SetReg(SiS_Pr->SiS_P3c4,0x00,0x03);
  1663. /* or "display off" */
  1664. SRdata = SiS_Pr->SiS_StandTable[StandTableIndex].SR[0] | 0x20;
  1665. /* determine whether to force x8 dotclock */
  1666. if((SiS_Pr->SiS_VBType & VB_SISVB) || (SiS_Pr->SiS_IF_DEF_LVDS)) {
  1667. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
  1668. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) SRdata |= 0x01;
  1669. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) SRdata |= 0x01;
  1670. }
  1671. SiS_SetReg(SiS_Pr->SiS_P3c4,0x01,SRdata);
  1672. for(i = 2; i <= 4; i++) {
  1673. SRdata = SiS_Pr->SiS_StandTable[StandTableIndex].SR[i - 1];
  1674. SiS_SetReg(SiS_Pr->SiS_P3c4,i,SRdata);
  1675. }
  1676. }
  1677. /*********************************************/
  1678. /* MISC */
  1679. /*********************************************/
  1680. static void
  1681. SiS_SetMiscRegs(struct SiS_Private *SiS_Pr, unsigned short StandTableIndex)
  1682. {
  1683. unsigned char Miscdata;
  1684. Miscdata = SiS_Pr->SiS_StandTable[StandTableIndex].MISC;
  1685. if(SiS_Pr->ChipType < SIS_661) {
  1686. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  1687. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  1688. Miscdata |= 0x0C;
  1689. }
  1690. }
  1691. }
  1692. SiS_SetRegByte(SiS_Pr->SiS_P3c2,Miscdata);
  1693. }
  1694. /*********************************************/
  1695. /* CRTC */
  1696. /*********************************************/
  1697. static void
  1698. SiS_SetCRTCRegs(struct SiS_Private *SiS_Pr, unsigned short StandTableIndex)
  1699. {
  1700. unsigned char CRTCdata;
  1701. unsigned short i;
  1702. /* Unlock CRTC */
  1703. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x11,0x7f);
  1704. for(i = 0; i <= 0x18; i++) {
  1705. CRTCdata = SiS_Pr->SiS_StandTable[StandTableIndex].CRTC[i];
  1706. SiS_SetReg(SiS_Pr->SiS_P3d4,i,CRTCdata);
  1707. }
  1708. if(SiS_Pr->ChipType >= SIS_661) {
  1709. SiS_OpenCRTC(SiS_Pr);
  1710. for(i = 0x13; i <= 0x14; i++) {
  1711. CRTCdata = SiS_Pr->SiS_StandTable[StandTableIndex].CRTC[i];
  1712. SiS_SetReg(SiS_Pr->SiS_P3d4,i,CRTCdata);
  1713. }
  1714. } else if( ( (SiS_Pr->ChipType == SIS_630) ||
  1715. (SiS_Pr->ChipType == SIS_730) ) &&
  1716. (SiS_Pr->ChipRevision >= 0x30) ) {
  1717. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  1718. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
  1719. SiS_SetReg(SiS_Pr->SiS_P3d4,0x18,0xFE);
  1720. }
  1721. }
  1722. }
  1723. }
  1724. /*********************************************/
  1725. /* ATT */
  1726. /*********************************************/
  1727. static void
  1728. SiS_SetATTRegs(struct SiS_Private *SiS_Pr, unsigned short StandTableIndex)
  1729. {
  1730. unsigned char ARdata;
  1731. unsigned short i;
  1732. for(i = 0; i <= 0x13; i++) {
  1733. ARdata = SiS_Pr->SiS_StandTable[StandTableIndex].ATTR[i];
  1734. if(i == 0x13) {
  1735. /* Pixel shift. If screen on LCD or TV is shifted left or right,
  1736. * this might be the cause.
  1737. */
  1738. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  1739. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) ARdata = 0;
  1740. }
  1741. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  1742. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  1743. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  1744. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) ARdata = 0;
  1745. }
  1746. }
  1747. }
  1748. if(SiS_Pr->ChipType >= SIS_661) {
  1749. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToTV | SetCRT2ToLCD)) {
  1750. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) ARdata = 0;
  1751. }
  1752. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  1753. if(SiS_Pr->ChipType >= SIS_315H) {
  1754. if(IS_SIS550650740660) {
  1755. /* 315, 330 don't do this */
  1756. if(SiS_Pr->SiS_VBType & VB_SIS30xB) {
  1757. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) ARdata = 0;
  1758. } else {
  1759. ARdata = 0;
  1760. }
  1761. }
  1762. } else {
  1763. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) ARdata = 0;
  1764. }
  1765. }
  1766. }
  1767. SiS_GetRegByte(SiS_Pr->SiS_P3da); /* reset 3da */
  1768. SiS_SetRegByte(SiS_Pr->SiS_P3c0,i); /* set index */
  1769. SiS_SetRegByte(SiS_Pr->SiS_P3c0,ARdata); /* set data */
  1770. }
  1771. SiS_GetRegByte(SiS_Pr->SiS_P3da); /* reset 3da */
  1772. SiS_SetRegByte(SiS_Pr->SiS_P3c0,0x14); /* set index */
  1773. SiS_SetRegByte(SiS_Pr->SiS_P3c0,0x00); /* set data */
  1774. SiS_GetRegByte(SiS_Pr->SiS_P3da);
  1775. SiS_SetRegByte(SiS_Pr->SiS_P3c0,0x20); /* Enable Attribute */
  1776. SiS_GetRegByte(SiS_Pr->SiS_P3da);
  1777. }
  1778. /*********************************************/
  1779. /* GRC */
  1780. /*********************************************/
  1781. static void
  1782. SiS_SetGRCRegs(struct SiS_Private *SiS_Pr, unsigned short StandTableIndex)
  1783. {
  1784. unsigned char GRdata;
  1785. unsigned short i;
  1786. for(i = 0; i <= 0x08; i++) {
  1787. GRdata = SiS_Pr->SiS_StandTable[StandTableIndex].GRC[i];
  1788. SiS_SetReg(SiS_Pr->SiS_P3ce,i,GRdata);
  1789. }
  1790. if(SiS_Pr->SiS_ModeType > ModeVGA) {
  1791. /* 256 color disable */
  1792. SiS_SetRegAND(SiS_Pr->SiS_P3ce,0x05,0xBF);
  1793. }
  1794. }
  1795. /*********************************************/
  1796. /* CLEAR EXTENDED REGISTERS */
  1797. /*********************************************/
  1798. static void
  1799. SiS_ClearExt1Regs(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
  1800. {
  1801. unsigned short i;
  1802. for(i = 0x0A; i <= 0x0E; i++) {
  1803. SiS_SetReg(SiS_Pr->SiS_P3c4,i,0x00);
  1804. }
  1805. if(SiS_Pr->ChipType >= SIS_315H) {
  1806. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x37,0xFE);
  1807. if(ModeNo <= 0x13) {
  1808. if(ModeNo == 0x06 || ModeNo >= 0x0e) {
  1809. SiS_SetReg(SiS_Pr->SiS_P3c4,0x0e,0x20);
  1810. }
  1811. }
  1812. }
  1813. }
  1814. /*********************************************/
  1815. /* RESET VCLK */
  1816. /*********************************************/
  1817. static void
  1818. SiS_ResetCRT1VCLK(struct SiS_Private *SiS_Pr)
  1819. {
  1820. if(SiS_Pr->ChipType >= SIS_315H) {
  1821. if(SiS_Pr->ChipType < SIS_661) {
  1822. if(SiS_Pr->SiS_IF_DEF_LVDS == 0) return;
  1823. }
  1824. } else {
  1825. if((SiS_Pr->SiS_IF_DEF_LVDS == 0) &&
  1826. (!(SiS_Pr->SiS_VBType & VB_SIS30xBLV)) ) {
  1827. return;
  1828. }
  1829. }
  1830. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x31,0xcf,0x20);
  1831. SiS_SetReg(SiS_Pr->SiS_P3c4,0x2B,SiS_Pr->SiS_VCLKData[1].SR2B);
  1832. SiS_SetReg(SiS_Pr->SiS_P3c4,0x2C,SiS_Pr->SiS_VCLKData[1].SR2C);
  1833. SiS_SetReg(SiS_Pr->SiS_P3c4,0x2D,0x80);
  1834. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x31,0xcf,0x10);
  1835. SiS_SetReg(SiS_Pr->SiS_P3c4,0x2B,SiS_Pr->SiS_VCLKData[0].SR2B);
  1836. SiS_SetReg(SiS_Pr->SiS_P3c4,0x2C,SiS_Pr->SiS_VCLKData[0].SR2C);
  1837. SiS_SetReg(SiS_Pr->SiS_P3c4,0x2D,0x80);
  1838. }
  1839. /*********************************************/
  1840. /* SYNC */
  1841. /*********************************************/
  1842. static void
  1843. SiS_SetCRT1Sync(struct SiS_Private *SiS_Pr, unsigned short RRTI)
  1844. {
  1845. unsigned short sync;
  1846. if(SiS_Pr->UseCustomMode) {
  1847. sync = SiS_Pr->CInfoFlag >> 8;
  1848. } else {
  1849. sync = SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag >> 8;
  1850. }
  1851. sync &= 0xC0;
  1852. sync |= 0x2f;
  1853. SiS_SetRegByte(SiS_Pr->SiS_P3c2,sync);
  1854. }
  1855. /*********************************************/
  1856. /* CRTC/2 */
  1857. /*********************************************/
  1858. static void
  1859. SiS_SetCRT1CRTC(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
  1860. unsigned short ModeIdIndex, unsigned short RRTI)
  1861. {
  1862. unsigned short temp, i, j, modeflag;
  1863. unsigned char *crt1data = NULL;
  1864. modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
  1865. if(SiS_Pr->UseCustomMode) {
  1866. crt1data = &SiS_Pr->CCRT1CRTC[0];
  1867. } else {
  1868. temp = SiS_GetRefCRT1CRTC(SiS_Pr, RRTI, SiS_Pr->SiS_UseWide);
  1869. /* Alternate for 1600x1200 LCDA */
  1870. if((temp == 0x20) && (SiS_Pr->Alternate1600x1200)) temp = 0x57;
  1871. crt1data = (unsigned char *)&SiS_Pr->SiS_CRT1Table[temp].CR[0];
  1872. }
  1873. /* unlock cr0-7 */
  1874. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x11,0x7f);
  1875. for(i = 0, j = 0; i <= 7; i++, j++) {
  1876. SiS_SetReg(SiS_Pr->SiS_P3d4,j,crt1data[i]);
  1877. }
  1878. for(j = 0x10; i <= 10; i++, j++) {
  1879. SiS_SetReg(SiS_Pr->SiS_P3d4,j,crt1data[i]);
  1880. }
  1881. for(j = 0x15; i <= 12; i++, j++) {
  1882. SiS_SetReg(SiS_Pr->SiS_P3d4,j,crt1data[i]);
  1883. }
  1884. for(j = 0x0A; i <= 15; i++, j++) {
  1885. SiS_SetReg(SiS_Pr->SiS_P3c4,j,crt1data[i]);
  1886. }
  1887. SiS_SetReg(SiS_Pr->SiS_P3c4,0x0E,crt1data[16] & 0xE0);
  1888. temp = (crt1data[16] & 0x01) << 5;
  1889. if(modeflag & DoubleScanMode) temp |= 0x80;
  1890. SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x09,0x5F,temp);
  1891. if(SiS_Pr->SiS_ModeType > ModeVGA) {
  1892. SiS_SetReg(SiS_Pr->SiS_P3d4,0x14,0x4F);
  1893. }
  1894. #ifdef CONFIG_FB_SIS_315
  1895. if(SiS_Pr->ChipType == XGI_20) {
  1896. SiS_SetReg(SiS_Pr->SiS_P3d4,0x04,crt1data[4] - 1);
  1897. if(!(temp = crt1data[5] & 0x1f)) {
  1898. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x0c,0xfb);
  1899. }
  1900. SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x05,0xe0,((temp - 1) & 0x1f));
  1901. temp = (crt1data[16] >> 5) + 3;
  1902. if(temp > 7) temp -= 7;
  1903. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0e,0x1f,(temp << 5));
  1904. }
  1905. #endif
  1906. }
  1907. /*********************************************/
  1908. /* OFFSET & PITCH */
  1909. /*********************************************/
  1910. /* (partly overruled by SetPitch() in XF86) */
  1911. /*********************************************/
  1912. static void
  1913. SiS_SetCRT1Offset(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
  1914. unsigned short ModeIdIndex, unsigned short RRTI)
  1915. {
  1916. unsigned short temp, DisplayUnit, infoflag;
  1917. if(SiS_Pr->UseCustomMode) {
  1918. infoflag = SiS_Pr->CInfoFlag;
  1919. } else {
  1920. infoflag = SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag;
  1921. }
  1922. DisplayUnit = SiS_GetOffset(SiS_Pr, ModeNo, ModeIdIndex, RRTI);
  1923. temp = (DisplayUnit >> 8) & 0x0f;
  1924. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0E,0xF0,temp);
  1925. SiS_SetReg(SiS_Pr->SiS_P3d4,0x13,DisplayUnit & 0xFF);
  1926. if(infoflag & InterlaceMode) DisplayUnit >>= 1;
  1927. DisplayUnit <<= 5;
  1928. temp = (DisplayUnit >> 8) + 1;
  1929. if(DisplayUnit & 0xff) temp++;
  1930. if(SiS_Pr->ChipType == XGI_20) {
  1931. if(ModeNo == 0x4a || ModeNo == 0x49) temp--;
  1932. }
  1933. SiS_SetReg(SiS_Pr->SiS_P3c4,0x10,temp);
  1934. }
  1935. /*********************************************/
  1936. /* VCLK */
  1937. /*********************************************/
  1938. static void
  1939. SiS_SetCRT1VCLK(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
  1940. unsigned short ModeIdIndex, unsigned short RRTI)
  1941. {
  1942. unsigned short index = 0, clka, clkb;
  1943. if(SiS_Pr->UseCustomMode) {
  1944. clka = SiS_Pr->CSR2B;
  1945. clkb = SiS_Pr->CSR2C;
  1946. } else {
  1947. index = SiS_GetVCLK2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RRTI);
  1948. if((SiS_Pr->SiS_VBType & VB_SIS30xBLV) &&
  1949. (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  1950. /* Alternate for 1600x1200 LCDA */
  1951. if((index == 0x21) && (SiS_Pr->Alternate1600x1200)) index = 0x72;
  1952. clka = SiS_Pr->SiS_VBVCLKData[index].Part4_A;
  1953. clkb = SiS_Pr->SiS_VBVCLKData[index].Part4_B;
  1954. } else {
  1955. clka = SiS_Pr->SiS_VCLKData[index].SR2B;
  1956. clkb = SiS_Pr->SiS_VCLKData[index].SR2C;
  1957. }
  1958. }
  1959. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x31,0xCF);
  1960. SiS_SetReg(SiS_Pr->SiS_P3c4,0x2b,clka);
  1961. SiS_SetReg(SiS_Pr->SiS_P3c4,0x2c,clkb);
  1962. if(SiS_Pr->ChipType >= SIS_315H) {
  1963. #ifdef CONFIG_FB_SIS_315
  1964. SiS_SetReg(SiS_Pr->SiS_P3c4,0x2D,0x01);
  1965. if(SiS_Pr->ChipType == XGI_20) {
  1966. unsigned short mf = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
  1967. if(mf & HalfDCLK) {
  1968. SiS_SetReg(SiS_Pr->SiS_P3c4,0x2b,SiS_GetReg(SiS_Pr->SiS_P3c4,0x2b));
  1969. clkb = SiS_GetReg(SiS_Pr->SiS_P3c4,0x2c);
  1970. clkb = (((clkb & 0x1f) << 1) + 1) | (clkb & 0xe0);
  1971. SiS_SetReg(SiS_Pr->SiS_P3c4,0x2c,clkb);
  1972. }
  1973. }
  1974. #endif
  1975. } else {
  1976. SiS_SetReg(SiS_Pr->SiS_P3c4,0x2D,0x80);
  1977. }
  1978. }
  1979. /*********************************************/
  1980. /* FIFO */
  1981. /*********************************************/
  1982. #ifdef CONFIG_FB_SIS_300
  1983. void
  1984. SiS_GetFIFOThresholdIndex300(struct SiS_Private *SiS_Pr, unsigned short *idx1,
  1985. unsigned short *idx2)
  1986. {
  1987. unsigned short temp1, temp2;
  1988. static const unsigned char ThTiming[8] = {
  1989. 1, 2, 2, 3, 0, 1, 1, 2
  1990. };
  1991. temp1 = temp2 = (SiS_GetReg(SiS_Pr->SiS_P3c4,0x18) & 0x62) >> 1;
  1992. (*idx2) = (unsigned short)(ThTiming[((temp2 >> 3) | temp1) & 0x07]);
  1993. (*idx1) = (unsigned short)(SiS_GetReg(SiS_Pr->SiS_P3c4,0x16) >> 6) & 0x03;
  1994. (*idx1) |= (unsigned short)(((SiS_GetReg(SiS_Pr->SiS_P3c4,0x14) >> 4) & 0x0c));
  1995. (*idx1) <<= 1;
  1996. }
  1997. static unsigned short
  1998. SiS_GetFIFOThresholdA300(unsigned short idx1, unsigned short idx2)
  1999. {
  2000. static const unsigned char ThLowA[8 * 3] = {
  2001. 61, 3,52, 5,68, 7,100,11,
  2002. 43, 3,42, 5,54, 7, 78,11,
  2003. 34, 3,37, 5,47, 7, 67,11
  2004. };
  2005. return (unsigned short)((ThLowA[idx1 + 1] * idx2) + ThLowA[idx1]);
  2006. }
  2007. unsigned short
  2008. SiS_GetFIFOThresholdB300(unsigned short idx1, unsigned short idx2)
  2009. {
  2010. static const unsigned char ThLowB[8 * 3] = {
  2011. 81, 4,72, 6,88, 8,120,12,
  2012. 55, 4,54, 6,66, 8, 90,12,
  2013. 42, 4,45, 6,55, 8, 75,12
  2014. };
  2015. return (unsigned short)((ThLowB[idx1 + 1] * idx2) + ThLowB[idx1]);
  2016. }
  2017. static unsigned short
  2018. SiS_DoCalcDelay(struct SiS_Private *SiS_Pr, unsigned short MCLK, unsigned short VCLK,
  2019. unsigned short colordepth, unsigned short key)
  2020. {
  2021. unsigned short idx1, idx2;
  2022. unsigned int longtemp = VCLK * colordepth;
  2023. SiS_GetFIFOThresholdIndex300(SiS_Pr, &idx1, &idx2);
  2024. if(key == 0) {
  2025. longtemp *= SiS_GetFIFOThresholdA300(idx1, idx2);
  2026. } else {
  2027. longtemp *= SiS_GetFIFOThresholdB300(idx1, idx2);
  2028. }
  2029. idx1 = longtemp % (MCLK * 16);
  2030. longtemp /= (MCLK * 16);
  2031. if(idx1) longtemp++;
  2032. return (unsigned short)longtemp;
  2033. }
  2034. static unsigned short
  2035. SiS_CalcDelay(struct SiS_Private *SiS_Pr, unsigned short VCLK,
  2036. unsigned short colordepth, unsigned short MCLK)
  2037. {
  2038. unsigned short temp1, temp2;
  2039. temp2 = SiS_DoCalcDelay(SiS_Pr, MCLK, VCLK, colordepth, 0);
  2040. temp1 = SiS_DoCalcDelay(SiS_Pr, MCLK, VCLK, colordepth, 1);
  2041. if(temp1 < 4) temp1 = 4;
  2042. temp1 -= 4;
  2043. if(temp2 < temp1) temp2 = temp1;
  2044. return temp2;
  2045. }
  2046. static void
  2047. SiS_SetCRT1FIFO_300(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
  2048. unsigned short RefreshRateTableIndex)
  2049. {
  2050. unsigned short ThresholdLow = 0;
  2051. unsigned short temp, index, VCLK, MCLK, colorth;
  2052. static const unsigned short colortharray[6] = { 1, 1, 2, 2, 3, 4 };
  2053. if(ModeNo > 0x13) {
  2054. /* Get VCLK */
  2055. if(SiS_Pr->UseCustomMode) {
  2056. VCLK = SiS_Pr->CSRClock;
  2057. } else {
  2058. index = SiS_GetRefCRTVCLK(SiS_Pr, RefreshRateTableIndex, SiS_Pr->SiS_UseWide);
  2059. VCLK = SiS_Pr->SiS_VCLKData[index].CLOCK;
  2060. }
  2061. /* Get half colordepth */
  2062. colorth = colortharray[(SiS_Pr->SiS_ModeType - ModeEGA)];
  2063. /* Get MCLK */
  2064. index = SiS_GetReg(SiS_Pr->SiS_P3c4,0x3A) & 0x07;
  2065. MCLK = SiS_Pr->SiS_MCLKData_0[index].CLOCK;
  2066. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35) & 0xc3;
  2067. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x16,0x3c,temp);
  2068. do {
  2069. ThresholdLow = SiS_CalcDelay(SiS_Pr, VCLK, colorth, MCLK) + 1;
  2070. if(ThresholdLow < 0x13) break;
  2071. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x16,0xfc);
  2072. ThresholdLow = 0x13;
  2073. temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x16) >> 6;
  2074. if(!temp) break;
  2075. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x16,0x3f,((temp - 1) << 6));
  2076. } while(0);
  2077. } else ThresholdLow = 2;
  2078. /* Write CRT/CPU threshold low, CRT/Engine threshold high */
  2079. temp = (ThresholdLow << 4) | 0x0f;
  2080. SiS_SetReg(SiS_Pr->SiS_P3c4,0x08,temp);
  2081. temp = (ThresholdLow & 0x10) << 1;
  2082. if(ModeNo > 0x13) temp |= 0x40;
  2083. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0f,0x9f,temp);
  2084. /* What is this? */
  2085. SiS_SetReg(SiS_Pr->SiS_P3c4,0x3B,0x09);
  2086. /* Write CRT/CPU threshold high */
  2087. temp = ThresholdLow + 3;
  2088. if(temp > 0x0f) temp = 0x0f;
  2089. SiS_SetReg(SiS_Pr->SiS_P3c4,0x09,temp);
  2090. }
  2091. unsigned short
  2092. SiS_GetLatencyFactor630(struct SiS_Private *SiS_Pr, unsigned short index)
  2093. {
  2094. static const unsigned char LatencyFactor[] = {
  2095. 97, 88, 86, 79, 77, 0, /* 64 bit BQ=2 */
  2096. 0, 87, 85, 78, 76, 54, /* 64 bit BQ=1 */
  2097. 97, 88, 86, 79, 77, 0, /* 128 bit BQ=2 */
  2098. 0, 79, 77, 70, 68, 48, /* 128 bit BQ=1 */
  2099. 80, 72, 69, 63, 61, 0, /* 64 bit BQ=2 */
  2100. 0, 70, 68, 61, 59, 37, /* 64 bit BQ=1 */
  2101. 86, 77, 75, 68, 66, 0, /* 128 bit BQ=2 */
  2102. 0, 68, 66, 59, 57, 37 /* 128 bit BQ=1 */
  2103. };
  2104. static const unsigned char LatencyFactor730[] = {
  2105. 69, 63, 61,
  2106. 86, 79, 77,
  2107. 103, 96, 94,
  2108. 120,113,111,
  2109. 137,130,128
  2110. };
  2111. if(SiS_Pr->ChipType == SIS_730) {
  2112. return (unsigned short)LatencyFactor730[index];
  2113. } else {
  2114. return (unsigned short)LatencyFactor[index];
  2115. }
  2116. }
  2117. static unsigned short
  2118. SiS_CalcDelay2(struct SiS_Private *SiS_Pr, unsigned char key)
  2119. {
  2120. unsigned short index;
  2121. if(SiS_Pr->ChipType == SIS_730) {
  2122. index = ((key & 0x0f) * 3) + ((key & 0xc0) >> 6);
  2123. } else {
  2124. index = (key & 0xe0) >> 5;
  2125. if(key & 0x10) index += 6;
  2126. if(!(key & 0x01)) index += 24;
  2127. if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x14) & 0x80) index += 12;
  2128. }
  2129. return SiS_GetLatencyFactor630(SiS_Pr, index);
  2130. }
  2131. static void
  2132. SiS_SetCRT1FIFO_630(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
  2133. unsigned short RefreshRateTableIndex)
  2134. {
  2135. unsigned short ThresholdLow = 0;
  2136. unsigned short i, data, VCLK, MCLK16, colorth = 0;
  2137. unsigned int templ, datal;
  2138. const unsigned char *queuedata = NULL;
  2139. static const unsigned char FQBQData[21] = {
  2140. 0x01,0x21,0x41,0x61,0x81,
  2141. 0x31,0x51,0x71,0x91,0xb1,
  2142. 0x00,0x20,0x40,0x60,0x80,
  2143. 0x30,0x50,0x70,0x90,0xb0,
  2144. 0xff
  2145. };
  2146. static const unsigned char FQBQData730[16] = {
  2147. 0x34,0x74,0xb4,
  2148. 0x23,0x63,0xa3,
  2149. 0x12,0x52,0x92,
  2150. 0x01,0x41,0x81,
  2151. 0x00,0x40,0x80,
  2152. 0xff
  2153. };
  2154. static const unsigned short colortharray[6] = {
  2155. 1, 1, 2, 2, 3, 4
  2156. };
  2157. i = 0;
  2158. if(ModeNo > 0x13) {
  2159. /* Get VCLK */
  2160. if(SiS_Pr->UseCustomMode) {
  2161. VCLK = SiS_Pr->CSRClock;
  2162. } else {
  2163. data = SiS_GetRefCRTVCLK(SiS_Pr, RefreshRateTableIndex, SiS_Pr->SiS_UseWide);
  2164. VCLK = SiS_Pr->SiS_VCLKData[data].CLOCK;
  2165. }
  2166. /* Get MCLK * 16 */
  2167. data = SiS_GetReg(SiS_Pr->SiS_P3c4,0x1A) & 0x07;
  2168. MCLK16 = SiS_Pr->SiS_MCLKData_0[data].CLOCK * 16;
  2169. /* Get half colordepth */
  2170. colorth = colortharray[(SiS_Pr->SiS_ModeType - ModeEGA)];
  2171. if(SiS_Pr->ChipType == SIS_730) {
  2172. queuedata = &FQBQData730[0];
  2173. } else {
  2174. queuedata = &FQBQData[0];
  2175. }
  2176. do {
  2177. templ = SiS_CalcDelay2(SiS_Pr, queuedata[i]) * VCLK * colorth;
  2178. datal = templ % MCLK16;
  2179. templ = (templ / MCLK16) + 1;
  2180. if(datal) templ++;
  2181. if(templ > 0x13) {
  2182. if(queuedata[i + 1] == 0xFF) {
  2183. ThresholdLow = 0x13;
  2184. break;
  2185. }
  2186. i++;
  2187. } else {
  2188. ThresholdLow = templ;
  2189. break;
  2190. }
  2191. } while(queuedata[i] != 0xFF);
  2192. } else {
  2193. if(SiS_Pr->ChipType != SIS_730) i = 9;
  2194. ThresholdLow = 0x02;
  2195. }
  2196. /* Write CRT/CPU threshold low, CRT/Engine threshold high */
  2197. data = ((ThresholdLow & 0x0f) << 4) | 0x0f;
  2198. SiS_SetReg(SiS_Pr->SiS_P3c4,0x08,data);
  2199. data = (ThresholdLow & 0x10) << 1;
  2200. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0F,0xDF,data);
  2201. /* What is this? */
  2202. SiS_SetReg(SiS_Pr->SiS_P3c4,0x3B,0x09);
  2203. /* Write CRT/CPU threshold high (gap = 3) */
  2204. data = ThresholdLow + 3;
  2205. if(data > 0x0f) data = 0x0f;
  2206. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x09,0x80,data);
  2207. /* Write foreground and background queue */
  2208. templ = sisfb_read_nbridge_pci_dword(SiS_Pr, 0x50);
  2209. if(SiS_Pr->ChipType == SIS_730) {
  2210. templ &= 0xfffff9ff;
  2211. templ |= ((queuedata[i] & 0xc0) << 3);
  2212. } else {
  2213. templ &= 0xf0ffffff;
  2214. if( (ModeNo <= 0x13) &&
  2215. (SiS_Pr->ChipType == SIS_630) &&
  2216. (SiS_Pr->ChipRevision >= 0x30) ) {
  2217. templ |= 0x0b000000;
  2218. } else {
  2219. templ |= ((queuedata[i] & 0xf0) << 20);
  2220. }
  2221. }
  2222. sisfb_write_nbridge_pci_dword(SiS_Pr, 0x50, templ);
  2223. templ = sisfb_read_nbridge_pci_dword(SiS_Pr, 0xA0);
  2224. /* GUI grant timer (PCI config 0xA3) */
  2225. if(SiS_Pr->ChipType == SIS_730) {
  2226. templ &= 0x00ffffff;
  2227. datal = queuedata[i] << 8;
  2228. templ |= (((datal & 0x0f00) | ((datal & 0x3000) >> 8)) << 20);
  2229. } else {
  2230. templ &= 0xf0ffffff;
  2231. templ |= ((queuedata[i] & 0x0f) << 24);
  2232. }
  2233. sisfb_write_nbridge_pci_dword(SiS_Pr, 0xA0, templ);
  2234. }
  2235. #endif /* CONFIG_FB_SIS_300 */
  2236. #ifdef CONFIG_FB_SIS_315
  2237. static void
  2238. SiS_SetCRT1FIFO_310(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  2239. {
  2240. unsigned short modeflag;
  2241. /* disable auto-threshold */
  2242. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x3D,0xFE);
  2243. modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
  2244. SiS_SetReg(SiS_Pr->SiS_P3c4,0x08,0xAE);
  2245. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x09,0xF0);
  2246. if(ModeNo > 0x13) {
  2247. if(SiS_Pr->ChipType >= XGI_20) {
  2248. SiS_SetReg(SiS_Pr->SiS_P3c4,0x08,0x34);
  2249. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x3D,0x01);
  2250. } else if(SiS_Pr->ChipType >= SIS_661) {
  2251. if(!(modeflag & HalfDCLK)) {
  2252. SiS_SetReg(SiS_Pr->SiS_P3c4,0x08,0x34);
  2253. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x3D,0x01);
  2254. }
  2255. } else {
  2256. if((!(modeflag & DoubleScanMode)) || (!(modeflag & HalfDCLK))) {
  2257. SiS_SetReg(SiS_Pr->SiS_P3c4,0x08,0x34);
  2258. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x3D,0x01);
  2259. }
  2260. }
  2261. }
  2262. }
  2263. #endif
  2264. /*********************************************/
  2265. /* MODE REGISTERS */
  2266. /*********************************************/
  2267. static void
  2268. SiS_SetVCLKState(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
  2269. unsigned short RefreshRateTableIndex, unsigned short ModeIdIndex)
  2270. {
  2271. unsigned short data = 0, VCLK = 0, index = 0;
  2272. if(ModeNo > 0x13) {
  2273. if(SiS_Pr->UseCustomMode) {
  2274. VCLK = SiS_Pr->CSRClock;
  2275. } else {
  2276. index = SiS_GetVCLK2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  2277. VCLK = SiS_Pr->SiS_VCLKData[index].CLOCK;
  2278. }
  2279. }
  2280. if(SiS_Pr->ChipType < SIS_315H) {
  2281. #ifdef CONFIG_FB_SIS_300
  2282. if(VCLK > 150) data |= 0x80;
  2283. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x07,0x7B,data);
  2284. data = 0x00;
  2285. if(VCLK >= 150) data |= 0x08;
  2286. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x32,0xF7,data);
  2287. #endif
  2288. } else if(SiS_Pr->ChipType < XGI_20) {
  2289. #ifdef CONFIG_FB_SIS_315
  2290. if(VCLK >= 166) data |= 0x0c;
  2291. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x32,0xf3,data);
  2292. if(VCLK >= 166) {
  2293. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1f,0xe7);
  2294. }
  2295. #endif
  2296. } else {
  2297. #ifdef CONFIG_FB_SIS_315
  2298. if(VCLK >= 200) data |= 0x0c;
  2299. if(SiS_Pr->ChipType == XGI_20) data &= ~0x04;
  2300. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x32,0xf3,data);
  2301. if(SiS_Pr->ChipType != XGI_20) {
  2302. data = SiS_GetReg(SiS_Pr->SiS_P3c4,0x1f) & 0xe7;
  2303. if(VCLK < 200) data |= 0x10;
  2304. SiS_SetReg(SiS_Pr->SiS_P3c4,0x1f,data);
  2305. }
  2306. #endif
  2307. }
  2308. /* DAC speed */
  2309. if(SiS_Pr->ChipType >= SIS_661) {
  2310. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x07,0xE8,0x10);
  2311. } else {
  2312. data = 0x03;
  2313. if(VCLK >= 260) data = 0x00;
  2314. else if(VCLK >= 160) data = 0x01;
  2315. else if(VCLK >= 135) data = 0x02;
  2316. if(SiS_Pr->ChipType == SIS_540) {
  2317. /* Was == 203 or < 234 which made no sense */
  2318. if (VCLK < 234) data = 0x02;
  2319. }
  2320. if(SiS_Pr->ChipType < SIS_315H) {
  2321. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x07,0xFC,data);
  2322. } else {
  2323. if(SiS_Pr->ChipType > SIS_315PRO) {
  2324. if(ModeNo > 0x13) data &= 0xfc;
  2325. }
  2326. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x07,0xF8,data);
  2327. }
  2328. }
  2329. }
  2330. static void
  2331. SiS_SetCRT1ModeRegs(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
  2332. unsigned short ModeIdIndex, unsigned short RRTI)
  2333. {
  2334. unsigned short data, infoflag = 0, modeflag, resindex;
  2335. #ifdef CONFIG_FB_SIS_315
  2336. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  2337. unsigned short data2, data3;
  2338. #endif
  2339. modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
  2340. if(SiS_Pr->UseCustomMode) {
  2341. infoflag = SiS_Pr->CInfoFlag;
  2342. } else {
  2343. resindex = SiS_GetResInfo(SiS_Pr, ModeNo, ModeIdIndex);
  2344. if(ModeNo > 0x13) {
  2345. infoflag = SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag;
  2346. }
  2347. }
  2348. /* Disable DPMS */
  2349. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1F,0x3F);
  2350. data = 0;
  2351. if(ModeNo > 0x13) {
  2352. if(SiS_Pr->SiS_ModeType > ModeEGA) {
  2353. data |= 0x02;
  2354. data |= ((SiS_Pr->SiS_ModeType - ModeVGA) << 2);
  2355. }
  2356. if(infoflag & InterlaceMode) data |= 0x20;
  2357. }
  2358. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x06,0xC0,data);
  2359. if(SiS_Pr->ChipType != SIS_300) {
  2360. data = 0;
  2361. if(infoflag & InterlaceMode) {
  2362. /* data = (Hsync / 8) - ((Htotal / 8) / 2) + 3 */
  2363. int hrs = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x04) |
  2364. ((SiS_GetReg(SiS_Pr->SiS_P3c4,0x0b) & 0xc0) << 2)) - 3;
  2365. int hto = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x00) |
  2366. ((SiS_GetReg(SiS_Pr->SiS_P3c4,0x0b) & 0x03) << 8)) + 5;
  2367. data = hrs - (hto >> 1) + 3;
  2368. }
  2369. SiS_SetReg(SiS_Pr->SiS_P3d4,0x19,data);
  2370. SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x1a,0xFC,((data >> 8) & 0x03));
  2371. }
  2372. if(modeflag & HalfDCLK) {
  2373. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x01,0x08);
  2374. }
  2375. data = 0;
  2376. if(modeflag & LineCompareOff) data = 0x08;
  2377. if(SiS_Pr->ChipType == SIS_300) {
  2378. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0F,0xF7,data);
  2379. } else {
  2380. if(SiS_Pr->ChipType >= XGI_20) data |= 0x20;
  2381. if(SiS_Pr->SiS_ModeType == ModeEGA) {
  2382. if(ModeNo > 0x13) {
  2383. data |= 0x40;
  2384. }
  2385. }
  2386. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0F,0xB7,data);
  2387. }
  2388. #ifdef CONFIG_FB_SIS_315
  2389. if(SiS_Pr->ChipType >= SIS_315H) {
  2390. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x31,0xfb);
  2391. }
  2392. if(SiS_Pr->ChipType == SIS_315PRO) {
  2393. data = SiS_Pr->SiS_SR15[(2 * 4) + SiS_Get310DRAMType(SiS_Pr)];
  2394. if(SiS_Pr->SiS_ModeType == ModeText) {
  2395. data &= 0xc7;
  2396. } else {
  2397. data2 = SiS_GetOffset(SiS_Pr, ModeNo, ModeIdIndex, RRTI) >> 1;
  2398. if(infoflag & InterlaceMode) data2 >>= 1;
  2399. data3 = SiS_GetColorDepth(SiS_Pr, ModeNo, ModeIdIndex) >> 1;
  2400. if(data3) data2 /= data3;
  2401. if(data2 >= 0x50) {
  2402. data &= 0x0f;
  2403. data |= 0x50;
  2404. }
  2405. }
  2406. SiS_SetReg(SiS_Pr->SiS_P3c4,0x17,data);
  2407. } else if((SiS_Pr->ChipType == SIS_330) || (SiS_Pr->SiS_SysFlags & SF_760LFB)) {
  2408. data = SiS_Get310DRAMType(SiS_Pr);
  2409. if(SiS_Pr->ChipType == SIS_330) {
  2410. data = SiS_Pr->SiS_SR15[(2 * 4) + data];
  2411. } else {
  2412. if(SiS_Pr->SiS_ROMNew) data = ROMAddr[0xf6];
  2413. else if(SiS_Pr->SiS_UseROM) data = ROMAddr[0x100 + data];
  2414. else data = 0xba;
  2415. }
  2416. if(SiS_Pr->SiS_ModeType <= ModeEGA) {
  2417. data &= 0xc7;
  2418. } else {
  2419. if(SiS_Pr->UseCustomMode) {
  2420. data2 = SiS_Pr->CSRClock;
  2421. } else {
  2422. data2 = SiS_GetVCLK2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RRTI);
  2423. data2 = SiS_Pr->SiS_VCLKData[data2].CLOCK;
  2424. }
  2425. data3 = SiS_GetColorDepth(SiS_Pr, ModeNo, ModeIdIndex) >> 1;
  2426. if(data3) data2 *= data3;
  2427. data2 = ((unsigned int)(SiS_GetMCLK(SiS_Pr) * 1024)) / data2;
  2428. if(SiS_Pr->ChipType == SIS_330) {
  2429. if(SiS_Pr->SiS_ModeType != Mode16Bpp) {
  2430. if (data2 >= 0x19c) data = 0xba;
  2431. else if(data2 >= 0x140) data = 0x7a;
  2432. else if(data2 >= 0x101) data = 0x3a;
  2433. else if(data2 >= 0xf5) data = 0x32;
  2434. else if(data2 >= 0xe2) data = 0x2a;
  2435. else if(data2 >= 0xc4) data = 0x22;
  2436. else if(data2 >= 0xac) data = 0x1a;
  2437. else if(data2 >= 0x9e) data = 0x12;
  2438. else if(data2 >= 0x8e) data = 0x0a;
  2439. else data = 0x02;
  2440. } else {
  2441. if(data2 >= 0x127) data = 0xba;
  2442. else data = 0x7a;
  2443. }
  2444. } else { /* 76x+LFB */
  2445. if (data2 >= 0x190) data = 0xba;
  2446. else if(data2 >= 0xff) data = 0x7a;
  2447. else if(data2 >= 0xd3) data = 0x3a;
  2448. else if(data2 >= 0xa9) data = 0x1a;
  2449. else if(data2 >= 0x93) data = 0x0a;
  2450. else data = 0x02;
  2451. }
  2452. }
  2453. SiS_SetReg(SiS_Pr->SiS_P3c4,0x17,data);
  2454. }
  2455. /* XGI: Nothing. */
  2456. /* TODO: Check SiS340 */
  2457. #endif
  2458. data = 0x60;
  2459. if(SiS_Pr->SiS_ModeType != ModeText) {
  2460. data ^= 0x60;
  2461. if(SiS_Pr->SiS_ModeType != ModeEGA) {
  2462. data ^= 0xA0;
  2463. }
  2464. }
  2465. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x21,0x1F,data);
  2466. SiS_SetVCLKState(SiS_Pr, ModeNo, RRTI, ModeIdIndex);
  2467. #ifdef CONFIG_FB_SIS_315
  2468. if(((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->ChipType < SIS_661)) ||
  2469. (SiS_Pr->ChipType == XGI_40)) {
  2470. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & 0x40) {
  2471. SiS_SetReg(SiS_Pr->SiS_P3d4,0x52,0x2c);
  2472. } else {
  2473. SiS_SetReg(SiS_Pr->SiS_P3d4,0x52,0x6c);
  2474. }
  2475. } else if(SiS_Pr->ChipType == XGI_20) {
  2476. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & 0x40) {
  2477. SiS_SetReg(SiS_Pr->SiS_P3d4,0x52,0x33);
  2478. } else {
  2479. SiS_SetReg(SiS_Pr->SiS_P3d4,0x52,0x73);
  2480. }
  2481. SiS_SetReg(SiS_Pr->SiS_P3d4,0x51,0x02);
  2482. }
  2483. #endif
  2484. }
  2485. #ifdef CONFIG_FB_SIS_315
  2486. static void
  2487. SiS_SetupDualChip(struct SiS_Private *SiS_Pr)
  2488. {
  2489. #if 0
  2490. /* TODO: Find out about IOAddress2 */
  2491. SISIOADDRESS P2_3c2 = SiS_Pr->IOAddress2 + 0x12;
  2492. SISIOADDRESS P2_3c4 = SiS_Pr->IOAddress2 + 0x14;
  2493. SISIOADDRESS P2_3ce = SiS_Pr->IOAddress2 + 0x1e;
  2494. int i;
  2495. if((SiS_Pr->ChipRevision != 0) ||
  2496. (!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x3a) & 0x04)))
  2497. return;
  2498. for(i = 0; i <= 4; i++) { /* SR00 - SR04 */
  2499. SiS_SetReg(P2_3c4,i,SiS_GetReg(SiS_Pr->SiS_P3c4,i));
  2500. }
  2501. for(i = 0; i <= 8; i++) { /* GR00 - GR08 */
  2502. SiS_SetReg(P2_3ce,i,SiS_GetReg(SiS_Pr->SiS_P3ce,i));
  2503. }
  2504. SiS_SetReg(P2_3c4,0x05,0x86);
  2505. SiS_SetReg(P2_3c4,0x06,SiS_GetReg(SiS_Pr->SiS_P3c4,0x06)); /* SR06 */
  2506. SiS_SetReg(P2_3c4,0x21,SiS_GetReg(SiS_Pr->SiS_P3c4,0x21)); /* SR21 */
  2507. SiS_SetRegByte(P2_3c2,SiS_GetRegByte(SiS_Pr->SiS_P3cc)); /* MISC */
  2508. SiS_SetReg(P2_3c4,0x05,0x00);
  2509. #endif
  2510. }
  2511. #endif
  2512. /*********************************************/
  2513. /* LOAD DAC */
  2514. /*********************************************/
  2515. static void
  2516. SiS_WriteDAC(struct SiS_Private *SiS_Pr, SISIOADDRESS DACData, unsigned short shiftflag,
  2517. unsigned short dl, unsigned short ah, unsigned short al, unsigned short dh)
  2518. {
  2519. unsigned short d1, d2, d3;
  2520. switch(dl) {
  2521. case 0: d1 = dh; d2 = ah; d3 = al; break;
  2522. case 1: d1 = ah; d2 = al; d3 = dh; break;
  2523. default: d1 = al; d2 = dh; d3 = ah;
  2524. }
  2525. SiS_SetRegByte(DACData, (d1 << shiftflag));
  2526. SiS_SetRegByte(DACData, (d2 << shiftflag));
  2527. SiS_SetRegByte(DACData, (d3 << shiftflag));
  2528. }
  2529. void
  2530. SiS_LoadDAC(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  2531. {
  2532. unsigned short data, data2, time, i, j, k, m, n, o;
  2533. unsigned short si, di, bx, sf;
  2534. SISIOADDRESS DACAddr, DACData;
  2535. const unsigned char *table = NULL;
  2536. data = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex) & DACInfoFlag;
  2537. j = time = 64;
  2538. if(data == 0x00) table = SiS_MDA_DAC;
  2539. else if(data == 0x08) table = SiS_CGA_DAC;
  2540. else if(data == 0x10) table = SiS_EGA_DAC;
  2541. else if(data == 0x18) {
  2542. j = 16;
  2543. time = 256;
  2544. table = SiS_VGA_DAC;
  2545. }
  2546. if( ( (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && /* 301B-DH LCD */
  2547. (SiS_Pr->SiS_VBType & VB_NoLCD) ) ||
  2548. (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) || /* LCDA */
  2549. (!(SiS_Pr->SiS_SetFlag & ProgrammingCRT2)) ) { /* Programming CRT1 */
  2550. SiS_SetRegByte(SiS_Pr->SiS_P3c6,0xFF);
  2551. DACAddr = SiS_Pr->SiS_P3c8;
  2552. DACData = SiS_Pr->SiS_P3c9;
  2553. sf = 0;
  2554. } else {
  2555. DACAddr = SiS_Pr->SiS_Part5Port;
  2556. DACData = SiS_Pr->SiS_Part5Port + 1;
  2557. sf = 2;
  2558. }
  2559. SiS_SetRegByte(DACAddr,0x00);
  2560. for(i = 0; i < j; i++) {
  2561. data = table[i];
  2562. for(k = 0; k < 3; k++) {
  2563. data2 = 0;
  2564. if(data & 0x01) data2 += 0x2A;
  2565. if(data & 0x02) data2 += 0x15;
  2566. SiS_SetRegByte(DACData, (data2 << sf));
  2567. data >>= 2;
  2568. }
  2569. }
  2570. if(time == 256) {
  2571. for(i = 16; i < 32; i++) {
  2572. data = table[i] << sf;
  2573. for(k = 0; k < 3; k++) SiS_SetRegByte(DACData, data);
  2574. }
  2575. si = 32;
  2576. for(m = 0; m < 9; m++) {
  2577. di = si;
  2578. bx = si + 4;
  2579. for(n = 0; n < 3; n++) {
  2580. for(o = 0; o < 5; o++) {
  2581. SiS_WriteDAC(SiS_Pr, DACData, sf, n, table[di], table[bx], table[si]);
  2582. si++;
  2583. }
  2584. si -= 2;
  2585. for(o = 0; o < 3; o++) {
  2586. SiS_WriteDAC(SiS_Pr, DACData, sf, n, table[di], table[si], table[bx]);
  2587. si--;
  2588. }
  2589. } /* for n < 3 */
  2590. si += 5;
  2591. } /* for m < 9 */
  2592. }
  2593. }
  2594. /*********************************************/
  2595. /* SET CRT1 REGISTER GROUP */
  2596. /*********************************************/
  2597. static void
  2598. SiS_SetCRT1Group(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  2599. {
  2600. unsigned short StandTableIndex, RefreshRateTableIndex;
  2601. SiS_Pr->SiS_CRT1Mode = ModeNo;
  2602. StandTableIndex = SiS_GetModePtr(SiS_Pr, ModeNo, ModeIdIndex);
  2603. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  2604. if(SiS_Pr->SiS_VBInfo & (SetSimuScanMode | SwitchCRT2)) {
  2605. SiS_DisableBridge(SiS_Pr);
  2606. }
  2607. }
  2608. SiS_ResetSegmentRegisters(SiS_Pr);
  2609. SiS_SetSeqRegs(SiS_Pr, StandTableIndex);
  2610. SiS_SetMiscRegs(SiS_Pr, StandTableIndex);
  2611. SiS_SetCRTCRegs(SiS_Pr, StandTableIndex);
  2612. SiS_SetATTRegs(SiS_Pr, StandTableIndex);
  2613. SiS_SetGRCRegs(SiS_Pr, StandTableIndex);
  2614. SiS_ClearExt1Regs(SiS_Pr, ModeNo);
  2615. SiS_ResetCRT1VCLK(SiS_Pr);
  2616. SiS_Pr->SiS_SelectCRT2Rate = 0;
  2617. SiS_Pr->SiS_SetFlag &= (~ProgrammingCRT2);
  2618. if(SiS_Pr->SiS_VBInfo & SetSimuScanMode) {
  2619. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  2620. SiS_Pr->SiS_SetFlag |= ProgrammingCRT2;
  2621. }
  2622. }
  2623. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  2624. SiS_Pr->SiS_SetFlag |= ProgrammingCRT2;
  2625. }
  2626. RefreshRateTableIndex = SiS_GetRatePtr(SiS_Pr, ModeNo, ModeIdIndex);
  2627. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  2628. SiS_Pr->SiS_SetFlag &= ~ProgrammingCRT2;
  2629. }
  2630. if(RefreshRateTableIndex != 0xFFFF) {
  2631. SiS_SetCRT1Sync(SiS_Pr, RefreshRateTableIndex);
  2632. SiS_SetCRT1CRTC(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  2633. SiS_SetCRT1Offset(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  2634. SiS_SetCRT1VCLK(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  2635. }
  2636. switch(SiS_Pr->ChipType) {
  2637. #ifdef CONFIG_FB_SIS_300
  2638. case SIS_300:
  2639. SiS_SetCRT1FIFO_300(SiS_Pr, ModeNo, RefreshRateTableIndex);
  2640. break;
  2641. case SIS_540:
  2642. case SIS_630:
  2643. case SIS_730:
  2644. SiS_SetCRT1FIFO_630(SiS_Pr, ModeNo, RefreshRateTableIndex);
  2645. break;
  2646. #endif
  2647. default:
  2648. #ifdef CONFIG_FB_SIS_315
  2649. if(SiS_Pr->ChipType == XGI_20) {
  2650. unsigned char sr2b = 0, sr2c = 0;
  2651. switch(ModeNo) {
  2652. case 0x00:
  2653. case 0x01: sr2b = 0x4e; sr2c = 0xe9; break;
  2654. case 0x04:
  2655. case 0x05:
  2656. case 0x0d: sr2b = 0x1b; sr2c = 0xe3; break;
  2657. }
  2658. if(sr2b) {
  2659. SiS_SetReg(SiS_Pr->SiS_P3c4,0x2b,sr2b);
  2660. SiS_SetReg(SiS_Pr->SiS_P3c4,0x2c,sr2c);
  2661. SiS_SetRegByte(SiS_Pr->SiS_P3c2,(SiS_GetRegByte(SiS_Pr->SiS_P3cc) | 0x0c));
  2662. }
  2663. }
  2664. SiS_SetCRT1FIFO_310(SiS_Pr, ModeNo, ModeIdIndex);
  2665. #endif
  2666. break;
  2667. }
  2668. SiS_SetCRT1ModeRegs(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  2669. #ifdef CONFIG_FB_SIS_315
  2670. if(SiS_Pr->ChipType == XGI_40) {
  2671. SiS_SetupDualChip(SiS_Pr);
  2672. }
  2673. #endif
  2674. SiS_LoadDAC(SiS_Pr, ModeNo, ModeIdIndex);
  2675. if(SiS_Pr->SiS_flag_clearbuffer) {
  2676. SiS_ClearBuffer(SiS_Pr, ModeNo);
  2677. }
  2678. if(!(SiS_Pr->SiS_VBInfo & (SetSimuScanMode | SwitchCRT2 | SetCRT2ToLCDA))) {
  2679. SiS_WaitRetrace1(SiS_Pr);
  2680. SiS_DisplayOn(SiS_Pr);
  2681. }
  2682. }
  2683. /*********************************************/
  2684. /* HELPER: VIDEO BRIDGE PROG CLK */
  2685. /*********************************************/
  2686. static void
  2687. SiS_InitVB(struct SiS_Private *SiS_Pr)
  2688. {
  2689. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  2690. SiS_Pr->Init_P4_0E = 0;
  2691. if(SiS_Pr->SiS_ROMNew) {
  2692. SiS_Pr->Init_P4_0E = ROMAddr[0x82];
  2693. } else if(SiS_Pr->ChipType >= XGI_40) {
  2694. if(SiS_Pr->SiS_XGIROM) {
  2695. SiS_Pr->Init_P4_0E = ROMAddr[0x80];
  2696. }
  2697. }
  2698. }
  2699. static void
  2700. SiS_ResetVB(struct SiS_Private *SiS_Pr)
  2701. {
  2702. #ifdef CONFIG_FB_SIS_315
  2703. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  2704. unsigned short temp;
  2705. /* VB programming clock */
  2706. if(SiS_Pr->SiS_UseROM) {
  2707. if(SiS_Pr->ChipType < SIS_330) {
  2708. temp = ROMAddr[VB310Data_1_2_Offset] | 0x40;
  2709. if(SiS_Pr->SiS_ROMNew) temp = ROMAddr[0x80] | 0x40;
  2710. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x02,temp);
  2711. } else if(SiS_Pr->ChipType >= SIS_661 && SiS_Pr->ChipType < XGI_20) {
  2712. temp = ROMAddr[0x7e] | 0x40;
  2713. if(SiS_Pr->SiS_ROMNew) temp = ROMAddr[0x80] | 0x40;
  2714. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x02,temp);
  2715. }
  2716. } else if(SiS_Pr->ChipType >= XGI_40) {
  2717. temp = 0x40;
  2718. if(SiS_Pr->SiS_XGIROM) temp |= ROMAddr[0x7e];
  2719. /* Can we do this on any chipset? */
  2720. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x02,temp);
  2721. }
  2722. #endif
  2723. }
  2724. /*********************************************/
  2725. /* HELPER: SET VIDEO/CAPTURE REGISTERS */
  2726. /*********************************************/
  2727. static void
  2728. SiS_StrangeStuff(struct SiS_Private *SiS_Pr)
  2729. {
  2730. /* SiS65x and XGI set up some sort of "lock mode" for text
  2731. * which locks CRT2 in some way to CRT1 timing. Disable
  2732. * this here.
  2733. */
  2734. #ifdef CONFIG_FB_SIS_315
  2735. if((IS_SIS651) || (IS_SISM650) ||
  2736. SiS_Pr->ChipType == SIS_340 ||
  2737. SiS_Pr->ChipType == XGI_40) {
  2738. SiS_SetReg(SiS_Pr->SiS_VidCapt, 0x3f, 0x00); /* Fiddle with capture regs */
  2739. SiS_SetReg(SiS_Pr->SiS_VidCapt, 0x00, 0x00);
  2740. SiS_SetReg(SiS_Pr->SiS_VidPlay, 0x00, 0x86); /* (BIOS does NOT unlock) */
  2741. SiS_SetRegAND(SiS_Pr->SiS_VidPlay, 0x30, 0xfe); /* Fiddle with video regs */
  2742. SiS_SetRegAND(SiS_Pr->SiS_VidPlay, 0x3f, 0xef);
  2743. }
  2744. /* !!! This does not support modes < 0x13 !!! */
  2745. #endif
  2746. }
  2747. /*********************************************/
  2748. /* HELPER: SET AGP TIMING FOR SiS760 */
  2749. /*********************************************/
  2750. static void
  2751. SiS_Handle760(struct SiS_Private *SiS_Pr)
  2752. {
  2753. #ifdef CONFIG_FB_SIS_315
  2754. unsigned int somebase;
  2755. unsigned char temp1, temp2, temp3;
  2756. if( (SiS_Pr->ChipType != SIS_760) ||
  2757. ((SiS_GetReg(SiS_Pr->SiS_P3d4, 0x5c) & 0xf8) != 0x80) ||
  2758. (!(SiS_Pr->SiS_SysFlags & SF_760LFB)) ||
  2759. (!(SiS_Pr->SiS_SysFlags & SF_760UMA)) )
  2760. return;
  2761. somebase = sisfb_read_mio_pci_word(SiS_Pr, 0x74);
  2762. somebase &= 0xffff;
  2763. if(somebase == 0) return;
  2764. temp3 = SiS_GetRegByte((somebase + 0x85)) & 0xb7;
  2765. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & 0x40) {
  2766. temp1 = 0x21;
  2767. temp2 = 0x03;
  2768. temp3 |= 0x08;
  2769. } else {
  2770. temp1 = 0x25;
  2771. temp2 = 0x0b;
  2772. }
  2773. sisfb_write_nbridge_pci_byte(SiS_Pr, 0x7e, temp1);
  2774. sisfb_write_nbridge_pci_byte(SiS_Pr, 0x8d, temp2);
  2775. SiS_SetRegByte((somebase + 0x85), temp3);
  2776. #endif
  2777. }
  2778. /*********************************************/
  2779. /* SiSSetMode() */
  2780. /*********************************************/
  2781. bool
  2782. SiSSetMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
  2783. {
  2784. SISIOADDRESS BaseAddr = SiS_Pr->IOAddress;
  2785. unsigned short RealModeNo, ModeIdIndex;
  2786. unsigned char backupreg = 0;
  2787. unsigned short KeepLockReg;
  2788. SiS_Pr->UseCustomMode = false;
  2789. SiS_Pr->CRT1UsesCustomMode = false;
  2790. SiS_Pr->SiS_flag_clearbuffer = 0;
  2791. if(SiS_Pr->UseCustomMode) {
  2792. ModeNo = 0xfe;
  2793. } else {
  2794. if(!(ModeNo & 0x80)) SiS_Pr->SiS_flag_clearbuffer = 1;
  2795. ModeNo &= 0x7f;
  2796. }
  2797. /* Don't use FSTN mode for CRT1 */
  2798. RealModeNo = ModeNo;
  2799. if(ModeNo == 0x5b) ModeNo = 0x56;
  2800. SiSInitPtr(SiS_Pr);
  2801. SiSRegInit(SiS_Pr, BaseAddr);
  2802. SiS_GetSysFlags(SiS_Pr);
  2803. SiS_Pr->SiS_VGAINFO = 0x11;
  2804. KeepLockReg = SiS_GetReg(SiS_Pr->SiS_P3c4,0x05);
  2805. SiS_SetReg(SiS_Pr->SiS_P3c4,0x05,0x86);
  2806. SiSInitPCIetc(SiS_Pr);
  2807. SiSSetLVDSetc(SiS_Pr);
  2808. SiSDetermineROMUsage(SiS_Pr);
  2809. SiS_UnLockCRT2(SiS_Pr);
  2810. if(!SiS_Pr->UseCustomMode) {
  2811. if(!(SiS_SearchModeID(SiS_Pr, &ModeNo, &ModeIdIndex))) return false;
  2812. } else {
  2813. ModeIdIndex = 0;
  2814. }
  2815. SiS_GetVBType(SiS_Pr);
  2816. /* Init/restore some VB registers */
  2817. SiS_InitVB(SiS_Pr);
  2818. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  2819. if(SiS_Pr->ChipType >= SIS_315H) {
  2820. SiS_ResetVB(SiS_Pr);
  2821. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x32,0x10);
  2822. SiS_SetRegOR(SiS_Pr->SiS_Part2Port,0x00,0x0c);
  2823. backupreg = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  2824. } else {
  2825. backupreg = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35);
  2826. }
  2827. }
  2828. /* Get VB information (connectors, connected devices) */
  2829. SiS_GetVBInfo(SiS_Pr, ModeNo, ModeIdIndex, (SiS_Pr->UseCustomMode) ? 0 : 1);
  2830. SiS_SetYPbPr(SiS_Pr);
  2831. SiS_SetTVMode(SiS_Pr, ModeNo, ModeIdIndex);
  2832. SiS_GetLCDResInfo(SiS_Pr, ModeNo, ModeIdIndex);
  2833. SiS_SetLowModeTest(SiS_Pr, ModeNo);
  2834. /* Check memory size (kernel framebuffer driver only) */
  2835. if(!SiS_CheckMemorySize(SiS_Pr, ModeNo, ModeIdIndex)) {
  2836. return false;
  2837. }
  2838. SiS_OpenCRTC(SiS_Pr);
  2839. if(SiS_Pr->UseCustomMode) {
  2840. SiS_Pr->CRT1UsesCustomMode = true;
  2841. SiS_Pr->CSRClock_CRT1 = SiS_Pr->CSRClock;
  2842. SiS_Pr->CModeFlag_CRT1 = SiS_Pr->CModeFlag;
  2843. } else {
  2844. SiS_Pr->CRT1UsesCustomMode = false;
  2845. }
  2846. /* Set mode on CRT1 */
  2847. if( (SiS_Pr->SiS_VBInfo & (SetSimuScanMode | SetCRT2ToLCDA)) ||
  2848. (!(SiS_Pr->SiS_VBInfo & SwitchCRT2)) ) {
  2849. SiS_SetCRT1Group(SiS_Pr, ModeNo, ModeIdIndex);
  2850. }
  2851. /* Set mode on CRT2 */
  2852. if(SiS_Pr->SiS_VBInfo & (SetSimuScanMode | SwitchCRT2 | SetCRT2ToLCDA)) {
  2853. if( (SiS_Pr->SiS_VBType & VB_SISVB) ||
  2854. (SiS_Pr->SiS_IF_DEF_LVDS == 1) ||
  2855. (SiS_Pr->SiS_IF_DEF_CH70xx != 0) ||
  2856. (SiS_Pr->SiS_IF_DEF_TRUMPION != 0) ) {
  2857. SiS_SetCRT2Group(SiS_Pr, RealModeNo);
  2858. }
  2859. }
  2860. SiS_HandleCRT1(SiS_Pr);
  2861. SiS_StrangeStuff(SiS_Pr);
  2862. SiS_DisplayOn(SiS_Pr);
  2863. SiS_SetRegByte(SiS_Pr->SiS_P3c6,0xFF);
  2864. #ifdef CONFIG_FB_SIS_315
  2865. if(SiS_Pr->ChipType >= SIS_315H) {
  2866. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  2867. if(!(SiS_IsDualEdge(SiS_Pr))) {
  2868. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xfb);
  2869. }
  2870. }
  2871. }
  2872. #endif
  2873. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  2874. if(SiS_Pr->ChipType >= SIS_315H) {
  2875. #ifdef CONFIG_FB_SIS_315
  2876. if(!SiS_Pr->SiS_ROMNew) {
  2877. if(SiS_IsVAMode(SiS_Pr)) {
  2878. SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x35,0x01);
  2879. } else {
  2880. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x35,0xFE);
  2881. }
  2882. }
  2883. SiS_SetReg(SiS_Pr->SiS_P3d4,0x38,backupreg);
  2884. if((IS_SIS650) && (SiS_GetReg(SiS_Pr->SiS_P3d4,0x30) & 0xfc)) {
  2885. if((ModeNo == 0x03) || (ModeNo == 0x10)) {
  2886. SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x51,0x80);
  2887. SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x56,0x08);
  2888. }
  2889. }
  2890. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x30) & SetCRT2ToLCD) {
  2891. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x38,0xfc);
  2892. }
  2893. #endif
  2894. } else if((SiS_Pr->ChipType == SIS_630) ||
  2895. (SiS_Pr->ChipType == SIS_730)) {
  2896. SiS_SetReg(SiS_Pr->SiS_P3d4,0x35,backupreg);
  2897. }
  2898. }
  2899. SiS_CloseCRTC(SiS_Pr);
  2900. SiS_Handle760(SiS_Pr);
  2901. /* We never lock registers in XF86 */
  2902. if(KeepLockReg != 0xA1) SiS_SetReg(SiS_Pr->SiS_P3c4,0x05,0x00);
  2903. return true;
  2904. }
  2905. #ifndef GETBITSTR
  2906. #define GENBITSMASK(mask) GENMASK(1?mask,0?mask)
  2907. #define GETBITS(var,mask) (((var) & GENBITSMASK(mask)) >> (0?mask))
  2908. #define GETBITSTR(val,from,to) ((GETBITS(val,from)) << (0?to))
  2909. #endif
  2910. void
  2911. SiS_CalcCRRegisters(struct SiS_Private *SiS_Pr, int depth)
  2912. {
  2913. int x = 1; /* Fix sync */
  2914. SiS_Pr->CCRT1CRTC[0] = ((SiS_Pr->CHTotal >> 3) - 5) & 0xff; /* CR0 */
  2915. SiS_Pr->CCRT1CRTC[1] = (SiS_Pr->CHDisplay >> 3) - 1; /* CR1 */
  2916. SiS_Pr->CCRT1CRTC[2] = (SiS_Pr->CHBlankStart >> 3) - 1; /* CR2 */
  2917. SiS_Pr->CCRT1CRTC[3] = (((SiS_Pr->CHBlankEnd >> 3) - 1) & 0x1F) | 0x80; /* CR3 */
  2918. SiS_Pr->CCRT1CRTC[4] = (SiS_Pr->CHSyncStart >> 3) + 3; /* CR4 */
  2919. SiS_Pr->CCRT1CRTC[5] = ((((SiS_Pr->CHBlankEnd >> 3) - 1) & 0x20) << 2) | /* CR5 */
  2920. (((SiS_Pr->CHSyncEnd >> 3) + 3) & 0x1F);
  2921. SiS_Pr->CCRT1CRTC[6] = (SiS_Pr->CVTotal - 2) & 0xFF; /* CR6 */
  2922. SiS_Pr->CCRT1CRTC[7] = (((SiS_Pr->CVTotal - 2) & 0x100) >> 8) /* CR7 */
  2923. | (((SiS_Pr->CVDisplay - 1) & 0x100) >> 7)
  2924. | (((SiS_Pr->CVSyncStart - x) & 0x100) >> 6)
  2925. | (((SiS_Pr->CVBlankStart- 1) & 0x100) >> 5)
  2926. | 0x10
  2927. | (((SiS_Pr->CVTotal - 2) & 0x200) >> 4)
  2928. | (((SiS_Pr->CVDisplay - 1) & 0x200) >> 3)
  2929. | (((SiS_Pr->CVSyncStart - x) & 0x200) >> 2);
  2930. SiS_Pr->CCRT1CRTC[16] = ((((SiS_Pr->CVBlankStart - 1) & 0x200) >> 4) >> 5); /* CR9 */
  2931. if(depth != 8) {
  2932. if(SiS_Pr->CHDisplay >= 1600) SiS_Pr->CCRT1CRTC[16] |= 0x60; /* SRE */
  2933. else if(SiS_Pr->CHDisplay >= 640) SiS_Pr->CCRT1CRTC[16] |= 0x40;
  2934. }
  2935. SiS_Pr->CCRT1CRTC[8] = (SiS_Pr->CVSyncStart - x) & 0xFF; /* CR10 */
  2936. SiS_Pr->CCRT1CRTC[9] = ((SiS_Pr->CVSyncEnd - x) & 0x0F) | 0x80; /* CR11 */
  2937. SiS_Pr->CCRT1CRTC[10] = (SiS_Pr->CVDisplay - 1) & 0xFF; /* CR12 */
  2938. SiS_Pr->CCRT1CRTC[11] = (SiS_Pr->CVBlankStart - 1) & 0xFF; /* CR15 */
  2939. SiS_Pr->CCRT1CRTC[12] = (SiS_Pr->CVBlankEnd - 1) & 0xFF; /* CR16 */
  2940. SiS_Pr->CCRT1CRTC[13] = /* SRA */
  2941. GETBITSTR((SiS_Pr->CVTotal -2), 10:10, 0:0) |
  2942. GETBITSTR((SiS_Pr->CVDisplay -1), 10:10, 1:1) |
  2943. GETBITSTR((SiS_Pr->CVBlankStart-1), 10:10, 2:2) |
  2944. GETBITSTR((SiS_Pr->CVSyncStart -x), 10:10, 3:3) |
  2945. GETBITSTR((SiS_Pr->CVBlankEnd -1), 8:8, 4:4) |
  2946. GETBITSTR((SiS_Pr->CVSyncEnd ), 4:4, 5:5) ;
  2947. SiS_Pr->CCRT1CRTC[14] = /* SRB */
  2948. GETBITSTR((SiS_Pr->CHTotal >> 3) - 5, 9:8, 1:0) |
  2949. GETBITSTR((SiS_Pr->CHDisplay >> 3) - 1, 9:8, 3:2) |
  2950. GETBITSTR((SiS_Pr->CHBlankStart >> 3) - 1, 9:8, 5:4) |
  2951. GETBITSTR((SiS_Pr->CHSyncStart >> 3) + 3, 9:8, 7:6) ;
  2952. SiS_Pr->CCRT1CRTC[15] = /* SRC */
  2953. GETBITSTR((SiS_Pr->CHBlankEnd >> 3) - 1, 7:6, 1:0) |
  2954. GETBITSTR((SiS_Pr->CHSyncEnd >> 3) + 3, 5:5, 2:2) ;
  2955. }
  2956. void
  2957. SiS_CalcLCDACRT1Timing(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
  2958. unsigned short ModeIdIndex)
  2959. {
  2960. unsigned short modeflag, tempax, tempbx = 0, remaining = 0;
  2961. unsigned short VGAHDE = SiS_Pr->SiS_VGAHDE;
  2962. int i, j;
  2963. /* 1:1 data: use data set by setcrt1crtc() */
  2964. if(SiS_Pr->SiS_LCDInfo & LCDPass11) return;
  2965. modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
  2966. if(modeflag & HalfDCLK) VGAHDE >>= 1;
  2967. SiS_Pr->CHDisplay = VGAHDE;
  2968. SiS_Pr->CHBlankStart = VGAHDE;
  2969. SiS_Pr->CVDisplay = SiS_Pr->SiS_VGAVDE;
  2970. SiS_Pr->CVBlankStart = SiS_Pr->SiS_VGAVDE;
  2971. if(SiS_Pr->ChipType < SIS_315H) {
  2972. #ifdef CONFIG_FB_SIS_300
  2973. tempbx = SiS_Pr->SiS_VGAHT;
  2974. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  2975. tempbx = SiS_Pr->PanelHT;
  2976. }
  2977. if(modeflag & HalfDCLK) tempbx >>= 1;
  2978. remaining = tempbx % 8;
  2979. #endif
  2980. } else {
  2981. #ifdef CONFIG_FB_SIS_315
  2982. /* OK for LCDA, LVDS */
  2983. tempbx = SiS_Pr->PanelHT - SiS_Pr->PanelXRes;
  2984. tempax = SiS_Pr->SiS_VGAHDE; /* not /2 ! */
  2985. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  2986. tempax = SiS_Pr->PanelXRes;
  2987. }
  2988. tempbx += tempax;
  2989. if(modeflag & HalfDCLK) tempbx -= VGAHDE;
  2990. #endif
  2991. }
  2992. SiS_Pr->CHTotal = SiS_Pr->CHBlankEnd = tempbx;
  2993. if(SiS_Pr->ChipType < SIS_315H) {
  2994. #ifdef CONFIG_FB_SIS_300
  2995. if(SiS_Pr->SiS_VGAHDE == SiS_Pr->PanelXRes) {
  2996. SiS_Pr->CHSyncStart = SiS_Pr->SiS_VGAHDE + ((SiS_Pr->PanelHRS + 1) & ~1);
  2997. SiS_Pr->CHSyncEnd = SiS_Pr->CHSyncStart + SiS_Pr->PanelHRE;
  2998. if(modeflag & HalfDCLK) {
  2999. SiS_Pr->CHSyncStart >>= 1;
  3000. SiS_Pr->CHSyncEnd >>= 1;
  3001. }
  3002. } else if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  3003. tempax = (SiS_Pr->PanelXRes - SiS_Pr->SiS_VGAHDE) >> 1;
  3004. tempbx = (SiS_Pr->PanelHRS + 1) & ~1;
  3005. if(modeflag & HalfDCLK) {
  3006. tempax >>= 1;
  3007. tempbx >>= 1;
  3008. }
  3009. SiS_Pr->CHSyncStart = (VGAHDE + tempax + tempbx + 7) & ~7;
  3010. tempax = SiS_Pr->PanelHRE + 7;
  3011. if(modeflag & HalfDCLK) tempax >>= 1;
  3012. SiS_Pr->CHSyncEnd = (SiS_Pr->CHSyncStart + tempax) & ~7;
  3013. } else {
  3014. SiS_Pr->CHSyncStart = SiS_Pr->SiS_VGAHDE;
  3015. if(modeflag & HalfDCLK) {
  3016. SiS_Pr->CHSyncStart >>= 1;
  3017. tempax = ((SiS_Pr->CHTotal - SiS_Pr->CHSyncStart) / 3) << 1;
  3018. SiS_Pr->CHSyncEnd = SiS_Pr->CHSyncStart + tempax;
  3019. } else {
  3020. SiS_Pr->CHSyncEnd = (SiS_Pr->CHSyncStart + (SiS_Pr->CHTotal / 10) + 7) & ~7;
  3021. SiS_Pr->CHSyncStart += 8;
  3022. }
  3023. }
  3024. #endif
  3025. } else {
  3026. #ifdef CONFIG_FB_SIS_315
  3027. tempax = VGAHDE;
  3028. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  3029. tempbx = SiS_Pr->PanelXRes;
  3030. if(modeflag & HalfDCLK) tempbx >>= 1;
  3031. tempax += ((tempbx - tempax) >> 1);
  3032. }
  3033. tempax += SiS_Pr->PanelHRS;
  3034. SiS_Pr->CHSyncStart = tempax;
  3035. tempax += SiS_Pr->PanelHRE;
  3036. SiS_Pr->CHSyncEnd = tempax;
  3037. #endif
  3038. }
  3039. tempbx = SiS_Pr->PanelVT - SiS_Pr->PanelYRes;
  3040. tempax = SiS_Pr->SiS_VGAVDE;
  3041. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  3042. tempax = SiS_Pr->PanelYRes;
  3043. } else if(SiS_Pr->ChipType < SIS_315H) {
  3044. #ifdef CONFIG_FB_SIS_300
  3045. /* Stupid hack for 640x400/320x200 */
  3046. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  3047. if((tempax + tempbx) == 438) tempbx += 16;
  3048. } else if((SiS_Pr->SiS_LCDResInfo == Panel_800x600) ||
  3049. (SiS_Pr->SiS_LCDResInfo == Panel_1024x600)) {
  3050. tempax = 0;
  3051. tempbx = SiS_Pr->SiS_VGAVT;
  3052. }
  3053. #endif
  3054. }
  3055. SiS_Pr->CVTotal = SiS_Pr->CVBlankEnd = tempbx + tempax;
  3056. tempax = SiS_Pr->SiS_VGAVDE;
  3057. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  3058. tempax += (SiS_Pr->PanelYRes - tempax) >> 1;
  3059. }
  3060. tempax += SiS_Pr->PanelVRS;
  3061. SiS_Pr->CVSyncStart = tempax;
  3062. tempax += SiS_Pr->PanelVRE;
  3063. SiS_Pr->CVSyncEnd = tempax;
  3064. if(SiS_Pr->ChipType < SIS_315H) {
  3065. SiS_Pr->CVSyncStart--;
  3066. SiS_Pr->CVSyncEnd--;
  3067. }
  3068. SiS_CalcCRRegisters(SiS_Pr, 8);
  3069. SiS_Pr->CCRT1CRTC[15] &= ~0xF8;
  3070. SiS_Pr->CCRT1CRTC[15] |= (remaining << 4);
  3071. SiS_Pr->CCRT1CRTC[16] &= ~0xE0;
  3072. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x11,0x7f);
  3073. for(i = 0, j = 0; i <= 7; i++, j++) {
  3074. SiS_SetReg(SiS_Pr->SiS_P3d4,j,SiS_Pr->CCRT1CRTC[i]);
  3075. }
  3076. for(j = 0x10; i <= 10; i++, j++) {
  3077. SiS_SetReg(SiS_Pr->SiS_P3d4,j,SiS_Pr->CCRT1CRTC[i]);
  3078. }
  3079. for(j = 0x15; i <= 12; i++, j++) {
  3080. SiS_SetReg(SiS_Pr->SiS_P3d4,j,SiS_Pr->CCRT1CRTC[i]);
  3081. }
  3082. for(j = 0x0A; i <= 15; i++, j++) {
  3083. SiS_SetReg(SiS_Pr->SiS_P3c4,j,SiS_Pr->CCRT1CRTC[i]);
  3084. }
  3085. tempax = SiS_Pr->CCRT1CRTC[16] & 0xE0;
  3086. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0E,0x1F,tempax);
  3087. tempax = (SiS_Pr->CCRT1CRTC[16] & 0x01) << 5;
  3088. if(modeflag & DoubleScanMode) tempax |= 0x80;
  3089. SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x09,0x5F,tempax);
  3090. }
  3091. void
  3092. SiS_Generic_ConvertCRData(struct SiS_Private *SiS_Pr, unsigned char *crdata,
  3093. int xres, int yres,
  3094. struct fb_var_screeninfo *var, bool writeres
  3095. )
  3096. {
  3097. unsigned short HRE, HBE, HRS, HBS, HDE, HT;
  3098. unsigned short VRE, VBE, VRS, VBS, VDE, VT;
  3099. unsigned char sr_data, cr_data, cr_data2;
  3100. int A, B, C, D, E, F, temp;
  3101. sr_data = crdata[14];
  3102. /* Horizontal total */
  3103. HT = crdata[0] | ((unsigned short)(sr_data & 0x03) << 8);
  3104. A = HT + 5;
  3105. /* Horizontal display enable end */
  3106. HDE = crdata[1] | ((unsigned short)(sr_data & 0x0C) << 6);
  3107. E = HDE + 1;
  3108. /* Horizontal retrace (=sync) start */
  3109. HRS = crdata[4] | ((unsigned short)(sr_data & 0xC0) << 2);
  3110. F = HRS - E - 3;
  3111. /* Horizontal blank start */
  3112. HBS = crdata[2] | ((unsigned short)(sr_data & 0x30) << 4);
  3113. sr_data = crdata[15];
  3114. cr_data = crdata[5];
  3115. /* Horizontal blank end */
  3116. HBE = (crdata[3] & 0x1f) |
  3117. ((unsigned short)(cr_data & 0x80) >> 2) |
  3118. ((unsigned short)(sr_data & 0x03) << 6);
  3119. /* Horizontal retrace (=sync) end */
  3120. HRE = (cr_data & 0x1f) | ((sr_data & 0x04) << 3);
  3121. temp = HBE - ((E - 1) & 255);
  3122. B = (temp > 0) ? temp : (temp + 256);
  3123. temp = HRE - ((E + F + 3) & 63);
  3124. C = (temp > 0) ? temp : (temp + 64);
  3125. D = B - F - C;
  3126. if(writeres) var->xres = xres = E * 8;
  3127. var->left_margin = D * 8;
  3128. var->right_margin = F * 8;
  3129. var->hsync_len = C * 8;
  3130. /* Vertical */
  3131. sr_data = crdata[13];
  3132. cr_data = crdata[7];
  3133. /* Vertical total */
  3134. VT = crdata[6] |
  3135. ((unsigned short)(cr_data & 0x01) << 8) |
  3136. ((unsigned short)(cr_data & 0x20) << 4) |
  3137. ((unsigned short)(sr_data & 0x01) << 10);
  3138. A = VT + 2;
  3139. /* Vertical display enable end */
  3140. VDE = crdata[10] |
  3141. ((unsigned short)(cr_data & 0x02) << 7) |
  3142. ((unsigned short)(cr_data & 0x40) << 3) |
  3143. ((unsigned short)(sr_data & 0x02) << 9);
  3144. E = VDE + 1;
  3145. /* Vertical retrace (=sync) start */
  3146. VRS = crdata[8] |
  3147. ((unsigned short)(cr_data & 0x04) << 6) |
  3148. ((unsigned short)(cr_data & 0x80) << 2) |
  3149. ((unsigned short)(sr_data & 0x08) << 7);
  3150. F = VRS + 1 - E;
  3151. cr_data2 = (crdata[16] & 0x01) << 5;
  3152. /* Vertical blank start */
  3153. VBS = crdata[11] |
  3154. ((unsigned short)(cr_data & 0x08) << 5) |
  3155. ((unsigned short)(cr_data2 & 0x20) << 4) |
  3156. ((unsigned short)(sr_data & 0x04) << 8);
  3157. /* Vertical blank end */
  3158. VBE = crdata[12] | ((unsigned short)(sr_data & 0x10) << 4);
  3159. temp = VBE - ((E - 1) & 511);
  3160. B = (temp > 0) ? temp : (temp + 512);
  3161. /* Vertical retrace (=sync) end */
  3162. VRE = (crdata[9] & 0x0f) | ((sr_data & 0x20) >> 1);
  3163. temp = VRE - ((E + F - 1) & 31);
  3164. C = (temp > 0) ? temp : (temp + 32);
  3165. D = B - F - C;
  3166. if(writeres) var->yres = yres = E;
  3167. var->upper_margin = D;
  3168. var->lower_margin = F;
  3169. var->vsync_len = C;
  3170. if((xres == 320) && ((yres == 200) || (yres == 240))) {
  3171. /* Terrible hack, but correct CRTC data for
  3172. * these modes only produces a black screen...
  3173. * (HRE is 0, leading into a too large C and
  3174. * a negative D. The CRT controller does not
  3175. * seem to like correcting HRE to 50)
  3176. */
  3177. var->left_margin = (400 - 376);
  3178. var->right_margin = (328 - 320);
  3179. var->hsync_len = (376 - 328);
  3180. }
  3181. }