init.c 106 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654
  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 (SiS_Pr->ChipType == SIS_730)
  2159. queuedata = &FQBQData730[0];
  2160. else
  2161. queuedata = &FQBQData[0];
  2162. if(ModeNo > 0x13) {
  2163. /* Get VCLK */
  2164. if(SiS_Pr->UseCustomMode) {
  2165. VCLK = SiS_Pr->CSRClock;
  2166. } else {
  2167. data = SiS_GetRefCRTVCLK(SiS_Pr, RefreshRateTableIndex, SiS_Pr->SiS_UseWide);
  2168. VCLK = SiS_Pr->SiS_VCLKData[data].CLOCK;
  2169. }
  2170. /* Get MCLK * 16 */
  2171. data = SiS_GetReg(SiS_Pr->SiS_P3c4,0x1A) & 0x07;
  2172. MCLK16 = SiS_Pr->SiS_MCLKData_0[data].CLOCK * 16;
  2173. /* Get half colordepth */
  2174. colorth = colortharray[(SiS_Pr->SiS_ModeType - ModeEGA)];
  2175. do {
  2176. templ = SiS_CalcDelay2(SiS_Pr, queuedata[i]) * VCLK * colorth;
  2177. datal = templ % MCLK16;
  2178. templ = (templ / MCLK16) + 1;
  2179. if(datal) templ++;
  2180. if(templ > 0x13) {
  2181. if(queuedata[i + 1] == 0xFF) {
  2182. ThresholdLow = 0x13;
  2183. break;
  2184. }
  2185. i++;
  2186. } else {
  2187. ThresholdLow = templ;
  2188. break;
  2189. }
  2190. } while(queuedata[i] != 0xFF);
  2191. } else {
  2192. if(SiS_Pr->ChipType != SIS_730) i = 9;
  2193. ThresholdLow = 0x02;
  2194. }
  2195. /* Write CRT/CPU threshold low, CRT/Engine threshold high */
  2196. data = ((ThresholdLow & 0x0f) << 4) | 0x0f;
  2197. SiS_SetReg(SiS_Pr->SiS_P3c4,0x08,data);
  2198. data = (ThresholdLow & 0x10) << 1;
  2199. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0F,0xDF,data);
  2200. /* What is this? */
  2201. SiS_SetReg(SiS_Pr->SiS_P3c4,0x3B,0x09);
  2202. /* Write CRT/CPU threshold high (gap = 3) */
  2203. data = ThresholdLow + 3;
  2204. if(data > 0x0f) data = 0x0f;
  2205. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x09,0x80,data);
  2206. /* Write foreground and background queue */
  2207. templ = sisfb_read_nbridge_pci_dword(SiS_Pr, 0x50);
  2208. if(SiS_Pr->ChipType == SIS_730) {
  2209. templ &= 0xfffff9ff;
  2210. templ |= ((queuedata[i] & 0xc0) << 3);
  2211. } else {
  2212. templ &= 0xf0ffffff;
  2213. if( (ModeNo <= 0x13) &&
  2214. (SiS_Pr->ChipType == SIS_630) &&
  2215. (SiS_Pr->ChipRevision >= 0x30) ) {
  2216. templ |= 0x0b000000;
  2217. } else {
  2218. templ |= ((queuedata[i] & 0xf0) << 20);
  2219. }
  2220. }
  2221. sisfb_write_nbridge_pci_dword(SiS_Pr, 0x50, templ);
  2222. templ = sisfb_read_nbridge_pci_dword(SiS_Pr, 0xA0);
  2223. /* GUI grant timer (PCI config 0xA3) */
  2224. if(SiS_Pr->ChipType == SIS_730) {
  2225. templ &= 0x00ffffff;
  2226. datal = queuedata[i] << 8;
  2227. templ |= (((datal & 0x0f00) | ((datal & 0x3000) >> 8)) << 20);
  2228. } else {
  2229. templ &= 0xf0ffffff;
  2230. templ |= ((queuedata[i] & 0x0f) << 24);
  2231. }
  2232. sisfb_write_nbridge_pci_dword(SiS_Pr, 0xA0, templ);
  2233. }
  2234. #endif /* CONFIG_FB_SIS_300 */
  2235. #ifdef CONFIG_FB_SIS_315
  2236. static void
  2237. SiS_SetCRT1FIFO_310(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  2238. {
  2239. unsigned short modeflag;
  2240. /* disable auto-threshold */
  2241. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x3D,0xFE);
  2242. modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
  2243. SiS_SetReg(SiS_Pr->SiS_P3c4,0x08,0xAE);
  2244. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x09,0xF0);
  2245. if(ModeNo > 0x13) {
  2246. if(SiS_Pr->ChipType >= XGI_20) {
  2247. SiS_SetReg(SiS_Pr->SiS_P3c4,0x08,0x34);
  2248. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x3D,0x01);
  2249. } else if(SiS_Pr->ChipType >= SIS_661) {
  2250. if(!(modeflag & HalfDCLK)) {
  2251. SiS_SetReg(SiS_Pr->SiS_P3c4,0x08,0x34);
  2252. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x3D,0x01);
  2253. }
  2254. } else {
  2255. if((!(modeflag & DoubleScanMode)) || (!(modeflag & HalfDCLK))) {
  2256. SiS_SetReg(SiS_Pr->SiS_P3c4,0x08,0x34);
  2257. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x3D,0x01);
  2258. }
  2259. }
  2260. }
  2261. }
  2262. #endif
  2263. /*********************************************/
  2264. /* MODE REGISTERS */
  2265. /*********************************************/
  2266. static void
  2267. SiS_SetVCLKState(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
  2268. unsigned short RefreshRateTableIndex, unsigned short ModeIdIndex)
  2269. {
  2270. unsigned short data = 0, VCLK = 0, index = 0;
  2271. if(ModeNo > 0x13) {
  2272. if(SiS_Pr->UseCustomMode) {
  2273. VCLK = SiS_Pr->CSRClock;
  2274. } else {
  2275. index = SiS_GetVCLK2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  2276. VCLK = SiS_Pr->SiS_VCLKData[index].CLOCK;
  2277. }
  2278. }
  2279. if(SiS_Pr->ChipType < SIS_315H) {
  2280. #ifdef CONFIG_FB_SIS_300
  2281. if(VCLK > 150) data |= 0x80;
  2282. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x07,0x7B,data);
  2283. data = 0x00;
  2284. if(VCLK >= 150) data |= 0x08;
  2285. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x32,0xF7,data);
  2286. #endif
  2287. } else if(SiS_Pr->ChipType < XGI_20) {
  2288. #ifdef CONFIG_FB_SIS_315
  2289. if(VCLK >= 166) data |= 0x0c;
  2290. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x32,0xf3,data);
  2291. if(VCLK >= 166) {
  2292. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1f,0xe7);
  2293. }
  2294. #endif
  2295. } else {
  2296. #ifdef CONFIG_FB_SIS_315
  2297. if(VCLK >= 200) data |= 0x0c;
  2298. if(SiS_Pr->ChipType == XGI_20) data &= ~0x04;
  2299. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x32,0xf3,data);
  2300. if(SiS_Pr->ChipType != XGI_20) {
  2301. data = SiS_GetReg(SiS_Pr->SiS_P3c4,0x1f) & 0xe7;
  2302. if(VCLK < 200) data |= 0x10;
  2303. SiS_SetReg(SiS_Pr->SiS_P3c4,0x1f,data);
  2304. }
  2305. #endif
  2306. }
  2307. /* DAC speed */
  2308. if(SiS_Pr->ChipType >= SIS_661) {
  2309. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x07,0xE8,0x10);
  2310. } else {
  2311. data = 0x03;
  2312. if(VCLK >= 260) data = 0x00;
  2313. else if(VCLK >= 160) data = 0x01;
  2314. else if(VCLK >= 135) data = 0x02;
  2315. if(SiS_Pr->ChipType == SIS_540) {
  2316. /* Was == 203 or < 234 which made no sense */
  2317. if (VCLK < 234) data = 0x02;
  2318. }
  2319. if(SiS_Pr->ChipType < SIS_315H) {
  2320. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x07,0xFC,data);
  2321. } else {
  2322. if(SiS_Pr->ChipType > SIS_315PRO) {
  2323. if(ModeNo > 0x13) data &= 0xfc;
  2324. }
  2325. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x07,0xF8,data);
  2326. }
  2327. }
  2328. }
  2329. static void
  2330. SiS_SetCRT1ModeRegs(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
  2331. unsigned short ModeIdIndex, unsigned short RRTI)
  2332. {
  2333. unsigned short data, infoflag = 0, modeflag, resindex;
  2334. #ifdef CONFIG_FB_SIS_315
  2335. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  2336. unsigned short data2, data3;
  2337. #endif
  2338. modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
  2339. if(SiS_Pr->UseCustomMode) {
  2340. infoflag = SiS_Pr->CInfoFlag;
  2341. } else {
  2342. resindex = SiS_GetResInfo(SiS_Pr, ModeNo, ModeIdIndex);
  2343. if(ModeNo > 0x13) {
  2344. infoflag = SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag;
  2345. }
  2346. }
  2347. /* Disable DPMS */
  2348. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1F,0x3F);
  2349. data = 0;
  2350. if(ModeNo > 0x13) {
  2351. if(SiS_Pr->SiS_ModeType > ModeEGA) {
  2352. data |= 0x02;
  2353. data |= ((SiS_Pr->SiS_ModeType - ModeVGA) << 2);
  2354. }
  2355. if(infoflag & InterlaceMode) data |= 0x20;
  2356. }
  2357. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x06,0xC0,data);
  2358. if(SiS_Pr->ChipType != SIS_300) {
  2359. data = 0;
  2360. if(infoflag & InterlaceMode) {
  2361. /* data = (Hsync / 8) - ((Htotal / 8) / 2) + 3 */
  2362. int hrs = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x04) |
  2363. ((SiS_GetReg(SiS_Pr->SiS_P3c4,0x0b) & 0xc0) << 2)) - 3;
  2364. int hto = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x00) |
  2365. ((SiS_GetReg(SiS_Pr->SiS_P3c4,0x0b) & 0x03) << 8)) + 5;
  2366. data = hrs - (hto >> 1) + 3;
  2367. }
  2368. SiS_SetReg(SiS_Pr->SiS_P3d4,0x19,data);
  2369. SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x1a,0xFC,((data >> 8) & 0x03));
  2370. }
  2371. if(modeflag & HalfDCLK) {
  2372. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x01,0x08);
  2373. }
  2374. data = 0;
  2375. if(modeflag & LineCompareOff) data = 0x08;
  2376. if(SiS_Pr->ChipType == SIS_300) {
  2377. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0F,0xF7,data);
  2378. } else {
  2379. if(SiS_Pr->ChipType >= XGI_20) data |= 0x20;
  2380. if(SiS_Pr->SiS_ModeType == ModeEGA) {
  2381. if(ModeNo > 0x13) {
  2382. data |= 0x40;
  2383. }
  2384. }
  2385. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0F,0xB7,data);
  2386. }
  2387. #ifdef CONFIG_FB_SIS_315
  2388. if(SiS_Pr->ChipType >= SIS_315H) {
  2389. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x31,0xfb);
  2390. }
  2391. if(SiS_Pr->ChipType == SIS_315PRO) {
  2392. data = SiS_Pr->SiS_SR15[(2 * 4) + SiS_Get310DRAMType(SiS_Pr)];
  2393. if(SiS_Pr->SiS_ModeType == ModeText) {
  2394. data &= 0xc7;
  2395. } else {
  2396. data2 = SiS_GetOffset(SiS_Pr, ModeNo, ModeIdIndex, RRTI) >> 1;
  2397. if(infoflag & InterlaceMode) data2 >>= 1;
  2398. data3 = SiS_GetColorDepth(SiS_Pr, ModeNo, ModeIdIndex) >> 1;
  2399. if(data3) data2 /= data3;
  2400. if(data2 >= 0x50) {
  2401. data &= 0x0f;
  2402. data |= 0x50;
  2403. }
  2404. }
  2405. SiS_SetReg(SiS_Pr->SiS_P3c4,0x17,data);
  2406. } else if((SiS_Pr->ChipType == SIS_330) || (SiS_Pr->SiS_SysFlags & SF_760LFB)) {
  2407. data = SiS_Get310DRAMType(SiS_Pr);
  2408. if(SiS_Pr->ChipType == SIS_330) {
  2409. data = SiS_Pr->SiS_SR15[(2 * 4) + data];
  2410. } else {
  2411. if(SiS_Pr->SiS_ROMNew) data = ROMAddr[0xf6];
  2412. else if(SiS_Pr->SiS_UseROM) data = ROMAddr[0x100 + data];
  2413. else data = 0xba;
  2414. }
  2415. if(SiS_Pr->SiS_ModeType <= ModeEGA) {
  2416. data &= 0xc7;
  2417. } else {
  2418. if(SiS_Pr->UseCustomMode) {
  2419. data2 = SiS_Pr->CSRClock;
  2420. } else {
  2421. data2 = SiS_GetVCLK2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RRTI);
  2422. data2 = SiS_Pr->SiS_VCLKData[data2].CLOCK;
  2423. }
  2424. data3 = SiS_GetColorDepth(SiS_Pr, ModeNo, ModeIdIndex) >> 1;
  2425. if(data3) data2 *= data3;
  2426. data2 = ((unsigned int)(SiS_GetMCLK(SiS_Pr) * 1024)) / data2;
  2427. if(SiS_Pr->ChipType == SIS_330) {
  2428. if(SiS_Pr->SiS_ModeType != Mode16Bpp) {
  2429. if (data2 >= 0x19c) data = 0xba;
  2430. else if(data2 >= 0x140) data = 0x7a;
  2431. else if(data2 >= 0x101) data = 0x3a;
  2432. else if(data2 >= 0xf5) data = 0x32;
  2433. else if(data2 >= 0xe2) data = 0x2a;
  2434. else if(data2 >= 0xc4) data = 0x22;
  2435. else if(data2 >= 0xac) data = 0x1a;
  2436. else if(data2 >= 0x9e) data = 0x12;
  2437. else if(data2 >= 0x8e) data = 0x0a;
  2438. else data = 0x02;
  2439. } else {
  2440. if(data2 >= 0x127) data = 0xba;
  2441. else data = 0x7a;
  2442. }
  2443. } else { /* 76x+LFB */
  2444. if (data2 >= 0x190) data = 0xba;
  2445. else if(data2 >= 0xff) data = 0x7a;
  2446. else if(data2 >= 0xd3) data = 0x3a;
  2447. else if(data2 >= 0xa9) data = 0x1a;
  2448. else if(data2 >= 0x93) data = 0x0a;
  2449. else data = 0x02;
  2450. }
  2451. }
  2452. SiS_SetReg(SiS_Pr->SiS_P3c4,0x17,data);
  2453. }
  2454. /* XGI: Nothing. */
  2455. /* TODO: Check SiS340 */
  2456. #endif
  2457. data = 0x60;
  2458. if(SiS_Pr->SiS_ModeType != ModeText) {
  2459. data ^= 0x60;
  2460. if(SiS_Pr->SiS_ModeType != ModeEGA) {
  2461. data ^= 0xA0;
  2462. }
  2463. }
  2464. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x21,0x1F,data);
  2465. SiS_SetVCLKState(SiS_Pr, ModeNo, RRTI, ModeIdIndex);
  2466. #ifdef CONFIG_FB_SIS_315
  2467. if(((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->ChipType < SIS_661)) ||
  2468. (SiS_Pr->ChipType == XGI_40)) {
  2469. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & 0x40) {
  2470. SiS_SetReg(SiS_Pr->SiS_P3d4,0x52,0x2c);
  2471. } else {
  2472. SiS_SetReg(SiS_Pr->SiS_P3d4,0x52,0x6c);
  2473. }
  2474. } else if(SiS_Pr->ChipType == XGI_20) {
  2475. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & 0x40) {
  2476. SiS_SetReg(SiS_Pr->SiS_P3d4,0x52,0x33);
  2477. } else {
  2478. SiS_SetReg(SiS_Pr->SiS_P3d4,0x52,0x73);
  2479. }
  2480. SiS_SetReg(SiS_Pr->SiS_P3d4,0x51,0x02);
  2481. }
  2482. #endif
  2483. }
  2484. #ifdef CONFIG_FB_SIS_315
  2485. static void
  2486. SiS_SetupDualChip(struct SiS_Private *SiS_Pr)
  2487. {
  2488. #if 0
  2489. /* TODO: Find out about IOAddress2 */
  2490. SISIOADDRESS P2_3c2 = SiS_Pr->IOAddress2 + 0x12;
  2491. SISIOADDRESS P2_3c4 = SiS_Pr->IOAddress2 + 0x14;
  2492. SISIOADDRESS P2_3ce = SiS_Pr->IOAddress2 + 0x1e;
  2493. int i;
  2494. if((SiS_Pr->ChipRevision != 0) ||
  2495. (!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x3a) & 0x04)))
  2496. return;
  2497. for(i = 0; i <= 4; i++) { /* SR00 - SR04 */
  2498. SiS_SetReg(P2_3c4,i,SiS_GetReg(SiS_Pr->SiS_P3c4,i));
  2499. }
  2500. for(i = 0; i <= 8; i++) { /* GR00 - GR08 */
  2501. SiS_SetReg(P2_3ce,i,SiS_GetReg(SiS_Pr->SiS_P3ce,i));
  2502. }
  2503. SiS_SetReg(P2_3c4,0x05,0x86);
  2504. SiS_SetReg(P2_3c4,0x06,SiS_GetReg(SiS_Pr->SiS_P3c4,0x06)); /* SR06 */
  2505. SiS_SetReg(P2_3c4,0x21,SiS_GetReg(SiS_Pr->SiS_P3c4,0x21)); /* SR21 */
  2506. SiS_SetRegByte(P2_3c2,SiS_GetRegByte(SiS_Pr->SiS_P3cc)); /* MISC */
  2507. SiS_SetReg(P2_3c4,0x05,0x00);
  2508. #endif
  2509. }
  2510. #endif
  2511. /*********************************************/
  2512. /* LOAD DAC */
  2513. /*********************************************/
  2514. static void
  2515. SiS_WriteDAC(struct SiS_Private *SiS_Pr, SISIOADDRESS DACData, unsigned short shiftflag,
  2516. unsigned short dl, unsigned short ah, unsigned short al, unsigned short dh)
  2517. {
  2518. unsigned short d1, d2, d3;
  2519. switch(dl) {
  2520. case 0: d1 = dh; d2 = ah; d3 = al; break;
  2521. case 1: d1 = ah; d2 = al; d3 = dh; break;
  2522. default: d1 = al; d2 = dh; d3 = ah;
  2523. }
  2524. SiS_SetRegByte(DACData, (d1 << shiftflag));
  2525. SiS_SetRegByte(DACData, (d2 << shiftflag));
  2526. SiS_SetRegByte(DACData, (d3 << shiftflag));
  2527. }
  2528. void
  2529. SiS_LoadDAC(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  2530. {
  2531. unsigned short data, data2, time, i, j, k, m, n, o;
  2532. unsigned short si, di, bx, sf;
  2533. SISIOADDRESS DACAddr, DACData;
  2534. const unsigned char *table = NULL;
  2535. data = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex) & DACInfoFlag;
  2536. j = time = 64;
  2537. if(data == 0x00) table = SiS_MDA_DAC;
  2538. else if(data == 0x08) table = SiS_CGA_DAC;
  2539. else if(data == 0x10) table = SiS_EGA_DAC;
  2540. else if(data == 0x18) {
  2541. j = 16;
  2542. time = 256;
  2543. table = SiS_VGA_DAC;
  2544. }
  2545. if( ( (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && /* 301B-DH LCD */
  2546. (SiS_Pr->SiS_VBType & VB_NoLCD) ) ||
  2547. (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) || /* LCDA */
  2548. (!(SiS_Pr->SiS_SetFlag & ProgrammingCRT2)) ) { /* Programming CRT1 */
  2549. SiS_SetRegByte(SiS_Pr->SiS_P3c6,0xFF);
  2550. DACAddr = SiS_Pr->SiS_P3c8;
  2551. DACData = SiS_Pr->SiS_P3c9;
  2552. sf = 0;
  2553. } else {
  2554. DACAddr = SiS_Pr->SiS_Part5Port;
  2555. DACData = SiS_Pr->SiS_Part5Port + 1;
  2556. sf = 2;
  2557. }
  2558. SiS_SetRegByte(DACAddr,0x00);
  2559. for(i = 0; i < j; i++) {
  2560. data = table[i];
  2561. for(k = 0; k < 3; k++) {
  2562. data2 = 0;
  2563. if(data & 0x01) data2 += 0x2A;
  2564. if(data & 0x02) data2 += 0x15;
  2565. SiS_SetRegByte(DACData, (data2 << sf));
  2566. data >>= 2;
  2567. }
  2568. }
  2569. if(time == 256) {
  2570. for(i = 16; i < 32; i++) {
  2571. data = table[i] << sf;
  2572. for(k = 0; k < 3; k++) SiS_SetRegByte(DACData, data);
  2573. }
  2574. si = 32;
  2575. for(m = 0; m < 9; m++) {
  2576. di = si;
  2577. bx = si + 4;
  2578. for(n = 0; n < 3; n++) {
  2579. for(o = 0; o < 5; o++) {
  2580. SiS_WriteDAC(SiS_Pr, DACData, sf, n, table[di], table[bx], table[si]);
  2581. si++;
  2582. }
  2583. si -= 2;
  2584. for(o = 0; o < 3; o++) {
  2585. SiS_WriteDAC(SiS_Pr, DACData, sf, n, table[di], table[si], table[bx]);
  2586. si--;
  2587. }
  2588. } /* for n < 3 */
  2589. si += 5;
  2590. } /* for m < 9 */
  2591. }
  2592. }
  2593. /*********************************************/
  2594. /* SET CRT1 REGISTER GROUP */
  2595. /*********************************************/
  2596. static void
  2597. SiS_SetCRT1Group(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  2598. {
  2599. unsigned short StandTableIndex, RefreshRateTableIndex;
  2600. SiS_Pr->SiS_CRT1Mode = ModeNo;
  2601. StandTableIndex = SiS_GetModePtr(SiS_Pr, ModeNo, ModeIdIndex);
  2602. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  2603. if(SiS_Pr->SiS_VBInfo & (SetSimuScanMode | SwitchCRT2)) {
  2604. SiS_DisableBridge(SiS_Pr);
  2605. }
  2606. }
  2607. SiS_ResetSegmentRegisters(SiS_Pr);
  2608. SiS_SetSeqRegs(SiS_Pr, StandTableIndex);
  2609. SiS_SetMiscRegs(SiS_Pr, StandTableIndex);
  2610. SiS_SetCRTCRegs(SiS_Pr, StandTableIndex);
  2611. SiS_SetATTRegs(SiS_Pr, StandTableIndex);
  2612. SiS_SetGRCRegs(SiS_Pr, StandTableIndex);
  2613. SiS_ClearExt1Regs(SiS_Pr, ModeNo);
  2614. SiS_ResetCRT1VCLK(SiS_Pr);
  2615. SiS_Pr->SiS_SelectCRT2Rate = 0;
  2616. SiS_Pr->SiS_SetFlag &= (~ProgrammingCRT2);
  2617. if(SiS_Pr->SiS_VBInfo & SetSimuScanMode) {
  2618. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  2619. SiS_Pr->SiS_SetFlag |= ProgrammingCRT2;
  2620. }
  2621. }
  2622. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  2623. SiS_Pr->SiS_SetFlag |= ProgrammingCRT2;
  2624. }
  2625. RefreshRateTableIndex = SiS_GetRatePtr(SiS_Pr, ModeNo, ModeIdIndex);
  2626. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  2627. SiS_Pr->SiS_SetFlag &= ~ProgrammingCRT2;
  2628. }
  2629. if(RefreshRateTableIndex != 0xFFFF) {
  2630. SiS_SetCRT1Sync(SiS_Pr, RefreshRateTableIndex);
  2631. SiS_SetCRT1CRTC(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  2632. SiS_SetCRT1Offset(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  2633. SiS_SetCRT1VCLK(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  2634. }
  2635. switch(SiS_Pr->ChipType) {
  2636. #ifdef CONFIG_FB_SIS_300
  2637. case SIS_300:
  2638. SiS_SetCRT1FIFO_300(SiS_Pr, ModeNo, RefreshRateTableIndex);
  2639. break;
  2640. case SIS_540:
  2641. case SIS_630:
  2642. case SIS_730:
  2643. SiS_SetCRT1FIFO_630(SiS_Pr, ModeNo, RefreshRateTableIndex);
  2644. break;
  2645. #endif
  2646. default:
  2647. #ifdef CONFIG_FB_SIS_315
  2648. if(SiS_Pr->ChipType == XGI_20) {
  2649. unsigned char sr2b = 0, sr2c = 0;
  2650. switch(ModeNo) {
  2651. case 0x00:
  2652. case 0x01: sr2b = 0x4e; sr2c = 0xe9; break;
  2653. case 0x04:
  2654. case 0x05:
  2655. case 0x0d: sr2b = 0x1b; sr2c = 0xe3; break;
  2656. }
  2657. if(sr2b) {
  2658. SiS_SetReg(SiS_Pr->SiS_P3c4,0x2b,sr2b);
  2659. SiS_SetReg(SiS_Pr->SiS_P3c4,0x2c,sr2c);
  2660. SiS_SetRegByte(SiS_Pr->SiS_P3c2,(SiS_GetRegByte(SiS_Pr->SiS_P3cc) | 0x0c));
  2661. }
  2662. }
  2663. SiS_SetCRT1FIFO_310(SiS_Pr, ModeNo, ModeIdIndex);
  2664. #endif
  2665. break;
  2666. }
  2667. SiS_SetCRT1ModeRegs(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  2668. #ifdef CONFIG_FB_SIS_315
  2669. if(SiS_Pr->ChipType == XGI_40) {
  2670. SiS_SetupDualChip(SiS_Pr);
  2671. }
  2672. #endif
  2673. SiS_LoadDAC(SiS_Pr, ModeNo, ModeIdIndex);
  2674. if(SiS_Pr->SiS_flag_clearbuffer) {
  2675. SiS_ClearBuffer(SiS_Pr, ModeNo);
  2676. }
  2677. if(!(SiS_Pr->SiS_VBInfo & (SetSimuScanMode | SwitchCRT2 | SetCRT2ToLCDA))) {
  2678. SiS_WaitRetrace1(SiS_Pr);
  2679. SiS_DisplayOn(SiS_Pr);
  2680. }
  2681. }
  2682. /*********************************************/
  2683. /* HELPER: VIDEO BRIDGE PROG CLK */
  2684. /*********************************************/
  2685. static void
  2686. SiS_InitVB(struct SiS_Private *SiS_Pr)
  2687. {
  2688. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  2689. SiS_Pr->Init_P4_0E = 0;
  2690. if(SiS_Pr->SiS_ROMNew) {
  2691. SiS_Pr->Init_P4_0E = ROMAddr[0x82];
  2692. } else if(SiS_Pr->ChipType >= XGI_40) {
  2693. if(SiS_Pr->SiS_XGIROM) {
  2694. SiS_Pr->Init_P4_0E = ROMAddr[0x80];
  2695. }
  2696. }
  2697. }
  2698. static void
  2699. SiS_ResetVB(struct SiS_Private *SiS_Pr)
  2700. {
  2701. #ifdef CONFIG_FB_SIS_315
  2702. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  2703. unsigned short temp;
  2704. /* VB programming clock */
  2705. if(SiS_Pr->SiS_UseROM) {
  2706. if(SiS_Pr->ChipType < SIS_330) {
  2707. temp = ROMAddr[VB310Data_1_2_Offset] | 0x40;
  2708. if(SiS_Pr->SiS_ROMNew) temp = ROMAddr[0x80] | 0x40;
  2709. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x02,temp);
  2710. } else if(SiS_Pr->ChipType >= SIS_661 && SiS_Pr->ChipType < XGI_20) {
  2711. temp = ROMAddr[0x7e] | 0x40;
  2712. if(SiS_Pr->SiS_ROMNew) temp = ROMAddr[0x80] | 0x40;
  2713. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x02,temp);
  2714. }
  2715. } else if(SiS_Pr->ChipType >= XGI_40) {
  2716. temp = 0x40;
  2717. if(SiS_Pr->SiS_XGIROM) temp |= ROMAddr[0x7e];
  2718. /* Can we do this on any chipset? */
  2719. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x02,temp);
  2720. }
  2721. #endif
  2722. }
  2723. /*********************************************/
  2724. /* HELPER: SET VIDEO/CAPTURE REGISTERS */
  2725. /*********************************************/
  2726. static void
  2727. SiS_StrangeStuff(struct SiS_Private *SiS_Pr)
  2728. {
  2729. /* SiS65x and XGI set up some sort of "lock mode" for text
  2730. * which locks CRT2 in some way to CRT1 timing. Disable
  2731. * this here.
  2732. */
  2733. #ifdef CONFIG_FB_SIS_315
  2734. if((IS_SIS651) || (IS_SISM650) ||
  2735. SiS_Pr->ChipType == SIS_340 ||
  2736. SiS_Pr->ChipType == XGI_40) {
  2737. SiS_SetReg(SiS_Pr->SiS_VidCapt, 0x3f, 0x00); /* Fiddle with capture regs */
  2738. SiS_SetReg(SiS_Pr->SiS_VidCapt, 0x00, 0x00);
  2739. SiS_SetReg(SiS_Pr->SiS_VidPlay, 0x00, 0x86); /* (BIOS does NOT unlock) */
  2740. SiS_SetRegAND(SiS_Pr->SiS_VidPlay, 0x30, 0xfe); /* Fiddle with video regs */
  2741. SiS_SetRegAND(SiS_Pr->SiS_VidPlay, 0x3f, 0xef);
  2742. }
  2743. /* !!! This does not support modes < 0x13 !!! */
  2744. #endif
  2745. }
  2746. /*********************************************/
  2747. /* HELPER: SET AGP TIMING FOR SiS760 */
  2748. /*********************************************/
  2749. static void
  2750. SiS_Handle760(struct SiS_Private *SiS_Pr)
  2751. {
  2752. #ifdef CONFIG_FB_SIS_315
  2753. unsigned int somebase;
  2754. unsigned char temp1, temp2, temp3;
  2755. if( (SiS_Pr->ChipType != SIS_760) ||
  2756. ((SiS_GetReg(SiS_Pr->SiS_P3d4, 0x5c) & 0xf8) != 0x80) ||
  2757. (!(SiS_Pr->SiS_SysFlags & SF_760LFB)) ||
  2758. (!(SiS_Pr->SiS_SysFlags & SF_760UMA)) )
  2759. return;
  2760. somebase = sisfb_read_mio_pci_word(SiS_Pr, 0x74);
  2761. somebase &= 0xffff;
  2762. if(somebase == 0) return;
  2763. temp3 = SiS_GetRegByte((somebase + 0x85)) & 0xb7;
  2764. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & 0x40) {
  2765. temp1 = 0x21;
  2766. temp2 = 0x03;
  2767. temp3 |= 0x08;
  2768. } else {
  2769. temp1 = 0x25;
  2770. temp2 = 0x0b;
  2771. }
  2772. sisfb_write_nbridge_pci_byte(SiS_Pr, 0x7e, temp1);
  2773. sisfb_write_nbridge_pci_byte(SiS_Pr, 0x8d, temp2);
  2774. SiS_SetRegByte((somebase + 0x85), temp3);
  2775. #endif
  2776. }
  2777. /*********************************************/
  2778. /* SiSSetMode() */
  2779. /*********************************************/
  2780. bool
  2781. SiSSetMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
  2782. {
  2783. SISIOADDRESS BaseAddr = SiS_Pr->IOAddress;
  2784. unsigned short RealModeNo, ModeIdIndex;
  2785. unsigned char backupreg = 0;
  2786. unsigned short KeepLockReg;
  2787. SiS_Pr->UseCustomMode = false;
  2788. SiS_Pr->CRT1UsesCustomMode = false;
  2789. SiS_Pr->SiS_flag_clearbuffer = 0;
  2790. if(SiS_Pr->UseCustomMode) {
  2791. ModeNo = 0xfe;
  2792. } else {
  2793. if(!(ModeNo & 0x80)) SiS_Pr->SiS_flag_clearbuffer = 1;
  2794. ModeNo &= 0x7f;
  2795. }
  2796. /* Don't use FSTN mode for CRT1 */
  2797. RealModeNo = ModeNo;
  2798. if(ModeNo == 0x5b) ModeNo = 0x56;
  2799. SiSInitPtr(SiS_Pr);
  2800. SiSRegInit(SiS_Pr, BaseAddr);
  2801. SiS_GetSysFlags(SiS_Pr);
  2802. SiS_Pr->SiS_VGAINFO = 0x11;
  2803. KeepLockReg = SiS_GetReg(SiS_Pr->SiS_P3c4,0x05);
  2804. SiS_SetReg(SiS_Pr->SiS_P3c4,0x05,0x86);
  2805. SiSInitPCIetc(SiS_Pr);
  2806. SiSSetLVDSetc(SiS_Pr);
  2807. SiSDetermineROMUsage(SiS_Pr);
  2808. SiS_UnLockCRT2(SiS_Pr);
  2809. if(!SiS_Pr->UseCustomMode) {
  2810. if(!(SiS_SearchModeID(SiS_Pr, &ModeNo, &ModeIdIndex))) return false;
  2811. } else {
  2812. ModeIdIndex = 0;
  2813. }
  2814. SiS_GetVBType(SiS_Pr);
  2815. /* Init/restore some VB registers */
  2816. SiS_InitVB(SiS_Pr);
  2817. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  2818. if(SiS_Pr->ChipType >= SIS_315H) {
  2819. SiS_ResetVB(SiS_Pr);
  2820. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x32,0x10);
  2821. SiS_SetRegOR(SiS_Pr->SiS_Part2Port,0x00,0x0c);
  2822. backupreg = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  2823. } else {
  2824. backupreg = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35);
  2825. }
  2826. }
  2827. /* Get VB information (connectors, connected devices) */
  2828. SiS_GetVBInfo(SiS_Pr, ModeNo, ModeIdIndex, (SiS_Pr->UseCustomMode) ? 0 : 1);
  2829. SiS_SetYPbPr(SiS_Pr);
  2830. SiS_SetTVMode(SiS_Pr, ModeNo, ModeIdIndex);
  2831. SiS_GetLCDResInfo(SiS_Pr, ModeNo, ModeIdIndex);
  2832. SiS_SetLowModeTest(SiS_Pr, ModeNo);
  2833. /* Check memory size (kernel framebuffer driver only) */
  2834. if(!SiS_CheckMemorySize(SiS_Pr, ModeNo, ModeIdIndex)) {
  2835. return false;
  2836. }
  2837. SiS_OpenCRTC(SiS_Pr);
  2838. if(SiS_Pr->UseCustomMode) {
  2839. SiS_Pr->CRT1UsesCustomMode = true;
  2840. SiS_Pr->CSRClock_CRT1 = SiS_Pr->CSRClock;
  2841. SiS_Pr->CModeFlag_CRT1 = SiS_Pr->CModeFlag;
  2842. } else {
  2843. SiS_Pr->CRT1UsesCustomMode = false;
  2844. }
  2845. /* Set mode on CRT1 */
  2846. if( (SiS_Pr->SiS_VBInfo & (SetSimuScanMode | SetCRT2ToLCDA)) ||
  2847. (!(SiS_Pr->SiS_VBInfo & SwitchCRT2)) ) {
  2848. SiS_SetCRT1Group(SiS_Pr, ModeNo, ModeIdIndex);
  2849. }
  2850. /* Set mode on CRT2 */
  2851. if(SiS_Pr->SiS_VBInfo & (SetSimuScanMode | SwitchCRT2 | SetCRT2ToLCDA)) {
  2852. if( (SiS_Pr->SiS_VBType & VB_SISVB) ||
  2853. (SiS_Pr->SiS_IF_DEF_LVDS == 1) ||
  2854. (SiS_Pr->SiS_IF_DEF_CH70xx != 0) ||
  2855. (SiS_Pr->SiS_IF_DEF_TRUMPION != 0) ) {
  2856. SiS_SetCRT2Group(SiS_Pr, RealModeNo);
  2857. }
  2858. }
  2859. SiS_HandleCRT1(SiS_Pr);
  2860. SiS_StrangeStuff(SiS_Pr);
  2861. SiS_DisplayOn(SiS_Pr);
  2862. SiS_SetRegByte(SiS_Pr->SiS_P3c6,0xFF);
  2863. #ifdef CONFIG_FB_SIS_315
  2864. if(SiS_Pr->ChipType >= SIS_315H) {
  2865. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  2866. if(!(SiS_IsDualEdge(SiS_Pr))) {
  2867. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xfb);
  2868. }
  2869. }
  2870. }
  2871. #endif
  2872. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  2873. if(SiS_Pr->ChipType >= SIS_315H) {
  2874. #ifdef CONFIG_FB_SIS_315
  2875. if(!SiS_Pr->SiS_ROMNew) {
  2876. if(SiS_IsVAMode(SiS_Pr)) {
  2877. SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x35,0x01);
  2878. } else {
  2879. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x35,0xFE);
  2880. }
  2881. }
  2882. SiS_SetReg(SiS_Pr->SiS_P3d4,0x38,backupreg);
  2883. if((IS_SIS650) && (SiS_GetReg(SiS_Pr->SiS_P3d4,0x30) & 0xfc)) {
  2884. if((ModeNo == 0x03) || (ModeNo == 0x10)) {
  2885. SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x51,0x80);
  2886. SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x56,0x08);
  2887. }
  2888. }
  2889. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x30) & SetCRT2ToLCD) {
  2890. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x38,0xfc);
  2891. }
  2892. #endif
  2893. } else if((SiS_Pr->ChipType == SIS_630) ||
  2894. (SiS_Pr->ChipType == SIS_730)) {
  2895. SiS_SetReg(SiS_Pr->SiS_P3d4,0x35,backupreg);
  2896. }
  2897. }
  2898. SiS_CloseCRTC(SiS_Pr);
  2899. SiS_Handle760(SiS_Pr);
  2900. /* We never lock registers in XF86 */
  2901. if(KeepLockReg != 0xA1) SiS_SetReg(SiS_Pr->SiS_P3c4,0x05,0x00);
  2902. return true;
  2903. }
  2904. #ifndef GETBITSTR
  2905. #define GENBITSMASK(mask) GENMASK(1?mask,0?mask)
  2906. #define GETBITS(var,mask) (((var) & GENBITSMASK(mask)) >> (0?mask))
  2907. #define GETBITSTR(val,from,to) ((GETBITS(val,from)) << (0?to))
  2908. #endif
  2909. void
  2910. SiS_CalcCRRegisters(struct SiS_Private *SiS_Pr, int depth)
  2911. {
  2912. int x = 1; /* Fix sync */
  2913. SiS_Pr->CCRT1CRTC[0] = ((SiS_Pr->CHTotal >> 3) - 5) & 0xff; /* CR0 */
  2914. SiS_Pr->CCRT1CRTC[1] = (SiS_Pr->CHDisplay >> 3) - 1; /* CR1 */
  2915. SiS_Pr->CCRT1CRTC[2] = (SiS_Pr->CHBlankStart >> 3) - 1; /* CR2 */
  2916. SiS_Pr->CCRT1CRTC[3] = (((SiS_Pr->CHBlankEnd >> 3) - 1) & 0x1F) | 0x80; /* CR3 */
  2917. SiS_Pr->CCRT1CRTC[4] = (SiS_Pr->CHSyncStart >> 3) + 3; /* CR4 */
  2918. SiS_Pr->CCRT1CRTC[5] = ((((SiS_Pr->CHBlankEnd >> 3) - 1) & 0x20) << 2) | /* CR5 */
  2919. (((SiS_Pr->CHSyncEnd >> 3) + 3) & 0x1F);
  2920. SiS_Pr->CCRT1CRTC[6] = (SiS_Pr->CVTotal - 2) & 0xFF; /* CR6 */
  2921. SiS_Pr->CCRT1CRTC[7] = (((SiS_Pr->CVTotal - 2) & 0x100) >> 8) /* CR7 */
  2922. | (((SiS_Pr->CVDisplay - 1) & 0x100) >> 7)
  2923. | (((SiS_Pr->CVSyncStart - x) & 0x100) >> 6)
  2924. | (((SiS_Pr->CVBlankStart- 1) & 0x100) >> 5)
  2925. | 0x10
  2926. | (((SiS_Pr->CVTotal - 2) & 0x200) >> 4)
  2927. | (((SiS_Pr->CVDisplay - 1) & 0x200) >> 3)
  2928. | (((SiS_Pr->CVSyncStart - x) & 0x200) >> 2);
  2929. SiS_Pr->CCRT1CRTC[16] = ((((SiS_Pr->CVBlankStart - 1) & 0x200) >> 4) >> 5); /* CR9 */
  2930. if(depth != 8) {
  2931. if(SiS_Pr->CHDisplay >= 1600) SiS_Pr->CCRT1CRTC[16] |= 0x60; /* SRE */
  2932. else if(SiS_Pr->CHDisplay >= 640) SiS_Pr->CCRT1CRTC[16] |= 0x40;
  2933. }
  2934. SiS_Pr->CCRT1CRTC[8] = (SiS_Pr->CVSyncStart - x) & 0xFF; /* CR10 */
  2935. SiS_Pr->CCRT1CRTC[9] = ((SiS_Pr->CVSyncEnd - x) & 0x0F) | 0x80; /* CR11 */
  2936. SiS_Pr->CCRT1CRTC[10] = (SiS_Pr->CVDisplay - 1) & 0xFF; /* CR12 */
  2937. SiS_Pr->CCRT1CRTC[11] = (SiS_Pr->CVBlankStart - 1) & 0xFF; /* CR15 */
  2938. SiS_Pr->CCRT1CRTC[12] = (SiS_Pr->CVBlankEnd - 1) & 0xFF; /* CR16 */
  2939. SiS_Pr->CCRT1CRTC[13] = /* SRA */
  2940. GETBITSTR((SiS_Pr->CVTotal -2), 10:10, 0:0) |
  2941. GETBITSTR((SiS_Pr->CVDisplay -1), 10:10, 1:1) |
  2942. GETBITSTR((SiS_Pr->CVBlankStart-1), 10:10, 2:2) |
  2943. GETBITSTR((SiS_Pr->CVSyncStart -x), 10:10, 3:3) |
  2944. GETBITSTR((SiS_Pr->CVBlankEnd -1), 8:8, 4:4) |
  2945. GETBITSTR((SiS_Pr->CVSyncEnd ), 4:4, 5:5) ;
  2946. SiS_Pr->CCRT1CRTC[14] = /* SRB */
  2947. GETBITSTR((SiS_Pr->CHTotal >> 3) - 5, 9:8, 1:0) |
  2948. GETBITSTR((SiS_Pr->CHDisplay >> 3) - 1, 9:8, 3:2) |
  2949. GETBITSTR((SiS_Pr->CHBlankStart >> 3) - 1, 9:8, 5:4) |
  2950. GETBITSTR((SiS_Pr->CHSyncStart >> 3) + 3, 9:8, 7:6) ;
  2951. SiS_Pr->CCRT1CRTC[15] = /* SRC */
  2952. GETBITSTR((SiS_Pr->CHBlankEnd >> 3) - 1, 7:6, 1:0) |
  2953. GETBITSTR((SiS_Pr->CHSyncEnd >> 3) + 3, 5:5, 2:2) ;
  2954. }
  2955. void
  2956. SiS_CalcLCDACRT1Timing(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
  2957. unsigned short ModeIdIndex)
  2958. {
  2959. unsigned short modeflag, tempax, tempbx = 0, remaining = 0;
  2960. unsigned short VGAHDE = SiS_Pr->SiS_VGAHDE;
  2961. int i, j;
  2962. /* 1:1 data: use data set by setcrt1crtc() */
  2963. if(SiS_Pr->SiS_LCDInfo & LCDPass11) return;
  2964. modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
  2965. if(modeflag & HalfDCLK) VGAHDE >>= 1;
  2966. SiS_Pr->CHDisplay = VGAHDE;
  2967. SiS_Pr->CHBlankStart = VGAHDE;
  2968. SiS_Pr->CVDisplay = SiS_Pr->SiS_VGAVDE;
  2969. SiS_Pr->CVBlankStart = SiS_Pr->SiS_VGAVDE;
  2970. if(SiS_Pr->ChipType < SIS_315H) {
  2971. #ifdef CONFIG_FB_SIS_300
  2972. tempbx = SiS_Pr->SiS_VGAHT;
  2973. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  2974. tempbx = SiS_Pr->PanelHT;
  2975. }
  2976. if(modeflag & HalfDCLK) tempbx >>= 1;
  2977. remaining = tempbx % 8;
  2978. #endif
  2979. } else {
  2980. #ifdef CONFIG_FB_SIS_315
  2981. /* OK for LCDA, LVDS */
  2982. tempbx = SiS_Pr->PanelHT - SiS_Pr->PanelXRes;
  2983. tempax = SiS_Pr->SiS_VGAHDE; /* not /2 ! */
  2984. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  2985. tempax = SiS_Pr->PanelXRes;
  2986. }
  2987. tempbx += tempax;
  2988. if(modeflag & HalfDCLK) tempbx -= VGAHDE;
  2989. #endif
  2990. }
  2991. SiS_Pr->CHTotal = SiS_Pr->CHBlankEnd = tempbx;
  2992. if(SiS_Pr->ChipType < SIS_315H) {
  2993. #ifdef CONFIG_FB_SIS_300
  2994. if(SiS_Pr->SiS_VGAHDE == SiS_Pr->PanelXRes) {
  2995. SiS_Pr->CHSyncStart = SiS_Pr->SiS_VGAHDE + ((SiS_Pr->PanelHRS + 1) & ~1);
  2996. SiS_Pr->CHSyncEnd = SiS_Pr->CHSyncStart + SiS_Pr->PanelHRE;
  2997. if(modeflag & HalfDCLK) {
  2998. SiS_Pr->CHSyncStart >>= 1;
  2999. SiS_Pr->CHSyncEnd >>= 1;
  3000. }
  3001. } else if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  3002. tempax = (SiS_Pr->PanelXRes - SiS_Pr->SiS_VGAHDE) >> 1;
  3003. tempbx = (SiS_Pr->PanelHRS + 1) & ~1;
  3004. if(modeflag & HalfDCLK) {
  3005. tempax >>= 1;
  3006. tempbx >>= 1;
  3007. }
  3008. SiS_Pr->CHSyncStart = (VGAHDE + tempax + tempbx + 7) & ~7;
  3009. tempax = SiS_Pr->PanelHRE + 7;
  3010. if(modeflag & HalfDCLK) tempax >>= 1;
  3011. SiS_Pr->CHSyncEnd = (SiS_Pr->CHSyncStart + tempax) & ~7;
  3012. } else {
  3013. SiS_Pr->CHSyncStart = SiS_Pr->SiS_VGAHDE;
  3014. if(modeflag & HalfDCLK) {
  3015. SiS_Pr->CHSyncStart >>= 1;
  3016. tempax = ((SiS_Pr->CHTotal - SiS_Pr->CHSyncStart) / 3) << 1;
  3017. SiS_Pr->CHSyncEnd = SiS_Pr->CHSyncStart + tempax;
  3018. } else {
  3019. SiS_Pr->CHSyncEnd = (SiS_Pr->CHSyncStart + (SiS_Pr->CHTotal / 10) + 7) & ~7;
  3020. SiS_Pr->CHSyncStart += 8;
  3021. }
  3022. }
  3023. #endif
  3024. } else {
  3025. #ifdef CONFIG_FB_SIS_315
  3026. tempax = VGAHDE;
  3027. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  3028. tempbx = SiS_Pr->PanelXRes;
  3029. if(modeflag & HalfDCLK) tempbx >>= 1;
  3030. tempax += ((tempbx - tempax) >> 1);
  3031. }
  3032. tempax += SiS_Pr->PanelHRS;
  3033. SiS_Pr->CHSyncStart = tempax;
  3034. tempax += SiS_Pr->PanelHRE;
  3035. SiS_Pr->CHSyncEnd = tempax;
  3036. #endif
  3037. }
  3038. tempbx = SiS_Pr->PanelVT - SiS_Pr->PanelYRes;
  3039. tempax = SiS_Pr->SiS_VGAVDE;
  3040. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  3041. tempax = SiS_Pr->PanelYRes;
  3042. } else if(SiS_Pr->ChipType < SIS_315H) {
  3043. #ifdef CONFIG_FB_SIS_300
  3044. /* Stupid hack for 640x400/320x200 */
  3045. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  3046. if((tempax + tempbx) == 438) tempbx += 16;
  3047. } else if((SiS_Pr->SiS_LCDResInfo == Panel_800x600) ||
  3048. (SiS_Pr->SiS_LCDResInfo == Panel_1024x600)) {
  3049. tempax = 0;
  3050. tempbx = SiS_Pr->SiS_VGAVT;
  3051. }
  3052. #endif
  3053. }
  3054. SiS_Pr->CVTotal = SiS_Pr->CVBlankEnd = tempbx + tempax;
  3055. tempax = SiS_Pr->SiS_VGAVDE;
  3056. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  3057. tempax += (SiS_Pr->PanelYRes - tempax) >> 1;
  3058. }
  3059. tempax += SiS_Pr->PanelVRS;
  3060. SiS_Pr->CVSyncStart = tempax;
  3061. tempax += SiS_Pr->PanelVRE;
  3062. SiS_Pr->CVSyncEnd = tempax;
  3063. if(SiS_Pr->ChipType < SIS_315H) {
  3064. SiS_Pr->CVSyncStart--;
  3065. SiS_Pr->CVSyncEnd--;
  3066. }
  3067. SiS_CalcCRRegisters(SiS_Pr, 8);
  3068. SiS_Pr->CCRT1CRTC[15] &= ~0xF8;
  3069. SiS_Pr->CCRT1CRTC[15] |= (remaining << 4);
  3070. SiS_Pr->CCRT1CRTC[16] &= ~0xE0;
  3071. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x11,0x7f);
  3072. for(i = 0, j = 0; i <= 7; i++, j++) {
  3073. SiS_SetReg(SiS_Pr->SiS_P3d4,j,SiS_Pr->CCRT1CRTC[i]);
  3074. }
  3075. for(j = 0x10; i <= 10; i++, j++) {
  3076. SiS_SetReg(SiS_Pr->SiS_P3d4,j,SiS_Pr->CCRT1CRTC[i]);
  3077. }
  3078. for(j = 0x15; i <= 12; i++, j++) {
  3079. SiS_SetReg(SiS_Pr->SiS_P3d4,j,SiS_Pr->CCRT1CRTC[i]);
  3080. }
  3081. for(j = 0x0A; i <= 15; i++, j++) {
  3082. SiS_SetReg(SiS_Pr->SiS_P3c4,j,SiS_Pr->CCRT1CRTC[i]);
  3083. }
  3084. tempax = SiS_Pr->CCRT1CRTC[16] & 0xE0;
  3085. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0E,0x1F,tempax);
  3086. tempax = (SiS_Pr->CCRT1CRTC[16] & 0x01) << 5;
  3087. if(modeflag & DoubleScanMode) tempax |= 0x80;
  3088. SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x09,0x5F,tempax);
  3089. }
  3090. void
  3091. SiS_Generic_ConvertCRData(struct SiS_Private *SiS_Pr, unsigned char *crdata,
  3092. int xres, int yres,
  3093. struct fb_var_screeninfo *var, bool writeres
  3094. )
  3095. {
  3096. unsigned short HRE, HBE, HRS, HBS, HDE, HT;
  3097. unsigned short VRE, VBE, VRS, VBS, VDE, VT;
  3098. unsigned char sr_data, cr_data, cr_data2;
  3099. int A, B, C, D, E, F, temp;
  3100. sr_data = crdata[14];
  3101. /* Horizontal total */
  3102. HT = crdata[0] | ((unsigned short)(sr_data & 0x03) << 8);
  3103. A = HT + 5;
  3104. /* Horizontal display enable end */
  3105. HDE = crdata[1] | ((unsigned short)(sr_data & 0x0C) << 6);
  3106. E = HDE + 1;
  3107. /* Horizontal retrace (=sync) start */
  3108. HRS = crdata[4] | ((unsigned short)(sr_data & 0xC0) << 2);
  3109. F = HRS - E - 3;
  3110. /* Horizontal blank start */
  3111. HBS = crdata[2] | ((unsigned short)(sr_data & 0x30) << 4);
  3112. sr_data = crdata[15];
  3113. cr_data = crdata[5];
  3114. /* Horizontal blank end */
  3115. HBE = (crdata[3] & 0x1f) |
  3116. ((unsigned short)(cr_data & 0x80) >> 2) |
  3117. ((unsigned short)(sr_data & 0x03) << 6);
  3118. /* Horizontal retrace (=sync) end */
  3119. HRE = (cr_data & 0x1f) | ((sr_data & 0x04) << 3);
  3120. temp = HBE - ((E - 1) & 255);
  3121. B = (temp > 0) ? temp : (temp + 256);
  3122. temp = HRE - ((E + F + 3) & 63);
  3123. C = (temp > 0) ? temp : (temp + 64);
  3124. D = B - F - C;
  3125. if(writeres) var->xres = xres = E * 8;
  3126. var->left_margin = D * 8;
  3127. var->right_margin = F * 8;
  3128. var->hsync_len = C * 8;
  3129. /* Vertical */
  3130. sr_data = crdata[13];
  3131. cr_data = crdata[7];
  3132. /* Vertical total */
  3133. VT = crdata[6] |
  3134. ((unsigned short)(cr_data & 0x01) << 8) |
  3135. ((unsigned short)(cr_data & 0x20) << 4) |
  3136. ((unsigned short)(sr_data & 0x01) << 10);
  3137. A = VT + 2;
  3138. /* Vertical display enable end */
  3139. VDE = crdata[10] |
  3140. ((unsigned short)(cr_data & 0x02) << 7) |
  3141. ((unsigned short)(cr_data & 0x40) << 3) |
  3142. ((unsigned short)(sr_data & 0x02) << 9);
  3143. E = VDE + 1;
  3144. /* Vertical retrace (=sync) start */
  3145. VRS = crdata[8] |
  3146. ((unsigned short)(cr_data & 0x04) << 6) |
  3147. ((unsigned short)(cr_data & 0x80) << 2) |
  3148. ((unsigned short)(sr_data & 0x08) << 7);
  3149. F = VRS + 1 - E;
  3150. cr_data2 = (crdata[16] & 0x01) << 5;
  3151. /* Vertical blank start */
  3152. VBS = crdata[11] |
  3153. ((unsigned short)(cr_data & 0x08) << 5) |
  3154. ((unsigned short)(cr_data2 & 0x20) << 4) |
  3155. ((unsigned short)(sr_data & 0x04) << 8);
  3156. /* Vertical blank end */
  3157. VBE = crdata[12] | ((unsigned short)(sr_data & 0x10) << 4);
  3158. temp = VBE - ((E - 1) & 511);
  3159. B = (temp > 0) ? temp : (temp + 512);
  3160. /* Vertical retrace (=sync) end */
  3161. VRE = (crdata[9] & 0x0f) | ((sr_data & 0x20) >> 1);
  3162. temp = VRE - ((E + F - 1) & 31);
  3163. C = (temp > 0) ? temp : (temp + 32);
  3164. D = B - F - C;
  3165. if(writeres) var->yres = yres = E;
  3166. var->upper_margin = D;
  3167. var->lower_margin = F;
  3168. var->vsync_len = C;
  3169. if((xres == 320) && ((yres == 200) || (yres == 240))) {
  3170. /* Terrible hack, but correct CRTC data for
  3171. * these modes only produces a black screen...
  3172. * (HRE is 0, leading into a too large C and
  3173. * a negative D. The CRT controller does not
  3174. * seem to like correcting HRE to 50)
  3175. */
  3176. var->left_margin = (400 - 376);
  3177. var->right_margin = (328 - 320);
  3178. var->hsync_len = (376 - 328);
  3179. }
  3180. }