init.c 122 KB

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