init301.c 382 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240
  1. /* $XFree86$ */
  2. /* $XdotOrg$ */
  3. /*
  4. * Mode initializing code (CRT2 section)
  5. * for SiS 300/305/540/630/730 and
  6. * SiS 315/550/650/M650/651/661FX/M661xX/740/741(GX)/M741/330/660/M660/760/M760
  7. * (Universal module for Linux kernel framebuffer and XFree86/X.org 4.x)
  8. *
  9. * Copyright (C) 2001-2004 by Thomas Winischhofer, Vienna, Austria
  10. *
  11. * If distributed as part of the Linux kernel, the following license terms
  12. * apply:
  13. *
  14. * * This program is free software; you can redistribute it and/or modify
  15. * * it under the terms of the GNU General Public License as published by
  16. * * the Free Software Foundation; either version 2 of the named License,
  17. * * or any later version.
  18. * *
  19. * * This program is distributed in the hope that it will be useful,
  20. * * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * * GNU General Public License for more details.
  23. * *
  24. * * You should have received a copy of the GNU General Public License
  25. * * along with this program; if not, write to the Free Software
  26. * * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
  27. *
  28. * Otherwise, the following license terms apply:
  29. *
  30. * * Redistribution and use in source and binary forms, with or without
  31. * * modification, are permitted provided that the following conditions
  32. * * are met:
  33. * * 1) Redistributions of source code must retain the above copyright
  34. * * notice, this list of conditions and the following disclaimer.
  35. * * 2) Redistributions in binary form must reproduce the above copyright
  36. * * notice, this list of conditions and the following disclaimer in the
  37. * * documentation and/or other materials provided with the distribution.
  38. * * 3) The name of the author may not be used to endorse or promote products
  39. * * derived from this software without specific prior written permission.
  40. * *
  41. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESSED OR
  42. * * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  43. * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  44. * * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  45. * * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  46. * * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  47. * * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  48. * * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  49. * * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  50. * * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  51. *
  52. * Author: Thomas Winischhofer <thomas@winischhofer.net>
  53. *
  54. * Formerly based on non-functional code-fragements for 300 series by SiS, Inc.
  55. * Used by permission.
  56. *
  57. * TW says: This code looks awful, I know. But please don't do anything about
  58. * this otherwise debugging will be hell.
  59. * The code is extremely fragile as regards the different chipsets, different
  60. * video bridges and combinations thereof. If anything is changed, extreme
  61. * care has to be taken that that change doesn't break it for other chipsets,
  62. * bridges or combinations thereof.
  63. * All comments in this file are by me, regardless if marked TW or not.
  64. *
  65. */
  66. #if 1
  67. #define SET_EMI /* 302LV/ELV: Set EMI values */
  68. #endif
  69. #define COMPAL_HACK /* Needed for Compal 1400x1050 (EMI) */
  70. #define COMPAQ_HACK /* Needed for Inventec/Compaq 1280x1024 (EMI) */
  71. #define ASUS_HACK /* Needed for Asus A2H 1024x768 (EMI) */
  72. #include "init301.h"
  73. #ifdef SIS300
  74. #include "oem300.h"
  75. #endif
  76. #ifdef SIS315H
  77. #include "oem310.h"
  78. #endif
  79. #define SiS_I2CDELAY 1000
  80. #define SiS_I2CDELAYSHORT 150
  81. static USHORT SiS_GetBIOSLCDResInfo(SiS_Private *SiS_Pr);
  82. static void SiS_SetCH70xx(SiS_Private *SiS_Pr, USHORT tempbx);
  83. /*********************************************/
  84. /* HELPER: Lock/Unlock CRT2 */
  85. /*********************************************/
  86. void
  87. SiS_UnLockCRT2(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
  88. {
  89. if(HwInfo->jChipType >= SIS_315H)
  90. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2f,0x01);
  91. else
  92. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x24,0x01);
  93. }
  94. static void
  95. SiS_LockCRT2(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
  96. {
  97. if(HwInfo->jChipType >= SIS_315H)
  98. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2F,0xFE);
  99. else
  100. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x24,0xFE);
  101. }
  102. /*********************************************/
  103. /* HELPER: Write SR11 */
  104. /*********************************************/
  105. static void
  106. SiS_SetRegSR11ANDOR(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT DataAND, USHORT DataOR)
  107. {
  108. if(HwInfo->jChipType >= SIS_661) {
  109. DataAND &= 0x0f;
  110. DataOR &= 0x0f;
  111. }
  112. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x11,DataAND,DataOR);
  113. }
  114. /*********************************************/
  115. /* HELPER: Get Pointer to LCD structure */
  116. /*********************************************/
  117. #ifdef SIS315H
  118. static UCHAR *
  119. GetLCDStructPtr661(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
  120. {
  121. UCHAR *ROMAddr = HwInfo->pjVirtualRomBase;
  122. UCHAR *myptr = NULL;
  123. USHORT romindex = 0, reg = 0, idx = 0;
  124. /* Use the BIOS tables only for LVDS panels; TMDS is unreliable
  125. * due to the variaty of panels the BIOS doesn't know about.
  126. * Exception: If the BIOS has better knowledge (such as in case
  127. * of machines with a 301C and a panel that does not support DDC)
  128. * use the BIOS data as well.
  129. */
  130. if((SiS_Pr->SiS_ROMNew) &&
  131. ((SiS_Pr->SiS_VBType & VB_SIS301LV302LV) || (!SiS_Pr->PanelSelfDetected))) {
  132. if(HwInfo->jChipType < SIS_661) reg = 0x3c;
  133. else reg = 0x7d;
  134. idx = (SiS_GetReg(SiS_Pr->SiS_P3d4,reg) & 0x1f) * 26;
  135. if(idx < (8*26)) {
  136. myptr = (UCHAR *)&SiS_LCDStruct661[idx];
  137. }
  138. romindex = SISGETROMW(0x100);
  139. if(romindex) {
  140. romindex += idx;
  141. myptr = &ROMAddr[romindex];
  142. }
  143. }
  144. return myptr;
  145. }
  146. static USHORT
  147. GetLCDStructPtr661_2(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
  148. {
  149. UCHAR *ROMAddr = HwInfo->pjVirtualRomBase;
  150. USHORT romptr = 0;
  151. /* Use the BIOS tables only for LVDS panels; TMDS is unreliable
  152. * due to the variaty of panels the BIOS doesn't know about.
  153. * Exception: If the BIOS has better knowledge (such as in case
  154. * of machines with a 301C and a panel that does not support DDC)
  155. * use the BIOS data as well.
  156. */
  157. if((SiS_Pr->SiS_ROMNew) &&
  158. ((SiS_Pr->SiS_VBType & VB_SIS301LV302LV) || (!SiS_Pr->PanelSelfDetected))) {
  159. romptr = SISGETROMW(0x102);
  160. romptr += ((SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4) * SiS_Pr->SiS661LCD2TableSize);
  161. }
  162. return(romptr);
  163. }
  164. #endif
  165. /*********************************************/
  166. /* Adjust Rate for CRT2 */
  167. /*********************************************/
  168. static BOOLEAN
  169. SiS_AdjustCRT2Rate(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
  170. USHORT RRTI, USHORT *i, PSIS_HW_INFO HwInfo)
  171. {
  172. USHORT checkmask=0,modeid,infoflag;
  173. modeid = SiS_Pr->SiS_RefIndex[RRTI + (*i)].ModeID;
  174. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  175. if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) {
  176. checkmask |= SupportRAMDAC2;
  177. if(HwInfo->jChipType >= SIS_315H) {
  178. checkmask |= SupportRAMDAC2_135;
  179. if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
  180. checkmask |= SupportRAMDAC2_162;
  181. if(SiS_Pr->SiS_VBType & VB_SIS301C) {
  182. checkmask |= SupportRAMDAC2_202;
  183. }
  184. }
  185. }
  186. } else if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  187. checkmask |= SupportLCD;
  188. if(HwInfo->jChipType >= SIS_315H) {
  189. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  190. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  191. if(modeid == 0x2e) checkmask |= Support64048060Hz;
  192. }
  193. }
  194. }
  195. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  196. checkmask |= SupportHiVision;
  197. } else if(SiS_Pr->SiS_VBInfo & (SetCRT2ToYPbPr525750|SetCRT2ToAVIDEO|SetCRT2ToSVIDEO|SetCRT2ToSCART)) {
  198. checkmask |= SupportTV;
  199. if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
  200. checkmask |= SupportTV1024;
  201. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  202. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) {
  203. checkmask |= SupportYPbPr750p;
  204. }
  205. }
  206. }
  207. }
  208. } else { /* LVDS */
  209. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  210. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  211. checkmask |= SupportCHTV;
  212. }
  213. }
  214. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  215. checkmask |= SupportLCD;
  216. }
  217. }
  218. /* Look backwards in table for matching CRT2 mode */
  219. for(; SiS_Pr->SiS_RefIndex[RRTI + (*i)].ModeID == modeid; (*i)--) {
  220. infoflag = SiS_Pr->SiS_RefIndex[RRTI + (*i)].Ext_InfoFlag;
  221. if(infoflag & checkmask) return TRUE;
  222. if((*i) == 0) break;
  223. }
  224. /* Look through the whole mode-section of the table from the beginning
  225. * for a matching CRT2 mode if no mode was found yet.
  226. */
  227. for((*i) = 0; ; (*i)++) {
  228. if(SiS_Pr->SiS_RefIndex[RRTI + (*i)].ModeID != modeid) break;
  229. infoflag = SiS_Pr->SiS_RefIndex[RRTI + (*i)].Ext_InfoFlag;
  230. if(infoflag & checkmask) return TRUE;
  231. }
  232. return FALSE;
  233. }
  234. /*********************************************/
  235. /* Get rate index */
  236. /*********************************************/
  237. USHORT
  238. SiS_GetRatePtr(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
  239. PSIS_HW_INFO HwInfo)
  240. {
  241. SHORT LCDRefreshIndex[] = { 0x00, 0x00, 0x01, 0x01,
  242. 0x01, 0x01, 0x01, 0x01,
  243. 0x01, 0x01, 0x01, 0x01,
  244. 0x01, 0x01, 0x01, 0x01,
  245. 0x00, 0x00, 0x00, 0x00 };
  246. USHORT RRTI,i,backup_i;
  247. USHORT modeflag,index,temp,backupindex;
  248. /* Do NOT check for UseCustomMode here, will skrew up FIFO */
  249. if(ModeNo == 0xfe) return 0;
  250. if(ModeNo <= 0x13) {
  251. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  252. } else {
  253. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  254. }
  255. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  256. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  257. if(modeflag & HalfDCLK) return 0;
  258. }
  259. }
  260. if(ModeNo < 0x14) return 0xFFFF;
  261. index = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x33) >> SiS_Pr->SiS_SelectCRT2Rate) & 0x0F;
  262. backupindex = index;
  263. if(index > 0) index--;
  264. if(SiS_Pr->SiS_SetFlag & ProgrammingCRT2) {
  265. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  266. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  267. if(SiS_Pr->SiS_VBType & VB_NoLCD) index = 0;
  268. else if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) index = backupindex = 0;
  269. }
  270. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  271. if(!(SiS_Pr->SiS_VBType & VB_NoLCD)) {
  272. temp = LCDRefreshIndex[SiS_GetBIOSLCDResInfo(SiS_Pr)];
  273. if(index > temp) index = temp;
  274. }
  275. }
  276. } else {
  277. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) index = 0;
  278. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  279. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) index = 0;
  280. }
  281. }
  282. }
  283. RRTI = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].REFindex;
  284. ModeNo = SiS_Pr->SiS_RefIndex[RRTI].ModeID;
  285. if(HwInfo->jChipType >= SIS_315H) {
  286. if(!(SiS_Pr->SiS_VBInfo & DriverMode)) {
  287. if( (SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_VESAID == 0x105) ||
  288. (SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_VESAID == 0x107) ) {
  289. if(backupindex <= 1) RRTI++;
  290. }
  291. }
  292. }
  293. i = 0;
  294. do {
  295. if(SiS_Pr->SiS_RefIndex[RRTI + i].ModeID != ModeNo) break;
  296. temp = SiS_Pr->SiS_RefIndex[RRTI + i].Ext_InfoFlag;
  297. temp &= ModeTypeMask;
  298. if(temp < SiS_Pr->SiS_ModeType) break;
  299. i++;
  300. index--;
  301. } while(index != 0xFFFF);
  302. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) {
  303. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  304. temp = SiS_Pr->SiS_RefIndex[RRTI + i - 1].Ext_InfoFlag;
  305. if(temp & InterlaceMode) i++;
  306. }
  307. }
  308. i--;
  309. if((SiS_Pr->SiS_SetFlag & ProgrammingCRT2) && (!(SiS_Pr->SiS_VBInfo & DisableCRT2Display))) {
  310. backup_i = i;
  311. if(!(SiS_AdjustCRT2Rate(SiS_Pr, ModeNo, ModeIdIndex, RRTI, &i, HwInfo))) {
  312. i = backup_i;
  313. }
  314. }
  315. return(RRTI + i);
  316. }
  317. /*********************************************/
  318. /* STORE CRT2 INFO in CR34 */
  319. /*********************************************/
  320. static void
  321. SiS_SaveCRT2Info(SiS_Private *SiS_Pr, USHORT ModeNo)
  322. {
  323. USHORT temp1,temp2;
  324. /* Store CRT1 ModeNo in CR34 */
  325. SiS_SetReg(SiS_Pr->SiS_P3d4,0x34,ModeNo);
  326. temp1 = (SiS_Pr->SiS_VBInfo & SetInSlaveMode) >> 8;
  327. temp2 = ~(SetInSlaveMode >> 8);
  328. SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x31,temp2,temp1);
  329. }
  330. /*********************************************/
  331. /* HELPER: GET SOME DATA FROM BIOS ROM */
  332. /*********************************************/
  333. #ifdef SIS300
  334. static BOOLEAN
  335. SiS_CR36BIOSWord23b(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
  336. {
  337. UCHAR *ROMAddr = HwInfo->pjVirtualRomBase;
  338. USHORT temp,temp1;
  339. if(SiS_Pr->SiS_UseROM) {
  340. if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) {
  341. temp = 1 << ((SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4) & 0x0f);
  342. temp1 = SISGETROMW(0x23b);
  343. if(temp1 & temp) return TRUE;
  344. }
  345. }
  346. return FALSE;
  347. }
  348. static BOOLEAN
  349. SiS_CR36BIOSWord23d(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
  350. {
  351. UCHAR *ROMAddr = HwInfo->pjVirtualRomBase;
  352. USHORT temp,temp1;
  353. if(SiS_Pr->SiS_UseROM) {
  354. if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) {
  355. temp = 1 << ((SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4) & 0x0f);
  356. temp1 = SISGETROMW(0x23d);
  357. if(temp1 & temp) return TRUE;
  358. }
  359. }
  360. return FALSE;
  361. }
  362. #endif
  363. /*********************************************/
  364. /* HELPER: DELAY FUNCTIONS */
  365. /*********************************************/
  366. void
  367. SiS_DDC2Delay(SiS_Private *SiS_Pr, USHORT delaytime)
  368. {
  369. USHORT i, j;
  370. for(i=0; i<delaytime; i++) {
  371. j += SiS_GetReg(SiS_Pr->SiS_P3c4,0x05);
  372. }
  373. }
  374. #if defined(SIS300) || defined(SIS315H)
  375. static void
  376. SiS_GenericDelay(SiS_Private *SiS_Pr, USHORT delay)
  377. {
  378. USHORT temp,flag;
  379. flag = SiS_GetRegByte(0x61) & 0x10;
  380. while(delay) {
  381. temp = SiS_GetRegByte(0x61) & 0x10;
  382. if(temp == flag) continue;
  383. flag = temp;
  384. delay--;
  385. }
  386. }
  387. #endif
  388. #ifdef SIS315H
  389. static void
  390. SiS_LongDelay(SiS_Private *SiS_Pr, USHORT delay)
  391. {
  392. while(delay--) {
  393. SiS_GenericDelay(SiS_Pr,0x19df);
  394. }
  395. }
  396. #endif
  397. #if defined(SIS300) || defined(SIS315H)
  398. static void
  399. SiS_ShortDelay(SiS_Private *SiS_Pr, USHORT delay)
  400. {
  401. while(delay--) {
  402. SiS_GenericDelay(SiS_Pr,0x42);
  403. }
  404. }
  405. #endif
  406. static void
  407. SiS_PanelDelay(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT DelayTime)
  408. {
  409. #if defined(SIS300) || defined(SIS315H)
  410. UCHAR *ROMAddr = HwInfo->pjVirtualRomBase;
  411. USHORT PanelID, DelayIndex, Delay=0;
  412. #endif
  413. if(HwInfo->jChipType < SIS_315H) {
  414. #ifdef SIS300
  415. PanelID = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36);
  416. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  417. if(SiS_Pr->SiS_VBType & VB_SIS301) PanelID &= 0xf7;
  418. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x18) & 0x10)) PanelID = 0x12;
  419. }
  420. DelayIndex = PanelID >> 4;
  421. if((DelayTime >= 2) && ((PanelID & 0x0f) == 1)) {
  422. Delay = 3;
  423. } else {
  424. if(DelayTime >= 2) DelayTime -= 2;
  425. if(!(DelayTime & 0x01)) {
  426. Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[0];
  427. } else {
  428. Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[1];
  429. }
  430. if(SiS_Pr->SiS_UseROM) {
  431. if(ROMAddr[0x220] & 0x40) {
  432. if(!(DelayTime & 0x01)) Delay = (USHORT)ROMAddr[0x225];
  433. else Delay = (USHORT)ROMAddr[0x226];
  434. }
  435. }
  436. }
  437. SiS_ShortDelay(SiS_Pr, Delay);
  438. #endif /* SIS300 */
  439. } else {
  440. #ifdef SIS315H
  441. if((HwInfo->jChipType >= SIS_661) ||
  442. (HwInfo->jChipType <= SIS_315PRO) ||
  443. (HwInfo->jChipType == SIS_330) ||
  444. (SiS_Pr->SiS_ROMNew)) {
  445. if(!(DelayTime & 0x01)) {
  446. SiS_DDC2Delay(SiS_Pr, 0x1000);
  447. } else {
  448. SiS_DDC2Delay(SiS_Pr, 0x4000);
  449. }
  450. } else if((SiS_Pr->SiS_IF_DEF_LVDS == 1) /* ||
  451. (SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) ||
  452. (SiS_Pr->SiS_CustomT == CUT_CLEVO1400) */ ) { /* 315 series, LVDS; Special */
  453. if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
  454. PanelID = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36);
  455. if(SiS_Pr->SiS_CustomT == CUT_CLEVO1400) {
  456. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x1b) & 0x10)) PanelID = 0x12;
  457. }
  458. if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) {
  459. DelayIndex = PanelID & 0x0f;
  460. } else {
  461. DelayIndex = PanelID >> 4;
  462. }
  463. if((DelayTime >= 2) && ((PanelID & 0x0f) == 1)) {
  464. Delay = 3;
  465. } else {
  466. if(DelayTime >= 2) DelayTime -= 2;
  467. if(!(DelayTime & 0x01)) {
  468. Delay = SiS_Pr->SiS_PanelDelayTblLVDS[DelayIndex].timer[0];
  469. } else {
  470. Delay = SiS_Pr->SiS_PanelDelayTblLVDS[DelayIndex].timer[1];
  471. }
  472. if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
  473. if(ROMAddr[0x13c] & 0x40) {
  474. if(!(DelayTime & 0x01)) {
  475. Delay = (USHORT)ROMAddr[0x17e];
  476. } else {
  477. Delay = (USHORT)ROMAddr[0x17f];
  478. }
  479. }
  480. }
  481. }
  482. SiS_ShortDelay(SiS_Pr, Delay);
  483. }
  484. } else if(SiS_Pr->SiS_VBType & VB_SISVB) { /* 315 series, all bridges */
  485. DelayIndex = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4;
  486. if(!(DelayTime & 0x01)) {
  487. Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[0];
  488. } else {
  489. Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[1];
  490. }
  491. Delay <<= 8;
  492. SiS_DDC2Delay(SiS_Pr, Delay);
  493. }
  494. #endif /* SIS315H */
  495. }
  496. }
  497. #ifdef SIS315H
  498. static void
  499. SiS_PanelDelayLoop(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
  500. USHORT DelayTime, USHORT DelayLoop)
  501. {
  502. int i;
  503. for(i=0; i<DelayLoop; i++) {
  504. SiS_PanelDelay(SiS_Pr, HwInfo, DelayTime);
  505. }
  506. }
  507. #endif
  508. /*********************************************/
  509. /* HELPER: WAIT-FOR-RETRACE FUNCTIONS */
  510. /*********************************************/
  511. void
  512. SiS_WaitRetrace1(SiS_Private *SiS_Pr)
  513. {
  514. USHORT watchdog;
  515. if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x1f) & 0xc0) return;
  516. if(!(SiS_GetReg(SiS_Pr->SiS_P3d4,0x17) & 0x80)) return;
  517. watchdog = 65535;
  518. while((SiS_GetRegByte(SiS_Pr->SiS_P3da) & 0x08) && --watchdog);
  519. watchdog = 65535;
  520. while((!(SiS_GetRegByte(SiS_Pr->SiS_P3da) & 0x08)) && --watchdog);
  521. }
  522. #if defined(SIS300) || defined(SIS315H)
  523. static void
  524. SiS_WaitRetrace2(SiS_Private *SiS_Pr, USHORT reg)
  525. {
  526. USHORT watchdog;
  527. watchdog = 65535;
  528. while((SiS_GetReg(SiS_Pr->SiS_Part1Port,reg) & 0x02) && --watchdog);
  529. watchdog = 65535;
  530. while((!(SiS_GetReg(SiS_Pr->SiS_Part1Port,reg) & 0x02)) && --watchdog);
  531. }
  532. #endif
  533. static void
  534. SiS_WaitVBRetrace(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
  535. {
  536. if(HwInfo->jChipType < SIS_315H) {
  537. #ifdef SIS300
  538. if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
  539. if(!(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x20)) return;
  540. }
  541. if(!(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x80)) {
  542. SiS_WaitRetrace1(SiS_Pr);
  543. } else {
  544. SiS_WaitRetrace2(SiS_Pr, 0x25);
  545. }
  546. #endif
  547. } else {
  548. #ifdef SIS315H
  549. if(!(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x40)) {
  550. SiS_WaitRetrace1(SiS_Pr);
  551. } else {
  552. SiS_WaitRetrace2(SiS_Pr, 0x30);
  553. }
  554. #endif
  555. }
  556. }
  557. static void
  558. SiS_VBWait(SiS_Private *SiS_Pr)
  559. {
  560. USHORT tempal,temp,i,j;
  561. temp = 0;
  562. for(i=0; i<3; i++) {
  563. for(j=0; j<100; j++) {
  564. tempal = SiS_GetRegByte(SiS_Pr->SiS_P3da);
  565. if(temp & 0x01) {
  566. if((tempal & 0x08)) continue;
  567. else break;
  568. } else {
  569. if(!(tempal & 0x08)) continue;
  570. else break;
  571. }
  572. }
  573. temp ^= 0x01;
  574. }
  575. }
  576. static void
  577. SiS_VBLongWait(SiS_Private *SiS_Pr)
  578. {
  579. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  580. SiS_VBWait(SiS_Pr);
  581. } else {
  582. SiS_WaitRetrace1(SiS_Pr);
  583. }
  584. }
  585. /*********************************************/
  586. /* HELPER: MISC */
  587. /*********************************************/
  588. #ifdef SIS300
  589. static BOOLEAN
  590. SiS_Is301B(SiS_Private *SiS_Pr)
  591. {
  592. if(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x01) >= 0xb0) return TRUE;
  593. return FALSE;
  594. }
  595. #endif
  596. static BOOLEAN
  597. SiS_CRT2IsLCD(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
  598. {
  599. USHORT flag;
  600. if(HwInfo->jChipType == SIS_730) {
  601. flag = SiS_GetReg(SiS_Pr->SiS_P3c4,0x13);
  602. if(flag & 0x20) return TRUE;
  603. }
  604. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  605. if(flag & 0x20) return TRUE;
  606. return FALSE;
  607. }
  608. BOOLEAN
  609. SiS_IsDualEdge(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
  610. {
  611. #ifdef SIS315H
  612. USHORT flag;
  613. if(HwInfo->jChipType >= SIS_315H) {
  614. if((HwInfo->jChipType != SIS_650) || (SiS_GetReg(SiS_Pr->SiS_P3d4,0x5f) & 0xf0)) {
  615. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  616. if(flag & EnableDualEdge) return TRUE;
  617. }
  618. }
  619. #endif
  620. return FALSE;
  621. }
  622. BOOLEAN
  623. SiS_IsVAMode(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
  624. {
  625. #ifdef SIS315H
  626. USHORT flag;
  627. if(HwInfo->jChipType >= SIS_315H) {
  628. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  629. if((flag & EnableDualEdge) && (flag & SetToLCDA)) return TRUE;
  630. }
  631. #endif
  632. return FALSE;
  633. }
  634. #ifdef SIS315H
  635. static BOOLEAN
  636. SiS_IsVAorLCD(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
  637. {
  638. if(SiS_IsVAMode(SiS_Pr,HwInfo)) return TRUE;
  639. if(SiS_CRT2IsLCD(SiS_Pr, HwInfo)) return TRUE;
  640. return FALSE;
  641. }
  642. #endif
  643. static BOOLEAN
  644. SiS_IsDualLink(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
  645. {
  646. #ifdef SIS315H
  647. if(HwInfo->jChipType >= SIS_315H) {
  648. if((SiS_CRT2IsLCD(SiS_Pr, HwInfo)) ||
  649. (SiS_IsVAMode(SiS_Pr, HwInfo))) {
  650. if(SiS_Pr->SiS_LCDInfo & LCDDualLink) return TRUE;
  651. }
  652. }
  653. #endif
  654. return FALSE;
  655. }
  656. #ifdef SIS315H
  657. static BOOLEAN
  658. SiS_TVEnabled(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
  659. {
  660. if((SiS_GetReg(SiS_Pr->SiS_Part2Port,0x00) & 0x0f) != 0x0c) return TRUE;
  661. if(SiS_Pr->SiS_VBType & (VB_SIS301C | VB_SIS301LV302LV)) {
  662. if(SiS_GetReg(SiS_Pr->SiS_Part2Port,0x4d) & 0x10) return TRUE;
  663. }
  664. return FALSE;
  665. }
  666. #endif
  667. #ifdef SIS315H
  668. static BOOLEAN
  669. SiS_LCDAEnabled(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
  670. {
  671. if(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x13) & 0x04) return TRUE;
  672. return FALSE;
  673. }
  674. #endif
  675. #ifdef SIS315H
  676. static BOOLEAN
  677. SiS_WeHaveBacklightCtrl(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
  678. {
  679. if((HwInfo->jChipType >= SIS_315H) && (HwInfo->jChipType < SIS_661)) {
  680. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x79) & 0x10) return TRUE;
  681. }
  682. return FALSE;
  683. }
  684. #endif
  685. #ifdef SIS315H
  686. static BOOLEAN
  687. SiS_IsNotM650orLater(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
  688. {
  689. USHORT flag;
  690. if(HwInfo->jChipType == SIS_650) {
  691. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x5f);
  692. flag &= 0xF0;
  693. /* Check for revision != A0 only */
  694. if((flag == 0xe0) || (flag == 0xc0) ||
  695. (flag == 0xb0) || (flag == 0x90)) return FALSE;
  696. } else if(HwInfo->jChipType >= SIS_661) return FALSE;
  697. return TRUE;
  698. }
  699. #endif
  700. #ifdef SIS315H
  701. static BOOLEAN
  702. SiS_IsYPbPr(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
  703. {
  704. USHORT flag;
  705. if(HwInfo->jChipType >= SIS_315H) {
  706. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  707. if(flag & EnableCHYPbPr) return TRUE; /* = YPrPb = 0x08 */
  708. }
  709. return FALSE;
  710. }
  711. #endif
  712. #ifdef SIS315H
  713. static BOOLEAN
  714. SiS_IsChScart(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
  715. {
  716. USHORT flag;
  717. if(HwInfo->jChipType >= SIS_315H) {
  718. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  719. if(flag & EnableCHScart) return TRUE; /* = Scart = 0x04 */
  720. }
  721. return FALSE;
  722. }
  723. #endif
  724. #ifdef SIS315H
  725. static BOOLEAN
  726. SiS_IsTVOrYPbPrOrScart(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
  727. {
  728. USHORT flag;
  729. if(HwInfo->jChipType >= SIS_315H) {
  730. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  731. if(flag & SetCRT2ToTV) return TRUE;
  732. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  733. if(flag & EnableCHYPbPr) return TRUE; /* = YPrPb = 0x08 */
  734. if(flag & EnableCHScart) return TRUE; /* = Scart = 0x04 - TW */
  735. } else {
  736. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  737. if(flag & SetCRT2ToTV) return TRUE;
  738. }
  739. return FALSE;
  740. }
  741. #endif
  742. #ifdef SIS315H
  743. static BOOLEAN
  744. SiS_IsLCDOrLCDA(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
  745. {
  746. USHORT flag;
  747. if(HwInfo->jChipType >= SIS_315H) {
  748. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  749. if(flag & SetCRT2ToLCD) return TRUE;
  750. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  751. if(flag & SetToLCDA) return TRUE;
  752. } else {
  753. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  754. if(flag & SetCRT2ToLCD) return TRUE;
  755. }
  756. return FALSE;
  757. }
  758. #endif
  759. static BOOLEAN
  760. SiS_BridgeIsOn(SiS_Private *SiS_Pr)
  761. {
  762. USHORT flag;
  763. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  764. return TRUE;
  765. } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
  766. flag = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x00);
  767. if((flag == 1) || (flag == 2)) return TRUE;
  768. }
  769. return FALSE;
  770. }
  771. static BOOLEAN
  772. SiS_BridgeIsEnabled(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
  773. {
  774. USHORT flag;
  775. if(SiS_BridgeIsOn(SiS_Pr)) {
  776. flag = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00);
  777. if(HwInfo->jChipType < SIS_315H) {
  778. flag &= 0xa0;
  779. if((flag == 0x80) || (flag == 0x20)) return TRUE;
  780. } else {
  781. flag &= 0x50;
  782. if((flag == 0x40) || (flag == 0x10)) return TRUE;
  783. }
  784. }
  785. return FALSE;
  786. }
  787. static BOOLEAN
  788. SiS_BridgeInSlavemode(SiS_Private *SiS_Pr)
  789. {
  790. USHORT flag1;
  791. flag1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x31);
  792. if(flag1 & (SetInSlaveMode >> 8)) return TRUE;
  793. return FALSE;
  794. }
  795. /*********************************************/
  796. /* GET VIDEO BRIDGE CONFIG INFO */
  797. /*********************************************/
  798. /* Setup general purpose IO for Chrontel communication */
  799. void
  800. SiS_SetChrontelGPIO(SiS_Private *SiS_Pr, USHORT myvbinfo)
  801. {
  802. unsigned long acpibase;
  803. unsigned short temp;
  804. if(!(SiS_Pr->SiS_ChSW)) return;
  805. #ifdef LINUX_KERNEL
  806. SiS_SetRegLong(0xcf8,0x80000874); /* get ACPI base */
  807. acpibase = SiS_GetRegLong(0xcfc);
  808. #else
  809. acpibase = pciReadLong(0x00000800, 0x74);
  810. #endif
  811. acpibase &= 0xFFFF;
  812. temp = SiS_GetRegShort((USHORT)(acpibase + 0x3c)); /* ACPI register 0x3c: GP Event 1 I/O mode select */
  813. temp &= 0xFEFF;
  814. SiS_SetRegShort((USHORT)(acpibase + 0x3c), temp);
  815. temp = SiS_GetRegShort((USHORT)(acpibase + 0x3c));
  816. temp = SiS_GetRegShort((USHORT)(acpibase + 0x3a)); /* ACPI register 0x3a: GP Pin Level (low/high) */
  817. temp &= 0xFEFF;
  818. if(!(myvbinfo & SetCRT2ToTV)) temp |= 0x0100;
  819. SiS_SetRegShort((USHORT)(acpibase + 0x3a), temp);
  820. temp = SiS_GetRegShort((USHORT)(acpibase + 0x3a));
  821. }
  822. void
  823. SiS_GetVBInfo(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
  824. PSIS_HW_INFO HwInfo, int checkcrt2mode)
  825. {
  826. USHORT tempax,tempbx,temp;
  827. USHORT modeflag, resinfo=0;
  828. if(ModeNo <= 0x13) {
  829. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  830. } else if(SiS_Pr->UseCustomMode) {
  831. modeflag = SiS_Pr->CModeFlag;
  832. } else {
  833. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  834. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  835. }
  836. SiS_Pr->SiS_SetFlag = 0;
  837. SiS_Pr->SiS_ModeType = modeflag & ModeTypeMask;
  838. tempbx = 0;
  839. if(SiS_BridgeIsOn(SiS_Pr)) {
  840. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  841. #if 0
  842. if(HwInfo->jChipType < SIS_661) {
  843. /* NO - YPbPr not set yet ! */
  844. if(SiS_Pr->SiS_YPbPr & <all ypbpr except 525i>) {
  845. temp &= (SetCRT2ToHiVision | SwitchCRT2 | SetSimuScanMode); /* 0x83 */
  846. temp |= SetCRT2ToHiVision; /* 0x80 */
  847. }
  848. if(SiS_Pr->SiS_YPbPr & <ypbpr525i>) {
  849. temp &= (SetCRT2ToHiVision | SwitchCRT2 | SetSimuScanMode); /* 0x83 */
  850. temp |= SetCRT2ToSVIDEO; /* 0x08 */
  851. }
  852. }
  853. #endif
  854. tempbx |= temp;
  855. tempax = SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) << 8;
  856. tempax &= (DriverMode | LoadDACFlag | SetNotSimuMode | SetPALTV);
  857. tempbx |= tempax;
  858. #ifdef SIS315H
  859. if(HwInfo->jChipType >= SIS_315H) {
  860. if(SiS_Pr->SiS_VBType & VB_SISLCDA) {
  861. if(ModeNo == 0x03) {
  862. /* Mode 0x03 is never in driver mode */
  863. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x31,0xbf);
  864. }
  865. if(!(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & (DriverMode >> 8))) {
  866. /* Reset LCDA setting if not driver mode */
  867. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x38,0xfc);
  868. }
  869. if(IS_SIS650) {
  870. if(SiS_Pr->SiS_UseLCDA) {
  871. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x5f) & 0xF0) {
  872. if((ModeNo <= 0x13) || (!(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & (DriverMode >> 8)))) {
  873. SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x38,(EnableDualEdge | SetToLCDA));
  874. }
  875. }
  876. }
  877. }
  878. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  879. if((temp & (EnableDualEdge | SetToLCDA)) == (EnableDualEdge | SetToLCDA)) {
  880. tempbx |= SetCRT2ToLCDA;
  881. }
  882. }
  883. if(SiS_Pr->SiS_VBType & (VB_SIS301LV|VB_SIS302LV|VB_SIS302ELV)) {
  884. tempbx &= ~(SetCRT2ToRAMDAC);
  885. }
  886. if(HwInfo->jChipType >= SIS_661) {
  887. tempbx &= ~(SetCRT2ToYPbPr525750 | SetCRT2ToHiVision);
  888. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  889. if(SiS_Pr->SiS_VBType & VB_SISYPBPR) {
  890. if(temp & 0x04) {
  891. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35) & 0xe0;
  892. if(temp == 0x60) tempbx |= SetCRT2ToHiVision;
  893. else tempbx |= SetCRT2ToYPbPr525750;
  894. }
  895. } else if(SiS_Pr->SiS_VBType & VB_SISHIVISION) {
  896. if(temp & 0x04) {
  897. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35) & 0xe0;
  898. if(temp == 0x60) tempbx |= SetCRT2ToHiVision;
  899. }
  900. }
  901. }
  902. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  903. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  904. if(temp & SetToLCDA) {
  905. tempbx |= SetCRT2ToLCDA;
  906. }
  907. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  908. if(temp & EnableCHYPbPr) {
  909. tempbx |= SetCRT2ToCHYPbPr;
  910. }
  911. }
  912. }
  913. }
  914. #endif /* SIS315H */
  915. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  916. temp = SetCRT2ToSVIDEO |
  917. SetCRT2ToAVIDEO |
  918. SetCRT2ToSCART |
  919. SetCRT2ToLCDA |
  920. SetCRT2ToLCD |
  921. SetCRT2ToRAMDAC |
  922. SetCRT2ToHiVision |
  923. SetCRT2ToYPbPr525750;
  924. } else {
  925. if(HwInfo->jChipType >= SIS_315H) {
  926. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  927. temp = SetCRT2ToAVIDEO |
  928. SetCRT2ToSVIDEO |
  929. SetCRT2ToSCART |
  930. SetCRT2ToLCDA |
  931. SetCRT2ToLCD |
  932. SetCRT2ToCHYPbPr;
  933. } else {
  934. temp = SetCRT2ToLCDA |
  935. SetCRT2ToLCD;
  936. }
  937. } else {
  938. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  939. temp = SetCRT2ToTV | SetCRT2ToLCD;
  940. } else {
  941. temp = SetCRT2ToLCD;
  942. }
  943. }
  944. }
  945. if(!(tempbx & temp)) {
  946. tempax = DisableCRT2Display;
  947. tempbx = 0;
  948. }
  949. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  950. USHORT clearmask = ( DriverMode |
  951. DisableCRT2Display |
  952. LoadDACFlag |
  953. SetNotSimuMode |
  954. SetInSlaveMode |
  955. SetPALTV |
  956. SwitchCRT2 |
  957. SetSimuScanMode );
  958. if(tempbx & SetCRT2ToLCDA) tempbx &= (clearmask | SetCRT2ToLCDA);
  959. if(tempbx & SetCRT2ToRAMDAC) tempbx &= (clearmask | SetCRT2ToRAMDAC);
  960. if(tempbx & SetCRT2ToLCD) tempbx &= (clearmask | SetCRT2ToLCD);
  961. if(tempbx & SetCRT2ToSCART) tempbx &= (clearmask | SetCRT2ToSCART);
  962. if(tempbx & SetCRT2ToHiVision) tempbx &= (clearmask | SetCRT2ToHiVision);
  963. if(tempbx & SetCRT2ToYPbPr525750) tempbx &= (clearmask | SetCRT2ToYPbPr525750);
  964. } else {
  965. if(HwInfo->jChipType >= SIS_315H) {
  966. if(tempbx & SetCRT2ToLCDA) {
  967. tempbx &= (0xFF00|SwitchCRT2|SetSimuScanMode);
  968. }
  969. }
  970. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  971. if(tempbx & SetCRT2ToTV) {
  972. tempbx &= (0xFF00|SetCRT2ToTV|SwitchCRT2|SetSimuScanMode);
  973. }
  974. }
  975. if(tempbx & SetCRT2ToLCD) {
  976. tempbx &= (0xFF00|SetCRT2ToLCD|SwitchCRT2|SetSimuScanMode);
  977. }
  978. if(HwInfo->jChipType >= SIS_315H) {
  979. if(tempbx & SetCRT2ToLCDA) {
  980. tempbx |= SetCRT2ToLCD;
  981. }
  982. }
  983. }
  984. if(tempax & DisableCRT2Display) {
  985. if(!(tempbx & (SwitchCRT2 | SetSimuScanMode))) {
  986. tempbx = SetSimuScanMode | DisableCRT2Display;
  987. }
  988. }
  989. if(!(tempbx & DriverMode)) tempbx |= SetSimuScanMode;
  990. /* LVDS/CHRONTEL (LCD/TV) and 301BDH (LCD) can only be slave in 8bpp modes */
  991. if(SiS_Pr->SiS_ModeType <= ModeVGA) {
  992. if( (SiS_Pr->SiS_IF_DEF_LVDS == 1) ||
  993. ((SiS_Pr->SiS_VBType & VB_NoLCD) && (tempbx & SetCRT2ToLCD)) ) {
  994. modeflag &= (~CRT2Mode);
  995. }
  996. }
  997. if(!(tempbx & SetSimuScanMode)) {
  998. if(tempbx & SwitchCRT2) {
  999. if((!(modeflag & CRT2Mode)) && (checkcrt2mode)) {
  1000. if( (HwInfo->jChipType >= SIS_315H) &&
  1001. (SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) ) {
  1002. if(resinfo != SIS_RI_1600x1200) {
  1003. tempbx |= SetSimuScanMode;
  1004. }
  1005. } else {
  1006. tempbx |= SetSimuScanMode;
  1007. }
  1008. }
  1009. } else {
  1010. if(SiS_BridgeIsEnabled(SiS_Pr,HwInfo)) {
  1011. if(!(tempbx & DriverMode)) {
  1012. if(SiS_BridgeInSlavemode(SiS_Pr)) {
  1013. tempbx |= SetSimuScanMode;
  1014. }
  1015. }
  1016. }
  1017. }
  1018. }
  1019. if(!(tempbx & DisableCRT2Display)) {
  1020. if(tempbx & DriverMode) {
  1021. if(tempbx & SetSimuScanMode) {
  1022. if((!(modeflag & CRT2Mode)) && (checkcrt2mode)) {
  1023. if( (HwInfo->jChipType >= SIS_315H) &&
  1024. (SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) ) {
  1025. if(resinfo != SIS_RI_1600x1200) {
  1026. tempbx |= SetInSlaveMode;
  1027. }
  1028. } else {
  1029. tempbx |= SetInSlaveMode;
  1030. }
  1031. }
  1032. }
  1033. } else {
  1034. tempbx |= SetInSlaveMode;
  1035. }
  1036. }
  1037. }
  1038. SiS_Pr->SiS_VBInfo = tempbx;
  1039. if(HwInfo->jChipType == SIS_630) {
  1040. SiS_SetChrontelGPIO(SiS_Pr, SiS_Pr->SiS_VBInfo);
  1041. }
  1042. #ifdef TWDEBUG
  1043. #ifdef LINUX_KERNEL
  1044. printk(KERN_DEBUG "sisfb: (VBInfo= 0x%04x, SetFlag=0x%04x)\n",
  1045. SiS_Pr->SiS_VBInfo, SiS_Pr->SiS_SetFlag);
  1046. #endif
  1047. #ifdef LINUX_XF86
  1048. xf86DrvMsgVerb(0, X_PROBED, 3, "(init301: VBInfo=0x%04x, SetFlag=0x%04x)\n",
  1049. SiS_Pr->SiS_VBInfo, SiS_Pr->SiS_SetFlag);
  1050. #endif
  1051. #endif
  1052. }
  1053. /*********************************************/
  1054. /* DETERMINE YPbPr MODE */
  1055. /*********************************************/
  1056. void
  1057. SiS_SetYPbPr(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
  1058. {
  1059. UCHAR temp;
  1060. /* Note: This variable is only used on 30xLV systems.
  1061. * CR38 has a different meaning on LVDS/CH7019 systems.
  1062. * On 661 and later, these bits moved to CR35.
  1063. *
  1064. * On 301, 301B, only HiVision 1080i is supported.
  1065. * On 30xLV, 301C, only YPbPr 1080i is supported.
  1066. */
  1067. SiS_Pr->SiS_YPbPr = 0;
  1068. if(HwInfo->jChipType >= SIS_661) return;
  1069. if(SiS_Pr->SiS_VBType) {
  1070. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  1071. SiS_Pr->SiS_YPbPr = YPbPrHiVision;
  1072. }
  1073. }
  1074. if(HwInfo->jChipType >= SIS_315H) {
  1075. if(SiS_Pr->SiS_VBType & (VB_SIS301LV302LV | VB_SIS301C)) {
  1076. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  1077. if(temp & 0x08) {
  1078. switch((temp >> 4)) {
  1079. case 0x00: SiS_Pr->SiS_YPbPr = YPbPr525i; break;
  1080. case 0x01: SiS_Pr->SiS_YPbPr = YPbPr525p; break;
  1081. case 0x02: SiS_Pr->SiS_YPbPr = YPbPr750p; break;
  1082. case 0x03: SiS_Pr->SiS_YPbPr = YPbPrHiVision; break;
  1083. }
  1084. }
  1085. }
  1086. }
  1087. }
  1088. /*********************************************/
  1089. /* DETERMINE TVMode flag */
  1090. /*********************************************/
  1091. void
  1092. SiS_SetTVMode(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex, PSIS_HW_INFO HwInfo)
  1093. {
  1094. UCHAR *ROMAddr = HwInfo->pjVirtualRomBase;
  1095. USHORT temp, temp1, resinfo = 0, romindex = 0;
  1096. UCHAR OutputSelect = *SiS_Pr->pSiS_OutputSelect;
  1097. SiS_Pr->SiS_TVMode = 0;
  1098. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) return;
  1099. if(SiS_Pr->UseCustomMode) return;
  1100. if(ModeNo > 0x13) {
  1101. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  1102. }
  1103. if(HwInfo->jChipType < SIS_661) {
  1104. if(SiS_Pr->SiS_VBInfo & SetPALTV) SiS_Pr->SiS_TVMode |= TVSetPAL;
  1105. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  1106. temp = 0;
  1107. if((HwInfo->jChipType == SIS_630) ||
  1108. (HwInfo->jChipType == SIS_730)) {
  1109. temp = 0x35;
  1110. romindex = 0xfe;
  1111. } else if(HwInfo->jChipType >= SIS_315H) {
  1112. temp = 0x38;
  1113. romindex = 0xf3;
  1114. if(HwInfo->jChipType >= SIS_330) romindex = 0x11b;
  1115. }
  1116. if(temp) {
  1117. if(romindex && SiS_Pr->SiS_UseROM && (!(SiS_Pr->SiS_ROMNew))) {
  1118. OutputSelect = ROMAddr[romindex];
  1119. if(!(OutputSelect & EnablePALMN)) {
  1120. SiS_SetRegAND(SiS_Pr->SiS_P3d4,temp,0x3F);
  1121. }
  1122. }
  1123. temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,temp);
  1124. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  1125. if(temp1 & EnablePALM) { /* 0x40 */
  1126. SiS_Pr->SiS_TVMode |= TVSetPALM;
  1127. SiS_Pr->SiS_TVMode &= ~TVSetPAL;
  1128. } else if(temp1 & EnablePALN) { /* 0x80 */
  1129. SiS_Pr->SiS_TVMode |= TVSetPALN;
  1130. }
  1131. } else {
  1132. if(temp1 & EnableNTSCJ) { /* 0x40 */
  1133. SiS_Pr->SiS_TVMode |= TVSetNTSCJ;
  1134. }
  1135. }
  1136. }
  1137. /* Translate HiVision/YPbPr to our new flags */
  1138. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  1139. if(SiS_Pr->SiS_YPbPr == YPbPr750p) SiS_Pr->SiS_TVMode |= TVSetYPbPr750p;
  1140. else if(SiS_Pr->SiS_YPbPr == YPbPr525p) SiS_Pr->SiS_TVMode |= TVSetYPbPr525p;
  1141. else if(SiS_Pr->SiS_YPbPr == YPbPrHiVision) SiS_Pr->SiS_TVMode |= TVSetHiVision;
  1142. else SiS_Pr->SiS_TVMode |= TVSetYPbPr525i;
  1143. if(SiS_Pr->SiS_TVMode & (TVSetYPbPr750p | TVSetYPbPr525p | TVSetYPbPr525i)) {
  1144. SiS_Pr->SiS_VBInfo &= ~SetCRT2ToHiVision;
  1145. SiS_Pr->SiS_VBInfo |= SetCRT2ToYPbPr525750;
  1146. } else if(SiS_Pr->SiS_TVMode & TVSetHiVision) {
  1147. SiS_Pr->SiS_TVMode |= TVSetPAL;
  1148. }
  1149. }
  1150. } else if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  1151. if(SiS_Pr->SiS_CHOverScan) {
  1152. if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) {
  1153. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35);
  1154. if((temp & TVOverScan) || (SiS_Pr->SiS_CHOverScan == 1)) {
  1155. SiS_Pr->SiS_TVMode |= TVSetCHOverScan;
  1156. }
  1157. } else if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  1158. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x79);
  1159. if((temp & 0x80) || (SiS_Pr->SiS_CHOverScan == 1)) {
  1160. SiS_Pr->SiS_TVMode |= TVSetCHOverScan;
  1161. }
  1162. }
  1163. if(SiS_Pr->SiS_CHSOverScan) {
  1164. SiS_Pr->SiS_TVMode |= TVSetCHOverScan;
  1165. }
  1166. }
  1167. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  1168. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  1169. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  1170. if(temp & EnablePALM) SiS_Pr->SiS_TVMode |= TVSetPALM;
  1171. else if(temp & EnablePALN) SiS_Pr->SiS_TVMode |= TVSetPALN;
  1172. } else {
  1173. if(temp & EnableNTSCJ) {
  1174. SiS_Pr->SiS_TVMode |= TVSetNTSCJ;
  1175. }
  1176. }
  1177. }
  1178. }
  1179. } else { /* 661 and later */
  1180. temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35);
  1181. if(temp1 & 0x01) {
  1182. SiS_Pr->SiS_TVMode |= TVSetPAL;
  1183. if(temp1 & 0x08) {
  1184. SiS_Pr->SiS_TVMode |= TVSetPALN;
  1185. } else if(temp1 & 0x04) {
  1186. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  1187. SiS_Pr->SiS_TVMode &= ~TVSetPAL;
  1188. }
  1189. SiS_Pr->SiS_TVMode |= TVSetPALM;
  1190. }
  1191. } else {
  1192. if(temp1 & 0x02) {
  1193. SiS_Pr->SiS_TVMode |= TVSetNTSCJ;
  1194. }
  1195. }
  1196. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  1197. if(SiS_Pr->SiS_CHOverScan) {
  1198. if((temp1 & 0x10) || (SiS_Pr->SiS_CHOverScan == 1)) {
  1199. SiS_Pr->SiS_TVMode |= TVSetCHOverScan;
  1200. }
  1201. }
  1202. }
  1203. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  1204. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  1205. temp1 &= 0xe0;
  1206. if(temp1 == 0x00) SiS_Pr->SiS_TVMode |= TVSetYPbPr525i;
  1207. else if(temp1 == 0x20) SiS_Pr->SiS_TVMode |= TVSetYPbPr525p;
  1208. else if(temp1 == 0x40) SiS_Pr->SiS_TVMode |= TVSetYPbPr750p;
  1209. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  1210. SiS_Pr->SiS_TVMode |= (TVSetHiVision | TVSetPAL);
  1211. }
  1212. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToYPbPr525750 | SetCRT2ToHiVision)) {
  1213. if(resinfo == SIS_RI_800x480 || resinfo == SIS_RI_1024x576 || resinfo == SIS_RI_1280x720) {
  1214. SiS_Pr->SiS_TVMode |= TVAspect169;
  1215. } else {
  1216. temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x39);
  1217. if(temp1 & 0x02) {
  1218. if(SiS_Pr->SiS_TVMode & (TVSetYPbPr750p | TVSetHiVision)) {
  1219. SiS_Pr->SiS_TVMode |= TVAspect169;
  1220. } else {
  1221. SiS_Pr->SiS_TVMode |= TVAspect43LB;
  1222. }
  1223. } else {
  1224. SiS_Pr->SiS_TVMode |= TVAspect43;
  1225. }
  1226. }
  1227. }
  1228. }
  1229. }
  1230. if(SiS_Pr->SiS_VBInfo & SetCRT2ToSCART) SiS_Pr->SiS_TVMode |= TVSetPAL;
  1231. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  1232. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  1233. SiS_Pr->SiS_TVMode |= TVSetPAL;
  1234. SiS_Pr->SiS_TVMode &= ~(TVSetPALM | TVSetPALN | TVSetNTSCJ);
  1235. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  1236. if(SiS_Pr->SiS_TVMode & (TVSetYPbPr525i | TVSetYPbPr525p | TVSetYPbPr750p)) {
  1237. SiS_Pr->SiS_TVMode &= ~(TVSetPAL | TVSetNTSCJ | TVSetPALM | TVSetPALN);
  1238. }
  1239. }
  1240. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  1241. if(!(SiS_Pr->SiS_VBInfo & SetNotSimuMode)) {
  1242. SiS_Pr->SiS_TVMode |= TVSetTVSimuMode;
  1243. }
  1244. }
  1245. if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) {
  1246. /* BIOS sets TVNTSC1024 without checking 525p here. Wrong? */
  1247. if(!(SiS_Pr->SiS_TVMode & (TVSetHiVision | TVSetYPbPr525p | TVSetYPbPr750p))) {
  1248. if(resinfo == SIS_RI_1024x768) {
  1249. SiS_Pr->SiS_TVMode |= TVSetNTSC1024;
  1250. }
  1251. }
  1252. }
  1253. SiS_Pr->SiS_TVMode |= TVRPLLDIV2XO;
  1254. if((SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) &&
  1255. (SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  1256. SiS_Pr->SiS_TVMode &= ~TVRPLLDIV2XO;
  1257. } else if(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p)) {
  1258. SiS_Pr->SiS_TVMode &= ~TVRPLLDIV2XO;
  1259. } else if(!(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV)) {
  1260. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) {
  1261. SiS_Pr->SiS_TVMode &= ~TVRPLLDIV2XO;
  1262. }
  1263. }
  1264. }
  1265. SiS_Pr->SiS_VBInfo &= ~SetPALTV;
  1266. #ifdef TWDEBUG
  1267. xf86DrvMsg(0, X_INFO, "(init301: TVMode %x, VBInfo %x)\n", SiS_Pr->SiS_TVMode, SiS_Pr->SiS_VBInfo);
  1268. #endif
  1269. }
  1270. /*********************************************/
  1271. /* GET LCD INFO */
  1272. /*********************************************/
  1273. static USHORT
  1274. SiS_GetBIOSLCDResInfo(SiS_Private *SiS_Pr)
  1275. {
  1276. USHORT temp = SiS_Pr->SiS_LCDResInfo;
  1277. /* Translate my LCDResInfo to BIOS value */
  1278. if(temp == Panel_1280x768_2) temp = Panel_1280x768;
  1279. if(temp == Panel_1280x800_2) temp = Panel_1280x800;
  1280. return temp;
  1281. }
  1282. static void
  1283. SiS_GetLCDInfoBIOS(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
  1284. {
  1285. #ifdef SIS315H
  1286. UCHAR *ROMAddr;
  1287. USHORT temp;
  1288. #ifdef TWDEBUG
  1289. xf86DrvMsg(0, X_INFO, "Paneldata driver: [%d %d] [H %d %d] [V %d %d] [C %d 0x%02x 0x%02x]\n",
  1290. SiS_Pr->PanelHT, SiS_Pr->PanelVT,
  1291. SiS_Pr->PanelHRS, SiS_Pr->PanelHRE,
  1292. SiS_Pr->PanelVRS, SiS_Pr->PanelVRE,
  1293. SiS_Pr->SiS_VBVCLKData[SiS_Pr->PanelVCLKIdx315].CLOCK,
  1294. SiS_Pr->SiS_VBVCLKData[SiS_Pr->PanelVCLKIdx315].Part4_A,
  1295. SiS_Pr->SiS_VBVCLKData[SiS_Pr->PanelVCLKIdx315].Part4_B);
  1296. #endif
  1297. if((ROMAddr = GetLCDStructPtr661(SiS_Pr, HwInfo))) {
  1298. if((temp = SISGETROMW(6)) != SiS_Pr->PanelHT) {
  1299. SiS_Pr->SiS_NeedRomModeData = TRUE;
  1300. SiS_Pr->PanelHT = temp;
  1301. }
  1302. if((temp = SISGETROMW(8)) != SiS_Pr->PanelVT) {
  1303. SiS_Pr->SiS_NeedRomModeData = TRUE;
  1304. SiS_Pr->PanelVT = temp;
  1305. }
  1306. SiS_Pr->PanelHRS = SISGETROMW(10);
  1307. SiS_Pr->PanelHRE = SISGETROMW(12);
  1308. SiS_Pr->PanelVRS = SISGETROMW(14);
  1309. SiS_Pr->PanelVRE = SISGETROMW(16);
  1310. SiS_Pr->PanelVCLKIdx315 = VCLK_CUSTOM_315;
  1311. SiS_Pr->SiS_VCLKData[VCLK_CUSTOM_315].CLOCK =
  1312. SiS_Pr->SiS_VBVCLKData[VCLK_CUSTOM_315].CLOCK = (USHORT)((UCHAR)ROMAddr[18]);
  1313. SiS_Pr->SiS_VCLKData[VCLK_CUSTOM_315].SR2B =
  1314. SiS_Pr->SiS_VBVCLKData[VCLK_CUSTOM_315].Part4_A = ROMAddr[19];
  1315. SiS_Pr->SiS_VCLKData[VCLK_CUSTOM_315].SR2C =
  1316. SiS_Pr->SiS_VBVCLKData[VCLK_CUSTOM_315].Part4_B = ROMAddr[20];
  1317. #ifdef TWDEBUG
  1318. xf86DrvMsg(0, X_INFO, "Paneldata BIOS: [%d %d] [H %d %d] [V %d %d] [C %d 0x%02x 0x%02x]\n",
  1319. SiS_Pr->PanelHT, SiS_Pr->PanelVT,
  1320. SiS_Pr->PanelHRS, SiS_Pr->PanelHRE,
  1321. SiS_Pr->PanelVRS, SiS_Pr->PanelVRE,
  1322. SiS_Pr->SiS_VBVCLKData[SiS_Pr->PanelVCLKIdx315].CLOCK,
  1323. SiS_Pr->SiS_VBVCLKData[SiS_Pr->PanelVCLKIdx315].Part4_A,
  1324. SiS_Pr->SiS_VBVCLKData[SiS_Pr->PanelVCLKIdx315].Part4_B);
  1325. #endif
  1326. }
  1327. #endif
  1328. }
  1329. static void
  1330. SiS_CheckScaling(SiS_Private *SiS_Pr, USHORT resinfo, const UCHAR *nonscalingmodes)
  1331. {
  1332. int i = 0;
  1333. while(nonscalingmodes[i] != 0xff) {
  1334. if(nonscalingmodes[i++] == resinfo) {
  1335. if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) ||
  1336. (SiS_Pr->UsePanelScaler == -1)) {
  1337. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1338. }
  1339. break;
  1340. }
  1341. }
  1342. }
  1343. void
  1344. SiS_GetLCDResInfo(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
  1345. PSIS_HW_INFO HwInfo)
  1346. {
  1347. #ifdef SIS300
  1348. UCHAR *ROMAddr = HwInfo->pjVirtualRomBase;
  1349. const unsigned char SiS300SeriesLCDRes[] =
  1350. { 0, 1, 2, 3, 7, 4, 5, 8,
  1351. 0, 0, 10, 0, 0, 0, 0, 15 };
  1352. #endif
  1353. #ifdef SIS315H
  1354. UCHAR *myptr = NULL;
  1355. #endif
  1356. USHORT temp,modeflag,resinfo=0,modexres=0,modeyres=0;
  1357. BOOLEAN panelcanscale = FALSE;
  1358. SiS_Pr->SiS_LCDResInfo = 0;
  1359. SiS_Pr->SiS_LCDTypeInfo = 0;
  1360. SiS_Pr->SiS_LCDInfo = 0;
  1361. SiS_Pr->PanelHRS = 999; /* HSync start */
  1362. SiS_Pr->PanelHRE = 999; /* HSync end */
  1363. SiS_Pr->PanelVRS = 999; /* VSync start */
  1364. SiS_Pr->PanelVRE = 999; /* VSync end */
  1365. SiS_Pr->SiS_NeedRomModeData = FALSE;
  1366. if(!(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA))) return;
  1367. if(ModeNo <= 0x13) {
  1368. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  1369. } else if(SiS_Pr->UseCustomMode) {
  1370. modeflag = SiS_Pr->CModeFlag;
  1371. } else {
  1372. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  1373. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  1374. modexres = SiS_Pr->SiS_ModeResInfo[resinfo].HTotal;
  1375. modeyres = SiS_Pr->SiS_ModeResInfo[resinfo].VTotal;
  1376. }
  1377. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36);
  1378. /* For broken BIOSes: Assume 1024x768 */
  1379. if(temp == 0) temp = 0x02;
  1380. if((HwInfo->jChipType >= SIS_661) || (SiS_Pr->SiS_ROMNew)) {
  1381. SiS_Pr->SiS_LCDTypeInfo = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x39) & 0x7c) >> 2;
  1382. } else if((HwInfo->jChipType < SIS_315H) || (HwInfo->jChipType >= SIS_661)) {
  1383. SiS_Pr->SiS_LCDTypeInfo = temp >> 4;
  1384. } else {
  1385. SiS_Pr->SiS_LCDTypeInfo = (temp & 0x0F) - 1;
  1386. }
  1387. temp &= 0x0f;
  1388. #ifdef SIS300
  1389. if(HwInfo->jChipType < SIS_315H) {
  1390. /* Very old BIOSes only know 7 sizes (NetVista 2179, 1.01g) */
  1391. if(SiS_Pr->SiS_VBType & VB_SIS301) {
  1392. if(temp < 0x0f) temp &= 0x07;
  1393. }
  1394. /* Translate 300 series LCDRes to 315 series for unified usage */
  1395. temp = SiS300SeriesLCDRes[temp];
  1396. }
  1397. #endif
  1398. /* Translate to our internal types */
  1399. if(HwInfo->jChipType == SIS_550) {
  1400. if(temp == Panel310_640x480_2) temp = Panel_640x480_2;
  1401. if(temp == Panel310_640x480_3) temp = Panel_640x480_3;
  1402. }
  1403. if(SiS_Pr->SiS_VBType & VB_SISLVDS) { /* SiS LVDS */
  1404. if(temp == Panel310_1280x768) {
  1405. temp = Panel_1280x768_2;
  1406. }
  1407. if(SiS_Pr->SiS_ROMNew) {
  1408. if(temp == Panel661_1280x800) {
  1409. temp = Panel_1280x800_2;
  1410. }
  1411. }
  1412. }
  1413. SiS_Pr->SiS_LCDResInfo = temp;
  1414. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  1415. if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) {
  1416. SiS_Pr->SiS_LCDResInfo = Panel_Barco1366;
  1417. } else if(SiS_Pr->SiS_CustomT == CUT_PANEL848) {
  1418. SiS_Pr->SiS_LCDResInfo = Panel_848x480;
  1419. }
  1420. }
  1421. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  1422. if(SiS_Pr->SiS_LCDResInfo < SiS_Pr->SiS_PanelMin301)
  1423. SiS_Pr->SiS_LCDResInfo = SiS_Pr->SiS_PanelMin301;
  1424. } else {
  1425. if(SiS_Pr->SiS_LCDResInfo < SiS_Pr->SiS_PanelMinLVDS)
  1426. SiS_Pr->SiS_LCDResInfo = SiS_Pr->SiS_PanelMinLVDS;
  1427. }
  1428. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x37);
  1429. SiS_Pr->SiS_LCDInfo = temp & ~0x000e;
  1430. /* Need temp below! */
  1431. /* These can't scale no matter what */
  1432. switch(SiS_Pr->SiS_LCDResInfo) {
  1433. case Panel_1280x960:
  1434. SiS_Pr->SiS_LCDInfo &= ~DontExpandLCD;
  1435. }
  1436. panelcanscale = (SiS_Pr->SiS_LCDInfo & DontExpandLCD) ? TRUE : FALSE;
  1437. if(!SiS_Pr->UsePanelScaler) SiS_Pr->SiS_LCDInfo &= ~DontExpandLCD;
  1438. else if(SiS_Pr->UsePanelScaler == 1) SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1439. /* Dual link, Pass 1:1 BIOS default, etc. */
  1440. #ifdef SIS315H
  1441. if(HwInfo->jChipType >= SIS_661) {
  1442. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  1443. if(temp & 0x08) SiS_Pr->SiS_LCDInfo |= LCDPass11;
  1444. }
  1445. if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV)) {
  1446. if(SiS_Pr->SiS_ROMNew) {
  1447. if(temp & 0x02) SiS_Pr->SiS_LCDInfo |= LCDDualLink;
  1448. } else if((myptr = GetLCDStructPtr661(SiS_Pr, HwInfo))) {
  1449. if(myptr[2] & 0x01) SiS_Pr->SiS_LCDInfo |= LCDDualLink;
  1450. }
  1451. }
  1452. } else if(HwInfo->jChipType >= SIS_315H) {
  1453. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  1454. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x39) & 0x01) SiS_Pr->SiS_LCDInfo |= LCDPass11;
  1455. }
  1456. if((SiS_Pr->SiS_ROMNew) && (!(SiS_Pr->PanelSelfDetected))) {
  1457. SiS_Pr->SiS_LCDInfo &= ~(LCDRGB18Bit);
  1458. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35);
  1459. if(temp & 0x01) SiS_Pr->SiS_LCDInfo |= LCDRGB18Bit;
  1460. if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV)) {
  1461. if(temp & 0x02) SiS_Pr->SiS_LCDInfo |= LCDDualLink;
  1462. }
  1463. } else if(!(SiS_Pr->SiS_ROMNew)) {
  1464. if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV)) {
  1465. if((SiS_Pr->SiS_CustomT == CUT_CLEVO1024) &&
  1466. (SiS_Pr->SiS_LCDResInfo == Panel_1024x768)) {
  1467. SiS_Pr->SiS_LCDInfo |= LCDDualLink;
  1468. }
  1469. if((SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) ||
  1470. (SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) ||
  1471. (SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) ||
  1472. (SiS_Pr->SiS_LCDResInfo == Panel_1680x1050)) {
  1473. SiS_Pr->SiS_LCDInfo |= LCDDualLink;
  1474. }
  1475. }
  1476. }
  1477. }
  1478. #endif
  1479. /* Pass 1:1 */
  1480. if((SiS_Pr->SiS_IF_DEF_LVDS == 1) || (SiS_Pr->SiS_VBType & VB_NoLCD)) {
  1481. /* Always center screen on LVDS (if scaling is disabled) */
  1482. SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  1483. } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
  1484. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  1485. /* Always center screen on SiS LVDS (if scaling is disabled) */
  1486. SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  1487. } else {
  1488. /* By default, pass 1:1 on SiS TMDS (if scaling is supported) */
  1489. if(panelcanscale) SiS_Pr->SiS_LCDInfo |= LCDPass11;
  1490. if(SiS_Pr->CenterScreen == 1) SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  1491. }
  1492. }
  1493. SiS_Pr->PanelVCLKIdx300 = VCLK65_300;
  1494. SiS_Pr->PanelVCLKIdx315 = VCLK108_2_315;
  1495. switch(SiS_Pr->SiS_LCDResInfo) {
  1496. case Panel_320x480: SiS_Pr->PanelXRes = 320; SiS_Pr->PanelYRes = 480;
  1497. SiS_Pr->PanelHT = 400; SiS_Pr->PanelVT = 525;
  1498. SiS_Pr->PanelVCLKIdx300 = VCLK28;
  1499. SiS_Pr->PanelVCLKIdx315 = VCLK28;
  1500. break;
  1501. case Panel_640x480_2:
  1502. case Panel_640x480_3: SiS_Pr->PanelXRes = 640; SiS_Pr->PanelYRes = 480;
  1503. SiS_Pr->PanelVRS = 24; SiS_Pr->PanelVRE = 3;
  1504. SiS_Pr->PanelVCLKIdx300 = VCLK28;
  1505. SiS_Pr->PanelVCLKIdx315 = VCLK28;
  1506. break;
  1507. case Panel_640x480: SiS_Pr->PanelXRes = 640; SiS_Pr->PanelYRes = 480;
  1508. SiS_Pr->PanelVRE = 3;
  1509. SiS_Pr->PanelVCLKIdx300 = VCLK28;
  1510. SiS_Pr->PanelVCLKIdx315 = VCLK28;
  1511. break;
  1512. case Panel_800x600: SiS_Pr->PanelXRes = 800; SiS_Pr->PanelYRes = 600;
  1513. SiS_Pr->PanelHT = 1056; SiS_Pr->PanelVT = 628;
  1514. SiS_Pr->PanelHRS = 40; SiS_Pr->PanelHRE = 128;
  1515. SiS_Pr->PanelVRS = 1; SiS_Pr->PanelVRE = 4;
  1516. SiS_Pr->PanelVCLKIdx300 = VCLK40;
  1517. SiS_Pr->PanelVCLKIdx315 = VCLK40;
  1518. break;
  1519. case Panel_1024x600: SiS_Pr->PanelXRes = 1024; SiS_Pr->PanelYRes = 600;
  1520. SiS_Pr->PanelHT = 1344; SiS_Pr->PanelVT = 800;
  1521. SiS_Pr->PanelHRS = 24; SiS_Pr->PanelHRE = 136;
  1522. SiS_Pr->PanelVRS = 2 /* 88 */ ; SiS_Pr->PanelVRE = 6;
  1523. SiS_Pr->PanelVCLKIdx300 = VCLK65_300;
  1524. SiS_Pr->PanelVCLKIdx315 = VCLK65_315;
  1525. break;
  1526. case Panel_1024x768: SiS_Pr->PanelXRes = 1024; SiS_Pr->PanelYRes = 768;
  1527. SiS_Pr->PanelHT = 1344; SiS_Pr->PanelVT = 806;
  1528. SiS_Pr->PanelHRS = 24; SiS_Pr->PanelHRE = 136;
  1529. SiS_Pr->PanelVRS = 3; SiS_Pr->PanelVRE = 6;
  1530. if(HwInfo->jChipType < SIS_315H) {
  1531. SiS_Pr->PanelHRS = 23;
  1532. SiS_Pr->PanelVRE = 5;
  1533. }
  1534. SiS_Pr->PanelVCLKIdx300 = VCLK65_300;
  1535. SiS_Pr->PanelVCLKIdx315 = VCLK65_315;
  1536. SiS_GetLCDInfoBIOS(SiS_Pr, HwInfo);
  1537. break;
  1538. case Panel_1152x768: SiS_Pr->PanelXRes = 1152; SiS_Pr->PanelYRes = 768;
  1539. SiS_Pr->PanelHT = 1344; SiS_Pr->PanelVT = 806;
  1540. SiS_Pr->PanelHRS = 24;
  1541. SiS_Pr->PanelVRS = 3; SiS_Pr->PanelVRE = 6;
  1542. if(HwInfo->jChipType < SIS_315H) {
  1543. SiS_Pr->PanelHRS = 23;
  1544. SiS_Pr->PanelVRE = 5;
  1545. }
  1546. SiS_Pr->PanelVCLKIdx300 = VCLK65_300;
  1547. SiS_Pr->PanelVCLKIdx315 = VCLK65_315;
  1548. break;
  1549. case Panel_1152x864: SiS_Pr->PanelXRes = 1152; SiS_Pr->PanelYRes = 864;
  1550. break;
  1551. case Panel_1280x720: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 720;
  1552. SiS_Pr->PanelHT = 1650; SiS_Pr->PanelVT = 750;
  1553. SiS_Pr->PanelHRS = 110; SiS_Pr->PanelHRE = 40;
  1554. SiS_Pr->PanelVRS = 5; SiS_Pr->PanelVRE = 5;
  1555. SiS_Pr->PanelVCLKIdx315 = VCLK_1280x720;
  1556. /* Data above for TMDS (projector); get from BIOS for LVDS */
  1557. SiS_GetLCDInfoBIOS(SiS_Pr, HwInfo);
  1558. break;
  1559. case Panel_1280x768: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 768;
  1560. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  1561. SiS_Pr->PanelHT = 1408; SiS_Pr->PanelVT = 806;
  1562. SiS_Pr->PanelVCLKIdx300 = VCLK81_300; /* ? */
  1563. SiS_Pr->PanelVCLKIdx315 = VCLK81_315; /* ? */
  1564. } else {
  1565. SiS_Pr->PanelHT = 1688; SiS_Pr->PanelVT = 802;
  1566. SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRS = 112;
  1567. SiS_Pr->PanelVRS = 3; SiS_Pr->PanelVRE = 6;
  1568. SiS_Pr->PanelVCLKIdx300 = VCLK81_300;
  1569. SiS_Pr->PanelVCLKIdx315 = VCLK81_315;
  1570. }
  1571. break;
  1572. case Panel_1280x768_2: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 768;
  1573. SiS_Pr->PanelHT = 1660; SiS_Pr->PanelVT = 806;
  1574. SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 112;
  1575. SiS_Pr->PanelVRS = 3; SiS_Pr->PanelVRE = 6;
  1576. SiS_Pr->PanelVCLKIdx315 = VCLK_1280x768_2;
  1577. SiS_GetLCDInfoBIOS(SiS_Pr, HwInfo);
  1578. break;
  1579. case Panel_1280x800: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 800;
  1580. SiS_Pr->PanelHT = 1408; SiS_Pr->PanelVT = 816;
  1581. SiS_Pr->PanelHRS = 21; SiS_Pr->PanelHRE = 24;
  1582. SiS_Pr->PanelVRS = 4; SiS_Pr->PanelVRE = 3;
  1583. SiS_Pr->PanelVCLKIdx315 = VCLK_1280x800_315;
  1584. SiS_GetLCDInfoBIOS(SiS_Pr, HwInfo);
  1585. break;
  1586. case Panel_1280x800_2: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 800;
  1587. SiS_Pr->PanelHT = 1552; SiS_Pr->PanelVT = 812;
  1588. SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 112;
  1589. SiS_Pr->PanelVRS = 4; SiS_Pr->PanelVRE = 3;
  1590. SiS_Pr->PanelVCLKIdx315 = VCLK_1280x800_315_2;
  1591. SiS_GetLCDInfoBIOS(SiS_Pr, HwInfo);
  1592. break;
  1593. case Panel_1280x960: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 960;
  1594. SiS_Pr->PanelHT = 1800; SiS_Pr->PanelVT = 1000;
  1595. SiS_Pr->PanelVCLKIdx300 = VCLK108_3_300;
  1596. SiS_Pr->PanelVCLKIdx315 = VCLK108_3_315;
  1597. if(resinfo == SIS_RI_1280x1024) {
  1598. SiS_Pr->PanelVCLKIdx300 = VCLK100_300;
  1599. SiS_Pr->PanelVCLKIdx315 = VCLK100_315;
  1600. }
  1601. break;
  1602. case Panel_1280x1024: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 1024;
  1603. SiS_Pr->PanelHT = 1688; SiS_Pr->PanelVT = 1066;
  1604. SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 112;
  1605. SiS_Pr->PanelVRS = 1; SiS_Pr->PanelVRE = 3;
  1606. SiS_Pr->PanelVCLKIdx300 = VCLK108_3_300;
  1607. SiS_Pr->PanelVCLKIdx315 = VCLK108_2_315;
  1608. SiS_GetLCDInfoBIOS(SiS_Pr, HwInfo);
  1609. break;
  1610. case Panel_1400x1050: SiS_Pr->PanelXRes = 1400; SiS_Pr->PanelYRes = 1050;
  1611. SiS_Pr->PanelHT = 1688; SiS_Pr->PanelVT = 1066;
  1612. SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 112; /* HRE OK for LVDS, not for LCDA */
  1613. SiS_Pr->PanelVRS = 1; SiS_Pr->PanelVRE = 3;
  1614. SiS_Pr->PanelVCLKIdx315 = VCLK108_2_315;
  1615. SiS_GetLCDInfoBIOS(SiS_Pr, HwInfo);
  1616. break;
  1617. case Panel_1600x1200: SiS_Pr->PanelXRes = 1600; SiS_Pr->PanelYRes = 1200;
  1618. SiS_Pr->PanelHT = 2160; SiS_Pr->PanelVT = 1250;
  1619. SiS_Pr->PanelHRS = 64; SiS_Pr->PanelHRE = 192;
  1620. SiS_Pr->PanelVRS = 1; SiS_Pr->PanelVRE = 3;
  1621. SiS_Pr->PanelVCLKIdx315 = VCLK162_315;
  1622. SiS_GetLCDInfoBIOS(SiS_Pr, HwInfo);
  1623. break;
  1624. case Panel_1680x1050: SiS_Pr->PanelXRes = 1680; SiS_Pr->PanelYRes = 1050;
  1625. SiS_Pr->PanelHT = 1900; SiS_Pr->PanelVT = 1066;
  1626. SiS_Pr->PanelHRS = 26; SiS_Pr->PanelHRE = 76;
  1627. SiS_Pr->PanelVRS = 3; SiS_Pr->PanelVRE = 6;
  1628. SiS_Pr->PanelVCLKIdx315 = VCLK121_315;
  1629. SiS_GetLCDInfoBIOS(SiS_Pr, HwInfo);
  1630. break;
  1631. case Panel_Barco1366: SiS_Pr->PanelXRes = 1360; SiS_Pr->PanelYRes = 1024;
  1632. SiS_Pr->PanelHT = 1688; SiS_Pr->PanelVT = 1066;
  1633. break;
  1634. case Panel_848x480: SiS_Pr->PanelXRes = 848; SiS_Pr->PanelYRes = 480;
  1635. SiS_Pr->PanelHT = 1088; SiS_Pr->PanelVT = 525;
  1636. break;
  1637. case Panel_Custom: SiS_Pr->PanelXRes = SiS_Pr->CP_MaxX;
  1638. SiS_Pr->PanelYRes = SiS_Pr->CP_MaxY;
  1639. SiS_Pr->PanelHT = SiS_Pr->CHTotal;
  1640. SiS_Pr->PanelVT = SiS_Pr->CVTotal;
  1641. if(SiS_Pr->CP_PreferredIndex != -1) {
  1642. SiS_Pr->PanelXRes = SiS_Pr->CP_HDisplay[SiS_Pr->CP_PreferredIndex];
  1643. SiS_Pr->PanelYRes = SiS_Pr->CP_VDisplay[SiS_Pr->CP_PreferredIndex];
  1644. SiS_Pr->PanelHT = SiS_Pr->CP_HTotal[SiS_Pr->CP_PreferredIndex];
  1645. SiS_Pr->PanelVT = SiS_Pr->CP_VTotal[SiS_Pr->CP_PreferredIndex];
  1646. SiS_Pr->PanelHRS = SiS_Pr->CP_HSyncStart[SiS_Pr->CP_PreferredIndex];
  1647. SiS_Pr->PanelHRE = SiS_Pr->CP_HSyncEnd[SiS_Pr->CP_PreferredIndex];
  1648. SiS_Pr->PanelVRS = SiS_Pr->CP_VSyncStart[SiS_Pr->CP_PreferredIndex];
  1649. SiS_Pr->PanelVRE = SiS_Pr->CP_VSyncEnd[SiS_Pr->CP_PreferredIndex];
  1650. SiS_Pr->PanelHRS -= SiS_Pr->PanelXRes;
  1651. SiS_Pr->PanelHRE -= SiS_Pr->PanelHRS;
  1652. SiS_Pr->PanelVRS -= SiS_Pr->PanelYRes;
  1653. SiS_Pr->PanelVRE -= SiS_Pr->PanelVRS;
  1654. if(SiS_Pr->CP_PrefClock) {
  1655. int idx;
  1656. SiS_Pr->PanelVCLKIdx315 = VCLK_CUSTOM_315;
  1657. SiS_Pr->PanelVCLKIdx300 = VCLK_CUSTOM_300;
  1658. if(HwInfo->jChipType < SIS_315H) idx = VCLK_CUSTOM_300;
  1659. else idx = VCLK_CUSTOM_315;
  1660. SiS_Pr->SiS_VCLKData[idx].CLOCK =
  1661. SiS_Pr->SiS_VBVCLKData[idx].CLOCK = SiS_Pr->CP_PrefClock;
  1662. SiS_Pr->SiS_VCLKData[idx].SR2B =
  1663. SiS_Pr->SiS_VBVCLKData[idx].Part4_A = SiS_Pr->CP_PrefSR2B;
  1664. SiS_Pr->SiS_VCLKData[idx].SR2C =
  1665. SiS_Pr->SiS_VBVCLKData[idx].Part4_B = SiS_Pr->CP_PrefSR2C;
  1666. }
  1667. }
  1668. break;
  1669. default: SiS_Pr->PanelXRes = 1024; SiS_Pr->PanelYRes = 768;
  1670. SiS_Pr->PanelHT = 1344; SiS_Pr->PanelVT = 806;
  1671. break;
  1672. }
  1673. /* Special cases */
  1674. if( (SiS_Pr->SiS_IF_DEF_FSTN) ||
  1675. (SiS_Pr->SiS_IF_DEF_DSTN) ||
  1676. (SiS_Pr->SiS_CustomT == CUT_BARCO1366) ||
  1677. (SiS_Pr->SiS_CustomT == CUT_BARCO1024) ||
  1678. (SiS_Pr->SiS_CustomT == CUT_PANEL848) ) {
  1679. SiS_Pr->PanelHRS = 999;
  1680. SiS_Pr->PanelHRE = 999;
  1681. }
  1682. if( (SiS_Pr->SiS_CustomT == CUT_BARCO1366) ||
  1683. (SiS_Pr->SiS_CustomT == CUT_BARCO1024) ||
  1684. (SiS_Pr->SiS_CustomT == CUT_PANEL848) ) {
  1685. SiS_Pr->PanelVRS = 999;
  1686. SiS_Pr->PanelVRE = 999;
  1687. }
  1688. /* DontExpand overrule */
  1689. if((SiS_Pr->SiS_VBType & VB_SISVB) && (!(SiS_Pr->SiS_VBType & VB_NoLCD))) {
  1690. if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && (modeflag & NoSupportLCDScale)) {
  1691. /* No scaling for this mode on any panel (LCD=CRT2)*/
  1692. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1693. }
  1694. switch(SiS_Pr->SiS_LCDResInfo) {
  1695. case Panel_Custom:
  1696. case Panel_1152x864:
  1697. case Panel_1280x768: /* TMDS only */
  1698. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1699. break;
  1700. case Panel_800x600: {
  1701. static const UCHAR nonscalingmodes[] = {
  1702. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, 0xff
  1703. };
  1704. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1705. break;
  1706. }
  1707. case Panel_1024x768: {
  1708. static const UCHAR nonscalingmodes[] = {
  1709. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1710. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1711. 0xff
  1712. };
  1713. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1714. break;
  1715. }
  1716. case Panel_1280x720: {
  1717. static const UCHAR nonscalingmodes[] = {
  1718. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1719. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1720. 0xff
  1721. };
  1722. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1723. if(SiS_Pr->PanelHT == 1650) {
  1724. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1725. }
  1726. break;
  1727. }
  1728. case Panel_1280x768_2: { /* LVDS only */
  1729. static const UCHAR nonscalingmodes[] = {
  1730. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1731. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1732. SIS_RI_1152x768,0xff
  1733. };
  1734. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1735. switch(resinfo) {
  1736. case SIS_RI_1280x720: if(SiS_Pr->UsePanelScaler == -1) {
  1737. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1738. }
  1739. break;
  1740. }
  1741. break;
  1742. }
  1743. case Panel_1280x800: { /* SiS TMDS special (Averatec 6200 series) */
  1744. static const UCHAR nonscalingmodes[] = {
  1745. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1746. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1747. SIS_RI_1152x768,SIS_RI_1280x720,SIS_RI_1280x768,0xff
  1748. };
  1749. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1750. break;
  1751. }
  1752. case Panel_1280x800_2: { /* SiS LVDS */
  1753. static const UCHAR nonscalingmodes[] = {
  1754. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1755. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1756. SIS_RI_1152x768,0xff
  1757. };
  1758. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1759. switch(resinfo) {
  1760. case SIS_RI_1280x720:
  1761. case SIS_RI_1280x768: if(SiS_Pr->UsePanelScaler == -1) {
  1762. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1763. }
  1764. break;
  1765. }
  1766. break;
  1767. }
  1768. case Panel_1280x960: {
  1769. static const UCHAR nonscalingmodes[] = {
  1770. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1771. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1772. SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x720,SIS_RI_1280x768,SIS_RI_1280x800,
  1773. 0xff
  1774. };
  1775. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1776. break;
  1777. }
  1778. case Panel_1280x1024: {
  1779. static const UCHAR nonscalingmodes[] = {
  1780. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1781. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1782. SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x720,SIS_RI_1280x768,SIS_RI_1280x800,
  1783. SIS_RI_1280x960,0xff
  1784. };
  1785. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1786. break;
  1787. }
  1788. case Panel_1400x1050: {
  1789. static const UCHAR nonscalingmodes[] = {
  1790. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1791. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1792. SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x768,SIS_RI_1280x800,SIS_RI_1280x960,
  1793. 0xff
  1794. };
  1795. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1796. switch(resinfo) {
  1797. case SIS_RI_1280x720: if(SiS_Pr->UsePanelScaler == -1) {
  1798. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1799. }
  1800. break;
  1801. case SIS_RI_1280x1024: SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1802. break;
  1803. }
  1804. break;
  1805. }
  1806. case Panel_1600x1200: {
  1807. static const UCHAR nonscalingmodes[] = {
  1808. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1809. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1810. SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x720,SIS_RI_1280x768,SIS_RI_1280x800,
  1811. SIS_RI_1280x960,SIS_RI_1360x768,SIS_RI_1360x1024,0xff
  1812. };
  1813. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1814. break;
  1815. }
  1816. case Panel_1680x1050: {
  1817. static const UCHAR nonscalingmodes[] = {
  1818. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1819. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1820. SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x960,SIS_RI_1360x768,SIS_RI_1360x1024,
  1821. 0xff
  1822. };
  1823. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1824. break;
  1825. }
  1826. }
  1827. }
  1828. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  1829. if(SiS_Pr->SiS_CustomT == CUT_PANEL848) {
  1830. SiS_Pr->SiS_LCDInfo = 0x80 | 0x40 | 0x20; /* neg h/v sync, RGB24(D0 = 0) */
  1831. }
  1832. }
  1833. #ifdef SIS300
  1834. if(HwInfo->jChipType < SIS_315H) {
  1835. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  1836. if(SiS_Pr->SiS_UseROM) {
  1837. if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) {
  1838. if(!(ROMAddr[0x235] & 0x02)) {
  1839. SiS_Pr->SiS_LCDInfo &= (~DontExpandLCD);
  1840. }
  1841. }
  1842. }
  1843. } else if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
  1844. if((SiS_Pr->SiS_SetFlag & SetDOSMode) && ((ModeNo == 0x03) || (ModeNo == 0x10))) {
  1845. SiS_Pr->SiS_LCDInfo &= (~DontExpandLCD);
  1846. }
  1847. }
  1848. }
  1849. #endif
  1850. /* Special cases */
  1851. if(modexres == SiS_Pr->PanelXRes && modeyres == SiS_Pr->PanelYRes) {
  1852. SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  1853. }
  1854. if(SiS_Pr->SiS_IF_DEF_TRUMPION) {
  1855. SiS_Pr->SiS_LCDInfo |= (DontExpandLCD | LCDPass11);
  1856. }
  1857. switch(SiS_Pr->SiS_LCDResInfo) {
  1858. case Panel_640x480:
  1859. SiS_Pr->SiS_LCDInfo |= LCDPass11;
  1860. break;
  1861. case Panel_1280x800:
  1862. /* Don't pass 1:1 by default (TMDS special) */
  1863. if(SiS_Pr->CenterScreen == -1) SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  1864. break;
  1865. case Panel_1280x960:
  1866. SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  1867. break;
  1868. case Panel_Custom:
  1869. if((!SiS_Pr->CP_PrefClock) ||
  1870. (modexres > SiS_Pr->PanelXRes) || (modeyres > SiS_Pr->PanelYRes)) {
  1871. SiS_Pr->SiS_LCDInfo |= LCDPass11;
  1872. }
  1873. break;
  1874. }
  1875. if(SiS_Pr->UseCustomMode) {
  1876. SiS_Pr->SiS_LCDInfo |= (DontExpandLCD | LCDPass11);
  1877. }
  1878. /* (In)validate LCDPass11 flag */
  1879. if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
  1880. SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  1881. }
  1882. /* LVDS DDA */
  1883. if(!((HwInfo->jChipType < SIS_315H) && (SiS_Pr->SiS_SetFlag & SetDOSMode))) {
  1884. if((SiS_Pr->SiS_IF_DEF_LVDS == 1) || (SiS_Pr->SiS_VBType & VB_NoLCD)) {
  1885. if(SiS_Pr->SiS_IF_DEF_TRUMPION == 0) {
  1886. if(ModeNo == 0x12) {
  1887. if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
  1888. SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
  1889. }
  1890. } else if(ModeNo > 0x13) {
  1891. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x600) {
  1892. if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
  1893. if((resinfo == SIS_RI_800x600) || (resinfo == SIS_RI_400x300)) {
  1894. SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
  1895. }
  1896. }
  1897. }
  1898. }
  1899. }
  1900. }
  1901. if(modeflag & HalfDCLK) {
  1902. if(SiS_Pr->SiS_IF_DEF_TRUMPION == 1) {
  1903. SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
  1904. } else if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  1905. SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
  1906. } else if(SiS_Pr->SiS_LCDResInfo == Panel_640x480) {
  1907. SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
  1908. } else if(ModeNo > 0x13) {
  1909. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  1910. if(resinfo == SIS_RI_512x384) SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
  1911. } else if(SiS_Pr->SiS_LCDResInfo == Panel_800x600) {
  1912. if(resinfo == SIS_RI_400x300) SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
  1913. }
  1914. }
  1915. }
  1916. }
  1917. /* VESA timing */
  1918. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  1919. if(SiS_Pr->SiS_VBInfo & SetNotSimuMode) {
  1920. SiS_Pr->SiS_SetFlag |= LCDVESATiming;
  1921. }
  1922. } else {
  1923. SiS_Pr->SiS_SetFlag |= LCDVESATiming;
  1924. }
  1925. #ifdef LINUX_KERNEL
  1926. #ifdef TWDEBUG
  1927. printk(KERN_DEBUG "sisfb: (LCDInfo=0x%04x LCDResInfo=0x%02x LCDTypeInfo=0x%02x)\n",
  1928. SiS_Pr->SiS_LCDInfo, SiS_Pr->SiS_LCDResInfo, SiS_Pr->SiS_LCDTypeInfo);
  1929. #endif
  1930. #endif
  1931. #ifdef LINUX_XF86
  1932. xf86DrvMsgVerb(0, X_PROBED, 4,
  1933. "(init301: LCDInfo=0x%04x LCDResInfo=0x%02x LCDTypeInfo=0x%02x SetFlag=0x%04x)\n",
  1934. SiS_Pr->SiS_LCDInfo, SiS_Pr->SiS_LCDResInfo, SiS_Pr->SiS_LCDTypeInfo, SiS_Pr->SiS_SetFlag);
  1935. #endif
  1936. }
  1937. /*********************************************/
  1938. /* GET VCLK */
  1939. /*********************************************/
  1940. USHORT
  1941. SiS_GetVCLK2Ptr(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
  1942. USHORT RefreshRateTableIndex, PSIS_HW_INFO HwInfo)
  1943. {
  1944. USHORT CRT2Index,VCLKIndex=0,VCLKIndexGEN=0;
  1945. USHORT modeflag,resinfo,tempbx;
  1946. const UCHAR *CHTVVCLKPtr = NULL;
  1947. if(ModeNo <= 0x13) {
  1948. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  1949. resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
  1950. CRT2Index = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  1951. VCLKIndexGEN = (SiS_GetRegByte((SiS_Pr->SiS_P3ca+0x02)) >> 2) & 0x03;
  1952. } else {
  1953. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  1954. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  1955. CRT2Index = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  1956. VCLKIndexGEN = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
  1957. if(HwInfo->jChipType < SIS_315H) VCLKIndexGEN &= 0x3f;
  1958. }
  1959. if(SiS_Pr->SiS_VBType & VB_SISVB) { /* 30x/B/LV */
  1960. if(SiS_Pr->SiS_SetFlag & ProgrammingCRT2) {
  1961. CRT2Index >>= 6;
  1962. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { /* LCD */
  1963. if(HwInfo->jChipType < SIS_315H) {
  1964. VCLKIndex = SiS_Pr->PanelVCLKIdx300;
  1965. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  1966. VCLKIndex = VCLKIndexGEN;
  1967. }
  1968. } else {
  1969. VCLKIndex = SiS_Pr->PanelVCLKIdx315;
  1970. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  1971. switch(resinfo) {
  1972. /* Only those whose IndexGEN doesn't match VBVCLK array */
  1973. case SIS_RI_1280x720: VCLKIndex = VCLK_1280x720; break;
  1974. case SIS_RI_720x480: VCLKIndex = VCLK_720x480; break;
  1975. case SIS_RI_720x576: VCLKIndex = VCLK_720x576; break;
  1976. case SIS_RI_768x576: VCLKIndex = VCLK_768x576; break;
  1977. case SIS_RI_848x480: VCLKIndex = VCLK_848x480; break;
  1978. case SIS_RI_856x480: VCLKIndex = VCLK_856x480; break;
  1979. case SIS_RI_800x480: VCLKIndex = VCLK_800x480; break;
  1980. case SIS_RI_1024x576: VCLKIndex = VCLK_1024x576; break;
  1981. case SIS_RI_1152x864: VCLKIndex = VCLK_1152x864; break;
  1982. case SIS_RI_1360x768: VCLKIndex = VCLK_1360x768; break;
  1983. default: VCLKIndex = VCLKIndexGEN;
  1984. }
  1985. if(ModeNo <= 0x13) {
  1986. if(HwInfo->jChipType <= SIS_315PRO) {
  1987. if(SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC == 1) VCLKIndex = 0x42;
  1988. } else {
  1989. if(SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC == 1) VCLKIndex = 0x00;
  1990. }
  1991. }
  1992. if(HwInfo->jChipType <= SIS_315PRO) {
  1993. if(VCLKIndex == 0) VCLKIndex = 0x41;
  1994. if(VCLKIndex == 1) VCLKIndex = 0x43;
  1995. if(VCLKIndex == 4) VCLKIndex = 0x44;
  1996. }
  1997. }
  1998. }
  1999. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { /* TV */
  2000. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  2001. if(SiS_Pr->SiS_TVMode & TVRPLLDIV2XO) VCLKIndex = HiTVVCLKDIV2;
  2002. else VCLKIndex = HiTVVCLK;
  2003. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) {
  2004. if(modeflag & Charx8Dot) VCLKIndex = HiTVSimuVCLK;
  2005. else VCLKIndex = HiTVTextVCLK;
  2006. }
  2007. } else if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) VCLKIndex = YPbPr750pVCLK;
  2008. else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) VCLKIndex = TVVCLKDIV2;
  2009. else if(SiS_Pr->SiS_TVMode & TVRPLLDIV2XO) VCLKIndex = TVVCLKDIV2;
  2010. else VCLKIndex = TVVCLK;
  2011. if(HwInfo->jChipType < SIS_315H) VCLKIndex += TVCLKBASE_300;
  2012. else VCLKIndex += TVCLKBASE_315;
  2013. } else { /* VGA2 */
  2014. VCLKIndex = VCLKIndexGEN;
  2015. if(HwInfo->jChipType < SIS_315H) {
  2016. if(ModeNo > 0x13) {
  2017. if( (HwInfo->jChipType == SIS_630) &&
  2018. (HwInfo->jChipRevision >= 0x30)) {
  2019. if(VCLKIndex == 0x14) VCLKIndex = 0x34;
  2020. }
  2021. /* Better VGA2 clock for 1280x1024@75 */
  2022. if(VCLKIndex == 0x17) VCLKIndex = 0x45;
  2023. }
  2024. }
  2025. }
  2026. } else { /* If not programming CRT2 */
  2027. VCLKIndex = VCLKIndexGEN;
  2028. if(HwInfo->jChipType < SIS_315H) {
  2029. if(ModeNo > 0x13) {
  2030. if( (HwInfo->jChipType != SIS_630) &&
  2031. (HwInfo->jChipType != SIS_300) ) {
  2032. if(VCLKIndex == 0x1b) VCLKIndex = 0x48;
  2033. }
  2034. }
  2035. }
  2036. }
  2037. } else { /* LVDS */
  2038. VCLKIndex = CRT2Index;
  2039. if(SiS_Pr->SiS_SetFlag & ProgrammingCRT2) {
  2040. if( (SiS_Pr->SiS_IF_DEF_CH70xx != 0) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV) ) {
  2041. VCLKIndex &= 0x1f;
  2042. tempbx = 0;
  2043. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx += 1;
  2044. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  2045. tempbx += 2;
  2046. if(SiS_Pr->SiS_ModeType > ModeVGA) {
  2047. if(SiS_Pr->SiS_CHSOverScan) tempbx = 8;
  2048. }
  2049. if(SiS_Pr->SiS_TVMode & TVSetPALM) {
  2050. tempbx = 4;
  2051. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx += 1;
  2052. } else if(SiS_Pr->SiS_TVMode & TVSetPALN) {
  2053. tempbx = 6;
  2054. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx += 1;
  2055. }
  2056. }
  2057. switch(tempbx) {
  2058. case 0: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKUNTSC; break;
  2059. case 1: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKONTSC; break;
  2060. case 2: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKUPAL; break;
  2061. case 3: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKOPAL; break;
  2062. case 4: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKUPALM; break;
  2063. case 5: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKOPALM; break;
  2064. case 6: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKUPALN; break;
  2065. case 7: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKOPALN; break;
  2066. case 8: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKSOPAL; break;
  2067. default: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKOPAL; break;
  2068. }
  2069. VCLKIndex = CHTVVCLKPtr[VCLKIndex];
  2070. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  2071. if(HwInfo->jChipType < SIS_315H) {
  2072. VCLKIndex = SiS_Pr->PanelVCLKIdx300;
  2073. } else {
  2074. VCLKIndex = SiS_Pr->PanelVCLKIdx315;
  2075. }
  2076. /* Special Timing: Barco iQ Pro R series */
  2077. if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) VCLKIndex = 0x44;
  2078. /* Special Timing: 848x480 parallel lvds */
  2079. if(SiS_Pr->SiS_CustomT == CUT_PANEL848) {
  2080. if(HwInfo->jChipType < SIS_315H) {
  2081. VCLKIndex = VCLK34_300;
  2082. /* if(resinfo == SIS_RI_1360x768) VCLKIndex = ?; */
  2083. } else {
  2084. VCLKIndex = VCLK34_315;
  2085. /* if(resinfo == SIS_RI_1360x768) VCLKIndex = ?; */
  2086. }
  2087. }
  2088. } else {
  2089. VCLKIndex = VCLKIndexGEN;
  2090. if(HwInfo->jChipType < SIS_315H) {
  2091. if(ModeNo > 0x13) {
  2092. if( (HwInfo->jChipType == SIS_630) &&
  2093. (HwInfo->jChipRevision >= 0x30) ) {
  2094. if(VCLKIndex == 0x14) VCLKIndex = 0x2e;
  2095. }
  2096. }
  2097. }
  2098. }
  2099. } else { /* if not programming CRT2 */
  2100. VCLKIndex = VCLKIndexGEN;
  2101. if(HwInfo->jChipType < SIS_315H) {
  2102. if(ModeNo > 0x13) {
  2103. if( (HwInfo->jChipType != SIS_630) &&
  2104. (HwInfo->jChipType != SIS_300) ) {
  2105. if(VCLKIndex == 0x1b) VCLKIndex = 0x48;
  2106. }
  2107. #if 0
  2108. if(HwInfo->jChipType == SIS_730) {
  2109. if(VCLKIndex == 0x0b) VCLKIndex = 0x40; /* 1024x768-70 */
  2110. if(VCLKIndex == 0x0d) VCLKIndex = 0x41; /* 1024x768-75 */
  2111. }
  2112. #endif
  2113. }
  2114. }
  2115. }
  2116. }
  2117. #ifdef TWDEBUG
  2118. xf86DrvMsg(0, X_INFO, "VCLKIndex %d (0x%x)\n", VCLKIndex, VCLKIndex);
  2119. #endif
  2120. return(VCLKIndex);
  2121. }
  2122. /*********************************************/
  2123. /* SET CRT2 MODE TYPE REGISTERS */
  2124. /*********************************************/
  2125. static void
  2126. SiS_SetCRT2ModeRegs(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
  2127. PSIS_HW_INFO HwInfo)
  2128. {
  2129. USHORT i,j,modeflag;
  2130. USHORT tempcl,tempah=0;
  2131. #if defined(SIS300) || defined(SIS315H)
  2132. USHORT tempbl;
  2133. #endif
  2134. #ifdef SIS315H
  2135. UCHAR *ROMAddr = HwInfo->pjVirtualRomBase;
  2136. USHORT tempah2, tempbl2;
  2137. #endif
  2138. if(ModeNo <= 0x13) {
  2139. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  2140. } else if(SiS_Pr->UseCustomMode) {
  2141. modeflag = SiS_Pr->CModeFlag;
  2142. } else {
  2143. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  2144. }
  2145. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  2146. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x00,0xAF,0x40);
  2147. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2E,0xF7);
  2148. } else {
  2149. for(i=0,j=4; i<3; i++,j++) SiS_SetReg(SiS_Pr->SiS_Part1Port,j,0);
  2150. if(HwInfo->jChipType >= SIS_315H) {
  2151. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x02,0x7F);
  2152. }
  2153. tempcl = SiS_Pr->SiS_ModeType;
  2154. if(HwInfo->jChipType < SIS_315H) {
  2155. #ifdef SIS300 /* ---- 300 series ---- */
  2156. /* For 301BDH: (with LCD via LVDS) */
  2157. if(SiS_Pr->SiS_VBType & VB_NoLCD) {
  2158. tempbl = SiS_GetReg(SiS_Pr->SiS_P3c4,0x32);
  2159. tempbl &= 0xef;
  2160. tempbl |= 0x02;
  2161. if((SiS_Pr->SiS_VBInfo & SetCRT2ToTV) || (SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) {
  2162. tempbl |= 0x10;
  2163. tempbl &= 0xfd;
  2164. }
  2165. SiS_SetReg(SiS_Pr->SiS_P3c4,0x32,tempbl);
  2166. }
  2167. if(ModeNo > 0x13) {
  2168. tempcl -= ModeVGA;
  2169. if((tempcl > 0) || (tempcl == 0)) { /* tempcl is USHORT -> always true! */
  2170. tempah = ((0x10 >> tempcl) | 0x80);
  2171. }
  2172. } else tempah = 0x80;
  2173. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) tempah ^= 0xA0;
  2174. #endif /* SIS300 */
  2175. } else {
  2176. #ifdef SIS315H /* ------- 315/330 series ------ */
  2177. if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
  2178. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) {
  2179. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2e,0x08);
  2180. }
  2181. }
  2182. if(ModeNo > 0x13) {
  2183. tempcl -= ModeVGA;
  2184. if((tempcl > 0) || (tempcl == 0)) { /* tempcl is USHORT -> always true! */
  2185. tempah = (0x08 >> tempcl);
  2186. if (tempah == 0) tempah = 1;
  2187. tempah |= 0x40;
  2188. }
  2189. } else tempah = 0x40;
  2190. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) tempah ^= 0x50;
  2191. #endif /* SIS315H */
  2192. }
  2193. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 0;
  2194. if(HwInfo->jChipType < SIS_315H) {
  2195. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,tempah);
  2196. } else {
  2197. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  2198. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x00,0xa0,tempah);
  2199. } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
  2200. if(IS_SIS740) {
  2201. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,tempah);
  2202. } else {
  2203. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x00,0xa0,tempah);
  2204. }
  2205. }
  2206. }
  2207. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  2208. tempah = 0x01;
  2209. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  2210. tempah |= 0x02;
  2211. }
  2212. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) {
  2213. tempah ^= 0x05;
  2214. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) {
  2215. tempah ^= 0x01;
  2216. }
  2217. }
  2218. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 0;
  2219. if(HwInfo->jChipType < SIS_315H) {
  2220. tempah = (tempah << 5) & 0xFF;
  2221. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x01,tempah);
  2222. tempah = (tempah >> 5) & 0xFF;
  2223. } else {
  2224. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2E,0xF8,tempah);
  2225. }
  2226. if((SiS_Pr->SiS_ModeType == ModeVGA) && (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode))) {
  2227. tempah |= 0x10;
  2228. }
  2229. tempah |= 0x80;
  2230. if(SiS_Pr->SiS_VBType & VB_SIS301) {
  2231. if(SiS_Pr->PanelXRes < 1280 && SiS_Pr->PanelYRes < 960) tempah &= ~0x80;
  2232. }
  2233. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  2234. if(!(SiS_Pr->SiS_TVMode & (TVSetYPbPr750p | TVSetYPbPr525p))) {
  2235. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  2236. tempah |= 0x20;
  2237. }
  2238. }
  2239. }
  2240. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x0D,0x40,tempah);
  2241. tempah = 0x80;
  2242. if(SiS_Pr->SiS_VBType & VB_SIS301) {
  2243. if(SiS_Pr->PanelXRes < 1280 && SiS_Pr->PanelYRes < 960) tempah = 0;
  2244. }
  2245. if(SiS_IsDualLink(SiS_Pr, HwInfo)) tempah |= 0x40;
  2246. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  2247. if(SiS_Pr->SiS_TVMode & TVRPLLDIV2XO) {
  2248. tempah |= 0x40;
  2249. }
  2250. }
  2251. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0C,tempah);
  2252. } else { /* LVDS */
  2253. if(HwInfo->jChipType >= SIS_315H) {
  2254. #ifdef SIS315H
  2255. /* LVDS can only be slave in 8bpp modes */
  2256. tempah = 0x80;
  2257. if((modeflag & CRT2Mode) && (SiS_Pr->SiS_ModeType > ModeVGA)) {
  2258. if(SiS_Pr->SiS_VBInfo & DriverMode) {
  2259. tempah |= 0x02;
  2260. }
  2261. }
  2262. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  2263. tempah |= 0x02;
  2264. }
  2265. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  2266. tempah ^= 0x01;
  2267. }
  2268. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) {
  2269. tempah = 1;
  2270. }
  2271. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2e,0xF0,tempah);
  2272. #endif
  2273. } else {
  2274. #ifdef SIS300
  2275. tempah = 0;
  2276. if( (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) && (SiS_Pr->SiS_ModeType > ModeVGA) ) {
  2277. tempah |= 0x02;
  2278. }
  2279. tempah <<= 5;
  2280. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 0;
  2281. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x01,tempah);
  2282. #endif
  2283. }
  2284. }
  2285. } /* LCDA */
  2286. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  2287. if(HwInfo->jChipType >= SIS_315H) {
  2288. #ifdef SIS315H
  2289. unsigned char bridgerev = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x01);
  2290. /* The following is nearly unpreditable and varies from machine
  2291. * to machine. Especially the 301DH seems to be a real trouble
  2292. * maker. Some BIOSes simply set the registers (like in the
  2293. * NoLCD-if-statements here), some set them according to the
  2294. * LCDA stuff. It is very likely that some machines are not
  2295. * treated correctly in the following, very case-orientated
  2296. * code. What do I do then...?
  2297. */
  2298. /* 740 variants match for 30xB, 301B-DH, 30xLV */
  2299. if(!(IS_SIS740)) {
  2300. tempah = 0x04; /* For all bridges */
  2301. tempbl = 0xfb;
  2302. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  2303. tempah = 0x00;
  2304. if(SiS_IsDualEdge(SiS_Pr, HwInfo)) {
  2305. tempbl = 0xff;
  2306. }
  2307. }
  2308. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,tempbl,tempah);
  2309. }
  2310. /* The following two are responsible for eventually wrong colors
  2311. * in TV output. The DH (VB_NoLCD) conditions are unknown; the
  2312. * b0 was found in some 651 machine (Pim; P4_23=0xe5); the b1 version
  2313. * in a 650 box (Jake). What is the criteria?
  2314. */
  2315. if((IS_SIS740) || (HwInfo->jChipType >= SIS_661) || (SiS_Pr->SiS_ROMNew)) {
  2316. tempah = 0x30;
  2317. tempbl = 0xc0;
  2318. if((SiS_Pr->SiS_VBInfo & DisableCRT2Display) ||
  2319. ((SiS_Pr->SiS_ROMNew) && (!(ROMAddr[0x5b] & 0x04)))) {
  2320. tempah = 0x00;
  2321. tempbl = 0x00;
  2322. }
  2323. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2c,0xcf,tempah);
  2324. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x21,0x3f,tempbl);
  2325. } else if(SiS_Pr->SiS_VBType & VB_SIS301) {
  2326. /* Fixes "TV-blue-bug" on 315+301 */
  2327. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2c,0xcf); /* For 301 */
  2328. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x21,0x3f);
  2329. } else if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {
  2330. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2c,0x30); /* For 30xLV */
  2331. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x21,0xc0);
  2332. } else if((SiS_Pr->SiS_VBType & VB_NoLCD) && (bridgerev == 0xb0)) {
  2333. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2c,0x30); /* For 30xB-DH rev b0 (or "DH on 651"?) */
  2334. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x21,0xc0);
  2335. } else {
  2336. tempah = 0x30; tempah2 = 0xc0; /* For 30xB (and 301BDH rev b1) */
  2337. tempbl = 0xcf; tempbl2 = 0x3f;
  2338. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  2339. tempah = tempah2 = 0x00;
  2340. if(SiS_IsDualEdge(SiS_Pr, HwInfo)) {
  2341. tempbl = tempbl2 = 0xff;
  2342. }
  2343. }
  2344. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2c,tempbl,tempah);
  2345. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x21,tempbl2,tempah2);
  2346. }
  2347. if(IS_SIS740) {
  2348. tempah = 0x80;
  2349. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 0x00;
  2350. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x23,0x7f,tempah);
  2351. } else {
  2352. tempah = 0x00;
  2353. tempbl = 0x7f;
  2354. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  2355. tempbl = 0xff;
  2356. if(!(SiS_IsDualEdge(SiS_Pr, HwInfo))) tempah = 0x80;
  2357. }
  2358. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x23,tempbl,tempah);
  2359. }
  2360. #endif /* SIS315H */
  2361. } else if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
  2362. #ifdef SIS300
  2363. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x21,0x3f);
  2364. if((SiS_Pr->SiS_VBInfo & DisableCRT2Display) ||
  2365. ((SiS_Pr->SiS_VBType & VB_NoLCD) &&
  2366. (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD))) {
  2367. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x23,0x7F);
  2368. } else {
  2369. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x23,0x80);
  2370. }
  2371. #endif
  2372. }
  2373. if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
  2374. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x0D,0x80);
  2375. if(SiS_Pr->SiS_VBType & VB_SIS301C) {
  2376. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x3A,0xC0);
  2377. }
  2378. }
  2379. } else { /* LVDS */
  2380. #ifdef SIS315H
  2381. if(HwInfo->jChipType >= SIS_315H) {
  2382. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  2383. tempah = 0x04;
  2384. tempbl = 0xfb;
  2385. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  2386. tempah = 0x00;
  2387. if(SiS_IsDualEdge(SiS_Pr, HwInfo)) tempbl = 0xff;
  2388. }
  2389. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,tempbl,tempah);
  2390. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) {
  2391. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xfb);
  2392. }
  2393. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2c,0x30);
  2394. } else if(HwInfo->jChipType == SIS_550) {
  2395. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xfb);
  2396. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2c,0x30);
  2397. }
  2398. }
  2399. #endif
  2400. }
  2401. }
  2402. /*********************************************/
  2403. /* GET RESOLUTION DATA */
  2404. /*********************************************/
  2405. USHORT
  2406. SiS_GetResInfo(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex)
  2407. {
  2408. if(ModeNo <= 0x13) return((USHORT)SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo);
  2409. else return((USHORT)SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO);
  2410. }
  2411. static void
  2412. SiS_GetCRT2ResInfo(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex,
  2413. PSIS_HW_INFO HwInfo)
  2414. {
  2415. USHORT xres,yres,modeflag=0,resindex;
  2416. if(SiS_Pr->UseCustomMode) {
  2417. xres = SiS_Pr->CHDisplay;
  2418. if(SiS_Pr->CModeFlag & HalfDCLK) xres *= 2;
  2419. SiS_Pr->SiS_VGAHDE = SiS_Pr->SiS_HDE = xres;
  2420. yres = SiS_Pr->CVDisplay;
  2421. if(SiS_Pr->CModeFlag & DoubleScanMode) yres *= 2;
  2422. SiS_Pr->SiS_VGAVDE = SiS_Pr->SiS_VDE = yres;
  2423. return;
  2424. }
  2425. resindex = SiS_GetResInfo(SiS_Pr,ModeNo,ModeIdIndex);
  2426. if(ModeNo <= 0x13) {
  2427. xres = SiS_Pr->SiS_StResInfo[resindex].HTotal;
  2428. yres = SiS_Pr->SiS_StResInfo[resindex].VTotal;
  2429. } else {
  2430. xres = SiS_Pr->SiS_ModeResInfo[resindex].HTotal;
  2431. yres = SiS_Pr->SiS_ModeResInfo[resindex].VTotal;
  2432. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  2433. }
  2434. if(!SiS_Pr->SiS_IF_DEF_DSTN && !SiS_Pr->SiS_IF_DEF_FSTN) {
  2435. if((HwInfo->jChipType >= SIS_315H) && (SiS_Pr->SiS_IF_DEF_LVDS == 1)) {
  2436. if((ModeNo != 0x03) && (SiS_Pr->SiS_SetFlag & SetDOSMode)) {
  2437. if(yres == 350) yres = 400;
  2438. }
  2439. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x3a) & 0x01) {
  2440. if(ModeNo == 0x12) yres = 400;
  2441. }
  2442. }
  2443. if(modeflag & HalfDCLK) xres *= 2;
  2444. if(modeflag & DoubleScanMode) yres *= 2;
  2445. }
  2446. if((SiS_Pr->SiS_VBType & VB_SISVB) && (!(SiS_Pr->SiS_VBType & VB_NoLCD))) {
  2447. #if 0
  2448. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCDA | SetCRT2ToLCD | SetCRT2ToHiVision)) {
  2449. if(xres == 720) xres = 640;
  2450. }
  2451. #endif
  2452. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  2453. switch(SiS_Pr->SiS_LCDResInfo) {
  2454. case Panel_1024x768:
  2455. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
  2456. if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
  2457. if(yres == 350) yres = 357;
  2458. if(yres == 400) yres = 420;
  2459. if(yres == 480) yres = 525;
  2460. }
  2461. }
  2462. break;
  2463. case Panel_1280x1024:
  2464. if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
  2465. /* BIOS bug - does this regardless of scaling */
  2466. if(yres == 400) yres = 405;
  2467. }
  2468. if(yres == 350) yres = 360;
  2469. if(SiS_Pr->SiS_SetFlag & LCDVESATiming) {
  2470. if(yres == 360) yres = 375;
  2471. }
  2472. break;
  2473. case Panel_1600x1200:
  2474. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
  2475. if(yres == 1024) yres = 1056;
  2476. }
  2477. break;
  2478. }
  2479. }
  2480. } else {
  2481. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  2482. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToHiVision)) {
  2483. if(xres == 720) xres = 640;
  2484. }
  2485. } else if(xres == 720) xres = 640;
  2486. if(SiS_Pr->SiS_SetFlag & SetDOSMode) {
  2487. yres = 400;
  2488. if(HwInfo->jChipType >= SIS_315H) {
  2489. if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x17) & 0x80) yres = 480;
  2490. } else {
  2491. if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x80) yres = 480;
  2492. }
  2493. if(SiS_Pr->SiS_IF_DEF_DSTN || SiS_Pr->SiS_IF_DEF_FSTN) yres = 480;
  2494. }
  2495. }
  2496. SiS_Pr->SiS_VGAHDE = SiS_Pr->SiS_HDE = xres;
  2497. SiS_Pr->SiS_VGAVDE = SiS_Pr->SiS_VDE = yres;
  2498. }
  2499. /*********************************************/
  2500. /* GET CRT2 TIMING DATA */
  2501. /*********************************************/
  2502. static BOOLEAN
  2503. SiS_GetLVDSCRT1Ptr(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
  2504. USHORT RefreshRateTableIndex, USHORT *ResIndex,
  2505. USHORT *DisplayType)
  2506. {
  2507. USHORT modeflag=0;
  2508. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  2509. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  2510. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) return FALSE;
  2511. }
  2512. } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
  2513. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) return FALSE;
  2514. } else
  2515. return FALSE;
  2516. if(ModeNo <= 0x13) {
  2517. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  2518. (*ResIndex) = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  2519. } else {
  2520. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  2521. (*ResIndex) = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  2522. }
  2523. (*ResIndex) &= 0x3F;
  2524. if((SiS_Pr->SiS_IF_DEF_CH70xx) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
  2525. (*DisplayType) = 18;
  2526. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) (*DisplayType)++;
  2527. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  2528. (*DisplayType) += 2;
  2529. if(SiS_Pr->SiS_ModeType > ModeVGA) {
  2530. if(SiS_Pr->SiS_CHSOverScan) (*DisplayType) = 99;
  2531. }
  2532. if(SiS_Pr->SiS_TVMode & TVSetPALM) {
  2533. (*DisplayType) = 18; /* PALM uses NTSC data */
  2534. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) (*DisplayType)++;
  2535. } else if(SiS_Pr->SiS_TVMode & TVSetPALN) {
  2536. (*DisplayType) = 20; /* PALN uses PAL data */
  2537. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) (*DisplayType)++;
  2538. }
  2539. }
  2540. } else {
  2541. switch(SiS_Pr->SiS_LCDResInfo) {
  2542. case Panel_640x480: (*DisplayType) = 50; break;
  2543. case Panel_640x480_2: (*DisplayType) = 52; break;
  2544. case Panel_640x480_3: (*DisplayType) = 54; break;
  2545. case Panel_800x600: (*DisplayType) = 0; break;
  2546. case Panel_1024x600: (*DisplayType) = 23; break;
  2547. case Panel_1024x768: (*DisplayType) = 4; break;
  2548. case Panel_1152x768: (*DisplayType) = 27; break;
  2549. case Panel_1280x768: (*DisplayType) = 40; break;
  2550. case Panel_1280x1024: (*DisplayType) = 8; break;
  2551. case Panel_1400x1050: (*DisplayType) = 14; break;
  2552. case Panel_1600x1200: (*DisplayType) = 36; break;
  2553. default: return FALSE;
  2554. }
  2555. if(modeflag & HalfDCLK) (*DisplayType)++;
  2556. switch(SiS_Pr->SiS_LCDResInfo) {
  2557. case Panel_640x480:
  2558. case Panel_640x480_2:
  2559. case Panel_640x480_3:
  2560. break;
  2561. default:
  2562. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) (*DisplayType) += 2;
  2563. }
  2564. if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
  2565. (*DisplayType) = 12;
  2566. if(modeflag & HalfDCLK) (*DisplayType)++;
  2567. }
  2568. }
  2569. #if 0
  2570. if(SiS_Pr->SiS_IF_DEF_FSTN) {
  2571. if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel320x480){
  2572. (*DisplayType) = 22;
  2573. }
  2574. }
  2575. #endif
  2576. return TRUE;
  2577. }
  2578. static void
  2579. SiS_GetCRT2Ptr(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex,
  2580. USHORT RefreshRateTableIndex,USHORT *CRT2Index,USHORT *ResIndex,
  2581. PSIS_HW_INFO HwInfo)
  2582. {
  2583. USHORT tempbx=0,tempal=0,resinfo=0;
  2584. if(ModeNo <= 0x13) {
  2585. tempal = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  2586. } else {
  2587. tempal = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  2588. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  2589. }
  2590. if((SiS_Pr->SiS_VBType & VB_SISVB) && (SiS_Pr->SiS_IF_DEF_LVDS == 0)) {
  2591. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { /* LCD */
  2592. tempbx = SiS_Pr->SiS_LCDResInfo;
  2593. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) tempbx += 32;
  2594. if(SiS_Pr->SiS_LCDResInfo == Panel_1680x1050) {
  2595. if (resinfo == SIS_RI_1280x800) tempal = 9;
  2596. else if(resinfo == SIS_RI_1400x1050) tempal = 11;
  2597. } else if((SiS_Pr->SiS_LCDResInfo == Panel_1280x800) ||
  2598. (SiS_Pr->SiS_LCDResInfo == Panel_1280x800_2)) {
  2599. if (resinfo == SIS_RI_1280x768) tempal = 9;
  2600. }
  2601. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  2602. /* Pass 1:1 only (center-screen handled outside) */
  2603. /* This is never called for the panel's native resolution */
  2604. /* since Pass1:1 will not be set in this case */
  2605. tempbx = 100;
  2606. if(ModeNo >= 0x13) {
  2607. tempal = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC_NS;
  2608. }
  2609. }
  2610. #ifdef SIS315H
  2611. if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) {
  2612. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) {
  2613. if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
  2614. tempbx = 200;
  2615. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) tempbx++;
  2616. }
  2617. }
  2618. }
  2619. #endif
  2620. } else { /* TV */
  2621. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  2622. /* if(SiS_Pr->SiS_VGAVDE > 480) SiS_Pr->SiS_TVMode &= (~TVSetTVSimuMode); */
  2623. tempbx = 2;
  2624. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  2625. tempbx = 13;
  2626. if(!(SiS_Pr->SiS_TVMode & TVSetTVSimuMode)) tempbx = 14;
  2627. }
  2628. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  2629. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) tempbx = 7;
  2630. else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) tempbx = 6;
  2631. else tempbx = 5;
  2632. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) tempbx += 5;
  2633. } else {
  2634. if(SiS_Pr->SiS_TVMode & TVSetPAL) tempbx = 3;
  2635. else tempbx = 4;
  2636. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) tempbx += 5;
  2637. }
  2638. }
  2639. tempal &= 0x3F;
  2640. if(ModeNo > 0x13) {
  2641. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoHiVision) {
  2642. if(tempal == 6) tempal = 7;
  2643. if((resinfo == SIS_RI_720x480) ||
  2644. (resinfo == SIS_RI_720x576) ||
  2645. (resinfo == SIS_RI_768x576)) {
  2646. tempal = 6;
  2647. if(SiS_Pr->SiS_TVMode & (TVSetPAL | TVSetPALN)) {
  2648. if(resinfo == SIS_RI_720x480) tempal = 9;
  2649. }
  2650. }
  2651. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  2652. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) {
  2653. if(resinfo == SIS_RI_1024x768) tempal = 8;
  2654. }
  2655. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) {
  2656. if((resinfo == SIS_RI_720x576) ||
  2657. (resinfo == SIS_RI_768x576)) {
  2658. tempal = 8;
  2659. }
  2660. if(resinfo == SIS_RI_1280x720) tempal = 9;
  2661. }
  2662. }
  2663. }
  2664. }
  2665. *CRT2Index = tempbx;
  2666. *ResIndex = tempal;
  2667. } else { /* LVDS, 301B-DH (if running on LCD) */
  2668. tempbx = 0;
  2669. if((SiS_Pr->SiS_IF_DEF_CH70xx) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
  2670. tempbx = 10;
  2671. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx += 1;
  2672. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  2673. tempbx += 2;
  2674. if(SiS_Pr->SiS_ModeType > ModeVGA) {
  2675. if(SiS_Pr->SiS_CHSOverScan) tempbx = 99;
  2676. }
  2677. if(SiS_Pr->SiS_TVMode & TVSetPALM) {
  2678. tempbx = 90;
  2679. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx += 1;
  2680. } else if(SiS_Pr->SiS_TVMode & TVSetPALN) {
  2681. tempbx = 92;
  2682. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx += 1;
  2683. }
  2684. }
  2685. } else {
  2686. switch(SiS_Pr->SiS_LCDResInfo) {
  2687. case Panel_640x480: tempbx = 6; break;
  2688. case Panel_640x480_2:
  2689. case Panel_640x480_3: tempbx = 30; break;
  2690. case Panel_800x600: tempbx = 0; break;
  2691. case Panel_1024x600: tempbx = 15; break;
  2692. case Panel_1024x768: tempbx = 2; break;
  2693. case Panel_1152x768: tempbx = 17; break;
  2694. case Panel_1280x768: tempbx = 18; break;
  2695. case Panel_1280x1024: tempbx = 4; break;
  2696. case Panel_1400x1050: tempbx = 8; break;
  2697. case Panel_1600x1200: tempbx = 21; break;
  2698. case Panel_Barco1366: tempbx = 80; break;
  2699. }
  2700. switch(SiS_Pr->SiS_LCDResInfo) {
  2701. case Panel_640x480:
  2702. case Panel_640x480_2:
  2703. case Panel_640x480_3:
  2704. break;
  2705. default:
  2706. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++;
  2707. }
  2708. if(SiS_Pr->SiS_LCDInfo & LCDPass11) tempbx = 7;
  2709. if(SiS_Pr->SiS_CustomT == CUT_BARCO1024) {
  2710. tempbx = 82;
  2711. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++;
  2712. } else if(SiS_Pr->SiS_CustomT == CUT_PANEL848) {
  2713. tempbx = 84;
  2714. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++;
  2715. }
  2716. if((SiS_Pr->SiS_CustomT != CUT_BARCO1366) &&
  2717. (SiS_Pr->SiS_CustomT != CUT_PANEL848)) {
  2718. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) &&
  2719. (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
  2720. tempal = 0;
  2721. }
  2722. }
  2723. }
  2724. (*CRT2Index) = tempbx;
  2725. (*ResIndex) = tempal & 0x1F;
  2726. }
  2727. }
  2728. static void
  2729. SiS_GetRAMDAC2DATA(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex,
  2730. USHORT RefreshRateTableIndex,PSIS_HW_INFO HwInfo)
  2731. {
  2732. USHORT tempax=0,tempbx=0;
  2733. USHORT temp1=0,modeflag=0,tempcx=0;
  2734. USHORT index;
  2735. SiS_Pr->SiS_RVBHCMAX = 1;
  2736. SiS_Pr->SiS_RVBHCFACT = 1;
  2737. if(ModeNo <= 0x13) {
  2738. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  2739. index = SiS_GetModePtr(SiS_Pr,ModeNo,ModeIdIndex);
  2740. tempax = SiS_Pr->SiS_StandTable[index].CRTC[0];
  2741. tempbx = SiS_Pr->SiS_StandTable[index].CRTC[6];
  2742. temp1 = SiS_Pr->SiS_StandTable[index].CRTC[7];
  2743. } else {
  2744. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  2745. index = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
  2746. tempax = SiS_Pr->SiS_CRT1Table[index].CR[0];
  2747. tempax |= (SiS_Pr->SiS_CRT1Table[index].CR[14] << 8);
  2748. tempax &= 0x03FF;
  2749. tempbx = SiS_Pr->SiS_CRT1Table[index].CR[6];
  2750. tempcx = SiS_Pr->SiS_CRT1Table[index].CR[13] << 8;
  2751. tempcx &= 0x0100;
  2752. tempcx <<= 2;
  2753. tempbx |= tempcx;
  2754. temp1 = SiS_Pr->SiS_CRT1Table[index].CR[7];
  2755. }
  2756. if(temp1 & 0x01) tempbx |= 0x0100;
  2757. if(temp1 & 0x20) tempbx |= 0x0200;
  2758. tempax += 5;
  2759. /* Charx8Dot is no more used (and assumed), so we set it */
  2760. if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
  2761. modeflag |= Charx8Dot;
  2762. }
  2763. if(modeflag & Charx8Dot) tempax *= 8;
  2764. else tempax *= 9;
  2765. if(modeflag & HalfDCLK) tempax <<= 1;
  2766. tempbx++;
  2767. SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_HT = tempax;
  2768. SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_VT = tempbx;
  2769. }
  2770. static void
  2771. SiS_GetCRT2DataLVDS(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex,
  2772. USHORT RefreshRateTableIndex, PSIS_HW_INFO HwInfo)
  2773. {
  2774. USHORT CRT2Index, ResIndex;
  2775. const SiS_LVDSDataStruct *LVDSData = NULL;
  2776. SiS_GetCRT2ResInfo(SiS_Pr, ModeNo, ModeIdIndex, HwInfo);
  2777. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  2778. SiS_Pr->SiS_RVBHCMAX = 1;
  2779. SiS_Pr->SiS_RVBHCFACT = 1;
  2780. SiS_Pr->SiS_NewFlickerMode = 0;
  2781. SiS_Pr->SiS_RVBHRS = 50;
  2782. SiS_Pr->SiS_RY1COE = 0;
  2783. SiS_Pr->SiS_RY2COE = 0;
  2784. SiS_Pr->SiS_RY3COE = 0;
  2785. SiS_Pr->SiS_RY4COE = 0;
  2786. }
  2787. if((SiS_Pr->SiS_VBType & VB_SISVB) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  2788. #ifdef SIS315H
  2789. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  2790. if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
  2791. if(SiS_Pr->UseCustomMode) {
  2792. SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_HT = SiS_Pr->CHTotal;
  2793. SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_VT = SiS_Pr->CVTotal;
  2794. } else {
  2795. if(ModeNo < 0x13) {
  2796. ResIndex = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  2797. } else {
  2798. ResIndex = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC_NS;
  2799. }
  2800. SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_NoScaleData[ResIndex].VGAHT;
  2801. SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_NoScaleData[ResIndex].VGAVT;
  2802. SiS_Pr->SiS_HT = SiS_Pr->SiS_NoScaleData[ResIndex].LCDHT;
  2803. SiS_Pr->SiS_VT = SiS_Pr->SiS_NoScaleData[ResIndex].LCDVT;
  2804. }
  2805. } else {
  2806. SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_HT = SiS_Pr->PanelHT;
  2807. SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_VT = SiS_Pr->PanelVT;
  2808. }
  2809. } else {
  2810. /* This handles custom modes and custom panels */
  2811. SiS_Pr->SiS_HDE = SiS_Pr->PanelXRes;
  2812. SiS_Pr->SiS_VDE = SiS_Pr->PanelYRes;
  2813. SiS_Pr->SiS_HT = SiS_Pr->PanelHT;
  2814. SiS_Pr->SiS_VT = SiS_Pr->PanelVT;
  2815. SiS_Pr->SiS_VGAHT = SiS_Pr->PanelHT - (SiS_Pr->PanelXRes - SiS_Pr->SiS_VGAHDE);
  2816. SiS_Pr->SiS_VGAVT = SiS_Pr->PanelVT - (SiS_Pr->PanelYRes - SiS_Pr->SiS_VGAVDE);
  2817. }
  2818. SiS_CalcLCDACRT1Timing(SiS_Pr,ModeNo,ModeIdIndex);
  2819. #endif
  2820. } else {
  2821. /* 301BDH needs LVDS Data */
  2822. if((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) {
  2823. SiS_Pr->SiS_IF_DEF_LVDS = 1;
  2824. }
  2825. SiS_GetCRT2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex,
  2826. &CRT2Index, &ResIndex, HwInfo);
  2827. /* 301BDH needs LVDS Data */
  2828. if((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) {
  2829. SiS_Pr->SiS_IF_DEF_LVDS = 0;
  2830. }
  2831. switch (CRT2Index) {
  2832. case 0: LVDSData = SiS_Pr->SiS_LVDS800x600Data_1; break;
  2833. case 1: LVDSData = SiS_Pr->SiS_LVDS800x600Data_2; break;
  2834. case 2: LVDSData = SiS_Pr->SiS_LVDS1024x768Data_1; break;
  2835. case 3: LVDSData = SiS_Pr->SiS_LVDS1024x768Data_2; break;
  2836. case 4: LVDSData = SiS_Pr->SiS_LVDS1280x1024Data_1; break;
  2837. case 5: LVDSData = SiS_Pr->SiS_LVDS1280x1024Data_2; break;
  2838. case 6: LVDSData = SiS_Pr->SiS_LVDS640x480Data_1; break;
  2839. case 7: LVDSData = SiS_Pr->SiS_LVDSXXXxXXXData_1; break;
  2840. case 8: LVDSData = SiS_Pr->SiS_LVDS1400x1050Data_1; break;
  2841. case 9: LVDSData = SiS_Pr->SiS_LVDS1400x1050Data_2; break;
  2842. case 10: LVDSData = SiS_Pr->SiS_CHTVUNTSCData; break;
  2843. case 11: LVDSData = SiS_Pr->SiS_CHTVONTSCData; break;
  2844. case 12: LVDSData = SiS_Pr->SiS_CHTVUPALData; break;
  2845. case 13: LVDSData = SiS_Pr->SiS_CHTVOPALData; break;
  2846. case 14: LVDSData = SiS_Pr->SiS_LVDS320x480Data_1; break;
  2847. case 15: LVDSData = SiS_Pr->SiS_LVDS1024x600Data_1; break;
  2848. case 16: LVDSData = SiS_Pr->SiS_LVDS1024x600Data_2; break;
  2849. case 17: LVDSData = SiS_Pr->SiS_LVDS1152x768Data_1; break;
  2850. case 18: LVDSData = SiS_Pr->SiS_LVDS1152x768Data_2; break;
  2851. case 19: LVDSData = SiS_Pr->SiS_LVDS1280x768Data_1; break;
  2852. case 20: LVDSData = SiS_Pr->SiS_LVDS1280x768Data_2; break;
  2853. case 21: LVDSData = SiS_Pr->SiS_LVDS1600x1200Data_1; break;
  2854. case 22: LVDSData = SiS_Pr->SiS_LVDS1600x1200Data_2; break;
  2855. case 30: LVDSData = SiS_Pr->SiS_LVDS640x480Data_2; break;
  2856. case 80: LVDSData = SiS_Pr->SiS_LVDSBARCO1366Data_1; break;
  2857. case 81: LVDSData = SiS_Pr->SiS_LVDSBARCO1366Data_2; break;
  2858. case 82: LVDSData = SiS_Pr->SiS_LVDSBARCO1024Data_1; break;
  2859. case 83: LVDSData = SiS_Pr->SiS_LVDSBARCO1024Data_2; break;
  2860. case 84: LVDSData = SiS_Pr->SiS_LVDS848x480Data_1; break;
  2861. case 85: LVDSData = SiS_Pr->SiS_LVDS848x480Data_2; break;
  2862. case 90: LVDSData = SiS_Pr->SiS_CHTVUPALMData; break;
  2863. case 91: LVDSData = SiS_Pr->SiS_CHTVOPALMData; break;
  2864. case 92: LVDSData = SiS_Pr->SiS_CHTVUPALNData; break;
  2865. case 93: LVDSData = SiS_Pr->SiS_CHTVOPALNData; break;
  2866. case 99: LVDSData = SiS_Pr->SiS_CHTVSOPALData; break; /* Super Overscan */
  2867. default: LVDSData = SiS_Pr->SiS_LVDS1024x768Data_1; break;
  2868. }
  2869. SiS_Pr->SiS_VGAHT = (LVDSData+ResIndex)->VGAHT;
  2870. SiS_Pr->SiS_VGAVT = (LVDSData+ResIndex)->VGAVT;
  2871. SiS_Pr->SiS_HT = (LVDSData+ResIndex)->LCDHT;
  2872. SiS_Pr->SiS_VT = (LVDSData+ResIndex)->LCDVT;
  2873. if(!(SiS_Pr->SiS_VBType & VB_SISVB)) {
  2874. if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
  2875. if((!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) || (SiS_Pr->SiS_SetFlag & SetDOSMode)) {
  2876. SiS_Pr->SiS_HDE = SiS_Pr->PanelXRes;
  2877. SiS_Pr->SiS_VDE = SiS_Pr->PanelYRes;
  2878. if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) {
  2879. if(ResIndex < 0x08) {
  2880. SiS_Pr->SiS_HDE = 1280;
  2881. SiS_Pr->SiS_VDE = 1024;
  2882. }
  2883. }
  2884. }
  2885. }
  2886. }
  2887. }
  2888. }
  2889. static void
  2890. SiS_GetCRT2Data301(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex,
  2891. USHORT RefreshRateTableIndex,
  2892. PSIS_HW_INFO HwInfo)
  2893. {
  2894. UCHAR *ROMAddr = NULL;
  2895. USHORT tempax,tempbx,modeflag,romptr=0;
  2896. USHORT resinfo,CRT2Index,ResIndex;
  2897. const SiS_LCDDataStruct *LCDPtr = NULL;
  2898. const SiS_TVDataStruct *TVPtr = NULL;
  2899. #ifdef SIS315H
  2900. SHORT resinfo661;
  2901. #endif
  2902. if(ModeNo <= 0x13) {
  2903. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  2904. resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
  2905. } else if(SiS_Pr->UseCustomMode) {
  2906. modeflag = SiS_Pr->CModeFlag;
  2907. resinfo = 0;
  2908. } else {
  2909. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  2910. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  2911. #ifdef SIS315H
  2912. resinfo661 = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].ROMMODEIDX661;
  2913. if( (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) &&
  2914. (SiS_Pr->SiS_SetFlag & LCDVESATiming) &&
  2915. (resinfo661 >= 0) &&
  2916. (SiS_Pr->SiS_NeedRomModeData) ) {
  2917. if((ROMAddr = GetLCDStructPtr661(SiS_Pr, HwInfo))) {
  2918. if((romptr = (SISGETROMW(21)))) {
  2919. romptr += (resinfo661 * 10);
  2920. ROMAddr = HwInfo->pjVirtualRomBase;
  2921. }
  2922. }
  2923. }
  2924. #endif
  2925. }
  2926. SiS_Pr->SiS_NewFlickerMode = 0;
  2927. SiS_Pr->SiS_RVBHRS = 50;
  2928. SiS_Pr->SiS_RY1COE = 0;
  2929. SiS_Pr->SiS_RY2COE = 0;
  2930. SiS_Pr->SiS_RY3COE = 0;
  2931. SiS_Pr->SiS_RY4COE = 0;
  2932. SiS_GetCRT2ResInfo(SiS_Pr,ModeNo,ModeIdIndex,HwInfo);
  2933. if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC){
  2934. if(SiS_Pr->UseCustomMode) {
  2935. SiS_Pr->SiS_RVBHCMAX = 1;
  2936. SiS_Pr->SiS_RVBHCFACT = 1;
  2937. SiS_Pr->SiS_VGAHT = SiS_Pr->CHTotal;
  2938. SiS_Pr->SiS_VGAVT = SiS_Pr->CVTotal;
  2939. SiS_Pr->SiS_HT = SiS_Pr->CHTotal;
  2940. SiS_Pr->SiS_VT = SiS_Pr->CVTotal;
  2941. SiS_Pr->SiS_HDE = SiS_Pr->SiS_VGAHDE;
  2942. SiS_Pr->SiS_VDE = SiS_Pr->SiS_VGAVDE;
  2943. } else {
  2944. SiS_GetRAMDAC2DATA(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex, HwInfo);
  2945. }
  2946. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  2947. SiS_GetCRT2Ptr(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex,
  2948. &CRT2Index,&ResIndex,HwInfo);
  2949. switch(CRT2Index) {
  2950. case 2: TVPtr = SiS_Pr->SiS_ExtHiTVData; break;
  2951. case 3: TVPtr = SiS_Pr->SiS_ExtPALData; break;
  2952. case 4: TVPtr = SiS_Pr->SiS_ExtNTSCData; break;
  2953. case 5: TVPtr = SiS_Pr->SiS_Ext525iData; break;
  2954. case 6: TVPtr = SiS_Pr->SiS_Ext525pData; break;
  2955. case 7: TVPtr = SiS_Pr->SiS_Ext750pData; break;
  2956. case 8: TVPtr = SiS_Pr->SiS_StPALData; break;
  2957. case 9: TVPtr = SiS_Pr->SiS_StNTSCData; break;
  2958. case 10: TVPtr = SiS_Pr->SiS_St525iData; break;
  2959. case 11: TVPtr = SiS_Pr->SiS_St525pData; break;
  2960. case 12: TVPtr = SiS_Pr->SiS_St750pData; break;
  2961. case 13: TVPtr = SiS_Pr->SiS_St1HiTVData; break;
  2962. case 14: TVPtr = SiS_Pr->SiS_St2HiTVData; break;
  2963. default: TVPtr = SiS_Pr->SiS_StPALData; break;
  2964. }
  2965. SiS_Pr->SiS_RVBHCMAX = (TVPtr+ResIndex)->RVBHCMAX;
  2966. SiS_Pr->SiS_RVBHCFACT = (TVPtr+ResIndex)->RVBHCFACT;
  2967. SiS_Pr->SiS_VGAHT = (TVPtr+ResIndex)->VGAHT;
  2968. SiS_Pr->SiS_VGAVT = (TVPtr+ResIndex)->VGAVT;
  2969. SiS_Pr->SiS_HDE = (TVPtr+ResIndex)->TVHDE;
  2970. SiS_Pr->SiS_VDE = (TVPtr+ResIndex)->TVVDE;
  2971. SiS_Pr->SiS_RVBHRS = (TVPtr+ResIndex)->RVBHRS;
  2972. SiS_Pr->SiS_NewFlickerMode = (TVPtr+ResIndex)->FlickerMode;
  2973. if(modeflag & HalfDCLK) {
  2974. SiS_Pr->SiS_RVBHRS = (TVPtr+ResIndex)->HALFRVBHRS;
  2975. }
  2976. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  2977. if((resinfo == SIS_RI_1024x768) ||
  2978. (resinfo == SIS_RI_1280x1024) ||
  2979. (resinfo == SIS_RI_1280x720)) {
  2980. SiS_Pr->SiS_NewFlickerMode = 0x40;
  2981. }
  2982. if(SiS_Pr->SiS_VGAVDE == 350) SiS_Pr->SiS_TVMode |= TVSetTVSimuMode;
  2983. SiS_Pr->SiS_HT = ExtHiTVHT;
  2984. SiS_Pr->SiS_VT = ExtHiTVVT;
  2985. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  2986. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) {
  2987. SiS_Pr->SiS_HT = StHiTVHT;
  2988. SiS_Pr->SiS_VT = StHiTVVT;
  2989. #if 0
  2990. if(!(modeflag & Charx8Dot)) {
  2991. SiS_Pr->SiS_HT = StHiTextTVHT;
  2992. SiS_Pr->SiS_VT = StHiTextTVVT;
  2993. }
  2994. #endif
  2995. }
  2996. }
  2997. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  2998. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) {
  2999. SiS_Pr->SiS_HT = 1650;
  3000. SiS_Pr->SiS_VT = 750;
  3001. } else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) {
  3002. SiS_Pr->SiS_HT = NTSCHT;
  3003. SiS_Pr->SiS_VT = NTSCVT;
  3004. } else {
  3005. SiS_Pr->SiS_HT = NTSCHT;
  3006. if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) SiS_Pr->SiS_HT = NTSC2HT;
  3007. SiS_Pr->SiS_VT = NTSCVT;
  3008. }
  3009. } else {
  3010. SiS_Pr->SiS_RY1COE = (TVPtr+ResIndex)->RY1COE;
  3011. SiS_Pr->SiS_RY2COE = (TVPtr+ResIndex)->RY2COE;
  3012. SiS_Pr->SiS_RY3COE = (TVPtr+ResIndex)->RY3COE;
  3013. SiS_Pr->SiS_RY4COE = (TVPtr+ResIndex)->RY4COE;
  3014. if(modeflag & HalfDCLK) {
  3015. SiS_Pr->SiS_RY1COE = 0x00;
  3016. SiS_Pr->SiS_RY2COE = 0xf4;
  3017. SiS_Pr->SiS_RY3COE = 0x10;
  3018. SiS_Pr->SiS_RY4COE = 0x38;
  3019. }
  3020. if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) {
  3021. SiS_Pr->SiS_HT = NTSCHT;
  3022. if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) SiS_Pr->SiS_HT = NTSC2HT;
  3023. SiS_Pr->SiS_VT = NTSCVT;
  3024. } else {
  3025. SiS_Pr->SiS_HT = PALHT;
  3026. SiS_Pr->SiS_VT = PALVT;
  3027. }
  3028. }
  3029. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  3030. SiS_Pr->SiS_RVBHCMAX = 1;
  3031. SiS_Pr->SiS_RVBHCFACT = 1;
  3032. if(SiS_Pr->UseCustomMode) {
  3033. SiS_Pr->SiS_VGAHT = SiS_Pr->CHTotal;
  3034. SiS_Pr->SiS_VGAVT = SiS_Pr->CVTotal;
  3035. SiS_Pr->SiS_HT = SiS_Pr->CHTotal;
  3036. SiS_Pr->SiS_VT = SiS_Pr->CVTotal;
  3037. SiS_Pr->SiS_HDE = SiS_Pr->SiS_VGAHDE;
  3038. SiS_Pr->SiS_VDE = SiS_Pr->SiS_VGAVDE;
  3039. } else {
  3040. BOOLEAN gotit = FALSE;
  3041. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
  3042. SiS_Pr->SiS_VGAHT = SiS_Pr->PanelHT;
  3043. SiS_Pr->SiS_VGAVT = SiS_Pr->PanelVT;
  3044. SiS_Pr->SiS_HT = SiS_Pr->PanelHT;
  3045. SiS_Pr->SiS_VT = SiS_Pr->PanelVT;
  3046. gotit = TRUE;
  3047. } else if( (!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) && (romptr) && (ROMAddr) ) {
  3048. #ifdef SIS315H
  3049. SiS_Pr->SiS_RVBHCMAX = ROMAddr[romptr];
  3050. SiS_Pr->SiS_RVBHCFACT = ROMAddr[romptr+1];
  3051. SiS_Pr->SiS_VGAHT = ROMAddr[romptr+2] | ((ROMAddr[romptr+3] & 0x0f) << 8);
  3052. SiS_Pr->SiS_VGAVT = ROMAddr[romptr+4] | ((ROMAddr[romptr+3] & 0xf0) << 4);
  3053. SiS_Pr->SiS_HT = ROMAddr[romptr+5] | ((ROMAddr[romptr+6] & 0x0f) << 8);
  3054. SiS_Pr->SiS_VT = ROMAddr[romptr+7] | ((ROMAddr[romptr+6] & 0xf0) << 4);
  3055. if(SiS_Pr->SiS_VGAHT) gotit = TRUE;
  3056. else {
  3057. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  3058. SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  3059. SiS_Pr->SiS_VGAHT = SiS_Pr->PanelHT;
  3060. SiS_Pr->SiS_VGAVT = SiS_Pr->PanelVT;
  3061. SiS_Pr->SiS_HT = SiS_Pr->PanelHT;
  3062. SiS_Pr->SiS_VT = SiS_Pr->PanelVT;
  3063. gotit = TRUE;
  3064. }
  3065. #endif
  3066. }
  3067. if(!gotit) {
  3068. SiS_GetCRT2Ptr(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex,
  3069. &CRT2Index,&ResIndex,HwInfo);
  3070. switch(CRT2Index) {
  3071. case Panel_1024x768 : LCDPtr = SiS_Pr->SiS_ExtLCD1024x768Data; break;
  3072. case Panel_1024x768 + 32: LCDPtr = SiS_Pr->SiS_St2LCD1024x768Data; break;
  3073. case Panel_1280x720 :
  3074. case Panel_1280x720 + 32: LCDPtr = SiS_Pr->SiS_LCD1280x720Data; break;
  3075. case Panel_1280x768_2 : LCDPtr = SiS_Pr->SiS_ExtLCD1280x768_2Data; break;
  3076. case Panel_1280x768_2+ 32: LCDPtr = SiS_Pr->SiS_StLCD1280x768_2Data; break;
  3077. case Panel_1280x800 :
  3078. case Panel_1280x800 + 32: LCDPtr = SiS_Pr->SiS_LCD1280x800Data; break;
  3079. case Panel_1280x800_2 :
  3080. case Panel_1280x800_2+ 32: LCDPtr = SiS_Pr->SiS_LCD1280x800_2Data; break;
  3081. case Panel_1280x960 :
  3082. case Panel_1280x960 + 32: LCDPtr = SiS_Pr->SiS_LCD1280x960Data; break;
  3083. case Panel_1280x1024 : LCDPtr = SiS_Pr->SiS_ExtLCD1280x1024Data; break;
  3084. case Panel_1280x1024 + 32: LCDPtr = SiS_Pr->SiS_St2LCD1280x1024Data; break;
  3085. case Panel_1400x1050 : LCDPtr = SiS_Pr->SiS_ExtLCD1400x1050Data; break;
  3086. case Panel_1400x1050 + 32: LCDPtr = SiS_Pr->SiS_StLCD1400x1050Data; break;
  3087. case Panel_1600x1200 : LCDPtr = SiS_Pr->SiS_ExtLCD1600x1200Data; break;
  3088. case Panel_1600x1200 + 32: LCDPtr = SiS_Pr->SiS_StLCD1600x1200Data; break;
  3089. case Panel_1680x1050 :
  3090. case Panel_1680x1050 + 32: LCDPtr = SiS_Pr->SiS_LCD1680x1050Data; break;
  3091. case 100 : LCDPtr = SiS_Pr->SiS_NoScaleData; break;
  3092. #ifdef SIS315H
  3093. case 200 : LCDPtr = SiS310_ExtCompaq1280x1024Data; break;
  3094. case 201 : LCDPtr = SiS_Pr->SiS_St2LCD1280x1024Data; break;
  3095. #endif
  3096. default : LCDPtr = SiS_Pr->SiS_ExtLCD1024x768Data; break;
  3097. }
  3098. #ifdef TWDEBUG
  3099. xf86DrvMsg(0, X_INFO, "GetCRT2Data: Index %d ResIndex %d\n", CRT2Index, ResIndex);
  3100. #endif
  3101. SiS_Pr->SiS_RVBHCMAX = (LCDPtr+ResIndex)->RVBHCMAX;
  3102. SiS_Pr->SiS_RVBHCFACT = (LCDPtr+ResIndex)->RVBHCFACT;
  3103. SiS_Pr->SiS_VGAHT = (LCDPtr+ResIndex)->VGAHT;
  3104. SiS_Pr->SiS_VGAVT = (LCDPtr+ResIndex)->VGAVT;
  3105. SiS_Pr->SiS_HT = (LCDPtr+ResIndex)->LCDHT;
  3106. SiS_Pr->SiS_VT = (LCDPtr+ResIndex)->LCDVT;
  3107. }
  3108. tempax = SiS_Pr->PanelXRes;
  3109. tempbx = SiS_Pr->PanelYRes;
  3110. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  3111. if(SiS_Pr->SiS_SetFlag & LCDVESATiming) {
  3112. if(HwInfo->jChipType < SIS_315H) {
  3113. if (SiS_Pr->SiS_VGAVDE == 350) tempbx = 560;
  3114. else if(SiS_Pr->SiS_VGAVDE == 400) tempbx = 640;
  3115. }
  3116. } else {
  3117. if (SiS_Pr->SiS_VGAVDE == 357) tempbx = 527;
  3118. else if(SiS_Pr->SiS_VGAVDE == 420) tempbx = 620;
  3119. else if(SiS_Pr->SiS_VGAVDE == 525) tempbx = 775;
  3120. else if(SiS_Pr->SiS_VGAVDE == 600) tempbx = 775;
  3121. else if(SiS_Pr->SiS_VGAVDE == 350) tempbx = 560;
  3122. else if(SiS_Pr->SiS_VGAVDE == 400) tempbx = 640;
  3123. }
  3124. } else if(SiS_Pr->SiS_LCDResInfo == Panel_1280x960) {
  3125. if (SiS_Pr->SiS_VGAVDE == 350) tempbx = 700;
  3126. else if(SiS_Pr->SiS_VGAVDE == 400) tempbx = 800;
  3127. else if(SiS_Pr->SiS_VGAVDE == 1024) tempbx = 960;
  3128. } else if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) {
  3129. if (SiS_Pr->SiS_VGAVDE == 360) tempbx = 768;
  3130. else if(SiS_Pr->SiS_VGAVDE == 375) tempbx = 800;
  3131. else if(SiS_Pr->SiS_VGAVDE == 405) tempbx = 864;
  3132. } else if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) {
  3133. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
  3134. if (SiS_Pr->SiS_VGAVDE == 350) tempbx = 875;
  3135. else if(SiS_Pr->SiS_VGAVDE == 400) tempbx = 1000;
  3136. }
  3137. }
  3138. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  3139. tempax = SiS_Pr->SiS_VGAHDE;
  3140. tempbx = SiS_Pr->SiS_VGAVDE;
  3141. }
  3142. SiS_Pr->SiS_HDE = tempax;
  3143. SiS_Pr->SiS_VDE = tempbx;
  3144. }
  3145. }
  3146. }
  3147. static void
  3148. SiS_GetCRT2Data(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
  3149. USHORT RefreshRateTableIndex, PSIS_HW_INFO HwInfo)
  3150. {
  3151. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  3152. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  3153. SiS_GetCRT2DataLVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex, HwInfo);
  3154. } else {
  3155. if((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) {
  3156. /* Need LVDS Data for LCD on 301B-DH */
  3157. SiS_GetCRT2DataLVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex, HwInfo);
  3158. } else {
  3159. SiS_GetCRT2Data301(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex, HwInfo);
  3160. }
  3161. }
  3162. } else {
  3163. SiS_GetCRT2DataLVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex, HwInfo);
  3164. }
  3165. }
  3166. /*********************************************/
  3167. /* GET LVDS DES (SKEW) DATA */
  3168. /*********************************************/
  3169. static void
  3170. SiS_GetLVDSDesPtr(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
  3171. USHORT RefreshRateTableIndex, USHORT *PanelIndex,
  3172. USHORT *ResIndex, PSIS_HW_INFO HwInfo)
  3173. {
  3174. USHORT modeflag;
  3175. if(ModeNo <= 0x13) {
  3176. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  3177. (*ResIndex) = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  3178. } else {
  3179. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  3180. (*ResIndex) = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  3181. }
  3182. (*ResIndex) &= 0x1F;
  3183. (*PanelIndex) = 0;
  3184. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  3185. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  3186. (*PanelIndex) = 50;
  3187. if((SiS_Pr->SiS_TVMode & TVSetPAL) && (!(SiS_Pr->SiS_TVMode & TVSetPALM))) (*PanelIndex) += 2;
  3188. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) (*PanelIndex) += 1;
  3189. /* Nothing special needed for SOverscan */
  3190. /* PALM uses NTSC data, PALN uses PAL data */
  3191. }
  3192. }
  3193. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  3194. *PanelIndex = SiS_Pr->SiS_LCDTypeInfo;
  3195. if(HwInfo->jChipType >= SIS_661) {
  3196. /* As long as we don's use the BIOS tables, we
  3197. * need to convert the TypeInfo as for 315 series
  3198. */
  3199. (*PanelIndex) = SiS_Pr->SiS_LCDResInfo - 1;
  3200. }
  3201. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  3202. (*PanelIndex) += 16;
  3203. if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
  3204. (*PanelIndex) = 32;
  3205. if(modeflag & HalfDCLK) (*PanelIndex)++;
  3206. }
  3207. }
  3208. }
  3209. if(SiS_Pr->SiS_SetFlag & SetDOSMode) {
  3210. if(SiS_Pr->SiS_LCDResInfo != Panel_640x480) {
  3211. (*ResIndex) = 7;
  3212. if(HwInfo->jChipType < SIS_315H) {
  3213. if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x80) (*ResIndex)++;
  3214. }
  3215. }
  3216. }
  3217. }
  3218. static void
  3219. SiS_GetLVDSDesData(SiS_Private *SiS_Pr, USHORT ModeNo,USHORT ModeIdIndex,
  3220. USHORT RefreshRateTableIndex, PSIS_HW_INFO HwInfo)
  3221. {
  3222. USHORT modeflag;
  3223. USHORT PanelIndex,ResIndex;
  3224. const SiS_LVDSDesStruct *PanelDesPtr = NULL;
  3225. SiS_Pr->SiS_LCDHDES = 0;
  3226. SiS_Pr->SiS_LCDVDES = 0;
  3227. if( (SiS_Pr->UseCustomMode) ||
  3228. (SiS_Pr->SiS_LCDResInfo == Panel_Custom) ||
  3229. (SiS_Pr->SiS_CustomT == CUT_PANEL848) ||
  3230. ((SiS_Pr->SiS_VBType & VB_SISVB) &&
  3231. (SiS_Pr->SiS_LCDInfo & DontExpandLCD) &&
  3232. (SiS_Pr->SiS_LCDInfo & LCDPass11)) ) {
  3233. return;
  3234. }
  3235. if((SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  3236. #ifdef SIS315H
  3237. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  3238. /* non-pass 1:1 only, see above */
  3239. if(SiS_Pr->SiS_VGAHDE != SiS_Pr->PanelXRes) {
  3240. SiS_Pr->SiS_LCDHDES = SiS_Pr->SiS_HT - ((SiS_Pr->PanelXRes - SiS_Pr->SiS_VGAHDE) / 2);
  3241. }
  3242. if(SiS_Pr->SiS_VGAVDE != SiS_Pr->PanelYRes) {
  3243. SiS_Pr->SiS_LCDVDES = SiS_Pr->SiS_VT - ((SiS_Pr->PanelYRes - SiS_Pr->SiS_VGAVDE) / 2);
  3244. }
  3245. }
  3246. if(SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) {
  3247. switch(SiS_Pr->SiS_CustomT) {
  3248. case CUT_UNIWILL1024:
  3249. case CUT_UNIWILL10242:
  3250. case CUT_CLEVO1400:
  3251. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  3252. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3253. }
  3254. break;
  3255. }
  3256. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) {
  3257. if(SiS_Pr->SiS_CustomT != CUT_COMPAQ1280) {
  3258. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3259. }
  3260. }
  3261. }
  3262. #endif
  3263. } else {
  3264. SiS_GetLVDSDesPtr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex,
  3265. &PanelIndex, &ResIndex, HwInfo);
  3266. switch(PanelIndex) {
  3267. case 0: PanelDesPtr = SiS_Pr->SiS_PanelType00_1; break; /* --- */
  3268. case 1: PanelDesPtr = SiS_Pr->SiS_PanelType01_1; break;
  3269. case 2: PanelDesPtr = SiS_Pr->SiS_PanelType02_1; break;
  3270. case 3: PanelDesPtr = SiS_Pr->SiS_PanelType03_1; break;
  3271. case 4: PanelDesPtr = SiS_Pr->SiS_PanelType04_1; break;
  3272. case 5: PanelDesPtr = SiS_Pr->SiS_PanelType05_1; break;
  3273. case 6: PanelDesPtr = SiS_Pr->SiS_PanelType06_1; break;
  3274. case 7: PanelDesPtr = SiS_Pr->SiS_PanelType07_1; break;
  3275. case 8: PanelDesPtr = SiS_Pr->SiS_PanelType08_1; break;
  3276. case 9: PanelDesPtr = SiS_Pr->SiS_PanelType09_1; break;
  3277. case 10: PanelDesPtr = SiS_Pr->SiS_PanelType0a_1; break;
  3278. case 11: PanelDesPtr = SiS_Pr->SiS_PanelType0b_1; break;
  3279. case 12: PanelDesPtr = SiS_Pr->SiS_PanelType0c_1; break;
  3280. case 13: PanelDesPtr = SiS_Pr->SiS_PanelType0d_1; break;
  3281. case 14: PanelDesPtr = SiS_Pr->SiS_PanelType0e_1; break;
  3282. case 15: PanelDesPtr = SiS_Pr->SiS_PanelType0f_1; break;
  3283. case 16: PanelDesPtr = SiS_Pr->SiS_PanelType00_2; break; /* --- */
  3284. case 17: PanelDesPtr = SiS_Pr->SiS_PanelType01_2; break;
  3285. case 18: PanelDesPtr = SiS_Pr->SiS_PanelType02_2; break;
  3286. case 19: PanelDesPtr = SiS_Pr->SiS_PanelType03_2; break;
  3287. case 20: PanelDesPtr = SiS_Pr->SiS_PanelType04_2; break;
  3288. case 21: PanelDesPtr = SiS_Pr->SiS_PanelType05_2; break;
  3289. case 22: PanelDesPtr = SiS_Pr->SiS_PanelType06_2; break;
  3290. case 23: PanelDesPtr = SiS_Pr->SiS_PanelType07_2; break;
  3291. case 24: PanelDesPtr = SiS_Pr->SiS_PanelType08_2; break;
  3292. case 25: PanelDesPtr = SiS_Pr->SiS_PanelType09_2; break;
  3293. case 26: PanelDesPtr = SiS_Pr->SiS_PanelType0a_2; break;
  3294. case 27: PanelDesPtr = SiS_Pr->SiS_PanelType0b_2; break;
  3295. case 28: PanelDesPtr = SiS_Pr->SiS_PanelType0c_2; break;
  3296. case 29: PanelDesPtr = SiS_Pr->SiS_PanelType0d_2; break;
  3297. case 30: PanelDesPtr = SiS_Pr->SiS_PanelType0e_2; break;
  3298. case 31: PanelDesPtr = SiS_Pr->SiS_PanelType0f_2; break;
  3299. case 32: PanelDesPtr = SiS_Pr->SiS_PanelTypeNS_1; break; /* pass 1:1 */
  3300. case 33: PanelDesPtr = SiS_Pr->SiS_PanelTypeNS_2; break;
  3301. case 50: PanelDesPtr = SiS_Pr->SiS_CHTVUNTSCDesData; break; /* TV */
  3302. case 51: PanelDesPtr = SiS_Pr->SiS_CHTVONTSCDesData; break;
  3303. case 52: PanelDesPtr = SiS_Pr->SiS_CHTVUPALDesData; break;
  3304. case 53: PanelDesPtr = SiS_Pr->SiS_CHTVOPALDesData; break;
  3305. default: return;
  3306. }
  3307. SiS_Pr->SiS_LCDHDES = (PanelDesPtr+ResIndex)->LCDHDES;
  3308. SiS_Pr->SiS_LCDVDES = (PanelDesPtr+ResIndex)->LCDVDES;
  3309. if((ModeNo <= 0x13) && (SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
  3310. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  3311. if((SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  3312. if(!(modeflag & HalfDCLK)) SiS_Pr->SiS_LCDHDES = 632;
  3313. } else if(!(SiS_Pr->SiS_SetFlag & SetDOSMode)) {
  3314. if(SiS_Pr->SiS_LCDResInfo != Panel_1280x1024) {
  3315. if(SiS_Pr->SiS_LCDResInfo >= Panel_1024x768) {
  3316. if(HwInfo->jChipType < SIS_315H) {
  3317. if(!(modeflag & HalfDCLK)) SiS_Pr->SiS_LCDHDES = 320;
  3318. } else {
  3319. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) SiS_Pr->SiS_LCDHDES = 480;
  3320. if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) SiS_Pr->SiS_LCDHDES = 804;
  3321. if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) SiS_Pr->SiS_LCDHDES = 704;
  3322. if(!(modeflag & HalfDCLK)) {
  3323. SiS_Pr->SiS_LCDHDES = 320;
  3324. if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) SiS_Pr->SiS_LCDHDES = 632;
  3325. if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) SiS_Pr->SiS_LCDHDES = 542;
  3326. }
  3327. }
  3328. }
  3329. }
  3330. }
  3331. }
  3332. }
  3333. }
  3334. /*********************************************/
  3335. /* DISABLE VIDEO BRIDGE */
  3336. /*********************************************/
  3337. /* NEVER use any variables (VBInfo), this will be called
  3338. * from outside the context of modeswitch!
  3339. * MUST call getVBType before calling this
  3340. */
  3341. void
  3342. SiS_DisableBridge(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
  3343. {
  3344. #ifdef SIS315H
  3345. USHORT tempah,pushax=0,modenum;
  3346. #endif
  3347. USHORT temp=0;
  3348. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  3349. if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { /* ===== For 30xB/LV ===== */
  3350. if(HwInfo->jChipType < SIS_315H) {
  3351. #ifdef SIS300 /* 300 series */
  3352. if(!(SiS_CR36BIOSWord23b(SiS_Pr,HwInfo))) {
  3353. if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {
  3354. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFE);
  3355. } else {
  3356. SiS_SetRegSR11ANDOR(SiS_Pr,HwInfo,0xF7,0x08);
  3357. }
  3358. SiS_PanelDelay(SiS_Pr, HwInfo, 3);
  3359. }
  3360. if(SiS_Is301B(SiS_Pr)) {
  3361. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1f,0x3f);
  3362. SiS_ShortDelay(SiS_Pr,1);
  3363. }
  3364. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xDF);
  3365. SiS_DisplayOff(SiS_Pr);
  3366. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF);
  3367. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF);
  3368. SiS_UnLockCRT2(SiS_Pr,HwInfo);
  3369. if(!(SiS_Pr->SiS_VBType & VB_SIS301LV302LV)) {
  3370. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x01,0x80);
  3371. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x02,0x40);
  3372. }
  3373. if( (!(SiS_CRT2IsLCD(SiS_Pr, HwInfo))) ||
  3374. (!(SiS_CR36BIOSWord23d(SiS_Pr, HwInfo))) ) {
  3375. SiS_PanelDelay(SiS_Pr, HwInfo, 2);
  3376. if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {
  3377. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFD);
  3378. } else {
  3379. SiS_SetRegSR11ANDOR(SiS_Pr,HwInfo,0xFB,0x04);
  3380. }
  3381. }
  3382. #endif /* SIS300 */
  3383. } else {
  3384. #ifdef SIS315H /* 315 series */
  3385. BOOLEAN custom1 = ((SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) ||
  3386. (SiS_Pr->SiS_CustomT == CUT_CLEVO1400)) ? TRUE : FALSE;
  3387. modenum = SiS_GetReg(SiS_Pr->SiS_P3d4,0x34) & 0x7f;
  3388. if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {
  3389. #ifdef SET_EMI
  3390. if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV)) {
  3391. if(SiS_Pr->SiS_CustomT != CUT_CLEVO1400) {
  3392. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
  3393. }
  3394. }
  3395. #endif
  3396. if( (modenum <= 0x13) ||
  3397. (SiS_IsVAMode(SiS_Pr,HwInfo)) ||
  3398. (!(SiS_IsDualEdge(SiS_Pr,HwInfo))) ) {
  3399. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFE);
  3400. if(custom1) SiS_PanelDelay(SiS_Pr, HwInfo, 3);
  3401. }
  3402. if(!custom1) {
  3403. SiS_DDC2Delay(SiS_Pr,0xff00);
  3404. SiS_DDC2Delay(SiS_Pr,0xe000);
  3405. SiS_SetRegByte(SiS_Pr->SiS_P3c6,0x00);
  3406. pushax = SiS_GetReg(SiS_Pr->SiS_P3c4,0x06);
  3407. if(IS_SIS740) {
  3408. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x06,0xE3);
  3409. }
  3410. SiS_PanelDelay(SiS_Pr, HwInfo, 3);
  3411. }
  3412. }
  3413. if(!(SiS_IsNotM650orLater(SiS_Pr, HwInfo))) {
  3414. if(HwInfo->jChipType < SIS_340) {
  3415. tempah = 0xef;
  3416. if(SiS_IsVAMode(SiS_Pr,HwInfo)) tempah = 0xf7;
  3417. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x4c,tempah);
  3418. }
  3419. }
  3420. if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {
  3421. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1F,~0x10);
  3422. }
  3423. tempah = 0x3f;
  3424. if(SiS_IsDualEdge(SiS_Pr,HwInfo)) {
  3425. tempah = 0x7f;
  3426. if(!(SiS_IsVAMode(SiS_Pr,HwInfo))) tempah = 0xbf;
  3427. }
  3428. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1F,tempah);
  3429. if((SiS_IsVAMode(SiS_Pr,HwInfo)) ||
  3430. ((SiS_Pr->SiS_VBType & VB_SIS301LV302LV) && (modenum <= 0x13))) {
  3431. SiS_DisplayOff(SiS_Pr);
  3432. if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {
  3433. SiS_PanelDelay(SiS_Pr, HwInfo, 2);
  3434. }
  3435. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF);
  3436. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1E,0xDF);
  3437. }
  3438. if((!(SiS_IsVAMode(SiS_Pr,HwInfo))) ||
  3439. ((SiS_Pr->SiS_VBType & VB_SIS301LV302LV) && (modenum <= 0x13))) {
  3440. if(!(SiS_IsDualEdge(SiS_Pr,HwInfo))) {
  3441. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xdf);
  3442. SiS_DisplayOff(SiS_Pr);
  3443. }
  3444. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x80);
  3445. if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {
  3446. SiS_PanelDelay(SiS_Pr, HwInfo, 2);
  3447. }
  3448. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF);
  3449. temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00);
  3450. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x10);
  3451. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF);
  3452. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,temp);
  3453. }
  3454. if(SiS_IsNotM650orLater(SiS_Pr,HwInfo)) {
  3455. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0x7f);
  3456. }
  3457. if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {
  3458. if(!custom1) {
  3459. if(!(SiS_IsVAMode(SiS_Pr,HwInfo))) {
  3460. if(!(SiS_CRT2IsLCD(SiS_Pr,HwInfo))) {
  3461. if(!(SiS_IsDualEdge(SiS_Pr,HwInfo))) {
  3462. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFD);
  3463. }
  3464. }
  3465. }
  3466. SiS_SetReg(SiS_Pr->SiS_P3c4,0x06,pushax);
  3467. if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV)) {
  3468. if(SiS_IsVAorLCD(SiS_Pr, HwInfo)) {
  3469. SiS_PanelDelayLoop(SiS_Pr, HwInfo, 3, 20);
  3470. }
  3471. }
  3472. } else {
  3473. if((SiS_IsVAMode(SiS_Pr,HwInfo)) ||
  3474. (!(SiS_IsDualEdge(SiS_Pr,HwInfo)))) {
  3475. if((!(SiS_WeHaveBacklightCtrl(SiS_Pr, HwInfo))) ||
  3476. (!(SiS_CRT2IsLCD(SiS_Pr, HwInfo)))) {
  3477. SiS_PanelDelay(SiS_Pr, HwInfo, 2);
  3478. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFD);
  3479. SiS_PanelDelay(SiS_Pr, HwInfo, 4);
  3480. }
  3481. }
  3482. }
  3483. }
  3484. #endif /* SIS315H */
  3485. }
  3486. } else { /* ============ For 301 ================ */
  3487. if(HwInfo->jChipType < SIS_315H) {
  3488. #ifdef SIS300
  3489. if(!(SiS_CR36BIOSWord23b(SiS_Pr,HwInfo))) {
  3490. SiS_SetRegSR11ANDOR(SiS_Pr,HwInfo,0xF7,0x08);
  3491. SiS_PanelDelay(SiS_Pr, HwInfo, 3);
  3492. }
  3493. #endif
  3494. }
  3495. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xDF); /* disable VB */
  3496. SiS_DisplayOff(SiS_Pr);
  3497. if(HwInfo->jChipType >= SIS_315H) {
  3498. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x80);
  3499. }
  3500. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF); /* disable lock mode */
  3501. if(HwInfo->jChipType >= SIS_315H) {
  3502. temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00);
  3503. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x10);
  3504. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);
  3505. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,temp);
  3506. } else {
  3507. #ifdef SIS300
  3508. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF); /* disable CRT2 */
  3509. if( (!(SiS_CRT2IsLCD(SiS_Pr, HwInfo))) ||
  3510. (!(SiS_CR36BIOSWord23d(SiS_Pr,HwInfo))) ) {
  3511. SiS_PanelDelay(SiS_Pr, HwInfo, 2);
  3512. SiS_SetRegSR11ANDOR(SiS_Pr,HwInfo,0xFB,0x04);
  3513. }
  3514. #endif
  3515. }
  3516. }
  3517. } else { /* ============ For LVDS =============*/
  3518. if(HwInfo->jChipType < SIS_315H) {
  3519. #ifdef SIS300 /* 300 series */
  3520. if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) {
  3521. SiS_SetCH700x(SiS_Pr,0x090E);
  3522. }
  3523. if(HwInfo->jChipType == SIS_730) {
  3524. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x11) & 0x08)) {
  3525. SiS_WaitVBRetrace(SiS_Pr,HwInfo);
  3526. }
  3527. if(!(SiS_CR36BIOSWord23b(SiS_Pr,HwInfo))) {
  3528. SiS_SetRegSR11ANDOR(SiS_Pr,HwInfo,0xF7,0x08);
  3529. SiS_PanelDelay(SiS_Pr, HwInfo, 3);
  3530. }
  3531. } else {
  3532. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x11) & 0x08)) {
  3533. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x40)) {
  3534. if(!(SiS_CR36BIOSWord23b(SiS_Pr,HwInfo))) {
  3535. SiS_WaitVBRetrace(SiS_Pr,HwInfo);
  3536. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x06) & 0x1c)) {
  3537. SiS_DisplayOff(SiS_Pr);
  3538. }
  3539. SiS_SetRegSR11ANDOR(SiS_Pr,HwInfo,0xF7,0x08);
  3540. SiS_PanelDelay(SiS_Pr, HwInfo, 3);
  3541. }
  3542. }
  3543. }
  3544. }
  3545. SiS_DisplayOff(SiS_Pr);
  3546. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF);
  3547. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF);
  3548. SiS_UnLockCRT2(SiS_Pr,HwInfo);
  3549. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x01,0x80);
  3550. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x02,0x40);
  3551. if( (!(SiS_CRT2IsLCD(SiS_Pr, HwInfo))) ||
  3552. (!(SiS_CR36BIOSWord23d(SiS_Pr,HwInfo))) ) {
  3553. SiS_PanelDelay(SiS_Pr, HwInfo, 2);
  3554. SiS_SetRegSR11ANDOR(SiS_Pr,HwInfo,0xFB,0x04);
  3555. }
  3556. #endif /* SIS300 */
  3557. } else {
  3558. #ifdef SIS315H /* 315 series */
  3559. if(!(SiS_IsNotM650orLater(SiS_Pr,HwInfo))) {
  3560. if(HwInfo->jChipType < SIS_340) {
  3561. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x4c,~0x18);
  3562. }
  3563. }
  3564. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  3565. if(HwInfo->jChipType == SIS_740) {
  3566. temp = SiS_GetCH701x(SiS_Pr,0x61);
  3567. if(temp < 1) {
  3568. SiS_SetCH701x(SiS_Pr,0xac76);
  3569. SiS_SetCH701x(SiS_Pr,0x0066);
  3570. }
  3571. if( (!(SiS_IsDualEdge(SiS_Pr,HwInfo))) ||
  3572. (SiS_IsTVOrYPbPrOrScart(SiS_Pr,HwInfo)) ) {
  3573. SiS_SetCH701x(SiS_Pr,0x3e49);
  3574. }
  3575. }
  3576. if( (!(SiS_IsDualEdge(SiS_Pr,HwInfo))) ||
  3577. (SiS_IsVAMode(SiS_Pr,HwInfo)) ) {
  3578. SiS_Chrontel701xBLOff(SiS_Pr);
  3579. SiS_Chrontel701xOff(SiS_Pr,HwInfo);
  3580. }
  3581. if(HwInfo->jChipType != SIS_740) {
  3582. if( (!(SiS_IsDualEdge(SiS_Pr,HwInfo))) ||
  3583. (SiS_IsTVOrYPbPrOrScart(SiS_Pr,HwInfo)) ) {
  3584. SiS_SetCH701x(SiS_Pr,0x0149);
  3585. }
  3586. }
  3587. }
  3588. if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
  3589. SiS_SetRegSR11ANDOR(SiS_Pr,HwInfo,0xF7,0x08);
  3590. SiS_PanelDelay(SiS_Pr, HwInfo, 3);
  3591. }
  3592. if( (SiS_Pr->SiS_IF_DEF_CH70xx == 0) ||
  3593. (!(SiS_IsDualEdge(SiS_Pr,HwInfo))) ||
  3594. (!(SiS_IsTVOrYPbPrOrScart(SiS_Pr,HwInfo))) ) {
  3595. SiS_DisplayOff(SiS_Pr);
  3596. }
  3597. if( (SiS_Pr->SiS_IF_DEF_CH70xx == 0) ||
  3598. (!(SiS_IsDualEdge(SiS_Pr,HwInfo))) ||
  3599. (!(SiS_IsVAMode(SiS_Pr,HwInfo))) ) {
  3600. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x80);
  3601. }
  3602. if(HwInfo->jChipType == SIS_740) {
  3603. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0x7f);
  3604. }
  3605. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF);
  3606. if( (SiS_Pr->SiS_IF_DEF_CH70xx == 0) ||
  3607. (!(SiS_IsDualEdge(SiS_Pr,HwInfo))) ||
  3608. (!(SiS_IsVAMode(SiS_Pr,HwInfo))) ) {
  3609. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF);
  3610. }
  3611. if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
  3612. if(SiS_CRT2IsLCD(SiS_Pr, HwInfo)) {
  3613. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xdf);
  3614. if(HwInfo->jChipType == SIS_550) {
  3615. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xbf);
  3616. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xef);
  3617. }
  3618. }
  3619. } else {
  3620. if(HwInfo->jChipType == SIS_740) {
  3621. if(SiS_IsLCDOrLCDA(SiS_Pr,HwInfo)) {
  3622. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xdf);
  3623. }
  3624. } else if(SiS_IsVAMode(SiS_Pr,HwInfo)) {
  3625. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xdf);
  3626. }
  3627. }
  3628. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  3629. if(SiS_IsDualEdge(SiS_Pr,HwInfo)) {
  3630. /* SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xff); */
  3631. } else {
  3632. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xfb);
  3633. }
  3634. }
  3635. SiS_UnLockCRT2(SiS_Pr,HwInfo);
  3636. if(HwInfo->jChipType == SIS_550) {
  3637. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x01,0x80); /* DirectDVD PAL?*/
  3638. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x02,0x40); /* VB clock / 4 ? */
  3639. } else if( (SiS_Pr->SiS_IF_DEF_CH70xx == 0) ||
  3640. (!(SiS_IsDualEdge(SiS_Pr,HwInfo))) ||
  3641. (!(SiS_IsVAMode(SiS_Pr,HwInfo))) ) {
  3642. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0xf7);
  3643. }
  3644. if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
  3645. if(SiS_CRT2IsLCD(SiS_Pr, HwInfo)) {
  3646. if(!(SiS_WeHaveBacklightCtrl(SiS_Pr,HwInfo))) {
  3647. SiS_PanelDelay(SiS_Pr, HwInfo, 2);
  3648. SiS_SetRegSR11ANDOR(SiS_Pr,HwInfo,0xFB,0x04);
  3649. }
  3650. }
  3651. }
  3652. #endif /* SIS315H */
  3653. } /* 315 series */
  3654. } /* LVDS */
  3655. }
  3656. /*********************************************/
  3657. /* ENABLE VIDEO BRIDGE */
  3658. /*********************************************/
  3659. /* NEVER use any variables (VBInfo), this will be called
  3660. * from outside the context of a mode switch!
  3661. * MUST call getVBType before calling this
  3662. */
  3663. static void
  3664. SiS_EnableBridge(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
  3665. {
  3666. USHORT temp=0,tempah;
  3667. #ifdef SIS315H
  3668. USHORT temp1,pushax=0;
  3669. BOOLEAN delaylong = FALSE;
  3670. #endif
  3671. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  3672. if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { /* ====== For 301B et al ====== */
  3673. if(HwInfo->jChipType < SIS_315H) {
  3674. #ifdef SIS300 /* 300 series */
  3675. if(SiS_CRT2IsLCD(SiS_Pr, HwInfo)) {
  3676. if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {
  3677. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x02);
  3678. } else if(SiS_Pr->SiS_VBType & VB_NoLCD) {
  3679. SiS_SetRegSR11ANDOR(SiS_Pr,HwInfo,0xFB,0x00);
  3680. }
  3681. if(SiS_Pr->SiS_VBType & (VB_SIS301LV302LV | VB_NoLCD)) {
  3682. if(!(SiS_CR36BIOSWord23d(SiS_Pr, HwInfo))) {
  3683. SiS_PanelDelay(SiS_Pr, HwInfo, 0);
  3684. }
  3685. }
  3686. }
  3687. if((SiS_Pr->SiS_VBType & VB_NoLCD) &&
  3688. (SiS_CRT2IsLCD(SiS_Pr, HwInfo))) {
  3689. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20); /* Enable CRT2 */
  3690. SiS_DisplayOn(SiS_Pr);
  3691. SiS_UnLockCRT2(SiS_Pr,HwInfo);
  3692. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x02,0xBF);
  3693. if(SiS_BridgeInSlavemode(SiS_Pr)) {
  3694. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x01,0x1F);
  3695. } else {
  3696. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x01,0x1F,0x40);
  3697. }
  3698. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x40)) {
  3699. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x16) & 0x10)) {
  3700. if(!(SiS_CR36BIOSWord23b(SiS_Pr,HwInfo))) {
  3701. SiS_PanelDelay(SiS_Pr, HwInfo, 1);
  3702. }
  3703. SiS_WaitVBRetrace(SiS_Pr,HwInfo);
  3704. SiS_SetRegSR11ANDOR(SiS_Pr,HwInfo,0xF7,0x00);
  3705. }
  3706. }
  3707. } else {
  3708. temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x32) & 0xDF; /* lock mode */
  3709. if(SiS_BridgeInSlavemode(SiS_Pr)) {
  3710. tempah = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  3711. if(!(tempah & SetCRT2ToRAMDAC)) temp |= 0x20;
  3712. }
  3713. SiS_SetReg(SiS_Pr->SiS_P3c4,0x32,temp);
  3714. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);
  3715. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x00,0x1F,0x20); /* enable VB processor */
  3716. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x1F,0xC0);
  3717. SiS_DisplayOn(SiS_Pr);
  3718. if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {
  3719. if(SiS_CRT2IsLCD(SiS_Pr, HwInfo)) {
  3720. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x16) & 0x10)) {
  3721. if(!(SiS_CR36BIOSWord23b(SiS_Pr,HwInfo))) {
  3722. SiS_PanelDelay(SiS_Pr, HwInfo, 1);
  3723. }
  3724. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x01);
  3725. }
  3726. }
  3727. }
  3728. }
  3729. #endif /* SIS300 */
  3730. } else {
  3731. #ifdef SIS315H /* 315 series */
  3732. #ifdef SET_EMI
  3733. UCHAR r30=0, r31=0, r32=0, r33=0, cr36=0;
  3734. /* USHORT emidelay=0; */
  3735. #endif
  3736. if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {
  3737. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1f,0xef);
  3738. #ifdef SET_EMI
  3739. if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV)) {
  3740. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
  3741. }
  3742. #endif
  3743. }
  3744. if(!(SiS_IsNotM650orLater(SiS_Pr, HwInfo))) {
  3745. if(HwInfo->jChipType < SIS_340) {
  3746. tempah = 0x10;
  3747. if(SiS_LCDAEnabled(SiS_Pr, HwInfo)) {
  3748. if(SiS_TVEnabled(SiS_Pr, HwInfo)) tempah = 0x18;
  3749. else tempah = 0x08;
  3750. }
  3751. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x4c,tempah);
  3752. }
  3753. }
  3754. if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {
  3755. SiS_SetRegByte(SiS_Pr->SiS_P3c6,0x00);
  3756. SiS_DisplayOff(SiS_Pr);
  3757. pushax = SiS_GetReg(SiS_Pr->SiS_P3c4,0x06);
  3758. if(IS_SIS740) {
  3759. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x06,0xE3);
  3760. }
  3761. if(SiS_IsVAorLCD(SiS_Pr, HwInfo)) {
  3762. if(!(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x26) & 0x02)) {
  3763. SiS_PanelDelayLoop(SiS_Pr, HwInfo, 3, 2);
  3764. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x02);
  3765. SiS_PanelDelayLoop(SiS_Pr, HwInfo, 3, 2);
  3766. if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV)) {
  3767. SiS_GenericDelay(SiS_Pr, 0x4500);
  3768. }
  3769. }
  3770. }
  3771. if(!(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & 0x40)) {
  3772. SiS_PanelDelayLoop(SiS_Pr, HwInfo, 3, 10);
  3773. delaylong = TRUE;
  3774. }
  3775. }
  3776. if(!(SiS_IsVAMode(SiS_Pr,HwInfo))) {
  3777. temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x32) & 0xDF;
  3778. if(SiS_BridgeInSlavemode(SiS_Pr)) {
  3779. tempah = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  3780. if(!(tempah & SetCRT2ToRAMDAC)) {
  3781. if(!(SiS_LCDAEnabled(SiS_Pr, HwInfo))) temp |= 0x20;
  3782. }
  3783. }
  3784. SiS_SetReg(SiS_Pr->SiS_P3c4,0x32,temp);
  3785. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20); /* enable CRT2 */
  3786. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0x7f);
  3787. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2e,0x80);
  3788. if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {
  3789. SiS_PanelDelay(SiS_Pr, HwInfo, 2);
  3790. }
  3791. } else {
  3792. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1e,0x20);
  3793. }
  3794. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x00,0x1f,0x20);
  3795. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2e,0x80);
  3796. tempah = 0xc0;
  3797. if(SiS_IsDualEdge(SiS_Pr, HwInfo)) {
  3798. tempah = 0x80;
  3799. if(!(SiS_IsVAMode(SiS_Pr, HwInfo))) tempah = 0x40;
  3800. }
  3801. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x1F,tempah);
  3802. if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {
  3803. SiS_PanelDelay(SiS_Pr, HwInfo, 2);
  3804. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x1f,0x10);
  3805. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2e,0x80);
  3806. if(SiS_Pr->SiS_CustomT != CUT_CLEVO1400) {
  3807. #ifdef SET_EMI
  3808. if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV)) {
  3809. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
  3810. SiS_GenericDelay(SiS_Pr, 0x500);
  3811. }
  3812. #endif
  3813. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x27,0x0c);
  3814. if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV)) {
  3815. #ifdef SET_EMI
  3816. cr36 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36);
  3817. if(SiS_Pr->SiS_ROMNew) {
  3818. UCHAR *ROMAddr = HwInfo->pjVirtualRomBase;
  3819. USHORT romptr = GetLCDStructPtr661_2(SiS_Pr, HwInfo);
  3820. if(romptr) {
  3821. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x30,0x20); /* Reset */
  3822. SiS_Pr->EMI_30 = 0;
  3823. SiS_Pr->EMI_31 = ROMAddr[romptr + SiS_Pr->SiS_EMIOffset + 0];
  3824. SiS_Pr->EMI_32 = ROMAddr[romptr + SiS_Pr->SiS_EMIOffset + 1];
  3825. SiS_Pr->EMI_33 = ROMAddr[romptr + SiS_Pr->SiS_EMIOffset + 2];
  3826. if(ROMAddr[romptr + 1] & 0x10) SiS_Pr->EMI_30 = 0x40;
  3827. /* emidelay = SISGETROMW((romptr + 0x22)); */
  3828. SiS_Pr->HaveEMI = SiS_Pr->HaveEMILCD = SiS_Pr->OverruleEMI = TRUE;
  3829. }
  3830. }
  3831. /* (P4_30|0x40) */
  3832. /* Compal 1400x1050: 0x05, 0x60, 0x00 YES (1.10.7w; CR36=69) */
  3833. /* Compal 1400x1050: 0x0d, 0x70, 0x40 YES (1.10.7x; CR36=69) */
  3834. /* Acer 1280x1024: 0x12, 0xd0, 0x6b NO (1.10.9k; CR36=73) */
  3835. /* Compaq 1280x1024: 0x0d, 0x70, 0x6b YES (1.12.04b; CR36=03) */
  3836. /* Clevo 1024x768: 0x05, 0x60, 0x33 NO (1.10.8e; CR36=12, DL!) */
  3837. /* Clevo 1024x768: 0x0d, 0x70, 0x40 (if type == 3) YES (1.10.8y; CR36=?2) */
  3838. /* Clevo 1024x768: 0x05, 0x60, 0x33 (if type != 3) YES (1.10.8y; CR36=?2) */
  3839. /* Asus 1024x768: ? ? (1.10.8o; CR36=?2) */
  3840. /* Asus 1024x768: 0x08, 0x10, 0x3c (problematic) YES (1.10.8q; CR36=22) */
  3841. if(SiS_Pr->HaveEMI) {
  3842. r30 = SiS_Pr->EMI_30; r31 = SiS_Pr->EMI_31;
  3843. r32 = SiS_Pr->EMI_32; r33 = SiS_Pr->EMI_33;
  3844. } else {
  3845. r30 = 0;
  3846. }
  3847. /* EMI_30 is read at driver start; however, the BIOS sets this
  3848. * (if it is used) only if the LCD is in use. In case we caught
  3849. * the machine while on TV output, this bit is not set and we
  3850. * don't know if it should be set - hence our detection is wrong.
  3851. * Work-around this here:
  3852. */
  3853. if((!SiS_Pr->HaveEMI) || (!SiS_Pr->HaveEMILCD)) {
  3854. switch((cr36 & 0x0f)) {
  3855. case 2:
  3856. r30 |= 0x40;
  3857. if(SiS_Pr->SiS_CustomT == CUT_CLEVO1024) r30 &= ~0x40;
  3858. if(!SiS_Pr->HaveEMI) {
  3859. r31 = 0x05; r32 = 0x60; r33 = 0x33;
  3860. if((cr36 & 0xf0) == 0x30) {
  3861. r31 = 0x0d; r32 = 0x70; r33 = 0x40;
  3862. }
  3863. }
  3864. break;
  3865. case 3: /* 1280x1024 */
  3866. if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) r30 |= 0x40;
  3867. if(!SiS_Pr->HaveEMI) {
  3868. r31 = 0x12; r32 = 0xd0; r33 = 0x6b;
  3869. if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) {
  3870. r31 = 0x0d; r32 = 0x70; r33 = 0x6b;
  3871. }
  3872. }
  3873. break;
  3874. case 9: /* 1400x1050 */
  3875. r30 |= 0x40;
  3876. if(!SiS_Pr->HaveEMI) {
  3877. r31 = 0x05; r32 = 0x60; r33 = 0x00;
  3878. if(SiS_Pr->SiS_CustomT == CUT_COMPAL1400_2) {
  3879. r31 = 0x0d; r32 = 0x70; r33 = 0x40; /* BIOS values */
  3880. }
  3881. }
  3882. break;
  3883. case 11: /* 1600x1200 - unknown */
  3884. r30 |= 0x40;
  3885. if(!SiS_Pr->HaveEMI) {
  3886. r31 = 0x05; r32 = 0x60; r33 = 0x00;
  3887. }
  3888. }
  3889. }
  3890. /* BIOS values don't work so well sometimes */
  3891. if(!SiS_Pr->OverruleEMI) {
  3892. #ifdef COMPAL_HACK
  3893. if(SiS_Pr->SiS_CustomT == CUT_COMPAL1400_2) {
  3894. if((cr36 & 0x0f) == 0x09) {
  3895. r30 = 0x60; r31 = 0x05; r32 = 0x60; r33 = 0x00;
  3896. }
  3897. }
  3898. #endif
  3899. #ifdef COMPAQ_HACK
  3900. if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) {
  3901. if((cr36 & 0x0f) == 0x03) {
  3902. r30 = 0x20; r31 = 0x12; r32 = 0xd0; r33 = 0x6b;
  3903. }
  3904. }
  3905. #endif
  3906. #ifdef ASUS_HACK
  3907. if(SiS_Pr->SiS_CustomT == CUT_ASUSA2H_2) {
  3908. if((cr36 & 0x0f) == 0x02) {
  3909. /* r30 = 0x60; r31 = 0x05; r32 = 0x60; r33 = 0x33; */ /* rev 2 */
  3910. /* r30 = 0x20; r31 = 0x05; r32 = 0x60; r33 = 0x33; */ /* rev 3 */
  3911. /* r30 = 0x60; r31 = 0x0d; r32 = 0x70; r33 = 0x40; */ /* rev 4 */
  3912. /* r30 = 0x20; r31 = 0x0d; r32 = 0x70; r33 = 0x40; */ /* rev 5 */
  3913. }
  3914. }
  3915. #endif
  3916. }
  3917. if(!(SiS_Pr->OverruleEMI && (!r30) && (!r31) && (!r32) && (!r33))) {
  3918. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x30,0x20); /* Reset */
  3919. SiS_GenericDelay(SiS_Pr, 0x500);
  3920. }
  3921. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x31,r31);
  3922. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x32,r32);
  3923. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x33,r33);
  3924. #endif /* SET_EMI */
  3925. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x34,0x10);
  3926. #ifdef SET_EMI
  3927. if( (SiS_LCDAEnabled(SiS_Pr, HwInfo)) ||
  3928. (SiS_CRT2IsLCD(SiS_Pr, HwInfo)) ) {
  3929. if(r30 & 0x40) {
  3930. SiS_PanelDelayLoop(SiS_Pr, HwInfo, 3, 5);
  3931. if(delaylong) {
  3932. SiS_PanelDelayLoop(SiS_Pr, HwInfo, 3, 5);
  3933. delaylong = FALSE;
  3934. }
  3935. SiS_WaitVBRetrace(SiS_Pr,HwInfo);
  3936. if(SiS_Pr->SiS_CustomT == CUT_ASUSA2H_2) {
  3937. SiS_GenericDelay(SiS_Pr, 0x500);
  3938. }
  3939. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x30,0x40); /* Enable */
  3940. }
  3941. }
  3942. #endif
  3943. }
  3944. }
  3945. if(!(SiS_WeHaveBacklightCtrl(SiS_Pr,HwInfo))) {
  3946. if(SiS_IsVAorLCD(SiS_Pr, HwInfo)) {
  3947. SiS_PanelDelayLoop(SiS_Pr, HwInfo, 3, 10);
  3948. if(delaylong) {
  3949. SiS_PanelDelayLoop(SiS_Pr, HwInfo, 3, 10);
  3950. }
  3951. SiS_WaitVBRetrace(SiS_Pr,HwInfo);
  3952. if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV)) {
  3953. SiS_GenericDelay(SiS_Pr, 0x500);
  3954. }
  3955. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x01);
  3956. }
  3957. }
  3958. SiS_SetReg(SiS_Pr->SiS_P3c4,0x06,pushax);
  3959. SiS_DisplayOn(SiS_Pr);
  3960. SiS_SetRegByte(SiS_Pr->SiS_P3c6,0xff);
  3961. }
  3962. if(!(SiS_WeHaveBacklightCtrl(SiS_Pr,HwInfo))) {
  3963. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x00,0x7f);
  3964. }
  3965. #endif /* SIS315H */
  3966. }
  3967. } else { /* ============ For 301 ================ */
  3968. if(HwInfo->jChipType < SIS_315H) {
  3969. if(SiS_CRT2IsLCD(SiS_Pr, HwInfo)) {
  3970. SiS_SetRegSR11ANDOR(SiS_Pr,HwInfo,0xFB,0x00);
  3971. SiS_PanelDelay(SiS_Pr, HwInfo, 0);
  3972. }
  3973. }
  3974. temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x32) & 0xDF; /* lock mode */
  3975. if(SiS_BridgeInSlavemode(SiS_Pr)) {
  3976. tempah = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  3977. if(!(tempah & SetCRT2ToRAMDAC)) temp |= 0x20;
  3978. }
  3979. SiS_SetReg(SiS_Pr->SiS_P3c4,0x32,temp);
  3980. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20); /* enable CRT2 */
  3981. if(HwInfo->jChipType >= SIS_315H) {
  3982. temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x2E);
  3983. if(!(temp & 0x80)) {
  3984. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2E,0x80); /* BVBDOENABLE=1 */
  3985. }
  3986. }
  3987. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x00,0x1F,0x20); /* enable VB processor */
  3988. SiS_VBLongWait(SiS_Pr);
  3989. SiS_DisplayOn(SiS_Pr);
  3990. if(HwInfo->jChipType >= SIS_315H) {
  3991. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x00,0x7f);
  3992. }
  3993. SiS_VBLongWait(SiS_Pr);
  3994. if(HwInfo->jChipType < SIS_315H) {
  3995. if(SiS_CRT2IsLCD(SiS_Pr, HwInfo)) {
  3996. SiS_PanelDelay(SiS_Pr, HwInfo, 1);
  3997. SiS_SetRegSR11ANDOR(SiS_Pr,HwInfo,0xF7,0x00);
  3998. }
  3999. }
  4000. }
  4001. } else { /* =================== For LVDS ================== */
  4002. if(HwInfo->jChipType < SIS_315H) {
  4003. #ifdef SIS300 /* 300 series */
  4004. if(SiS_CRT2IsLCD(SiS_Pr, HwInfo)) {
  4005. if(HwInfo->jChipType == SIS_730) {
  4006. SiS_PanelDelay(SiS_Pr, HwInfo, 1);
  4007. SiS_PanelDelay(SiS_Pr, HwInfo, 1);
  4008. SiS_PanelDelay(SiS_Pr, HwInfo, 1);
  4009. }
  4010. SiS_SetRegSR11ANDOR(SiS_Pr,HwInfo,0xFB,0x00);
  4011. if(!(SiS_CR36BIOSWord23d(SiS_Pr,HwInfo))) {
  4012. SiS_PanelDelay(SiS_Pr, HwInfo, 0);
  4013. }
  4014. }
  4015. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);
  4016. SiS_DisplayOn(SiS_Pr);
  4017. SiS_UnLockCRT2(SiS_Pr,HwInfo);
  4018. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x02,0xBF);
  4019. if(SiS_BridgeInSlavemode(SiS_Pr)) {
  4020. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x01,0x1F);
  4021. } else {
  4022. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x01,0x1F,0x40);
  4023. }
  4024. if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) {
  4025. if(!(SiS_CRT2IsLCD(SiS_Pr, HwInfo))) {
  4026. SiS_WaitVBRetrace(SiS_Pr, HwInfo);
  4027. SiS_SetCH700x(SiS_Pr,0x0B0E);
  4028. }
  4029. }
  4030. if(SiS_CRT2IsLCD(SiS_Pr, HwInfo)) {
  4031. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x40)) {
  4032. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x16) & 0x10)) {
  4033. if(!(SiS_CR36BIOSWord23b(SiS_Pr,HwInfo))) {
  4034. SiS_PanelDelay(SiS_Pr, HwInfo, 1);
  4035. SiS_PanelDelay(SiS_Pr, HwInfo, 1);
  4036. }
  4037. SiS_WaitVBRetrace(SiS_Pr, HwInfo);
  4038. SiS_SetRegSR11ANDOR(SiS_Pr,HwInfo,0xF7,0x00);
  4039. }
  4040. }
  4041. }
  4042. #endif /* SIS300 */
  4043. } else {
  4044. #ifdef SIS315H /* 315 series */
  4045. if(!(SiS_IsNotM650orLater(SiS_Pr,HwInfo))) {
  4046. if(HwInfo->jChipType < SIS_340) {
  4047. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x4c,0x18);
  4048. }
  4049. }
  4050. if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
  4051. if(SiS_CRT2IsLCD(SiS_Pr, HwInfo)) {
  4052. SiS_SetRegSR11ANDOR(SiS_Pr,HwInfo,0xFB,0x00);
  4053. SiS_PanelDelay(SiS_Pr, HwInfo, 0);
  4054. }
  4055. }
  4056. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);
  4057. SiS_UnLockCRT2(SiS_Pr,HwInfo);
  4058. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0xf7);
  4059. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  4060. temp = SiS_GetCH701x(SiS_Pr,0x66);
  4061. temp &= 0x20;
  4062. SiS_Chrontel701xBLOff(SiS_Pr);
  4063. }
  4064. if(HwInfo->jChipType != SIS_550) {
  4065. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0x7f);
  4066. }
  4067. if(HwInfo->jChipType == SIS_740) {
  4068. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  4069. if(SiS_IsLCDOrLCDA(SiS_Pr, HwInfo)) {
  4070. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x20);
  4071. }
  4072. }
  4073. }
  4074. temp1 = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x2E);
  4075. if(!(temp1 & 0x80)) {
  4076. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2E,0x80);
  4077. }
  4078. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  4079. if(temp) {
  4080. SiS_Chrontel701xBLOn(SiS_Pr, HwInfo);
  4081. }
  4082. }
  4083. if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
  4084. if(SiS_CRT2IsLCD(SiS_Pr, HwInfo)) {
  4085. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x20);
  4086. if(HwInfo->jChipType == SIS_550) {
  4087. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x40);
  4088. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x10);
  4089. }
  4090. }
  4091. } else if(SiS_IsVAMode(SiS_Pr,HwInfo)) {
  4092. if(HwInfo->jChipType != SIS_740) {
  4093. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x20);
  4094. }
  4095. }
  4096. if(!(SiS_WeHaveBacklightCtrl(SiS_Pr,HwInfo))) {
  4097. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x00,0x7f);
  4098. }
  4099. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  4100. if(SiS_IsTVOrYPbPrOrScart(SiS_Pr,HwInfo)) {
  4101. SiS_Chrontel701xOn(SiS_Pr,HwInfo);
  4102. }
  4103. if( (SiS_IsVAMode(SiS_Pr,HwInfo)) ||
  4104. (SiS_IsLCDOrLCDA(SiS_Pr,HwInfo)) ) {
  4105. SiS_ChrontelDoSomething1(SiS_Pr,HwInfo);
  4106. }
  4107. }
  4108. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  4109. if(!(SiS_WeHaveBacklightCtrl(SiS_Pr,HwInfo))) {
  4110. if( (SiS_IsVAMode(SiS_Pr,HwInfo)) ||
  4111. (SiS_IsLCDOrLCDA(SiS_Pr,HwInfo)) ) {
  4112. SiS_Chrontel701xBLOn(SiS_Pr, HwInfo);
  4113. SiS_ChrontelInitTVVSync(SiS_Pr,HwInfo);
  4114. }
  4115. }
  4116. } else if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
  4117. if(!(SiS_WeHaveBacklightCtrl(SiS_Pr,HwInfo))) {
  4118. if(SiS_CRT2IsLCD(SiS_Pr, HwInfo)) {
  4119. SiS_PanelDelay(SiS_Pr, HwInfo, 1);
  4120. SiS_SetRegSR11ANDOR(SiS_Pr,HwInfo,0xF7,0x00);
  4121. }
  4122. }
  4123. }
  4124. #endif /* SIS315H */
  4125. } /* 310 series */
  4126. } /* LVDS */
  4127. }
  4128. /*********************************************/
  4129. /* SET PART 1 REGISTER GROUP */
  4130. /*********************************************/
  4131. /* Set CRT2 OFFSET / PITCH */
  4132. static void
  4133. SiS_SetCRT2Offset(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
  4134. USHORT RRTI, PSIS_HW_INFO HwInfo)
  4135. {
  4136. USHORT offset;
  4137. UCHAR temp;
  4138. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) return;
  4139. offset = SiS_GetOffset(SiS_Pr,ModeNo,ModeIdIndex,RRTI,HwInfo);
  4140. if((SiS_Pr->SiS_LCDResInfo == Panel_640x480_2) ||
  4141. (SiS_Pr->SiS_LCDResInfo == Panel_640x480_3)) {
  4142. offset >>= 1;
  4143. }
  4144. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x07,(offset & 0xFF));
  4145. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x09,(offset >> 8));
  4146. temp = (UCHAR)(((offset >> 3) & 0xFF) + 1);
  4147. if(offset % 8) temp++;
  4148. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x03,temp);
  4149. }
  4150. /* Set CRT2 sync and PanelLink mode */
  4151. static void
  4152. SiS_SetCRT2Sync(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT RefreshRateTableIndex,
  4153. PSIS_HW_INFO HwInfo)
  4154. {
  4155. USHORT tempah=0,tempbl,infoflag;
  4156. tempbl = 0xC0;
  4157. if(SiS_Pr->UseCustomMode) {
  4158. infoflag = SiS_Pr->CInfoFlag;
  4159. } else {
  4160. infoflag = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
  4161. }
  4162. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { /* LVDS */
  4163. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  4164. tempah = 0;
  4165. } else if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && (SiS_Pr->SiS_LCDInfo & LCDSync)) {
  4166. tempah = SiS_Pr->SiS_LCDInfo;
  4167. } else tempah = infoflag >> 8;
  4168. tempah &= 0xC0;
  4169. tempah |= 0x20;
  4170. if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10;
  4171. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  4172. if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) ||
  4173. (SiS_Pr->SiS_CustomT == CUT_BARCO1024)) {
  4174. tempah |= 0xf0;
  4175. }
  4176. if( (SiS_Pr->SiS_IF_DEF_FSTN) ||
  4177. (SiS_Pr->SiS_IF_DEF_DSTN) ||
  4178. (SiS_Pr->SiS_IF_DEF_TRUMPION) ||
  4179. (SiS_Pr->SiS_CustomT == CUT_PANEL848) ) {
  4180. tempah |= 0x30;
  4181. }
  4182. }
  4183. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  4184. if(HwInfo->jChipType >= SIS_315H) {
  4185. tempah >>= 3;
  4186. tempah &= 0x18;
  4187. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,0xE7,tempah);
  4188. /* Don't care about 12/18/24 bit mode - TV is via VGA, not PL */
  4189. } else {
  4190. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,0xe0);
  4191. }
  4192. } else {
  4193. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah);
  4194. }
  4195. } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
  4196. if(HwInfo->jChipType < SIS_315H) {
  4197. #ifdef SIS300 /* ---- 300 series --- */
  4198. if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) { /* 630 - 301B(-DH) */
  4199. tempah = infoflag >> 8;
  4200. tempbl = 0;
  4201. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  4202. if(SiS_Pr->SiS_LCDInfo & LCDSync) {
  4203. tempah = SiS_Pr->SiS_LCDInfo;
  4204. tempbl = (tempah >> 6) & 0x03;
  4205. }
  4206. }
  4207. tempah &= 0xC0;
  4208. tempah |= 0x20;
  4209. if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10;
  4210. tempah |= 0xc0;
  4211. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah);
  4212. if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && (!(SiS_Pr->SiS_VBType & VB_NoLCD))) {
  4213. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1a,0xf0,tempbl);
  4214. }
  4215. } else { /* 630 - 301 */
  4216. tempah = infoflag >> 8;
  4217. tempah &= 0xC0;
  4218. tempah |= 0x20;
  4219. if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10;
  4220. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah);
  4221. }
  4222. #endif /* SIS300 */
  4223. } else {
  4224. #ifdef SIS315H /* ------- 315 series ------ */
  4225. if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) { /* 315 - LVDS */
  4226. tempbl = 0;
  4227. if((SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) &&
  4228. (SiS_Pr->SiS_LCDResInfo == Panel_1280x1024)) {
  4229. tempah = infoflag >> 8;
  4230. if(SiS_Pr->SiS_LCDInfo & LCDSync) {
  4231. tempbl = ((SiS_Pr->SiS_LCDInfo & 0xc0) >> 6);
  4232. }
  4233. } else if((SiS_Pr->SiS_CustomT == CUT_CLEVO1400) &&
  4234. (SiS_Pr->SiS_LCDResInfo == Panel_1400x1050)) {
  4235. tempah = infoflag >> 8;
  4236. tempbl = 0x03;
  4237. } else {
  4238. tempah = SiS_GetReg(SiS_Pr->SiS_P3d4,0x37);
  4239. tempbl = (tempah >> 6) & 0x03;
  4240. tempbl |= 0x08;
  4241. if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempbl |= 0x04;
  4242. }
  4243. tempah &= 0xC0;
  4244. tempah |= 0x20;
  4245. if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10;
  4246. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) tempah |= 0xc0;
  4247. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah);
  4248. if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
  4249. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  4250. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1a,0xf0,tempbl);
  4251. }
  4252. }
  4253. } else { /* 315 - TMDS */
  4254. tempah = tempbl = infoflag >> 8;
  4255. if(!SiS_Pr->UseCustomMode) {
  4256. tempbl = 0;
  4257. if((SiS_Pr->SiS_VBType & VB_SIS301C) && (SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) {
  4258. if(ModeNo <= 0x13) {
  4259. tempah = SiS_GetRegByte((SiS_Pr->SiS_P3ca+0x02));
  4260. }
  4261. }
  4262. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4263. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  4264. if(SiS_Pr->SiS_LCDInfo & LCDSync) {
  4265. tempah = SiS_Pr->SiS_LCDInfo;
  4266. tempbl = (tempah >> 6) & 0x03;
  4267. }
  4268. }
  4269. }
  4270. }
  4271. tempah &= 0xC0;
  4272. tempah |= 0x20;
  4273. if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10;
  4274. if(SiS_Pr->SiS_VBType & VB_NoLCD) {
  4275. /* Imitate BIOS bug */
  4276. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) tempah |= 0xc0;
  4277. }
  4278. if((SiS_Pr->SiS_VBType & VB_SIS301C) && (SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) {
  4279. tempah >>= 3;
  4280. tempah &= 0x18;
  4281. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,0xe7,tempah);
  4282. } else {
  4283. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah);
  4284. if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
  4285. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  4286. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1a,0xf0,tempbl);
  4287. }
  4288. }
  4289. }
  4290. }
  4291. #endif /* SIS315H */
  4292. }
  4293. }
  4294. }
  4295. /* Set CRT2 FIFO on 300/630/730 */
  4296. #ifdef SIS300
  4297. static void
  4298. SiS_SetCRT2FIFO_300(SiS_Private *SiS_Pr,USHORT ModeNo,
  4299. PSIS_HW_INFO HwInfo)
  4300. {
  4301. UCHAR *ROMAddr = HwInfo->pjVirtualRomBase;
  4302. USHORT temp,index;
  4303. USHORT modeidindex,refreshratetableindex;
  4304. USHORT VCLK=0,MCLK,colorth=0,data2=0;
  4305. USHORT tempal, tempah, tempbx, tempcl, tempax;
  4306. USHORT CRT1ModeNo,CRT2ModeNo;
  4307. USHORT SelectRate_backup;
  4308. ULONG data,eax;
  4309. const UCHAR LatencyFactor[] = {
  4310. 97, 88, 86, 79, 77, 00, /*; 64 bit BQ=2 */
  4311. 00, 87, 85, 78, 76, 54, /*; 64 bit BQ=1 */
  4312. 97, 88, 86, 79, 77, 00, /*; 128 bit BQ=2 */
  4313. 00, 79, 77, 70, 68, 48, /*; 128 bit BQ=1 */
  4314. 80, 72, 69, 63, 61, 00, /*; 64 bit BQ=2 */
  4315. 00, 70, 68, 61, 59, 37, /*; 64 bit BQ=1 */
  4316. 86, 77, 75, 68, 66, 00, /*; 128 bit BQ=2 */
  4317. 00, 68, 66, 59, 57, 37 /*; 128 bit BQ=1 */
  4318. };
  4319. const UCHAR LatencyFactor730[] = {
  4320. 69, 63, 61,
  4321. 86, 79, 77,
  4322. 103, 96, 94,
  4323. 120,113,111,
  4324. 137,130,128, /* <-- last entry, data below */
  4325. 137,130,128, /* to avoid using illegal values */
  4326. 137,130,128,
  4327. 137,130,128,
  4328. 137,130,128,
  4329. 137,130,128,
  4330. 137,130,128,
  4331. 137,130,128,
  4332. 137,130,128,
  4333. 137,130,128,
  4334. 137,130,128,
  4335. 137,130,128,
  4336. };
  4337. const UCHAR ThLowB[] = {
  4338. 81, 4, 72, 6, 88, 8,120,12,
  4339. 55, 4, 54, 6, 66, 8, 90,12,
  4340. 42, 4, 45, 6, 55, 8, 75,12
  4341. };
  4342. const UCHAR ThTiming[] = {
  4343. 1, 2, 2, 3, 0, 1, 1, 2
  4344. };
  4345. SelectRate_backup = SiS_Pr->SiS_SelectCRT2Rate;
  4346. if(!SiS_Pr->CRT1UsesCustomMode) {
  4347. CRT1ModeNo = SiS_Pr->SiS_CRT1Mode; /* get CRT1 ModeNo */
  4348. SiS_SearchModeID(SiS_Pr, &CRT1ModeNo, &modeidindex);
  4349. SiS_Pr->SiS_SetFlag &= (~ProgrammingCRT2);
  4350. SiS_Pr->SiS_SelectCRT2Rate = 0;
  4351. refreshratetableindex = SiS_GetRatePtr(SiS_Pr, CRT1ModeNo, modeidindex, HwInfo);
  4352. if(CRT1ModeNo >= 0x13) {
  4353. index = SiS_Pr->SiS_RefIndex[refreshratetableindex].Ext_CRTVCLK;
  4354. index &= 0x3F;
  4355. VCLK = SiS_Pr->SiS_VCLKData[index].CLOCK; /* Get VCLK */
  4356. colorth = SiS_GetColorDepth(SiS_Pr,CRT1ModeNo,modeidindex); /* Get colordepth */
  4357. colorth >>= 1;
  4358. if(!colorth) colorth++;
  4359. }
  4360. } else {
  4361. CRT1ModeNo = 0xfe;
  4362. VCLK = SiS_Pr->CSRClock_CRT1; /* Get VCLK */
  4363. data2 = (SiS_Pr->CModeFlag_CRT1 & ModeTypeMask) - 2;
  4364. switch(data2) { /* Get color depth */
  4365. case 0 : colorth = 1; break;
  4366. case 1 : colorth = 1; break;
  4367. case 2 : colorth = 2; break;
  4368. case 3 : colorth = 2; break;
  4369. case 4 : colorth = 3; break;
  4370. case 5 : colorth = 4; break;
  4371. default: colorth = 2;
  4372. }
  4373. }
  4374. if(CRT1ModeNo >= 0x13) {
  4375. if(HwInfo->jChipType == SIS_300) {
  4376. index = SiS_GetReg(SiS_Pr->SiS_P3c4,0x3A);
  4377. } else {
  4378. index = SiS_GetReg(SiS_Pr->SiS_P3c4,0x1A);
  4379. }
  4380. index &= 0x07;
  4381. MCLK = SiS_Pr->SiS_MCLKData_0[index].CLOCK; /* Get MCLK */
  4382. data2 = (colorth * VCLK) / MCLK;
  4383. temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x14);
  4384. temp = ((temp & 0x00FF) >> 6) << 1;
  4385. if(temp == 0) temp = 1;
  4386. temp <<= 2;
  4387. temp &= 0xff;
  4388. data2 = temp - data2;
  4389. if((28 * 16) % data2) {
  4390. data2 = (28 * 16) / data2;
  4391. data2++;
  4392. } else {
  4393. data2 = (28 * 16) / data2;
  4394. }
  4395. if(HwInfo->jChipType == SIS_300) {
  4396. tempah = SiS_GetReg(SiS_Pr->SiS_P3c4,0x18);
  4397. tempah &= 0x62;
  4398. tempah >>= 1;
  4399. tempal = tempah;
  4400. tempah >>= 3;
  4401. tempal |= tempah;
  4402. tempal &= 0x07;
  4403. tempcl = ThTiming[tempal];
  4404. tempbx = SiS_GetReg(SiS_Pr->SiS_P3c4,0x16);
  4405. tempbx >>= 6;
  4406. tempah = SiS_GetReg(SiS_Pr->SiS_P3c4,0x14);
  4407. tempah >>= 4;
  4408. tempah &= 0x0c;
  4409. tempbx |= tempah;
  4410. tempbx <<= 1;
  4411. tempal = ThLowB[tempbx + 1];
  4412. tempal *= tempcl;
  4413. tempal += ThLowB[tempbx];
  4414. data = tempal;
  4415. } else if(HwInfo->jChipType == SIS_730) {
  4416. #ifdef LINUX_KERNEL
  4417. SiS_SetRegLong(0xcf8,0x80000050);
  4418. eax = SiS_GetRegLong(0xcfc);
  4419. #else
  4420. eax = pciReadLong(0x00000000, 0x50);
  4421. #endif
  4422. tempal = (USHORT)(eax >> 8);
  4423. tempal &= 0x06;
  4424. tempal <<= 5;
  4425. #ifdef LINUX_KERNEL
  4426. SiS_SetRegLong(0xcf8,0x800000A0);
  4427. eax = SiS_GetRegLong(0xcfc);
  4428. #else
  4429. eax = pciReadLong(0x00000000, 0xA0);
  4430. #endif
  4431. temp = (USHORT)(eax >> 28);
  4432. temp &= 0x0F;
  4433. tempal |= temp;
  4434. tempbx = tempal; /* BIOS BUG (2.04.5d, 2.04.6a use ah here, which is unset!) */
  4435. tempbx = 0; /* -- do it like the BIOS anyway... */
  4436. tempax = tempbx;
  4437. tempbx &= 0xc0;
  4438. tempbx >>= 6;
  4439. tempax &= 0x0f;
  4440. tempax *= 3;
  4441. tempbx += tempax;
  4442. data = LatencyFactor730[tempbx];
  4443. data += 15;
  4444. temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x14);
  4445. if(!(temp & 0x80)) data += 5;
  4446. } else {
  4447. index = 0;
  4448. temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x14);
  4449. if(temp & 0x0080) index += 12;
  4450. #ifdef LINUX_KERNEL
  4451. SiS_SetRegLong(0xcf8,0x800000A0);
  4452. eax = SiS_GetRegLong(0xcfc);
  4453. #else
  4454. /* We use pci functions X offers. We use tag 0, because
  4455. * we want to read/write to the host bridge (which is always
  4456. * 00:00.0 on 630, 730 and 540), not the VGA device.
  4457. */
  4458. eax = pciReadLong(0x00000000, 0xA0);
  4459. #endif
  4460. temp = (USHORT)(eax >> 24);
  4461. if(!(temp&0x01)) index += 24;
  4462. #ifdef LINUX_KERNEL
  4463. SiS_SetRegLong(0xcf8,0x80000050);
  4464. eax = SiS_GetRegLong(0xcfc);
  4465. #else
  4466. eax = pciReadLong(0x00000000, 0x50);
  4467. #endif
  4468. temp=(USHORT)(eax >> 24);
  4469. if(temp & 0x01) index += 6;
  4470. temp = (temp & 0x0F) >> 1;
  4471. index += temp;
  4472. data = LatencyFactor[index];
  4473. data += 15;
  4474. temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x14);
  4475. if(!(temp & 0x80)) data += 5;
  4476. }
  4477. data += data2; /* CRT1 Request Period */
  4478. SiS_Pr->SiS_SetFlag |= ProgrammingCRT2;
  4479. SiS_Pr->SiS_SelectCRT2Rate = SelectRate_backup;
  4480. if(!SiS_Pr->UseCustomMode) {
  4481. CRT2ModeNo = ModeNo;
  4482. SiS_SearchModeID(SiS_Pr, &CRT2ModeNo, &modeidindex);
  4483. refreshratetableindex = SiS_GetRatePtr(SiS_Pr, CRT2ModeNo, modeidindex, HwInfo);
  4484. index = SiS_GetVCLK2Ptr(SiS_Pr,CRT2ModeNo,modeidindex,
  4485. refreshratetableindex,HwInfo);
  4486. VCLK = SiS_Pr->SiS_VCLKData[index].CLOCK; /* Get VCLK */
  4487. if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) || (SiS_Pr->SiS_CustomT == CUT_BARCO1024)) {
  4488. if(SiS_Pr->SiS_UseROM) {
  4489. if(ROMAddr[0x220] & 0x01) {
  4490. VCLK = ROMAddr[0x229] | (ROMAddr[0x22a] << 8);
  4491. }
  4492. }
  4493. }
  4494. } else {
  4495. CRT2ModeNo = 0xfe;
  4496. VCLK = SiS_Pr->CSRClock; /* Get VCLK */
  4497. }
  4498. colorth = SiS_GetColorDepth(SiS_Pr,CRT2ModeNo,modeidindex); /* Get colordepth */
  4499. colorth >>= 1;
  4500. if(!colorth) colorth++;
  4501. data = data * VCLK * colorth;
  4502. if(data % (MCLK << 4)) {
  4503. data = data / (MCLK << 4);
  4504. data++;
  4505. } else {
  4506. data = data / (MCLK << 4);
  4507. }
  4508. if(data <= 6) data = 6;
  4509. if(data > 0x14) data = 0x14;
  4510. temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x01);
  4511. if(HwInfo->jChipType == SIS_300) {
  4512. if(data <= 0x0f) temp = (temp & (~0x1F)) | 0x13;
  4513. else temp = (temp & (~0x1F)) | 0x16;
  4514. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) {
  4515. temp = (temp & (~0x1F)) | 0x13;
  4516. }
  4517. } else {
  4518. if( ( (HwInfo->jChipType == SIS_630) ||
  4519. (HwInfo->jChipType == SIS_730) ) &&
  4520. (HwInfo->jChipRevision >= 0x30) ) /* 630s or 730(s?) */
  4521. {
  4522. temp = (temp & (~0x1F)) | 0x1b;
  4523. } else {
  4524. temp = (temp & (~0x1F)) | 0x16;
  4525. }
  4526. }
  4527. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x01,0xe0,temp);
  4528. if( (HwInfo->jChipType == SIS_630) &&
  4529. (HwInfo->jChipRevision >= 0x30) ) /* 630s, NOT 730 */
  4530. {
  4531. if(data > 0x13) data = 0x13;
  4532. }
  4533. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x02,0xe0,data);
  4534. } else { /* If mode <= 0x13, we just restore everything */
  4535. SiS_Pr->SiS_SetFlag |= ProgrammingCRT2;
  4536. SiS_Pr->SiS_SelectCRT2Rate = SelectRate_backup;
  4537. }
  4538. }
  4539. #endif
  4540. /* Set CRT2 FIFO on 315/330 series */
  4541. #ifdef SIS315H
  4542. static void
  4543. SiS_SetCRT2FIFO_310(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
  4544. {
  4545. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x01,0x3B);
  4546. if( (HwInfo->jChipType == SIS_760) &&
  4547. (SiS_Pr->SiS_SysFlags & SF_760LFB) &&
  4548. (SiS_Pr->SiS_ModeType == Mode32Bpp) &&
  4549. (SiS_Pr->SiS_VGAHDE >= 1280) &&
  4550. (SiS_Pr->SiS_VGAVDE >= 1024) ) {
  4551. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2f,0x03);
  4552. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x01,0x3b);
  4553. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x4d,0xc0);
  4554. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2f,0x01);
  4555. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x4d,0xc0);
  4556. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x02,0x6e);
  4557. } else {
  4558. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x02,~0x3f,0x04);
  4559. }
  4560. }
  4561. #endif
  4562. static USHORT
  4563. SiS_GetVGAHT2(SiS_Private *SiS_Pr)
  4564. {
  4565. ULONG tempax,tempbx;
  4566. tempbx = (SiS_Pr->SiS_VGAVT - SiS_Pr->SiS_VGAVDE) * SiS_Pr->SiS_RVBHCMAX;
  4567. tempax = (SiS_Pr->SiS_VT - SiS_Pr->SiS_VDE) * SiS_Pr->SiS_RVBHCFACT;
  4568. tempax = (tempax * SiS_Pr->SiS_HT) / tempbx;
  4569. return((USHORT)tempax);
  4570. }
  4571. /* Set Part 1 / SiS bridge slave mode */
  4572. static void
  4573. SiS_SetGroup1_301(SiS_Private *SiS_Pr, USHORT ModeNo,USHORT ModeIdIndex,
  4574. PSIS_HW_INFO HwInfo,USHORT RefreshRateTableIndex)
  4575. {
  4576. USHORT push1,push2;
  4577. USHORT tempax,tempbx,tempcx,temp;
  4578. USHORT resinfo,modeflag,xres=0;
  4579. unsigned char p1_7, p1_8;
  4580. if(ModeNo <= 0x13) {
  4581. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  4582. resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
  4583. } else if(SiS_Pr->UseCustomMode) {
  4584. modeflag = SiS_Pr->CModeFlag;
  4585. resinfo = 0;
  4586. xres = SiS_Pr->CHDisplay;
  4587. } else {
  4588. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  4589. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  4590. xres = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].XRes;
  4591. }
  4592. /* The following is only done if bridge is in slave mode: */
  4593. if((HwInfo->jChipType >= SIS_661) && (ModeNo > 0x13)) {
  4594. if(xres >= 1600) {
  4595. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x31,0x04);
  4596. }
  4597. }
  4598. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x03,0xff); /* set MAX HT */
  4599. if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) modeflag |= Charx8Dot;
  4600. if(modeflag & Charx8Dot) tempcx = 0x08;
  4601. else tempcx = 0x09;
  4602. tempax = SiS_Pr->SiS_VGAHDE; /* 0x04 Horizontal Display End */
  4603. if(modeflag & HalfDCLK) tempax >>= 1;
  4604. tempax = ((tempax / tempcx) - 1) & 0xff;
  4605. tempbx = tempax;
  4606. temp = tempax;
  4607. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x04,temp);
  4608. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  4609. if(!(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV)) {
  4610. temp += 2;
  4611. }
  4612. }
  4613. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  4614. if(resinfo == SIS_RI_800x600) temp -= 2;
  4615. }
  4616. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x05,temp); /* 0x05 Horizontal Display Start */
  4617. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x06,0x03); /* 0x06 Horizontal Blank end */
  4618. tempax = 0xFFFF;
  4619. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) tempax = SiS_GetVGAHT2(SiS_Pr);
  4620. if(tempax >= SiS_Pr->SiS_VGAHT) tempax = SiS_Pr->SiS_VGAHT;
  4621. if(modeflag & HalfDCLK) tempax >>= 1;
  4622. tempax = (tempax / tempcx) - 5;
  4623. tempcx = tempax;
  4624. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  4625. temp = tempcx - 1;
  4626. if(!(modeflag & HalfDCLK)) {
  4627. temp -= 6;
  4628. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) {
  4629. temp -= 2;
  4630. if(ModeNo > 0x13) temp -= 10;
  4631. }
  4632. }
  4633. } else {
  4634. tempcx = (tempcx + tempbx) >> 1;
  4635. temp = (tempcx & 0x00FF) + 2;
  4636. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  4637. temp--;
  4638. if(!(modeflag & HalfDCLK)) {
  4639. if((modeflag & Charx8Dot)) {
  4640. temp += 4;
  4641. if(SiS_Pr->SiS_VGAHDE >= 800) temp -= 6;
  4642. if(HwInfo->jChipType >= SIS_315H) {
  4643. if(SiS_Pr->SiS_VGAHDE == 800) temp += 2;
  4644. }
  4645. }
  4646. }
  4647. } else {
  4648. if(!(modeflag & HalfDCLK)) {
  4649. temp -= 4;
  4650. if((SiS_Pr->SiS_LCDResInfo != Panel_1280x960) &&
  4651. (SiS_Pr->SiS_LCDResInfo != Panel_1600x1200)) {
  4652. if(SiS_Pr->SiS_VGAHDE >= 800) {
  4653. temp -= 7;
  4654. if(HwInfo->jChipType < SIS_315H) {
  4655. if(SiS_Pr->SiS_ModeType == ModeEGA) {
  4656. if(SiS_Pr->SiS_VGAVDE == 1024) {
  4657. temp += 15;
  4658. if(SiS_Pr->SiS_LCDResInfo != Panel_1280x1024)
  4659. temp += 7;
  4660. }
  4661. }
  4662. }
  4663. if(SiS_Pr->SiS_LCDResInfo != Panel_1400x1050) {
  4664. if(SiS_Pr->SiS_VGAHDE >= 1280) {
  4665. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) temp += 28;
  4666. }
  4667. }
  4668. }
  4669. }
  4670. }
  4671. }
  4672. }
  4673. p1_7 = temp;
  4674. p1_8 = 0x00;
  4675. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  4676. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) {
  4677. if(ModeNo <= 0x01) {
  4678. p1_7 = 0x2a;
  4679. if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) p1_8 = 0x61;
  4680. else p1_8 = 0x41;
  4681. } else if(SiS_Pr->SiS_ModeType == ModeText) {
  4682. if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) p1_7 = 0x54;
  4683. else p1_7 = 0x55;
  4684. p1_8 = 0x00;
  4685. } else if(ModeNo <= 0x13) {
  4686. if(modeflag & HalfDCLK) {
  4687. if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) {
  4688. p1_7 = 0x30;
  4689. p1_8 = 0x03;
  4690. } else {
  4691. p1_7 = 0x2f;
  4692. p1_8 = 0x02;
  4693. }
  4694. } else {
  4695. p1_7 = 0x5b;
  4696. p1_8 = 0x03;
  4697. }
  4698. } else if( ((HwInfo->jChipType >= SIS_315H) &&
  4699. ((ModeNo == 0x50) || (ModeNo == 0x56) || (ModeNo == 0x53))) ||
  4700. ((HwInfo->jChipType < SIS_315H) &&
  4701. (resinfo == SIS_RI_320x200 || resinfo == SIS_RI_320x240)) ) {
  4702. if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) {
  4703. p1_7 = 0x30,
  4704. p1_8 = 0x03;
  4705. } else {
  4706. p1_7 = 0x2f;
  4707. p1_8 = 0x03;
  4708. }
  4709. }
  4710. }
  4711. }
  4712. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  4713. if(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p|TVSetYPbPr750p)) {
  4714. p1_7 = 0x63;
  4715. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) p1_7 = 0x55;
  4716. }
  4717. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) {
  4718. if(!(modeflag & HalfDCLK)) {
  4719. p1_7 = 0xb2;
  4720. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) {
  4721. p1_7 = 0xab;
  4722. }
  4723. }
  4724. } else {
  4725. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) {
  4726. if(modeflag & HalfDCLK) p1_7 = 0x30;
  4727. }
  4728. }
  4729. }
  4730. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x07,p1_7); /* 0x07 Horizontal Retrace Start */
  4731. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x08,p1_8); /* 0x08 Horizontal Retrace End */
  4732. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x03); /* 0x18 SR08 (FIFO Threshold?) */
  4733. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x19,0xF0);
  4734. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x09,0xFF); /* 0x09 Set Max VT */
  4735. tempcx = 0x121;
  4736. tempbx = SiS_Pr->SiS_VGAVDE; /* 0x0E Vertical Display End */
  4737. if (tempbx == 357) tempbx = 350;
  4738. else if(tempbx == 360) tempbx = 350;
  4739. else if(tempbx == 375) tempbx = 350;
  4740. else if(tempbx == 405) tempbx = 400;
  4741. else if(tempbx == 420) tempbx = 400;
  4742. else if(tempbx == 525) tempbx = 480;
  4743. push2 = tempbx;
  4744. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  4745. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  4746. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
  4747. if (tempbx == 350) tempbx += 5;
  4748. else if(tempbx == 480) tempbx += 5;
  4749. }
  4750. }
  4751. }
  4752. tempbx -= 2;
  4753. temp = tempbx & 0x00FF;
  4754. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x10,temp); /* 0x10 vertical Blank Start */
  4755. tempbx = push2;
  4756. tempbx--;
  4757. temp = tempbx & 0x00FF;
  4758. #if 0
  4759. /* Missing code from 630/301B 2.04.5a and 650/302LV 1.10.6s (calles int 2f) */
  4760. if(xxx()) {
  4761. if(temp == 0xdf) temp = 0xda;
  4762. }
  4763. #endif
  4764. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0E,temp);
  4765. temp = 0;
  4766. if(modeflag & DoubleScanMode) temp |= 0x80;
  4767. if(HwInfo->jChipType >= SIS_661) {
  4768. if(tempbx & 0x0200) temp |= 0x20;
  4769. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x0B,0x5F,temp);
  4770. if(tempbx & 0x0100) tempcx |= 0x000a;
  4771. if(tempbx & 0x0400) tempcx |= 0x1200;
  4772. } else {
  4773. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0B,temp);
  4774. if(tempbx & 0x0100) tempcx |= 0x0002;
  4775. if(tempbx & 0x0400) tempcx |= 0x0600;
  4776. }
  4777. if(tempbx & 0x0200) tempcx |= 0x0040;
  4778. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x11,0x00); /* 0x11 Vertical Blank End */
  4779. tempax = (SiS_Pr->SiS_VGAVT - tempbx) >> 2;
  4780. if((ModeNo > 0x13) || (HwInfo->jChipType < SIS_315H)) {
  4781. if(resinfo != SIS_RI_1280x1024) {
  4782. tempbx += (tempax << 1);
  4783. }
  4784. } else if(HwInfo->jChipType >= SIS_315H) {
  4785. if(SiS_Pr->SiS_LCDResInfo != Panel_1400x1050) {
  4786. tempbx += (tempax << 1);
  4787. }
  4788. }
  4789. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  4790. tempbx -= 10;
  4791. } else {
  4792. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) {
  4793. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  4794. tempbx += 40;
  4795. if(HwInfo->jChipType >= SIS_315H) {
  4796. if(SiS_Pr->SiS_VGAHDE == 800) tempbx += 10;
  4797. }
  4798. }
  4799. }
  4800. }
  4801. tempax >>= 2;
  4802. tempax++;
  4803. tempax += tempbx;
  4804. push1 = tempax;
  4805. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  4806. if(tempbx <= 513) {
  4807. if(tempax >= 513) tempbx = 513;
  4808. }
  4809. }
  4810. temp = tempbx & 0x00FF;
  4811. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0C,temp); /* 0x0C Vertical Retrace Start */
  4812. tempbx--;
  4813. temp = tempbx & 0x00FF;
  4814. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x10,temp);
  4815. if(tempbx & 0x0100) tempcx |= 0x0008;
  4816. if(tempbx & 0x0200) {
  4817. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x0B,0x20);
  4818. }
  4819. tempbx++;
  4820. if(tempbx & 0x0100) tempcx |= 0x0004;
  4821. if(tempbx & 0x0200) tempcx |= 0x0080;
  4822. if(tempbx & 0x0400) {
  4823. if(HwInfo->jChipType >= SIS_661) tempcx |= 0x0800;
  4824. else if(SiS_Pr->SiS_VBType & VB_SIS301) tempcx |= 0x0800;
  4825. else tempcx |= 0x0C00;
  4826. }
  4827. tempbx = push1;
  4828. temp = tempbx & 0x000F;
  4829. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0D,temp); /* 0x0D vertical Retrace End */
  4830. if(tempbx & 0x0010) tempcx |= 0x2000;
  4831. temp = tempcx & 0x00FF;
  4832. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0A,temp); /* 0x0A CR07 */
  4833. temp = (tempcx & 0xFF00) >> 8;
  4834. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x17,temp); /* 0x17 SR0A */
  4835. tempax = modeflag;
  4836. temp = (tempax & 0xFF00) >> 8;
  4837. temp = (temp >> 1) & 0x09;
  4838. if(!(SiS_Pr->SiS_VBType & VB_SIS301)) temp |= 0x01; /* Always 8 dotclock */
  4839. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x16,temp); /* 0x16 SR01 */
  4840. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0F,0x00); /* 0x0F CR14 */
  4841. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x12,0x00); /* 0x12 CR17 */
  4842. temp = 0x00;
  4843. if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) {
  4844. if(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x01) {
  4845. temp = 0x80;
  4846. }
  4847. }
  4848. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1A,temp); /* 0x1A SR0E */
  4849. temp = SiS_GetRegByte((SiS_Pr->SiS_P3ca+0x02));
  4850. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,temp);
  4851. }
  4852. /* Setup panel link
  4853. * This is used for LVDS, LCDA and Chrontel TV output
  4854. * 300/LVDS+TV, 300/301B-DH, 315/LVDS+TV, 315/LCDA
  4855. */
  4856. static void
  4857. SiS_SetGroup1_LVDS(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
  4858. PSIS_HW_INFO HwInfo, USHORT RefreshRateTableIndex)
  4859. {
  4860. USHORT modeflag,resinfo;
  4861. USHORT push2,tempax,tempbx,tempcx,temp;
  4862. ULONG tempeax=0,tempebx,tempecx,tempvcfact=0;
  4863. BOOLEAN islvds = FALSE, issis = FALSE, chkdclkfirst = FALSE;
  4864. #ifdef SIS300
  4865. USHORT crt2crtc;
  4866. #endif
  4867. #ifdef SIS315H
  4868. USHORT pushcx;
  4869. #endif
  4870. if(ModeNo <= 0x13) {
  4871. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  4872. resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
  4873. #ifdef SIS300
  4874. crt2crtc = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  4875. #endif
  4876. } else if(SiS_Pr->UseCustomMode) {
  4877. modeflag = SiS_Pr->CModeFlag;
  4878. resinfo = 0;
  4879. #ifdef SIS300
  4880. crt2crtc = 0;
  4881. #endif
  4882. } else {
  4883. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  4884. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  4885. #ifdef SIS300
  4886. crt2crtc = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  4887. #endif
  4888. }
  4889. /* is lvds if really LVDS, or 301B-DH with external LVDS transmitter */
  4890. if((SiS_Pr->SiS_IF_DEF_LVDS == 1) || (SiS_Pr->SiS_VBType & VB_NoLCD)) {
  4891. islvds = TRUE;
  4892. }
  4893. /* is really sis if sis bridge, but not 301B-DH */
  4894. if((SiS_Pr->SiS_VBType & VB_SISVB) && (!(SiS_Pr->SiS_VBType & VB_NoLCD))) {
  4895. issis = TRUE;
  4896. }
  4897. if((HwInfo->jChipType >= SIS_315H) && (islvds) && (!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA))) {
  4898. if((!SiS_Pr->SiS_IF_DEF_FSTN) && (!SiS_Pr->SiS_IF_DEF_DSTN)) {
  4899. chkdclkfirst = TRUE;
  4900. }
  4901. }
  4902. #ifdef SIS315H
  4903. if((HwInfo->jChipType >= SIS_315H) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  4904. if(IS_SIS330) {
  4905. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x10);
  4906. } else if(IS_SIS740) {
  4907. if(islvds) {
  4908. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,0xfb,0x04);
  4909. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x03);
  4910. } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
  4911. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x10);
  4912. }
  4913. } else {
  4914. if(islvds) {
  4915. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,0xfb,0x04);
  4916. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x00);
  4917. } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
  4918. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2D,0x0f);
  4919. if(SiS_Pr->SiS_VBType & VB_SIS301C) {
  4920. if((SiS_Pr->SiS_LCDResInfo == Panel_1024x768) ||
  4921. (SiS_Pr->SiS_LCDResInfo == Panel_1280x1024)) {
  4922. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x20);
  4923. }
  4924. }
  4925. }
  4926. }
  4927. }
  4928. #endif
  4929. /* Horizontal */
  4930. tempax = SiS_Pr->SiS_LCDHDES;
  4931. if(islvds) {
  4932. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4933. if((!SiS_Pr->SiS_IF_DEF_FSTN) && (!SiS_Pr->SiS_IF_DEF_DSTN)) {
  4934. if((SiS_Pr->SiS_LCDResInfo == Panel_640x480) &&
  4935. (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode))) {
  4936. tempax -= 8;
  4937. }
  4938. }
  4939. }
  4940. }
  4941. temp = (tempax & 0x0007);
  4942. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1A,temp); /* BPLHDESKEW[2:0] */
  4943. temp = (tempax >> 3) & 0x00FF;
  4944. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x16,temp); /* BPLHDESKEW[10:3] */
  4945. tempbx = SiS_Pr->SiS_HDE;
  4946. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4947. if((SiS_Pr->SiS_LCDResInfo == Panel_640x480_2) ||
  4948. (SiS_Pr->SiS_LCDResInfo == Panel_640x480_3)) {
  4949. tempbx >>= 1;
  4950. }
  4951. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  4952. tempbx = SiS_Pr->PanelXRes;
  4953. }
  4954. }
  4955. tempax += tempbx;
  4956. if(tempax >= SiS_Pr->SiS_HT) tempax -= SiS_Pr->SiS_HT;
  4957. temp = tempax;
  4958. if(temp & 0x07) temp += 8;
  4959. temp >>= 3;
  4960. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x17,temp); /* BPLHDEE */
  4961. tempcx = (SiS_Pr->SiS_HT - tempbx) >> 2;
  4962. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4963. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  4964. if(SiS_Pr->PanelHRS != 999) tempcx = SiS_Pr->PanelHRS;
  4965. }
  4966. }
  4967. tempcx += tempax;
  4968. if(tempcx >= SiS_Pr->SiS_HT) tempcx -= SiS_Pr->SiS_HT;
  4969. temp = (tempcx >> 3) & 0x00FF;
  4970. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4971. if(SiS_Pr->SiS_IF_DEF_TRUMPION) {
  4972. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  4973. switch(ModeNo) {
  4974. case 0x04:
  4975. case 0x05:
  4976. case 0x0d: temp = 0x56; break;
  4977. case 0x10: temp = 0x60; break;
  4978. case 0x13: temp = 0x5f; break;
  4979. case 0x40:
  4980. case 0x41:
  4981. case 0x4f:
  4982. case 0x43:
  4983. case 0x44:
  4984. case 0x62:
  4985. case 0x56:
  4986. case 0x53:
  4987. case 0x5d:
  4988. case 0x5e: temp = 0x54; break;
  4989. }
  4990. }
  4991. }
  4992. }
  4993. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x14,temp); /* BPLHRS */
  4994. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4995. temp += 2;
  4996. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  4997. temp += 8;
  4998. if(SiS_Pr->PanelHRE != 999) {
  4999. temp = tempcx + SiS_Pr->PanelHRE;
  5000. if(temp >= SiS_Pr->SiS_HT) temp -= SiS_Pr->SiS_HT;
  5001. temp >>= 3;
  5002. }
  5003. }
  5004. } else {
  5005. temp += 10;
  5006. }
  5007. temp &= 0x1F;
  5008. temp |= ((tempcx & 0x07) << 5);
  5009. #if 0
  5010. if(SiS_Pr->SiS_IF_DEF_FSTN) temp = 0x20; /* WRONG? BIOS loads cl, not ah */
  5011. #endif
  5012. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x15,temp); /* BPLHRE */
  5013. /* Vertical */
  5014. tempax = SiS_Pr->SiS_VGAVDE;
  5015. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  5016. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  5017. tempax = SiS_Pr->PanelYRes;
  5018. }
  5019. }
  5020. tempbx = SiS_Pr->SiS_LCDVDES + tempax;
  5021. if(tempbx >= SiS_Pr->SiS_VT) tempbx -= SiS_Pr->SiS_VT;
  5022. push2 = tempbx;
  5023. tempcx = SiS_Pr->SiS_VGAVT - SiS_Pr->SiS_VGAVDE;
  5024. if(HwInfo->jChipType < SIS_315H) {
  5025. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  5026. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  5027. tempcx = SiS_Pr->SiS_VGAVT - SiS_Pr->PanelYRes;
  5028. }
  5029. }
  5030. }
  5031. if(islvds) tempcx >>= 1;
  5032. else tempcx >>= 2;
  5033. if( (SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) &&
  5034. (!(SiS_Pr->SiS_LCDInfo & LCDPass11)) &&
  5035. (SiS_Pr->PanelVRS != 999) ) {
  5036. tempcx = SiS_Pr->PanelVRS;
  5037. tempbx += tempcx;
  5038. if(issis) tempbx++;
  5039. } else {
  5040. tempbx += tempcx;
  5041. if(HwInfo->jChipType < SIS_315H) tempbx++;
  5042. else if(issis) tempbx++;
  5043. }
  5044. if(tempbx >= SiS_Pr->SiS_VT) tempbx -= SiS_Pr->SiS_VT; /* BPLVRS */
  5045. temp = tempbx & 0x00FF;
  5046. if(SiS_Pr->SiS_IF_DEF_TRUMPION) {
  5047. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  5048. if(ModeNo == 0x10) temp = 0xa9;
  5049. }
  5050. }
  5051. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,temp);
  5052. tempcx >>= 3;
  5053. tempcx++;
  5054. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  5055. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  5056. if(SiS_Pr->PanelVRE != 999) tempcx = SiS_Pr->PanelVRE;
  5057. }
  5058. }
  5059. tempcx += tempbx;
  5060. temp = tempcx & 0x000F;
  5061. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0xF0,temp); /* BPLVRE */
  5062. temp = ((tempbx >> 8) & 0x07) << 3;
  5063. if(SiS_Pr->SiS_IF_DEF_FSTN || SiS_Pr->SiS_IF_DEF_DSTN) {
  5064. if(SiS_Pr->SiS_HDE != 640) {
  5065. if(SiS_Pr->SiS_VGAVDE != SiS_Pr->SiS_VDE) temp |= 0x40;
  5066. }
  5067. } else if(SiS_Pr->SiS_VGAVDE != SiS_Pr->SiS_VDE) temp |= 0x40;
  5068. if(SiS_Pr->SiS_SetFlag & EnableLVDSDDA) temp |= 0x40;
  5069. tempbx = 0x87;
  5070. if((HwInfo->jChipType >= SIS_315H) ||
  5071. (HwInfo->jChipRevision >= 0x30)) {
  5072. tempbx = 0x07;
  5073. if((SiS_Pr->SiS_IF_DEF_CH70xx == 1) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
  5074. if(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x03) temp |= 0x80;
  5075. }
  5076. /* Chrontel 701x operates in 24bit mode (8-8-8, 2x12bit mutliplexed) via VGA2 */
  5077. if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) {
  5078. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  5079. if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x06) & 0x10) temp |= 0x80;
  5080. } else {
  5081. if(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x01) temp |= 0x80;
  5082. }
  5083. }
  5084. }
  5085. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x1A,tempbx,temp);
  5086. tempbx = push2; /* BPLVDEE */
  5087. tempcx = SiS_Pr->SiS_LCDVDES; /* BPLVDES */
  5088. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  5089. switch(SiS_Pr->SiS_LCDResInfo) {
  5090. case Panel_640x480:
  5091. tempbx = SiS_Pr->SiS_VGAVDE - 1;
  5092. tempcx = SiS_Pr->SiS_VGAVDE;
  5093. break;
  5094. case Panel_800x600:
  5095. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  5096. if(resinfo == SIS_RI_800x600) tempcx++;
  5097. }
  5098. break;
  5099. case Panel_1024x600:
  5100. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  5101. if(resinfo == SIS_RI_1024x600) tempcx++;
  5102. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  5103. if(resinfo == SIS_RI_800x600) tempcx++;
  5104. }
  5105. }
  5106. break;
  5107. case Panel_1024x768:
  5108. if(HwInfo->jChipType < SIS_315H) {
  5109. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  5110. if(resinfo == SIS_RI_1024x768) tempcx++;
  5111. }
  5112. }
  5113. break;
  5114. }
  5115. }
  5116. temp = ((tempbx >> 8) & 0x07) << 3;
  5117. temp = temp | ((tempcx >> 8) & 0x07);
  5118. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1D,temp);
  5119. /* if(SiS_Pr->SiS_IF_DEF_FSTN) tempbx++; */
  5120. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1C,tempbx);
  5121. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1B,tempcx);
  5122. /* Vertical scaling */
  5123. if(HwInfo->jChipType < SIS_315H) {
  5124. #ifdef SIS300 /* 300 series */
  5125. tempeax = SiS_Pr->SiS_VGAVDE << 6;
  5126. temp = (tempeax % (ULONG)SiS_Pr->SiS_VDE);
  5127. tempeax = tempeax / (ULONG)SiS_Pr->SiS_VDE;
  5128. if(temp) tempeax++;
  5129. if(SiS_Pr->SiS_SetFlag & EnableLVDSDDA) tempeax = 0x3F;
  5130. temp = (USHORT)(tempeax & 0x00FF);
  5131. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1E,temp); /* BPLVCFACT */
  5132. tempvcfact = temp;
  5133. #endif /* SIS300 */
  5134. } else {
  5135. #ifdef SIS315H /* 315 series */
  5136. tempeax = SiS_Pr->SiS_VGAVDE << 18;
  5137. tempebx = SiS_Pr->SiS_VDE;
  5138. temp = (tempeax % tempebx);
  5139. tempeax = tempeax / tempebx;
  5140. if(temp) tempeax++;
  5141. tempvcfact = tempeax;
  5142. temp = (USHORT)(tempeax & 0x00FF);
  5143. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x37,temp);
  5144. temp = (USHORT)((tempeax & 0x00FF00) >> 8);
  5145. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x36,temp);
  5146. temp = (USHORT)((tempeax & 0x00030000) >> 16);
  5147. if(SiS_Pr->SiS_VDE == SiS_Pr->SiS_VGAVDE) temp |= 0x04;
  5148. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x35,temp);
  5149. if(SiS_Pr->SiS_VBType & (VB_SIS301C | VB_SIS302ELV)) {
  5150. temp = (USHORT)(tempeax & 0x00FF);
  5151. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x3c,temp);
  5152. temp = (USHORT)((tempeax & 0x00FF00) >> 8);
  5153. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x3b,temp);
  5154. temp = (USHORT)(((tempeax & 0x00030000) >> 16) << 6);
  5155. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x3a,0x3f,temp);
  5156. temp = 0;
  5157. if(SiS_Pr->SiS_VDE != SiS_Pr->SiS_VGAVDE) temp |= 0x08;
  5158. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x30,0xf3,temp);
  5159. }
  5160. #endif
  5161. }
  5162. /* Horizontal scaling */
  5163. tempeax = SiS_Pr->SiS_VGAHDE; /* 1f = ( (VGAHDE * 65536) / ( (VGAHDE * 65536) / HDE ) ) - 1*/
  5164. if(chkdclkfirst) {
  5165. if(modeflag & HalfDCLK) tempeax >>= 1;
  5166. }
  5167. tempebx = tempeax << 16;
  5168. if(SiS_Pr->SiS_HDE == tempeax) {
  5169. tempecx = 0xFFFF;
  5170. } else {
  5171. tempecx = tempebx / SiS_Pr->SiS_HDE;
  5172. if(HwInfo->jChipType >= SIS_315H) {
  5173. if(tempebx % SiS_Pr->SiS_HDE) tempecx++;
  5174. }
  5175. }
  5176. if(HwInfo->jChipType >= SIS_315H) {
  5177. tempeax = (tempebx / tempecx) - 1;
  5178. } else {
  5179. tempeax = ((SiS_Pr->SiS_VGAHT << 16) / tempecx) - 1;
  5180. }
  5181. tempecx = (tempecx << 16) | (tempeax & 0xFFFF);
  5182. temp = (USHORT)(tempecx & 0x00FF);
  5183. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1F,temp);
  5184. if(HwInfo->jChipType >= SIS_315H) {
  5185. tempeax = (SiS_Pr->SiS_VGAVDE << 18) / tempvcfact;
  5186. tempbx = (USHORT)(tempeax & 0xFFFF);
  5187. } else {
  5188. tempeax = SiS_Pr->SiS_VGAVDE << 6;
  5189. tempbx = tempvcfact & 0x3f;
  5190. if(tempbx == 0) tempbx = 64;
  5191. tempeax /= tempbx;
  5192. tempbx = (USHORT)(tempeax & 0xFFFF);
  5193. }
  5194. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) tempbx--;
  5195. if(SiS_Pr->SiS_SetFlag & EnableLVDSDDA) {
  5196. if((!SiS_Pr->SiS_IF_DEF_FSTN) && (!SiS_Pr->SiS_IF_DEF_DSTN)) tempbx = 1;
  5197. else if(SiS_Pr->SiS_LCDResInfo != Panel_640x480) tempbx = 1;
  5198. }
  5199. temp = ((tempbx >> 8) & 0x07) << 3;
  5200. temp = temp | ((tempecx >> 8) & 0x07);
  5201. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x20,temp);
  5202. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x21,tempbx);
  5203. tempecx >>= 16; /* BPLHCFACT */
  5204. if(!chkdclkfirst) {
  5205. if(modeflag & HalfDCLK) tempecx >>= 1;
  5206. }
  5207. temp = (USHORT)((tempecx & 0xFF00) >> 8);
  5208. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x22,temp);
  5209. temp = (USHORT)(tempecx & 0x00FF);
  5210. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x23,temp);
  5211. #ifdef SIS315H
  5212. if(HwInfo->jChipType >= SIS_315H) {
  5213. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  5214. if((islvds) || (SiS_Pr->SiS_VBInfo & VB_SIS301LV302LV)) {
  5215. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1e,0x20);
  5216. }
  5217. } else {
  5218. if(islvds) {
  5219. if(HwInfo->jChipType == SIS_740) {
  5220. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1e,0x03);
  5221. } else {
  5222. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1e,0x23);
  5223. }
  5224. }
  5225. }
  5226. }
  5227. #endif
  5228. #ifdef SIS300
  5229. if(SiS_Pr->SiS_IF_DEF_TRUMPION) {
  5230. int i;
  5231. UCHAR TrumpMode13[4] = { 0x01, 0x10, 0x2c, 0x00 };
  5232. UCHAR TrumpMode10_1[4] = { 0x01, 0x10, 0x27, 0x00 };
  5233. UCHAR TrumpMode10_2[4] = { 0x01, 0x16, 0x10, 0x00 };
  5234. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x02,0xbf);
  5235. for(i=0; i<5; i++) {
  5236. SiS_SetTrumpionBlock(SiS_Pr, &SiS300_TrumpionData[crt2crtc][0]);
  5237. }
  5238. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  5239. if(ModeNo == 0x13) {
  5240. for(i=0; i<4; i++) {
  5241. SiS_SetTrumpionBlock(SiS_Pr, &TrumpMode13[0]);
  5242. }
  5243. } else if(ModeNo == 0x10) {
  5244. for(i=0; i<4; i++) {
  5245. SiS_SetTrumpionBlock(SiS_Pr, &TrumpMode10_1[0]);
  5246. SiS_SetTrumpionBlock(SiS_Pr, &TrumpMode10_2[0]);
  5247. }
  5248. }
  5249. }
  5250. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x02,0x40);
  5251. }
  5252. #endif
  5253. #ifdef SIS315H
  5254. if(SiS_Pr->SiS_IF_DEF_FSTN || SiS_Pr->SiS_IF_DEF_DSTN) {
  5255. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x25,0x00);
  5256. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x26,0x00);
  5257. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x27,0x00);
  5258. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x28,0x87);
  5259. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x29,0x5A);
  5260. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2A,0x4B);
  5261. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x44,~0x07,0x03);
  5262. tempax = SiS_Pr->SiS_HDE; /* Blps = lcdhdee(lcdhdes+HDE) + 64 */
  5263. if(SiS_Pr->SiS_LCDResInfo == Panel_640x480_2 ||
  5264. SiS_Pr->SiS_LCDResInfo == Panel_640x480_3) tempax >>= 1;
  5265. tempax += 64;
  5266. temp = tempax & 0x00FF;
  5267. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x38,temp);
  5268. temp = ((tempax & 0xFF00) >> 8) << 3;
  5269. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x35,~0x078,temp);
  5270. tempax += 32; /* Blpe=lBlps+32 */
  5271. temp = tempax & 0x00FF;
  5272. if(SiS_Pr->SiS_IF_DEF_FSTN) temp = 0;
  5273. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x39,temp);
  5274. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3A,0x00); /* Bflml=0 */
  5275. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x3C,~0x007,0x00);
  5276. tempax = SiS_Pr->SiS_VDE;
  5277. if(SiS_Pr->SiS_LCDResInfo == Panel_640x480_2 ||
  5278. SiS_Pr->SiS_LCDResInfo == Panel_640x480_3) tempax >>= 1;
  5279. tempax >>= 1;
  5280. temp = tempax & 0x00FF;
  5281. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3B,temp);
  5282. temp = ((tempax & 0xFF00) >> 8) << 3;
  5283. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x3C,~0x038,temp);
  5284. tempeax = SiS_Pr->SiS_HDE;
  5285. if(SiS_Pr->SiS_LCDResInfo == Panel_640x480_2 ||
  5286. SiS_Pr->SiS_LCDResInfo == Panel_640x480_3) tempeax >>= 1;
  5287. tempeax <<= 2; /* BDxFIFOSTOP = (HDE*4)/128 */
  5288. tempebx = 128;
  5289. temp = (USHORT)(tempeax % tempebx);
  5290. tempeax = tempeax / tempebx;
  5291. if(temp) tempeax++;
  5292. temp = (USHORT)(tempeax & 0x003F);
  5293. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x45,~0x0FF,temp);
  5294. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3F,0x00); /* BDxWadrst0 */
  5295. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3E,0x00);
  5296. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3D,0x10);
  5297. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x3C,~0x040,0x00);
  5298. tempax = SiS_Pr->SiS_HDE;
  5299. if(SiS_Pr->SiS_LCDResInfo == Panel_640x480_2 ||
  5300. SiS_Pr->SiS_LCDResInfo == Panel_640x480_3) tempax >>= 1;
  5301. tempax >>= 4; /* BDxWadroff = HDE*4/8/8 */
  5302. pushcx = tempax;
  5303. temp = tempax & 0x00FF;
  5304. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x43,temp);
  5305. temp = ((tempax & 0xFF00) >> 8) << 3;
  5306. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x44,~0x0F8,temp);
  5307. tempax = SiS_Pr->SiS_VDE; /* BDxWadrst1 = BDxWadrst0 + BDxWadroff * VDE */
  5308. if(SiS_Pr->SiS_LCDResInfo == Panel_640x480_2 ||
  5309. SiS_Pr->SiS_LCDResInfo == Panel_640x480_3) tempax >>= 1;
  5310. tempeax = (tempax * pushcx);
  5311. tempebx = 0x00100000 + tempeax;
  5312. temp = (USHORT)tempebx & 0x000000FF;
  5313. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x42,temp);
  5314. temp = (USHORT)((tempebx & 0x0000FF00) >> 8);
  5315. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x41,temp);
  5316. temp = (USHORT)((tempebx & 0x00FF0000) >> 16);
  5317. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x40,temp);
  5318. temp = (USHORT)(((tempebx & 0x01000000) >> 24) << 7);
  5319. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x3C,~0x080,temp);
  5320. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2F,0x03);
  5321. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x03,0x50);
  5322. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x04,0x00);
  5323. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2F,0x01);
  5324. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x19,0x38);
  5325. if(SiS_Pr->SiS_IF_DEF_FSTN) {
  5326. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2b,0x02);
  5327. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2c,0x00);
  5328. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2d,0x00);
  5329. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x35,0x0c);
  5330. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x36,0x00);
  5331. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x37,0x00);
  5332. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x38,0x80);
  5333. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x39,0xA0);
  5334. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3a,0x00);
  5335. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3b,0xf0);
  5336. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3c,0x00);
  5337. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3d,0x10);
  5338. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3e,0x00);
  5339. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3f,0x00);
  5340. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x40,0x10);
  5341. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x41,0x25);
  5342. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x42,0x80);
  5343. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x43,0x14);
  5344. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x44,0x03);
  5345. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x45,0x0a);
  5346. }
  5347. }
  5348. #endif /* SIS315H */
  5349. }
  5350. /* Set Part 1 */
  5351. static void
  5352. SiS_SetGroup1(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
  5353. PSIS_HW_INFO HwInfo, USHORT RefreshRateTableIndex)
  5354. {
  5355. #if defined(SIS300) || defined(SIS315H)
  5356. UCHAR *ROMAddr = HwInfo->pjVirtualRomBase;
  5357. #endif
  5358. USHORT temp=0, tempax=0, tempbx=0, tempcx=0, bridgeadd=0;
  5359. USHORT pushbx=0, CRT1Index=0, modeflag, resinfo=0;
  5360. #ifdef SIS315H
  5361. USHORT tempbl=0;
  5362. #endif
  5363. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  5364. SiS_SetGroup1_LVDS(SiS_Pr, ModeNo, ModeIdIndex, HwInfo, RefreshRateTableIndex);
  5365. return;
  5366. }
  5367. if(ModeNo <= 0x13) {
  5368. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  5369. } else if(SiS_Pr->UseCustomMode) {
  5370. modeflag = SiS_Pr->CModeFlag;
  5371. } else {
  5372. CRT1Index = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
  5373. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  5374. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  5375. }
  5376. SiS_SetCRT2Offset(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex, HwInfo);
  5377. if( ! ((HwInfo->jChipType >= SIS_315H) &&
  5378. (SiS_Pr->SiS_IF_DEF_LVDS == 1) &&
  5379. (SiS_Pr->SiS_VBInfo & SetInSlaveMode)) ) {
  5380. if(HwInfo->jChipType < SIS_315H ) {
  5381. #ifdef SIS300
  5382. SiS_SetCRT2FIFO_300(SiS_Pr, ModeNo, HwInfo);
  5383. #endif
  5384. } else {
  5385. #ifdef SIS315H
  5386. SiS_SetCRT2FIFO_310(SiS_Pr, HwInfo);
  5387. #endif
  5388. }
  5389. /* 1. Horizontal setup */
  5390. if(HwInfo->jChipType < SIS_315H ) {
  5391. #ifdef SIS300 /* ------------- 300 series --------------*/
  5392. temp = (SiS_Pr->SiS_VGAHT - 1) & 0x0FF; /* BTVGA2HT 0x08,0x09 */
  5393. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x08,temp); /* CRT2 Horizontal Total */
  5394. temp = (((SiS_Pr->SiS_VGAHT - 1) & 0xFF00) >> 8) << 4;
  5395. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x09,0x0f,temp); /* CRT2 Horizontal Total Overflow [7:4] */
  5396. temp = (SiS_Pr->SiS_VGAHDE + 12) & 0x0FF; /* BTVGA2HDEE 0x0A,0x0C */
  5397. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0A,temp); /* CRT2 Horizontal Display Enable End */
  5398. pushbx = SiS_Pr->SiS_VGAHDE + 12; /* bx BTVGA2HRS 0x0B,0x0C */
  5399. tempcx = (SiS_Pr->SiS_VGAHT - SiS_Pr->SiS_VGAHDE) >> 2;
  5400. tempbx = pushbx + tempcx;
  5401. tempcx <<= 1;
  5402. tempcx += tempbx;
  5403. bridgeadd = 12;
  5404. #endif /* SIS300 */
  5405. } else {
  5406. #ifdef SIS315H /* ------------------- 315/330 series --------------- */
  5407. tempcx = SiS_Pr->SiS_VGAHT; /* BTVGA2HT 0x08,0x09 */
  5408. if(modeflag & HalfDCLK) {
  5409. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  5410. tempcx >>= 1;
  5411. } else {
  5412. tempax = SiS_Pr->SiS_VGAHDE >> 1;
  5413. tempcx = SiS_Pr->SiS_HT - SiS_Pr->SiS_HDE + tempax;
  5414. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  5415. tempcx = SiS_Pr->SiS_HT - tempax;
  5416. }
  5417. }
  5418. }
  5419. tempcx--;
  5420. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x08,tempcx); /* CRT2 Horizontal Total */
  5421. temp = (tempcx >> 4) & 0xF0;
  5422. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x09,0x0F,temp); /* CRT2 Horizontal Total Overflow [7:4] */
  5423. tempcx = SiS_Pr->SiS_VGAHT; /* BTVGA2HDEE 0x0A,0x0C */
  5424. tempbx = SiS_Pr->SiS_VGAHDE;
  5425. tempcx -= tempbx;
  5426. tempcx >>= 2;
  5427. if(modeflag & HalfDCLK) {
  5428. tempbx >>= 1;
  5429. tempcx >>= 1;
  5430. }
  5431. tempbx += 16;
  5432. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0A,tempbx); /* CRT2 Horizontal Display Enable End */
  5433. pushbx = tempbx;
  5434. tempcx >>= 1;
  5435. tempbx += tempcx;
  5436. tempcx += tempbx;
  5437. bridgeadd = 16;
  5438. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  5439. if(HwInfo->jChipType >= SIS_661) {
  5440. if((SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) ||
  5441. (SiS_Pr->SiS_LCDResInfo == Panel_1280x1024)) {
  5442. if(resinfo == SIS_RI_1280x1024) {
  5443. tempcx = (tempcx & 0xff00) | 0x30;
  5444. } else if(resinfo == SIS_RI_1600x1200) {
  5445. tempcx = (tempcx & 0xff00) | 0xff;
  5446. }
  5447. }
  5448. }
  5449. }
  5450. #endif /* SIS315H */
  5451. } /* 315/330 series */
  5452. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  5453. if(SiS_Pr->UseCustomMode) {
  5454. tempbx = SiS_Pr->CHSyncStart + bridgeadd;
  5455. tempcx = SiS_Pr->CHSyncEnd + bridgeadd;
  5456. tempax = SiS_Pr->SiS_VGAHT;
  5457. if(modeflag & HalfDCLK) tempax >>= 1;
  5458. tempax--;
  5459. if(tempcx > tempax) tempcx = tempax;
  5460. }
  5461. if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) {
  5462. unsigned char cr4, cr14, cr5, cr15;
  5463. if(SiS_Pr->UseCustomMode) {
  5464. cr4 = SiS_Pr->CCRT1CRTC[4];
  5465. cr14 = SiS_Pr->CCRT1CRTC[14];
  5466. cr5 = SiS_Pr->CCRT1CRTC[5];
  5467. cr15 = SiS_Pr->CCRT1CRTC[15];
  5468. } else {
  5469. cr4 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[4];
  5470. cr14 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[14];
  5471. cr5 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[5];
  5472. cr15 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[15];
  5473. }
  5474. tempbx = ((cr4 | ((cr14 & 0xC0) << 2)) - 3) << 3; /* (VGAHRS-3)*8 */
  5475. tempcx = (((cr5 & 0x1f) | ((cr15 & 0x04) << (5-2))) - 3) << 3; /* (VGAHRE-3)*8 */
  5476. tempcx &= 0x00FF;
  5477. tempcx |= (tempbx & 0xFF00);
  5478. tempbx += bridgeadd;
  5479. tempcx += bridgeadd;
  5480. tempax = SiS_Pr->SiS_VGAHT;
  5481. if(modeflag & HalfDCLK) tempax >>= 1;
  5482. tempax--;
  5483. if(tempcx > tempax) tempcx = tempax;
  5484. }
  5485. if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) {
  5486. tempbx = 1040;
  5487. tempcx = 1044; /* HWCursor bug! */
  5488. }
  5489. }
  5490. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0B,tempbx); /* CRT2 Horizontal Retrace Start */
  5491. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0D,tempcx); /* CRT2 Horizontal Retrace End */
  5492. temp = ((tempbx >> 8) & 0x0F) | ((pushbx >> 4) & 0xF0);
  5493. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0C,temp); /* Overflow */
  5494. /* 2. Vertical setup */
  5495. tempcx = SiS_Pr->SiS_VGAVT - 1;
  5496. temp = tempcx & 0x00FF;
  5497. if(HwInfo->jChipType < SIS_661) {
  5498. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  5499. if(HwInfo->jChipType < SIS_315H) {
  5500. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  5501. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToSVIDEO | SetCRT2ToAVIDEO)) {
  5502. temp--;
  5503. }
  5504. }
  5505. } else {
  5506. temp--;
  5507. }
  5508. } else if(HwInfo->jChipType >= SIS_315H) {
  5509. temp--;
  5510. }
  5511. }
  5512. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0E,temp); /* CRT2 Vertical Total */
  5513. tempbx = SiS_Pr->SiS_VGAVDE - 1;
  5514. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0F,tempbx); /* CRT2 Vertical Display Enable End */
  5515. temp = ((tempbx >> 5) & 0x38) | ((tempcx >> 8) & 0x07);
  5516. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x12,temp); /* Overflow */
  5517. if((HwInfo->jChipType >= SIS_315H) && (HwInfo->jChipType < SIS_661)) {
  5518. tempbx++;
  5519. tempax = tempbx;
  5520. tempcx++;
  5521. tempcx -= tempax;
  5522. tempcx >>= 2;
  5523. tempbx += tempcx;
  5524. if(tempcx < 4) tempcx = 4;
  5525. tempcx >>= 2;
  5526. tempcx += tempbx;
  5527. tempcx++;
  5528. } else {
  5529. tempbx = (SiS_Pr->SiS_VGAVT + SiS_Pr->SiS_VGAVDE) >> 1; /* BTVGA2VRS 0x10,0x11 */
  5530. tempcx = ((SiS_Pr->SiS_VGAVT - SiS_Pr->SiS_VGAVDE) >> 4) + tempbx + 1; /* BTVGA2VRE 0x11 */
  5531. }
  5532. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  5533. if(SiS_Pr->UseCustomMode) {
  5534. tempbx = SiS_Pr->CVSyncStart;
  5535. tempcx = SiS_Pr->CVSyncEnd;
  5536. }
  5537. if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) {
  5538. unsigned char cr8, cr7, cr13;
  5539. if(SiS_Pr->UseCustomMode) {
  5540. cr8 = SiS_Pr->CCRT1CRTC[8];
  5541. cr7 = SiS_Pr->CCRT1CRTC[7];
  5542. cr13 = SiS_Pr->CCRT1CRTC[13];
  5543. tempcx = SiS_Pr->CCRT1CRTC[9];
  5544. } else {
  5545. cr8 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[8];
  5546. cr7 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[7];
  5547. cr13 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[13];
  5548. tempcx = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[9];
  5549. }
  5550. tempbx = cr8;
  5551. if(cr7 & 0x04) tempbx |= 0x0100;
  5552. if(cr7 & 0x80) tempbx |= 0x0200;
  5553. if(cr13 & 0x08) tempbx |= 0x0400;
  5554. }
  5555. }
  5556. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x10,tempbx); /* CRT2 Vertical Retrace Start */
  5557. temp = ((tempbx >> 4) & 0x70) | (tempcx & 0x0F);
  5558. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x11,temp); /* CRT2 Vert. Retrace End; Overflow */
  5559. /* 3. Panel delay compensation */
  5560. if(HwInfo->jChipType < SIS_315H) {
  5561. #ifdef SIS300 /* ---------- 300 series -------------- */
  5562. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  5563. temp = 0x20;
  5564. if(HwInfo->jChipType == SIS_300) {
  5565. temp = 0x10;
  5566. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) temp = 0x2c;
  5567. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) temp = 0x20;
  5568. }
  5569. if(SiS_Pr->SiS_VBType & VB_SIS301) {
  5570. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) temp = 0x20;
  5571. }
  5572. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x960) temp = 0x24;
  5573. if(SiS_Pr->SiS_LCDResInfo == Panel_Custom) temp = 0x2c;
  5574. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) temp = 0x08;
  5575. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  5576. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) temp = 0x2c;
  5577. else temp = 0x20;
  5578. }
  5579. if(SiS_Pr->SiS_UseROM) {
  5580. if(ROMAddr[0x220] & 0x80) {
  5581. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoYPbPrHiVision)
  5582. temp = ROMAddr[0x221];
  5583. else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision)
  5584. temp = ROMAddr[0x222];
  5585. else if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024)
  5586. temp = ROMAddr[0x223];
  5587. else
  5588. temp = ROMAddr[0x224];
  5589. temp &= 0x3c;
  5590. }
  5591. }
  5592. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  5593. if(SiS_Pr->PDC != -1) temp = SiS_Pr->PDC & 0x3c;
  5594. }
  5595. } else {
  5596. temp = 0x20;
  5597. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
  5598. if(SiS_Pr->SiS_LCDResInfo == Panel_640x480) temp = 0x04;
  5599. }
  5600. if(SiS_Pr->SiS_UseROM) {
  5601. if(ROMAddr[0x220] & 0x80) {
  5602. temp = ROMAddr[0x220] & 0x3c;
  5603. }
  5604. }
  5605. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  5606. if(SiS_Pr->PDC != -1) temp = SiS_Pr->PDC & 0x3c;
  5607. }
  5608. }
  5609. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,~0x3C,temp); /* Panel Link Delay Compensation; (Software Command Reset; Power Saving) */
  5610. #endif /* SIS300 */
  5611. } else {
  5612. #ifdef SIS315H /* --------------- 315/330 series ---------------*/
  5613. if(HwInfo->jChipType < SIS_661) {
  5614. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  5615. if(HwInfo->jChipType == SIS_740) temp = 0x03;
  5616. else temp = 0x00;
  5617. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) temp = 0x0a;
  5618. tempbl = 0xF0;
  5619. if(HwInfo->jChipType == SIS_650) {
  5620. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  5621. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) tempbl = 0x0F;
  5622. }
  5623. }
  5624. if(SiS_Pr->SiS_IF_DEF_DSTN || SiS_Pr->SiS_IF_DEF_FSTN) {
  5625. temp = 0x08;
  5626. tempbl = 0;
  5627. if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
  5628. if(ROMAddr[0x13c] & 0x80) tempbl = 0xf0;
  5629. }
  5630. }
  5631. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,tempbl,temp); /* Panel Link Delay Compensation */
  5632. }
  5633. } /* < 661 */
  5634. tempax = 0;
  5635. if(modeflag & DoubleScanMode) tempax |= 0x80;
  5636. if(modeflag & HalfDCLK) tempax |= 0x40;
  5637. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2C,0x3f,tempax);
  5638. #endif /* SIS315H */
  5639. }
  5640. } /* Slavemode */
  5641. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  5642. if((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) {
  5643. /* For 301BDH with LCD, we set up the Panel Link */
  5644. SiS_SetGroup1_LVDS(SiS_Pr, ModeNo, ModeIdIndex, HwInfo, RefreshRateTableIndex);
  5645. } else if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  5646. SiS_SetGroup1_301(SiS_Pr, ModeNo, ModeIdIndex, HwInfo, RefreshRateTableIndex);
  5647. }
  5648. } else {
  5649. if(HwInfo->jChipType < SIS_315H) {
  5650. SiS_SetGroup1_LVDS(SiS_Pr, ModeNo, ModeIdIndex, HwInfo, RefreshRateTableIndex);
  5651. } else {
  5652. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  5653. if((!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) || (SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  5654. SiS_SetGroup1_LVDS(SiS_Pr, ModeNo,ModeIdIndex, HwInfo,RefreshRateTableIndex);
  5655. }
  5656. } else {
  5657. SiS_SetGroup1_LVDS(SiS_Pr, ModeNo,ModeIdIndex, HwInfo,RefreshRateTableIndex);
  5658. }
  5659. }
  5660. }
  5661. }
  5662. /*********************************************/
  5663. /* SET PART 2 REGISTER GROUP */
  5664. /*********************************************/
  5665. #ifdef SIS315H
  5666. static UCHAR *
  5667. SiS_GetGroup2CLVXPtr(SiS_Private *SiS_Pr, int tabletype, PSIS_HW_INFO HwInfo)
  5668. {
  5669. const UCHAR *tableptr = NULL;
  5670. USHORT a, b, p = 0;
  5671. a = SiS_Pr->SiS_VGAHDE;
  5672. b = SiS_Pr->SiS_HDE;
  5673. if(tabletype) {
  5674. a = SiS_Pr->SiS_VGAVDE;
  5675. b = SiS_Pr->SiS_VDE;
  5676. }
  5677. if(a < b) {
  5678. tableptr = SiS_Part2CLVX_1;
  5679. } else if(a == b) {
  5680. tableptr = SiS_Part2CLVX_2;
  5681. } else {
  5682. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  5683. tableptr = SiS_Part2CLVX_4;
  5684. } else {
  5685. tableptr = SiS_Part2CLVX_3;
  5686. }
  5687. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  5688. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525i) tableptr = SiS_Part2CLVX_3;
  5689. else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) tableptr = SiS_Part2CLVX_3;
  5690. else tableptr = SiS_Part2CLVX_5;
  5691. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  5692. tableptr = SiS_Part2CLVX_6;
  5693. }
  5694. do {
  5695. if((tableptr[p] | tableptr[p+1] << 8) == a) break;
  5696. p += 0x42;
  5697. } while((tableptr[p] | tableptr[p+1] << 8) != 0xffff);
  5698. if((tableptr[p] | tableptr[p+1] << 8) == 0xffff) p -= 0x42;
  5699. }
  5700. p += 2;
  5701. return((UCHAR *)&tableptr[p]);
  5702. }
  5703. static void
  5704. SiS_SetGroup2_C_ELV(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
  5705. USHORT RefreshRateTableIndex, PSIS_HW_INFO HwInfo)
  5706. {
  5707. UCHAR *tableptr;
  5708. int i, j;
  5709. UCHAR temp;
  5710. if(!(SiS_Pr->SiS_VBType & (VB_SIS301C | VB_SIS302ELV))) return;
  5711. tableptr = SiS_GetGroup2CLVXPtr(SiS_Pr, 0, HwInfo);
  5712. for(i = 0x80, j = 0; i <= 0xbf; i++, j++) {
  5713. SiS_SetReg(SiS_Pr->SiS_Part2Port, i, tableptr[j]);
  5714. }
  5715. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  5716. tableptr = SiS_GetGroup2CLVXPtr(SiS_Pr, 1, HwInfo);
  5717. for(i = 0xc0, j = 0; i <= 0xff; i++, j++) {
  5718. SiS_SetReg(SiS_Pr->SiS_Part2Port, i, tableptr[j]);
  5719. }
  5720. }
  5721. temp = 0x10;
  5722. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) temp |= 0x04;
  5723. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x4e,0xeb,temp);
  5724. }
  5725. static BOOLEAN
  5726. SiS_GetCRT2Part2Ptr(SiS_Private *SiS_Pr,USHORT ModeNo,USHORT ModeIdIndex,
  5727. USHORT RefreshRateTableIndex,USHORT *CRT2Index,
  5728. USHORT *ResIndex,PSIS_HW_INFO HwInfo)
  5729. {
  5730. if(HwInfo->jChipType < SIS_315H) return FALSE;
  5731. if(ModeNo <= 0x13)
  5732. (*ResIndex) = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  5733. else
  5734. (*ResIndex) = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  5735. (*ResIndex) &= 0x3f;
  5736. (*CRT2Index) = 0;
  5737. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  5738. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
  5739. (*CRT2Index) = 200;
  5740. }
  5741. }
  5742. if(SiS_Pr->SiS_CustomT == CUT_ASUSA2H_2) {
  5743. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  5744. if(SiS_Pr->SiS_SetFlag & LCDVESATiming) (*CRT2Index) = 206;
  5745. }
  5746. }
  5747. return(((*CRT2Index) != 0));
  5748. }
  5749. #endif
  5750. #ifdef SIS300
  5751. static void
  5752. SiS_Group2LCDSpecial(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo, USHORT crt2crtc)
  5753. {
  5754. USHORT tempcx;
  5755. const UCHAR atable[] = {
  5756. 0xc3,0x9e,0xc3,0x9e,0x02,0x02,0x02,
  5757. 0xab,0x87,0xab,0x9e,0xe7,0x02,0x02
  5758. };
  5759. if(!SiS_Pr->UseCustomMode) {
  5760. if( ( ( (HwInfo->jChipType == SIS_630) ||
  5761. (HwInfo->jChipType == SIS_730) ) &&
  5762. (HwInfo->jChipRevision > 2) ) &&
  5763. (SiS_Pr->SiS_LCDResInfo == Panel_1024x768) &&
  5764. (!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) &&
  5765. (!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) ) {
  5766. if(ModeNo == 0x13) {
  5767. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,0xB9);
  5768. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x05,0xCC);
  5769. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x06,0xA6);
  5770. } else {
  5771. if((crt2crtc & 0x3F) == 4) {
  5772. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x2B);
  5773. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x13);
  5774. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,0xE5);
  5775. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x05,0x08);
  5776. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x06,0xE2);
  5777. }
  5778. }
  5779. }
  5780. if(HwInfo->jChipType < SIS_315H) {
  5781. if(SiS_Pr->SiS_LCDTypeInfo == 0x0c) {
  5782. crt2crtc &= 0x1f;
  5783. tempcx = 0;
  5784. if(!(SiS_Pr->SiS_VBInfo & SetNotSimuMode)) {
  5785. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  5786. tempcx += 7;
  5787. }
  5788. }
  5789. tempcx += crt2crtc;
  5790. if(crt2crtc >= 4) {
  5791. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x06,0xff);
  5792. }
  5793. if(!(SiS_Pr->SiS_VBInfo & SetNotSimuMode)) {
  5794. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  5795. if(crt2crtc == 4) {
  5796. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x28);
  5797. }
  5798. }
  5799. }
  5800. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x18);
  5801. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,atable[tempcx]);
  5802. }
  5803. }
  5804. }
  5805. }
  5806. /* For ECS A907. Highly preliminary. */
  5807. static void
  5808. SiS_Set300Part2Regs(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
  5809. USHORT ModeIdIndex, USHORT RefreshRateTableIndex,
  5810. USHORT ModeNo)
  5811. {
  5812. USHORT crt2crtc, resindex;
  5813. int i,j;
  5814. const SiS_Part2PortTblStruct *CRT2Part2Ptr = NULL;
  5815. if(HwInfo->jChipType != SIS_300) return;
  5816. if(!(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV)) return;
  5817. if(SiS_Pr->UseCustomMode) return;
  5818. if(ModeNo <= 0x13) {
  5819. crt2crtc = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  5820. } else {
  5821. crt2crtc = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  5822. }
  5823. resindex = crt2crtc & 0x3F;
  5824. if(SiS_Pr->SiS_SetFlag & LCDVESATiming) CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1024x768_1;
  5825. else CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1024x768_2;
  5826. /* The BIOS code (1.16.51,56) is obviously a fragment! */
  5827. if(ModeNo > 0x13) {
  5828. CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1024x768_1;
  5829. resindex = 4;
  5830. }
  5831. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x01,0x80,(CRT2Part2Ptr+resindex)->CR[0]);
  5832. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x02,0x80,(CRT2Part2Ptr+resindex)->CR[1]);
  5833. for(i = 2, j = 0x04; j <= 0x06; i++, j++ ) {
  5834. SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]);
  5835. }
  5836. for(j = 0x1c; j <= 0x1d; i++, j++ ) {
  5837. SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]);
  5838. }
  5839. for(j = 0x1f; j <= 0x21; i++, j++ ) {
  5840. SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]);
  5841. }
  5842. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x23,(CRT2Part2Ptr+resindex)->CR[10]);
  5843. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x25,0x0f,(CRT2Part2Ptr+resindex)->CR[11]);
  5844. }
  5845. #endif
  5846. static void
  5847. SiS_SetTVSpecial(SiS_Private *SiS_Pr, USHORT ModeNo)
  5848. {
  5849. if(!(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV)) return;
  5850. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoHiVision)) return;
  5851. if(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p)) return;
  5852. if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) {
  5853. if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) {
  5854. const UCHAR specialtv[] = {
  5855. 0xa7,0x07,0xf2,0x6e,0x17,0x8b,0x73,0x53,
  5856. 0x13,0x40,0x34,0xf4,0x63,0xbb,0xcc,0x7a,
  5857. 0x58,0xe4,0x73,0xda,0x13
  5858. };
  5859. int i, j;
  5860. for(i = 0x1c, j = 0; i <= 0x30; i++, j++) {
  5861. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,specialtv[j]);
  5862. }
  5863. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x43,0x72);
  5864. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750)) {
  5865. if(SiS_Pr->SiS_TVMode & TVSetPALM) {
  5866. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x14);
  5867. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x1b);
  5868. } else {
  5869. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x14); /* 15 */
  5870. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x1a); /* 1b */
  5871. }
  5872. }
  5873. }
  5874. } else {
  5875. if((ModeNo == 0x38) || (ModeNo == 0x4a) || (ModeNo == 0x64) ||
  5876. (ModeNo == 0x52) || (ModeNo == 0x58) || (ModeNo == 0x5c)) {
  5877. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x1b); /* 21 */
  5878. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x54); /* 5a */
  5879. } else {
  5880. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x1a); /* 21 */
  5881. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x53); /* 5a */
  5882. }
  5883. }
  5884. }
  5885. static void
  5886. SiS_SetGroup2_Tail(SiS_Private *SiS_Pr, USHORT ModeNo)
  5887. {
  5888. USHORT temp;
  5889. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
  5890. if(SiS_Pr->SiS_VGAVDE == 525) {
  5891. temp = 0xc3;
  5892. if(SiS_Pr->SiS_ModeType <= ModeVGA) {
  5893. temp++;
  5894. if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) temp += 2;
  5895. }
  5896. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2f,temp);
  5897. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x30,0xb3);
  5898. } else if(SiS_Pr->SiS_VGAVDE == 420) {
  5899. temp = 0x4d;
  5900. if(SiS_Pr->SiS_ModeType <= ModeVGA) {
  5901. temp++;
  5902. if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) temp++;
  5903. }
  5904. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2f,temp);
  5905. }
  5906. }
  5907. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  5908. if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) {
  5909. if(SiS_Pr->SiS_VBType & VB_SIS301B302B) {
  5910. SiS_SetRegOR(SiS_Pr->SiS_Part2Port,0x1a,0x03);
  5911. /* Not always for LV, see SetGrp2 */
  5912. }
  5913. temp = 1;
  5914. if(ModeNo <= 0x13) temp = 3;
  5915. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x0b,temp);
  5916. }
  5917. #if 0
  5918. /* 651+301C, for 1280x768 - do I really need that? */
  5919. if((SiS_Pr->SiS_PanelXRes == 1280) && (SiS_Pr->SiS_PanelYRes == 768)) {
  5920. if(SiS_Pr->SiS_VBInfo & SetSimuScanMode) {
  5921. if(((SiS_Pr->SiS_HDE == 640) && (SiS_Pr->SiS_VDE == 480)) ||
  5922. ((SiS_Pr->SiS_HDE == 320) && (SiS_Pr->SiS_VDE == 240))) {
  5923. SiS_SetReg(SiS_Part2Port,0x01,0x2b);
  5924. SiS_SetReg(SiS_Part2Port,0x02,0x13);
  5925. SiS_SetReg(SiS_Part2Port,0x04,0xe5);
  5926. SiS_SetReg(SiS_Part2Port,0x05,0x08);
  5927. SiS_SetReg(SiS_Part2Port,0x06,0xe2);
  5928. SiS_SetReg(SiS_Part2Port,0x1c,0x21);
  5929. SiS_SetReg(SiS_Part2Port,0x1d,0x45);
  5930. SiS_SetReg(SiS_Part2Port,0x1f,0x0b);
  5931. SiS_SetReg(SiS_Part2Port,0x20,0x00);
  5932. SiS_SetReg(SiS_Part2Port,0x21,0xa9);
  5933. SiS_SetReg(SiS_Part2Port,0x23,0x0b);
  5934. SiS_SetReg(SiS_Part2Port,0x25,0x04);
  5935. }
  5936. }
  5937. }
  5938. #endif
  5939. }
  5940. }
  5941. static void
  5942. SiS_SetGroup2(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,USHORT RefreshRateTableIndex,
  5943. PSIS_HW_INFO HwInfo)
  5944. {
  5945. USHORT i, j, tempax, tempbx, tempcx, tempch, tempcl, temp;
  5946. USHORT push2, modeflag, crt2crtc, bridgeoffset;
  5947. ULONG longtemp;
  5948. const UCHAR *PhasePoint;
  5949. const UCHAR *TimingPoint;
  5950. #ifdef SIS315H
  5951. USHORT resindex, CRT2Index;
  5952. const SiS_Part2PortTblStruct *CRT2Part2Ptr = NULL;
  5953. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) return;
  5954. #endif
  5955. if(ModeNo <= 0x13) {
  5956. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  5957. crt2crtc = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  5958. } else if(SiS_Pr->UseCustomMode) {
  5959. modeflag = SiS_Pr->CModeFlag;
  5960. crt2crtc = 0;
  5961. } else {
  5962. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  5963. crt2crtc = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  5964. }
  5965. temp = 0;
  5966. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToAVIDEO)) temp |= 0x08;
  5967. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToSVIDEO)) temp |= 0x04;
  5968. if(SiS_Pr->SiS_VBInfo & SetCRT2ToSCART) temp |= 0x02;
  5969. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) temp |= 0x01;
  5970. if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) temp |= 0x10;
  5971. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x00,temp);
  5972. PhasePoint = SiS_Pr->SiS_PALPhase;
  5973. TimingPoint = SiS_Pr->SiS_PALTiming;
  5974. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  5975. TimingPoint = SiS_Pr->SiS_HiTVExtTiming;
  5976. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  5977. TimingPoint = SiS_Pr->SiS_HiTVSt2Timing;
  5978. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) {
  5979. TimingPoint = SiS_Pr->SiS_HiTVSt1Timing;
  5980. #if 0
  5981. if(!(modeflag & Charx8Dot)) TimingPoint = SiS_Pr->SiS_HiTVTextTiming;
  5982. #endif
  5983. }
  5984. }
  5985. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  5986. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) TimingPoint = &SiS_YPbPrTable[2][0];
  5987. else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) TimingPoint = &SiS_YPbPrTable[1][0];
  5988. else TimingPoint = &SiS_YPbPrTable[0][0];
  5989. PhasePoint = SiS_Pr->SiS_NTSCPhase;
  5990. } else if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  5991. if( (SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) &&
  5992. ( (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) ||
  5993. (SiS_Pr->SiS_TVMode & TVSetTVSimuMode) ) ) {
  5994. PhasePoint = SiS_Pr->SiS_PALPhase2;
  5995. }
  5996. } else {
  5997. TimingPoint = SiS_Pr->SiS_NTSCTiming;
  5998. PhasePoint = SiS_Pr->SiS_NTSCPhase;
  5999. if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) {
  6000. PhasePoint = SiS_Pr->SiS_PALPhase;
  6001. }
  6002. if( (SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) &&
  6003. ( (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) ||
  6004. (SiS_Pr->SiS_TVMode & TVSetTVSimuMode) ) ) {
  6005. PhasePoint = SiS_Pr->SiS_NTSCPhase2;
  6006. if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) {
  6007. PhasePoint = SiS_Pr->SiS_PALPhase2;
  6008. }
  6009. }
  6010. }
  6011. if(SiS_Pr->SiS_TVMode & TVSetPALM) {
  6012. PhasePoint = SiS_Pr->SiS_PALMPhase;
  6013. if( (SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) &&
  6014. ( (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) ||
  6015. (SiS_Pr->SiS_TVMode & TVSetTVSimuMode) ) ) {
  6016. PhasePoint = SiS_Pr->SiS_PALMPhase2;
  6017. }
  6018. }
  6019. if(SiS_Pr->SiS_TVMode & TVSetPALN) {
  6020. PhasePoint = SiS_Pr->SiS_PALNPhase;
  6021. if( (SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) &&
  6022. ( (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) ||
  6023. (SiS_Pr->SiS_TVMode & TVSetTVSimuMode) ) ) {
  6024. PhasePoint = SiS_Pr->SiS_PALNPhase2;
  6025. }
  6026. }
  6027. if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) {
  6028. PhasePoint = SiS_Pr->SiS_SpecialPhase;
  6029. if(SiS_Pr->SiS_TVMode & TVSetPALM) {
  6030. PhasePoint = SiS_Pr->SiS_SpecialPhaseM;
  6031. } else if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) {
  6032. PhasePoint = SiS_Pr->SiS_SpecialPhaseJ;
  6033. }
  6034. }
  6035. for(i=0x31, j=0; i<=0x34; i++, j++) {
  6036. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,PhasePoint[j]);
  6037. }
  6038. for(i=0x01, j=0; i<=0x2D; i++, j++) {
  6039. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,TimingPoint[j]);
  6040. }
  6041. for(i=0x39; i<=0x45; i++, j++) {
  6042. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,TimingPoint[j]);
  6043. }
  6044. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  6045. if(SiS_Pr->SiS_ModeType != ModeText) {
  6046. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x3A,0x1F);
  6047. }
  6048. }
  6049. SiS_SetRegOR(SiS_Pr->SiS_Part2Port,0x0A,SiS_Pr->SiS_NewFlickerMode);
  6050. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x35,SiS_Pr->SiS_RY1COE);
  6051. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x36,SiS_Pr->SiS_RY2COE);
  6052. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x37,SiS_Pr->SiS_RY3COE);
  6053. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x38,SiS_Pr->SiS_RY4COE);
  6054. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) tempax = 950;
  6055. else if(SiS_Pr->SiS_TVMode & TVSetPAL) tempax = 520;
  6056. else tempax = 440; /* NTSC, YPbPr 525, 750 */
  6057. if( ( (!(SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoHiVision)) && (SiS_Pr->SiS_VDE <= tempax) ) ||
  6058. ( (SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoHiVision) &&
  6059. ((SiS_Pr->SiS_VGAHDE == 1024) || (SiS_Pr->SiS_VDE <= tempax)) ) ) {
  6060. tempax -= SiS_Pr->SiS_VDE;
  6061. tempax >>= 2;
  6062. tempax &= 0x00ff;
  6063. temp = tempax + (USHORT)TimingPoint[0];
  6064. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,temp);
  6065. temp = tempax + (USHORT)TimingPoint[1];
  6066. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,temp);
  6067. if((SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoYPbPrHiVision) && (SiS_Pr->SiS_VGAHDE >= 1024)) {
  6068. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  6069. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x1b); /* 19 */
  6070. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x54); /* 52 */
  6071. } else {
  6072. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x17);
  6073. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x1d);
  6074. }
  6075. }
  6076. }
  6077. tempcx = SiS_Pr->SiS_HT;
  6078. if(SiS_IsDualLink(SiS_Pr, HwInfo)) tempcx >>= 1;
  6079. tempcx--;
  6080. if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) tempcx--;
  6081. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x1B,tempcx);
  6082. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1D,0xF0,((tempcx >> 8) & 0x0f));
  6083. tempcx = SiS_Pr->SiS_HT >> 1;
  6084. if(SiS_IsDualLink(SiS_Pr, HwInfo)) tempcx >>= 1;
  6085. tempcx += 7;
  6086. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) tempcx -= 4;
  6087. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x22,0x0F,((tempcx << 4) & 0xf0));
  6088. tempbx = TimingPoint[j] | (TimingPoint[j+1] << 8);
  6089. tempbx += tempcx;
  6090. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x24,tempbx);
  6091. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x25,0x0F,((tempbx >> 4) & 0xf0));
  6092. tempbx += 8;
  6093. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  6094. tempbx -= 4;
  6095. tempcx = tempbx;
  6096. }
  6097. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x29,0x0F,((tempbx << 4) & 0xf0));
  6098. j += 2;
  6099. tempcx += (TimingPoint[j] | (TimingPoint[j+1] << 8));
  6100. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x27,tempcx);
  6101. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x28,0x0F,((tempcx >> 4) & 0xf0));
  6102. tempcx += 8;
  6103. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) tempcx -= 4;
  6104. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2A,0x0F,((tempcx << 4) & 0xf0));
  6105. tempcx = SiS_Pr->SiS_HT >> 1;
  6106. if(SiS_IsDualLink(SiS_Pr, HwInfo)) tempcx >>= 1;
  6107. j += 2;
  6108. tempcx -= (TimingPoint[j] | ((TimingPoint[j+1]) << 8));
  6109. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2D,0x0F,((tempcx << 4) & 0xf0));
  6110. tempcx -= 11;
  6111. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
  6112. tempcx = SiS_GetVGAHT2(SiS_Pr) - 1;
  6113. }
  6114. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2E,tempcx);
  6115. tempbx = SiS_Pr->SiS_VDE;
  6116. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  6117. if(SiS_Pr->SiS_VGAVDE == 360) tempbx = 746;
  6118. if(SiS_Pr->SiS_VGAVDE == 375) tempbx = 746;
  6119. if(SiS_Pr->SiS_VGAVDE == 405) tempbx = 853;
  6120. } else if( (SiS_Pr->SiS_VBInfo & SetCRT2ToTV) &&
  6121. (!(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p|TVSetYPbPr750p))) ) {
  6122. tempbx >>= 1;
  6123. if(HwInfo->jChipType >= SIS_315H) {
  6124. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) {
  6125. if((ModeNo <= 0x13) && (crt2crtc == 1)) tempbx++;
  6126. } else if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  6127. if(SiS_Pr->SiS_ModeType <= ModeVGA) {
  6128. if(crt2crtc == 4) tempbx++;
  6129. }
  6130. }
  6131. }
  6132. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  6133. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  6134. if((ModeNo == 0x2f) || (ModeNo == 0x5d) || (ModeNo == 0x5e)) tempbx++;
  6135. }
  6136. if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) {
  6137. if(ModeNo == 0x03) tempbx++; /* From 1.10.7w - doesn't make sense */
  6138. }
  6139. }
  6140. }
  6141. tempbx -= 2;
  6142. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2F,tempbx);
  6143. temp = (tempcx >> 8) & 0x0F;
  6144. temp |= ((tempbx >> 2) & 0xC0);
  6145. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToSVIDEO | SetCRT2ToAVIDEO)) {
  6146. temp |= 0x10;
  6147. if(SiS_Pr->SiS_VBInfo & SetCRT2ToAVIDEO) temp |= 0x20;
  6148. }
  6149. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x30,temp);
  6150. if(SiS_Pr->SiS_VBType & (VB_SIS301C | VB_SIS302LV | VB_SIS302ELV)) {
  6151. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x10,0xdf,((tempbx & 0x0400) >> 5));
  6152. }
  6153. #if 0
  6154. /* TEST qqqq */
  6155. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  6156. for(i=0x01, j=0; i<=0x2D; i++, j++) {
  6157. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,TimingPoint[j]);
  6158. }
  6159. for(i=0x39; i<=0x45; i++, j++) {
  6160. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,TimingPoint[j]);
  6161. }
  6162. }
  6163. #endif
  6164. if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
  6165. tempbx = SiS_Pr->SiS_VDE;
  6166. if( (SiS_Pr->SiS_VBInfo & SetCRT2ToTV) &&
  6167. (!(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p))) ) {
  6168. tempbx >>= 1;
  6169. }
  6170. tempbx -= 3;
  6171. temp = ((tempbx >> 3) & 0x60) | 0x18;
  6172. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x46,temp);
  6173. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x47,tempbx);
  6174. if(SiS_Pr->SiS_VBType & (VB_SIS301C | VB_SIS302LV | VB_SIS302ELV)) {
  6175. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x10,0xbf,((tempbx & 0x0400) >> 4));
  6176. }
  6177. }
  6178. tempbx = 0;
  6179. if(!(modeflag & HalfDCLK)) {
  6180. if(SiS_Pr->SiS_VGAHDE >= SiS_Pr->SiS_HDE) {
  6181. tempax = 0;
  6182. tempbx |= 0x20;
  6183. }
  6184. }
  6185. tempch = tempcl = 0x01;
  6186. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  6187. if(SiS_Pr->SiS_VGAHDE >= 1024) {
  6188. if((!(modeflag & HalfDCLK)) || (HwInfo->jChipType < SIS_315H)) {
  6189. tempch = 0x19;
  6190. tempcl = 0x20;
  6191. if(SiS_Pr->SiS_VGAHDE >= 1280) {
  6192. tempch = 0x14;
  6193. tempbx &= ~0x20;
  6194. }
  6195. }
  6196. }
  6197. }
  6198. if(!(tempbx & 0x20)) {
  6199. if(modeflag & HalfDCLK) tempcl <<= 1;
  6200. longtemp = ((SiS_Pr->SiS_VGAHDE * tempch) / tempcl) << 13;
  6201. if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) longtemp <<= 3;
  6202. tempax = longtemp / SiS_Pr->SiS_HDE;
  6203. if(longtemp % SiS_Pr->SiS_HDE) tempax++;
  6204. tempbx |= ((tempax >> 8) & 0x1F);
  6205. tempcx = tempax >> 13;
  6206. }
  6207. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x44,tempax);
  6208. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x45,0xC0,tempbx);
  6209. if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
  6210. tempcx &= 0x07;
  6211. if(tempbx & 0x20) tempcx = 0;
  6212. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x46,0xF8,tempcx);
  6213. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  6214. tempbx = 0x0382;
  6215. tempcx = 0x007e;
  6216. } else {
  6217. tempbx = 0x0369;
  6218. tempcx = 0x0061;
  6219. }
  6220. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x4B,tempbx);
  6221. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x4C,tempcx);
  6222. temp = (tempcx & 0x0300) >> 6;
  6223. temp |= ((tempbx >> 8) & 0x03);
  6224. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  6225. temp |= 0x10;
  6226. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) temp |= 0x20;
  6227. else if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) temp |= 0x40;
  6228. }
  6229. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x4D,temp);
  6230. temp = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x43);
  6231. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x43,(temp - 3));
  6232. SiS_SetTVSpecial(SiS_Pr, ModeNo);
  6233. if(SiS_Pr->SiS_VBType & VB_SIS301C) {
  6234. temp = 0;
  6235. if(SiS_Pr->SiS_TVMode & TVSetPALM) temp = 8;
  6236. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x4e,0xf7,temp);
  6237. }
  6238. }
  6239. if(SiS_Pr->SiS_TVMode & TVSetPALM) {
  6240. if(!(SiS_Pr->SiS_TVMode & TVSetNTSC1024)) {
  6241. temp = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x01);
  6242. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,(temp - 1));
  6243. }
  6244. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xEF);
  6245. }
  6246. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  6247. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  6248. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x0B,0x00);
  6249. }
  6250. }
  6251. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) return;
  6252. /* From here: Part2 LCD setup */
  6253. tempbx = SiS_Pr->SiS_HDE;
  6254. if(SiS_IsDualLink(SiS_Pr, HwInfo)) tempbx >>= 1;
  6255. tempbx--; /* RHACTE = HDE - 1 */
  6256. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2C,tempbx);
  6257. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2B,0x0F,((tempbx >> 4) & 0xf0));
  6258. temp = 0x01;
  6259. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) {
  6260. if(SiS_Pr->SiS_ModeType == ModeEGA) {
  6261. if(SiS_Pr->SiS_VGAHDE >= 1024) {
  6262. temp = 0x02;
  6263. if(HwInfo->jChipType >= SIS_315H) {
  6264. if(SiS_Pr->SiS_SetFlag & LCDVESATiming) {
  6265. temp = 0x01;
  6266. }
  6267. }
  6268. }
  6269. }
  6270. }
  6271. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x0B,temp);
  6272. tempbx = SiS_Pr->SiS_VDE - 1;
  6273. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x03,tempbx);
  6274. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x0C,0xF8,((tempbx >> 8) & 0x07));
  6275. tempcx = SiS_Pr->SiS_VT - 1;
  6276. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x19,tempcx);
  6277. temp = (tempcx >> 3) & 0xE0;
  6278. if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) {
  6279. /* Enable dithering; only do this for 32bpp mode */
  6280. if(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x01) {
  6281. temp |= 0x10;
  6282. }
  6283. }
  6284. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1A,0x0f,temp);
  6285. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x09,0xF0);
  6286. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x0A,0xF0);
  6287. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x17,0xFB);
  6288. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x18,0xDF);
  6289. #ifdef SIS315H
  6290. if(SiS_GetCRT2Part2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex,
  6291. &CRT2Index, &resindex, HwInfo)) {
  6292. switch(CRT2Index) {
  6293. case 200: CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1024x768_1; break;
  6294. case 206: CRT2Part2Ptr = SiS310_CRT2Part2_Asus1024x768_3; break;
  6295. default: CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1024x768_3; break;
  6296. }
  6297. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x01,0x80,(CRT2Part2Ptr+resindex)->CR[0]);
  6298. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x02,0x80,(CRT2Part2Ptr+resindex)->CR[1]);
  6299. for(i = 2, j = 0x04; j <= 0x06; i++, j++ ) {
  6300. SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]);
  6301. }
  6302. for(j = 0x1c; j <= 0x1d; i++, j++ ) {
  6303. SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]);
  6304. }
  6305. for(j = 0x1f; j <= 0x21; i++, j++ ) {
  6306. SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]);
  6307. }
  6308. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x23,(CRT2Part2Ptr+resindex)->CR[10]);
  6309. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x25,0x0f,(CRT2Part2Ptr+resindex)->CR[11]);
  6310. SiS_SetGroup2_Tail(SiS_Pr, ModeNo);
  6311. } else {
  6312. #endif
  6313. /* Checked for 1024x768, 1280x1024, 1400x1050, 1600x1200 */
  6314. /* Clevo dual-link 1024x768 */
  6315. /* Compaq 1280x1024 has HT 1696 sometimes (calculation OK, if given HT is correct) */
  6316. /* Acer: OK, but uses different setting for VESA timing at 640/800/1024 and 640x400 */
  6317. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  6318. if((SiS_Pr->SiS_LCDInfo & LCDPass11) || (SiS_Pr->PanelYRes == SiS_Pr->SiS_VDE)) {
  6319. tempbx = SiS_Pr->SiS_VDE - 1;
  6320. tempcx = SiS_Pr->SiS_VT - 1;
  6321. } else {
  6322. tempbx = SiS_Pr->SiS_VDE + ((SiS_Pr->PanelYRes - SiS_Pr->SiS_VDE) / 2);
  6323. tempcx = SiS_Pr->SiS_VT - ((SiS_Pr->PanelYRes - SiS_Pr->SiS_VDE) / 2);
  6324. }
  6325. } else {
  6326. tempbx = SiS_Pr->PanelYRes;
  6327. tempcx = SiS_Pr->SiS_VT;
  6328. tempax = 1;
  6329. if(SiS_Pr->PanelYRes != SiS_Pr->SiS_VDE) {
  6330. tempax = SiS_Pr->PanelYRes;
  6331. /* if(SiS_Pr->SiS_VGAVDE == 525) tempax += 0x3c; */ /* 651+301C */
  6332. if(SiS_Pr->PanelYRes < SiS_Pr->SiS_VDE) {
  6333. tempax = tempcx = 0;
  6334. } else {
  6335. tempax -= SiS_Pr->SiS_VDE;
  6336. }
  6337. tempax >>= 1;
  6338. }
  6339. tempcx -= tempax; /* lcdvdes */
  6340. tempbx -= tempax; /* lcdvdee */
  6341. }
  6342. /* Non-expanding: lcdvdes = tempcx = VT-1; lcdvdee = tempbx = VDE-1 */
  6343. #ifdef TWDEBUG
  6344. xf86DrvMsg(0, X_INFO, "lcdvdes 0x%x lcdvdee 0x%x\n", tempcx, tempbx);
  6345. #endif
  6346. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x05,tempcx); /* lcdvdes */
  6347. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x06,tempbx); /* lcdvdee */
  6348. temp = (tempbx >> 5) & 0x38;
  6349. temp |= ((tempcx >> 8) & 0x07);
  6350. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,temp);
  6351. tempax = SiS_Pr->SiS_VDE;
  6352. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
  6353. tempax = SiS_Pr->PanelYRes;
  6354. }
  6355. tempcx = (SiS_Pr->SiS_VT - tempax) >> 4;
  6356. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
  6357. if(SiS_Pr->PanelYRes != SiS_Pr->SiS_VDE) {
  6358. tempcx = (SiS_Pr->SiS_VT - tempax) / 10;
  6359. }
  6360. }
  6361. tempbx = ((SiS_Pr->SiS_VT + SiS_Pr->SiS_VDE) >> 1) - 1;
  6362. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  6363. if(SiS_Pr->PanelYRes != SiS_Pr->SiS_VDE) {
  6364. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) { /* ? */
  6365. tempax = SiS_Pr->SiS_VT - SiS_Pr->PanelYRes;
  6366. if(tempax % 4) { tempax >>= 2; tempax++; }
  6367. else { tempax >>= 2; }
  6368. tempbx -= (tempax - 1);
  6369. } else {
  6370. tempbx -= 10;
  6371. if(tempbx <= SiS_Pr->SiS_VDE) tempbx = SiS_Pr->SiS_VDE + 1;
  6372. }
  6373. }
  6374. }
  6375. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  6376. tempbx++;
  6377. if((!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) || (crt2crtc == 6)) {
  6378. if(SiS_Pr->SiS_SetFlag & LCDVESATiming) {
  6379. tempbx = 770;
  6380. tempcx = 3;
  6381. }
  6382. }
  6383. }
  6384. /* non-expanding: lcdvrs = ((VT + VDE) / 2) - 10 */
  6385. if(SiS_Pr->UseCustomMode) {
  6386. tempbx = SiS_Pr->CVSyncStart;
  6387. }
  6388. #ifdef TWDEBUG
  6389. xf86DrvMsg(0, X_INFO, "lcdvrs 0x%x\n", tempbx);
  6390. #endif
  6391. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,tempbx); /* lcdvrs */
  6392. temp = (tempbx >> 4) & 0xF0;
  6393. tempbx += (tempcx + 1);
  6394. temp |= (tempbx & 0x0F);
  6395. if(SiS_Pr->UseCustomMode) {
  6396. temp &= 0xf0;
  6397. temp |= (SiS_Pr->CVSyncEnd & 0x0f);
  6398. }
  6399. #ifdef TWDEBUG
  6400. xf86DrvMsg(0, X_INFO, "lcdvre[3:0] 0x%x\n", (temp & 0x0f));
  6401. #endif
  6402. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,temp);
  6403. #ifdef SIS300
  6404. SiS_Group2LCDSpecial(SiS_Pr, HwInfo, ModeNo, crt2crtc);
  6405. #endif
  6406. bridgeoffset = 7;
  6407. if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) bridgeoffset += 2;
  6408. if(SiS_Pr->SiS_VBType & (VB_SIS301C | VB_SIS302ELV)) bridgeoffset++;
  6409. if(SiS_IsDualLink(SiS_Pr, HwInfo)) bridgeoffset++;
  6410. temp = 0;
  6411. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
  6412. if(SiS_Pr->PanelXRes != SiS_Pr->SiS_HDE) {
  6413. temp = SiS_Pr->SiS_HT - ((SiS_Pr->PanelXRes - SiS_Pr->SiS_HDE) / 2);
  6414. if(SiS_IsDualLink(SiS_Pr, HwInfo)) temp >>= 1;
  6415. }
  6416. }
  6417. temp += bridgeoffset;
  6418. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x1F,temp); /* lcdhdes */
  6419. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x20,0x0F,((temp >> 4) & 0xf0));
  6420. tempcx = SiS_Pr->SiS_HT;
  6421. tempax = tempbx = SiS_Pr->SiS_HDE;
  6422. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
  6423. if(SiS_Pr->PanelXRes != SiS_Pr->SiS_HDE) {
  6424. tempax = SiS_Pr->PanelXRes;
  6425. tempbx = SiS_Pr->PanelXRes - ((SiS_Pr->PanelXRes - SiS_Pr->SiS_HDE) / 2);
  6426. }
  6427. }
  6428. if(SiS_IsDualLink(SiS_Pr, HwInfo)) {
  6429. tempcx >>= 1;
  6430. tempbx >>= 1;
  6431. tempax >>= 1;
  6432. }
  6433. #ifdef TWDEBUG
  6434. xf86DrvMsg(0, X_INFO, "lcdhdee 0x%x\n", tempbx);
  6435. #endif
  6436. tempbx += bridgeoffset;
  6437. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x23,tempbx); /* lcdhdee */
  6438. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x25,0xF0,((tempbx >> 8) & 0x0f));
  6439. tempcx = (tempcx - tempax) >> 2;
  6440. tempbx += tempcx;
  6441. push2 = tempbx;
  6442. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) {
  6443. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  6444. if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
  6445. if(SiS_Pr->SiS_HDE == 1280) tempbx = (tempbx & 0xff00) | 0x47;
  6446. }
  6447. }
  6448. }
  6449. if(SiS_Pr->UseCustomMode) {
  6450. tempbx = SiS_Pr->CHSyncStart;
  6451. if(SiS_IsDualLink(SiS_Pr, HwInfo)) tempbx >>= 1;
  6452. tempbx += bridgeoffset;
  6453. }
  6454. #ifdef TWDEBUG
  6455. xf86DrvMsg(0, X_INFO, "lcdhrs 0x%x\n", tempbx);
  6456. #endif
  6457. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x1C,tempbx); /* lcdhrs */
  6458. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1D,0x0F,((tempbx >> 4) & 0xf0));
  6459. tempbx = push2;
  6460. tempcx <<= 1;
  6461. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
  6462. if(SiS_Pr->PanelXRes != SiS_Pr->SiS_HDE) tempcx >>= 2;
  6463. }
  6464. tempbx += tempcx;
  6465. if(SiS_Pr->UseCustomMode) {
  6466. tempbx = SiS_Pr->CHSyncEnd;
  6467. if(SiS_IsDualLink(SiS_Pr, HwInfo)) tempbx >>= 1;
  6468. tempbx += bridgeoffset;
  6469. }
  6470. #ifdef TWDEBUG
  6471. xf86DrvMsg(0, X_INFO, "lcdhre 0x%x\n", tempbx);
  6472. #endif
  6473. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x21,tempbx); /* lcdhre */
  6474. SiS_SetGroup2_Tail(SiS_Pr, ModeNo);
  6475. #ifdef SIS300
  6476. SiS_Set300Part2Regs(SiS_Pr, HwInfo, ModeIdIndex, RefreshRateTableIndex, ModeNo);
  6477. #endif
  6478. #ifdef SIS315H
  6479. } /* CRT2-LCD from table */
  6480. #endif
  6481. }
  6482. /*********************************************/
  6483. /* SET PART 3 REGISTER GROUP */
  6484. /*********************************************/
  6485. static void
  6486. SiS_SetGroup3(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
  6487. PSIS_HW_INFO HwInfo)
  6488. {
  6489. USHORT i;
  6490. const UCHAR *tempdi;
  6491. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) return;
  6492. #ifndef SIS_CP
  6493. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x00,0x00);
  6494. #else
  6495. SIS_CP_INIT301_CP
  6496. #endif
  6497. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  6498. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x13,0xFA);
  6499. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x14,0xC8);
  6500. } else {
  6501. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x13,0xF5);
  6502. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x14,0xB7);
  6503. }
  6504. if(SiS_Pr->SiS_TVMode & TVSetPALM) {
  6505. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x13,0xFA);
  6506. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x14,0xC8);
  6507. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x3D,0xA8);
  6508. }
  6509. tempdi = NULL;
  6510. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  6511. tempdi = SiS_Pr->SiS_HiTVGroup3Data;
  6512. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) {
  6513. tempdi = SiS_Pr->SiS_HiTVGroup3Simu;
  6514. }
  6515. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  6516. if(!(SiS_Pr->SiS_TVMode & TVSetYPbPr525i)) {
  6517. tempdi = SiS_HiTVGroup3_1;
  6518. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) tempdi = SiS_HiTVGroup3_2;
  6519. }
  6520. }
  6521. if(tempdi) {
  6522. for(i=0; i<=0x3E; i++) {
  6523. SiS_SetReg(SiS_Pr->SiS_Part3Port,i,tempdi[i]);
  6524. }
  6525. if(SiS_Pr->SiS_VBType & (VB_SIS301C | VB_SIS302ELV)) {
  6526. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) {
  6527. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x28,0x3f);
  6528. }
  6529. }
  6530. }
  6531. #ifdef SIS_CP
  6532. SIS_CP_INIT301_CP2
  6533. #endif
  6534. }
  6535. /*********************************************/
  6536. /* SET PART 4 REGISTER GROUP */
  6537. /*********************************************/
  6538. #ifdef SIS315H
  6539. static void
  6540. SiS_ShiftXPos(SiS_Private *SiS_Pr, int shift)
  6541. {
  6542. USHORT temp, temp1, temp2;
  6543. temp1 = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x1f);
  6544. temp2 = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x20);
  6545. temp = (USHORT)((int)((temp1 | ((temp2 & 0xf0) << 4))) + shift);
  6546. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x1f,temp);
  6547. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x20,0x0f,((temp >> 4) & 0xf0));
  6548. temp = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x2b) & 0x0f;
  6549. temp = (USHORT)((int)(temp) + shift);
  6550. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2b,0xf0,(temp & 0x0f));
  6551. temp1 = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x43);
  6552. temp2 = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x42);
  6553. temp = (USHORT)((int)((temp1 | ((temp2 & 0xf0) << 4))) + shift);
  6554. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x43,temp);
  6555. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x42,0x0f,((temp >> 4) & 0xf0));
  6556. }
  6557. static void
  6558. SiS_SetGroup4_C_ELV(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
  6559. USHORT ModeNo, USHORT ModeIdIndex)
  6560. {
  6561. USHORT temp, temp1, resinfo = 0;
  6562. if(!(SiS_Pr->SiS_VBType & VB_SIS301C)) return;
  6563. if(!(SiS_Pr->SiS_VBInfo & (SetCRT2ToHiVision | SetCRT2ToYPbPr525750))) return;
  6564. if(ModeNo > 0x13) {
  6565. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  6566. }
  6567. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x3a,0x08);
  6568. temp = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x3a);
  6569. if(!(temp & 0x01)) {
  6570. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x3a,0xdf);
  6571. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x25,0xfc);
  6572. if((HwInfo->jChipType < SIS_661) && (!(SiS_Pr->SiS_ROMNew))) {
  6573. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x25,0xf8);
  6574. }
  6575. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x0f,0xfb);
  6576. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) temp = 0x0000;
  6577. else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) temp = 0x0002;
  6578. else if(SiS_Pr->SiS_TVMode & TVSetHiVision) temp = 0x0400;
  6579. else temp = 0x0402;
  6580. if((HwInfo->jChipType >= SIS_661) || (SiS_Pr->SiS_ROMNew)) {
  6581. temp1 = 0;
  6582. if(SiS_Pr->SiS_TVMode & TVAspect43) temp1 = 4;
  6583. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x0f,0xfb,temp1);
  6584. if(SiS_Pr->SiS_TVMode & TVAspect43LB) temp |= 0x01;
  6585. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x26,0x7c,(temp & 0xff));
  6586. } else {
  6587. temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x3b) & 0x03;
  6588. if(temp1 == 0x01) temp |= 0x01;
  6589. if(temp1 == 0x03) temp |= 0x04; /* ? why not 0x10? */
  6590. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x26,0xf8,(temp & 0xff));
  6591. }
  6592. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x3a,0xfb,(temp >> 8));
  6593. if(ModeNo > 0x13) {
  6594. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x3b,0xfd);
  6595. }
  6596. if(HwInfo->jChipType >= SIS_661) { /* ? */
  6597. if(SiS_Pr->SiS_TVMode & TVAspect43) {
  6598. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) {
  6599. if(resinfo == SIS_RI_1024x768) {
  6600. SiS_ShiftXPos(SiS_Pr, 97);
  6601. } else {
  6602. SiS_ShiftXPos(SiS_Pr, 111);
  6603. }
  6604. } else if(SiS_Pr->SiS_TVMode & TVSetHiVision) {
  6605. SiS_ShiftXPos(SiS_Pr, 136);
  6606. }
  6607. }
  6608. }
  6609. }
  6610. }
  6611. #endif
  6612. static void
  6613. SiS_SetCRT2VCLK(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
  6614. USHORT RefreshRateTableIndex, PSIS_HW_INFO HwInfo)
  6615. {
  6616. USHORT vclkindex;
  6617. USHORT temp, reg1, reg2;
  6618. if(SiS_Pr->UseCustomMode) {
  6619. reg1 = SiS_Pr->CSR2B;
  6620. reg2 = SiS_Pr->CSR2C;
  6621. } else {
  6622. vclkindex = SiS_GetVCLK2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex,
  6623. HwInfo);
  6624. reg1 = SiS_Pr->SiS_VBVCLKData[vclkindex].Part4_A;
  6625. reg2 = SiS_Pr->SiS_VBVCLKData[vclkindex].Part4_B;
  6626. }
  6627. if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
  6628. if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) {
  6629. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0a,0x57);
  6630. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0b,0x46);
  6631. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1f,0xf6);
  6632. } else {
  6633. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0a,reg1);
  6634. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0b,reg2);
  6635. }
  6636. } else {
  6637. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0a,0x01);
  6638. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0b,reg2);
  6639. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0a,reg1);
  6640. }
  6641. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x12,0x00);
  6642. temp = 0x08;
  6643. if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) temp |= 0x20;
  6644. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x12,temp);
  6645. }
  6646. static void
  6647. SiS_SetGroup4(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
  6648. USHORT RefreshRateTableIndex, PSIS_HW_INFO HwInfo)
  6649. {
  6650. USHORT tempax,tempcx,tempbx,modeflag,temp,resinfo;
  6651. ULONG tempebx,tempeax,templong;
  6652. if(ModeNo <= 0x13) {
  6653. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  6654. resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
  6655. } else if(SiS_Pr->UseCustomMode) {
  6656. modeflag = SiS_Pr->CModeFlag;
  6657. resinfo = 0;
  6658. } else {
  6659. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  6660. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  6661. }
  6662. if(HwInfo->jChipType >= SIS_315H) {
  6663. if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {
  6664. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  6665. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x24,0x0e);
  6666. }
  6667. }
  6668. }
  6669. if(SiS_Pr->SiS_VBType & (VB_SIS301C | VB_SIS302LV)) {
  6670. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  6671. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x10,0x9f);
  6672. }
  6673. }
  6674. if(HwInfo->jChipType >= SIS_315H) {
  6675. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  6676. if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {
  6677. if(SiS_IsDualLink(SiS_Pr, HwInfo)) {
  6678. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x27,0x2c);
  6679. } else {
  6680. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x27,~0x20);
  6681. }
  6682. if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV)) {
  6683. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2a,0x00);
  6684. #ifdef SET_EMI
  6685. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
  6686. #endif
  6687. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x34,0x10);
  6688. }
  6689. }
  6690. return;
  6691. }
  6692. }
  6693. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x13,SiS_Pr->SiS_RVBHCFACT);
  6694. tempbx = SiS_Pr->SiS_RVBHCMAX;
  6695. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x14,tempbx);
  6696. temp = (tempbx >> 1) & 0x80;
  6697. tempcx = SiS_Pr->SiS_VGAHT - 1;
  6698. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x16,tempcx);
  6699. temp |= ((tempcx >> 5) & 0x78);
  6700. tempcx = SiS_Pr->SiS_VGAVT - 1;
  6701. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) tempcx -= 5;
  6702. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x17,tempcx);
  6703. temp |= ((tempcx >> 8) & 0x07);
  6704. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x15,temp);
  6705. tempbx = SiS_Pr->SiS_VGAHDE;
  6706. if(modeflag & HalfDCLK) tempbx >>= 1;
  6707. if(SiS_IsDualLink(SiS_Pr, HwInfo)) tempbx >>= 1;
  6708. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  6709. temp = 0;
  6710. if(tempbx > 800) temp = 0x60;
  6711. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  6712. temp = 0;
  6713. if(tempbx == 1024) temp = 0xA0;
  6714. else if(tempbx > 1024) temp = 0xC0;
  6715. } else if(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p)) {
  6716. temp = 0;
  6717. if(tempbx >= 1280) temp = 0x40;
  6718. else if(tempbx >= 1024) temp = 0x20;
  6719. } else {
  6720. temp = 0x80;
  6721. if(tempbx >= 1024) temp = 0xA0;
  6722. }
  6723. if(SiS_Pr->SiS_VBType & VB_SIS301) {
  6724. if(SiS_Pr->SiS_LCDResInfo != Panel_1280x1024) temp |= 0x0A;
  6725. }
  6726. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x0E,0x10,temp);
  6727. tempeax = SiS_Pr->SiS_VGAVDE;
  6728. tempebx = SiS_Pr->SiS_VDE;
  6729. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  6730. if(!(temp & 0xE0)) tempebx >>=1;
  6731. }
  6732. tempcx = SiS_Pr->SiS_RVBHRS;
  6733. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x18,tempcx);
  6734. tempcx >>= 8;
  6735. tempcx |= 0x40;
  6736. if(tempeax <= tempebx) {
  6737. tempcx ^= 0x40;
  6738. } else {
  6739. tempeax -= tempebx;
  6740. }
  6741. tempeax *= (256 * 1024);
  6742. templong = tempeax % tempebx;
  6743. tempeax /= tempebx;
  6744. if(templong) tempeax++;
  6745. temp = (USHORT)(tempeax & 0x000000FF);
  6746. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1B,temp);
  6747. temp = (USHORT)((tempeax & 0x0000FF00) >> 8);
  6748. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1A,temp);
  6749. temp = (USHORT)((tempeax >> 12) & 0x70); /* sic! */
  6750. temp |= (tempcx & 0x4F);
  6751. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x19,temp);
  6752. if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
  6753. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1C,0x28);
  6754. /* Calc Linebuffer max address and set/clear decimode */
  6755. tempbx = 0;
  6756. if(SiS_Pr->SiS_TVMode & (TVSetHiVision | TVSetYPbPr750p)) tempbx = 0x08;
  6757. tempax = SiS_Pr->SiS_VGAHDE;
  6758. if(modeflag & HalfDCLK) tempax >>= 1;
  6759. if(SiS_IsDualLink(SiS_Pr, HwInfo)) tempax >>= 1;
  6760. if(tempax > 800) {
  6761. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  6762. tempax -= 800;
  6763. } else { /* 651+301C: Only if TVNoHiviNoYPbPr */
  6764. tempbx = 0x08;
  6765. if(tempax == 1024) tempax *= 25;
  6766. else tempax *= 20;
  6767. temp = tempax % 32;
  6768. tempax /= 32;
  6769. if(temp) tempax++;
  6770. tempax++;
  6771. if((SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoYPbPrHiVision) ||
  6772. (SiS_Pr->SiS_TVMode & TVSetYPbPr525i)) {
  6773. if(resinfo == SIS_RI_1024x768) {
  6774. /* Otherwise white line at right edge */
  6775. tempax = (tempax & 0xff00) | 0x20;
  6776. }
  6777. }
  6778. }
  6779. }
  6780. tempax--;
  6781. temp = ((tempax >> 4) & 0x30) | tempbx;
  6782. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1D,tempax);
  6783. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1E,temp);
  6784. temp = 0x0036; tempbx = 0xD0;
  6785. if((HwInfo->jChipType >= SIS_315H) && (SiS_Pr->SiS_VBType & VB_SIS301LV302LV)) {
  6786. temp = 0x0026; tempbx = 0xC0; /* See En/DisableBridge() */
  6787. }
  6788. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  6789. if(!(SiS_Pr->SiS_TVMode & (TVSetNTSC1024 | TVSetHiVision | TVSetYPbPr750p | TVSetYPbPr525p))) {
  6790. temp |= 0x01;
  6791. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  6792. if(!(SiS_Pr->SiS_TVMode & TVSetTVSimuMode)) {
  6793. temp &= ~0x01;
  6794. }
  6795. }
  6796. }
  6797. }
  6798. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x1F,tempbx,temp);
  6799. tempbx = SiS_Pr->SiS_HT >> 1;
  6800. if(SiS_IsDualLink(SiS_Pr, HwInfo)) tempbx >>= 1;
  6801. tempbx -= 2;
  6802. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x22,tempbx);
  6803. temp = (tempbx >> 5) & 0x38;
  6804. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x21,0xC0,temp);
  6805. if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {
  6806. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  6807. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x24,0x0e);
  6808. /* LCD-too-dark-error-source, see FinalizeLCD() */
  6809. }
  6810. if(HwInfo->jChipType >= SIS_315H) {
  6811. if(SiS_IsDualLink(SiS_Pr, HwInfo)) {
  6812. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x27,0x2c);
  6813. } else {
  6814. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x27,~0x20);
  6815. }
  6816. }
  6817. if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV)) {
  6818. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2a,0x00);
  6819. #ifdef SET_EMI
  6820. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
  6821. #endif
  6822. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x34,0x10);
  6823. }
  6824. }
  6825. } /* 301B */
  6826. SiS_SetCRT2VCLK(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex, HwInfo);
  6827. }
  6828. /*********************************************/
  6829. /* SET PART 5 REGISTER GROUP */
  6830. /*********************************************/
  6831. static void
  6832. SiS_SetGroup5(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
  6833. PSIS_HW_INFO HwInfo)
  6834. {
  6835. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) return;
  6836. if(SiS_Pr->SiS_ModeType == ModeVGA) {
  6837. if(!(SiS_Pr->SiS_VBInfo & (SetInSlaveMode | LoadDACFlag))) {
  6838. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);
  6839. SiS_LoadDAC(SiS_Pr, HwInfo, ModeNo, ModeIdIndex);
  6840. }
  6841. }
  6842. }
  6843. /*********************************************/
  6844. /* MODIFY CRT1 GROUP FOR SLAVE MODE */
  6845. /*********************************************/
  6846. static void
  6847. SiS_ModCRT1CRTC(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
  6848. USHORT RefreshRateTableIndex, PSIS_HW_INFO HwInfo)
  6849. {
  6850. USHORT tempah,i,modeflag,j;
  6851. USHORT ResIndex,DisplayType;
  6852. const SiS_LVDSCRT1DataStruct *LVDSCRT1Ptr=NULL;
  6853. if(ModeNo <= 0x13) modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  6854. else modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  6855. if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) ||
  6856. (SiS_Pr->SiS_CustomT == CUT_BARCO1024) ||
  6857. (SiS_Pr->SiS_CustomT == CUT_PANEL848))
  6858. return;
  6859. if(!(SiS_GetLVDSCRT1Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex,
  6860. &ResIndex, &DisplayType))) {
  6861. return;
  6862. }
  6863. if(HwInfo->jChipType < SIS_315H) {
  6864. if(SiS_Pr->SiS_SetFlag & SetDOSMode) return;
  6865. }
  6866. switch(DisplayType) {
  6867. case 0 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1800x600_1; break;
  6868. case 1 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1800x600_1_H; break;
  6869. case 2 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1800x600_2; break;
  6870. case 3 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1800x600_2_H; break;
  6871. case 4 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x768_1; break;
  6872. case 5 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x768_1_H; break;
  6873. case 6 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x768_2; break;
  6874. case 7 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x768_2_H; break;
  6875. case 8 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11280x1024_1; break;
  6876. case 9 : LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11280x1024_1_H; break;
  6877. case 10: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11280x1024_2; break;
  6878. case 11: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11280x1024_2_H; break;
  6879. case 12: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1XXXxXXX_1; break;
  6880. case 13: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1XXXxXXX_1_H; break;
  6881. case 14: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11400x1050_1; break;
  6882. case 15: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11400x1050_1_H; break;
  6883. case 16: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11400x1050_2; break;
  6884. case 17: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11400x1050_2_H; break;
  6885. case 18: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1UNTSC; break;
  6886. case 19: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1ONTSC; break;
  6887. case 20: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1UPAL; break;
  6888. case 21: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1OPAL; break;
  6889. case 22: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1320x480_1; break; /* FSTN */
  6890. case 23: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x600_1; break;
  6891. case 24: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x600_1_H; break;
  6892. case 25: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x600_2; break;
  6893. case 26: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x600_2_H; break;
  6894. case 27: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11152x768_1; break;
  6895. case 28: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11152x768_1_H; break;
  6896. case 29: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11152x768_2; break;
  6897. case 30: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11152x768_2_H; break;
  6898. case 36: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11600x1200_1; break;
  6899. case 37: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11600x1200_1_H; break;
  6900. case 38: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11600x1200_2; break;
  6901. case 39: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11600x1200_2_H; break;
  6902. case 40: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11280x768_1; break;
  6903. case 41: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11280x768_1_H; break;
  6904. case 42: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11280x768_2; break;
  6905. case 43: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11280x768_2_H; break;
  6906. case 50: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1640x480_1; break;
  6907. case 51: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1640x480_1_H; break;
  6908. case 52: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1640x480_2; break;
  6909. case 53: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1640x480_2_H; break;
  6910. case 54: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1640x480_3; break;
  6911. case 55: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1640x480_3_H; break;
  6912. case 99: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1SOPAL; break;
  6913. default: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x768_1; break;
  6914. }
  6915. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x11,0x7f);
  6916. tempah = (LVDSCRT1Ptr + ResIndex)->CR[0];
  6917. SiS_SetReg(SiS_Pr->SiS_P3d4,0x00,tempah);
  6918. for(i=0x02,j=1;i<=0x05;i++,j++){
  6919. tempah = (LVDSCRT1Ptr + ResIndex)->CR[j];
  6920. SiS_SetReg(SiS_Pr->SiS_P3d4,i,tempah);
  6921. }
  6922. for(i=0x06,j=5;i<=0x07;i++,j++){
  6923. tempah = (LVDSCRT1Ptr + ResIndex)->CR[j];
  6924. SiS_SetReg(SiS_Pr->SiS_P3d4,i,tempah);
  6925. }
  6926. for(i=0x10,j=7;i<=0x11;i++,j++){
  6927. tempah = (LVDSCRT1Ptr + ResIndex)->CR[j];
  6928. SiS_SetReg(SiS_Pr->SiS_P3d4,i,tempah);
  6929. }
  6930. for(i=0x15,j=9;i<=0x16;i++,j++){
  6931. tempah = (LVDSCRT1Ptr + ResIndex)->CR[j];
  6932. SiS_SetReg(SiS_Pr->SiS_P3d4,i,tempah);
  6933. }
  6934. for(i=0x0A,j=11;i<=0x0C;i++,j++){
  6935. tempah = (LVDSCRT1Ptr + ResIndex)->CR[j];
  6936. SiS_SetReg(SiS_Pr->SiS_P3c4,i,tempah);
  6937. }
  6938. tempah = (LVDSCRT1Ptr + ResIndex)->CR[14];
  6939. tempah &= 0xE0;
  6940. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0E,0x1f,tempah);
  6941. tempah = (LVDSCRT1Ptr + ResIndex)->CR[14];
  6942. tempah &= 0x01;
  6943. tempah <<= 5;
  6944. if(modeflag & DoubleScanMode) tempah |= 0x080;
  6945. SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x09,~0x020,tempah);
  6946. }
  6947. /*********************************************/
  6948. /* SET CRT2 ECLK */
  6949. /*********************************************/
  6950. static void
  6951. SiS_SetCRT2ECLK(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
  6952. USHORT RefreshRateTableIndex, PSIS_HW_INFO HwInfo)
  6953. {
  6954. UCHAR *ROMAddr = HwInfo->pjVirtualRomBase;
  6955. USHORT clkbase, vclkindex=0;
  6956. UCHAR sr2b, sr2c;
  6957. if((SiS_Pr->SiS_LCDResInfo == Panel_640x480) || (SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  6958. SiS_Pr->SiS_SetFlag &= (~ProgrammingCRT2);
  6959. if((SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK & 0x3f) == 2) {
  6960. RefreshRateTableIndex--;
  6961. }
  6962. vclkindex = SiS_GetVCLK2Ptr(SiS_Pr, ModeNo, ModeIdIndex,
  6963. RefreshRateTableIndex, HwInfo);
  6964. SiS_Pr->SiS_SetFlag |= ProgrammingCRT2;
  6965. } else {
  6966. vclkindex = SiS_GetVCLK2Ptr(SiS_Pr, ModeNo, ModeIdIndex,
  6967. RefreshRateTableIndex, HwInfo);
  6968. }
  6969. sr2b = SiS_Pr->SiS_VCLKData[vclkindex].SR2B;
  6970. sr2c = SiS_Pr->SiS_VCLKData[vclkindex].SR2C;
  6971. if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) || (SiS_Pr->SiS_CustomT == CUT_BARCO1024)) {
  6972. if(SiS_Pr->SiS_UseROM) {
  6973. if(ROMAddr[0x220] & 0x01) {
  6974. sr2b = ROMAddr[0x227];
  6975. sr2c = ROMAddr[0x228];
  6976. }
  6977. }
  6978. }
  6979. clkbase = 0x02B;
  6980. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  6981. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  6982. clkbase += 3;
  6983. }
  6984. }
  6985. SiS_SetReg(SiS_Pr->SiS_P3c4,0x31,0x20);
  6986. SiS_SetReg(SiS_Pr->SiS_P3c4,clkbase,sr2b);
  6987. SiS_SetReg(SiS_Pr->SiS_P3c4,clkbase+1,sr2c);
  6988. SiS_SetReg(SiS_Pr->SiS_P3c4,0x31,0x10);
  6989. SiS_SetReg(SiS_Pr->SiS_P3c4,clkbase,sr2b);
  6990. SiS_SetReg(SiS_Pr->SiS_P3c4,clkbase+1,sr2c);
  6991. SiS_SetReg(SiS_Pr->SiS_P3c4,0x31,0x00);
  6992. SiS_SetReg(SiS_Pr->SiS_P3c4,clkbase,sr2b);
  6993. SiS_SetReg(SiS_Pr->SiS_P3c4,clkbase+1,sr2c);
  6994. }
  6995. /*********************************************/
  6996. /* SET UP CHRONTEL CHIPS */
  6997. /*********************************************/
  6998. static void
  6999. SiS_SetCHTVReg(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
  7000. USHORT RefreshRateTableIndex)
  7001. {
  7002. #if defined(SIS300) || defined(SIS315H)
  7003. USHORT temp, tempbx;
  7004. #endif
  7005. USHORT tempcl;
  7006. USHORT TVType, resindex;
  7007. const SiS_CHTVRegDataStruct *CHTVRegData = NULL;
  7008. if(ModeNo <= 0x13)
  7009. tempcl = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  7010. else
  7011. tempcl = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  7012. TVType = 0;
  7013. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) TVType += 1;
  7014. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  7015. TVType += 2;
  7016. if(SiS_Pr->SiS_ModeType > ModeVGA) {
  7017. if(SiS_Pr->SiS_CHSOverScan) TVType = 8;
  7018. }
  7019. if(SiS_Pr->SiS_TVMode & TVSetPALM) {
  7020. TVType = 4;
  7021. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) TVType += 1;
  7022. } else if(SiS_Pr->SiS_TVMode & TVSetPALN) {
  7023. TVType = 6;
  7024. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) TVType += 1;
  7025. }
  7026. }
  7027. switch(TVType) {
  7028. case 0: CHTVRegData = SiS_Pr->SiS_CHTVReg_UNTSC; break;
  7029. case 1: CHTVRegData = SiS_Pr->SiS_CHTVReg_ONTSC; break;
  7030. case 2: CHTVRegData = SiS_Pr->SiS_CHTVReg_UPAL; break;
  7031. case 3: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPAL; break;
  7032. case 4: CHTVRegData = SiS_Pr->SiS_CHTVReg_UPALM; break;
  7033. case 5: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPALM; break;
  7034. case 6: CHTVRegData = SiS_Pr->SiS_CHTVReg_UPALN; break;
  7035. case 7: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPALN; break;
  7036. case 8: CHTVRegData = SiS_Pr->SiS_CHTVReg_SOPAL; break;
  7037. default: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPAL; break;
  7038. }
  7039. resindex = tempcl & 0x3F;
  7040. if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) {
  7041. #ifdef SIS300
  7042. /* Chrontel 7005 - I assume that it does not come with a 315 series chip */
  7043. /* We don't support modes >800x600 */
  7044. if (resindex > 5) return;
  7045. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  7046. SiS_SetCH700x(SiS_Pr,0x4304); /* 0x40=76uA (PAL); 0x03=15bit non-multi RGB*/
  7047. SiS_SetCH700x(SiS_Pr,0x6909); /* Black level for PAL (105)*/
  7048. } else {
  7049. SiS_SetCH700x(SiS_Pr,0x0304); /* upper nibble=71uA (NTSC), 0x03=15bit non-multi RGB*/
  7050. SiS_SetCH700x(SiS_Pr,0x7109); /* Black level for NTSC (113)*/
  7051. }
  7052. temp = CHTVRegData[resindex].Reg[0];
  7053. tempbx=((temp&0x00FF)<<8)|0x00; /* Mode register */
  7054. SiS_SetCH700x(SiS_Pr,tempbx);
  7055. temp = CHTVRegData[resindex].Reg[1];
  7056. tempbx=((temp&0x00FF)<<8)|0x07; /* Start active video register */
  7057. SiS_SetCH700x(SiS_Pr,tempbx);
  7058. temp = CHTVRegData[resindex].Reg[2];
  7059. tempbx=((temp&0x00FF)<<8)|0x08; /* Position overflow register */
  7060. SiS_SetCH700x(SiS_Pr,tempbx);
  7061. temp = CHTVRegData[resindex].Reg[3];
  7062. tempbx=((temp&0x00FF)<<8)|0x0A; /* Horiz Position register */
  7063. SiS_SetCH700x(SiS_Pr,tempbx);
  7064. temp = CHTVRegData[resindex].Reg[4];
  7065. tempbx=((temp&0x00FF)<<8)|0x0B; /* Vertical Position register */
  7066. SiS_SetCH700x(SiS_Pr,tempbx);
  7067. /* Set minimum flicker filter for Luma channel (SR1-0=00),
  7068. minimum text enhancement (S3-2=10),
  7069. maximum flicker filter for Chroma channel (S5-4=10)
  7070. =00101000=0x28 (When reading, S1-0->S3-2, and S3-2->S1-0!)
  7071. */
  7072. SiS_SetCH700x(SiS_Pr,0x2801);
  7073. /* Set video bandwidth
  7074. High bandwith Luma composite video filter(S0=1)
  7075. low bandwith Luma S-video filter (S2-1=00)
  7076. disable peak filter in S-video channel (S3=0)
  7077. high bandwidth Chroma Filter (S5-4=11)
  7078. =00110001=0x31
  7079. */
  7080. SiS_SetCH700x(SiS_Pr,0xb103); /* old: 3103 */
  7081. /* Register 0x3D does not exist in non-macrovision register map
  7082. (Maybe this is a macrovision register?)
  7083. */
  7084. #ifndef SIS_CP
  7085. SiS_SetCH70xx(SiS_Pr,0x003D);
  7086. #endif
  7087. /* Register 0x10 only contains 1 writable bit (S0) for sensing,
  7088. all other bits a read-only. Macrovision?
  7089. */
  7090. SiS_SetCH70xxANDOR(SiS_Pr,0x0010,0x1F);
  7091. /* Register 0x11 only contains 3 writable bits (S0-S2) for
  7092. contrast enhancement (set to 010 -> gain 1 Yout = 17/16*(Yin-30) )
  7093. */
  7094. SiS_SetCH70xxANDOR(SiS_Pr,0x0211,0xF8);
  7095. /* Clear DSEN
  7096. */
  7097. SiS_SetCH70xxANDOR(SiS_Pr,0x001C,0xEF);
  7098. if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) { /* ---- NTSC ---- */
  7099. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) {
  7100. if(resindex == 0x04) { /* 640x480 overscan: Mode 16 */
  7101. SiS_SetCH70xxANDOR(SiS_Pr,0x0020,0xEF); /* loop filter off */
  7102. SiS_SetCH70xxANDOR(SiS_Pr,0x0121,0xFE); /* ACIV on, no need to set FSCI */
  7103. } else if(resindex == 0x05) { /* 800x600 overscan: Mode 23 */
  7104. SiS_SetCH70xxANDOR(SiS_Pr,0x0118,0xF0); /* 0x18-0x1f: FSCI 469,762,048 */
  7105. SiS_SetCH70xxANDOR(SiS_Pr,0x0C19,0xF0);
  7106. SiS_SetCH70xxANDOR(SiS_Pr,0x001A,0xF0);
  7107. SiS_SetCH70xxANDOR(SiS_Pr,0x001B,0xF0);
  7108. SiS_SetCH70xxANDOR(SiS_Pr,0x001C,0xF0);
  7109. SiS_SetCH70xxANDOR(SiS_Pr,0x001D,0xF0);
  7110. SiS_SetCH70xxANDOR(SiS_Pr,0x001E,0xF0);
  7111. SiS_SetCH70xxANDOR(SiS_Pr,0x001F,0xF0);
  7112. SiS_SetCH70xxANDOR(SiS_Pr,0x0120,0xEF); /* Loop filter on for mode 23 */
  7113. SiS_SetCH70xxANDOR(SiS_Pr,0x0021,0xFE); /* ACIV off, need to set FSCI */
  7114. }
  7115. } else {
  7116. if(resindex == 0x04) { /* ----- 640x480 underscan; Mode 17 */
  7117. SiS_SetCH70xxANDOR(SiS_Pr,0x0020,0xEF); /* loop filter off */
  7118. SiS_SetCH70xxANDOR(SiS_Pr,0x0121,0xFE);
  7119. } else if(resindex == 0x05) { /* ----- 800x600 underscan: Mode 24 */
  7120. #if 0
  7121. SiS_SetCH70xxANDOR(SiS_Pr,0x0118,0xF0); /* (FSCI was 0x1f1c71c7 - this is for mode 22) */
  7122. SiS_SetCH70xxANDOR(SiS_Pr,0x0919,0xF0); /* FSCI for mode 24 is 428,554,851 */
  7123. SiS_SetCH70xxANDOR(SiS_Pr,0x081A,0xF0); /* 198b3a63 */
  7124. SiS_SetCH70xxANDOR(SiS_Pr,0x0b1B,0xF0);
  7125. SiS_SetCH70xxANDOR(SiS_Pr,0x041C,0xF0);
  7126. SiS_SetCH70xxANDOR(SiS_Pr,0x011D,0xF0);
  7127. SiS_SetCH70xxANDOR(SiS_Pr,0x061E,0xF0);
  7128. SiS_SetCH70xxANDOR(SiS_Pr,0x051F,0xF0);
  7129. SiS_SetCH70xxANDOR(SiS_Pr,0x0020,0xEF); /* loop filter off for mode 24 */
  7130. SiS_SetCH70xxANDOR(SiS_Pr,0x0021,0xFE); /* ACIV off, need to set FSCI */
  7131. #endif /* All alternatives wrong (datasheet wrong?), don't use FSCI */
  7132. SiS_SetCH70xxANDOR(SiS_Pr,0x0020,0xEF); /* loop filter off */
  7133. SiS_SetCH70xxANDOR(SiS_Pr,0x0121,0xFE);
  7134. }
  7135. }
  7136. } else { /* ---- PAL ---- */
  7137. /* We don't play around with FSCI in PAL mode */
  7138. if(resindex == 0x04) {
  7139. SiS_SetCH70xxANDOR(SiS_Pr,0x0020,0xEF); /* loop filter off */
  7140. SiS_SetCH70xxANDOR(SiS_Pr,0x0121,0xFE); /* ACIV on */
  7141. } else {
  7142. SiS_SetCH70xxANDOR(SiS_Pr,0x0020,0xEF); /* loop filter off */
  7143. SiS_SetCH70xxANDOR(SiS_Pr,0x0121,0xFE); /* ACIV on */
  7144. }
  7145. }
  7146. #endif /* 300 */
  7147. } else {
  7148. /* Chrontel 7019 - assumed that it does not come with a 300 series chip */
  7149. #ifdef SIS315H
  7150. /* We don't support modes >1024x768 */
  7151. if (resindex > 6) return;
  7152. temp = CHTVRegData[resindex].Reg[0];
  7153. if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) {
  7154. temp |= 0x10;
  7155. }
  7156. tempbx=((temp & 0x00FF) << 8) | 0x00;
  7157. SiS_SetCH701x(SiS_Pr,tempbx);
  7158. temp = CHTVRegData[resindex].Reg[1];
  7159. tempbx=((temp & 0x00FF) << 8) | 0x01;
  7160. SiS_SetCH701x(SiS_Pr,tempbx);
  7161. temp = CHTVRegData[resindex].Reg[2];
  7162. tempbx=((temp & 0x00FF) << 8) | 0x02;
  7163. SiS_SetCH701x(SiS_Pr,tempbx);
  7164. temp = CHTVRegData[resindex].Reg[3];
  7165. tempbx=((temp & 0x00FF) << 8) | 0x04;
  7166. SiS_SetCH701x(SiS_Pr,tempbx);
  7167. temp = CHTVRegData[resindex].Reg[4];
  7168. tempbx=((temp & 0x00FF) << 8) | 0x03;
  7169. SiS_SetCH701x(SiS_Pr,tempbx);
  7170. temp = CHTVRegData[resindex].Reg[5];
  7171. tempbx=((temp & 0x00FF) << 8) | 0x05;
  7172. SiS_SetCH701x(SiS_Pr,tempbx);
  7173. temp = CHTVRegData[resindex].Reg[6];
  7174. tempbx=((temp & 0x00FF) << 8) | 0x06;
  7175. SiS_SetCH701x(SiS_Pr,tempbx);
  7176. temp = CHTVRegData[resindex].Reg[7];
  7177. if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) {
  7178. temp = 0x66;
  7179. }
  7180. tempbx=((temp & 0x00FF) << 8) | 0x07;
  7181. SiS_SetCH701x(SiS_Pr,tempbx);
  7182. temp = CHTVRegData[resindex].Reg[8];
  7183. tempbx=((temp & 0x00FF) << 8) | 0x08;
  7184. SiS_SetCH701x(SiS_Pr,tempbx);
  7185. temp = CHTVRegData[resindex].Reg[9];
  7186. tempbx=((temp & 0x00FF) << 8) | 0x15;
  7187. SiS_SetCH701x(SiS_Pr,tempbx);
  7188. temp = CHTVRegData[resindex].Reg[10];
  7189. tempbx=((temp & 0x00FF) << 8) | 0x1f;
  7190. SiS_SetCH701x(SiS_Pr,tempbx);
  7191. temp = CHTVRegData[resindex].Reg[11];
  7192. tempbx=((temp & 0x00FF) << 8) | 0x0c;
  7193. SiS_SetCH701x(SiS_Pr,tempbx);
  7194. temp = CHTVRegData[resindex].Reg[12];
  7195. tempbx=((temp & 0x00FF) << 8) | 0x0d;
  7196. SiS_SetCH701x(SiS_Pr,tempbx);
  7197. temp = CHTVRegData[resindex].Reg[13];
  7198. tempbx=((temp & 0x00FF) << 8) | 0x0e;
  7199. SiS_SetCH701x(SiS_Pr,tempbx);
  7200. temp = CHTVRegData[resindex].Reg[14];
  7201. tempbx=((temp & 0x00FF) << 8) | 0x0f;
  7202. SiS_SetCH701x(SiS_Pr,tempbx);
  7203. temp = CHTVRegData[resindex].Reg[15];
  7204. tempbx=((temp & 0x00FF) << 8) | 0x10;
  7205. SiS_SetCH701x(SiS_Pr,tempbx);
  7206. temp = SiS_GetCH701x(SiS_Pr,0x21) & ~0x02;
  7207. /* D1 should be set for PAL, PAL-N and NTSC-J,
  7208. but I won't do that for PAL unless somebody
  7209. tells me to do so. Since the BIOS uses
  7210. non-default CIV values and blacklevels,
  7211. this might be compensated anyway.
  7212. */
  7213. if(SiS_Pr->SiS_TVMode & (TVSetPALN | TVSetNTSCJ)) temp |= 0x02;
  7214. SiS_SetCH701x(SiS_Pr,((temp << 8) | 0x21));
  7215. #endif /* 315 */
  7216. }
  7217. #ifdef SIS_CP
  7218. SIS_CP_INIT301_CP3
  7219. #endif
  7220. }
  7221. void
  7222. SiS_Chrontel701xBLOn(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
  7223. {
  7224. USHORT temp;
  7225. /* Enable Chrontel 7019 LCD panel backlight */
  7226. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  7227. if(HwInfo->jChipType == SIS_740) {
  7228. SiS_SetCH701x(SiS_Pr,0x6566);
  7229. } else {
  7230. temp = SiS_GetCH701x(SiS_Pr,0x66);
  7231. temp |= 0x20;
  7232. SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x66);
  7233. }
  7234. }
  7235. }
  7236. void
  7237. SiS_Chrontel701xBLOff(SiS_Private *SiS_Pr)
  7238. {
  7239. USHORT temp;
  7240. /* Disable Chrontel 7019 LCD panel backlight */
  7241. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  7242. temp = SiS_GetCH701x(SiS_Pr,0x66);
  7243. temp &= 0xDF;
  7244. SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x66);
  7245. }
  7246. }
  7247. #ifdef SIS315H /* ----------- 315 series only ---------- */
  7248. static void
  7249. SiS_ChrontelPowerSequencing(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
  7250. {
  7251. UCHAR regtable[] = { 0x67, 0x68, 0x69, 0x6a, 0x6b };
  7252. UCHAR table1024_740[] = { 0x01, 0x02, 0x01, 0x01, 0x01 };
  7253. UCHAR table1400_740[] = { 0x01, 0x6e, 0x01, 0x01, 0x01 };
  7254. UCHAR asus1024_740[] = { 0x19, 0x6e, 0x01, 0x19, 0x09 };
  7255. UCHAR asus1400_740[] = { 0x19, 0x6e, 0x01, 0x19, 0x09 };
  7256. UCHAR table1024_650[] = { 0x01, 0x02, 0x01, 0x01, 0x02 };
  7257. UCHAR table1400_650[] = { 0x01, 0x02, 0x01, 0x01, 0x02 };
  7258. UCHAR *tableptr = NULL;
  7259. int i;
  7260. /* Set up Power up/down timing */
  7261. if(HwInfo->jChipType == SIS_740) {
  7262. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  7263. if(SiS_Pr->SiS_CustomT == CUT_ASUSL3000D) tableptr = asus1024_740;
  7264. else tableptr = table1024_740;
  7265. } else if((SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) ||
  7266. (SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) ||
  7267. (SiS_Pr->SiS_LCDResInfo == Panel_1600x1200)) {
  7268. if(SiS_Pr->SiS_CustomT == CUT_ASUSL3000D) tableptr = asus1400_740;
  7269. else tableptr = table1400_740;
  7270. } else return;
  7271. } else {
  7272. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  7273. tableptr = table1024_650;
  7274. } else if((SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) ||
  7275. (SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) ||
  7276. (SiS_Pr->SiS_LCDResInfo == Panel_1600x1200)) {
  7277. tableptr = table1400_650;
  7278. } else return;
  7279. }
  7280. for(i=0; i<5; i++) {
  7281. SiS_SetCH701x(SiS_Pr,(tableptr[i] << 8) | regtable[i]);
  7282. }
  7283. }
  7284. static void
  7285. SiS_SetCH701xForLCD(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
  7286. {
  7287. UCHAR regtable[] = { 0x1c, 0x5f, 0x64, 0x6f, 0x70, 0x71,
  7288. 0x72, 0x73, 0x74, 0x76, 0x78, 0x7d, 0x66 };
  7289. UCHAR table1024_740[] = { 0x60, 0x02, 0x00, 0x07, 0x40, 0xed,
  7290. 0xa3, 0xc8, 0xc7, 0xac, 0xe0, 0x02, 0x44 };
  7291. UCHAR table1280_740[] = { 0x60, 0x03, 0x11, 0x00, 0x40, 0xe3,
  7292. 0xad, 0xdb, 0xf6, 0xac, 0xe0, 0x02, 0x44 };
  7293. UCHAR table1400_740[] = { 0x60, 0x03, 0x11, 0x00, 0x40, 0xe3,
  7294. 0xad, 0xdb, 0xf6, 0xac, 0xe0, 0x02, 0x44 };
  7295. UCHAR table1600_740[] = { 0x60, 0x04, 0x11, 0x00, 0x40, 0xe3,
  7296. 0xad, 0xde, 0xf6, 0xac, 0x60, 0x1a, 0x44 };
  7297. UCHAR table1024_650[] = { 0x60, 0x02, 0x00, 0x07, 0x40, 0xed,
  7298. 0xa3, 0xc8, 0xc7, 0xac, 0x60, 0x02 };
  7299. UCHAR table1280_650[] = { 0x60, 0x03, 0x11, 0x00, 0x40, 0xe3,
  7300. 0xad, 0xdb, 0xf6, 0xac, 0xe0, 0x02 };
  7301. UCHAR table1400_650[] = { 0x60, 0x03, 0x11, 0x00, 0x40, 0xef,
  7302. 0xad, 0xdb, 0xf6, 0xac, 0x60, 0x02 };
  7303. UCHAR table1600_650[] = { 0x60, 0x04, 0x11, 0x00, 0x40, 0xe3,
  7304. 0xad, 0xde, 0xf6, 0xac, 0x60, 0x1a };
  7305. UCHAR *tableptr = NULL;
  7306. USHORT tempbh;
  7307. int i;
  7308. if(HwInfo->jChipType == SIS_740) {
  7309. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) tableptr = table1024_740;
  7310. else if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) tableptr = table1280_740;
  7311. else if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) tableptr = table1400_740;
  7312. else if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) tableptr = table1600_740;
  7313. else return;
  7314. } else {
  7315. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) tableptr = table1024_650;
  7316. else if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) tableptr = table1280_650;
  7317. else if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) tableptr = table1400_650;
  7318. else if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) tableptr = table1600_650;
  7319. else return;
  7320. }
  7321. tempbh = SiS_GetCH701x(SiS_Pr,0x74);
  7322. if((tempbh == 0xf6) || (tempbh == 0xc7)) {
  7323. tempbh = SiS_GetCH701x(SiS_Pr,0x73);
  7324. if(tempbh == 0xc8) {
  7325. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) return;
  7326. } else if(tempbh == 0xdb) {
  7327. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) return;
  7328. if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) return;
  7329. } else if(tempbh == 0xde) {
  7330. if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) return;
  7331. }
  7332. }
  7333. if(HwInfo->jChipType == SIS_740) tempbh = 0x0d;
  7334. else tempbh = 0x0c;
  7335. for(i = 0; i < tempbh; i++) {
  7336. SiS_SetCH701x(SiS_Pr,(tableptr[i] << 8) | regtable[i]);
  7337. }
  7338. SiS_ChrontelPowerSequencing(SiS_Pr,HwInfo);
  7339. tempbh = SiS_GetCH701x(SiS_Pr,0x1e);
  7340. tempbh |= 0xc0;
  7341. SiS_SetCH701x(SiS_Pr,(tempbh << 8) | 0x1e);
  7342. if(HwInfo->jChipType == SIS_740) {
  7343. tempbh = SiS_GetCH701x(SiS_Pr,0x1c);
  7344. tempbh &= 0xfb;
  7345. SiS_SetCH701x(SiS_Pr,(tempbh << 8) | 0x1c);
  7346. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2d,0x03);
  7347. tempbh = SiS_GetCH701x(SiS_Pr,0x64);
  7348. tempbh |= 0x40;
  7349. SiS_SetCH701x(SiS_Pr,(tempbh << 8) | 0x64);
  7350. tempbh = SiS_GetCH701x(SiS_Pr,0x03);
  7351. tempbh &= 0x3f;
  7352. SiS_SetCH701x(SiS_Pr,(tempbh << 8) | 0x03);
  7353. }
  7354. }
  7355. static void
  7356. SiS_ChrontelResetVSync(SiS_Private *SiS_Pr)
  7357. {
  7358. unsigned char temp, temp1;
  7359. temp1 = SiS_GetCH701x(SiS_Pr,0x49);
  7360. SiS_SetCH701x(SiS_Pr,0x3e49);
  7361. temp = SiS_GetCH701x(SiS_Pr,0x47);
  7362. temp &= 0x7f; /* Use external VSYNC */
  7363. SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x47);
  7364. SiS_LongDelay(SiS_Pr,3);
  7365. temp = SiS_GetCH701x(SiS_Pr,0x47);
  7366. temp |= 0x80; /* Use internal VSYNC */
  7367. SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x47);
  7368. SiS_SetCH701x(SiS_Pr,(temp1 << 8) | 0x49);
  7369. }
  7370. static void
  7371. SiS_Chrontel701xOn(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
  7372. {
  7373. USHORT temp;
  7374. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  7375. if(HwInfo->jChipType == SIS_740) {
  7376. temp = SiS_GetCH701x(SiS_Pr,0x1c);
  7377. temp |= 0x04; /* Invert XCLK phase */
  7378. SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x1c);
  7379. }
  7380. if(SiS_IsYPbPr(SiS_Pr, HwInfo)) {
  7381. temp = SiS_GetCH701x(SiS_Pr,0x01);
  7382. temp &= 0x3f;
  7383. temp |= 0x80; /* Enable YPrPb (HDTV) */
  7384. SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x01);
  7385. }
  7386. if(SiS_IsChScart(SiS_Pr, HwInfo)) {
  7387. temp = SiS_GetCH701x(SiS_Pr,0x01);
  7388. temp &= 0x3f;
  7389. temp |= 0xc0; /* Enable SCART + CVBS */
  7390. SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x01);
  7391. }
  7392. if(HwInfo->jChipType == SIS_740) {
  7393. SiS_ChrontelResetVSync(SiS_Pr);
  7394. SiS_SetCH701x(SiS_Pr,0x2049); /* Enable TV path */
  7395. } else {
  7396. SiS_SetCH701x(SiS_Pr,0x2049); /* Enable TV path */
  7397. temp = SiS_GetCH701x(SiS_Pr,0x49);
  7398. if(SiS_IsYPbPr(SiS_Pr,HwInfo)) {
  7399. temp = SiS_GetCH701x(SiS_Pr,0x73);
  7400. temp |= 0x60;
  7401. SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x73);
  7402. }
  7403. temp = SiS_GetCH701x(SiS_Pr,0x47);
  7404. temp &= 0x7f;
  7405. SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x47);
  7406. SiS_LongDelay(SiS_Pr,2);
  7407. temp = SiS_GetCH701x(SiS_Pr,0x47);
  7408. temp |= 0x80;
  7409. SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x47);
  7410. }
  7411. }
  7412. }
  7413. static void
  7414. SiS_Chrontel701xOff(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
  7415. {
  7416. USHORT temp;
  7417. /* Complete power down of LVDS */
  7418. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  7419. if(HwInfo->jChipType == SIS_740) {
  7420. SiS_LongDelay(SiS_Pr,1);
  7421. SiS_GenericDelay(SiS_Pr,0x16ff);
  7422. SiS_SetCH701x(SiS_Pr,0xac76);
  7423. SiS_SetCH701x(SiS_Pr,0x0066);
  7424. } else {
  7425. SiS_LongDelay(SiS_Pr,2);
  7426. temp = SiS_GetCH701x(SiS_Pr,0x76);
  7427. temp &= 0xfc;
  7428. SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x76);
  7429. SiS_SetCH701x(SiS_Pr,0x0066);
  7430. }
  7431. }
  7432. }
  7433. static void
  7434. SiS_ChrontelResetDB(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
  7435. {
  7436. USHORT temp;
  7437. if(HwInfo->jChipType == SIS_740) {
  7438. temp = SiS_GetCH701x(SiS_Pr,0x4a); /* Version ID */
  7439. temp &= 0x01;
  7440. if(!temp) {
  7441. if(SiS_WeHaveBacklightCtrl(SiS_Pr,HwInfo)) {
  7442. temp = SiS_GetCH701x(SiS_Pr,0x49);
  7443. SiS_SetCH701x(SiS_Pr,0x3e49);
  7444. }
  7445. /* Reset Chrontel 7019 datapath */
  7446. SiS_SetCH701x(SiS_Pr,0x1048);
  7447. SiS_LongDelay(SiS_Pr,1);
  7448. SiS_SetCH701x(SiS_Pr,0x1848);
  7449. if(SiS_WeHaveBacklightCtrl(SiS_Pr, HwInfo)) {
  7450. SiS_ChrontelResetVSync(SiS_Pr);
  7451. SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x49);
  7452. }
  7453. } else {
  7454. /* Clear/set/clear GPIO */
  7455. temp = SiS_GetCH701x(SiS_Pr,0x5c);
  7456. temp &= 0xef;
  7457. SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x5c);
  7458. temp = SiS_GetCH701x(SiS_Pr,0x5c);
  7459. temp |= 0x10;
  7460. SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x5c);
  7461. temp = SiS_GetCH701x(SiS_Pr,0x5c);
  7462. temp &= 0xef;
  7463. SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x5c);
  7464. temp = SiS_GetCH701x(SiS_Pr,0x61);
  7465. if(!temp) {
  7466. SiS_SetCH701xForLCD(SiS_Pr, HwInfo);
  7467. }
  7468. }
  7469. } else { /* 650 */
  7470. /* Reset Chrontel 7019 datapath */
  7471. SiS_SetCH701x(SiS_Pr,0x1048);
  7472. SiS_LongDelay(SiS_Pr,1);
  7473. SiS_SetCH701x(SiS_Pr,0x1848);
  7474. }
  7475. }
  7476. static void
  7477. SiS_ChrontelInitTVVSync(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
  7478. {
  7479. USHORT temp;
  7480. if(HwInfo->jChipType == SIS_740) {
  7481. if(SiS_WeHaveBacklightCtrl(SiS_Pr,HwInfo)) {
  7482. SiS_ChrontelResetVSync(SiS_Pr);
  7483. }
  7484. } else {
  7485. SiS_SetCH701x(SiS_Pr,0xaf76); /* Power up LVDS block */
  7486. temp = SiS_GetCH701x(SiS_Pr,0x49);
  7487. temp &= 1;
  7488. if(temp != 1) { /* TV block powered? (0 = yes, 1 = no) */
  7489. temp = SiS_GetCH701x(SiS_Pr,0x47);
  7490. temp &= 0x70;
  7491. SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x47); /* enable VSYNC */
  7492. SiS_LongDelay(SiS_Pr,3);
  7493. temp = SiS_GetCH701x(SiS_Pr,0x47);
  7494. temp |= 0x80;
  7495. SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x47); /* disable VSYNC */
  7496. }
  7497. }
  7498. }
  7499. static void
  7500. SiS_ChrontelDoSomething3(SiS_Private *SiS_Pr, USHORT ModeNo, PSIS_HW_INFO HwInfo)
  7501. {
  7502. USHORT temp,temp1;
  7503. if(HwInfo->jChipType == SIS_740) {
  7504. temp = SiS_GetCH701x(SiS_Pr,0x61);
  7505. if(temp < 1) {
  7506. temp++;
  7507. SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x61);
  7508. }
  7509. SiS_SetCH701x(SiS_Pr,0x4566); /* Panel power on */
  7510. SiS_SetCH701x(SiS_Pr,0xaf76); /* All power on */
  7511. SiS_LongDelay(SiS_Pr,1);
  7512. SiS_GenericDelay(SiS_Pr,0x16ff);
  7513. } else { /* 650 */
  7514. temp1 = 0;
  7515. temp = SiS_GetCH701x(SiS_Pr,0x61);
  7516. if(temp < 2) {
  7517. temp++;
  7518. SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x61);
  7519. temp1 = 1;
  7520. }
  7521. SiS_SetCH701x(SiS_Pr,0xac76);
  7522. temp = SiS_GetCH701x(SiS_Pr,0x66);
  7523. temp |= 0x5f;
  7524. SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x66);
  7525. if(ModeNo > 0x13) {
  7526. if(SiS_WeHaveBacklightCtrl(SiS_Pr, HwInfo)) {
  7527. SiS_GenericDelay(SiS_Pr,0x3ff);
  7528. } else {
  7529. SiS_GenericDelay(SiS_Pr,0x2ff);
  7530. }
  7531. } else {
  7532. if(!temp1)
  7533. SiS_GenericDelay(SiS_Pr,0x2ff);
  7534. }
  7535. temp = SiS_GetCH701x(SiS_Pr,0x76);
  7536. temp |= 0x03;
  7537. SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x76);
  7538. temp = SiS_GetCH701x(SiS_Pr,0x66);
  7539. temp &= 0x7f;
  7540. SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x66);
  7541. SiS_LongDelay(SiS_Pr,1);
  7542. }
  7543. }
  7544. static void
  7545. SiS_ChrontelDoSomething2(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
  7546. {
  7547. USHORT temp,tempcl,tempch;
  7548. SiS_LongDelay(SiS_Pr, 1);
  7549. tempcl = 3;
  7550. tempch = 0;
  7551. do {
  7552. temp = SiS_GetCH701x(SiS_Pr,0x66);
  7553. temp &= 0x04; /* PLL stable? -> bail out */
  7554. if(temp == 0x04) break;
  7555. if(HwInfo->jChipType == SIS_740) {
  7556. /* Power down LVDS output, PLL normal operation */
  7557. SiS_SetCH701x(SiS_Pr,0xac76);
  7558. }
  7559. SiS_SetCH701xForLCD(SiS_Pr,HwInfo);
  7560. if(tempcl == 0) {
  7561. if(tempch == 3) break;
  7562. SiS_ChrontelResetDB(SiS_Pr,HwInfo);
  7563. tempcl = 3;
  7564. tempch++;
  7565. }
  7566. tempcl--;
  7567. temp = SiS_GetCH701x(SiS_Pr,0x76);
  7568. temp &= 0xfb; /* Reset PLL */
  7569. SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x76);
  7570. SiS_LongDelay(SiS_Pr,2);
  7571. temp = SiS_GetCH701x(SiS_Pr,0x76);
  7572. temp |= 0x04; /* PLL normal operation */
  7573. SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x76);
  7574. if(HwInfo->jChipType == SIS_740) {
  7575. SiS_SetCH701x(SiS_Pr,0xe078); /* PLL loop filter */
  7576. } else {
  7577. SiS_SetCH701x(SiS_Pr,0x6078);
  7578. }
  7579. SiS_LongDelay(SiS_Pr,2);
  7580. } while(0);
  7581. SiS_SetCH701x(SiS_Pr,0x0077); /* MV? */
  7582. }
  7583. static void
  7584. SiS_ChrontelDoSomething1(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
  7585. {
  7586. USHORT temp;
  7587. temp = SiS_GetCH701x(SiS_Pr,0x03);
  7588. temp |= 0x80; /* Set datapath 1 to TV */
  7589. temp &= 0xbf; /* Set datapath 2 to LVDS */
  7590. SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x03);
  7591. if(HwInfo->jChipType == SIS_740) {
  7592. temp = SiS_GetCH701x(SiS_Pr,0x1c);
  7593. temp &= 0xfb; /* Normal XCLK phase */
  7594. SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x1c);
  7595. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2d,0x03);
  7596. temp = SiS_GetCH701x(SiS_Pr,0x64);
  7597. temp |= 0x40; /* ? Bit not defined */
  7598. SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x64);
  7599. temp = SiS_GetCH701x(SiS_Pr,0x03);
  7600. temp &= 0x3f; /* D1 input to both LVDS and TV */
  7601. SiS_SetCH701x(SiS_Pr,(temp << 8) | 0x03);
  7602. if(SiS_Pr->SiS_CustomT == CUT_ASUSL3000D) {
  7603. SiS_SetCH701x(SiS_Pr,0x4063); /* LVDS off */
  7604. SiS_LongDelay(SiS_Pr, 1);
  7605. SiS_SetCH701x(SiS_Pr,0x0063); /* LVDS on */
  7606. SiS_ChrontelResetDB(SiS_Pr, HwInfo);
  7607. SiS_ChrontelDoSomething2(SiS_Pr, HwInfo);
  7608. SiS_ChrontelDoSomething3(SiS_Pr, 0, HwInfo);
  7609. } else {
  7610. temp = SiS_GetCH701x(SiS_Pr,0x66);
  7611. if(temp != 0x45) {
  7612. SiS_ChrontelResetDB(SiS_Pr, HwInfo);
  7613. SiS_ChrontelDoSomething2(SiS_Pr, HwInfo);
  7614. SiS_ChrontelDoSomething3(SiS_Pr, 0, HwInfo);
  7615. }
  7616. }
  7617. } else { /* 650 */
  7618. SiS_ChrontelResetDB(SiS_Pr,HwInfo);
  7619. SiS_ChrontelDoSomething2(SiS_Pr,HwInfo);
  7620. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x34);
  7621. SiS_ChrontelDoSomething3(SiS_Pr,temp,HwInfo);
  7622. SiS_SetCH701x(SiS_Pr,0xaf76); /* All power on, LVDS normal operation */
  7623. }
  7624. }
  7625. #endif /* 315 series */
  7626. /*********************************************/
  7627. /* MAIN: SET CRT2 REGISTER GROUP */
  7628. /*********************************************/
  7629. BOOLEAN
  7630. SiS_SetCRT2Group(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo)
  7631. {
  7632. #ifdef SIS300
  7633. UCHAR *ROMAddr = HwInfo->pjVirtualRomBase;
  7634. #endif
  7635. USHORT ModeIdIndex, RefreshRateTableIndex;
  7636. #if 0
  7637. USHORT temp;
  7638. #endif
  7639. SiS_Pr->SiS_SetFlag |= ProgrammingCRT2;
  7640. if(!SiS_Pr->UseCustomMode) {
  7641. SiS_SearchModeID(SiS_Pr, &ModeNo, &ModeIdIndex);
  7642. } else {
  7643. ModeIdIndex = 0;
  7644. }
  7645. /* Used for shifting CR33 */
  7646. SiS_Pr->SiS_SelectCRT2Rate = 4;
  7647. SiS_UnLockCRT2(SiS_Pr, HwInfo);
  7648. RefreshRateTableIndex = SiS_GetRatePtr(SiS_Pr, ModeNo, ModeIdIndex, HwInfo);
  7649. SiS_SaveCRT2Info(SiS_Pr,ModeNo);
  7650. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7651. SiS_DisableBridge(SiS_Pr,HwInfo);
  7652. if((SiS_Pr->SiS_IF_DEF_LVDS == 1) && (HwInfo->jChipType == SIS_730)) {
  7653. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,0x80);
  7654. }
  7655. SiS_SetCRT2ModeRegs(SiS_Pr, ModeNo, ModeIdIndex, HwInfo);
  7656. }
  7657. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) {
  7658. SiS_LockCRT2(SiS_Pr, HwInfo);
  7659. SiS_DisplayOn(SiS_Pr);
  7660. return TRUE;
  7661. }
  7662. SiS_GetCRT2Data(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex, HwInfo);
  7663. /* Set up Panel Link for LVDS and LCDA */
  7664. SiS_Pr->SiS_LCDHDES = SiS_Pr->SiS_LCDVDES = 0;
  7665. if( (SiS_Pr->SiS_IF_DEF_LVDS == 1) ||
  7666. ((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) ||
  7667. ((HwInfo->jChipType >= SIS_315H) && (SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV)) ) {
  7668. SiS_GetLVDSDesData(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex, HwInfo);
  7669. }
  7670. #ifdef LINUX_XF86
  7671. #ifdef TWDEBUG
  7672. xf86DrvMsg(0, X_INFO, "(init301: LCDHDES 0x%03x LCDVDES 0x%03x)\n", SiS_Pr->SiS_LCDHDES, SiS_Pr->SiS_LCDVDES);
  7673. xf86DrvMsg(0, X_INFO, "(init301: HDE 0x%03x VDE 0x%03x)\n", SiS_Pr->SiS_HDE, SiS_Pr->SiS_VDE);
  7674. xf86DrvMsg(0, X_INFO, "(init301: VGAHDE 0x%03x VGAVDE 0x%03x)\n", SiS_Pr->SiS_VGAHDE, SiS_Pr->SiS_VGAVDE);
  7675. xf86DrvMsg(0, X_INFO, "(init301: HT 0x%03x VT 0x%03x)\n", SiS_Pr->SiS_HT, SiS_Pr->SiS_VT);
  7676. xf86DrvMsg(0, X_INFO, "(init301: VGAHT 0x%03x VGAVT 0x%03x)\n", SiS_Pr->SiS_VGAHT, SiS_Pr->SiS_VGAVT);
  7677. #endif
  7678. #endif
  7679. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7680. SiS_SetGroup1(SiS_Pr, ModeNo, ModeIdIndex, HwInfo, RefreshRateTableIndex);
  7681. }
  7682. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  7683. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7684. SiS_SetGroup2(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex, HwInfo);
  7685. #ifdef SIS315H
  7686. SiS_SetGroup2_C_ELV(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex, HwInfo);
  7687. #endif
  7688. SiS_SetGroup3(SiS_Pr, ModeNo, ModeIdIndex, HwInfo);
  7689. SiS_SetGroup4(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex, HwInfo);
  7690. #ifdef SIS315H
  7691. SiS_SetGroup4_C_ELV(SiS_Pr, HwInfo, ModeNo, ModeIdIndex);
  7692. #endif
  7693. SiS_SetGroup5(SiS_Pr, ModeNo, ModeIdIndex, HwInfo);
  7694. SiS_SetCRT2Sync(SiS_Pr, ModeNo, RefreshRateTableIndex, HwInfo);
  7695. /* For 301BDH (Panel link initialization): */
  7696. if((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) {
  7697. if(SiS_Pr->SiS_LCDResInfo != Panel_640x480) {
  7698. if(!((SiS_Pr->SiS_SetFlag & SetDOSMode) && ((ModeNo == 0x03) || (ModeNo == 0x10)))) {
  7699. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  7700. SiS_ModCRT1CRTC(SiS_Pr,ModeNo,ModeIdIndex,
  7701. RefreshRateTableIndex,HwInfo);
  7702. }
  7703. }
  7704. }
  7705. SiS_SetCRT2ECLK(SiS_Pr,ModeNo,ModeIdIndex,
  7706. RefreshRateTableIndex,HwInfo);
  7707. }
  7708. }
  7709. } else {
  7710. SiS_SetCRT2Sync(SiS_Pr, ModeNo, RefreshRateTableIndex, HwInfo);
  7711. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  7712. SiS_ModCRT1CRTC(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex,HwInfo);
  7713. }
  7714. SiS_SetCRT2ECLK(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex,HwInfo);
  7715. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7716. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  7717. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  7718. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  7719. #ifdef SIS315H
  7720. SiS_SetCH701xForLCD(SiS_Pr,HwInfo);
  7721. #endif
  7722. }
  7723. }
  7724. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  7725. SiS_SetCHTVReg(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex);
  7726. }
  7727. }
  7728. }
  7729. }
  7730. #ifdef SIS300
  7731. if(HwInfo->jChipType < SIS_315H) {
  7732. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7733. if(SiS_Pr->SiS_UseOEM) {
  7734. if((SiS_Pr->SiS_UseROM) && (SiS_Pr->SiS_UseOEM == -1)) {
  7735. if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) {
  7736. SiS_OEM300Setting(SiS_Pr,HwInfo,ModeNo,ModeIdIndex,
  7737. RefreshRateTableIndex);
  7738. }
  7739. } else {
  7740. SiS_OEM300Setting(SiS_Pr,HwInfo,ModeNo,ModeIdIndex,
  7741. RefreshRateTableIndex);
  7742. }
  7743. }
  7744. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  7745. if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) ||
  7746. (SiS_Pr->SiS_CustomT == CUT_BARCO1024)) {
  7747. SetOEMLCDData2(SiS_Pr, HwInfo, ModeNo, ModeIdIndex,RefreshRateTableIndex);
  7748. }
  7749. SiS_DisplayOn(SiS_Pr);
  7750. }
  7751. }
  7752. }
  7753. #endif
  7754. #ifdef SIS315H
  7755. if(HwInfo->jChipType >= SIS_315H) {
  7756. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7757. if(HwInfo->jChipType < SIS_661) {
  7758. SiS_FinalizeLCD(SiS_Pr, ModeNo, ModeIdIndex, HwInfo);
  7759. SiS_OEM310Setting(SiS_Pr, HwInfo, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7760. } else {
  7761. SiS_OEM661Setting(SiS_Pr, HwInfo, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7762. }
  7763. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x01,0x40);
  7764. }
  7765. }
  7766. #endif
  7767. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7768. SiS_EnableBridge(SiS_Pr, HwInfo);
  7769. }
  7770. SiS_DisplayOn(SiS_Pr);
  7771. if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) {
  7772. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  7773. /* Disable LCD panel when using TV */
  7774. SiS_SetRegSR11ANDOR(SiS_Pr,HwInfo,0xFF,0x0C);
  7775. } else {
  7776. /* Disable TV when using LCD */
  7777. SiS_SetCH70xxANDOR(SiS_Pr,0x010E,0xF8);
  7778. }
  7779. }
  7780. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7781. SiS_LockCRT2(SiS_Pr,HwInfo);
  7782. }
  7783. return TRUE;
  7784. }
  7785. /*********************************************/
  7786. /* ENABLE/DISABLE LCD BACKLIGHT (SIS) */
  7787. /*********************************************/
  7788. void
  7789. SiS_SiS30xBLOn(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
  7790. {
  7791. /* Switch on LCD backlight on SiS30xLV */
  7792. SiS_DDC2Delay(SiS_Pr,0xff00);
  7793. if(!(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x26) & 0x02)) {
  7794. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x02);
  7795. SiS_WaitVBRetrace(SiS_Pr,HwInfo);
  7796. }
  7797. if(!(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x26) & 0x01)) {
  7798. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x01);
  7799. }
  7800. }
  7801. void
  7802. SiS_SiS30xBLOff(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
  7803. {
  7804. /* Switch off LCD backlight on SiS30xLV */
  7805. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFE);
  7806. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFD);
  7807. SiS_DDC2Delay(SiS_Pr,0xe000);
  7808. }
  7809. /*********************************************/
  7810. /* DDC RELATED FUNCTIONS */
  7811. /*********************************************/
  7812. static void
  7813. SiS_SetupDDCN(SiS_Private *SiS_Pr)
  7814. {
  7815. SiS_Pr->SiS_DDC_NData = ~SiS_Pr->SiS_DDC_Data;
  7816. SiS_Pr->SiS_DDC_NClk = ~SiS_Pr->SiS_DDC_Clk;
  7817. if((SiS_Pr->SiS_DDC_Index == 0x11) && (SiS_Pr->SiS_SensibleSR11)) {
  7818. SiS_Pr->SiS_DDC_NData &= 0x0f;
  7819. SiS_Pr->SiS_DDC_NClk &= 0x0f;
  7820. }
  7821. }
  7822. #ifdef SIS300
  7823. static UCHAR *
  7824. SiS_SetTrumpBlockLoop(SiS_Private *SiS_Pr, UCHAR *dataptr)
  7825. {
  7826. int i, j, num;
  7827. USHORT tempah,temp;
  7828. UCHAR *mydataptr;
  7829. for(i=0; i<20; i++) { /* Do 20 attempts to write */
  7830. mydataptr = dataptr;
  7831. num = *mydataptr++;
  7832. if(!num) return mydataptr;
  7833. if(i) {
  7834. SiS_SetStop(SiS_Pr);
  7835. SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT*2);
  7836. }
  7837. if(SiS_SetStart(SiS_Pr)) continue; /* Set start condition */
  7838. tempah = SiS_Pr->SiS_DDC_DeviceAddr;
  7839. temp = SiS_WriteDDC2Data(SiS_Pr,tempah); /* Write DAB (S0=0=write) */
  7840. if(temp) continue; /* (ERROR: no ack) */
  7841. tempah = *mydataptr++;
  7842. temp = SiS_WriteDDC2Data(SiS_Pr,tempah); /* Write register number */
  7843. if(temp) continue; /* (ERROR: no ack) */
  7844. for(j=0; j<num; j++) {
  7845. tempah = *mydataptr++;
  7846. temp = SiS_WriteDDC2Data(SiS_Pr,tempah);/* Write DAB (S0=0=write) */
  7847. if(temp) break;
  7848. }
  7849. if(temp) continue;
  7850. if(SiS_SetStop(SiS_Pr)) continue;
  7851. return mydataptr;
  7852. }
  7853. return NULL;
  7854. }
  7855. static BOOLEAN
  7856. SiS_SetTrumpionBlock(SiS_Private *SiS_Pr, UCHAR *dataptr)
  7857. {
  7858. SiS_Pr->SiS_DDC_DeviceAddr = 0xF0; /* DAB (Device Address Byte) */
  7859. SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */
  7860. SiS_Pr->SiS_DDC_Data = 0x02; /* Bitmask in IndexReg for Data */
  7861. SiS_Pr->SiS_DDC_Clk = 0x01; /* Bitmask in IndexReg for Clk */
  7862. SiS_SetupDDCN(SiS_Pr);
  7863. SiS_SetSwitchDDC2(SiS_Pr);
  7864. while(*dataptr) {
  7865. dataptr = SiS_SetTrumpBlockLoop(SiS_Pr, dataptr);
  7866. if(!dataptr) return FALSE;
  7867. }
  7868. #ifdef TWDEBUG
  7869. xf86DrvMsg(0, X_INFO, "Trumpion block success\n");
  7870. #endif
  7871. return TRUE;
  7872. }
  7873. #endif
  7874. /* The Chrontel 700x is connected to the 630/730 via
  7875. * the 630/730's DDC/I2C port.
  7876. *
  7877. * On 630(S)T chipset, the index changed from 0x11 to
  7878. * 0x0a, possibly for working around the DDC problems
  7879. */
  7880. static BOOLEAN
  7881. SiS_SetChReg(SiS_Private *SiS_Pr, USHORT tempbx, USHORT myor)
  7882. {
  7883. USHORT tempah,temp,i;
  7884. for(i=0; i<20; i++) { /* Do 20 attempts to write */
  7885. if(i) {
  7886. SiS_SetStop(SiS_Pr);
  7887. SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT);
  7888. }
  7889. if(SiS_SetStart(SiS_Pr)) continue; /* Set start condition */
  7890. tempah = SiS_Pr->SiS_DDC_DeviceAddr;
  7891. temp = SiS_WriteDDC2Data(SiS_Pr,tempah); /* Write DAB (S0=0=write) */
  7892. if(temp) continue; /* (ERROR: no ack) */
  7893. tempah = tempbx & 0x00FF; /* Write RAB */
  7894. tempah |= myor; /* (700x: set bit 7, see datasheet) */
  7895. temp = SiS_WriteDDC2Data(SiS_Pr,tempah);
  7896. if(temp) continue; /* (ERROR: no ack) */
  7897. tempah = (tempbx & 0xFF00) >> 8;
  7898. temp = SiS_WriteDDC2Data(SiS_Pr,tempah); /* Write data */
  7899. if(temp) continue; /* (ERROR: no ack) */
  7900. if(SiS_SetStop(SiS_Pr)) continue; /* Set stop condition */
  7901. SiS_Pr->SiS_ChrontelInit = 1;
  7902. return TRUE;
  7903. }
  7904. return FALSE;
  7905. }
  7906. #if 0
  7907. #ifdef SIS300
  7908. /* Write Trumpion register */
  7909. static void
  7910. SiS_SetTrumpReg(SiS_Private *SiS_Pr, USHORT tempbx)
  7911. {
  7912. SiS_Pr->SiS_DDC_DeviceAddr = 0xF0; /* DAB (Device Address Byte) */
  7913. SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */
  7914. SiS_Pr->SiS_DDC_Data = 0x02; /* Bitmask in IndexReg for Data */
  7915. SiS_Pr->SiS_DDC_Clk = 0x01; /* Bitmask in IndexReg for Clk */
  7916. SiS_SetupDDCN(SiS_Pr);
  7917. SiS_SetChReg(SiS_Pr, tempbx, 0);
  7918. }
  7919. #endif
  7920. #endif
  7921. /* Write to Chrontel 700x */
  7922. /* Parameter is [Data (S15-S8) | Register no (S7-S0)] */
  7923. void
  7924. SiS_SetCH700x(SiS_Private *SiS_Pr, USHORT tempbx)
  7925. {
  7926. SiS_Pr->SiS_DDC_DeviceAddr = 0xEA; /* DAB (Device Address Byte) */
  7927. if(!(SiS_Pr->SiS_ChrontelInit)) {
  7928. SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */
  7929. SiS_Pr->SiS_DDC_Data = 0x02; /* Bitmask in IndexReg for Data */
  7930. SiS_Pr->SiS_DDC_Clk = 0x01; /* Bitmask in IndexReg for Clk */
  7931. SiS_SetupDDCN(SiS_Pr);
  7932. }
  7933. if( (!(SiS_SetChReg(SiS_Pr, tempbx, 0x80))) &&
  7934. (!(SiS_Pr->SiS_ChrontelInit)) ) {
  7935. SiS_Pr->SiS_DDC_Index = 0x0a; /* Bit 7 = SC; Bit 6 = SD */
  7936. SiS_Pr->SiS_DDC_Data = 0x80; /* Bitmask in IndexReg for Data */
  7937. SiS_Pr->SiS_DDC_Clk = 0x40; /* Bitmask in IndexReg for Clk */
  7938. SiS_SetupDDCN(SiS_Pr);
  7939. SiS_SetChReg(SiS_Pr, tempbx, 0x80);
  7940. }
  7941. }
  7942. /* Write to Chrontel 701x */
  7943. /* Parameter is [Data (S15-S8) | Register no (S7-S0)] */
  7944. void
  7945. SiS_SetCH701x(SiS_Private *SiS_Pr, USHORT tempbx)
  7946. {
  7947. SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */
  7948. SiS_Pr->SiS_DDC_Data = 0x08; /* Bitmask in IndexReg for Data */
  7949. SiS_Pr->SiS_DDC_Clk = 0x04; /* Bitmask in IndexReg for Clk */
  7950. SiS_SetupDDCN(SiS_Pr);
  7951. SiS_Pr->SiS_DDC_DeviceAddr = 0xEA; /* DAB (Device Address Byte) */
  7952. SiS_SetChReg(SiS_Pr, tempbx, 0);
  7953. }
  7954. static void
  7955. SiS_SetCH70xx(SiS_Private *SiS_Pr, USHORT tempbx)
  7956. {
  7957. if(SiS_Pr->SiS_IF_DEF_CH70xx == 1)
  7958. SiS_SetCH700x(SiS_Pr,tempbx);
  7959. else
  7960. SiS_SetCH701x(SiS_Pr,tempbx);
  7961. }
  7962. static USHORT
  7963. SiS_GetChReg(SiS_Private *SiS_Pr, USHORT myor)
  7964. {
  7965. USHORT tempah,temp,i;
  7966. for(i=0; i<20; i++) { /* Do 20 attempts to read */
  7967. if(i) {
  7968. SiS_SetStop(SiS_Pr);
  7969. SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT);
  7970. }
  7971. if(SiS_SetStart(SiS_Pr)) continue; /* Set start condition */
  7972. tempah = SiS_Pr->SiS_DDC_DeviceAddr;
  7973. temp = SiS_WriteDDC2Data(SiS_Pr,tempah); /* Write DAB (S0=0=write) */
  7974. if(temp) continue; /* (ERROR: no ack) */
  7975. tempah = SiS_Pr->SiS_DDC_ReadAddr | myor; /* Write RAB (700x: | 0x80) */
  7976. temp = SiS_WriteDDC2Data(SiS_Pr,tempah);
  7977. if(temp) continue; /* (ERROR: no ack) */
  7978. if (SiS_SetStart(SiS_Pr)) continue; /* Re-start */
  7979. tempah = SiS_Pr->SiS_DDC_DeviceAddr | 0x01;/* DAB | 0x01 = Read */
  7980. temp = SiS_WriteDDC2Data(SiS_Pr,tempah); /* DAB (S0=1=read) */
  7981. if(temp) continue; /* (ERROR: no ack) */
  7982. tempah = SiS_ReadDDC2Data(SiS_Pr,tempah); /* Read byte */
  7983. if(SiS_SetStop(SiS_Pr)) continue; /* Stop condition */
  7984. SiS_Pr->SiS_ChrontelInit = 1;
  7985. return(tempah);
  7986. }
  7987. return 0xFFFF;
  7988. }
  7989. #if 0
  7990. #ifdef SIS300
  7991. /* Read from Trumpion */
  7992. static USHORT
  7993. SiS_GetTrumpReg(SiS_Private *SiS_Pr, USHORT tempbx)
  7994. {
  7995. SiS_Pr->SiS_DDC_DeviceAddr = 0xF0; /* DAB */
  7996. SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */
  7997. SiS_Pr->SiS_DDC_Data = 0x02; /* Bitmask in IndexReg for Data */
  7998. SiS_Pr->SiS_DDC_Clk = 0x01; /* Bitmask in IndexReg for Clk */
  7999. SiS_SetupDDCN(SiS_Pr);
  8000. SiS_Pr->SiS_DDC_ReadAddr = tempbx;
  8001. return(SiS_GetChReg(SiS_Pr,0));
  8002. }
  8003. #endif
  8004. #endif
  8005. /* Read from Chrontel 700x */
  8006. /* Parameter is [Register no (S7-S0)] */
  8007. USHORT
  8008. SiS_GetCH700x(SiS_Private *SiS_Pr, USHORT tempbx)
  8009. {
  8010. USHORT result;
  8011. SiS_Pr->SiS_DDC_DeviceAddr = 0xEA; /* DAB */
  8012. if(!(SiS_Pr->SiS_ChrontelInit)) {
  8013. SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */
  8014. SiS_Pr->SiS_DDC_Data = 0x02; /* Bitmask in IndexReg for Data */
  8015. SiS_Pr->SiS_DDC_Clk = 0x01; /* Bitmask in IndexReg for Clk */
  8016. SiS_SetupDDCN(SiS_Pr);
  8017. }
  8018. SiS_Pr->SiS_DDC_ReadAddr = tempbx;
  8019. if( ((result = SiS_GetChReg(SiS_Pr,0x80)) == 0xFFFF) &&
  8020. (!SiS_Pr->SiS_ChrontelInit) ) {
  8021. SiS_Pr->SiS_DDC_Index = 0x0a;
  8022. SiS_Pr->SiS_DDC_Data = 0x80;
  8023. SiS_Pr->SiS_DDC_Clk = 0x40;
  8024. SiS_SetupDDCN(SiS_Pr);
  8025. result = SiS_GetChReg(SiS_Pr,0x80);
  8026. }
  8027. return(result);
  8028. }
  8029. /* Read from Chrontel 701x */
  8030. /* Parameter is [Register no (S7-S0)] */
  8031. USHORT
  8032. SiS_GetCH701x(SiS_Private *SiS_Pr, USHORT tempbx)
  8033. {
  8034. SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */
  8035. SiS_Pr->SiS_DDC_Data = 0x08; /* Bitmask in IndexReg for Data */
  8036. SiS_Pr->SiS_DDC_Clk = 0x04; /* Bitmask in IndexReg for Clk */
  8037. SiS_SetupDDCN(SiS_Pr);
  8038. SiS_Pr->SiS_DDC_DeviceAddr = 0xEA; /* DAB */
  8039. SiS_Pr->SiS_DDC_ReadAddr = tempbx;
  8040. return(SiS_GetChReg(SiS_Pr,0));
  8041. }
  8042. /* Read from Chrontel 70xx */
  8043. /* Parameter is [Register no (S7-S0)] */
  8044. static USHORT
  8045. SiS_GetCH70xx(SiS_Private *SiS_Pr, USHORT tempbx)
  8046. {
  8047. if(SiS_Pr->SiS_IF_DEF_CH70xx == 1)
  8048. return(SiS_GetCH700x(SiS_Pr, tempbx));
  8049. else
  8050. return(SiS_GetCH701x(SiS_Pr, tempbx));
  8051. }
  8052. /* Our own DDC functions */
  8053. static USHORT
  8054. SiS_InitDDCRegs(SiS_Private *SiS_Pr, unsigned long VBFlags, int VGAEngine,
  8055. USHORT adaptnum, USHORT DDCdatatype, BOOLEAN checkcr32)
  8056. {
  8057. unsigned char ddcdtype[] = { 0xa0, 0xa0, 0xa0, 0xa2, 0xa6 };
  8058. unsigned char flag, cr32;
  8059. USHORT temp = 0, myadaptnum = adaptnum;
  8060. if(adaptnum != 0) {
  8061. if(!(VBFlags & (VB_301|VB_301B|VB_301C|VB_302B))) return 0xFFFF;
  8062. if((VBFlags & VB_30xBDH) && (adaptnum == 1)) return 0xFFFF;
  8063. }
  8064. /* adapternum for SiS bridges: 0 = CRT1, 1 = LCD, 2 = VGA2 */
  8065. SiS_Pr->SiS_ChrontelInit = 0; /* force re-detection! */
  8066. SiS_Pr->SiS_DDC_SecAddr = 0;
  8067. SiS_Pr->SiS_DDC_DeviceAddr = ddcdtype[DDCdatatype];
  8068. SiS_Pr->SiS_DDC_Port = SiS_Pr->SiS_P3c4;
  8069. SiS_Pr->SiS_DDC_Index = 0x11;
  8070. flag = 0xff;
  8071. cr32 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x32);
  8072. #if 0
  8073. if(VBFlags & VB_SISBRIDGE) {
  8074. if(myadaptnum == 0) {
  8075. if(!(cr32 & 0x20)) {
  8076. myadaptnum = 2;
  8077. if(!(cr32 & 0x10)) {
  8078. myadaptnum = 1;
  8079. if(!(cr32 & 0x08)) {
  8080. myadaptnum = 0;
  8081. }
  8082. }
  8083. }
  8084. }
  8085. }
  8086. #endif
  8087. if(VGAEngine == SIS_300_VGA) { /* 300 series */
  8088. if(myadaptnum != 0) {
  8089. flag = 0;
  8090. if(VBFlags & VB_SISBRIDGE) {
  8091. SiS_Pr->SiS_DDC_Port = SiS_Pr->SiS_Part4Port;
  8092. SiS_Pr->SiS_DDC_Index = 0x0f;
  8093. }
  8094. }
  8095. if(!(VBFlags & VB_301)) {
  8096. if((cr32 & 0x80) && (checkcr32)) {
  8097. if(myadaptnum >= 1) {
  8098. if(!(cr32 & 0x08)) {
  8099. myadaptnum = 1;
  8100. if(!(cr32 & 0x10)) return 0xFFFF;
  8101. }
  8102. }
  8103. }
  8104. }
  8105. temp = 4 - (myadaptnum * 2);
  8106. if(flag) temp = 0;
  8107. } else { /* 315/330 series */
  8108. /* here we simplify: 0 = CRT1, 1 = CRT2 (VGA, LCD) */
  8109. if(VBFlags & VB_SISBRIDGE) {
  8110. if(myadaptnum == 2) {
  8111. myadaptnum = 1;
  8112. }
  8113. }
  8114. if(myadaptnum == 1) {
  8115. flag = 0;
  8116. if(VBFlags & VB_SISBRIDGE) {
  8117. SiS_Pr->SiS_DDC_Port = SiS_Pr->SiS_Part4Port;
  8118. SiS_Pr->SiS_DDC_Index = 0x0f;
  8119. }
  8120. }
  8121. if((cr32 & 0x80) && (checkcr32)) {
  8122. if(myadaptnum >= 1) {
  8123. if(!(cr32 & 0x08)) {
  8124. myadaptnum = 1;
  8125. if(!(cr32 & 0x10)) return 0xFFFF;
  8126. }
  8127. }
  8128. }
  8129. temp = myadaptnum;
  8130. if(myadaptnum == 1) {
  8131. temp = 0;
  8132. if(VBFlags & VB_LVDS) flag = 0xff;
  8133. }
  8134. if(flag) temp = 0;
  8135. }
  8136. SiS_Pr->SiS_DDC_Data = 0x02 << temp;
  8137. SiS_Pr->SiS_DDC_Clk = 0x01 << temp;
  8138. SiS_SetupDDCN(SiS_Pr);
  8139. #ifdef TWDEBUG
  8140. xf86DrvMsg(0, X_INFO, "DDC Port %x Index %x Shift %d\n",
  8141. SiS_Pr->SiS_DDC_Port, SiS_Pr->SiS_DDC_Index, temp);
  8142. #endif
  8143. return 0;
  8144. }
  8145. static USHORT
  8146. SiS_WriteDABDDC(SiS_Private *SiS_Pr)
  8147. {
  8148. if(SiS_SetStart(SiS_Pr)) return 0xFFFF;
  8149. if(SiS_WriteDDC2Data(SiS_Pr, SiS_Pr->SiS_DDC_DeviceAddr)) {
  8150. return 0xFFFF;
  8151. }
  8152. if(SiS_WriteDDC2Data(SiS_Pr, SiS_Pr->SiS_DDC_SecAddr)) {
  8153. return 0xFFFF;
  8154. }
  8155. return(0);
  8156. }
  8157. static USHORT
  8158. SiS_PrepareReadDDC(SiS_Private *SiS_Pr)
  8159. {
  8160. if(SiS_SetStart(SiS_Pr)) return 0xFFFF;
  8161. if(SiS_WriteDDC2Data(SiS_Pr, (SiS_Pr->SiS_DDC_DeviceAddr | 0x01))) {
  8162. return 0xFFFF;
  8163. }
  8164. return(0);
  8165. }
  8166. static USHORT
  8167. SiS_PrepareDDC(SiS_Private *SiS_Pr)
  8168. {
  8169. if(SiS_WriteDABDDC(SiS_Pr)) SiS_WriteDABDDC(SiS_Pr);
  8170. if(SiS_PrepareReadDDC(SiS_Pr)) return(SiS_PrepareReadDDC(SiS_Pr));
  8171. return(0);
  8172. }
  8173. static void
  8174. SiS_SendACK(SiS_Private *SiS_Pr, USHORT yesno)
  8175. {
  8176. SiS_SetSCLKLow(SiS_Pr);
  8177. if(yesno) {
  8178. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8179. SiS_Pr->SiS_DDC_Index,
  8180. SiS_Pr->SiS_DDC_NData,
  8181. SiS_Pr->SiS_DDC_Data);
  8182. } else {
  8183. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8184. SiS_Pr->SiS_DDC_Index,
  8185. SiS_Pr->SiS_DDC_NData,
  8186. 0);
  8187. }
  8188. SiS_SetSCLKHigh(SiS_Pr);
  8189. }
  8190. static USHORT
  8191. SiS_DoProbeDDC(SiS_Private *SiS_Pr)
  8192. {
  8193. unsigned char mask, value;
  8194. USHORT temp, ret=0;
  8195. BOOLEAN failed = FALSE;
  8196. SiS_SetSwitchDDC2(SiS_Pr);
  8197. if(SiS_PrepareDDC(SiS_Pr)) {
  8198. SiS_SetStop(SiS_Pr);
  8199. #ifdef TWDEBUG
  8200. xf86DrvMsg(0, X_INFO, "Probe: Prepare failed\n");
  8201. #endif
  8202. return(0xFFFF);
  8203. }
  8204. mask = 0xf0;
  8205. value = 0x20;
  8206. if(SiS_Pr->SiS_DDC_DeviceAddr == 0xa0) {
  8207. temp = (unsigned char)SiS_ReadDDC2Data(SiS_Pr, 0);
  8208. SiS_SendACK(SiS_Pr, 0);
  8209. if(temp == 0) {
  8210. mask = 0xff;
  8211. value = 0xff;
  8212. } else {
  8213. failed = TRUE;
  8214. ret = 0xFFFF;
  8215. #ifdef TWDEBUG
  8216. xf86DrvMsg(0, X_INFO, "Probe: Read 1 failed\n");
  8217. #endif
  8218. }
  8219. }
  8220. if(failed == FALSE) {
  8221. temp = (unsigned char)SiS_ReadDDC2Data(SiS_Pr, 0);
  8222. SiS_SendACK(SiS_Pr, 1);
  8223. temp &= mask;
  8224. if(temp == value) ret = 0;
  8225. else {
  8226. ret = 0xFFFF;
  8227. #ifdef TWDEBUG
  8228. xf86DrvMsg(0, X_INFO, "Probe: Read 2 failed\n");
  8229. #endif
  8230. if(SiS_Pr->SiS_DDC_DeviceAddr == 0xa0) {
  8231. if(temp == 0x30) ret = 0;
  8232. }
  8233. }
  8234. }
  8235. SiS_SetStop(SiS_Pr);
  8236. return(ret);
  8237. }
  8238. static USHORT
  8239. SiS_ProbeDDC(SiS_Private *SiS_Pr)
  8240. {
  8241. USHORT flag;
  8242. flag = 0x180;
  8243. SiS_Pr->SiS_DDC_DeviceAddr = 0xa0;
  8244. if(!(SiS_DoProbeDDC(SiS_Pr))) flag |= 0x02;
  8245. SiS_Pr->SiS_DDC_DeviceAddr = 0xa2;
  8246. if(!(SiS_DoProbeDDC(SiS_Pr))) flag |= 0x08;
  8247. SiS_Pr->SiS_DDC_DeviceAddr = 0xa6;
  8248. if(!(SiS_DoProbeDDC(SiS_Pr))) flag |= 0x10;
  8249. if(!(flag & 0x1a)) flag = 0;
  8250. return(flag);
  8251. }
  8252. static USHORT
  8253. SiS_ReadDDC(SiS_Private *SiS_Pr, USHORT DDCdatatype, unsigned char *buffer)
  8254. {
  8255. USHORT flag, length, i;
  8256. unsigned char chksum,gotcha;
  8257. if(DDCdatatype > 4) return 0xFFFF;
  8258. flag = 0;
  8259. SiS_SetSwitchDDC2(SiS_Pr);
  8260. if(!(SiS_PrepareDDC(SiS_Pr))) {
  8261. length = 127;
  8262. if(DDCdatatype != 1) length = 255;
  8263. chksum = 0;
  8264. gotcha = 0;
  8265. for(i=0; i<length; i++) {
  8266. buffer[i] = (unsigned char)SiS_ReadDDC2Data(SiS_Pr, 0);
  8267. chksum += buffer[i];
  8268. gotcha |= buffer[i];
  8269. SiS_SendACK(SiS_Pr, 0);
  8270. }
  8271. buffer[i] = (unsigned char)SiS_ReadDDC2Data(SiS_Pr, 0);
  8272. chksum += buffer[i];
  8273. SiS_SendACK(SiS_Pr, 1);
  8274. if(gotcha) flag = (USHORT)chksum;
  8275. else flag = 0xFFFF;
  8276. } else {
  8277. flag = 0xFFFF;
  8278. }
  8279. SiS_SetStop(SiS_Pr);
  8280. return(flag);
  8281. }
  8282. /* Our private DDC functions
  8283. It complies somewhat with the corresponding VESA function
  8284. in arguments and return values.
  8285. Since this is probably called before the mode is changed,
  8286. we use our pre-detected pSiS-values instead of SiS_Pr as
  8287. regards chipset and video bridge type.
  8288. Arguments:
  8289. adaptnum: 0=CRT1(analog), 1=CRT2/LCD(digital), 2=CRT2/VGA2(analog)
  8290. CRT2 DDC is only supported on SiS301, 301B, 301C, 302B.
  8291. LCDA is CRT1, but DDC is read from CRT2 port.
  8292. DDCdatatype: 0=Probe, 1=EDID, 2=EDID+VDIF, 3=EDID V2 (P&D), 4=EDID V2 (FPDI-2)
  8293. buffer: ptr to 256 data bytes which will be filled with read data.
  8294. Returns 0xFFFF if error, otherwise
  8295. if DDCdatatype > 0: Returns 0 if reading OK (included a correct checksum)
  8296. if DDCdatatype = 0: Returns supported DDC modes
  8297. */
  8298. USHORT
  8299. SiS_HandleDDC(SiS_Private *SiS_Pr, unsigned long VBFlags, int VGAEngine,
  8300. USHORT adaptnum, USHORT DDCdatatype, unsigned char *buffer)
  8301. {
  8302. unsigned char sr1f,cr17=1;
  8303. USHORT result;
  8304. if(adaptnum > 2) return 0xFFFF;
  8305. if(DDCdatatype > 4) return 0xFFFF;
  8306. if((!(VBFlags & VB_VIDEOBRIDGE)) && (adaptnum > 0)) return 0xFFFF;
  8307. if(SiS_InitDDCRegs(SiS_Pr, VBFlags, VGAEngine, adaptnum, DDCdatatype, FALSE) == 0xFFFF) return 0xFFFF;
  8308. sr1f = SiS_GetReg(SiS_Pr->SiS_P3c4,0x1f);
  8309. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x1f,0x3f,0x04);
  8310. if(VGAEngine == SIS_300_VGA) {
  8311. cr17 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x17) & 0x80;
  8312. if(!cr17) {
  8313. SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x17,0x80);
  8314. SiS_SetReg(SiS_Pr->SiS_P3c4,0x00,0x01);
  8315. SiS_SetReg(SiS_Pr->SiS_P3c4,0x00,0x03);
  8316. }
  8317. }
  8318. if((sr1f) || (!cr17)) {
  8319. SiS_WaitRetrace1(SiS_Pr);
  8320. SiS_WaitRetrace1(SiS_Pr);
  8321. SiS_WaitRetrace1(SiS_Pr);
  8322. SiS_WaitRetrace1(SiS_Pr);
  8323. }
  8324. if(DDCdatatype == 0) {
  8325. result = SiS_ProbeDDC(SiS_Pr);
  8326. } else {
  8327. result = SiS_ReadDDC(SiS_Pr, DDCdatatype, buffer);
  8328. if((!result) && (DDCdatatype == 1)) {
  8329. if((buffer[0] == 0x00) && (buffer[1] == 0xff) &&
  8330. (buffer[2] == 0xff) && (buffer[3] == 0xff) &&
  8331. (buffer[4] == 0xff) && (buffer[5] == 0xff) &&
  8332. (buffer[6] == 0xff) && (buffer[7] == 0x00) &&
  8333. (buffer[0x12] == 1)) {
  8334. if(adaptnum == 1) {
  8335. if(!(buffer[0x14] & 0x80)) result = 0xFFFE;
  8336. } else {
  8337. if(buffer[0x14] & 0x80) result = 0xFFFE;
  8338. }
  8339. }
  8340. }
  8341. }
  8342. SiS_SetReg(SiS_Pr->SiS_P3c4,0x1f,sr1f);
  8343. if(VGAEngine == SIS_300_VGA) {
  8344. SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x17,0x7f,cr17);
  8345. }
  8346. return result;
  8347. }
  8348. #ifdef LINUX_XF86
  8349. static BOOLEAN
  8350. checkedid1(unsigned char *buffer)
  8351. {
  8352. /* Check header */
  8353. if((buffer[0] != 0x00) ||
  8354. (buffer[1] != 0xff) ||
  8355. (buffer[2] != 0xff) ||
  8356. (buffer[3] != 0xff) ||
  8357. (buffer[4] != 0xff) ||
  8358. (buffer[5] != 0xff) ||
  8359. (buffer[6] != 0xff) ||
  8360. (buffer[7] != 0x00))
  8361. return FALSE;
  8362. /* Check EDID version and revision */
  8363. if((buffer[0x12] != 1) || (buffer[0x13] > 4)) return FALSE;
  8364. /* Check week of manufacture for sanity */
  8365. if(buffer[0x10] > 53) return FALSE;
  8366. /* Check year of manufacture for sanity */
  8367. if(buffer[0x11] > 40) return FALSE;
  8368. return TRUE;
  8369. }
  8370. static BOOLEAN
  8371. checkedid2(unsigned char *buffer)
  8372. {
  8373. USHORT year = buffer[6] | (buffer[7] << 8);
  8374. /* Check EDID version */
  8375. if((buffer[0] & 0xf0) != 0x20) return FALSE;
  8376. /* Check week of manufacture for sanity */
  8377. if(buffer[5] > 53) return FALSE;
  8378. /* Check year of manufacture for sanity */
  8379. if((year != 0) && ((year < 1990) || (year > 2030))) return FALSE;
  8380. return TRUE;
  8381. }
  8382. /* Sense the LCD parameters (CR36, CR37) via DDC */
  8383. /* SiS30x(B) only */
  8384. USHORT
  8385. SiS_SenseLCDDDC(SiS_Private *SiS_Pr, SISPtr pSiS)
  8386. {
  8387. USHORT DDCdatatype, paneltype, flag, xres=0, yres=0;
  8388. USHORT index, myindex, lumsize, numcodes, panelvendor, panelproduct;
  8389. int maxx=0, maxy=0, prefx=0, prefy=0;
  8390. unsigned char cr37=0, seekcode;
  8391. BOOLEAN checkexpand = FALSE;
  8392. BOOLEAN havesync = FALSE;
  8393. BOOLEAN indb = FALSE;
  8394. int retry, i;
  8395. unsigned char buffer[256];
  8396. for(i=0; i<7; i++) SiS_Pr->CP_DataValid[i] = FALSE;
  8397. SiS_Pr->CP_HaveCustomData = FALSE;
  8398. SiS_Pr->CP_MaxX = SiS_Pr->CP_MaxY = SiS_Pr->CP_MaxClock = 0;
  8399. SiS_Pr->CP_PreferredX = SiS_Pr->CP_PreferredY = 0;
  8400. SiS_Pr->CP_PreferredIndex = -1;
  8401. SiS_Pr->CP_PrefClock = 0;
  8402. SiS_Pr->PanelSelfDetected = FALSE;
  8403. if(!(pSiS->VBFlags & (VB_301|VB_301B|VB_301C|VB_302B))) return 0;
  8404. if(pSiS->VBFlags & VB_30xBDH) return 0;
  8405. if(SiS_InitDDCRegs(SiS_Pr, pSiS->VBFlags, pSiS->VGAEngine, 1, 0, FALSE) == 0xFFFF) return 0;
  8406. SiS_Pr->SiS_DDC_SecAddr = 0x00;
  8407. /* Probe supported DA's */
  8408. flag = SiS_ProbeDDC(SiS_Pr);
  8409. #ifdef TWDEBUG
  8410. xf86DrvMsg(pSiS->pScrn->scrnIndex, X_INFO,
  8411. "CRT2 DDC capabilities 0x%x\n", flag);
  8412. #endif
  8413. if(flag & 0x10) {
  8414. SiS_Pr->SiS_DDC_DeviceAddr = 0xa6; /* EDID V2 (FP) */
  8415. DDCdatatype = 4;
  8416. } else if(flag & 0x08) {
  8417. SiS_Pr->SiS_DDC_DeviceAddr = 0xa2; /* EDID V2 (P&D-D Monitor) */
  8418. DDCdatatype = 3;
  8419. } else if(flag & 0x02) {
  8420. SiS_Pr->SiS_DDC_DeviceAddr = 0xa0; /* EDID V1 */
  8421. DDCdatatype = 1;
  8422. } else return 0; /* no DDC support (or no device attached) */
  8423. /* Read the entire EDID */
  8424. retry = 2;
  8425. do {
  8426. if(SiS_ReadDDC(SiS_Pr, DDCdatatype, buffer)) {
  8427. xf86DrvMsg(pSiS->pScrn->scrnIndex, X_PROBED,
  8428. "CRT2: DDC read failed (attempt %d), %s\n",
  8429. (3-retry), (retry == 1) ? "giving up" : "retrying");
  8430. retry--;
  8431. if(retry == 0) return 0xFFFF;
  8432. } else break;
  8433. } while(1);
  8434. #ifdef TWDEBUG
  8435. for(i=0; i<256; i+=16) {
  8436. xf86DrvMsg(pSiS->pScrn->scrnIndex, X_PROBED,
  8437. "%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
  8438. buffer[i], buffer[i+1], buffer[i+2], buffer[i+3],
  8439. buffer[i+4], buffer[i+5], buffer[i+6], buffer[i+7],
  8440. buffer[i+8], buffer[i+9], buffer[i+10], buffer[i+11],
  8441. buffer[i+12], buffer[i+13], buffer[i+14], buffer[i+15]);
  8442. }
  8443. #endif
  8444. /* Analyze EDID and retrieve LCD panel information */
  8445. paneltype = 0;
  8446. switch(DDCdatatype) {
  8447. case 1: /* Analyze EDID V1 */
  8448. /* Catch a few clear cases: */
  8449. if(!(checkedid1(buffer))) {
  8450. xf86DrvMsg(pSiS->pScrn->scrnIndex, X_PROBED,
  8451. "LCD sense: EDID corrupt\n");
  8452. return 0;
  8453. }
  8454. if(!(buffer[0x14] & 0x80)) {
  8455. xf86DrvMsg(pSiS->pScrn->scrnIndex, X_PROBED,
  8456. "LCD sense: Attached display expects analog input (0x%02x)\n",
  8457. buffer[0x14]);
  8458. return 0;
  8459. }
  8460. if((buffer[0x18] & 0x18) != 0x08) {
  8461. xf86DrvMsg(pSiS->pScrn->scrnIndex, X_PROBED,
  8462. "LCD sense: Warning: Attached display is not of RGB but of %s type (0x%02x)\n",
  8463. ((buffer[0x18] & 0x18) == 0x00) ? "monochrome/greyscale" :
  8464. ( ((buffer[0x18] & 0x18) == 0x10) ? "non-RGB multicolor" :
  8465. "undefined"),
  8466. buffer[0x18]);
  8467. }
  8468. /* Now analyze the first Detailed Timing Block and see
  8469. * if the preferred timing mode is stored there. If so,
  8470. * check if this is a standard panel for which we already
  8471. * know the timing.
  8472. */
  8473. paneltype = Panel_Custom;
  8474. checkexpand = FALSE;
  8475. panelvendor = buffer[9] | (buffer[8] << 8);
  8476. panelproduct = buffer[10] | (buffer[11] << 8);
  8477. /* Overrule bogus preferred modes from database */
  8478. if((indb = SiS_FindPanelFromDB(pSiS, panelvendor, panelproduct, &maxx, &maxy, &prefx, &prefy))) {
  8479. if(prefx) SiS_Pr->CP_PreferredX = xres = prefx;
  8480. if(prefy) SiS_Pr->CP_PreferredY = yres = prefy;
  8481. }
  8482. if(buffer[0x18] & 0x02) {
  8483. USHORT pclk = (buffer[0x36] | (buffer[0x37] << 8));
  8484. USHORT phb = (buffer[0x39] | ((buffer[0x3a] & 0x0f) << 8));
  8485. USHORT pvb = (buffer[0x3c] | ((buffer[0x3d] & 0x0f) << 8));
  8486. if(!xres) SiS_Pr->CP_PreferredX = xres = buffer[0x38] | ((buffer[0x3a] & 0xf0) << 4);
  8487. if(!yres) SiS_Pr->CP_PreferredY = yres = buffer[0x3b] | ((buffer[0x3d] & 0xf0) << 4);
  8488. switch(xres) {
  8489. #if 0 /* Treat as custom */
  8490. case 800:
  8491. if(yres == 600) {
  8492. paneltype = Panel_800x600;
  8493. checkexpand = TRUE;
  8494. }
  8495. break;
  8496. #endif
  8497. case 1024:
  8498. if(yres == 768) {
  8499. paneltype = Panel_1024x768;
  8500. checkexpand = TRUE;
  8501. }
  8502. break;
  8503. case 1280:
  8504. if(yres == 1024) {
  8505. paneltype = Panel_1280x1024;
  8506. checkexpand = TRUE;
  8507. } else if(yres == 960) {
  8508. if(pSiS->VGAEngine == SIS_300_VGA) {
  8509. paneltype = Panel300_1280x960;
  8510. } else {
  8511. paneltype = Panel310_1280x960;
  8512. }
  8513. } else if(yres == 768) {
  8514. if( (pclk == 8100) &&
  8515. (phb == (1688 - 1280)) &&
  8516. (pvb == (802 - 768)) ) {
  8517. paneltype = Panel_1280x768;
  8518. checkexpand = FALSE;
  8519. cr37 |= 0x10;
  8520. }
  8521. } else if(yres == 800) {
  8522. if( (pclk == 6900) &&
  8523. (phb == (1408 - 1280)) &&
  8524. (pvb == (816 - 800)) ) {
  8525. paneltype = Panel_1280x800;
  8526. }
  8527. }
  8528. break;
  8529. case 1400:
  8530. if(pSiS->VGAEngine == SIS_315_VGA) {
  8531. if(yres == 1050) {
  8532. paneltype = Panel310_1400x1050;
  8533. checkexpand = TRUE;
  8534. }
  8535. }
  8536. break;
  8537. case 1600:
  8538. if(pSiS->VGAEngine == SIS_315_VGA) {
  8539. if(pSiS->VBFlags & VB_301C) {
  8540. if(yres == 1200) {
  8541. paneltype = Panel310_1600x1200;
  8542. checkexpand = TRUE;
  8543. }
  8544. }
  8545. }
  8546. break;
  8547. }
  8548. /* Save sync: This is used if "Pass 1:1" is off; in this case
  8549. * we always use the panel's native mode = this "preferred mode"
  8550. * we just have been analysing. Hence, we also need its sync.
  8551. */
  8552. if((buffer[0x47] & 0x18) == 0x18) {
  8553. cr37 |= ((((buffer[0x47] & 0x06) ^ 0x06) << 5) | 0x20);
  8554. havesync = TRUE;
  8555. } else {
  8556. /* What now? There is no digital separate output timing... */
  8557. xf86DrvMsg(pSiS->pScrn->scrnIndex, X_WARNING,
  8558. "LCD sense: Unable to retrieve Sync polarity information\n");
  8559. cr37 |= 0xc0; /* Default */
  8560. }
  8561. }
  8562. /* Check against our database; eg. Sanyo Z2 projector reports
  8563. * 1024x768 as preferred mode, although it supports 1280x720
  8564. * natively in non-HDCP mode. Treat such wrongly reporting
  8565. * panels as custom and fixup actual maximum resolutions.
  8566. */
  8567. if(paneltype != Panel_Custom) {
  8568. if(indb) {
  8569. paneltype = Panel_Custom;
  8570. SiS_Pr->CP_MaxX = maxx;
  8571. SiS_Pr->CP_MaxY = maxy;
  8572. /* Leave preferred unchanged (MUST contain a valid mode!) */
  8573. }
  8574. }
  8575. /* If we still don't know what panel this is, we take it
  8576. * as a custom panel and derive the timing data from the
  8577. * detailed timing blocks
  8578. */
  8579. if(paneltype == Panel_Custom) {
  8580. int i, temp, base = 0x36;
  8581. unsigned long estpack;
  8582. const unsigned short estx[] = {
  8583. 720, 720, 640, 640, 640, 640, 800, 800,
  8584. 800, 800, 832,1024,1024,1024,1024,1280,
  8585. 1152
  8586. };
  8587. const unsigned short esty[] = {
  8588. 400, 400, 480, 480, 480, 480, 600, 600,
  8589. 600, 600, 624, 768, 768, 768, 768,1024,
  8590. 870
  8591. };
  8592. const int estclk[] = {
  8593. 0, 0, 25100, 0, 31500, 31500, 36100, 40000,
  8594. 50100, 49500, 0, 0, 65100, 75200, 78700,135200,
  8595. 0
  8596. };
  8597. paneltype = 0;
  8598. SiS_Pr->CP_Supports64048075 = TRUE;
  8599. /* Find the maximum resolution */
  8600. /* 1. From Established timings */
  8601. estpack = (buffer[0x23] << 9) | (buffer[0x24] << 1) | ((buffer[0x25] >> 7) & 0x01);
  8602. for(i=16; i>=0; i--) {
  8603. if(estpack & (1 << i)) {
  8604. if(estx[16 - i] > SiS_Pr->CP_MaxX) SiS_Pr->CP_MaxX = estx[16 - i];
  8605. if(esty[16 - i] > SiS_Pr->CP_MaxY) SiS_Pr->CP_MaxY = esty[16 - i];
  8606. if(estclk[16 - i] > SiS_Pr->CP_MaxClock) SiS_Pr->CP_MaxClock = estclk[16 - i];
  8607. }
  8608. }
  8609. /* By default we drive the LCD at 75Hz in 640x480 mode; if
  8610. * the panel does not provide this mode, use 60hz
  8611. */
  8612. if(!(buffer[0x23] & 0x04)) SiS_Pr->CP_Supports64048075 = FALSE;
  8613. /* 2. From Standard Timings */
  8614. for(i=0x26; i < 0x36; i+=2) {
  8615. if((buffer[i] != 0x01) && (buffer[i+1] != 0x01)) {
  8616. temp = (buffer[i] + 31) * 8;
  8617. if(temp > SiS_Pr->CP_MaxX) SiS_Pr->CP_MaxX = temp;
  8618. switch((buffer[i+1] & 0xc0) >> 6) {
  8619. case 0x03: temp = temp * 9 / 16; break;
  8620. case 0x02: temp = temp * 4 / 5; break;
  8621. case 0x01: temp = temp * 3 / 4; break;
  8622. }
  8623. if(temp > SiS_Pr->CP_MaxY) SiS_Pr->CP_MaxY = temp;
  8624. }
  8625. }
  8626. /* Now extract the Detailed Timings and convert them into modes */
  8627. for(i = 0; i < 4; i++, base += 18) {
  8628. /* Is this a detailed timing block or a monitor descriptor? */
  8629. if(buffer[base] || buffer[base+1] || buffer[base+2]) {
  8630. xres = buffer[base+2] | ((buffer[base+4] & 0xf0) << 4);
  8631. yres = buffer[base+5] | ((buffer[base+7] & 0xf0) << 4);
  8632. SiS_Pr->CP_HDisplay[i] = xres;
  8633. SiS_Pr->CP_HSyncStart[i] = xres + (buffer[base+8] | ((buffer[base+11] & 0xc0) << 2));
  8634. SiS_Pr->CP_HSyncEnd[i] = SiS_Pr->CP_HSyncStart[i] + (buffer[base+9] | ((buffer[base+11] & 0x30) << 4));
  8635. SiS_Pr->CP_HTotal[i] = xres + (buffer[base+3] | ((buffer[base+4] & 0x0f) << 8));
  8636. SiS_Pr->CP_HBlankStart[i] = xres + 1;
  8637. SiS_Pr->CP_HBlankEnd[i] = SiS_Pr->CP_HTotal[i];
  8638. SiS_Pr->CP_VDisplay[i] = yres;
  8639. SiS_Pr->CP_VSyncStart[i] = yres + (((buffer[base+10] & 0xf0) >> 4) | ((buffer[base+11] & 0x0c) << 2));
  8640. SiS_Pr->CP_VSyncEnd[i] = SiS_Pr->CP_VSyncStart[i] + ((buffer[base+10] & 0x0f) | ((buffer[base+11] & 0x03) << 4));
  8641. SiS_Pr->CP_VTotal[i] = yres + (buffer[base+6] | ((buffer[base+7] & 0x0f) << 8));
  8642. SiS_Pr->CP_VBlankStart[i] = yres + 1;
  8643. SiS_Pr->CP_VBlankEnd[i] = SiS_Pr->CP_VTotal[i];
  8644. SiS_Pr->CP_Clock[i] = (buffer[base] | (buffer[base+1] << 8)) * 10;
  8645. SiS_Pr->CP_DataValid[i] = TRUE;
  8646. /* Sort out invalid timings, interlace and too high clocks */
  8647. if((SiS_Pr->CP_HDisplay[i] & 7) ||
  8648. (SiS_Pr->CP_HDisplay[i] > SiS_Pr->CP_HSyncStart[i]) ||
  8649. (SiS_Pr->CP_HDisplay[i] >= SiS_Pr->CP_HSyncEnd[i]) ||
  8650. (SiS_Pr->CP_HDisplay[i] >= SiS_Pr->CP_HTotal[i]) ||
  8651. (SiS_Pr->CP_HSyncStart[i] >= SiS_Pr->CP_HSyncEnd[i]) ||
  8652. (SiS_Pr->CP_HSyncStart[i] > SiS_Pr->CP_HTotal[i]) ||
  8653. (SiS_Pr->CP_HSyncEnd[i] > SiS_Pr->CP_HTotal[i]) ||
  8654. (SiS_Pr->CP_VDisplay[i] > SiS_Pr->CP_VSyncStart[i]) ||
  8655. (SiS_Pr->CP_VDisplay[i] >= SiS_Pr->CP_VSyncEnd[i]) ||
  8656. (SiS_Pr->CP_VDisplay[i] >= SiS_Pr->CP_VTotal[i]) ||
  8657. (SiS_Pr->CP_VSyncStart[i] > SiS_Pr->CP_VSyncEnd[i]) ||
  8658. (SiS_Pr->CP_VSyncStart[i] > SiS_Pr->CP_VTotal[i]) ||
  8659. (SiS_Pr->CP_VSyncEnd[i] > SiS_Pr->CP_VTotal[i]) ||
  8660. (((pSiS->VBFlags & VB_301C) && (SiS_Pr->CP_Clock[i] > 162500)) ||
  8661. ((!(pSiS->VBFlags & VB_301C)) &&
  8662. ((SiS_Pr->CP_Clock[i] > 108200) || (SiS_Pr->CP_VDisplay[i] > 1024) ||
  8663. (SiS_Pr->CP_HDisplay[i] > 1600)))) ||
  8664. (buffer[base+17] & 0x80)) {
  8665. SiS_Pr->CP_DataValid[i] = FALSE;
  8666. } else {
  8667. SiS_Pr->CP_HaveCustomData = TRUE;
  8668. if(xres > SiS_Pr->CP_MaxX) SiS_Pr->CP_MaxX = xres;
  8669. if(yres > SiS_Pr->CP_MaxY) SiS_Pr->CP_MaxY = yres;
  8670. if(SiS_Pr->CP_Clock[i] > SiS_Pr->CP_MaxClock) SiS_Pr->CP_MaxClock = SiS_Pr->CP_Clock[i];
  8671. if((SiS_Pr->CP_PreferredX == xres) && (SiS_Pr->CP_PreferredY == yres)) {
  8672. SiS_Pr->CP_PreferredIndex = i;
  8673. SiS_MakeClockRegs(pSiS->pScrn, SiS_Pr->CP_Clock[i], &SiS_Pr->CP_PrefSR2B, &SiS_Pr->CP_PrefSR2C);
  8674. SiS_Pr->CP_PrefClock = (SiS_Pr->CP_Clock[i] / 1000) + 1;
  8675. }
  8676. /* Extract the sync polarisation information. This only works
  8677. * if the Flags indicate a digital separate output.
  8678. */
  8679. if((buffer[base+17] & 0x18) == 0x18) {
  8680. SiS_Pr->CP_HSync_P[i] = (buffer[base+17] & 0x02) ? TRUE : FALSE;
  8681. SiS_Pr->CP_VSync_P[i] = (buffer[base+17] & 0x04) ? TRUE : FALSE;
  8682. SiS_Pr->CP_SyncValid[i] = TRUE;
  8683. if((i == SiS_Pr->CP_PreferredIndex) && (!havesync)) {
  8684. cr37 |= ((((buffer[base+17] & 0x06) ^ 0x06) << 5) | 0x20);
  8685. havesync = TRUE;
  8686. }
  8687. } else {
  8688. SiS_Pr->CP_SyncValid[i] = FALSE;
  8689. }
  8690. }
  8691. } else if((!buffer[base]) && (!buffer[base+1]) && (!buffer[base+2]) && (!buffer[base+4])) {
  8692. /* Maximum pixclock from Monitor Range Limits */
  8693. if((buffer[base+3] == 0xfd) && (buffer[base+9] != 0xff)) {
  8694. int maxclk = buffer[base+9] * 10;
  8695. /* More than 170 is not supported anyway */
  8696. if(maxclk <= 170) SiS_Pr->CP_MaxClock = maxclk * 1000;
  8697. }
  8698. }
  8699. }
  8700. if(SiS_Pr->CP_MaxX && SiS_Pr->CP_MaxY) {
  8701. paneltype = Panel_Custom;
  8702. checkexpand = FALSE;
  8703. cr37 |= 0x10;
  8704. SiS_Pr->CP_Vendor = panelvendor;
  8705. SiS_Pr->CP_Product = panelproduct;
  8706. }
  8707. }
  8708. if(paneltype && checkexpand) {
  8709. /* If any of the Established low-res modes is supported, the
  8710. * panel can scale automatically. For 800x600 panels, we only
  8711. * check the even lower ones.
  8712. */
  8713. if(paneltype == Panel_800x600) {
  8714. if(buffer[0x23] & 0xfc) cr37 |= 0x10;
  8715. } else {
  8716. if(buffer[0x23]) cr37 |= 0x10;
  8717. }
  8718. }
  8719. break;
  8720. case 3: /* Analyze EDID V2 */
  8721. case 4:
  8722. index = 0;
  8723. if(!(checkedid2(buffer))) {
  8724. xf86DrvMsg(pSiS->pScrn->scrnIndex, X_PROBED,
  8725. "LCD sense: EDID corrupt\n");
  8726. return 0;
  8727. }
  8728. if((buffer[0x41] & 0x0f) == 0x03) {
  8729. index = 0x42 + 3;
  8730. xf86DrvMsg(pSiS->pScrn->scrnIndex, X_PROBED,
  8731. "LCD sense: Display supports TMDS input on primary interface\n");
  8732. } else if((buffer[0x41] & 0xf0) == 0x30) {
  8733. index = 0x46 + 3;
  8734. xf86DrvMsg(pSiS->pScrn->scrnIndex, X_PROBED,
  8735. "LCD sense: Display supports TMDS input on secondary interface\n");
  8736. } else {
  8737. xf86DrvMsg(pSiS->pScrn->scrnIndex, X_PROBED,
  8738. "LCD sense: Display does not support TMDS video interface (0x%02x)\n",
  8739. buffer[0x41]);
  8740. return 0;
  8741. }
  8742. SiS_Pr->CP_Vendor = panelvendor = buffer[2] | (buffer[1] << 8);
  8743. SiS_Pr->CP_Product = panelproduct = buffer[3] | (buffer[4] << 8);
  8744. paneltype = Panel_Custom;
  8745. SiS_Pr->CP_MaxX = SiS_Pr->CP_PreferredX = xres = buffer[0x76] | (buffer[0x77] << 8);
  8746. SiS_Pr->CP_MaxY = SiS_Pr->CP_PreferredY = yres = buffer[0x78] | (buffer[0x79] << 8);
  8747. switch(xres) {
  8748. #if 0
  8749. case 800:
  8750. if(yres == 600) {
  8751. paneltype = Panel_800x600;
  8752. checkexpand = TRUE;
  8753. }
  8754. break;
  8755. #endif
  8756. case 1024:
  8757. if(yres == 768) {
  8758. paneltype = Panel_1024x768;
  8759. checkexpand = TRUE;
  8760. }
  8761. break;
  8762. case 1280:
  8763. if(yres == 960) {
  8764. if(pSiS->VGAEngine == SIS_315_VGA) {
  8765. paneltype = Panel310_1280x960;
  8766. } else {
  8767. paneltype = Panel300_1280x960;
  8768. }
  8769. } else if(yres == 1024) {
  8770. paneltype = Panel_1280x1024;
  8771. checkexpand = TRUE;
  8772. }
  8773. /* 1280x768 treated as custom here */
  8774. break;
  8775. case 1400:
  8776. if(pSiS->VGAEngine == SIS_315_VGA) {
  8777. if(yres == 1050) {
  8778. paneltype = Panel310_1400x1050;
  8779. checkexpand = TRUE;
  8780. }
  8781. }
  8782. break;
  8783. case 1600:
  8784. if(pSiS->VGAEngine == SIS_315_VGA) {
  8785. if(pSiS->VBFlags & VB_301C) {
  8786. if(yres == 1200) {
  8787. paneltype = Panel310_1600x1200;
  8788. checkexpand = TRUE;
  8789. }
  8790. }
  8791. }
  8792. break;
  8793. }
  8794. /* Determine if RGB18 or RGB24 */
  8795. if(index) {
  8796. if((buffer[index] == 0x20) || (buffer[index] == 0x34)) {
  8797. cr37 |= 0x01;
  8798. }
  8799. }
  8800. if(checkexpand) {
  8801. /* TODO - for now, we let the panel scale */
  8802. cr37 |= 0x10;
  8803. }
  8804. /* Now seek 4-Byte Timing codes and extract sync pol info */
  8805. index = 0x80;
  8806. if(buffer[0x7e] & 0x20) { /* skip Luminance Table (if provided) */
  8807. lumsize = buffer[0x80] & 0x1f;
  8808. if(buffer[0x80] & 0x80) lumsize *= 3;
  8809. lumsize++; /* luminance header byte */
  8810. index += lumsize;
  8811. }
  8812. #if 0 /* "pixel rate" = pixel clock? */
  8813. if(buffer[0x7e] & 0x1c) {
  8814. for(i=0; i<((buffer[0x7e] & 0x1c) >> 2); i++) {
  8815. if(buffer[index + (i*8) + 6] && (buffer[index + (i*8) + 7] & 0x0f)) {
  8816. int clk = (buffer[index + (i*8) + 6] | ((buffer[index + (i*8) + 7] & 0x0f) << 4)) * 1000;
  8817. if(clk > SiS_Pr->CP_MaxClock) SiS_Pr->CP_MaxClock = clk;
  8818. }
  8819. }
  8820. }
  8821. #endif
  8822. index += (((buffer[0x7e] & 0x1c) >> 2) * 8); /* skip Frequency Ranges */
  8823. if(buffer[0x7e] & 0x03) {
  8824. for(i=0; i<(buffer[0x7e] & 0x03); i++) {
  8825. if((buffer[index + (i*27) + 9]) || (buffer[index + (i*27) + 10])) {
  8826. int clk = ((buffer[index + (i*27) + 9]) | ((buffer[index + (i*27) + 9]) << 8)) * 10;
  8827. if(clk > SiS_Pr->CP_MaxClock) SiS_Pr->CP_MaxClock = clk;
  8828. }
  8829. }
  8830. }
  8831. index += ((buffer[0x7e] & 0x03) * 27); /* skip Detailed Range Limits */
  8832. numcodes = (buffer[0x7f] & 0xf8) >> 3;
  8833. if(numcodes) {
  8834. myindex = index;
  8835. seekcode = (xres - 256) / 16;
  8836. for(i=0; i<numcodes; i++) {
  8837. if(buffer[myindex] == seekcode) break;
  8838. myindex += 4;
  8839. }
  8840. if(buffer[myindex] == seekcode) {
  8841. cr37 |= ((((buffer[myindex + 1] & 0x0c) ^ 0x0c) << 4) | 0x20);
  8842. havesync = TRUE;
  8843. } else {
  8844. xf86DrvMsg(pSiS->pScrn->scrnIndex, X_WARNING,
  8845. "LCD sense: Unable to retrieve Sync polarity information\n");
  8846. }
  8847. } else {
  8848. xf86DrvMsg(pSiS->pScrn->scrnIndex, X_WARNING,
  8849. "LCD sense: Unable to retrieve Sync polarity information\n");
  8850. }
  8851. /* Check against our database; Eg. Sanyo projector reports
  8852. * 1024x768 in non-HDPC mode, although it supports 1280x720.
  8853. * Treat such wrongly reporting panels as custom.
  8854. */
  8855. if(paneltype != Panel_Custom) {
  8856. int maxx, maxy, prefx, prefy;
  8857. if((SiS_FindPanelFromDB(pSiS, panelvendor, panelproduct, &maxx, &maxy, &prefx, &prefy))) {
  8858. paneltype = Panel_Custom;
  8859. SiS_Pr->CP_MaxX = maxx;
  8860. SiS_Pr->CP_MaxY = maxy;
  8861. cr37 |= 0x10;
  8862. /* Leave preferred unchanged (MUST be a valid mode!) */
  8863. }
  8864. }
  8865. /* Now seek the detailed timing descriptions for custom panels */
  8866. if(paneltype == Panel_Custom) {
  8867. SiS_Pr->CP_Supports64048075 = TRUE;
  8868. index += (numcodes * 4);
  8869. numcodes = buffer[0x7f] & 0x07;
  8870. for(i=0; i<numcodes; i++, index += 18) {
  8871. xres = buffer[index+2] | ((buffer[index+4] & 0xf0) << 4);
  8872. yres = buffer[index+5] | ((buffer[index+7] & 0xf0) << 4);
  8873. SiS_Pr->CP_HDisplay[i] = xres;
  8874. SiS_Pr->CP_HSyncStart[i] = xres + (buffer[index+8] | ((buffer[index+11] & 0xc0) << 2));
  8875. SiS_Pr->CP_HSyncEnd[i] = SiS_Pr->CP_HSyncStart[i] + (buffer[index+9] | ((buffer[index+11] & 0x30) << 4));
  8876. SiS_Pr->CP_HTotal[i] = xres + (buffer[index+3] | ((buffer[index+4] & 0x0f) << 8));
  8877. SiS_Pr->CP_HBlankStart[i] = xres + 1;
  8878. SiS_Pr->CP_HBlankEnd[i] = SiS_Pr->CP_HTotal[i];
  8879. SiS_Pr->CP_VDisplay[i] = yres;
  8880. SiS_Pr->CP_VSyncStart[i] = yres + (((buffer[index+10] & 0xf0) >> 4) | ((buffer[index+11] & 0x0c) << 2));
  8881. SiS_Pr->CP_VSyncEnd[i] = SiS_Pr->CP_VSyncStart[i] + ((buffer[index+10] & 0x0f) | ((buffer[index+11] & 0x03) << 4));
  8882. SiS_Pr->CP_VTotal[i] = yres + (buffer[index+6] | ((buffer[index+7] & 0x0f) << 8));
  8883. SiS_Pr->CP_VBlankStart[i] = yres + 1;
  8884. SiS_Pr->CP_VBlankEnd[i] = SiS_Pr->CP_VTotal[i];
  8885. SiS_Pr->CP_Clock[i] = (buffer[index] | (buffer[index+1] << 8)) * 10;
  8886. SiS_Pr->CP_DataValid[i] = TRUE;
  8887. if((SiS_Pr->CP_HDisplay[i] & 7) ||
  8888. (SiS_Pr->CP_HDisplay[i] > SiS_Pr->CP_HSyncStart[i]) ||
  8889. (SiS_Pr->CP_HDisplay[i] >= SiS_Pr->CP_HSyncEnd[i]) ||
  8890. (SiS_Pr->CP_HDisplay[i] >= SiS_Pr->CP_HTotal[i]) ||
  8891. (SiS_Pr->CP_HSyncStart[i] >= SiS_Pr->CP_HSyncEnd[i]) ||
  8892. (SiS_Pr->CP_HSyncStart[i] > SiS_Pr->CP_HTotal[i]) ||
  8893. (SiS_Pr->CP_HSyncEnd[i] > SiS_Pr->CP_HTotal[i]) ||
  8894. (SiS_Pr->CP_VDisplay[i] > SiS_Pr->CP_VSyncStart[i]) ||
  8895. (SiS_Pr->CP_VDisplay[i] >= SiS_Pr->CP_VSyncEnd[i]) ||
  8896. (SiS_Pr->CP_VDisplay[i] >= SiS_Pr->CP_VTotal[i]) ||
  8897. (SiS_Pr->CP_VSyncStart[i] > SiS_Pr->CP_VSyncEnd[i]) ||
  8898. (SiS_Pr->CP_VSyncStart[i] > SiS_Pr->CP_VTotal[i]) ||
  8899. (SiS_Pr->CP_VSyncEnd[i] > SiS_Pr->CP_VTotal[i]) ||
  8900. (((pSiS->VBFlags & VB_301C) && (SiS_Pr->CP_Clock[i] > 162500)) ||
  8901. ((!(pSiS->VBFlags & VB_301C)) &&
  8902. ((SiS_Pr->CP_Clock[i] > 108200) || (SiS_Pr->CP_VDisplay[i] > 1024)))) ||
  8903. (buffer[index + 17] & 0x80)) {
  8904. SiS_Pr->CP_DataValid[i] = FALSE;
  8905. } else {
  8906. SiS_Pr->CP_HaveCustomData = TRUE;
  8907. if(SiS_Pr->CP_Clock[i] > SiS_Pr->CP_MaxClock) SiS_Pr->CP_MaxClock = SiS_Pr->CP_Clock[i];
  8908. if((SiS_Pr->CP_PreferredX == xres) && (SiS_Pr->CP_PreferredY == yres)) {
  8909. SiS_Pr->CP_PreferredIndex = i;
  8910. SiS_MakeClockRegs(pSiS->pScrn, SiS_Pr->CP_Clock[i], &SiS_Pr->CP_PrefSR2B, &SiS_Pr->CP_PrefSR2C);
  8911. SiS_Pr->CP_PrefClock = (SiS_Pr->CP_Clock[i] / 1000) + 1;
  8912. if(!havesync) {
  8913. cr37 |= ((((buffer[index + 17] & 0x06) ^ 0x06) << 5) | 0x20);
  8914. havesync = TRUE;
  8915. }
  8916. }
  8917. SiS_Pr->CP_HSync_P[i] = (buffer[index + 17] & 0x02) ? TRUE : FALSE;
  8918. SiS_Pr->CP_VSync_P[i] = (buffer[index + 17] & 0x04) ? TRUE : FALSE;
  8919. SiS_Pr->CP_SyncValid[i] = TRUE;
  8920. }
  8921. }
  8922. cr37 |= 0x10;
  8923. }
  8924. break;
  8925. }
  8926. /* 1280x960 panels are always RGB24, unable to scale and use
  8927. * high active sync polarity
  8928. */
  8929. if(pSiS->VGAEngine == SIS_315_VGA) {
  8930. if(paneltype == Panel310_1280x960) cr37 &= 0x0e;
  8931. } else {
  8932. if(paneltype == Panel300_1280x960) cr37 &= 0x0e;
  8933. }
  8934. for(i = 0; i < 7; i++) {
  8935. if(SiS_Pr->CP_DataValid[i]) {
  8936. xf86DrvMsg(pSiS->pScrn->scrnIndex, X_PROBED,
  8937. "Non-standard LCD/DVI-D timing data no. %d:\n", i);
  8938. xf86DrvMsg(pSiS->pScrn->scrnIndex, X_PROBED,
  8939. " HDisplay %d HSync %d HSyncEnd %d HTotal %d\n",
  8940. SiS_Pr->CP_HDisplay[i], SiS_Pr->CP_HSyncStart[i],
  8941. SiS_Pr->CP_HSyncEnd[i], SiS_Pr->CP_HTotal[i]);
  8942. xf86DrvMsg(pSiS->pScrn->scrnIndex, X_PROBED,
  8943. " VDisplay %d VSync %d VSyncEnd %d VTotal %d\n",
  8944. SiS_Pr->CP_VDisplay[i], SiS_Pr->CP_VSyncStart[i],
  8945. SiS_Pr->CP_VSyncEnd[i], SiS_Pr->CP_VTotal[i]);
  8946. xf86DrvMsg(pSiS->pScrn->scrnIndex, X_PROBED,
  8947. " Pixel clock: %3.3fMhz\n", (float)SiS_Pr->CP_Clock[i] / 1000);
  8948. xf86DrvMsg(pSiS->pScrn->scrnIndex, X_INFO,
  8949. " To use this, add \"%dx%d\" to the list of Modes in the Screen section\n",
  8950. SiS_Pr->CP_HDisplay[i],
  8951. SiS_Pr->CP_VDisplay[i]);
  8952. }
  8953. }
  8954. if(paneltype) {
  8955. if(!SiS_Pr->CP_PreferredX) SiS_Pr->CP_PreferredX = SiS_Pr->CP_MaxX;
  8956. if(!SiS_Pr->CP_PreferredY) SiS_Pr->CP_PreferredY = SiS_Pr->CP_MaxY;
  8957. SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x32,0x08);
  8958. SiS_SetReg(SiS_Pr->SiS_P3d4,0x36,paneltype);
  8959. cr37 &= 0xf1;
  8960. SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x37,0x0c,cr37);
  8961. SiS_Pr->PanelSelfDetected = TRUE;
  8962. #ifdef TWDEBUG
  8963. xf86DrvMsgVerb(pSiS->pScrn->scrnIndex, X_PROBED, 3,
  8964. "LCD sense: [DDC LCD results: 0x%02x, 0x%02x]\n", paneltype, cr37);
  8965. #endif
  8966. } else {
  8967. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x32,~0x08);
  8968. SiS_SetReg(SiS_Pr->SiS_P3d4,0x36,0x00);
  8969. }
  8970. return 0;
  8971. }
  8972. USHORT
  8973. SiS_SenseVGA2DDC(SiS_Private *SiS_Pr, SISPtr pSiS)
  8974. {
  8975. USHORT DDCdatatype,flag;
  8976. BOOLEAN foundcrt = FALSE;
  8977. int retry;
  8978. unsigned char buffer[256];
  8979. if(!(pSiS->VBFlags & (VB_301|VB_301B|VB_301C|VB_302B))) return 0;
  8980. if(SiS_InitDDCRegs(SiS_Pr, pSiS->VBFlags, pSiS->VGAEngine, 2, 0, FALSE) == 0xFFFF) return 0;
  8981. SiS_Pr->SiS_DDC_SecAddr = 0x00;
  8982. /* Probe supported DA's */
  8983. flag = SiS_ProbeDDC(SiS_Pr);
  8984. if(flag & 0x10) {
  8985. SiS_Pr->SiS_DDC_DeviceAddr = 0xa6; /* EDID V2 (FP) */
  8986. DDCdatatype = 4;
  8987. } else if(flag & 0x08) {
  8988. SiS_Pr->SiS_DDC_DeviceAddr = 0xa2; /* EDID V2 (P&D-D Monitor) */
  8989. DDCdatatype = 3;
  8990. } else if(flag & 0x02) {
  8991. SiS_Pr->SiS_DDC_DeviceAddr = 0xa0; /* EDID V1 */
  8992. DDCdatatype = 1;
  8993. } else {
  8994. xf86DrvMsg(pSiS->pScrn->scrnIndex, X_PROBED,
  8995. "VGA2 sense: Do DDC answer\n");
  8996. return 0; /* no DDC support (or no device attached) */
  8997. }
  8998. /* Read the entire EDID */
  8999. retry = 2;
  9000. do {
  9001. if(SiS_ReadDDC(SiS_Pr, DDCdatatype, buffer)) {
  9002. xf86DrvMsg(pSiS->pScrn->scrnIndex, X_PROBED,
  9003. "VGA2 sense: DDC read failed (attempt %d), %s\n",
  9004. (3-retry), (retry == 1) ? "giving up" : "retrying");
  9005. retry--;
  9006. if(retry == 0) return 0xFFFF;
  9007. } else break;
  9008. } while(1);
  9009. /* Analyze EDID. We don't have many chances to
  9010. * distinguish a flat panel from a CRT...
  9011. */
  9012. switch(DDCdatatype) {
  9013. case 1:
  9014. if(!(checkedid1(buffer))) {
  9015. xf86DrvMsg(pSiS->pScrn->scrnIndex, X_ERROR,
  9016. "VGA2 sense: EDID corrupt\n");
  9017. return 0;
  9018. }
  9019. if(buffer[0x14] & 0x80) { /* Display uses digital input */
  9020. xf86DrvMsg(pSiS->pScrn->scrnIndex, X_ERROR,
  9021. "VGA2 sense: Attached display expects digital input\n");
  9022. return 0;
  9023. }
  9024. SiS_Pr->CP_Vendor = buffer[9] | (buffer[8] << 8);
  9025. SiS_Pr->CP_Product = buffer[10] | (buffer[11] << 8);
  9026. foundcrt = TRUE;
  9027. break;
  9028. case 3:
  9029. case 4:
  9030. if(!(checkedid2(buffer))) {
  9031. xf86DrvMsg(pSiS->pScrn->scrnIndex, X_ERROR,
  9032. "VGA2 sense: EDID corrupt\n");
  9033. return 0;
  9034. }
  9035. if( ((buffer[0x41] & 0x0f) != 0x01) && /* Display does not support analog input */
  9036. ((buffer[0x41] & 0x0f) != 0x02) &&
  9037. ((buffer[0x41] & 0xf0) != 0x10) &&
  9038. ((buffer[0x41] & 0xf0) != 0x20) ) {
  9039. xf86DrvMsg(pSiS->pScrn->scrnIndex, X_ERROR,
  9040. "VGA2 sense: Attached display does not support analog input (0x%02x)\n",
  9041. buffer[0x41]);
  9042. return 0;
  9043. }
  9044. SiS_Pr->CP_Vendor = buffer[2] | (buffer[1] << 8);
  9045. SiS_Pr->CP_Product = buffer[3] | (buffer[4] << 8);
  9046. foundcrt = TRUE;
  9047. break;
  9048. }
  9049. if(foundcrt) {
  9050. SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x32,0x10);
  9051. }
  9052. return(0);
  9053. }
  9054. #endif
  9055. void
  9056. SiS_SetCH70xxANDOR(SiS_Private *SiS_Pr, USHORT tempax,USHORT tempbh)
  9057. {
  9058. USHORT tempbl;
  9059. tempbl = SiS_GetCH70xx(SiS_Pr,(tempax & 0x00FF));
  9060. tempbl = (((tempbl & tempbh) << 8) | tempax);
  9061. SiS_SetCH70xx(SiS_Pr,tempbl);
  9062. }
  9063. /* Generic I2C functions for Chrontel & DDC --------- */
  9064. static void
  9065. SiS_SetSwitchDDC2(SiS_Private *SiS_Pr)
  9066. {
  9067. SiS_SetSCLKHigh(SiS_Pr);
  9068. SiS_WaitRetrace1(SiS_Pr);
  9069. SiS_SetSCLKLow(SiS_Pr);
  9070. SiS_WaitRetrace1(SiS_Pr);
  9071. }
  9072. USHORT
  9073. SiS_ReadDDC1Bit(SiS_Private *SiS_Pr)
  9074. {
  9075. SiS_WaitRetrace1(SiS_Pr);
  9076. return((SiS_GetReg(SiS_Pr->SiS_P3c4,0x11) & 0x02) >> 1);
  9077. }
  9078. /* Set I2C start condition */
  9079. /* This is done by a SD high-to-low transition while SC is high */
  9080. static USHORT
  9081. SiS_SetStart(SiS_Private *SiS_Pr)
  9082. {
  9083. if(SiS_SetSCLKLow(SiS_Pr)) return 0xFFFF; /* (SC->low) */
  9084. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  9085. SiS_Pr->SiS_DDC_Index,
  9086. SiS_Pr->SiS_DDC_NData,
  9087. SiS_Pr->SiS_DDC_Data); /* SD->high */
  9088. if(SiS_SetSCLKHigh(SiS_Pr)) return 0xFFFF; /* SC->high */
  9089. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  9090. SiS_Pr->SiS_DDC_Index,
  9091. SiS_Pr->SiS_DDC_NData,
  9092. 0x00); /* SD->low = start condition */
  9093. if(SiS_SetSCLKHigh(SiS_Pr)) return 0xFFFF; /* (SC->low) */
  9094. return 0;
  9095. }
  9096. /* Set I2C stop condition */
  9097. /* This is done by a SD low-to-high transition while SC is high */
  9098. static USHORT
  9099. SiS_SetStop(SiS_Private *SiS_Pr)
  9100. {
  9101. if(SiS_SetSCLKLow(SiS_Pr)) return 0xFFFF; /* (SC->low) */
  9102. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  9103. SiS_Pr->SiS_DDC_Index,
  9104. SiS_Pr->SiS_DDC_NData,
  9105. 0x00); /* SD->low */
  9106. if(SiS_SetSCLKHigh(SiS_Pr)) return 0xFFFF; /* SC->high */
  9107. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  9108. SiS_Pr->SiS_DDC_Index,
  9109. SiS_Pr->SiS_DDC_NData,
  9110. SiS_Pr->SiS_DDC_Data); /* SD->high = stop condition */
  9111. if(SiS_SetSCLKHigh(SiS_Pr)) return 0xFFFF; /* (SC->high) */
  9112. return 0;
  9113. }
  9114. /* Write 8 bits of data */
  9115. static USHORT
  9116. SiS_WriteDDC2Data(SiS_Private *SiS_Pr, USHORT tempax)
  9117. {
  9118. USHORT i,flag,temp;
  9119. flag = 0x80;
  9120. for(i=0; i<8; i++) {
  9121. SiS_SetSCLKLow(SiS_Pr); /* SC->low */
  9122. if(tempax & flag) {
  9123. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  9124. SiS_Pr->SiS_DDC_Index,
  9125. SiS_Pr->SiS_DDC_NData,
  9126. SiS_Pr->SiS_DDC_Data); /* Write bit (1) to SD */
  9127. } else {
  9128. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  9129. SiS_Pr->SiS_DDC_Index,
  9130. SiS_Pr->SiS_DDC_NData,
  9131. 0x00); /* Write bit (0) to SD */
  9132. }
  9133. SiS_SetSCLKHigh(SiS_Pr); /* SC->high */
  9134. flag >>= 1;
  9135. }
  9136. temp = SiS_CheckACK(SiS_Pr); /* Check acknowledge */
  9137. return(temp);
  9138. }
  9139. static USHORT
  9140. SiS_ReadDDC2Data(SiS_Private *SiS_Pr, USHORT tempax)
  9141. {
  9142. USHORT i,temp,getdata;
  9143. getdata=0;
  9144. for(i=0; i<8; i++) {
  9145. getdata <<= 1;
  9146. SiS_SetSCLKLow(SiS_Pr);
  9147. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  9148. SiS_Pr->SiS_DDC_Index,
  9149. SiS_Pr->SiS_DDC_NData,
  9150. SiS_Pr->SiS_DDC_Data);
  9151. SiS_SetSCLKHigh(SiS_Pr);
  9152. temp = SiS_GetReg(SiS_Pr->SiS_DDC_Port,SiS_Pr->SiS_DDC_Index);
  9153. if(temp & SiS_Pr->SiS_DDC_Data) getdata |= 0x01;
  9154. }
  9155. return(getdata);
  9156. }
  9157. static USHORT
  9158. SiS_SetSCLKLow(SiS_Private *SiS_Pr)
  9159. {
  9160. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  9161. SiS_Pr->SiS_DDC_Index,
  9162. SiS_Pr->SiS_DDC_NClk,
  9163. 0x00); /* SetSCLKLow() */
  9164. SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT);
  9165. return 0;
  9166. }
  9167. static USHORT
  9168. SiS_SetSCLKHigh(SiS_Private *SiS_Pr)
  9169. {
  9170. USHORT temp, watchdog=1000;
  9171. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  9172. SiS_Pr->SiS_DDC_Index,
  9173. SiS_Pr->SiS_DDC_NClk,
  9174. SiS_Pr->SiS_DDC_Clk); /* SetSCLKHigh() */
  9175. do {
  9176. temp = SiS_GetReg(SiS_Pr->SiS_DDC_Port,SiS_Pr->SiS_DDC_Index);
  9177. } while((!(temp & SiS_Pr->SiS_DDC_Clk)) && --watchdog);
  9178. if (!watchdog) {
  9179. #ifdef TWDEBUG
  9180. xf86DrvMsg(0, X_INFO, "SetClkHigh failed\n");
  9181. #endif
  9182. return 0xFFFF;
  9183. }
  9184. SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT);
  9185. return 0;
  9186. }
  9187. /* Check I2C acknowledge */
  9188. /* Returns 0 if ack ok, non-0 if ack not ok */
  9189. static USHORT
  9190. SiS_CheckACK(SiS_Private *SiS_Pr)
  9191. {
  9192. USHORT tempah;
  9193. SiS_SetSCLKLow(SiS_Pr); /* (SC->low) */
  9194. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  9195. SiS_Pr->SiS_DDC_Index,
  9196. SiS_Pr->SiS_DDC_NData,
  9197. SiS_Pr->SiS_DDC_Data); /* (SD->high) */
  9198. SiS_SetSCLKHigh(SiS_Pr); /* SC->high = clock impulse for ack */
  9199. tempah = SiS_GetReg(SiS_Pr->SiS_DDC_Port,SiS_Pr->SiS_DDC_Index); /* Read SD */
  9200. SiS_SetSCLKLow(SiS_Pr); /* SC->low = end of clock impulse */
  9201. if(tempah & SiS_Pr->SiS_DDC_Data) return(1); /* Ack OK if bit = 0 */
  9202. else return(0);
  9203. }
  9204. /* End of I2C functions ----------------------- */
  9205. /* =============== SiS 315/330 O.E.M. ================= */
  9206. #ifdef SIS315H
  9207. static USHORT
  9208. GetRAMDACromptr(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
  9209. {
  9210. UCHAR *ROMAddr = HwInfo->pjVirtualRomBase;
  9211. USHORT romptr;
  9212. if(HwInfo->jChipType < SIS_330) {
  9213. romptr = SISGETROMW(0x128);
  9214. if(SiS_Pr->SiS_VBType & VB_SIS301B302B)
  9215. romptr = SISGETROMW(0x12a);
  9216. } else {
  9217. romptr = SISGETROMW(0x1a8);
  9218. if(SiS_Pr->SiS_VBType & VB_SIS301B302B)
  9219. romptr = SISGETROMW(0x1aa);
  9220. }
  9221. return(romptr);
  9222. }
  9223. static USHORT
  9224. GetLCDromptr(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
  9225. {
  9226. UCHAR *ROMAddr = HwInfo->pjVirtualRomBase;
  9227. USHORT romptr;
  9228. if(HwInfo->jChipType < SIS_330) {
  9229. romptr = SISGETROMW(0x120);
  9230. if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV)
  9231. romptr = SISGETROMW(0x122);
  9232. } else {
  9233. romptr = SISGETROMW(0x1a0);
  9234. if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV)
  9235. romptr = SISGETROMW(0x1a2);
  9236. }
  9237. return(romptr);
  9238. }
  9239. static USHORT
  9240. GetTVromptr(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
  9241. {
  9242. UCHAR *ROMAddr = HwInfo->pjVirtualRomBase;
  9243. USHORT romptr;
  9244. if(HwInfo->jChipType < SIS_330) {
  9245. romptr = SISGETROMW(0x114);
  9246. if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV)
  9247. romptr = SISGETROMW(0x11a);
  9248. } else {
  9249. romptr = SISGETROMW(0x194);
  9250. if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV)
  9251. romptr = SISGETROMW(0x19a);
  9252. }
  9253. return(romptr);
  9254. }
  9255. static USHORT
  9256. GetLCDPtrIndexBIOS(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
  9257. {
  9258. USHORT index;
  9259. if((IS_SIS650) && (SiS_Pr->SiS_VBType & VB_SIS301LV302LV)) {
  9260. if(!(SiS_IsNotM650orLater(SiS_Pr, HwInfo))) {
  9261. if((index = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) & 0xf0)) {
  9262. index >>= 4;
  9263. index *= 3;
  9264. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) index += 2;
  9265. else if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) index++;
  9266. return index;
  9267. }
  9268. }
  9269. }
  9270. index = SiS_GetBIOSLCDResInfo(SiS_Pr) & 0x0F;
  9271. if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) index -= 5;
  9272. else if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) index -= 6;
  9273. index--;
  9274. index *= 3;
  9275. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) index += 2;
  9276. else if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) index++;
  9277. return index;
  9278. }
  9279. static USHORT
  9280. GetLCDPtrIndex(SiS_Private *SiS_Pr)
  9281. {
  9282. USHORT index;
  9283. index = ((SiS_GetBIOSLCDResInfo(SiS_Pr) & 0x0F) - 1) * 3;
  9284. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) index += 2;
  9285. else if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) index++;
  9286. return index;
  9287. }
  9288. static USHORT
  9289. GetTVPtrIndex(SiS_Private *SiS_Pr)
  9290. {
  9291. USHORT index;
  9292. index = 0;
  9293. if(SiS_Pr->SiS_TVMode & TVSetPAL) index = 1;
  9294. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) index = 2;
  9295. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) index = 0;
  9296. index <<= 1;
  9297. if((SiS_Pr->SiS_VBInfo & SetInSlaveMode) &&
  9298. (SiS_Pr->SiS_TVMode & TVSetTVSimuMode)) {
  9299. index++;
  9300. }
  9301. return index;
  9302. }
  9303. static ULONG
  9304. GetOEMTVPtr661_2_GEN(SiS_Private *SiS_Pr, int addme)
  9305. {
  9306. USHORT index = 0, temp = 0;
  9307. if(SiS_Pr->SiS_TVMode & TVSetPAL) index = 1;
  9308. if(SiS_Pr->SiS_TVMode & TVSetPALM) index = 2;
  9309. if(SiS_Pr->SiS_TVMode & TVSetPALN) index = 3;
  9310. if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) index = 6;
  9311. if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) {
  9312. index = 4;
  9313. if(SiS_Pr->SiS_TVMode & TVSetPALM) index++;
  9314. if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) index = 7;
  9315. }
  9316. if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
  9317. if((!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) ||
  9318. (SiS_Pr->SiS_TVMode & TVSetTVSimuMode)) {
  9319. index += addme;
  9320. temp++;
  9321. }
  9322. temp += 0x0100;
  9323. }
  9324. return(ULONG)(index | (temp << 16));
  9325. }
  9326. static ULONG
  9327. GetOEMTVPtr661_2_OLD(SiS_Private *SiS_Pr)
  9328. {
  9329. return(GetOEMTVPtr661_2_GEN(SiS_Pr, 8));
  9330. }
  9331. #if 0
  9332. static ULONG
  9333. GetOEMTVPtr661_2_NEW(SiS_Private *SiS_Pr)
  9334. {
  9335. return(GetOEMTVPtr661_2_GEN(SiS_Pr, 6));
  9336. }
  9337. #endif
  9338. static int
  9339. GetOEMTVPtr661(SiS_Private *SiS_Pr)
  9340. {
  9341. int index = 0;
  9342. if(SiS_Pr->SiS_TVMode & TVSetPAL) index = 2;
  9343. if(SiS_Pr->SiS_ROMNew) {
  9344. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525i) index = 4;
  9345. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) index = 6;
  9346. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) index = 8;
  9347. if(SiS_Pr->SiS_TVMode & TVSetHiVision) index = 10;
  9348. } else {
  9349. if(SiS_Pr->SiS_TVMode & TVSetHiVision) index = 4;
  9350. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525i) index = 6;
  9351. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) index = 8;
  9352. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) index = 10;
  9353. }
  9354. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) index++;
  9355. return index;
  9356. }
  9357. static void
  9358. SetDelayComp(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo)
  9359. {
  9360. UCHAR *ROMAddr = HwInfo->pjVirtualRomBase;
  9361. USHORT delay=0,index,myindex,temp,romptr=0;
  9362. BOOLEAN dochiptest = TRUE;
  9363. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  9364. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x20,0xbf);
  9365. } else {
  9366. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x35,0x7f);
  9367. }
  9368. /* Find delay (from ROM, internal tables, PCI subsystem) */
  9369. if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) { /* ------------ VGA */
  9370. if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
  9371. romptr = GetRAMDACromptr(SiS_Pr, HwInfo);
  9372. }
  9373. if(romptr) delay = ROMAddr[romptr];
  9374. else {
  9375. delay = 0x04;
  9376. if(SiS_Pr->SiS_VBType & VB_SIS301B302B) {
  9377. if(IS_SIS650) {
  9378. delay = 0x0a;
  9379. } else if(IS_SIS740) {
  9380. delay = 0x00;
  9381. } else if(HwInfo->jChipType < SIS_330) {
  9382. delay = 0x0c;
  9383. } else {
  9384. delay = 0x0c;
  9385. }
  9386. } else if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  9387. delay = 0x00;
  9388. }
  9389. }
  9390. } else if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD|SetCRT2ToLCDA)) { /* ---------- LCD/LCDA */
  9391. BOOLEAN gotitfrompci = FALSE;
  9392. /* Could we detect a PDC for LCD or did we get a user-defined? If yes, use it */
  9393. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  9394. if(SiS_Pr->PDC != -1) {
  9395. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0xf0,((SiS_Pr->PDC >> 1) & 0x0f));
  9396. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x35,0x7f,((SiS_Pr->PDC & 0x01) << 7));
  9397. return;
  9398. }
  9399. } else {
  9400. if(SiS_Pr->PDCA != -1) {
  9401. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0x0f,((SiS_Pr->PDCA << 3) & 0xf0));
  9402. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x20,0xbf,((SiS_Pr->PDCA & 0x01) << 6));
  9403. return;
  9404. }
  9405. }
  9406. /* Custom Panel? */
  9407. if(SiS_Pr->SiS_LCDResInfo == Panel_Custom) {
  9408. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  9409. delay = 0x00;
  9410. if((SiS_Pr->PanelXRes <= 1280) && (SiS_Pr->PanelYRes <= 1024)) {
  9411. delay = 0x20;
  9412. }
  9413. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0x0f,delay);
  9414. } else {
  9415. delay = 0x0c;
  9416. if(SiS_Pr->SiS_VBType & VB_SIS301C) delay = 0x03;
  9417. else if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {
  9418. if(IS_SIS740) delay = 0x01;
  9419. else delay = 0x03;
  9420. }
  9421. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0xf0,delay);
  9422. }
  9423. return;
  9424. }
  9425. /* This is a piece of typical SiS crap: They code the OEM LCD
  9426. * delay into the code, at no defined place in the BIOS.
  9427. * We now have to start doing a PCI subsystem check here.
  9428. */
  9429. switch(SiS_Pr->SiS_CustomT) {
  9430. case CUT_COMPAQ1280:
  9431. case CUT_COMPAQ12802:
  9432. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) {
  9433. gotitfrompci = TRUE;
  9434. dochiptest = FALSE;
  9435. delay = 0x03;
  9436. }
  9437. break;
  9438. case CUT_CLEVO1400:
  9439. case CUT_CLEVO14002:
  9440. gotitfrompci = TRUE;
  9441. dochiptest = FALSE;
  9442. delay = 0x02;
  9443. break;
  9444. case CUT_CLEVO1024:
  9445. case CUT_CLEVO10242:
  9446. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  9447. gotitfrompci = TRUE;
  9448. dochiptest = FALSE;
  9449. delay = 0x33;
  9450. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2D,delay);
  9451. delay &= 0x0f;
  9452. }
  9453. break;
  9454. }
  9455. /* Could we find it through the PCI ID? If no, use ROM or table */
  9456. if(!gotitfrompci) {
  9457. index = GetLCDPtrIndexBIOS(SiS_Pr, HwInfo);
  9458. myindex = GetLCDPtrIndex(SiS_Pr);
  9459. if(IS_SIS650 && (SiS_Pr->SiS_VBType & VB_SIS301LV302LV)) {
  9460. if(SiS_IsNotM650orLater(SiS_Pr, HwInfo)) {
  9461. if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
  9462. /* Always use the second pointer on 650; some BIOSes */
  9463. /* still carry old 301 data at the first location */
  9464. /* romptr = SISGETROMW(0x120); */
  9465. /* if(SiS_Pr->SiS_VBType & VB_SIS302LV) */
  9466. romptr = SISGETROMW(0x122);
  9467. if(!romptr) return;
  9468. delay = ROMAddr[(romptr + index)];
  9469. } else {
  9470. delay = SiS310_LCDDelayCompensation_650301LV[myindex];
  9471. }
  9472. } else {
  9473. delay = SiS310_LCDDelayCompensation_651301LV[myindex];
  9474. if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV))
  9475. delay = SiS310_LCDDelayCompensation_651302LV[myindex];
  9476. }
  9477. } else if(SiS_Pr->SiS_UseROM &&
  9478. (!(SiS_Pr->SiS_ROMNew)) &&
  9479. (SiS_Pr->SiS_LCDResInfo != Panel_1280x1024) &&
  9480. (SiS_Pr->SiS_LCDResInfo != Panel_1280x768) &&
  9481. (SiS_Pr->SiS_LCDResInfo != Panel_1280x960)) {
  9482. /* Data for 1280x1024 wrong in 301B BIOS */
  9483. romptr = GetLCDromptr(SiS_Pr, HwInfo);
  9484. if(!romptr) return;
  9485. delay = ROMAddr[(romptr + index)];
  9486. } else if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  9487. if(IS_SIS740) delay = 0x03;
  9488. else delay = 0x00;
  9489. } else {
  9490. delay = SiS310_LCDDelayCompensation_301[myindex];
  9491. if(SiS_Pr->SiS_VBType & VB_SIS301LV302LV) {
  9492. if(IS_SIS740) delay = 0x01;
  9493. else if(HwInfo->jChipType <= SIS_315PRO) delay = SiS310_LCDDelayCompensation_3xx301LV[myindex];
  9494. else delay = SiS310_LCDDelayCompensation_650301LV[myindex];
  9495. } else if(SiS_Pr->SiS_VBType & VB_SIS301C) {
  9496. if(IS_SIS740) delay = 0x01; /* ? */
  9497. else delay = 0x03;
  9498. } else if(SiS_Pr->SiS_VBType & VB_SIS301B302B) {
  9499. if(IS_SIS740) delay = 0x01;
  9500. else delay = SiS310_LCDDelayCompensation_3xx301B[myindex];
  9501. }
  9502. }
  9503. } /* got it from PCI */
  9504. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  9505. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,0x0F,((delay << 4) & 0xf0));
  9506. dochiptest = FALSE;
  9507. }
  9508. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { /* ------------ TV */
  9509. index = GetTVPtrIndex(SiS_Pr);
  9510. if(IS_SIS650 && (SiS_Pr->SiS_VBType & VB_SIS301LV302LV)) {
  9511. if(SiS_IsNotM650orLater(SiS_Pr,HwInfo)) {
  9512. if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
  9513. /* Always use the second pointer on 650; some BIOSes */
  9514. /* still carry old 301 data at the first location */
  9515. /* romptr = SISGETROMW(0x114); */
  9516. /* if(SiS_Pr->SiS_VBType & VB_SIS302LV) */
  9517. romptr = SISGETROMW(0x11a);
  9518. if(!romptr) return;
  9519. delay = ROMAddr[romptr + index];
  9520. } else {
  9521. delay = SiS310_TVDelayCompensation_301B[index];
  9522. }
  9523. } else {
  9524. switch(SiS_Pr->SiS_CustomT) {
  9525. case CUT_COMPAQ1280:
  9526. case CUT_COMPAQ12802:
  9527. case CUT_CLEVO1400:
  9528. case CUT_CLEVO14002:
  9529. delay = 0x02;
  9530. dochiptest = FALSE;
  9531. break;
  9532. case CUT_CLEVO1024:
  9533. case CUT_CLEVO10242:
  9534. delay = 0x03;
  9535. dochiptest = FALSE;
  9536. break;
  9537. default:
  9538. delay = SiS310_TVDelayCompensation_651301LV[index];
  9539. if(SiS_Pr->SiS_VBType & VB_SIS302LV) {
  9540. delay = SiS310_TVDelayCompensation_651302LV[index];
  9541. }
  9542. }
  9543. }
  9544. } else if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
  9545. romptr = GetTVromptr(SiS_Pr, HwInfo);
  9546. if(!romptr) return;
  9547. delay = ROMAddr[romptr + index];
  9548. } else if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  9549. delay = SiS310_TVDelayCompensation_LVDS[index];
  9550. } else {
  9551. delay = SiS310_TVDelayCompensation_301[index];
  9552. if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
  9553. if(IS_SIS740) {
  9554. delay = SiS310_TVDelayCompensation_740301B[index];
  9555. /* LV: use 301 data? BIOS bug? */
  9556. } else {
  9557. delay = SiS310_TVDelayCompensation_301B[index];
  9558. if(SiS_Pr->SiS_VBType & VB_SIS301C) delay = 0x02;
  9559. }
  9560. }
  9561. }
  9562. if(SiS_LCDAEnabled(SiS_Pr, HwInfo)) {
  9563. delay &= 0x0f;
  9564. dochiptest = FALSE;
  9565. }
  9566. } else return;
  9567. /* Write delay */
  9568. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  9569. if(IS_SIS650 && (SiS_Pr->SiS_VBType & VB_SIS301LV302LV) && dochiptest) {
  9570. temp = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) & 0xf0) >> 4;
  9571. if(temp == 8) { /* 1400x1050 BIOS (COMPAL) */
  9572. delay &= 0x0f;
  9573. delay |= 0xb0;
  9574. } else if(temp == 6) {
  9575. delay &= 0x0f;
  9576. delay |= 0xc0;
  9577. } else if(temp > 7) { /* 1280x1024 BIOS (which one?) */
  9578. delay = 0x35;
  9579. }
  9580. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2D,delay);
  9581. } else {
  9582. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,0xF0,delay);
  9583. }
  9584. } else { /* LVDS */
  9585. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  9586. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,0xF0,delay);
  9587. } else {
  9588. if(IS_SIS650 && (SiS_Pr->SiS_IF_DEF_CH70xx != 0)) {
  9589. delay <<= 4;
  9590. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,0x0F,delay);
  9591. } else {
  9592. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,0xF0,delay);
  9593. }
  9594. }
  9595. }
  9596. }
  9597. static void
  9598. SetAntiFlicker(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
  9599. USHORT ModeNo,USHORT ModeIdIndex)
  9600. {
  9601. UCHAR *ROMAddr = HwInfo->pjVirtualRomBase;
  9602. USHORT index,temp,temp1,romptr=0;
  9603. if(SiS_Pr->SiS_TVMode & (TVSetYPbPr750p|TVSetYPbPr525p)) return;
  9604. if(ModeNo<=0x13)
  9605. index = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].VB_StTVFlickerIndex;
  9606. else
  9607. index = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].VB_ExtTVFlickerIndex;
  9608. temp = GetTVPtrIndex(SiS_Pr);
  9609. temp >>= 1; /* 0: NTSC/YPbPr, 1: PAL, 2: HiTV */
  9610. temp1 = temp;
  9611. if(SiS_Pr->SiS_UseROM && (!(SiS_Pr->SiS_ROMNew))) {
  9612. if(HwInfo->jChipType >= SIS_661) {
  9613. temp1 = GetOEMTVPtr661(SiS_Pr);
  9614. temp1 >>= 1;
  9615. romptr = SISGETROMW(0x260);
  9616. if(HwInfo->jChipType >= SIS_760) {
  9617. romptr = SISGETROMW(0x360);
  9618. }
  9619. } else if(HwInfo->jChipType >= SIS_330) {
  9620. romptr = SISGETROMW(0x192);
  9621. } else {
  9622. romptr = SISGETROMW(0x112);
  9623. }
  9624. }
  9625. if(romptr) {
  9626. temp1 <<= 1;
  9627. temp = ROMAddr[romptr + temp1 + index];
  9628. } else {
  9629. temp = SiS310_TVAntiFlick1[temp][index];
  9630. }
  9631. temp <<= 4;
  9632. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x0A,0x8f,temp); /* index 0A D[6:4] */
  9633. }
  9634. static void
  9635. SetEdgeEnhance(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
  9636. USHORT ModeNo,USHORT ModeIdIndex)
  9637. {
  9638. UCHAR *ROMAddr = HwInfo->pjVirtualRomBase;
  9639. USHORT index,temp,temp1,romptr=0;
  9640. temp = temp1 = GetTVPtrIndex(SiS_Pr) >> 1; /* 0: NTSC/YPbPr, 1: PAL, 2: HiTV */
  9641. if(ModeNo <= 0x13)
  9642. index = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].VB_StTVEdgeIndex;
  9643. else
  9644. index = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].VB_ExtTVEdgeIndex;
  9645. if(SiS_Pr->SiS_UseROM && (!(SiS_Pr->SiS_ROMNew))) {
  9646. if(HwInfo->jChipType >= SIS_661) {
  9647. romptr = SISGETROMW(0x26c);
  9648. if(HwInfo->jChipType >= SIS_760) {
  9649. romptr = SISGETROMW(0x36c);
  9650. }
  9651. temp1 = GetOEMTVPtr661(SiS_Pr);
  9652. temp1 >>= 1;
  9653. } else if(HwInfo->jChipType >= SIS_330) {
  9654. romptr = SISGETROMW(0x1a4);
  9655. } else {
  9656. romptr = SISGETROMW(0x124);
  9657. }
  9658. }
  9659. if(romptr) {
  9660. temp1 <<= 1;
  9661. temp = ROMAddr[romptr + temp1 + index];
  9662. } else {
  9663. temp = SiS310_TVEdge1[temp][index];
  9664. }
  9665. temp <<= 5;
  9666. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x3A,0x1F,temp); /* index 0A D[7:5] */
  9667. }
  9668. static void
  9669. SetYFilter(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
  9670. USHORT ModeNo,USHORT ModeIdIndex)
  9671. {
  9672. USHORT index, temp, i, j;
  9673. if(ModeNo <= 0x13) {
  9674. index = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].VB_StTVYFilterIndex;
  9675. } else {
  9676. index = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].VB_ExtTVYFilterIndex;
  9677. }
  9678. temp = GetTVPtrIndex(SiS_Pr) >> 1; /* 0: NTSC/YPbPr, 1: PAL, 2: HiTV */
  9679. if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) temp = 1; /* NTSC-J uses PAL */
  9680. else if(SiS_Pr->SiS_TVMode & TVSetPALM) temp = 3; /* PAL-M */
  9681. else if(SiS_Pr->SiS_TVMode & TVSetPALN) temp = 4; /* PAL-N */
  9682. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) temp = 1; /* HiVision uses PAL */
  9683. if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
  9684. for(i=0x35, j=0; i<=0x38; i++, j++) {
  9685. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVYFilter2[temp][index][j]);
  9686. }
  9687. for(i=0x48; i<=0x4A; i++, j++) {
  9688. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVYFilter2[temp][index][j]);
  9689. }
  9690. } else {
  9691. for(i=0x35, j=0; i<=0x38; i++, j++) {
  9692. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVYFilter1[temp][index][j]);
  9693. }
  9694. }
  9695. }
  9696. static void
  9697. SetPhaseIncr(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
  9698. USHORT ModeNo,USHORT ModeIdIndex)
  9699. {
  9700. UCHAR *ROMAddr = HwInfo->pjVirtualRomBase;
  9701. USHORT index,temp,i,j,resinfo,romptr=0;
  9702. ULONG lindex;
  9703. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) return;
  9704. /* NTSC-J data not in BIOS, and already set in SetGroup2 */
  9705. if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) return;
  9706. if((HwInfo->jChipType >= SIS_661) || SiS_Pr->SiS_ROMNew) {
  9707. lindex = GetOEMTVPtr661_2_OLD(SiS_Pr) & 0xffff;
  9708. lindex <<= 2;
  9709. for(j=0, i=0x31; i<=0x34; i++, j++) {
  9710. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS661_TVPhase[lindex + j]);
  9711. }
  9712. return;
  9713. }
  9714. /* PAL-M, PAL-N not in BIOS, and already set in SetGroup2 */
  9715. if(SiS_Pr->SiS_TVMode & (TVSetPALM | TVSetPALN)) return;
  9716. if(ModeNo<=0x13) {
  9717. resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
  9718. } else {
  9719. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  9720. }
  9721. temp = GetTVPtrIndex(SiS_Pr);
  9722. /* 0: NTSC Graphics, 1: NTSC Text, 2: PAL Graphics,
  9723. * 3: PAL Text, 4: HiTV Graphics 5: HiTV Text
  9724. */
  9725. if(SiS_Pr->SiS_UseROM) {
  9726. romptr = SISGETROMW(0x116);
  9727. if(HwInfo->jChipType >= SIS_330) {
  9728. romptr = SISGETROMW(0x196);
  9729. }
  9730. if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
  9731. romptr = SISGETROMW(0x11c);
  9732. if(HwInfo->jChipType >= SIS_330) {
  9733. romptr = SISGETROMW(0x19c);
  9734. }
  9735. if((SiS_Pr->SiS_VBInfo & SetInSlaveMode) && (!(SiS_Pr->SiS_TVMode & TVSetTVSimuMode))) {
  9736. romptr = SISGETROMW(0x116);
  9737. if(HwInfo->jChipType >= SIS_330) {
  9738. romptr = SISGETROMW(0x196);
  9739. }
  9740. }
  9741. }
  9742. }
  9743. if(romptr) {
  9744. romptr += (temp << 2);
  9745. for(j=0, i=0x31; i<=0x34; i++, j++) {
  9746. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,ROMAddr[romptr + j]);
  9747. }
  9748. } else {
  9749. index = temp % 2;
  9750. temp >>= 1; /* 0:NTSC, 1:PAL, 2:HiTV */
  9751. for(j=0, i=0x31; i<=0x34; i++, j++) {
  9752. if(!(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV))
  9753. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVPhaseIncr1[temp][index][j]);
  9754. else if((!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) || (SiS_Pr->SiS_TVMode & TVSetTVSimuMode))
  9755. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVPhaseIncr2[temp][index][j]);
  9756. else
  9757. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVPhaseIncr1[temp][index][j]);
  9758. }
  9759. }
  9760. if((SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) && (!(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision))) {
  9761. if((!(SiS_Pr->SiS_TVMode & (TVSetPAL | TVSetYPbPr525p | TVSetYPbPr750p))) && (ModeNo > 0x13)) {
  9762. if((resinfo == SIS_RI_640x480) ||
  9763. (resinfo == SIS_RI_800x600)) {
  9764. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x31,0x21);
  9765. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x32,0xf0);
  9766. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x33,0xf5);
  9767. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x34,0x7f);
  9768. } else if(resinfo == SIS_RI_1024x768) {
  9769. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x31,0x1e);
  9770. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x32,0x8b);
  9771. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x33,0xfb);
  9772. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x34,0x7b);
  9773. }
  9774. }
  9775. }
  9776. }
  9777. static void
  9778. SetDelayComp661(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo,
  9779. USHORT ModeIdIndex, USHORT RTI)
  9780. {
  9781. USHORT delay = 0, romptr = 0, index, lcdpdcindex;
  9782. UCHAR *ROMAddr = HwInfo->pjVirtualRomBase;
  9783. if(!(SiS_Pr->SiS_VBInfo & (SetCRT2ToTV | SetCRT2ToLCD | SetCRT2ToLCDA | SetCRT2ToRAMDAC)))
  9784. return;
  9785. /* 1. New ROM: VGA2 and LCD/LCDA-Pass1:1 */
  9786. /* (If a custom mode is used, Pass1:1 is always set; hence we do this:) */
  9787. if(SiS_Pr->SiS_ROMNew) {
  9788. if((SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) ||
  9789. ((SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) &&
  9790. (SiS_Pr->SiS_LCDInfo & LCDPass11))) {
  9791. index = 25;
  9792. if(SiS_Pr->UseCustomMode) {
  9793. index = SiS_Pr->CSRClock;
  9794. } else if(ModeNo > 0x13) {
  9795. index = SiS_GetVCLK2Ptr(SiS_Pr,ModeNo,ModeIdIndex,RTI,HwInfo);
  9796. index = SiS_Pr->SiS_VCLKData[index].CLOCK;
  9797. }
  9798. if(index < 25) index = 25;
  9799. index = ((index / 25) - 1) << 1;
  9800. if((ROMAddr[0x5b] & 0x80) || (SiS_Pr->SiS_VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD))) {
  9801. index++;
  9802. }
  9803. romptr = SISGETROMW(0x104);
  9804. delay = ROMAddr[romptr + index];
  9805. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD)) {
  9806. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0xf0,((delay >> 1) & 0x0f));
  9807. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x35,0x7f,((delay & 0x01) << 7));
  9808. } else {
  9809. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0x0f,((delay << 3) & 0xf0));
  9810. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x20,0xbf,((delay & 0x01) << 6));
  9811. }
  9812. return;
  9813. }
  9814. }
  9815. /* 2. Old ROM: VGA2 and LCD/LCDA-Pass 1:1 */
  9816. if(SiS_Pr->UseCustomMode) delay = 0x04;
  9817. else if(ModeNo <= 0x13) delay = 0x04;
  9818. else delay = (SiS_Pr->SiS_RefIndex[RTI].Ext_PDC >> 4);
  9819. delay |= (delay << 8);
  9820. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  9821. /* 3. TV */
  9822. index = GetOEMTVPtr661(SiS_Pr);
  9823. if(SiS_Pr->SiS_ROMNew) {
  9824. romptr = SISGETROMW(0x106);
  9825. if(SiS_Pr->SiS_VBType & VB_UMC) romptr += 12;
  9826. delay = ROMAddr[romptr + index];
  9827. } else {
  9828. delay = 0x04;
  9829. if(index > 3) delay = 0;
  9830. }
  9831. } else if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  9832. /* 4. LCD, LCDA (for new ROM only LV and non-Pass 1:1) */
  9833. if( (SiS_Pr->SiS_LCDResInfo != Panel_Custom) &&
  9834. ((romptr = GetLCDStructPtr661_2(SiS_Pr, HwInfo))) ) {
  9835. lcdpdcindex = (SiS_Pr->SiS_VBType & VB_UMC) ? 14 : 12;
  9836. /* For LVDS (and sometimes TMDS), the BIOS must know about the correct value */
  9837. delay = ROMAddr[romptr + lcdpdcindex + 1]; /* LCD */
  9838. delay |= (ROMAddr[romptr + lcdpdcindex] << 8); /* LCDA */
  9839. } else {
  9840. /* TMDS: Set our own, since BIOS has no idea */
  9841. /* (This is done on >=661 only, since <661 is calling this only for LVDS) */
  9842. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  9843. switch(SiS_Pr->SiS_LCDResInfo) {
  9844. case Panel_1024x768: delay = 0x0008; break;
  9845. case Panel_1280x720: delay = 0x0004; break;
  9846. case Panel_1280x768:
  9847. case Panel_1280x768_2:delay = 0x0004; break;
  9848. case Panel_1280x800:
  9849. case Panel_1280x800_2:delay = 0x0004; break; /* Verified for 1280x800 */
  9850. case Panel_1280x1024: delay = 0x1e04; break;
  9851. case Panel_1400x1050: delay = 0x0004; break;
  9852. case Panel_1600x1200: delay = 0x0400; break;
  9853. case Panel_1680x1050: delay = 0x0e04; break;
  9854. default:
  9855. if((SiS_Pr->PanelXRes <= 1024) && (SiS_Pr->PanelYRes <= 768)) {
  9856. delay = 0x0008;
  9857. } else if((SiS_Pr->PanelXRes == 1280) && (SiS_Pr->PanelYRes == 1024)) {
  9858. delay = 0x1e04;
  9859. } else if((SiS_Pr->PanelXRes <= 1400) && (SiS_Pr->PanelYRes <= 1050)) {
  9860. delay = 0x0004;
  9861. } else if((SiS_Pr->PanelXRes <= 1600) && (SiS_Pr->PanelYRes <= 1200)) {
  9862. delay = 0x0400;
  9863. } else
  9864. delay = 0x0e04;
  9865. break;
  9866. }
  9867. }
  9868. /* Override by detected or user-set values */
  9869. /* (but only if, for some reason, we can't read value from BIOS) */
  9870. if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && (SiS_Pr->PDC != -1)) {
  9871. delay = SiS_Pr->PDC & 0x1f;
  9872. }
  9873. if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) && (SiS_Pr->PDCA != -1)) {
  9874. delay = (SiS_Pr->PDCA & 0x1f) << 8;
  9875. }
  9876. }
  9877. }
  9878. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  9879. delay >>= 8;
  9880. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0x0f,((delay << 3) & 0xf0));
  9881. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x20,0xbf,((delay & 0x01) << 6));
  9882. } else {
  9883. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0xf0,((delay >> 1) & 0x0f));
  9884. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x35,0x7f,((delay & 0x01) << 7));
  9885. }
  9886. }
  9887. static void
  9888. SetCRT2SyncDither661(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT ModeNo, USHORT RTI)
  9889. {
  9890. USHORT infoflag;
  9891. UCHAR temp;
  9892. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  9893. if(ModeNo <= 0x13) {
  9894. infoflag = SiS_GetRegByte(SiS_Pr->SiS_P3ca+2);
  9895. } else if(SiS_Pr->UseCustomMode) {
  9896. infoflag = SiS_Pr->CInfoFlag;
  9897. } else {
  9898. infoflag = SiS_Pr->SiS_RefIndex[RTI].Ext_InfoFlag;
  9899. }
  9900. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  9901. infoflag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x37); /* No longer check D5 */
  9902. }
  9903. infoflag &= 0xc0;
  9904. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  9905. temp = (infoflag >> 6) | 0x0c;
  9906. if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) {
  9907. temp ^= 0x04;
  9908. if(SiS_Pr->SiS_ModeType >= Mode24Bpp) temp |= 0x10;
  9909. }
  9910. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1a,0xe0,temp);
  9911. } else {
  9912. temp = 0x30;
  9913. if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) temp = 0x20;
  9914. temp |= infoflag;
  9915. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0f,temp);
  9916. temp = 0;
  9917. if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) {
  9918. if(SiS_Pr->SiS_ModeType >= Mode24Bpp) temp |= 0x80;
  9919. }
  9920. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x1a,0x7f,temp);
  9921. }
  9922. }
  9923. }
  9924. static void
  9925. SetPanelParms661(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
  9926. {
  9927. UCHAR *ROMAddr = HwInfo->pjVirtualRomBase;
  9928. USHORT romptr, temp1, temp2;
  9929. if(SiS_Pr->SiS_VBType & (VB_SIS301LV | VB_SIS302LV | VB_SIS302ELV)) {
  9930. if(SiS_Pr->LVDSHL != -1) {
  9931. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,0xfc,SiS_Pr->LVDSHL);
  9932. }
  9933. }
  9934. if(SiS_Pr->SiS_ROMNew) {
  9935. if((romptr = GetLCDStructPtr661_2(SiS_Pr, HwInfo))) {
  9936. if(SiS_Pr->SiS_VBType & (VB_SIS301LV | VB_SIS302LV | VB_SIS302ELV)) {
  9937. temp1 = (ROMAddr[romptr] & 0x03) | 0x0c;
  9938. temp2 = 0xfc;
  9939. if(SiS_Pr->LVDSHL != -1) {
  9940. temp1 &= 0xfc;
  9941. temp2 = 0xf3;
  9942. }
  9943. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,temp2,temp1);
  9944. }
  9945. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  9946. temp1 = (ROMAddr[romptr + 1] & 0x80) >> 1;
  9947. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x0d,0xbf,temp1);
  9948. }
  9949. }
  9950. }
  9951. }
  9952. static void
  9953. SiS_OEM310Setting(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
  9954. USHORT ModeNo,USHORT ModeIdIndex,USHORT RRTI)
  9955. {
  9956. if((SiS_Pr->SiS_ROMNew) && (SiS_Pr->SiS_VBType & VB_SISLVDS)) {
  9957. SetDelayComp661(SiS_Pr,HwInfo,ModeNo,ModeIdIndex,RRTI);
  9958. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  9959. SetCRT2SyncDither661(SiS_Pr,HwInfo,ModeNo,RRTI);
  9960. SetPanelParms661(SiS_Pr,HwInfo);
  9961. }
  9962. } else {
  9963. SetDelayComp(SiS_Pr,HwInfo,ModeNo);
  9964. }
  9965. if((SiS_Pr->SiS_VBType & VB_SISVB) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
  9966. SetAntiFlicker(SiS_Pr,HwInfo,ModeNo,ModeIdIndex);
  9967. SetPhaseIncr(SiS_Pr,HwInfo,ModeNo,ModeIdIndex);
  9968. SetYFilter(SiS_Pr,HwInfo,ModeNo,ModeIdIndex);
  9969. if(SiS_Pr->SiS_VBType & VB_SIS301) {
  9970. SetEdgeEnhance(SiS_Pr,HwInfo,ModeNo,ModeIdIndex);
  9971. }
  9972. }
  9973. }
  9974. static void
  9975. SiS_OEM661Setting(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
  9976. USHORT ModeNo,USHORT ModeIdIndex, USHORT RRTI)
  9977. {
  9978. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  9979. SetDelayComp661(SiS_Pr,HwInfo,ModeNo,ModeIdIndex,RRTI);
  9980. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  9981. SetCRT2SyncDither661(SiS_Pr,HwInfo,ModeNo,RRTI);
  9982. SetPanelParms661(SiS_Pr,HwInfo);
  9983. }
  9984. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  9985. SetPhaseIncr(SiS_Pr,HwInfo,ModeNo,ModeIdIndex);
  9986. SetYFilter(SiS_Pr,HwInfo,ModeNo,ModeIdIndex);
  9987. SetAntiFlicker(SiS_Pr,HwInfo,ModeNo,ModeIdIndex);
  9988. if(SiS_Pr->SiS_VBType & VB_SIS301) {
  9989. SetEdgeEnhance(SiS_Pr,HwInfo,ModeNo,ModeIdIndex);
  9990. }
  9991. }
  9992. }
  9993. }
  9994. /* FinalizeLCD
  9995. * This finalizes some CRT2 registers for the very panel used.
  9996. * If we have a backup if these registers, we use it; otherwise
  9997. * we set the register according to most BIOSes. However, this
  9998. * function looks quite different in every BIOS, so you better
  9999. * pray that we have a backup...
  10000. */
  10001. static void
  10002. SiS_FinalizeLCD(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
  10003. PSIS_HW_INFO HwInfo)
  10004. {
  10005. USHORT tempcl,tempch,tempbl,tempbh,tempbx,tempax,temp;
  10006. USHORT resinfo,modeflag;
  10007. if(!(SiS_Pr->SiS_VBType & VB_SIS301LV302LV)) return;
  10008. if(SiS_Pr->SiS_ROMNew) return;
  10009. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  10010. if(SiS_Pr->LVDSHL != -1) {
  10011. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,0xfc,SiS_Pr->LVDSHL);
  10012. }
  10013. }
  10014. if(SiS_Pr->SiS_LCDResInfo == Panel_Custom) return;
  10015. if(SiS_Pr->UseCustomMode) return;
  10016. switch(SiS_Pr->SiS_CustomT) {
  10017. case CUT_COMPAQ1280:
  10018. case CUT_COMPAQ12802:
  10019. case CUT_CLEVO1400:
  10020. case CUT_CLEVO14002:
  10021. return;
  10022. }
  10023. if(ModeNo <= 0x13) {
  10024. resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
  10025. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  10026. } else {
  10027. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  10028. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  10029. }
  10030. if(IS_SIS650) {
  10031. if(!(SiS_GetReg(SiS_Pr->SiS_P3d4, 0x5f) & 0xf0)) {
  10032. if(SiS_Pr->SiS_CustomT == CUT_CLEVO1024) {
  10033. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1e,0x02);
  10034. } else {
  10035. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1e,0x03);
  10036. }
  10037. }
  10038. }
  10039. if(SiS_Pr->SiS_CustomT == CUT_CLEVO1024) {
  10040. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  10041. /* Maybe all panels? */
  10042. if(SiS_Pr->LVDSHL == -1) {
  10043. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,0xfc,0x01);
  10044. }
  10045. return;
  10046. }
  10047. }
  10048. if(SiS_Pr->SiS_CustomT == CUT_CLEVO10242) {
  10049. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  10050. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  10051. if(SiS_Pr->LVDSHL == -1) {
  10052. /* Maybe all panels? */
  10053. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,0xfc,0x01);
  10054. }
  10055. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  10056. tempch = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4;
  10057. if(tempch == 3) {
  10058. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x02);
  10059. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,0x25);
  10060. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1c,0x00);
  10061. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1d,0x1b);
  10062. }
  10063. }
  10064. return;
  10065. }
  10066. }
  10067. }
  10068. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  10069. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  10070. if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV)) {
  10071. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2a,0x00);
  10072. #ifdef SET_EMI
  10073. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
  10074. #endif
  10075. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x34,0x10);
  10076. }
  10077. } else if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) {
  10078. if(SiS_Pr->LVDSHL == -1) {
  10079. /* Maybe ACER only? */
  10080. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,0xfc,0x01);
  10081. }
  10082. }
  10083. tempch = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4;
  10084. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  10085. if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) {
  10086. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1f,0x76);
  10087. } else if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  10088. if(tempch == 0x03) {
  10089. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x02);
  10090. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,0x25);
  10091. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1c,0x00);
  10092. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1d,0x1b);
  10093. }
  10094. if((SiS_Pr->Backup == TRUE) && (SiS_Pr->Backup_Mode == ModeNo)) {
  10095. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x14,SiS_Pr->Backup_14);
  10096. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x15,SiS_Pr->Backup_15);
  10097. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x16,SiS_Pr->Backup_16);
  10098. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x17,SiS_Pr->Backup_17);
  10099. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,SiS_Pr->Backup_18);
  10100. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x19,SiS_Pr->Backup_19);
  10101. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1a,SiS_Pr->Backup_1a);
  10102. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,SiS_Pr->Backup_1b);
  10103. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1c,SiS_Pr->Backup_1c);
  10104. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1d,SiS_Pr->Backup_1d);
  10105. } else if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) { /* 1.10.8w */
  10106. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x14,0x90);
  10107. if(ModeNo <= 0x13) {
  10108. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x11);
  10109. if((resinfo == 0) || (resinfo == 2)) return;
  10110. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x18);
  10111. if((resinfo == 1) || (resinfo == 3)) return;
  10112. }
  10113. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x02);
  10114. if((ModeNo > 0x13) && (resinfo == SIS_RI_1024x768)) {
  10115. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x02); /* 1.10.7u */
  10116. #if 0
  10117. tempbx = 806; /* 0x326 */ /* other older BIOSes */
  10118. tempbx--;
  10119. temp = tempbx & 0xff;
  10120. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,temp);
  10121. temp = (tempbx >> 8) & 0x03;
  10122. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x1d,0xf8,temp);
  10123. #endif
  10124. }
  10125. } else if(ModeNo <= 0x13) {
  10126. if(ModeNo <= 1) {
  10127. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x70);
  10128. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x19,0xff);
  10129. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,0x48);
  10130. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1d,0x12);
  10131. }
  10132. if(!(modeflag & HalfDCLK)) {
  10133. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x14,0x20);
  10134. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x15,0x1a);
  10135. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x16,0x28);
  10136. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x17,0x00);
  10137. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x4c);
  10138. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x19,0xdc);
  10139. if(ModeNo == 0x12) {
  10140. switch(tempch) {
  10141. case 0:
  10142. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x95);
  10143. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x19,0xdc);
  10144. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1a,0x10);
  10145. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,0x95);
  10146. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1c,0x48);
  10147. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1d,0x12);
  10148. break;
  10149. case 2:
  10150. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x95);
  10151. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,0x48);
  10152. break;
  10153. case 3:
  10154. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,0x95);
  10155. break;
  10156. }
  10157. }
  10158. }
  10159. }
  10160. }
  10161. } else {
  10162. tempcl = tempbh = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x01);
  10163. tempcl &= 0x0f;
  10164. tempbh &= 0x70;
  10165. tempbh >>= 4;
  10166. tempbl = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x04);
  10167. tempbx = (tempbh << 8) | tempbl;
  10168. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  10169. if((resinfo == SIS_RI_1024x768) || (!(SiS_Pr->SiS_LCDInfo & DontExpandLCD))) {
  10170. if(SiS_Pr->SiS_SetFlag & LCDVESATiming) {
  10171. tempbx = 770;
  10172. } else {
  10173. if(tempbx > 770) tempbx = 770;
  10174. if(SiS_Pr->SiS_VGAVDE < 600) {
  10175. tempax = 768 - SiS_Pr->SiS_VGAVDE;
  10176. tempax >>= 4; /* 1.10.7w; 1.10.6s: 3; */
  10177. if(SiS_Pr->SiS_VGAVDE <= 480) tempax >>= 4; /* 1.10.7w; 1.10.6s: < 480; >>=1; */
  10178. tempbx -= tempax;
  10179. }
  10180. }
  10181. } else return;
  10182. }
  10183. temp = tempbx & 0xff;
  10184. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,temp);
  10185. temp = ((tempbx & 0xff00) >> 4) | tempcl;
  10186. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x01,0x80,temp);
  10187. }
  10188. }
  10189. }
  10190. #endif
  10191. /* ================= SiS 300 O.E.M. ================== */
  10192. #ifdef SIS300
  10193. static void
  10194. SetOEMLCDData2(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
  10195. USHORT ModeNo,USHORT ModeIdIndex, USHORT RefTabIndex)
  10196. {
  10197. USHORT crt2crtc=0, modeflag, myindex=0;
  10198. UCHAR temp;
  10199. int i;
  10200. if(ModeNo <= 0x13) {
  10201. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  10202. crt2crtc = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  10203. } else {
  10204. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  10205. crt2crtc = SiS_Pr->SiS_RefIndex[RefTabIndex].Ext_CRT2CRTC;
  10206. }
  10207. crt2crtc &= 0x3f;
  10208. if(SiS_Pr->SiS_CustomT == CUT_BARCO1024) {
  10209. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xdf);
  10210. }
  10211. if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) {
  10212. if(modeflag & HalfDCLK) myindex = 1;
  10213. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  10214. for(i=0; i<7; i++) {
  10215. if(barco_p1[myindex][crt2crtc][i][0]) {
  10216. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,
  10217. barco_p1[myindex][crt2crtc][i][0],
  10218. barco_p1[myindex][crt2crtc][i][2],
  10219. barco_p1[myindex][crt2crtc][i][1]);
  10220. }
  10221. }
  10222. }
  10223. temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00);
  10224. if(temp & 0x80) {
  10225. temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x18);
  10226. temp++;
  10227. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,temp);
  10228. }
  10229. }
  10230. }
  10231. static USHORT
  10232. GetOEMLCDPtr(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, int Flag)
  10233. {
  10234. UCHAR *ROMAddr = HwInfo->pjVirtualRomBase;
  10235. USHORT tempbx=0,romptr=0;
  10236. UCHAR customtable300[] = {
  10237. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  10238. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
  10239. };
  10240. UCHAR customtable630[] = {
  10241. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  10242. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
  10243. };
  10244. if(HwInfo->jChipType == SIS_300) {
  10245. tempbx = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) & 0x0f;
  10246. if(SiS_Pr->SiS_VBType & VB_SIS301) tempbx &= 0x07;
  10247. tempbx -= 2;
  10248. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) tempbx += 4;
  10249. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  10250. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx += 3;
  10251. }
  10252. if(SiS_Pr->SiS_UseROM) {
  10253. if(ROMAddr[0x235] & 0x80) {
  10254. tempbx = SiS_Pr->SiS_LCDTypeInfo;
  10255. if(Flag) {
  10256. romptr = SISGETROMW(0x255);
  10257. if(romptr) tempbx = ROMAddr[romptr + SiS_Pr->SiS_LCDTypeInfo];
  10258. else tempbx = customtable300[SiS_Pr->SiS_LCDTypeInfo];
  10259. if(tempbx == 0xFF) return 0xFFFF;
  10260. }
  10261. tempbx <<= 1;
  10262. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) tempbx++;
  10263. }
  10264. }
  10265. } else {
  10266. if(Flag) {
  10267. if(SiS_Pr->SiS_UseROM) {
  10268. romptr = SISGETROMW(0x255);
  10269. if(romptr) tempbx = ROMAddr[romptr + SiS_Pr->SiS_LCDTypeInfo];
  10270. else tempbx = 0xff;
  10271. } else {
  10272. tempbx = customtable630[SiS_Pr->SiS_LCDTypeInfo];
  10273. }
  10274. if(tempbx == 0xFF) return 0xFFFF;
  10275. tempbx <<= 2;
  10276. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) tempbx += 2;
  10277. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++;
  10278. return tempbx;
  10279. }
  10280. tempbx = SiS_Pr->SiS_LCDTypeInfo << 2;
  10281. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) tempbx += 2;
  10282. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++;
  10283. }
  10284. return tempbx;
  10285. }
  10286. static void
  10287. SetOEMLCDDelay(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
  10288. USHORT ModeNo,USHORT ModeIdIndex)
  10289. {
  10290. UCHAR *ROMAddr = HwInfo->pjVirtualRomBase;
  10291. USHORT index,temp,romptr=0;
  10292. if(SiS_Pr->SiS_LCDResInfo == Panel_Custom) return;
  10293. if(SiS_Pr->SiS_UseROM) {
  10294. if(!(ROMAddr[0x237] & 0x01)) return;
  10295. if(!(ROMAddr[0x237] & 0x02)) return;
  10296. romptr = SISGETROMW(0x24b);
  10297. }
  10298. /* The Panel Compensation Delay should be set according to tables
  10299. * here. Unfortunately, various BIOS versions don't case about
  10300. * a uniform way using eg. ROM byte 0x220, but use different
  10301. * hard coded delays (0x04, 0x20, 0x18) in SetGroup1().
  10302. * Thus we don't set this if the user select a custom pdc or if
  10303. * we otherwise detected a valid pdc.
  10304. */
  10305. if(SiS_Pr->PDC != -1) return;
  10306. temp = GetOEMLCDPtr(SiS_Pr,HwInfo, 0);
  10307. if(SiS_Pr->UseCustomMode)
  10308. index = 0;
  10309. else
  10310. index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].VB_LCDDelayIndex;
  10311. if(HwInfo->jChipType != SIS_300) {
  10312. if(romptr) {
  10313. romptr += (temp * 2);
  10314. romptr = SISGETROMW(romptr);
  10315. romptr += index;
  10316. temp = ROMAddr[romptr];
  10317. } else {
  10318. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  10319. temp = SiS300_OEMLCDDelay2[temp][index];
  10320. } else {
  10321. temp = SiS300_OEMLCDDelay3[temp][index];
  10322. }
  10323. }
  10324. } else {
  10325. if(SiS_Pr->SiS_UseROM && (ROMAddr[0x235] & 0x80)) {
  10326. if(romptr) {
  10327. romptr += (temp * 2);
  10328. romptr = SISGETROMW(romptr);
  10329. romptr += index;
  10330. temp = ROMAddr[romptr];
  10331. } else {
  10332. temp = SiS300_OEMLCDDelay5[temp][index];
  10333. }
  10334. } else {
  10335. if(SiS_Pr->SiS_UseROM) {
  10336. romptr = ROMAddr[0x249] | (ROMAddr[0x24a] << 8);
  10337. if(romptr) {
  10338. romptr += (temp * 2);
  10339. romptr = SISGETROMW(romptr);
  10340. romptr += index;
  10341. temp = ROMAddr[romptr];
  10342. } else {
  10343. temp = SiS300_OEMLCDDelay4[temp][index];
  10344. }
  10345. } else {
  10346. temp = SiS300_OEMLCDDelay4[temp][index];
  10347. }
  10348. }
  10349. }
  10350. temp &= 0x3c;
  10351. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,~0x3C,temp); /* index 0A D[6:4] */
  10352. }
  10353. static void
  10354. SetOEMLCDData(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
  10355. USHORT ModeNo,USHORT ModeIdIndex)
  10356. {
  10357. #if 0 /* Unfinished; Data table missing */
  10358. UCHAR *ROMAddr = HwInfo->pjVirtualRomBase;
  10359. USHORT index,temp;
  10360. if((SiS_Pr->SiS_UseROM) {
  10361. if(!(ROMAddr[0x237] & 0x01)) return;
  10362. if(!(ROMAddr[0x237] & 0x04)) return;
  10363. /* No rom pointer in BIOS header! */
  10364. }
  10365. temp = GetOEMLCDPtr(SiS_Pr,HwInfo, 1);
  10366. if(temp = 0xFFFF) return;
  10367. index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex]._VB_LCDHIndex;
  10368. for(i=0x14, j=0; i<=0x17; i++, j++) {
  10369. SiS_SetReg(SiS_Pr->SiS_Part1Port,i,SiS300_LCDHData[temp][index][j]);
  10370. }
  10371. SiS_SetRegANDOR(SiS_SiS_Part1Port,0x1a, 0xf8, (SiS300_LCDHData[temp][index][j] & 0x07));
  10372. index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex]._VB_LCDVIndex;
  10373. SiS_SetReg(SiS_SiS_Part1Port,0x18, SiS300_LCDVData[temp][index][0]);
  10374. SiS_SetRegANDOR(SiS_SiS_Part1Port,0x19, 0xF0, SiS300_LCDVData[temp][index][1]);
  10375. SiS_SetRegANDOR(SiS_SiS_Part1Port,0x1A, 0xC7, (SiS300_LCDVData[temp][index][2] & 0x38));
  10376. for(i=0x1b, j=3; i<=0x1d; i++, j++) {
  10377. SiS_SetReg(SiS_Pr->SiS_Part1Port,i,SiS300_LCDVData[temp][index][j]);
  10378. }
  10379. #endif
  10380. }
  10381. static USHORT
  10382. GetOEMTVPtr(SiS_Private *SiS_Pr)
  10383. {
  10384. USHORT index;
  10385. index = 0;
  10386. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) index += 4;
  10387. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  10388. if(SiS_Pr->SiS_VBInfo & SetCRT2ToSCART) index += 2;
  10389. else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) index += 3;
  10390. else if(SiS_Pr->SiS_TVMode & TVSetPAL) index += 1;
  10391. } else {
  10392. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) index += 2;
  10393. if(SiS_Pr->SiS_TVMode & TVSetPAL) index += 1;
  10394. }
  10395. return index;
  10396. }
  10397. static void
  10398. SetOEMTVDelay(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
  10399. USHORT ModeNo,USHORT ModeIdIndex)
  10400. {
  10401. UCHAR *ROMAddr = HwInfo->pjVirtualRomBase;
  10402. USHORT index,temp,romptr=0;
  10403. if(SiS_Pr->SiS_UseROM) {
  10404. if(!(ROMAddr[0x238] & 0x01)) return;
  10405. if(!(ROMAddr[0x238] & 0x02)) return;
  10406. romptr = SISGETROMW(0x241);
  10407. }
  10408. temp = GetOEMTVPtr(SiS_Pr);
  10409. index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].VB_TVDelayIndex;
  10410. if(romptr) {
  10411. romptr += (temp * 2);
  10412. romptr = SISGETROMW(romptr);
  10413. romptr += index;
  10414. temp = ROMAddr[romptr];
  10415. } else {
  10416. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  10417. temp = SiS300_OEMTVDelay301[temp][index];
  10418. } else {
  10419. temp = SiS300_OEMTVDelayLVDS[temp][index];
  10420. }
  10421. }
  10422. temp &= 0x3c;
  10423. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,~0x3C,temp);
  10424. }
  10425. static void
  10426. SetOEMAntiFlicker(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
  10427. USHORT ModeNo, USHORT ModeIdIndex)
  10428. {
  10429. UCHAR *ROMAddr = HwInfo->pjVirtualRomBase;
  10430. USHORT index,temp,romptr=0;
  10431. if(SiS_Pr->SiS_UseROM) {
  10432. if(!(ROMAddr[0x238] & 0x01)) return;
  10433. if(!(ROMAddr[0x238] & 0x04)) return;
  10434. romptr = SISGETROMW(0x243);
  10435. }
  10436. temp = GetOEMTVPtr(SiS_Pr);
  10437. index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].VB_TVFlickerIndex;
  10438. if(romptr) {
  10439. romptr += (temp * 2);
  10440. romptr = SISGETROMW(romptr);
  10441. romptr += index;
  10442. temp = ROMAddr[romptr];
  10443. } else {
  10444. temp = SiS300_OEMTVFlicker[temp][index];
  10445. }
  10446. temp &= 0x70;
  10447. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x0A,0x8F,temp);
  10448. }
  10449. static void
  10450. SetOEMPhaseIncr(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
  10451. USHORT ModeNo,USHORT ModeIdIndex)
  10452. {
  10453. UCHAR *ROMAddr = HwInfo->pjVirtualRomBase;
  10454. USHORT index,i,j,temp,romptr=0;
  10455. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) return;
  10456. if(SiS_Pr->SiS_TVMode & (TVSetNTSC1024 | TVSetNTSCJ | TVSetPALM | TVSetPALN)) return;
  10457. if(SiS_Pr->SiS_UseROM) {
  10458. if(!(ROMAddr[0x238] & 0x01)) return;
  10459. if(!(ROMAddr[0x238] & 0x08)) return;
  10460. romptr = SISGETROMW(0x245);
  10461. }
  10462. temp = GetOEMTVPtr(SiS_Pr);
  10463. index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].VB_TVPhaseIndex;
  10464. if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
  10465. for(i=0x31, j=0; i<=0x34; i++, j++) {
  10466. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS300_Phase2[temp][index][j]);
  10467. }
  10468. } else {
  10469. if(romptr) {
  10470. romptr += (temp * 2);
  10471. romptr = SISGETROMW(romptr);
  10472. romptr += (index * 4);
  10473. for(i=0x31, j=0; i<=0x34; i++, j++) {
  10474. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,ROMAddr[romptr + j]);
  10475. }
  10476. } else {
  10477. for(i=0x31, j=0; i<=0x34; i++, j++) {
  10478. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS300_Phase1[temp][index][j]);
  10479. }
  10480. }
  10481. }
  10482. }
  10483. static void
  10484. SetOEMYFilter(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
  10485. USHORT ModeNo,USHORT ModeIdIndex)
  10486. {
  10487. UCHAR *ROMAddr = HwInfo->pjVirtualRomBase;
  10488. USHORT index,temp,i,j,romptr=0;
  10489. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToSCART | SetCRT2ToHiVision | SetCRT2ToYPbPr525750)) return;
  10490. if(SiS_Pr->SiS_UseROM) {
  10491. if(!(ROMAddr[0x238] & 0x01)) return;
  10492. if(!(ROMAddr[0x238] & 0x10)) return;
  10493. romptr = SISGETROMW(0x247);
  10494. }
  10495. temp = GetOEMTVPtr(SiS_Pr);
  10496. if(SiS_Pr->SiS_TVMode & TVSetPALM) temp = 8;
  10497. else if(SiS_Pr->SiS_TVMode & TVSetPALN) temp = 9;
  10498. /* NTSCJ uses NTSC filters */
  10499. index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].VB_TVYFilterIndex;
  10500. if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
  10501. for(i=0x35, j=0; i<=0x38; i++, j++) {
  10502. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS300_Filter2[temp][index][j]);
  10503. }
  10504. for(i=0x48; i<=0x4A; i++, j++) {
  10505. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS300_Filter2[temp][index][j]);
  10506. }
  10507. } else {
  10508. if((romptr) && (!(SiS_Pr->SiS_TVMode & (TVSetPALM|TVSetPALN)))) {
  10509. romptr += (temp * 2);
  10510. romptr = SISGETROMW(romptr);
  10511. romptr += (index * 4);
  10512. for(i=0x35, j=0; i<=0x38; i++, j++) {
  10513. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,ROMAddr[romptr + j]);
  10514. }
  10515. } else {
  10516. for(i=0x35, j=0; i<=0x38; i++, j++) {
  10517. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS300_Filter1[temp][index][j]);
  10518. }
  10519. }
  10520. }
  10521. }
  10522. static USHORT
  10523. SiS_SearchVBModeID(SiS_Private *SiS_Pr, USHORT *ModeNo)
  10524. {
  10525. USHORT ModeIdIndex;
  10526. UCHAR VGAINFO = SiS_Pr->SiS_VGAINFO;
  10527. if(*ModeNo <= 5) *ModeNo |= 1;
  10528. for(ModeIdIndex=0; ; ModeIdIndex++) {
  10529. if(SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].ModeID == *ModeNo) break;
  10530. if(SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].ModeID == 0xFF) return 0;
  10531. }
  10532. if(*ModeNo != 0x07) {
  10533. if(*ModeNo > 0x03) return ModeIdIndex;
  10534. if(VGAINFO & 0x80) return ModeIdIndex;
  10535. ModeIdIndex++;
  10536. }
  10537. if(VGAINFO & 0x10) ModeIdIndex++; /* 400 lines */
  10538. /* else 350 lines */
  10539. return ModeIdIndex;
  10540. }
  10541. static void
  10542. SiS_OEM300Setting(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
  10543. USHORT ModeNo, USHORT ModeIdIndex, USHORT RefTableIndex)
  10544. {
  10545. USHORT OEMModeIdIndex=0;
  10546. if(!SiS_Pr->UseCustomMode) {
  10547. OEMModeIdIndex = SiS_SearchVBModeID(SiS_Pr,&ModeNo);
  10548. if(!(OEMModeIdIndex)) return;
  10549. }
  10550. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  10551. SetOEMLCDDelay(SiS_Pr, HwInfo, ModeNo, OEMModeIdIndex);
  10552. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  10553. SetOEMLCDData(SiS_Pr, HwInfo, ModeNo, OEMModeIdIndex);
  10554. }
  10555. }
  10556. if(SiS_Pr->UseCustomMode) return;
  10557. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  10558. SetOEMTVDelay(SiS_Pr, HwInfo, ModeNo,OEMModeIdIndex);
  10559. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  10560. SetOEMAntiFlicker(SiS_Pr, HwInfo, ModeNo, OEMModeIdIndex);
  10561. SetOEMPhaseIncr(SiS_Pr, HwInfo, ModeNo, OEMModeIdIndex);
  10562. SetOEMYFilter(SiS_Pr, HwInfo, ModeNo, OEMModeIdIndex);
  10563. }
  10564. }
  10565. }
  10566. #endif