vb_setmode.c 142 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547
  1. #include <linux/delay.h>
  2. #include "XGIfb.h"
  3. #include "vb_def.h"
  4. #include "vb_init.h"
  5. #include "vb_util.h"
  6. #include "vb_table.h"
  7. #include "vb_setmode.h"
  8. #define IndexMask 0xff
  9. #define TVCLKBASE_315_25 (TVCLKBASE_315 + 25)
  10. static const unsigned short XGINew_VGA_DAC[] = {
  11. 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
  12. 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F,
  13. 0x00, 0x05, 0x08, 0x0B, 0x0E, 0x11, 0x14, 0x18,
  14. 0x1C, 0x20, 0x24, 0x28, 0x2D, 0x32, 0x38, 0x3F,
  15. 0x00, 0x10, 0x1F, 0x2F, 0x3F, 0x1F, 0x27, 0x2F,
  16. 0x37, 0x3F, 0x2D, 0x31, 0x36, 0x3A, 0x3F, 0x00,
  17. 0x07, 0x0E, 0x15, 0x1C, 0x0E, 0x11, 0x15, 0x18,
  18. 0x1C, 0x14, 0x16, 0x18, 0x1A, 0x1C, 0x00, 0x04,
  19. 0x08, 0x0C, 0x10, 0x08, 0x0A, 0x0C, 0x0E, 0x10,
  20. 0x0B, 0x0C, 0x0D, 0x0F, 0x10};
  21. void InitTo330Pointer(unsigned char ChipType, struct vb_device_info *pVBInfo)
  22. {
  23. pVBInfo->MCLKData = XGI340New_MCLKData;
  24. pVBInfo->LCDResInfo = 0;
  25. pVBInfo->LCDTypeInfo = 0;
  26. pVBInfo->LCDInfo = 0;
  27. pVBInfo->VBInfo = 0;
  28. pVBInfo->TVInfo = 0;
  29. pVBInfo->SR18 = XGI340_SR18;
  30. pVBInfo->CR40 = XGI340_cr41;
  31. if (ChipType < XG20)
  32. XGI_GetVBType(pVBInfo);
  33. /* 310 customization related */
  34. if ((pVBInfo->VBType & VB_SIS301LV) || (pVBInfo->VBType & VB_SIS302LV))
  35. pVBInfo->LCDCapList = XGI_LCDDLCapList;
  36. else
  37. pVBInfo->LCDCapList = XGI_LCDCapList;
  38. if (ChipType >= XG20)
  39. pVBInfo->XGINew_CR97 = 0x10;
  40. if (ChipType == XG27) {
  41. unsigned char temp;
  42. pVBInfo->MCLKData = XGI27New_MCLKData;
  43. pVBInfo->CR40 = XGI27_cr41;
  44. pVBInfo->XGINew_CR97 = 0xc1;
  45. pVBInfo->SR18 = XG27_SR18;
  46. /*Z11m DDR*/
  47. temp = xgifb_reg_get(pVBInfo->P3c4, 0x3B);
  48. /* SR3B[7][3]MAA15 MAA11 (Power on Trapping) */
  49. if (((temp & 0x88) == 0x80) || ((temp & 0x88) == 0x08))
  50. pVBInfo->XGINew_CR97 = 0x80;
  51. }
  52. }
  53. static void XGI_SetSeqRegs(struct vb_device_info *pVBInfo)
  54. {
  55. unsigned char SRdata, i;
  56. xgifb_reg_set(pVBInfo->P3c4, 0x00, 0x03); /* Set SR0 */
  57. for (i = 0; i < 4; i++) {
  58. /* Get SR1,2,3,4 from file */
  59. /* SR1 is with screen off 0x20 */
  60. SRdata = XGI330_StandTable.SR[i];
  61. xgifb_reg_set(pVBInfo->P3c4, i+1, SRdata); /* Set SR 1 2 3 4 */
  62. }
  63. }
  64. static void XGI_SetCRTCRegs(struct vb_device_info *pVBInfo)
  65. {
  66. unsigned char CRTCdata;
  67. unsigned short i;
  68. CRTCdata = xgifb_reg_get(pVBInfo->P3d4, 0x11);
  69. CRTCdata &= 0x7f;
  70. xgifb_reg_set(pVBInfo->P3d4, 0x11, CRTCdata); /* Unlock CRTC */
  71. for (i = 0; i <= 0x18; i++) {
  72. /* Get CRTC from file */
  73. CRTCdata = XGI330_StandTable.CRTC[i];
  74. xgifb_reg_set(pVBInfo->P3d4, i, CRTCdata); /* Set CRTC(3d4) */
  75. }
  76. }
  77. static void XGI_SetATTRegs(unsigned short ModeIdIndex,
  78. struct vb_device_info *pVBInfo)
  79. {
  80. unsigned char ARdata;
  81. unsigned short i, modeflag;
  82. modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  83. for (i = 0; i <= 0x13; i++) {
  84. ARdata = XGI330_StandTable.ATTR[i];
  85. if ((modeflag & Charx8Dot) && i == 0x13) { /* ifndef Dot9 */
  86. if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
  87. ARdata = 0;
  88. } else if ((pVBInfo->VBInfo &
  89. (SetCRT2ToTV | SetCRT2ToLCD)) &&
  90. (pVBInfo->VBInfo & SetInSlaveMode)) {
  91. ARdata = 0;
  92. }
  93. }
  94. inb(pVBInfo->P3da); /* reset 3da */
  95. outb(i, pVBInfo->P3c0); /* set index */
  96. outb(ARdata, pVBInfo->P3c0); /* set data */
  97. }
  98. inb(pVBInfo->P3da); /* reset 3da */
  99. outb(0x14, pVBInfo->P3c0); /* set index */
  100. outb(0x00, pVBInfo->P3c0); /* set data */
  101. inb(pVBInfo->P3da); /* Enable Attribute */
  102. outb(0x20, pVBInfo->P3c0);
  103. }
  104. static void XGI_SetGRCRegs(struct vb_device_info *pVBInfo)
  105. {
  106. unsigned char GRdata;
  107. unsigned short i;
  108. for (i = 0; i <= 0x08; i++) {
  109. /* Get GR from file */
  110. GRdata = XGI330_StandTable.GRC[i];
  111. xgifb_reg_set(pVBInfo->P3ce, i, GRdata); /* Set GR(3ce) */
  112. }
  113. if (pVBInfo->ModeType > ModeVGA) {
  114. GRdata = xgifb_reg_get(pVBInfo->P3ce, 0x05);
  115. GRdata &= 0xBF; /* 256 color disable */
  116. xgifb_reg_set(pVBInfo->P3ce, 0x05, GRdata);
  117. }
  118. }
  119. static void XGI_ClearExt1Regs(struct vb_device_info *pVBInfo)
  120. {
  121. unsigned short i;
  122. for (i = 0x0A; i <= 0x0E; i++)
  123. xgifb_reg_set(pVBInfo->P3c4, i, 0x00); /* Clear SR0A-SR0E */
  124. }
  125. static unsigned char XGI_SetDefaultVCLK(struct vb_device_info *pVBInfo)
  126. {
  127. xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x20);
  128. xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[0].SR2B);
  129. xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[0].SR2C);
  130. xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x10);
  131. xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[1].SR2B);
  132. xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[1].SR2C);
  133. xgifb_reg_and(pVBInfo->P3c4, 0x31, ~0x30);
  134. return 0;
  135. }
  136. static unsigned char XGI_AjustCRT2Rate(unsigned short ModeIdIndex,
  137. unsigned short RefreshRateTableIndex, unsigned short *i,
  138. struct vb_device_info *pVBInfo)
  139. {
  140. unsigned short tempax, tempbx, resinfo, modeflag, infoflag;
  141. modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  142. resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  143. tempbx = XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID;
  144. tempax = 0;
  145. if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
  146. tempax |= SupportRAMDAC2;
  147. if (pVBInfo->VBType & VB_XGI301C)
  148. tempax |= SupportCRT2in301C;
  149. }
  150. /* 301b */
  151. if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
  152. tempax |= SupportLCD;
  153. if (pVBInfo->LCDResInfo != Panel_1280x1024 &&
  154. pVBInfo->LCDResInfo != Panel_1280x960 &&
  155. (pVBInfo->LCDInfo & LCDNonExpanding) &&
  156. resinfo >= 9)
  157. return 0;
  158. }
  159. if (pVBInfo->VBInfo & SetCRT2ToHiVision) { /* for HiTV */
  160. tempax |= SupportHiVision;
  161. if ((pVBInfo->VBInfo & SetInSlaveMode) &&
  162. ((resinfo == 4) ||
  163. (resinfo == 3 && (pVBInfo->SetFlag & TVSimuMode)) ||
  164. (resinfo > 7)))
  165. return 0;
  166. } else if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO | SetCRT2ToSVIDEO |
  167. SetCRT2ToSCART | SetCRT2ToYPbPr525750 |
  168. SetCRT2ToHiVision)) {
  169. tempax |= SupportTV;
  170. if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV |
  171. VB_SIS302LV | VB_XGI301C))
  172. tempax |= SupportTV1024;
  173. if (!(pVBInfo->VBInfo & TVSetPAL) &&
  174. (modeflag & NoSupportSimuTV) &&
  175. (pVBInfo->VBInfo & SetInSlaveMode) &&
  176. (!(pVBInfo->VBInfo & SetNotSimuMode)))
  177. return 0;
  178. }
  179. for (; XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID ==
  180. tempbx; (*i)--) {
  181. infoflag = XGI330_RefIndex[RefreshRateTableIndex + (*i)].
  182. Ext_InfoFlag;
  183. if (infoflag & tempax)
  184. return 1;
  185. if ((*i) == 0)
  186. break;
  187. }
  188. for ((*i) = 0;; (*i)++) {
  189. infoflag = XGI330_RefIndex[RefreshRateTableIndex + (*i)].
  190. Ext_InfoFlag;
  191. if (XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID
  192. != tempbx) {
  193. return 0;
  194. }
  195. if (infoflag & tempax)
  196. return 1;
  197. }
  198. return 1;
  199. }
  200. static void XGI_SetSync(unsigned short RefreshRateTableIndex,
  201. struct vb_device_info *pVBInfo)
  202. {
  203. unsigned short sync, temp;
  204. /* di+0x00 */
  205. sync = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag >> 8;
  206. sync &= 0xC0;
  207. temp = 0x2F;
  208. temp |= sync;
  209. outb(temp, pVBInfo->P3c2); /* Set Misc(3c2) */
  210. }
  211. static void XGI_SetCRT1Timing_H(struct vb_device_info *pVBInfo,
  212. struct xgi_hw_device_info *HwDeviceExtension)
  213. {
  214. unsigned char data, data1, pushax;
  215. unsigned short i, j;
  216. /* unlock cr0-7 */
  217. data = xgifb_reg_get(pVBInfo->P3d4, 0x11);
  218. data &= 0x7F;
  219. xgifb_reg_set(pVBInfo->P3d4, 0x11, data);
  220. data = pVBInfo->TimingH.data[0];
  221. xgifb_reg_set(pVBInfo->P3d4, 0, data);
  222. for (i = 0x01; i <= 0x04; i++) {
  223. data = pVBInfo->TimingH.data[i];
  224. xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 1), data);
  225. }
  226. for (i = 0x05; i <= 0x06; i++) {
  227. data = pVBInfo->TimingH.data[i];
  228. xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i + 6), data);
  229. }
  230. j = xgifb_reg_get(pVBInfo->P3c4, 0x0e);
  231. j &= 0x1F;
  232. data = pVBInfo->TimingH.data[7];
  233. data &= 0xE0;
  234. data |= j;
  235. xgifb_reg_set(pVBInfo->P3c4, 0x0e, data);
  236. if (HwDeviceExtension->jChipType >= XG20) {
  237. data = xgifb_reg_get(pVBInfo->P3d4, 0x04);
  238. data = data - 1;
  239. xgifb_reg_set(pVBInfo->P3d4, 0x04, data);
  240. data = xgifb_reg_get(pVBInfo->P3d4, 0x05);
  241. data1 = data;
  242. data1 &= 0xE0;
  243. data &= 0x1F;
  244. if (data == 0) {
  245. pushax = data;
  246. data = xgifb_reg_get(pVBInfo->P3c4, 0x0c);
  247. data &= 0xFB;
  248. xgifb_reg_set(pVBInfo->P3c4, 0x0c, data);
  249. data = pushax;
  250. }
  251. data = data - 1;
  252. data |= data1;
  253. xgifb_reg_set(pVBInfo->P3d4, 0x05, data);
  254. data = xgifb_reg_get(pVBInfo->P3c4, 0x0e);
  255. data >>= 5;
  256. data = data + 3;
  257. if (data > 7)
  258. data = data - 7;
  259. data <<= 5;
  260. xgifb_reg_and_or(pVBInfo->P3c4, 0x0e, ~0xE0, data);
  261. }
  262. }
  263. static void XGI_SetCRT1Timing_V(unsigned short ModeIdIndex,
  264. struct vb_device_info *pVBInfo)
  265. {
  266. unsigned char data;
  267. unsigned short i, j;
  268. for (i = 0x00; i <= 0x01; i++) {
  269. data = pVBInfo->TimingV.data[i];
  270. xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 6), data);
  271. }
  272. for (i = 0x02; i <= 0x03; i++) {
  273. data = pVBInfo->TimingV.data[i];
  274. xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x0e), data);
  275. }
  276. for (i = 0x04; i <= 0x05; i++) {
  277. data = pVBInfo->TimingV.data[i];
  278. xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x11), data);
  279. }
  280. j = xgifb_reg_get(pVBInfo->P3c4, 0x0a);
  281. j &= 0xC0;
  282. data = pVBInfo->TimingV.data[6];
  283. data &= 0x3F;
  284. data |= j;
  285. xgifb_reg_set(pVBInfo->P3c4, 0x0a, data);
  286. data = pVBInfo->TimingV.data[6];
  287. data &= 0x80;
  288. data >>= 2;
  289. i = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  290. i &= DoubleScanMode;
  291. if (i)
  292. data |= 0x80;
  293. j = xgifb_reg_get(pVBInfo->P3d4, 0x09);
  294. j &= 0x5F;
  295. data |= j;
  296. xgifb_reg_set(pVBInfo->P3d4, 0x09, data);
  297. }
  298. static void XGI_SetCRT1CRTC(unsigned short ModeIdIndex,
  299. unsigned short RefreshRateTableIndex,
  300. struct vb_device_info *pVBInfo,
  301. struct xgi_hw_device_info *HwDeviceExtension)
  302. {
  303. unsigned char index, data;
  304. unsigned short i;
  305. /* Get index */
  306. index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
  307. index = index & IndexMask;
  308. data = xgifb_reg_get(pVBInfo->P3d4, 0x11);
  309. data &= 0x7F;
  310. xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
  311. for (i = 0; i < 8; i++)
  312. pVBInfo->TimingH.data[i]
  313. = XGI_CRT1Table[index].CR[i];
  314. for (i = 0; i < 7; i++)
  315. pVBInfo->TimingV.data[i]
  316. = XGI_CRT1Table[index].CR[i + 8];
  317. XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
  318. XGI_SetCRT1Timing_V(ModeIdIndex, pVBInfo);
  319. if (pVBInfo->ModeType > 0x03)
  320. xgifb_reg_set(pVBInfo->P3d4, 0x14, 0x4F);
  321. }
  322. /* --------------------------------------------------------------------- */
  323. /* Function : XGI_SetXG21CRTC */
  324. /* Input : Stand or enhance CRTC table */
  325. /* Output : Fill CRT Hsync/Vsync to SR2E/SR2F/SR30/SR33/SR34/SR3F */
  326. /* Description : Set LCD timing */
  327. /* --------------------------------------------------------------------- */
  328. static void XGI_SetXG21CRTC(unsigned short RefreshRateTableIndex,
  329. struct vb_device_info *pVBInfo)
  330. {
  331. unsigned char index, Tempax, Tempbx, Tempcx, Tempdx;
  332. unsigned short Temp1, Temp2, Temp3;
  333. index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
  334. /* Tempax: CR4 HRS */
  335. Tempax = XGI_CRT1Table[index].CR[3];
  336. Tempcx = Tempax; /* Tempcx: HRS */
  337. /* SR2E[7:0]->HRS */
  338. xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
  339. Tempdx = XGI_CRT1Table[index].CR[5]; /* SRB */
  340. Tempdx &= 0xC0; /* Tempdx[7:6]: SRB[7:6] */
  341. Temp1 = Tempdx; /* Temp1[7:6]: HRS[9:8] */
  342. Temp1 <<= 2; /* Temp1[9:8]: HRS[9:8] */
  343. Temp1 |= Tempax; /* Temp1[9:0]: HRS[9:0] */
  344. Tempax = XGI_CRT1Table[index].CR[4]; /* CR5 HRE */
  345. Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
  346. Tempbx = XGI_CRT1Table[index].CR[6]; /* SRC */
  347. Tempbx &= 0x04; /* Tempbx[2]: HRE[5] */
  348. Tempbx <<= 3; /* Tempbx[5]: HRE[5] */
  349. Tempax |= Tempbx; /* Tempax[5:0]: HRE[5:0] */
  350. Temp2 = Temp1 & 0x3C0; /* Temp2[9:6]: HRS[9:6] */
  351. Temp2 |= Tempax; /* Temp2[9:0]: HRE[9:0] */
  352. Tempcx &= 0x3F; /* Tempcx[5:0]: HRS[5:0] */
  353. if (Tempax < Tempcx) /* HRE < HRS */
  354. Temp2 |= 0x40; /* Temp2 + 0x40 */
  355. Temp2 &= 0xFF;
  356. Tempax = (unsigned char) Temp2; /* Tempax: HRE[7:0] */
  357. Tempax <<= 2; /* Tempax[7:2]: HRE[5:0] */
  358. Tempdx >>= 6; /* Tempdx[7:6]->[1:0] HRS[9:8] */
  359. Tempax |= Tempdx; /* HRE[5:0]HRS[9:8] */
  360. /* SR2F D[7:2]->HRE, D[1:0]->HRS */
  361. xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
  362. xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
  363. /* CR10 VRS */
  364. Tempax = XGI_CRT1Table[index].CR[10];
  365. Tempbx = Tempax; /* Tempbx: VRS */
  366. Tempax &= 0x01; /* Tempax[0]: VRS[0] */
  367. xgifb_reg_or(pVBInfo->P3c4, 0x33, Tempax); /* SR33[0]->VRS[0] */
  368. /* CR7[2][7] VRE */
  369. Tempax = XGI_CRT1Table[index].CR[9];
  370. Tempcx = Tempbx >> 1; /* Tempcx[6:0]: VRS[7:1] */
  371. Tempdx = Tempax & 0x04; /* Tempdx[2]: CR7[2] */
  372. Tempdx <<= 5; /* Tempdx[7]: VRS[8] */
  373. Tempcx |= Tempdx; /* Tempcx[7:0]: VRS[8:1] */
  374. xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempcx); /* SR34[8:1]->VRS */
  375. Temp1 = Tempdx; /* Temp1[7]: Tempdx[7] */
  376. Temp1 <<= 1; /* Temp1[8]: VRS[8] */
  377. Temp1 |= Tempbx; /* Temp1[8:0]: VRS[8:0] */
  378. Tempax &= 0x80;
  379. Temp2 = Tempax << 2; /* Temp2[9]: VRS[9] */
  380. Temp1 |= Temp2; /* Temp1[9:0]: VRS[9:0] */
  381. /* Tempax: SRA */
  382. Tempax = XGI_CRT1Table[index].CR[14];
  383. Tempax &= 0x08; /* Tempax[3]: VRS[3] */
  384. Temp2 = Tempax;
  385. Temp2 <<= 7; /* Temp2[10]: VRS[10] */
  386. Temp1 |= Temp2; /* Temp1[10:0]: VRS[10:0] */
  387. /* Tempax: CR11 VRE */
  388. Tempax = XGI_CRT1Table[index].CR[11];
  389. Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
  390. /* Tempbx: SRA */
  391. Tempbx = XGI_CRT1Table[index].CR[14];
  392. Tempbx &= 0x20; /* Tempbx[5]: VRE[5] */
  393. Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
  394. Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
  395. Temp2 = Temp1 & 0x7E0; /* Temp2[10:5]: VRS[10:5] */
  396. Temp2 |= Tempax; /* Temp2[10:5]: VRE[10:5] */
  397. Temp3 = Temp1 & 0x1F; /* Temp3[4:0]: VRS[4:0] */
  398. if (Tempax < Temp3) /* VRE < VRS */
  399. Temp2 |= 0x20; /* VRE + 0x20 */
  400. Temp2 &= 0xFF;
  401. Tempax = (unsigned char) Temp2; /* Tempax: VRE[7:0] */
  402. Tempax <<= 2; /* Tempax[7:0]; VRE[5:0]00 */
  403. Temp1 &= 0x600; /* Temp1[10:9]: VRS[10:9] */
  404. Temp1 >>= 9; /* Temp1[1:0]: VRS[10:9] */
  405. Tempbx = (unsigned char) Temp1;
  406. Tempax |= Tempbx; /* Tempax[7:0]: VRE[5:0]VRS[10:9] */
  407. Tempax &= 0x7F;
  408. /* SR3F D[7:2]->VRE D[1:0]->VRS */
  409. xgifb_reg_set(pVBInfo->P3c4, 0x3F, Tempax);
  410. }
  411. static void XGI_SetXG27CRTC(unsigned short RefreshRateTableIndex,
  412. struct vb_device_info *pVBInfo)
  413. {
  414. unsigned short index, Tempax, Tempbx, Tempcx;
  415. index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
  416. /* Tempax: CR4 HRS */
  417. Tempax = XGI_CRT1Table[index].CR[3];
  418. Tempbx = Tempax; /* Tempbx: HRS[7:0] */
  419. /* SR2E[7:0]->HRS */
  420. xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
  421. /* SR0B */
  422. Tempax = XGI_CRT1Table[index].CR[5];
  423. Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
  424. Tempbx |= (Tempax << 2); /* Tempbx: HRS[9:0] */
  425. Tempax = XGI_CRT1Table[index].CR[4]; /* CR5 HRE */
  426. Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
  427. Tempcx = Tempax; /* Tempcx: HRE[4:0] */
  428. Tempax = XGI_CRT1Table[index].CR[6]; /* SRC */
  429. Tempax &= 0x04; /* Tempax[2]: HRE[5] */
  430. Tempax <<= 3; /* Tempax[5]: HRE[5] */
  431. Tempcx |= Tempax; /* Tempcx[5:0]: HRE[5:0] */
  432. Tempbx = Tempbx & 0x3C0; /* Tempbx[9:6]: HRS[9:6] */
  433. Tempbx |= Tempcx; /* Tempbx: HRS[9:6]HRE[5:0] */
  434. /* Tempax: CR4 HRS */
  435. Tempax = XGI_CRT1Table[index].CR[3];
  436. Tempax &= 0x3F; /* Tempax: HRS[5:0] */
  437. if (Tempcx <= Tempax) /* HRE[5:0] < HRS[5:0] */
  438. Tempbx += 0x40; /* Tempbx= Tempbx + 0x40 : HRE[9:0]*/
  439. Tempax = XGI_CRT1Table[index].CR[5]; /* SR0B */
  440. Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
  441. Tempax >>= 6; /* Tempax[1:0]: HRS[9:8]*/
  442. Tempax |= ((Tempbx << 2) & 0xFF); /* Tempax[7:2]: HRE[5:0] */
  443. /* SR2F [7:2][1:0]: HRE[5:0]HRS[9:8] */
  444. xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
  445. xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
  446. /* CR10 VRS */
  447. Tempax = XGI_CRT1Table[index].CR[10];
  448. /* SR34[7:0]->VRS[7:0] */
  449. xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempax);
  450. Tempcx = Tempax; /* Tempcx <= VRS[7:0] */
  451. /* CR7[7][2] VRS[9][8] */
  452. Tempax = XGI_CRT1Table[index].CR[9];
  453. Tempbx = Tempax; /* Tempbx <= CR07[7:0] */
  454. Tempax = Tempax & 0x04; /* Tempax[2]: CR7[2]: VRS[8] */
  455. Tempax >>= 2; /* Tempax[0]: VRS[8] */
  456. /* SR35[0]: VRS[8] */
  457. xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x01, Tempax);
  458. Tempcx |= (Tempax << 8); /* Tempcx <= VRS[8:0] */
  459. Tempcx |= ((Tempbx & 0x80) << 2); /* Tempcx <= VRS[9:0] */
  460. /* Tempax: SR0A */
  461. Tempax = XGI_CRT1Table[index].CR[14];
  462. Tempax &= 0x08; /* SR0A[3] VRS[10] */
  463. Tempcx |= (Tempax << 7); /* Tempcx <= VRS[10:0] */
  464. /* Tempax: CR11 VRE */
  465. Tempax = XGI_CRT1Table[index].CR[11];
  466. Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
  467. /* Tempbx: SR0A */
  468. Tempbx = XGI_CRT1Table[index].CR[14];
  469. Tempbx &= 0x20; /* Tempbx[5]: SR0A[5]: VRE[4] */
  470. Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
  471. Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
  472. Tempbx = Tempcx; /* Tempbx: VRS[10:0] */
  473. Tempbx &= 0x7E0; /* Tempbx[10:5]: VRS[10:5] */
  474. Tempbx |= Tempax; /* Tempbx: VRS[10:5]VRE[4:0] */
  475. if (Tempbx <= Tempcx) /* VRE <= VRS */
  476. Tempbx |= 0x20; /* VRE + 0x20 */
  477. /* Tempax: Tempax[7:0]; VRE[5:0]00 */
  478. Tempax = (Tempbx << 2) & 0xFF;
  479. /* SR3F[7:2]:VRE[5:0] */
  480. xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC, Tempax);
  481. Tempax = Tempcx >> 8;
  482. /* SR35[2:0]:VRS[10:8] */
  483. xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07, Tempax);
  484. }
  485. static void XGI_SetXG27FPBits(struct vb_device_info *pVBInfo)
  486. {
  487. unsigned char temp;
  488. /* D[1:0] 01: 18bit, 00: dual 12, 10: single 24 */
  489. temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
  490. temp = (temp & 3) << 6;
  491. /* SR06[7]0: dual 12/1: single 24 [6] 18bit Dither <= 0 h/w recommend */
  492. xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0xc0, temp & 0x80);
  493. /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: 24bits */
  494. xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
  495. }
  496. static void xgifb_set_lcd(int chip_id,
  497. struct vb_device_info *pVBInfo,
  498. unsigned short RefreshRateTableIndex)
  499. {
  500. unsigned short temp;
  501. xgifb_reg_set(pVBInfo->P3d4, 0x2E, 0x00);
  502. xgifb_reg_set(pVBInfo->P3d4, 0x2F, 0x00);
  503. xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x00);
  504. xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x00);
  505. if (chip_id == XG27) {
  506. temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
  507. if ((temp & 0x03) == 0) { /* dual 12 */
  508. xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x13);
  509. xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x13);
  510. }
  511. }
  512. if (chip_id == XG27) {
  513. XGI_SetXG27FPBits(pVBInfo);
  514. } else {
  515. temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
  516. if (temp & 0x01) {
  517. /* 18 bits FP */
  518. xgifb_reg_or(pVBInfo->P3c4, 0x06, 0x40);
  519. xgifb_reg_or(pVBInfo->P3c4, 0x09, 0x40);
  520. }
  521. }
  522. xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x01); /* Negative blank polarity */
  523. xgifb_reg_and(pVBInfo->P3c4, 0x30, ~0x20); /* Hsync polarity */
  524. xgifb_reg_and(pVBInfo->P3c4, 0x35, ~0x80); /* Vsync polarity */
  525. temp = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
  526. if (temp & 0x4000)
  527. /* Hsync polarity */
  528. xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20);
  529. if (temp & 0x8000)
  530. /* Vsync polarity */
  531. xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80);
  532. }
  533. /* --------------------------------------------------------------------- */
  534. /* Function : XGI_UpdateXG21CRTC */
  535. /* Input : */
  536. /* Output : CRT1 CRTC */
  537. /* Description : Modify CRT1 Hsync/Vsync to fix LCD mode timing */
  538. /* --------------------------------------------------------------------- */
  539. static void XGI_UpdateXG21CRTC(unsigned short ModeNo,
  540. struct vb_device_info *pVBInfo,
  541. unsigned short RefreshRateTableIndex)
  542. {
  543. int index = -1;
  544. xgifb_reg_and(pVBInfo->P3d4, 0x11, 0x7F); /* Unlock CR0~7 */
  545. if (ModeNo == 0x2E &&
  546. (XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC ==
  547. RES640x480x60))
  548. index = 12;
  549. else if (ModeNo == 0x2E && (XGI330_RefIndex[RefreshRateTableIndex].
  550. Ext_CRT1CRTC == RES640x480x72))
  551. index = 13;
  552. else if (ModeNo == 0x2F)
  553. index = 14;
  554. else if (ModeNo == 0x50)
  555. index = 15;
  556. else if (ModeNo == 0x59)
  557. index = 16;
  558. if (index != -1) {
  559. xgifb_reg_set(pVBInfo->P3d4, 0x02,
  560. XGI_UpdateCRT1Table[index].CR02);
  561. xgifb_reg_set(pVBInfo->P3d4, 0x03,
  562. XGI_UpdateCRT1Table[index].CR03);
  563. xgifb_reg_set(pVBInfo->P3d4, 0x15,
  564. XGI_UpdateCRT1Table[index].CR15);
  565. xgifb_reg_set(pVBInfo->P3d4, 0x16,
  566. XGI_UpdateCRT1Table[index].CR16);
  567. }
  568. }
  569. static void XGI_SetCRT1DE(unsigned short ModeIdIndex,
  570. unsigned short RefreshRateTableIndex,
  571. struct vb_device_info *pVBInfo)
  572. {
  573. unsigned short resindex, tempax, tempbx, tempcx, temp, modeflag;
  574. unsigned char data;
  575. resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  576. modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  577. tempax = XGI330_ModeResInfo[resindex].HTotal;
  578. tempbx = XGI330_ModeResInfo[resindex].VTotal;
  579. if (modeflag & HalfDCLK)
  580. tempax >>= 1;
  581. if (modeflag & HalfDCLK)
  582. tempax <<= 1;
  583. temp = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
  584. if (temp & InterlaceMode)
  585. tempbx >>= 1;
  586. if (modeflag & DoubleScanMode)
  587. tempbx <<= 1;
  588. tempcx = 8;
  589. tempax /= tempcx;
  590. tempax -= 1;
  591. tempbx -= 1;
  592. tempcx = tempax;
  593. temp = xgifb_reg_get(pVBInfo->P3d4, 0x11);
  594. data = xgifb_reg_get(pVBInfo->P3d4, 0x11);
  595. data &= 0x7F;
  596. xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
  597. xgifb_reg_set(pVBInfo->P3d4, 0x01, (unsigned short) (tempcx & 0xff));
  598. xgifb_reg_and_or(pVBInfo->P3d4, 0x0b, ~0x0c,
  599. (unsigned short) ((tempcx & 0x0ff00) >> 10));
  600. xgifb_reg_set(pVBInfo->P3d4, 0x12, (unsigned short) (tempbx & 0xff));
  601. tempax = 0;
  602. tempbx >>= 8;
  603. if (tempbx & 0x01)
  604. tempax |= 0x02;
  605. if (tempbx & 0x02)
  606. tempax |= 0x40;
  607. xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x42, tempax);
  608. data = xgifb_reg_get(pVBInfo->P3d4, 0x07);
  609. tempax = 0;
  610. if (tempbx & 0x04)
  611. tempax |= 0x02;
  612. xgifb_reg_and_or(pVBInfo->P3d4, 0x0a, ~0x02, tempax);
  613. xgifb_reg_set(pVBInfo->P3d4, 0x11, temp);
  614. }
  615. static void XGI_SetCRT1Offset(unsigned short ModeNo,
  616. unsigned short ModeIdIndex,
  617. unsigned short RefreshRateTableIndex,
  618. struct xgi_hw_device_info *HwDeviceExtension,
  619. struct vb_device_info *pVBInfo)
  620. {
  621. unsigned short temp, ah, al, temp2, i, DisplayUnit;
  622. /* GetOffset */
  623. temp = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeInfo;
  624. temp >>= 8;
  625. temp = XGI330_ScreenOffset[temp];
  626. temp2 = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
  627. temp2 &= InterlaceMode;
  628. if (temp2)
  629. temp <<= 1;
  630. temp2 = pVBInfo->ModeType - ModeEGA;
  631. switch (temp2) {
  632. case 0:
  633. temp2 = 1;
  634. break;
  635. case 1:
  636. temp2 = 2;
  637. break;
  638. case 2:
  639. temp2 = 4;
  640. break;
  641. case 3:
  642. temp2 = 4;
  643. break;
  644. case 4:
  645. temp2 = 6;
  646. break;
  647. case 5:
  648. temp2 = 8;
  649. break;
  650. default:
  651. break;
  652. }
  653. if ((ModeNo >= 0x26) && (ModeNo <= 0x28))
  654. temp = temp * temp2 + temp2 / 2;
  655. else
  656. temp *= temp2;
  657. /* SetOffset */
  658. DisplayUnit = temp;
  659. temp2 = temp;
  660. temp >>= 8; /* ah */
  661. temp &= 0x0F;
  662. i = xgifb_reg_get(pVBInfo->P3c4, 0x0E);
  663. i &= 0xF0;
  664. i |= temp;
  665. xgifb_reg_set(pVBInfo->P3c4, 0x0E, i);
  666. temp = (unsigned char) temp2;
  667. temp &= 0xFF; /* al */
  668. xgifb_reg_set(pVBInfo->P3d4, 0x13, temp);
  669. /* SetDisplayUnit */
  670. temp2 = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
  671. temp2 &= InterlaceMode;
  672. if (temp2)
  673. DisplayUnit >>= 1;
  674. DisplayUnit <<= 5;
  675. ah = (DisplayUnit & 0xff00) >> 8;
  676. al = DisplayUnit & 0x00ff;
  677. if (al == 0)
  678. ah += 1;
  679. else
  680. ah += 2;
  681. if (HwDeviceExtension->jChipType >= XG20)
  682. if ((ModeNo == 0x4A) | (ModeNo == 0x49))
  683. ah -= 1;
  684. xgifb_reg_set(pVBInfo->P3c4, 0x10, ah);
  685. }
  686. static unsigned short XGI_GetVCLK2Ptr(unsigned short ModeIdIndex,
  687. unsigned short RefreshRateTableIndex,
  688. struct vb_device_info *pVBInfo)
  689. {
  690. unsigned short VCLKIndex, modeflag;
  691. /* si+Ext_ResInfo */
  692. modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  693. if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) { /*301b*/
  694. if (pVBInfo->LCDResInfo != Panel_1024x768)
  695. /* LCDXlat2VCLK */
  696. VCLKIndex = VCLK108_2_315 + 5;
  697. else
  698. VCLKIndex = VCLK65_315 + 2; /* LCDXlat1VCLK */
  699. } else if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
  700. if (pVBInfo->SetFlag & RPLLDIV2XO)
  701. VCLKIndex = TVCLKBASE_315_25 + HiTVVCLKDIV2;
  702. else
  703. VCLKIndex = TVCLKBASE_315_25 + HiTVVCLK;
  704. if (pVBInfo->SetFlag & TVSimuMode) {
  705. if (modeflag & Charx8Dot)
  706. VCLKIndex = TVCLKBASE_315_25 + HiTVSimuVCLK;
  707. else
  708. VCLKIndex = TVCLKBASE_315_25 + HiTVTextVCLK;
  709. }
  710. /* 301lv */
  711. if (pVBInfo->VBType & VB_SIS301LV) {
  712. if (pVBInfo->SetFlag & RPLLDIV2XO)
  713. VCLKIndex = YPbPr525iVCLK_2;
  714. else
  715. VCLKIndex = YPbPr525iVCLK;
  716. }
  717. } else if (pVBInfo->VBInfo & SetCRT2ToTV) {
  718. if (pVBInfo->SetFlag & RPLLDIV2XO)
  719. VCLKIndex = TVCLKBASE_315_25 + TVVCLKDIV2;
  720. else
  721. VCLKIndex = TVCLKBASE_315_25 + TVVCLK;
  722. } else { /* for CRT2 */
  723. /* di+Ext_CRTVCLK */
  724. VCLKIndex = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
  725. VCLKIndex &= IndexMask;
  726. }
  727. return VCLKIndex;
  728. }
  729. static void XGI_SetCRT1VCLK(unsigned short ModeIdIndex,
  730. struct xgi_hw_device_info *HwDeviceExtension,
  731. unsigned short RefreshRateTableIndex,
  732. struct vb_device_info *pVBInfo)
  733. {
  734. unsigned char index, data;
  735. unsigned short vclkindex;
  736. if ((pVBInfo->IF_DEF_LVDS == 0) &&
  737. (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV |
  738. VB_SIS302LV | VB_XGI301C)) &&
  739. (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) {
  740. vclkindex = XGI_GetVCLK2Ptr(ModeIdIndex, RefreshRateTableIndex,
  741. pVBInfo);
  742. data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
  743. xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
  744. data = XGI_VBVCLKData[vclkindex].Part4_A;
  745. xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
  746. data = XGI_VBVCLKData[vclkindex].Part4_B;
  747. xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
  748. xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
  749. } else {
  750. index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
  751. data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
  752. xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
  753. xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[index].SR2B);
  754. xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[index].SR2C);
  755. xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
  756. }
  757. if (HwDeviceExtension->jChipType >= XG20) {
  758. if (XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag &
  759. HalfDCLK) {
  760. data = xgifb_reg_get(pVBInfo->P3c4, 0x2B);
  761. xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
  762. data = xgifb_reg_get(pVBInfo->P3c4, 0x2C);
  763. index = data;
  764. index &= 0xE0;
  765. data &= 0x1F;
  766. data <<= 1;
  767. data += 1;
  768. data |= index;
  769. xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
  770. }
  771. }
  772. }
  773. static void XGI_SetXG21FPBits(struct vb_device_info *pVBInfo)
  774. {
  775. unsigned char temp;
  776. temp = xgifb_reg_get(pVBInfo->P3d4, 0x37); /* D[0] 1: 18bit */
  777. temp = (temp & 1) << 6;
  778. /* SR06[6] 18bit Dither */
  779. xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x40, temp);
  780. /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: dual 12bits */
  781. xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
  782. }
  783. static void XGI_SetCRT1FIFO(struct xgi_hw_device_info *HwDeviceExtension,
  784. struct vb_device_info *pVBInfo)
  785. {
  786. unsigned short data;
  787. data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
  788. data &= 0xfe;
  789. xgifb_reg_set(pVBInfo->P3c4, 0x3D, data); /* disable auto-threshold */
  790. xgifb_reg_set(pVBInfo->P3c4, 0x08, 0x34);
  791. data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
  792. data &= 0xC0;
  793. xgifb_reg_set(pVBInfo->P3c4, 0x09, data | 0x30);
  794. data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
  795. data |= 0x01;
  796. xgifb_reg_set(pVBInfo->P3c4, 0x3D, data);
  797. if (HwDeviceExtension->jChipType == XG21)
  798. XGI_SetXG21FPBits(pVBInfo); /* Fix SR9[7:6] can't read back */
  799. }
  800. static void XGI_SetVCLKState(struct xgi_hw_device_info *HwDeviceExtension,
  801. unsigned short RefreshRateTableIndex,
  802. struct vb_device_info *pVBInfo)
  803. {
  804. unsigned short data, data2 = 0;
  805. short VCLK;
  806. unsigned char index;
  807. index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
  808. index &= IndexMask;
  809. VCLK = XGI_VCLKData[index].CLOCK;
  810. data = xgifb_reg_get(pVBInfo->P3c4, 0x32);
  811. data &= 0xf3;
  812. if (VCLK >= 200)
  813. data |= 0x0c; /* VCLK > 200 */
  814. if (HwDeviceExtension->jChipType >= XG20)
  815. data &= ~0x04; /* 2 pixel mode */
  816. xgifb_reg_set(pVBInfo->P3c4, 0x32, data);
  817. if (HwDeviceExtension->jChipType < XG20) {
  818. data = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
  819. data &= 0xE7;
  820. if (VCLK < 200)
  821. data |= 0x10;
  822. xgifb_reg_set(pVBInfo->P3c4, 0x1F, data);
  823. }
  824. data2 = 0x00;
  825. xgifb_reg_and_or(pVBInfo->P3c4, 0x07, 0xFC, data2);
  826. if (HwDeviceExtension->jChipType >= XG27)
  827. xgifb_reg_and_or(pVBInfo->P3c4, 0x40, 0xFC, data2 & 0x03);
  828. }
  829. static void XGI_SetCRT1ModeRegs(struct xgi_hw_device_info *HwDeviceExtension,
  830. unsigned short ModeIdIndex,
  831. unsigned short RefreshRateTableIndex,
  832. struct vb_device_info *pVBInfo)
  833. {
  834. unsigned short data, data2, data3, infoflag = 0, modeflag, resindex,
  835. xres;
  836. modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  837. infoflag = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
  838. if (xgifb_reg_get(pVBInfo->P3d4, 0x31) & 0x01)
  839. xgifb_reg_and_or(pVBInfo->P3c4, 0x1F, 0x3F, 0x00);
  840. data = infoflag;
  841. data2 = 0;
  842. data2 |= 0x02;
  843. data3 = pVBInfo->ModeType - ModeVGA;
  844. data3 <<= 2;
  845. data2 |= data3;
  846. data &= InterlaceMode;
  847. if (data)
  848. data2 |= 0x20;
  849. xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x3F, data2);
  850. resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  851. xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
  852. data = 0x0000;
  853. if (infoflag & InterlaceMode) {
  854. if (xres == 1024)
  855. data = 0x0035;
  856. else if (xres == 1280)
  857. data = 0x0048;
  858. }
  859. xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFF, data);
  860. xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFC, 0);
  861. if (modeflag & HalfDCLK)
  862. xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xF7, 0x08);
  863. data2 = 0;
  864. if (modeflag & LineCompareOff)
  865. data2 |= 0x08;
  866. xgifb_reg_and_or(pVBInfo->P3c4, 0x0F, ~0x48, data2);
  867. data = 0x60;
  868. data = data ^ 0x60;
  869. data = data ^ 0xA0;
  870. xgifb_reg_and_or(pVBInfo->P3c4, 0x21, 0x1F, data);
  871. XGI_SetVCLKState(HwDeviceExtension, RefreshRateTableIndex, pVBInfo);
  872. data = xgifb_reg_get(pVBInfo->P3d4, 0x31);
  873. if (HwDeviceExtension->jChipType == XG27) {
  874. if (data & 0x40)
  875. data = 0x2c;
  876. else
  877. data = 0x6c;
  878. xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
  879. xgifb_reg_or(pVBInfo->P3d4, 0x51, 0x10);
  880. } else if (HwDeviceExtension->jChipType >= XG20) {
  881. if (data & 0x40)
  882. data = 0x33;
  883. else
  884. data = 0x73;
  885. xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
  886. xgifb_reg_set(pVBInfo->P3d4, 0x51, 0x02);
  887. } else {
  888. if (data & 0x40)
  889. data = 0x2c;
  890. else
  891. data = 0x6c;
  892. xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
  893. }
  894. }
  895. static void XGI_WriteDAC(unsigned short dl,
  896. unsigned short ah,
  897. unsigned short al,
  898. unsigned short dh,
  899. struct vb_device_info *pVBInfo)
  900. {
  901. unsigned short bh, bl;
  902. bh = ah;
  903. bl = al;
  904. if (dl != 0) {
  905. swap(bh, dh);
  906. if (dl == 1)
  907. swap(bl, dh);
  908. else
  909. swap(bl, bh);
  910. }
  911. outb((unsigned short) dh, pVBInfo->P3c9);
  912. outb((unsigned short) bh, pVBInfo->P3c9);
  913. outb((unsigned short) bl, pVBInfo->P3c9);
  914. }
  915. static void XGI_LoadDAC(struct vb_device_info *pVBInfo)
  916. {
  917. unsigned short data, data2, i, k, m, n, o, si, di, bx, dl, al, ah, dh;
  918. const unsigned short *table = XGINew_VGA_DAC;
  919. outb(0xFF, pVBInfo->P3c6);
  920. outb(0x00, pVBInfo->P3c8);
  921. for (i = 0; i < 16; i++) {
  922. data = table[i];
  923. for (k = 0; k < 3; k++) {
  924. data2 = 0;
  925. if (data & 0x01)
  926. data2 = 0x2A;
  927. if (data & 0x02)
  928. data2 += 0x15;
  929. outb(data2, pVBInfo->P3c9);
  930. data >>= 2;
  931. }
  932. }
  933. for (i = 16; i < 32; i++) {
  934. data = table[i];
  935. for (k = 0; k < 3; k++)
  936. outb(data, pVBInfo->P3c9);
  937. }
  938. si = 32;
  939. for (m = 0; m < 9; m++) {
  940. di = si;
  941. bx = si + 0x04;
  942. dl = 0;
  943. for (n = 0; n < 3; n++) {
  944. for (o = 0; o < 5; o++) {
  945. dh = table[si];
  946. ah = table[di];
  947. al = table[bx];
  948. si++;
  949. XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
  950. }
  951. si -= 2;
  952. for (o = 0; o < 3; o++) {
  953. dh = table[bx];
  954. ah = table[di];
  955. al = table[si];
  956. si--;
  957. XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
  958. }
  959. dl++;
  960. }
  961. si += 5;
  962. }
  963. }
  964. static void XGI_GetLVDSResInfo(unsigned short ModeIdIndex,
  965. struct vb_device_info *pVBInfo)
  966. {
  967. unsigned short resindex, xres, yres, modeflag;
  968. /* si+Ext_ResInfo */
  969. modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  970. /* si+Ext_ResInfo */
  971. resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  972. xres = XGI330_ModeResInfo[resindex].HTotal;
  973. yres = XGI330_ModeResInfo[resindex].VTotal;
  974. if (modeflag & HalfDCLK)
  975. xres <<= 1;
  976. if (modeflag & DoubleScanMode)
  977. yres <<= 1;
  978. if (xres == 720)
  979. xres = 640;
  980. pVBInfo->VGAHDE = xres;
  981. pVBInfo->HDE = xres;
  982. pVBInfo->VGAVDE = yres;
  983. pVBInfo->VDE = yres;
  984. }
  985. static void const *XGI_GetLcdPtr(struct XGI330_LCDDataTablStruct const *table,
  986. unsigned short ModeIdIndex,
  987. struct vb_device_info *pVBInfo)
  988. {
  989. unsigned short i, tempdx, tempbx, modeflag;
  990. tempbx = 0;
  991. modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  992. i = 0;
  993. while (table[i].PANELID != 0xff) {
  994. tempdx = pVBInfo->LCDResInfo;
  995. if (tempbx & 0x0080) { /* OEMUtil */
  996. tempbx &= (~0x0080);
  997. tempdx = pVBInfo->LCDTypeInfo;
  998. }
  999. if (pVBInfo->LCDInfo & EnableScalingLCD)
  1000. tempdx &= (~PanelResInfo);
  1001. if (table[i].PANELID == tempdx) {
  1002. tempbx = table[i].MASK;
  1003. tempdx = pVBInfo->LCDInfo;
  1004. if (modeflag & HalfDCLK)
  1005. tempdx |= SetLCDLowResolution;
  1006. tempbx &= tempdx;
  1007. if (tempbx == table[i].CAP)
  1008. break;
  1009. }
  1010. i++;
  1011. }
  1012. return table[i].DATAPTR;
  1013. }
  1014. static struct SiS_TVData const *XGI_GetTVPtr(unsigned short ModeIdIndex,
  1015. unsigned short RefreshRateTableIndex,
  1016. struct vb_device_info *pVBInfo)
  1017. {
  1018. unsigned short i, tempdx, tempal, modeflag;
  1019. modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  1020. tempal = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  1021. tempal = tempal & 0x3f;
  1022. tempdx = pVBInfo->TVInfo;
  1023. if (pVBInfo->VBInfo & SetInSlaveMode)
  1024. tempdx = tempdx | SetTVLockMode;
  1025. if (modeflag & HalfDCLK)
  1026. tempdx = tempdx | SetTVLowResolution;
  1027. i = 0;
  1028. while (XGI_TVDataTable[i].MASK != 0xffff) {
  1029. if ((tempdx & XGI_TVDataTable[i].MASK) ==
  1030. XGI_TVDataTable[i].CAP)
  1031. break;
  1032. i++;
  1033. }
  1034. return &XGI_TVDataTable[i].DATAPTR[tempal];
  1035. }
  1036. static void XGI_GetLVDSData(unsigned short ModeIdIndex,
  1037. struct vb_device_info *pVBInfo)
  1038. {
  1039. struct SiS_LVDSData const *LCDPtr;
  1040. if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
  1041. return;
  1042. LCDPtr = XGI_GetLcdPtr(XGI_EPLLCDDataPtr, ModeIdIndex, pVBInfo);
  1043. pVBInfo->VGAHT = LCDPtr->VGAHT;
  1044. pVBInfo->VGAVT = LCDPtr->VGAVT;
  1045. pVBInfo->HT = LCDPtr->LCDHT;
  1046. pVBInfo->VT = LCDPtr->LCDVT;
  1047. if (pVBInfo->LCDInfo & (SetLCDtoNonExpanding | EnableScalingLCD))
  1048. return;
  1049. if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
  1050. (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
  1051. pVBInfo->HDE = 1024;
  1052. pVBInfo->VDE = 768;
  1053. } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
  1054. (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
  1055. pVBInfo->HDE = 1280;
  1056. pVBInfo->VDE = 1024;
  1057. } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
  1058. pVBInfo->HDE = 1400;
  1059. pVBInfo->VDE = 1050;
  1060. } else {
  1061. pVBInfo->HDE = 1600;
  1062. pVBInfo->VDE = 1200;
  1063. }
  1064. }
  1065. static void XGI_ModCRT1Regs(unsigned short ModeIdIndex,
  1066. struct xgi_hw_device_info *HwDeviceExtension,
  1067. struct vb_device_info *pVBInfo)
  1068. {
  1069. unsigned short i;
  1070. struct XGI_LVDSCRT1HDataStruct const *LCDPtr = NULL;
  1071. struct XGI_LVDSCRT1VDataStruct const *LCDPtr1 = NULL;
  1072. if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
  1073. LCDPtr = XGI_GetLcdPtr(xgifb_epllcd_crt1_h, ModeIdIndex,
  1074. pVBInfo);
  1075. for (i = 0; i < 8; i++)
  1076. pVBInfo->TimingH.data[i] = LCDPtr[0].Reg[i];
  1077. }
  1078. XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
  1079. if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
  1080. LCDPtr1 = XGI_GetLcdPtr(xgifb_epllcd_crt1_v, ModeIdIndex,
  1081. pVBInfo);
  1082. for (i = 0; i < 7; i++)
  1083. pVBInfo->TimingV.data[i] = LCDPtr1[0].Reg[i];
  1084. }
  1085. XGI_SetCRT1Timing_V(ModeIdIndex, pVBInfo);
  1086. }
  1087. static unsigned short XGI_GetLCDCapPtr(struct vb_device_info *pVBInfo)
  1088. {
  1089. unsigned char tempal, tempah, tempbl, i;
  1090. tempah = xgifb_reg_get(pVBInfo->P3d4, 0x36);
  1091. tempal = tempah & 0x0F;
  1092. tempah = tempah & 0xF0;
  1093. i = 0;
  1094. tempbl = pVBInfo->LCDCapList[i].LCD_ID;
  1095. while (tempbl != 0xFF) {
  1096. if (tempbl & 0x80) { /* OEMUtil */
  1097. tempal = tempah;
  1098. tempbl = tempbl & ~(0x80);
  1099. }
  1100. if (tempal == tempbl)
  1101. break;
  1102. i++;
  1103. tempbl = pVBInfo->LCDCapList[i].LCD_ID;
  1104. }
  1105. return i;
  1106. }
  1107. static unsigned short XGI_GetLCDCapPtr1(struct vb_device_info *pVBInfo)
  1108. {
  1109. unsigned short tempah, tempal, tempbl, i;
  1110. tempal = pVBInfo->LCDResInfo;
  1111. tempah = pVBInfo->LCDTypeInfo;
  1112. i = 0;
  1113. tempbl = pVBInfo->LCDCapList[i].LCD_ID;
  1114. while (tempbl != 0xFF) {
  1115. if ((tempbl & 0x80) && (tempbl != 0x80)) {
  1116. tempal = tempah;
  1117. tempbl &= ~0x80;
  1118. }
  1119. if (tempal == tempbl)
  1120. break;
  1121. i++;
  1122. tempbl = pVBInfo->LCDCapList[i].LCD_ID;
  1123. }
  1124. if (tempbl == 0xFF) {
  1125. pVBInfo->LCDResInfo = Panel_1024x768;
  1126. pVBInfo->LCDTypeInfo = 0;
  1127. i = 0;
  1128. }
  1129. return i;
  1130. }
  1131. static void XGI_GetLCDSync(unsigned short *HSyncWidth,
  1132. unsigned short *VSyncWidth,
  1133. struct vb_device_info *pVBInfo)
  1134. {
  1135. unsigned short Index;
  1136. Index = XGI_GetLCDCapPtr(pVBInfo);
  1137. *HSyncWidth = pVBInfo->LCDCapList[Index].LCD_HSyncWidth;
  1138. *VSyncWidth = pVBInfo->LCDCapList[Index].LCD_VSyncWidth;
  1139. }
  1140. static void XGI_SetLVDSRegs(unsigned short ModeIdIndex,
  1141. struct vb_device_info *pVBInfo)
  1142. {
  1143. unsigned short tempbx, tempax, tempcx, tempdx, push1, push2, modeflag;
  1144. unsigned long temp, temp1, temp2, temp3, push3;
  1145. struct XGI330_LCDDataDesStruct2 const *LCDPtr1 = NULL;
  1146. modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  1147. LCDPtr1 = XGI_GetLcdPtr(XGI_EPLLCDDesDataPtr, ModeIdIndex, pVBInfo);
  1148. XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
  1149. push1 = tempbx;
  1150. push2 = tempax;
  1151. /* GetLCDResInfo */
  1152. if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
  1153. (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
  1154. tempax = 1024;
  1155. tempbx = 768;
  1156. } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
  1157. (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
  1158. tempax = 1280;
  1159. tempbx = 1024;
  1160. } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
  1161. tempax = 1400;
  1162. tempbx = 1050;
  1163. } else {
  1164. tempax = 1600;
  1165. tempbx = 1200;
  1166. }
  1167. if (pVBInfo->LCDInfo & SetLCDtoNonExpanding) {
  1168. pVBInfo->HDE = tempax;
  1169. pVBInfo->VDE = tempbx;
  1170. pVBInfo->VGAHDE = tempax;
  1171. pVBInfo->VGAVDE = tempbx;
  1172. }
  1173. tempax = pVBInfo->HT;
  1174. tempbx = LCDPtr1->LCDHDES;
  1175. tempcx = pVBInfo->HDE;
  1176. tempbx = tempbx & 0x0fff;
  1177. tempcx += tempbx;
  1178. if (tempcx >= tempax)
  1179. tempcx -= tempax;
  1180. xgifb_reg_set(pVBInfo->Part1Port, 0x1A, tempbx & 0x07);
  1181. tempcx >>= 3;
  1182. tempbx >>= 3;
  1183. xgifb_reg_set(pVBInfo->Part1Port, 0x16,
  1184. (unsigned short) (tempbx & 0xff));
  1185. xgifb_reg_set(pVBInfo->Part1Port, 0x17,
  1186. (unsigned short) (tempcx & 0xff));
  1187. tempax = pVBInfo->HT;
  1188. tempbx = LCDPtr1->LCDHRS;
  1189. tempcx = push2;
  1190. if (pVBInfo->LCDInfo & EnableScalingLCD)
  1191. tempcx = LCDPtr1->LCDHSync;
  1192. tempcx += tempbx;
  1193. if (tempcx >= tempax)
  1194. tempcx -= tempax;
  1195. tempax = tempbx & 0x07;
  1196. tempax >>= 5;
  1197. tempcx >>= 3;
  1198. tempbx >>= 3;
  1199. tempcx &= 0x1f;
  1200. tempax |= tempcx;
  1201. xgifb_reg_set(pVBInfo->Part1Port, 0x15, tempax);
  1202. xgifb_reg_set(pVBInfo->Part1Port, 0x14,
  1203. (unsigned short) (tempbx & 0xff));
  1204. tempax = pVBInfo->VT;
  1205. tempbx = LCDPtr1->LCDVDES;
  1206. tempcx = pVBInfo->VDE;
  1207. tempbx = tempbx & 0x0fff;
  1208. tempcx += tempbx;
  1209. if (tempcx >= tempax)
  1210. tempcx -= tempax;
  1211. xgifb_reg_set(pVBInfo->Part1Port, 0x1b,
  1212. (unsigned short) (tempbx & 0xff));
  1213. xgifb_reg_set(pVBInfo->Part1Port, 0x1c,
  1214. (unsigned short) (tempcx & 0xff));
  1215. tempbx = (tempbx >> 8) & 0x07;
  1216. tempcx = (tempcx >> 8) & 0x07;
  1217. xgifb_reg_set(pVBInfo->Part1Port, 0x1d,
  1218. (unsigned short) ((tempcx << 3)
  1219. | tempbx));
  1220. tempax = pVBInfo->VT;
  1221. tempbx = LCDPtr1->LCDVRS;
  1222. tempcx = push1;
  1223. if (pVBInfo->LCDInfo & EnableScalingLCD)
  1224. tempcx = LCDPtr1->LCDVSync;
  1225. tempcx += tempbx;
  1226. if (tempcx >= tempax)
  1227. tempcx -= tempax;
  1228. xgifb_reg_set(pVBInfo->Part1Port, 0x18,
  1229. (unsigned short) (tempbx & 0xff));
  1230. xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, ~0x0f,
  1231. (unsigned short) (tempcx & 0x0f));
  1232. tempax = ((tempbx >> 8) & 0x07) << 3;
  1233. tempbx = pVBInfo->VGAVDE;
  1234. if (tempbx != pVBInfo->VDE)
  1235. tempax |= 0x40;
  1236. if (pVBInfo->LCDInfo & XGI_EnableLVDSDDA)
  1237. tempax |= 0x40;
  1238. xgifb_reg_and_or(pVBInfo->Part1Port, 0x1a, 0x07,
  1239. tempax);
  1240. tempbx = pVBInfo->VDE;
  1241. tempax = pVBInfo->VGAVDE;
  1242. temp = tempax; /* 0430 ylshieh */
  1243. temp1 = (temp << 18) / tempbx;
  1244. tempdx = (unsigned short) ((temp << 18) % tempbx);
  1245. if (tempdx != 0)
  1246. temp1 += 1;
  1247. temp2 = temp1;
  1248. push3 = temp2;
  1249. xgifb_reg_set(pVBInfo->Part1Port, 0x37,
  1250. (unsigned short) (temp2 & 0xff));
  1251. xgifb_reg_set(pVBInfo->Part1Port, 0x36,
  1252. (unsigned short) ((temp2 >> 8) & 0xff));
  1253. tempbx = (unsigned short) (temp2 >> 16);
  1254. tempax = tempbx & 0x03;
  1255. tempbx = pVBInfo->VGAVDE;
  1256. if (tempbx == pVBInfo->VDE)
  1257. tempax |= 0x04;
  1258. xgifb_reg_set(pVBInfo->Part1Port, 0x35, tempax);
  1259. if (pVBInfo->VBType & VB_XGI301C) {
  1260. temp2 = push3;
  1261. xgifb_reg_set(pVBInfo->Part4Port,
  1262. 0x3c,
  1263. (unsigned short) (temp2 & 0xff));
  1264. xgifb_reg_set(pVBInfo->Part4Port,
  1265. 0x3b,
  1266. (unsigned short) ((temp2 >> 8) &
  1267. 0xff));
  1268. tempbx = (unsigned short) (temp2 >> 16);
  1269. xgifb_reg_and_or(pVBInfo->Part4Port, 0x3a,
  1270. ~0xc0,
  1271. (unsigned short) ((tempbx &
  1272. 0xff) << 6));
  1273. tempcx = pVBInfo->VGAVDE;
  1274. if (tempcx == pVBInfo->VDE)
  1275. xgifb_reg_and_or(pVBInfo->Part4Port,
  1276. 0x30, ~0x0c, 0x00);
  1277. else
  1278. xgifb_reg_and_or(pVBInfo->Part4Port,
  1279. 0x30, ~0x0c, 0x08);
  1280. }
  1281. tempcx = pVBInfo->VGAHDE;
  1282. tempbx = pVBInfo->HDE;
  1283. temp1 = tempcx << 16;
  1284. tempax = (unsigned short) (temp1 / tempbx);
  1285. if ((tempbx & 0xffff) == (tempcx & 0xffff))
  1286. tempax = 65535;
  1287. temp3 = tempax;
  1288. temp1 = pVBInfo->VGAHDE << 16;
  1289. temp1 /= temp3;
  1290. temp3 <<= 16;
  1291. temp1 -= 1;
  1292. temp3 = (temp3 & 0xffff0000) + (temp1 & 0xffff);
  1293. tempax = (unsigned short) (temp3 & 0xff);
  1294. xgifb_reg_set(pVBInfo->Part1Port, 0x1f, tempax);
  1295. temp1 = pVBInfo->VGAVDE << 18;
  1296. temp1 = temp1 / push3;
  1297. tempbx = (unsigned short) (temp1 & 0xffff);
  1298. if (pVBInfo->LCDResInfo == Panel_1024x768)
  1299. tempbx -= 1;
  1300. tempax = ((tempbx >> 8) & 0xff) << 3;
  1301. tempax |= (unsigned short) ((temp3 >> 8) & 0x07);
  1302. xgifb_reg_set(pVBInfo->Part1Port, 0x20,
  1303. (unsigned short) (tempax & 0xff));
  1304. xgifb_reg_set(pVBInfo->Part1Port, 0x21,
  1305. (unsigned short) (tempbx & 0xff));
  1306. temp3 >>= 16;
  1307. if (modeflag & HalfDCLK)
  1308. temp3 >>= 1;
  1309. xgifb_reg_set(pVBInfo->Part1Port, 0x22,
  1310. (unsigned short) ((temp3 >> 8) & 0xff));
  1311. xgifb_reg_set(pVBInfo->Part1Port, 0x23,
  1312. (unsigned short) (temp3 & 0xff));
  1313. }
  1314. /* --------------------------------------------------------------------- */
  1315. /* Function : XGI_GETLCDVCLKPtr */
  1316. /* Input : */
  1317. /* Output : al -> VCLK Index */
  1318. /* Description : */
  1319. /* --------------------------------------------------------------------- */
  1320. static void XGI_GetLCDVCLKPtr(unsigned char *di_0, unsigned char *di_1,
  1321. struct vb_device_info *pVBInfo)
  1322. {
  1323. unsigned short index;
  1324. if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
  1325. index = XGI_GetLCDCapPtr1(pVBInfo);
  1326. if (pVBInfo->VBInfo & SetCRT2ToLCD) { /* LCDB */
  1327. *di_0 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData1;
  1328. *di_1 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData2;
  1329. } else { /* LCDA */
  1330. *di_0 = pVBInfo->LCDCapList[index].LCDA_VCLKData1;
  1331. *di_1 = pVBInfo->LCDCapList[index].LCDA_VCLKData2;
  1332. }
  1333. }
  1334. }
  1335. static unsigned char XGI_GetVCLKPtr(unsigned short RefreshRateTableIndex,
  1336. unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
  1337. {
  1338. unsigned short index, modeflag;
  1339. unsigned char tempal;
  1340. /* si+Ext_ResInfo */
  1341. modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  1342. if ((pVBInfo->SetFlag & ProgrammingCRT2) &&
  1343. (!(pVBInfo->LCDInfo & EnableScalingLCD))) { /* {LCDA/LCDB} */
  1344. index = XGI_GetLCDCapPtr(pVBInfo);
  1345. tempal = pVBInfo->LCDCapList[index].LCD_VCLK;
  1346. if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
  1347. return tempal;
  1348. /* {TV} */
  1349. if (pVBInfo->VBType &
  1350. (VB_SIS301B |
  1351. VB_SIS302B |
  1352. VB_SIS301LV |
  1353. VB_SIS302LV |
  1354. VB_XGI301C)) {
  1355. if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
  1356. tempal = TVCLKBASE_315 + HiTVVCLKDIV2;
  1357. if (!(pVBInfo->TVInfo & RPLLDIV2XO))
  1358. tempal = TVCLKBASE_315 + HiTVVCLK;
  1359. if (pVBInfo->TVInfo & TVSimuMode) {
  1360. tempal = TVCLKBASE_315 + HiTVSimuVCLK;
  1361. if (!(modeflag & Charx8Dot))
  1362. tempal = TVCLKBASE_315 +
  1363. HiTVTextVCLK;
  1364. }
  1365. return tempal;
  1366. }
  1367. if (pVBInfo->TVInfo & TVSetYPbPr750p) {
  1368. tempal = XGI_YPbPr750pVCLK;
  1369. return tempal;
  1370. }
  1371. if (pVBInfo->TVInfo & TVSetYPbPr525p) {
  1372. tempal = YPbPr525pVCLK;
  1373. return tempal;
  1374. }
  1375. tempal = NTSC1024VCLK;
  1376. if (!(pVBInfo->TVInfo & NTSC1024x768)) {
  1377. tempal = TVCLKBASE_315 + TVVCLKDIV2;
  1378. if (!(pVBInfo->TVInfo & RPLLDIV2XO))
  1379. tempal = TVCLKBASE_315 + TVVCLK;
  1380. }
  1381. if (pVBInfo->VBInfo & SetCRT2ToTV)
  1382. return tempal;
  1383. }
  1384. } /* {End of VB} */
  1385. inb((pVBInfo->P3ca + 0x02));
  1386. tempal = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
  1387. return tempal;
  1388. }
  1389. static void XGI_GetVCLKLen(unsigned char tempal, unsigned char *di_0,
  1390. unsigned char *di_1, struct vb_device_info *pVBInfo)
  1391. {
  1392. if (pVBInfo->VBType & (VB_SIS301 | VB_SIS301B | VB_SIS302B
  1393. | VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
  1394. if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) &&
  1395. (pVBInfo->SetFlag & ProgrammingCRT2)) {
  1396. *di_0 = XGI_VBVCLKData[tempal].Part4_A;
  1397. *di_1 = XGI_VBVCLKData[tempal].Part4_B;
  1398. }
  1399. } else {
  1400. *di_0 = XGI_VCLKData[tempal].SR2B;
  1401. *di_1 = XGI_VCLKData[tempal].SR2C;
  1402. }
  1403. }
  1404. static void XGI_SetCRT2ECLK(unsigned short ModeIdIndex,
  1405. unsigned short RefreshRateTableIndex,
  1406. struct vb_device_info *pVBInfo)
  1407. {
  1408. unsigned char di_0, di_1, tempal;
  1409. int i;
  1410. tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeIdIndex, pVBInfo);
  1411. XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
  1412. XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
  1413. for (i = 0; i < 4; i++) {
  1414. xgifb_reg_and_or(pVBInfo->P3d4, 0x31, ~0x30,
  1415. (unsigned short) (0x10 * i));
  1416. if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
  1417. && (!(pVBInfo->VBInfo & SetInSlaveMode))) {
  1418. xgifb_reg_set(pVBInfo->P3c4, 0x2e, di_0);
  1419. xgifb_reg_set(pVBInfo->P3c4, 0x2f, di_1);
  1420. } else {
  1421. xgifb_reg_set(pVBInfo->P3c4, 0x2b, di_0);
  1422. xgifb_reg_set(pVBInfo->P3c4, 0x2c, di_1);
  1423. }
  1424. }
  1425. }
  1426. static void XGI_UpdateModeInfo(struct vb_device_info *pVBInfo)
  1427. {
  1428. unsigned short tempcl, tempch, temp, tempbl, tempax;
  1429. if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
  1430. | VB_SIS302LV | VB_XGI301C)) {
  1431. tempcl = 0;
  1432. tempch = 0;
  1433. temp = xgifb_reg_get(pVBInfo->P3c4, 0x01);
  1434. if (!(temp & 0x20)) {
  1435. temp = xgifb_reg_get(pVBInfo->P3d4, 0x17);
  1436. if (temp & 0x80) {
  1437. temp = xgifb_reg_get(pVBInfo->P3d4, 0x53);
  1438. if (!(temp & 0x40))
  1439. tempcl |= ActiveCRT1;
  1440. }
  1441. }
  1442. temp = xgifb_reg_get(pVBInfo->Part1Port, 0x2e);
  1443. temp &= 0x0f;
  1444. if (!(temp == 0x08)) {
  1445. /* Check ChannelA */
  1446. tempax = xgifb_reg_get(pVBInfo->Part1Port, 0x13);
  1447. if (tempax & 0x04)
  1448. tempcl = tempcl | ActiveLCD;
  1449. temp &= 0x05;
  1450. if (!(tempcl & ActiveLCD))
  1451. if (temp == 0x01)
  1452. tempcl |= ActiveCRT2;
  1453. if (temp == 0x04)
  1454. tempcl |= ActiveLCD;
  1455. if (temp == 0x05) {
  1456. temp = xgifb_reg_get(pVBInfo->Part2Port, 0x00);
  1457. if (!(temp & 0x08))
  1458. tempch |= ActiveAVideo;
  1459. if (!(temp & 0x04))
  1460. tempch |= ActiveSVideo;
  1461. if (temp & 0x02)
  1462. tempch |= ActiveSCART;
  1463. if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
  1464. if (temp & 0x01)
  1465. tempch |= ActiveHiTV;
  1466. }
  1467. if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
  1468. temp = xgifb_reg_get(
  1469. pVBInfo->Part2Port,
  1470. 0x4d);
  1471. if (temp & 0x10)
  1472. tempch |= ActiveYPbPr;
  1473. }
  1474. if (tempch != 0)
  1475. tempcl |= ActiveTV;
  1476. }
  1477. }
  1478. temp = xgifb_reg_get(pVBInfo->P3d4, 0x3d);
  1479. if (tempcl & ActiveLCD) {
  1480. if ((pVBInfo->SetFlag & ReserveTVOption)) {
  1481. if (temp & ActiveTV)
  1482. tempcl |= ActiveTV;
  1483. }
  1484. }
  1485. temp = tempcl;
  1486. tempbl = ~XGI_ModeSwitchStatus;
  1487. xgifb_reg_and_or(pVBInfo->P3d4, 0x3d, tempbl, temp);
  1488. if (!(pVBInfo->SetFlag & ReserveTVOption))
  1489. xgifb_reg_set(pVBInfo->P3d4, 0x3e, tempch);
  1490. }
  1491. }
  1492. void XGI_GetVBType(struct vb_device_info *pVBInfo)
  1493. {
  1494. unsigned short flag, tempbx, tempah;
  1495. tempbx = VB_SIS302B;
  1496. flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
  1497. if (flag == 0x02)
  1498. goto finish;
  1499. tempbx = VB_SIS301;
  1500. flag = xgifb_reg_get(pVBInfo->Part4Port, 0x01);
  1501. if (flag < 0xB0)
  1502. goto finish;
  1503. tempbx = VB_SIS301B;
  1504. if (flag < 0xC0)
  1505. goto bigger_than_0xB0;
  1506. tempbx = VB_XGI301C;
  1507. if (flag < 0xD0)
  1508. goto bigger_than_0xB0;
  1509. tempbx = VB_SIS301LV;
  1510. if (flag < 0xE0)
  1511. goto bigger_than_0xB0;
  1512. tempbx = VB_SIS302LV;
  1513. tempah = xgifb_reg_get(pVBInfo->Part4Port, 0x39);
  1514. if (tempah != 0xFF)
  1515. tempbx = VB_XGI301C;
  1516. bigger_than_0xB0:
  1517. if (tempbx & (VB_SIS301B | VB_SIS302B)) {
  1518. flag = xgifb_reg_get(pVBInfo->Part4Port, 0x23);
  1519. if (!(flag & 0x02))
  1520. tempbx = tempbx | VB_NoLCD;
  1521. }
  1522. finish:
  1523. pVBInfo->VBType = tempbx;
  1524. }
  1525. static void XGI_GetVBInfo(unsigned short ModeIdIndex,
  1526. struct vb_device_info *pVBInfo)
  1527. {
  1528. unsigned short tempax, push, tempbx, temp, modeflag;
  1529. modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  1530. pVBInfo->SetFlag = 0;
  1531. pVBInfo->ModeType = modeflag & ModeTypeMask;
  1532. tempbx = 0;
  1533. if (!(pVBInfo->VBType & 0xFFFF))
  1534. return;
  1535. /* Check Display Device */
  1536. temp = xgifb_reg_get(pVBInfo->P3d4, 0x30);
  1537. tempbx = tempbx | temp;
  1538. temp = xgifb_reg_get(pVBInfo->P3d4, 0x31);
  1539. push = temp;
  1540. push <<= 8;
  1541. tempax = temp << 8;
  1542. tempbx = tempbx | tempax;
  1543. temp = (SetCRT2ToDualEdge | SetCRT2ToYPbPr525750 | XGI_SetCRT2ToLCDA
  1544. | SetInSlaveMode | DisableCRT2Display);
  1545. temp = 0xFFFF ^ temp;
  1546. tempbx &= temp;
  1547. temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
  1548. if (pVBInfo->VBType & (VB_SIS302B | VB_SIS301LV | VB_SIS302LV |
  1549. VB_XGI301C)) {
  1550. if (temp & EnableDualEdge) {
  1551. tempbx |= SetCRT2ToDualEdge;
  1552. if (temp & SetToLCDA)
  1553. tempbx |= XGI_SetCRT2ToLCDA;
  1554. }
  1555. }
  1556. if (pVBInfo->VBType & (VB_SIS301LV|VB_SIS302LV|VB_XGI301C)) {
  1557. if (temp & SetYPbPr) {
  1558. /* shampoo add for new scratch */
  1559. temp = xgifb_reg_get(pVBInfo->P3d4, 0x35);
  1560. temp &= YPbPrMode;
  1561. tempbx |= SetCRT2ToHiVision;
  1562. if (temp != YPbPrMode1080i) {
  1563. tempbx &= (~SetCRT2ToHiVision);
  1564. tempbx |= SetCRT2ToYPbPr525750;
  1565. }
  1566. }
  1567. }
  1568. tempax = push; /* restore CR31 */
  1569. temp = 0x09FC;
  1570. if (!(tempbx & temp)) {
  1571. tempax |= DisableCRT2Display;
  1572. tempbx = 0;
  1573. }
  1574. if (!(pVBInfo->VBType & VB_NoLCD)) {
  1575. if (tempbx & XGI_SetCRT2ToLCDA) {
  1576. if (tempbx & SetSimuScanMode)
  1577. tempbx &= (~(SetCRT2ToLCD | SetCRT2ToRAMDAC |
  1578. SwitchCRT2));
  1579. else
  1580. tempbx &= (~(SetCRT2ToLCD | SetCRT2ToRAMDAC |
  1581. SetCRT2ToTV | SwitchCRT2));
  1582. }
  1583. }
  1584. /* shampoo add */
  1585. /* for driver abnormal */
  1586. if (!(tempbx & (SwitchCRT2 | SetSimuScanMode))) {
  1587. if (tempbx & SetCRT2ToRAMDAC) {
  1588. tempbx &= (0xFF00 | SetCRT2ToRAMDAC |
  1589. SwitchCRT2 | SetSimuScanMode);
  1590. tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
  1591. }
  1592. }
  1593. if (!(pVBInfo->VBType & VB_NoLCD)) {
  1594. if (tempbx & SetCRT2ToLCD) {
  1595. tempbx &= (0xFF00 | SetCRT2ToLCD | SwitchCRT2 |
  1596. SetSimuScanMode);
  1597. tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
  1598. }
  1599. }
  1600. if (tempbx & SetCRT2ToSCART) {
  1601. tempbx &= (0xFF00 | SetCRT2ToSCART | SwitchCRT2 |
  1602. SetSimuScanMode);
  1603. tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
  1604. }
  1605. if (tempbx & SetCRT2ToYPbPr525750)
  1606. tempbx &= (0xFF00 | SwitchCRT2 | SetSimuScanMode);
  1607. if (tempbx & SetCRT2ToHiVision)
  1608. tempbx &= (0xFF00 | SetCRT2ToHiVision | SwitchCRT2 |
  1609. SetSimuScanMode);
  1610. if (tempax & DisableCRT2Display) { /* Set Display Device Info */
  1611. if (!(tempbx & (SwitchCRT2 | SetSimuScanMode)))
  1612. tempbx = DisableCRT2Display;
  1613. }
  1614. if (!(tempbx & DisableCRT2Display)) {
  1615. if ((!(tempbx & DriverMode)) || (!(modeflag & CRT2Mode))) {
  1616. if (!(tempbx & XGI_SetCRT2ToLCDA))
  1617. tempbx |= (SetInSlaveMode | SetSimuScanMode);
  1618. }
  1619. /* LCD+TV can't support in slave mode
  1620. * (Force LCDA+TV->LCDB) */
  1621. if ((tempbx & SetInSlaveMode) && (tempbx & XGI_SetCRT2ToLCDA)) {
  1622. tempbx ^= (SetCRT2ToLCD | XGI_SetCRT2ToLCDA |
  1623. SetCRT2ToDualEdge);
  1624. pVBInfo->SetFlag |= ReserveTVOption;
  1625. }
  1626. }
  1627. pVBInfo->VBInfo = tempbx;
  1628. }
  1629. static void XGI_GetTVInfo(unsigned short ModeIdIndex,
  1630. struct vb_device_info *pVBInfo)
  1631. {
  1632. unsigned short tempbx = 0, resinfo = 0, modeflag, index1;
  1633. if (pVBInfo->VBInfo & SetCRT2ToTV) {
  1634. modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  1635. resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  1636. tempbx = xgifb_reg_get(pVBInfo->P3d4, 0x35);
  1637. if (tempbx & TVSetPAL) {
  1638. tempbx &= (SetCHTVOverScan |
  1639. TVSetPALM |
  1640. TVSetPALN |
  1641. TVSetPAL);
  1642. if (tempbx & TVSetPALM)
  1643. /* set to NTSC if PAL-M */
  1644. tempbx &= ~TVSetPAL;
  1645. } else
  1646. tempbx &= (SetCHTVOverScan |
  1647. TVSetNTSCJ |
  1648. TVSetPAL);
  1649. if (pVBInfo->VBInfo & SetCRT2ToSCART)
  1650. tempbx |= TVSetPAL;
  1651. if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
  1652. index1 = xgifb_reg_get(pVBInfo->P3d4, 0x35);
  1653. index1 &= YPbPrMode;
  1654. if (index1 == YPbPrMode525i)
  1655. tempbx |= TVSetYPbPr525i;
  1656. if (index1 == YPbPrMode525p)
  1657. tempbx = tempbx | TVSetYPbPr525p;
  1658. if (index1 == YPbPrMode750p)
  1659. tempbx = tempbx | TVSetYPbPr750p;
  1660. }
  1661. if (pVBInfo->VBInfo & SetCRT2ToHiVision)
  1662. tempbx = tempbx | TVSetHiVision | TVSetPAL;
  1663. if ((pVBInfo->VBInfo & SetInSlaveMode) &&
  1664. (!(pVBInfo->VBInfo & SetNotSimuMode)))
  1665. tempbx |= TVSimuMode;
  1666. if (!(tempbx & TVSetPAL) && (modeflag > 13) && (resinfo == 8))
  1667. /* NTSC 1024x768, */
  1668. tempbx |= NTSC1024x768;
  1669. tempbx |= RPLLDIV2XO;
  1670. if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
  1671. if (pVBInfo->VBInfo & SetInSlaveMode)
  1672. tempbx &= (~RPLLDIV2XO);
  1673. } else if (tempbx & (TVSetYPbPr525p | TVSetYPbPr750p)) {
  1674. tempbx &= (~RPLLDIV2XO);
  1675. } else if (!(pVBInfo->VBType & (VB_SIS301B | VB_SIS302B |
  1676. VB_SIS301LV | VB_SIS302LV |
  1677. VB_XGI301C))) {
  1678. if (tempbx & TVSimuMode)
  1679. tempbx &= (~RPLLDIV2XO);
  1680. }
  1681. }
  1682. pVBInfo->TVInfo = tempbx;
  1683. }
  1684. static unsigned char XGI_GetLCDInfo(unsigned short ModeIdIndex,
  1685. struct vb_device_info *pVBInfo)
  1686. {
  1687. unsigned short temp, tempax, tempbx, resinfo = 0, LCDIdIndex;
  1688. pVBInfo->LCDResInfo = 0;
  1689. pVBInfo->LCDTypeInfo = 0;
  1690. pVBInfo->LCDInfo = 0;
  1691. /* si+Ext_ResInfo // */
  1692. resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  1693. temp = xgifb_reg_get(pVBInfo->P3d4, 0x36); /* Get LCD Res.Info */
  1694. tempbx = temp & 0x0F;
  1695. if (tempbx == 0)
  1696. tempbx = Panel_1024x768; /* default */
  1697. /* LCD75 */
  1698. if ((tempbx == Panel_1024x768) || (tempbx == Panel_1280x1024)) {
  1699. if (pVBInfo->VBInfo & DriverMode) {
  1700. tempax = xgifb_reg_get(pVBInfo->P3d4, 0x33);
  1701. if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
  1702. tempax &= 0x0F;
  1703. else
  1704. tempax >>= 4;
  1705. if ((resinfo == 6) || (resinfo == 9)) {
  1706. if (tempax >= 3)
  1707. tempbx |= PanelRef75Hz;
  1708. } else if ((resinfo == 7) || (resinfo == 8)) {
  1709. if (tempax >= 4)
  1710. tempbx |= PanelRef75Hz;
  1711. }
  1712. }
  1713. }
  1714. pVBInfo->LCDResInfo = tempbx;
  1715. /* End of LCD75 */
  1716. if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
  1717. return 0;
  1718. tempbx = 0;
  1719. temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
  1720. temp &= (ScalingLCD | LCDNonExpanding | LCDSyncBit | SetPWDEnable);
  1721. tempbx |= temp;
  1722. LCDIdIndex = XGI_GetLCDCapPtr1(pVBInfo);
  1723. tempax = pVBInfo->LCDCapList[LCDIdIndex].LCD_Capability;
  1724. if (((pVBInfo->VBType & VB_SIS302LV) ||
  1725. (pVBInfo->VBType & VB_XGI301C)) && (tempax & XGI_LCDDualLink))
  1726. tempbx |= SetLCDDualLink;
  1727. if ((pVBInfo->LCDResInfo == Panel_1400x1050) &&
  1728. (pVBInfo->VBInfo & SetCRT2ToLCD) && (resinfo == 9) &&
  1729. (!(tempbx & EnableScalingLCD)))
  1730. /*
  1731. * set to center in 1280x1024 LCDB
  1732. * for Panel_1400x1050
  1733. */
  1734. tempbx |= SetLCDtoNonExpanding;
  1735. if (pVBInfo->VBInfo & SetInSlaveMode) {
  1736. if (pVBInfo->VBInfo & SetNotSimuMode)
  1737. tempbx |= XGI_LCDVESATiming;
  1738. } else {
  1739. tempbx |= XGI_LCDVESATiming;
  1740. }
  1741. pVBInfo->LCDInfo = tempbx;
  1742. return 1;
  1743. }
  1744. unsigned char XGI_SearchModeID(unsigned short ModeNo,
  1745. unsigned short *ModeIdIndex)
  1746. {
  1747. for (*ModeIdIndex = 0;; (*ModeIdIndex)++) {
  1748. if (XGI330_EModeIDTable[*ModeIdIndex].Ext_ModeID == ModeNo)
  1749. break;
  1750. if (XGI330_EModeIDTable[*ModeIdIndex].Ext_ModeID == 0xFF)
  1751. return 0;
  1752. }
  1753. return 1;
  1754. }
  1755. static unsigned char XG21GPIODataTransfer(unsigned char ujDate)
  1756. {
  1757. unsigned char ujRet = 0;
  1758. unsigned char i = 0;
  1759. for (i = 0; i < 8; i++) {
  1760. ujRet <<= 1;
  1761. ujRet |= (ujDate >> i) & 1;
  1762. }
  1763. return ujRet;
  1764. }
  1765. /*----------------------------------------------------------------------------*/
  1766. /* output */
  1767. /* bl[5] : LVDS signal */
  1768. /* bl[1] : LVDS backlight */
  1769. /* bl[0] : LVDS VDD */
  1770. /*----------------------------------------------------------------------------*/
  1771. static unsigned char XGI_XG21GetPSCValue(struct vb_device_info *pVBInfo)
  1772. {
  1773. unsigned char CR4A, temp;
  1774. CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
  1775. xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x23); /* enable GPIO write */
  1776. temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
  1777. temp = XG21GPIODataTransfer(temp);
  1778. temp &= 0x23;
  1779. xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
  1780. return temp;
  1781. }
  1782. /*----------------------------------------------------------------------------*/
  1783. /* output */
  1784. /* bl[5] : LVDS signal */
  1785. /* bl[1] : LVDS backlight */
  1786. /* bl[0] : LVDS VDD */
  1787. /*----------------------------------------------------------------------------*/
  1788. static unsigned char XGI_XG27GetPSCValue(struct vb_device_info *pVBInfo)
  1789. {
  1790. unsigned char CR4A, CRB4, temp;
  1791. CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
  1792. xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x0C); /* enable GPIO write */
  1793. temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
  1794. temp &= 0x0C;
  1795. temp >>= 2;
  1796. xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
  1797. CRB4 = xgifb_reg_get(pVBInfo->P3d4, 0xB4);
  1798. temp |= ((CRB4 & 0x04) << 3);
  1799. return temp;
  1800. }
  1801. /*----------------------------------------------------------------------------*/
  1802. /* input */
  1803. /* bl[5] : 1;LVDS signal on */
  1804. /* bl[1] : 1;LVDS backlight on */
  1805. /* bl[0] : 1:LVDS VDD on */
  1806. /* bh: 100000b : clear bit 5, to set bit5 */
  1807. /* 000010b : clear bit 1, to set bit1 */
  1808. /* 000001b : clear bit 0, to set bit0 */
  1809. /*----------------------------------------------------------------------------*/
  1810. static void XGI_XG21BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
  1811. struct vb_device_info *pVBInfo)
  1812. {
  1813. unsigned char CR4A, temp;
  1814. CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
  1815. tempbh &= 0x23;
  1816. tempbl &= 0x23;
  1817. xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
  1818. if (tempbh & 0x20) {
  1819. temp = (tempbl >> 4) & 0x02;
  1820. /* CR B4[1] */
  1821. xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
  1822. }
  1823. temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
  1824. temp = XG21GPIODataTransfer(temp);
  1825. temp &= ~tempbh;
  1826. temp |= tempbl;
  1827. xgifb_reg_set(pVBInfo->P3d4, 0x48, temp);
  1828. }
  1829. static void XGI_XG27BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
  1830. struct vb_device_info *pVBInfo)
  1831. {
  1832. unsigned char CR4A, temp;
  1833. unsigned short tempbh0, tempbl0;
  1834. tempbh0 = tempbh;
  1835. tempbl0 = tempbl;
  1836. tempbh0 &= 0x20;
  1837. tempbl0 &= 0x20;
  1838. tempbh0 >>= 3;
  1839. tempbl0 >>= 3;
  1840. if (tempbh & 0x20) {
  1841. temp = (tempbl >> 4) & 0x02;
  1842. /* CR B4[1] */
  1843. xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
  1844. }
  1845. xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~tempbh0, tempbl0);
  1846. CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
  1847. tempbh &= 0x03;
  1848. tempbl &= 0x03;
  1849. tempbh <<= 2;
  1850. tempbl <<= 2; /* GPIOC,GPIOD */
  1851. xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
  1852. xgifb_reg_and_or(pVBInfo->P3d4, 0x48, ~tempbh, tempbl);
  1853. }
  1854. static void XGI_DisplayOn(struct xgifb_video_info *xgifb_info,
  1855. struct xgi_hw_device_info *pXGIHWDE,
  1856. struct vb_device_info *pVBInfo)
  1857. {
  1858. xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x00);
  1859. if (pXGIHWDE->jChipType == XG21) {
  1860. if (pVBInfo->IF_DEF_LVDS == 1) {
  1861. if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x1)) {
  1862. /* LVDS VDD on */
  1863. XGI_XG21BLSignalVDD(0x01, 0x01, pVBInfo);
  1864. mdelay(xgifb_info->lvds_data.PSC_S2);
  1865. }
  1866. if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x20))
  1867. /* LVDS signal on */
  1868. XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
  1869. mdelay(xgifb_info->lvds_data.PSC_S3);
  1870. /* LVDS backlight on */
  1871. XGI_XG21BLSignalVDD(0x02, 0x02, pVBInfo);
  1872. } else {
  1873. /* DVO/DVI signal on */
  1874. XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
  1875. }
  1876. }
  1877. if (pXGIHWDE->jChipType == XG27) {
  1878. if (pVBInfo->IF_DEF_LVDS == 1) {
  1879. if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x1)) {
  1880. /* LVDS VDD on */
  1881. XGI_XG27BLSignalVDD(0x01, 0x01, pVBInfo);
  1882. mdelay(xgifb_info->lvds_data.PSC_S2);
  1883. }
  1884. if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x20))
  1885. /* LVDS signal on */
  1886. XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
  1887. mdelay(xgifb_info->lvds_data.PSC_S3);
  1888. /* LVDS backlight on */
  1889. XGI_XG27BLSignalVDD(0x02, 0x02, pVBInfo);
  1890. } else {
  1891. /* DVO/DVI signal on */
  1892. XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
  1893. }
  1894. }
  1895. }
  1896. void XGI_DisplayOff(struct xgifb_video_info *xgifb_info,
  1897. struct xgi_hw_device_info *pXGIHWDE,
  1898. struct vb_device_info *pVBInfo)
  1899. {
  1900. if (pXGIHWDE->jChipType == XG21) {
  1901. if (pVBInfo->IF_DEF_LVDS == 1) {
  1902. /* LVDS backlight off */
  1903. XGI_XG21BLSignalVDD(0x02, 0x00, pVBInfo);
  1904. mdelay(xgifb_info->lvds_data.PSC_S3);
  1905. } else {
  1906. /* DVO/DVI signal off */
  1907. XGI_XG21BLSignalVDD(0x20, 0x00, pVBInfo);
  1908. }
  1909. }
  1910. if (pXGIHWDE->jChipType == XG27) {
  1911. if ((XGI_XG27GetPSCValue(pVBInfo) & 0x2)) {
  1912. /* LVDS backlight off */
  1913. XGI_XG27BLSignalVDD(0x02, 0x00, pVBInfo);
  1914. mdelay(xgifb_info->lvds_data.PSC_S3);
  1915. }
  1916. if (pVBInfo->IF_DEF_LVDS == 0)
  1917. /* DVO/DVI signal off */
  1918. XGI_XG27BLSignalVDD(0x20, 0x00, pVBInfo);
  1919. }
  1920. xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x20);
  1921. }
  1922. static void XGI_WaitDisply(struct vb_device_info *pVBInfo)
  1923. {
  1924. while ((inb(pVBInfo->P3da) & 0x01))
  1925. break;
  1926. while (!(inb(pVBInfo->P3da) & 0x01))
  1927. break;
  1928. }
  1929. static void XGI_AutoThreshold(struct vb_device_info *pVBInfo)
  1930. {
  1931. xgifb_reg_or(pVBInfo->Part1Port, 0x01, 0x40);
  1932. }
  1933. static void XGI_SaveCRT2Info(unsigned short ModeNo,
  1934. struct vb_device_info *pVBInfo)
  1935. {
  1936. unsigned short temp1, temp2;
  1937. /* reserve CR34 for CRT1 Mode No */
  1938. xgifb_reg_set(pVBInfo->P3d4, 0x34, ModeNo);
  1939. temp1 = (pVBInfo->VBInfo & SetInSlaveMode) >> 8;
  1940. temp2 = ~(SetInSlaveMode >> 8);
  1941. xgifb_reg_and_or(pVBInfo->P3d4, 0x31, temp2, temp1);
  1942. }
  1943. static void XGI_GetCRT2ResInfo(unsigned short ModeIdIndex,
  1944. struct vb_device_info *pVBInfo)
  1945. {
  1946. unsigned short xres, yres, modeflag, resindex;
  1947. resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  1948. xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
  1949. yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
  1950. /* si+St_ModeFlag */
  1951. modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  1952. if (modeflag & HalfDCLK)
  1953. xres *= 2;
  1954. if (modeflag & DoubleScanMode)
  1955. yres *= 2;
  1956. if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
  1957. goto exit;
  1958. if (pVBInfo->LCDResInfo == Panel_1600x1200) {
  1959. if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
  1960. if (yres == 1024)
  1961. yres = 1056;
  1962. }
  1963. }
  1964. if (pVBInfo->LCDResInfo == Panel_1280x1024) {
  1965. if (yres == 400)
  1966. yres = 405;
  1967. else if (yres == 350)
  1968. yres = 360;
  1969. if (pVBInfo->LCDInfo & XGI_LCDVESATiming) {
  1970. if (yres == 360)
  1971. yres = 375;
  1972. }
  1973. }
  1974. if (pVBInfo->LCDResInfo == Panel_1024x768) {
  1975. if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
  1976. if (!(pVBInfo->LCDInfo & LCDNonExpanding)) {
  1977. if (yres == 350)
  1978. yres = 357;
  1979. else if (yres == 400)
  1980. yres = 420;
  1981. else if (yres == 480)
  1982. yres = 525;
  1983. }
  1984. }
  1985. }
  1986. if (xres == 720)
  1987. xres = 640;
  1988. exit:
  1989. pVBInfo->VGAHDE = xres;
  1990. pVBInfo->HDE = xres;
  1991. pVBInfo->VGAVDE = yres;
  1992. pVBInfo->VDE = yres;
  1993. }
  1994. static unsigned char XGI_IsLCDDualLink(struct vb_device_info *pVBInfo)
  1995. {
  1996. if ((pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) &&
  1997. (pVBInfo->LCDInfo & SetLCDDualLink)) /* shampoo0129 */
  1998. return 1;
  1999. return 0;
  2000. }
  2001. static void XGI_GetRAMDAC2DATA(unsigned short ModeIdIndex,
  2002. unsigned short RefreshRateTableIndex,
  2003. struct vb_device_info *pVBInfo)
  2004. {
  2005. unsigned short tempax, tempbx, temp1, temp2, modeflag = 0, tempcx,
  2006. CRT1Index;
  2007. pVBInfo->RVBHCMAX = 1;
  2008. pVBInfo->RVBHCFACT = 1;
  2009. modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  2010. CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
  2011. CRT1Index &= IndexMask;
  2012. temp1 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[0];
  2013. temp2 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[5];
  2014. tempax = (temp1 & 0xFF) | ((temp2 & 0x03) << 8);
  2015. tempbx = (unsigned short) XGI_CRT1Table[CRT1Index].CR[8];
  2016. tempcx = (unsigned short)
  2017. XGI_CRT1Table[CRT1Index].CR[14] << 8;
  2018. tempcx &= 0x0100;
  2019. tempcx <<= 2;
  2020. tempbx |= tempcx;
  2021. temp1 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[9];
  2022. if (temp1 & 0x01)
  2023. tempbx |= 0x0100;
  2024. if (temp1 & 0x20)
  2025. tempbx |= 0x0200;
  2026. tempax += 5;
  2027. if (modeflag & Charx8Dot)
  2028. tempax *= 8;
  2029. else
  2030. tempax *= 9;
  2031. pVBInfo->VGAHT = tempax;
  2032. pVBInfo->HT = tempax;
  2033. tempbx++;
  2034. pVBInfo->VGAVT = tempbx;
  2035. pVBInfo->VT = tempbx;
  2036. }
  2037. static void XGI_GetCRT2Data(unsigned short ModeIdIndex,
  2038. unsigned short RefreshRateTableIndex,
  2039. struct vb_device_info *pVBInfo)
  2040. {
  2041. unsigned short tempax = 0, tempbx = 0, modeflag, resinfo;
  2042. struct SiS_LCDData const *LCDPtr = NULL;
  2043. /* si+Ext_ResInfo */
  2044. modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  2045. resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  2046. pVBInfo->NewFlickerMode = 0;
  2047. pVBInfo->RVBHRS = 50;
  2048. if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
  2049. XGI_GetRAMDAC2DATA(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
  2050. return;
  2051. }
  2052. if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
  2053. LCDPtr = XGI_GetLcdPtr(XGI_LCDDataTable, ModeIdIndex,
  2054. pVBInfo);
  2055. pVBInfo->RVBHCMAX = LCDPtr->RVBHCMAX;
  2056. pVBInfo->RVBHCFACT = LCDPtr->RVBHCFACT;
  2057. pVBInfo->VGAHT = LCDPtr->VGAHT;
  2058. pVBInfo->VGAVT = LCDPtr->VGAVT;
  2059. pVBInfo->HT = LCDPtr->LCDHT;
  2060. pVBInfo->VT = LCDPtr->LCDVT;
  2061. if (pVBInfo->LCDResInfo == Panel_1024x768) {
  2062. tempax = 1024;
  2063. tempbx = 768;
  2064. if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
  2065. if (pVBInfo->VGAVDE == 357)
  2066. tempbx = 527;
  2067. else if (pVBInfo->VGAVDE == 420)
  2068. tempbx = 620;
  2069. else if (pVBInfo->VGAVDE == 525)
  2070. tempbx = 775;
  2071. else if (pVBInfo->VGAVDE == 600)
  2072. tempbx = 775;
  2073. }
  2074. } else if (pVBInfo->LCDResInfo == Panel_1024x768x75) {
  2075. tempax = 1024;
  2076. tempbx = 768;
  2077. } else if (pVBInfo->LCDResInfo == Panel_1280x1024) {
  2078. tempax = 1280;
  2079. if (pVBInfo->VGAVDE == 360)
  2080. tempbx = 768;
  2081. else if (pVBInfo->VGAVDE == 375)
  2082. tempbx = 800;
  2083. else if (pVBInfo->VGAVDE == 405)
  2084. tempbx = 864;
  2085. else
  2086. tempbx = 1024;
  2087. } else if (pVBInfo->LCDResInfo == Panel_1280x1024x75) {
  2088. tempax = 1280;
  2089. tempbx = 1024;
  2090. } else if (pVBInfo->LCDResInfo == Panel_1280x960) {
  2091. tempax = 1280;
  2092. if (pVBInfo->VGAVDE == 350)
  2093. tempbx = 700;
  2094. else if (pVBInfo->VGAVDE == 400)
  2095. tempbx = 800;
  2096. else if (pVBInfo->VGAVDE == 1024)
  2097. tempbx = 960;
  2098. else
  2099. tempbx = 960;
  2100. } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
  2101. tempax = 1400;
  2102. tempbx = 1050;
  2103. if (pVBInfo->VGAVDE == 1024) {
  2104. tempax = 1280;
  2105. tempbx = 1024;
  2106. }
  2107. } else if (pVBInfo->LCDResInfo == Panel_1600x1200) {
  2108. tempax = 1600;
  2109. tempbx = 1200; /* alan 10/14/2003 */
  2110. if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
  2111. if (pVBInfo->VGAVDE == 350)
  2112. tempbx = 875;
  2113. else if (pVBInfo->VGAVDE == 400)
  2114. tempbx = 1000;
  2115. }
  2116. }
  2117. if (pVBInfo->LCDInfo & LCDNonExpanding) {
  2118. tempax = pVBInfo->VGAHDE;
  2119. tempbx = pVBInfo->VGAVDE;
  2120. }
  2121. pVBInfo->HDE = tempax;
  2122. pVBInfo->VDE = tempbx;
  2123. return;
  2124. }
  2125. if (pVBInfo->VBInfo & (SetCRT2ToTV)) {
  2126. struct SiS_TVData const *TVPtr;
  2127. TVPtr = XGI_GetTVPtr(ModeIdIndex, RefreshRateTableIndex,
  2128. pVBInfo);
  2129. pVBInfo->RVBHCMAX = TVPtr->RVBHCMAX;
  2130. pVBInfo->RVBHCFACT = TVPtr->RVBHCFACT;
  2131. pVBInfo->VGAHT = TVPtr->VGAHT;
  2132. pVBInfo->VGAVT = TVPtr->VGAVT;
  2133. pVBInfo->HDE = TVPtr->TVHDE;
  2134. pVBInfo->VDE = TVPtr->TVVDE;
  2135. pVBInfo->RVBHRS = TVPtr->RVBHRS;
  2136. pVBInfo->NewFlickerMode = TVPtr->FlickerMode;
  2137. if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
  2138. if (resinfo == 0x08)
  2139. pVBInfo->NewFlickerMode = 0x40;
  2140. else if (resinfo == 0x09)
  2141. pVBInfo->NewFlickerMode = 0x40;
  2142. else if (resinfo == 0x12)
  2143. pVBInfo->NewFlickerMode = 0x40;
  2144. if (pVBInfo->VGAVDE == 350)
  2145. pVBInfo->TVInfo |= TVSimuMode;
  2146. tempax = ExtHiTVHT;
  2147. tempbx = ExtHiTVVT;
  2148. if (pVBInfo->VBInfo & SetInSlaveMode) {
  2149. if (pVBInfo->TVInfo & TVSimuMode) {
  2150. tempax = StHiTVHT;
  2151. tempbx = StHiTVVT;
  2152. if (!(modeflag & Charx8Dot)) {
  2153. tempax = StHiTextTVHT;
  2154. tempbx = StHiTextTVVT;
  2155. }
  2156. }
  2157. }
  2158. } else if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
  2159. if (pVBInfo->TVInfo & TVSetYPbPr750p) {
  2160. tempax = YPbPrTV750pHT; /* Ext750pTVHT */
  2161. tempbx = YPbPrTV750pVT; /* Ext750pTVVT */
  2162. }
  2163. if (pVBInfo->TVInfo & TVSetYPbPr525p) {
  2164. tempax = YPbPrTV525pHT; /* Ext525pTVHT */
  2165. tempbx = YPbPrTV525pVT; /* Ext525pTVVT */
  2166. } else if (pVBInfo->TVInfo & TVSetYPbPr525i) {
  2167. tempax = YPbPrTV525iHT; /* Ext525iTVHT */
  2168. tempbx = YPbPrTV525iVT; /* Ext525iTVVT */
  2169. if (pVBInfo->TVInfo & NTSC1024x768)
  2170. tempax = NTSC1024x768HT;
  2171. }
  2172. } else {
  2173. tempax = PALHT;
  2174. tempbx = PALVT;
  2175. if (!(pVBInfo->TVInfo & TVSetPAL)) {
  2176. tempax = NTSCHT;
  2177. tempbx = NTSCVT;
  2178. if (pVBInfo->TVInfo & NTSC1024x768)
  2179. tempax = NTSC1024x768HT;
  2180. }
  2181. }
  2182. pVBInfo->HT = tempax;
  2183. pVBInfo->VT = tempbx;
  2184. }
  2185. }
  2186. static void XGI_SetCRT2VCLK(unsigned short ModeIdIndex,
  2187. unsigned short RefreshRateTableIndex,
  2188. struct vb_device_info *pVBInfo)
  2189. {
  2190. unsigned char di_0, di_1, tempal;
  2191. tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeIdIndex, pVBInfo);
  2192. XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
  2193. XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
  2194. if (pVBInfo->VBType & VB_SIS301) { /* shampoo 0129 */
  2195. /* 301 */
  2196. xgifb_reg_set(pVBInfo->Part4Port, 0x0A, 0x10);
  2197. xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
  2198. xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
  2199. } else { /* 301b/302b/301lv/302lv */
  2200. xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
  2201. xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
  2202. }
  2203. xgifb_reg_set(pVBInfo->Part4Port, 0x00, 0x12);
  2204. if (pVBInfo->VBInfo & SetCRT2ToRAMDAC)
  2205. xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x28);
  2206. else
  2207. xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x08);
  2208. }
  2209. static unsigned short XGI_GetColorDepth(unsigned short ModeIdIndex)
  2210. {
  2211. unsigned short ColorDepth[6] = { 1, 2, 4, 4, 6, 8 };
  2212. short index;
  2213. unsigned short modeflag;
  2214. modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  2215. index = (modeflag & ModeTypeMask) - ModeEGA;
  2216. if (index < 0)
  2217. index = 0;
  2218. return ColorDepth[index];
  2219. }
  2220. static unsigned short XGI_GetOffset(unsigned short ModeNo,
  2221. unsigned short ModeIdIndex,
  2222. unsigned short RefreshRateTableIndex)
  2223. {
  2224. unsigned short temp, colordepth, modeinfo, index, infoflag,
  2225. ColorDepth[] = { 0x01, 0x02, 0x04 };
  2226. modeinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeInfo;
  2227. infoflag = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
  2228. index = (modeinfo >> 8) & 0xFF;
  2229. temp = XGI330_ScreenOffset[index];
  2230. if (infoflag & InterlaceMode)
  2231. temp <<= 1;
  2232. colordepth = XGI_GetColorDepth(ModeIdIndex);
  2233. if ((ModeNo >= 0x7C) && (ModeNo <= 0x7E)) {
  2234. temp = ModeNo - 0x7C;
  2235. colordepth = ColorDepth[temp];
  2236. temp = 0x6B;
  2237. if (infoflag & InterlaceMode)
  2238. temp <<= 1;
  2239. }
  2240. return temp * colordepth;
  2241. }
  2242. static void XGI_SetCRT2Offset(unsigned short ModeNo,
  2243. unsigned short ModeIdIndex,
  2244. unsigned short RefreshRateTableIndex,
  2245. struct vb_device_info *pVBInfo)
  2246. {
  2247. unsigned short offset;
  2248. unsigned char temp;
  2249. if (pVBInfo->VBInfo & SetInSlaveMode)
  2250. return;
  2251. offset = XGI_GetOffset(ModeNo, ModeIdIndex, RefreshRateTableIndex);
  2252. temp = (unsigned char) (offset & 0xFF);
  2253. xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
  2254. temp = (unsigned char) ((offset & 0xFF00) >> 8);
  2255. xgifb_reg_set(pVBInfo->Part1Port, 0x09, temp);
  2256. temp = (unsigned char) (((offset >> 3) & 0xFF) + 1);
  2257. xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
  2258. }
  2259. static void XGI_SetCRT2FIFO(struct vb_device_info *pVBInfo)
  2260. {
  2261. /* threshold high ,disable auto threshold */
  2262. xgifb_reg_set(pVBInfo->Part1Port, 0x01, 0x3B);
  2263. /* threshold low default 04h */
  2264. xgifb_reg_and_or(pVBInfo->Part1Port, 0x02, ~(0x3F), 0x04);
  2265. }
  2266. static void XGI_PreSetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
  2267. unsigned short RefreshRateTableIndex,
  2268. struct vb_device_info *pVBInfo)
  2269. {
  2270. u8 tempcx;
  2271. XGI_SetCRT2Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
  2272. XGI_SetCRT2FIFO(pVBInfo);
  2273. for (tempcx = 4; tempcx < 7; tempcx++)
  2274. xgifb_reg_set(pVBInfo->Part1Port, tempcx, 0x0);
  2275. xgifb_reg_set(pVBInfo->Part1Port, 0x50, 0x00);
  2276. xgifb_reg_set(pVBInfo->Part1Port, 0x02, 0x44); /* temp 0206 */
  2277. }
  2278. static void XGI_SetGroup1(unsigned short ModeIdIndex,
  2279. unsigned short RefreshRateTableIndex,
  2280. struct vb_device_info *pVBInfo)
  2281. {
  2282. unsigned short temp = 0, tempax = 0, tempbx = 0, tempcx = 0,
  2283. pushbx = 0, CRT1Index, modeflag;
  2284. CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
  2285. CRT1Index &= IndexMask;
  2286. modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  2287. /* bainy change table name */
  2288. if (modeflag & HalfDCLK) {
  2289. /* BTVGA2HT 0x08,0x09 */
  2290. temp = (pVBInfo->VGAHT / 2 - 1) & 0x0FF;
  2291. xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
  2292. temp = (((pVBInfo->VGAHT / 2 - 1) & 0xFF00) >> 8) << 4;
  2293. xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
  2294. /* BTVGA2HDEE 0x0A,0x0C */
  2295. temp = (pVBInfo->VGAHDE / 2 + 16) & 0x0FF;
  2296. xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
  2297. tempcx = ((pVBInfo->VGAHT - pVBInfo->VGAHDE) / 2) >> 2;
  2298. pushbx = pVBInfo->VGAHDE / 2 + 16;
  2299. tempcx >>= 1;
  2300. tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
  2301. tempcx += tempbx;
  2302. if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
  2303. tempbx = XGI_CRT1Table[CRT1Index].CR[4];
  2304. tempbx |= ((XGI_CRT1Table[CRT1Index].CR[14] &
  2305. 0xC0) << 2);
  2306. tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
  2307. tempcx = XGI_CRT1Table[CRT1Index].CR[5];
  2308. tempcx &= 0x1F;
  2309. temp = XGI_CRT1Table[CRT1Index].CR[15];
  2310. temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
  2311. tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
  2312. }
  2313. tempbx += 4;
  2314. tempcx += 4;
  2315. if (tempcx > (pVBInfo->VGAHT / 2))
  2316. tempcx = pVBInfo->VGAHT / 2;
  2317. temp = tempbx & 0x00FF;
  2318. xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
  2319. } else {
  2320. temp = (pVBInfo->VGAHT - 1) & 0x0FF; /* BTVGA2HT 0x08,0x09 */
  2321. xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
  2322. temp = (((pVBInfo->VGAHT - 1) & 0xFF00) >> 8) << 4;
  2323. xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
  2324. /* BTVGA2HDEE 0x0A,0x0C */
  2325. temp = (pVBInfo->VGAHDE + 16) & 0x0FF;
  2326. xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
  2327. tempcx = (pVBInfo->VGAHT - pVBInfo->VGAHDE) >> 2; /* cx */
  2328. pushbx = pVBInfo->VGAHDE + 16;
  2329. tempcx >>= 1;
  2330. tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
  2331. tempcx += tempbx;
  2332. if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
  2333. tempbx = XGI_CRT1Table[CRT1Index].CR[3];
  2334. tempbx |= ((XGI_CRT1Table[CRT1Index].CR[5] &
  2335. 0xC0) << 2);
  2336. tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
  2337. tempcx = XGI_CRT1Table[CRT1Index].CR[4];
  2338. tempcx &= 0x1F;
  2339. temp = XGI_CRT1Table[CRT1Index].CR[6];
  2340. temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
  2341. tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
  2342. tempbx += 16;
  2343. tempcx += 16;
  2344. }
  2345. if (tempcx > pVBInfo->VGAHT)
  2346. tempcx = pVBInfo->VGAHT;
  2347. temp = tempbx & 0x00FF;
  2348. xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
  2349. }
  2350. tempax = (tempax & 0x00FF) | (tempbx & 0xFF00);
  2351. tempbx = pushbx;
  2352. tempbx = (tempbx & 0x00FF) | ((tempbx & 0xFF00) << 4);
  2353. tempax |= (tempbx & 0xFF00);
  2354. temp = (tempax & 0xFF00) >> 8;
  2355. xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
  2356. temp = tempcx & 0x00FF;
  2357. xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
  2358. tempcx = (pVBInfo->VGAVT - 1);
  2359. temp = tempcx & 0x00FF;
  2360. xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
  2361. tempbx = pVBInfo->VGAVDE - 1;
  2362. temp = tempbx & 0x00FF;
  2363. xgifb_reg_set(pVBInfo->Part1Port, 0x0F, temp);
  2364. temp = ((tempbx & 0xFF00) << 3) >> 8;
  2365. temp |= ((tempcx & 0xFF00) >> 8);
  2366. xgifb_reg_set(pVBInfo->Part1Port, 0x12, temp);
  2367. /* BTVGA2VRS 0x10,0x11 */
  2368. tempbx = (pVBInfo->VGAVT + pVBInfo->VGAVDE) >> 1;
  2369. /* BTVGA2VRE 0x11 */
  2370. tempcx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) >> 4) + tempbx + 1;
  2371. if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
  2372. tempbx = XGI_CRT1Table[CRT1Index].CR[10];
  2373. temp = XGI_CRT1Table[CRT1Index].CR[9];
  2374. if (temp & 0x04)
  2375. tempbx |= 0x0100;
  2376. if (temp & 0x080)
  2377. tempbx |= 0x0200;
  2378. temp = XGI_CRT1Table[CRT1Index].CR[14];
  2379. if (temp & 0x08)
  2380. tempbx |= 0x0400;
  2381. temp = XGI_CRT1Table[CRT1Index].CR[11];
  2382. tempcx = (tempcx & 0xFF00) | (temp & 0x00FF);
  2383. }
  2384. temp = tempbx & 0x00FF;
  2385. xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
  2386. temp = ((tempbx & 0xFF00) >> 8) << 4;
  2387. temp = ((tempcx & 0x000F) | (temp));
  2388. xgifb_reg_set(pVBInfo->Part1Port, 0x11, temp);
  2389. tempax = 0;
  2390. if (modeflag & DoubleScanMode)
  2391. tempax |= 0x80;
  2392. if (modeflag & HalfDCLK)
  2393. tempax |= 0x40;
  2394. xgifb_reg_and_or(pVBInfo->Part1Port, 0x2C, ~0x0C0, tempax);
  2395. }
  2396. static unsigned short XGI_GetVGAHT2(struct vb_device_info *pVBInfo)
  2397. {
  2398. unsigned long tempax, tempbx;
  2399. tempbx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) * pVBInfo->RVBHCMAX)
  2400. & 0xFFFF;
  2401. tempax = (pVBInfo->VT - pVBInfo->VDE) * pVBInfo->RVBHCFACT;
  2402. tempax = (tempax * pVBInfo->HT) / tempbx;
  2403. return (unsigned short) tempax;
  2404. }
  2405. static void XGI_SetLockRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
  2406. struct vb_device_info *pVBInfo)
  2407. {
  2408. unsigned short push1, push2, tempax, tempbx = 0, tempcx, temp, resinfo,
  2409. modeflag;
  2410. /* si+Ext_ResInfo */
  2411. modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  2412. resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  2413. if (!(pVBInfo->VBInfo & SetInSlaveMode))
  2414. return;
  2415. temp = 0xFF; /* set MAX HT */
  2416. xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
  2417. tempcx = 0x08;
  2418. if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
  2419. modeflag |= Charx8Dot;
  2420. tempax = pVBInfo->VGAHDE; /* 0x04 Horizontal Display End */
  2421. if (modeflag & HalfDCLK)
  2422. tempax >>= 1;
  2423. tempax = (tempax / tempcx) - 1;
  2424. tempbx |= ((tempax & 0x00FF) << 8);
  2425. temp = tempax & 0x00FF;
  2426. xgifb_reg_set(pVBInfo->Part1Port, 0x04, temp);
  2427. temp = (tempbx & 0xFF00) >> 8;
  2428. if (pVBInfo->VBInfo & SetCRT2ToTV) {
  2429. if (!(pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
  2430. | VB_SIS302LV | VB_XGI301C)))
  2431. temp += 2;
  2432. if ((pVBInfo->VBInfo & SetCRT2ToHiVision) &&
  2433. !(pVBInfo->VBType & VB_SIS301LV) && (resinfo == 7))
  2434. temp -= 2;
  2435. }
  2436. /* 0x05 Horizontal Display Start */
  2437. xgifb_reg_set(pVBInfo->Part1Port, 0x05, temp);
  2438. /* 0x06 Horizontal Blank end */
  2439. xgifb_reg_set(pVBInfo->Part1Port, 0x06, 0x03);
  2440. if (!(pVBInfo->VBInfo & DisableCRT2Display)) { /* 030226 bainy */
  2441. if (pVBInfo->VBInfo & SetCRT2ToTV)
  2442. tempax = pVBInfo->VGAHT;
  2443. else
  2444. tempax = XGI_GetVGAHT2(pVBInfo);
  2445. }
  2446. if (tempax >= pVBInfo->VGAHT)
  2447. tempax = pVBInfo->VGAHT;
  2448. if (modeflag & HalfDCLK)
  2449. tempax >>= 1;
  2450. tempax = (tempax / tempcx) - 5;
  2451. tempcx = tempax; /* 20030401 0x07 horizontal Retrace Start */
  2452. if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
  2453. temp = (tempbx & 0x00FF) - 1;
  2454. if (!(modeflag & HalfDCLK)) {
  2455. temp -= 6;
  2456. if (pVBInfo->TVInfo & TVSimuMode) {
  2457. temp -= 4;
  2458. temp -= 10;
  2459. }
  2460. }
  2461. } else {
  2462. tempbx = (tempbx & 0xFF00) >> 8;
  2463. tempcx = (tempcx + tempbx) >> 1;
  2464. temp = (tempcx & 0x00FF) + 2;
  2465. if (pVBInfo->VBInfo & SetCRT2ToTV) {
  2466. temp -= 1;
  2467. if (!(modeflag & HalfDCLK)) {
  2468. if ((modeflag & Charx8Dot)) {
  2469. temp += 4;
  2470. if (pVBInfo->VGAHDE >= 800)
  2471. temp -= 6;
  2472. }
  2473. }
  2474. } else if (!(modeflag & HalfDCLK)) {
  2475. temp -= 4;
  2476. if (pVBInfo->LCDResInfo != Panel_1280x960 &&
  2477. pVBInfo->VGAHDE >= 800) {
  2478. temp -= 7;
  2479. if (pVBInfo->VGAHDE >= 1280 &&
  2480. pVBInfo->LCDResInfo != Panel_1280x960 &&
  2481. (pVBInfo->LCDInfo & LCDNonExpanding))
  2482. temp += 28;
  2483. }
  2484. }
  2485. }
  2486. /* 0x07 Horizontal Retrace Start */
  2487. xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
  2488. /* 0x08 Horizontal Retrace End */
  2489. xgifb_reg_set(pVBInfo->Part1Port, 0x08, 0);
  2490. if (pVBInfo->VBInfo & SetCRT2ToTV) {
  2491. if (pVBInfo->TVInfo & TVSimuMode) {
  2492. if (ModeNo == 0x50) {
  2493. if (pVBInfo->TVInfo == SetNTSCTV) {
  2494. xgifb_reg_set(pVBInfo->Part1Port,
  2495. 0x07, 0x30);
  2496. xgifb_reg_set(pVBInfo->Part1Port,
  2497. 0x08, 0x03);
  2498. } else {
  2499. xgifb_reg_set(pVBInfo->Part1Port,
  2500. 0x07, 0x2f);
  2501. xgifb_reg_set(pVBInfo->Part1Port,
  2502. 0x08, 0x02);
  2503. }
  2504. }
  2505. }
  2506. }
  2507. xgifb_reg_set(pVBInfo->Part1Port, 0x18, 0x03); /* 0x18 SR0B */
  2508. xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0xF0, 0x00);
  2509. xgifb_reg_set(pVBInfo->Part1Port, 0x09, 0xFF); /* 0x09 Set Max VT */
  2510. tempbx = pVBInfo->VGAVT;
  2511. push1 = tempbx;
  2512. tempcx = 0x121;
  2513. tempbx = pVBInfo->VGAVDE; /* 0x0E Virtical Display End */
  2514. if (tempbx == 357)
  2515. tempbx = 350;
  2516. if (tempbx == 360)
  2517. tempbx = 350;
  2518. if (tempbx == 375)
  2519. tempbx = 350;
  2520. if (tempbx == 405)
  2521. tempbx = 400;
  2522. if (tempbx == 525)
  2523. tempbx = 480;
  2524. push2 = tempbx;
  2525. if (pVBInfo->VBInfo & SetCRT2ToLCD) {
  2526. if (pVBInfo->LCDResInfo == Panel_1024x768) {
  2527. if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
  2528. if (tempbx == 350)
  2529. tempbx += 5;
  2530. if (tempbx == 480)
  2531. tempbx += 5;
  2532. }
  2533. }
  2534. }
  2535. tempbx--;
  2536. tempbx--;
  2537. temp = tempbx & 0x00FF;
  2538. /* 0x10 vertical Blank Start */
  2539. xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
  2540. tempbx = push2;
  2541. tempbx--;
  2542. temp = tempbx & 0x00FF;
  2543. xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
  2544. if (tempbx & 0x0100)
  2545. tempcx |= 0x0002;
  2546. tempax = 0x000B;
  2547. if (modeflag & DoubleScanMode)
  2548. tempax |= 0x08000;
  2549. if (tempbx & 0x0200)
  2550. tempcx |= 0x0040;
  2551. temp = (tempax & 0xFF00) >> 8;
  2552. xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
  2553. if (tempbx & 0x0400)
  2554. tempcx |= 0x0600;
  2555. /* 0x11 Vertival Blank End */
  2556. xgifb_reg_set(pVBInfo->Part1Port, 0x11, 0x00);
  2557. tempax = push1;
  2558. tempax -= tempbx; /* 0x0C Vertical Retrace Start */
  2559. tempax >>= 2;
  2560. push1 = tempax; /* push ax */
  2561. if (resinfo != 0x09) {
  2562. tempax <<= 1;
  2563. tempbx += tempax;
  2564. }
  2565. if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
  2566. if ((pVBInfo->VBType & VB_SIS301LV) &&
  2567. !(pVBInfo->TVInfo & TVSetHiVision)) {
  2568. if ((pVBInfo->TVInfo & TVSimuMode) &&
  2569. (pVBInfo->TVInfo & TVSetPAL)) {
  2570. if (!(pVBInfo->VBType & VB_SIS301LV) ||
  2571. !(pVBInfo->TVInfo &
  2572. (TVSetYPbPr525p |
  2573. TVSetYPbPr750p |
  2574. TVSetHiVision)))
  2575. tempbx += 40;
  2576. }
  2577. } else {
  2578. tempbx -= 10;
  2579. }
  2580. } else if (pVBInfo->TVInfo & TVSimuMode) {
  2581. if (pVBInfo->TVInfo & TVSetPAL) {
  2582. if (pVBInfo->VBType & VB_SIS301LV) {
  2583. if (!(pVBInfo->TVInfo &
  2584. (TVSetYPbPr525p |
  2585. TVSetYPbPr750p |
  2586. TVSetHiVision)))
  2587. tempbx += 40;
  2588. } else {
  2589. tempbx += 40;
  2590. }
  2591. }
  2592. }
  2593. tempax = push1;
  2594. tempax >>= 2;
  2595. tempax++;
  2596. tempax += tempbx;
  2597. push1 = tempax; /* push ax */
  2598. if ((pVBInfo->TVInfo & TVSetPAL)) {
  2599. if (tempbx <= 513) {
  2600. if (tempax >= 513)
  2601. tempbx = 513;
  2602. }
  2603. }
  2604. temp = tempbx & 0x00FF;
  2605. xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
  2606. tempbx--;
  2607. temp = tempbx & 0x00FF;
  2608. xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
  2609. if (tempbx & 0x0100)
  2610. tempcx |= 0x0008;
  2611. if (tempbx & 0x0200)
  2612. xgifb_reg_and_or(pVBInfo->Part1Port, 0x0B, 0x0FF, 0x20);
  2613. tempbx++;
  2614. if (tempbx & 0x0100)
  2615. tempcx |= 0x0004;
  2616. if (tempbx & 0x0200)
  2617. tempcx |= 0x0080;
  2618. if (tempbx & 0x0400)
  2619. tempcx |= 0x0C00;
  2620. tempbx = push1; /* pop ax */
  2621. temp = tempbx & 0x00FF;
  2622. temp &= 0x0F;
  2623. /* 0x0D vertical Retrace End */
  2624. xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
  2625. if (tempbx & 0x0010)
  2626. tempcx |= 0x2000;
  2627. temp = tempcx & 0x00FF;
  2628. xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp); /* 0x0A CR07 */
  2629. temp = (tempcx & 0x0FF00) >> 8;
  2630. xgifb_reg_set(pVBInfo->Part1Port, 0x17, temp); /* 0x17 SR0A */
  2631. tempax = modeflag;
  2632. temp = (tempax & 0xFF00) >> 8;
  2633. temp = (temp >> 1) & 0x09;
  2634. if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
  2635. temp |= 0x01;
  2636. xgifb_reg_set(pVBInfo->Part1Port, 0x16, temp); /* 0x16 SR01 */
  2637. xgifb_reg_set(pVBInfo->Part1Port, 0x0F, 0); /* 0x0F CR14 */
  2638. xgifb_reg_set(pVBInfo->Part1Port, 0x12, 0); /* 0x12 CR17 */
  2639. if (pVBInfo->LCDInfo & LCDRGB18Bit)
  2640. temp = 0x80;
  2641. else
  2642. temp = 0x00;
  2643. xgifb_reg_set(pVBInfo->Part1Port, 0x1A, temp); /* 0x1A SR0E */
  2644. }
  2645. static void XGI_SetGroup2(unsigned short ModeNo, unsigned short ModeIdIndex,
  2646. struct vb_device_info *pVBInfo)
  2647. {
  2648. unsigned short i, j, tempax, tempbx, tempcx, temp, push1, push2,
  2649. modeflag;
  2650. unsigned char const *TimingPoint;
  2651. unsigned long longtemp, tempeax, tempebx, temp2, tempecx;
  2652. /* si+Ext_ResInfo */
  2653. modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  2654. tempax = 0;
  2655. if (!(pVBInfo->VBInfo & SetCRT2ToAVIDEO))
  2656. tempax |= 0x0800;
  2657. if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
  2658. tempax |= 0x0400;
  2659. if (pVBInfo->VBInfo & SetCRT2ToSCART)
  2660. tempax |= 0x0200;
  2661. if (!(pVBInfo->TVInfo & TVSetPAL))
  2662. tempax |= 0x1000;
  2663. if (pVBInfo->VBInfo & SetCRT2ToHiVision)
  2664. tempax |= 0x0100;
  2665. if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
  2666. tempax &= 0xfe00;
  2667. tempax = (tempax & 0xff00) >> 8;
  2668. xgifb_reg_set(pVBInfo->Part2Port, 0x0, tempax);
  2669. TimingPoint = XGI330_NTSCTiming;
  2670. if (pVBInfo->TVInfo & TVSetPAL)
  2671. TimingPoint = XGI330_PALTiming;
  2672. if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
  2673. TimingPoint = XGI330_HiTVExtTiming;
  2674. if (pVBInfo->VBInfo & SetInSlaveMode)
  2675. TimingPoint = XGI330_HiTVSt2Timing;
  2676. if (pVBInfo->SetFlag & TVSimuMode)
  2677. TimingPoint = XGI330_HiTVSt1Timing;
  2678. if (!(modeflag & Charx8Dot))
  2679. TimingPoint = XGI330_HiTVTextTiming;
  2680. }
  2681. if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
  2682. if (pVBInfo->TVInfo & TVSetYPbPr525i)
  2683. TimingPoint = XGI330_YPbPr525iTiming;
  2684. if (pVBInfo->TVInfo & TVSetYPbPr525p)
  2685. TimingPoint = XGI330_YPbPr525pTiming;
  2686. if (pVBInfo->TVInfo & TVSetYPbPr750p)
  2687. TimingPoint = XGI330_YPbPr750pTiming;
  2688. }
  2689. for (i = 0x01, j = 0; i <= 0x2D; i++, j++)
  2690. xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
  2691. for (i = 0x39; i <= 0x45; i++, j++)
  2692. /* di->temp2[j] */
  2693. xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
  2694. if (pVBInfo->VBInfo & SetCRT2ToTV)
  2695. xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, 0x00);
  2696. temp = pVBInfo->NewFlickerMode;
  2697. temp &= 0x80;
  2698. xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xFF, temp);
  2699. if (pVBInfo->TVInfo & TVSetPAL)
  2700. tempax = 520;
  2701. else
  2702. tempax = 440;
  2703. if (pVBInfo->VDE <= tempax) {
  2704. tempax -= pVBInfo->VDE;
  2705. tempax >>= 2;
  2706. tempax = (tempax & 0x00FF) | ((tempax & 0x00FF) << 8);
  2707. push1 = tempax;
  2708. temp = (tempax & 0xFF00) >> 8;
  2709. temp += (unsigned short) TimingPoint[0];
  2710. if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
  2711. | VB_SIS302LV | VB_XGI301C)) {
  2712. if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO
  2713. | SetCRT2ToSVIDEO | SetCRT2ToSCART
  2714. | SetCRT2ToYPbPr525750)) {
  2715. tempcx = pVBInfo->VGAHDE;
  2716. if (tempcx >= 1024) {
  2717. temp = 0x17; /* NTSC */
  2718. if (pVBInfo->TVInfo & TVSetPAL)
  2719. temp = 0x19; /* PAL */
  2720. }
  2721. }
  2722. }
  2723. xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
  2724. tempax = push1;
  2725. temp = (tempax & 0xFF00) >> 8;
  2726. temp += TimingPoint[1];
  2727. if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
  2728. | VB_SIS302LV | VB_XGI301C)) {
  2729. if ((pVBInfo->VBInfo & (SetCRT2ToAVIDEO
  2730. | SetCRT2ToSVIDEO | SetCRT2ToSCART
  2731. | SetCRT2ToYPbPr525750))) {
  2732. tempcx = pVBInfo->VGAHDE;
  2733. if (tempcx >= 1024) {
  2734. temp = 0x1D; /* NTSC */
  2735. if (pVBInfo->TVInfo & TVSetPAL)
  2736. temp = 0x52; /* PAL */
  2737. }
  2738. }
  2739. }
  2740. xgifb_reg_set(pVBInfo->Part2Port, 0x02, temp);
  2741. }
  2742. /* 301b */
  2743. tempcx = pVBInfo->HT;
  2744. if (XGI_IsLCDDualLink(pVBInfo))
  2745. tempcx >>= 1;
  2746. tempcx -= 2;
  2747. temp = tempcx & 0x00FF;
  2748. xgifb_reg_set(pVBInfo->Part2Port, 0x1B, temp);
  2749. temp = (tempcx & 0xFF00) >> 8;
  2750. xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F, temp);
  2751. tempcx = pVBInfo->HT >> 1;
  2752. push1 = tempcx; /* push cx */
  2753. tempcx += 7;
  2754. if (pVBInfo->VBInfo & SetCRT2ToHiVision)
  2755. tempcx -= 4;
  2756. temp = tempcx & 0x00FF;
  2757. temp <<= 4;
  2758. xgifb_reg_and_or(pVBInfo->Part2Port, 0x22, 0x0F, temp);
  2759. tempbx = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
  2760. tempbx += tempcx;
  2761. push2 = tempbx;
  2762. temp = tempbx & 0x00FF;
  2763. xgifb_reg_set(pVBInfo->Part2Port, 0x24, temp);
  2764. temp = (tempbx & 0xFF00) >> 8;
  2765. temp <<= 4;
  2766. xgifb_reg_and_or(pVBInfo->Part2Port, 0x25, 0x0F, temp);
  2767. tempbx = push2;
  2768. tempbx = tempbx + 8;
  2769. if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
  2770. tempbx = tempbx - 4;
  2771. tempcx = tempbx;
  2772. }
  2773. temp = (tempbx & 0x00FF) << 4;
  2774. xgifb_reg_and_or(pVBInfo->Part2Port, 0x29, 0x0F, temp);
  2775. j += 2;
  2776. tempcx += (TimingPoint[j] | ((TimingPoint[j + 1]) << 8));
  2777. temp = tempcx & 0x00FF;
  2778. xgifb_reg_set(pVBInfo->Part2Port, 0x27, temp);
  2779. temp = ((tempcx & 0xFF00) >> 8) << 4;
  2780. xgifb_reg_and_or(pVBInfo->Part2Port, 0x28, 0x0F, temp);
  2781. tempcx += 8;
  2782. if (pVBInfo->VBInfo & SetCRT2ToHiVision)
  2783. tempcx -= 4;
  2784. temp = tempcx & 0xFF;
  2785. temp <<= 4;
  2786. xgifb_reg_and_or(pVBInfo->Part2Port, 0x2A, 0x0F, temp);
  2787. tempcx = push1; /* pop cx */
  2788. j += 2;
  2789. temp = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
  2790. tempcx -= temp;
  2791. temp = tempcx & 0x00FF;
  2792. temp <<= 4;
  2793. xgifb_reg_and_or(pVBInfo->Part2Port, 0x2D, 0x0F, temp);
  2794. tempcx -= 11;
  2795. if (!(pVBInfo->VBInfo & SetCRT2ToTV)) {
  2796. tempax = XGI_GetVGAHT2(pVBInfo);
  2797. tempcx = tempax - 1;
  2798. }
  2799. temp = tempcx & 0x00FF;
  2800. xgifb_reg_set(pVBInfo->Part2Port, 0x2E, temp);
  2801. tempbx = pVBInfo->VDE;
  2802. if (pVBInfo->VGAVDE == 360)
  2803. tempbx = 746;
  2804. if (pVBInfo->VGAVDE == 375)
  2805. tempbx = 746;
  2806. if (pVBInfo->VGAVDE == 405)
  2807. tempbx = 853;
  2808. if (pVBInfo->VBInfo & SetCRT2ToTV) {
  2809. if (pVBInfo->VBType &
  2810. (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
  2811. if (!(pVBInfo->TVInfo &
  2812. (TVSetYPbPr525p | TVSetYPbPr750p)))
  2813. tempbx >>= 1;
  2814. } else
  2815. tempbx >>= 1;
  2816. }
  2817. tempbx -= 2;
  2818. temp = tempbx & 0x00FF;
  2819. if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
  2820. if (pVBInfo->VBType & VB_SIS301LV) {
  2821. if (pVBInfo->TVInfo & TVSetHiVision) {
  2822. if (pVBInfo->VBInfo & SetInSlaveMode) {
  2823. if (ModeNo == 0x2f)
  2824. temp += 1;
  2825. }
  2826. }
  2827. } else if (pVBInfo->VBInfo & SetInSlaveMode) {
  2828. if (ModeNo == 0x2f)
  2829. temp += 1;
  2830. }
  2831. }
  2832. xgifb_reg_set(pVBInfo->Part2Port, 0x2F, temp);
  2833. temp = (tempcx & 0xFF00) >> 8;
  2834. temp |= ((tempbx & 0xFF00) >> 8) << 6;
  2835. if (!(pVBInfo->VBInfo & SetCRT2ToHiVision)) {
  2836. if (pVBInfo->VBType & VB_SIS301LV) {
  2837. if (pVBInfo->TVInfo & TVSetHiVision) {
  2838. temp |= 0x10;
  2839. if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
  2840. temp |= 0x20;
  2841. }
  2842. } else {
  2843. temp |= 0x10;
  2844. if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
  2845. temp |= 0x20;
  2846. }
  2847. }
  2848. xgifb_reg_set(pVBInfo->Part2Port, 0x30, temp);
  2849. if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
  2850. | VB_SIS302LV | VB_XGI301C)) { /* TV gatingno */
  2851. tempbx = pVBInfo->VDE;
  2852. tempcx = tempbx - 2;
  2853. if (pVBInfo->VBInfo & SetCRT2ToTV) {
  2854. if (!(pVBInfo->TVInfo & (TVSetYPbPr525p
  2855. | TVSetYPbPr750p)))
  2856. tempbx >>= 1;
  2857. }
  2858. if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
  2859. temp = 0;
  2860. if (tempcx & 0x0400)
  2861. temp |= 0x20;
  2862. if (tempbx & 0x0400)
  2863. temp |= 0x40;
  2864. xgifb_reg_set(pVBInfo->Part4Port, 0x10, temp);
  2865. }
  2866. temp = (((tempbx - 3) & 0x0300) >> 8) << 5;
  2867. xgifb_reg_set(pVBInfo->Part2Port, 0x46, temp);
  2868. temp = (tempbx - 3) & 0x00FF;
  2869. xgifb_reg_set(pVBInfo->Part2Port, 0x47, temp);
  2870. }
  2871. tempbx = tempbx & 0x00FF;
  2872. if (!(modeflag & HalfDCLK)) {
  2873. tempcx = pVBInfo->VGAHDE;
  2874. if (tempcx >= pVBInfo->HDE) {
  2875. tempbx |= 0x2000;
  2876. tempax &= 0x00FF;
  2877. }
  2878. }
  2879. tempcx = 0x0101;
  2880. if (pVBInfo->VBInfo & SetCRT2ToTV) { /*301b*/
  2881. if (pVBInfo->VGAHDE >= 1024) {
  2882. tempcx = 0x1920;
  2883. if (pVBInfo->VGAHDE >= 1280) {
  2884. tempcx = 0x1420;
  2885. tempbx = tempbx & 0xDFFF;
  2886. }
  2887. }
  2888. }
  2889. if (!(tempbx & 0x2000)) {
  2890. if (modeflag & HalfDCLK)
  2891. tempcx = (tempcx & 0xFF00) | ((tempcx & 0x00FF) << 1);
  2892. push1 = tempbx;
  2893. tempeax = pVBInfo->VGAHDE;
  2894. tempebx = (tempcx & 0xFF00) >> 8;
  2895. longtemp = tempeax * tempebx;
  2896. tempecx = tempcx & 0x00FF;
  2897. longtemp = longtemp / tempecx;
  2898. /* 301b */
  2899. tempecx = 8 * 1024;
  2900. if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
  2901. | VB_SIS302LV | VB_XGI301C)) {
  2902. tempecx = tempecx * 8;
  2903. }
  2904. longtemp = longtemp * tempecx;
  2905. tempecx = pVBInfo->HDE;
  2906. temp2 = longtemp % tempecx;
  2907. tempeax = longtemp / tempecx;
  2908. if (temp2 != 0)
  2909. tempeax += 1;
  2910. tempax = (unsigned short) tempeax;
  2911. /* 301b */
  2912. if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
  2913. | VB_SIS302LV | VB_XGI301C)) {
  2914. tempcx = ((tempax & 0xFF00) >> 5) >> 8;
  2915. }
  2916. /* end 301b */
  2917. tempbx = push1;
  2918. tempbx = (unsigned short) (((tempeax & 0x0000FF00) & 0x1F00)
  2919. | (tempbx & 0x00FF));
  2920. tempax = (unsigned short) (((tempeax & 0x000000FF) << 8)
  2921. | (tempax & 0x00FF));
  2922. temp = (tempax & 0xFF00) >> 8;
  2923. } else {
  2924. temp = (tempax & 0x00FF) >> 8;
  2925. }
  2926. xgifb_reg_set(pVBInfo->Part2Port, 0x44, temp);
  2927. temp = (tempbx & 0xFF00) >> 8;
  2928. xgifb_reg_and_or(pVBInfo->Part2Port, 0x45, ~0x03F, temp);
  2929. temp = tempcx & 0x00FF;
  2930. if (tempbx & 0x2000)
  2931. temp = 0;
  2932. if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
  2933. temp |= 0x18;
  2934. xgifb_reg_and_or(pVBInfo->Part2Port, 0x46, ~0x1F, temp);
  2935. if (pVBInfo->TVInfo & TVSetPAL) {
  2936. tempbx = 0x0382;
  2937. tempcx = 0x007e;
  2938. } else {
  2939. tempbx = 0x0369;
  2940. tempcx = 0x0061;
  2941. }
  2942. temp = tempbx & 0x00FF;
  2943. xgifb_reg_set(pVBInfo->Part2Port, 0x4b, temp);
  2944. temp = tempcx & 0x00FF;
  2945. xgifb_reg_set(pVBInfo->Part2Port, 0x4c, temp);
  2946. temp = ((tempcx & 0xFF00) >> 8) & 0x03;
  2947. temp <<= 2;
  2948. temp |= ((tempbx & 0xFF00) >> 8) & 0x03;
  2949. if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
  2950. temp |= 0x10;
  2951. if (pVBInfo->TVInfo & TVSetYPbPr525p)
  2952. temp |= 0x20;
  2953. if (pVBInfo->TVInfo & TVSetYPbPr750p)
  2954. temp |= 0x60;
  2955. }
  2956. xgifb_reg_set(pVBInfo->Part2Port, 0x4d, temp);
  2957. temp = xgifb_reg_get(pVBInfo->Part2Port, 0x43); /* 301b change */
  2958. xgifb_reg_set(pVBInfo->Part2Port, 0x43, (unsigned short) (temp - 3));
  2959. if (!(pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))) {
  2960. if (pVBInfo->TVInfo & NTSC1024x768) {
  2961. TimingPoint = XGI_NTSC1024AdjTime;
  2962. for (i = 0x1c, j = 0; i <= 0x30; i++, j++) {
  2963. xgifb_reg_set(pVBInfo->Part2Port, i,
  2964. TimingPoint[j]);
  2965. }
  2966. xgifb_reg_set(pVBInfo->Part2Port, 0x43, 0x72);
  2967. }
  2968. }
  2969. /* Modify for 301C PALM Support */
  2970. if (pVBInfo->VBType & VB_XGI301C) {
  2971. if (pVBInfo->TVInfo & TVSetPALM)
  2972. xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x08,
  2973. 0x08); /* PALM Mode */
  2974. }
  2975. if (pVBInfo->TVInfo & TVSetPALM) {
  2976. tempax = xgifb_reg_get(pVBInfo->Part2Port, 0x01);
  2977. tempax--;
  2978. xgifb_reg_and(pVBInfo->Part2Port, 0x01, tempax);
  2979. xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xEF);
  2980. }
  2981. if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
  2982. if (!(pVBInfo->VBInfo & SetInSlaveMode))
  2983. xgifb_reg_set(pVBInfo->Part2Port, 0x0B, 0x00);
  2984. }
  2985. }
  2986. static void XGI_SetLCDRegs(unsigned short ModeIdIndex,
  2987. struct vb_device_info *pVBInfo)
  2988. {
  2989. unsigned short pushbx, tempax, tempbx, tempcx, temp, tempah,
  2990. tempbh, tempch;
  2991. struct XGI_LCDDesStruct const *LCDBDesPtr = NULL;
  2992. /* si+Ext_ResInfo */
  2993. if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
  2994. return;
  2995. tempbx = pVBInfo->HDE; /* RHACTE=HDE-1 */
  2996. if (XGI_IsLCDDualLink(pVBInfo))
  2997. tempbx >>= 1;
  2998. tempbx -= 1;
  2999. temp = tempbx & 0x00FF;
  3000. xgifb_reg_set(pVBInfo->Part2Port, 0x2C, temp);
  3001. temp = (tempbx & 0xFF00) >> 8;
  3002. temp <<= 4;
  3003. xgifb_reg_and_or(pVBInfo->Part2Port, 0x2B, 0x0F, temp);
  3004. temp = 0x01;
  3005. xgifb_reg_set(pVBInfo->Part2Port, 0x0B, temp);
  3006. tempbx = pVBInfo->VDE; /* RTVACTEO=(VDE-1)&0xFF */
  3007. tempbx--;
  3008. temp = tempbx & 0x00FF;
  3009. xgifb_reg_set(pVBInfo->Part2Port, 0x03, temp);
  3010. temp = ((tempbx & 0xFF00) >> 8) & 0x07;
  3011. xgifb_reg_and_or(pVBInfo->Part2Port, 0x0C, ~0x07, temp);
  3012. tempcx = pVBInfo->VT - 1;
  3013. temp = tempcx & 0x00FF; /* RVTVT=VT-1 */
  3014. xgifb_reg_set(pVBInfo->Part2Port, 0x19, temp);
  3015. temp = (tempcx & 0xFF00) >> 8;
  3016. temp <<= 5;
  3017. xgifb_reg_set(pVBInfo->Part2Port, 0x1A, temp);
  3018. xgifb_reg_and_or(pVBInfo->Part2Port, 0x09, 0xF0, 0x00);
  3019. xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xF0, 0x00);
  3020. xgifb_reg_and_or(pVBInfo->Part2Port, 0x17, 0xFB, 0x00);
  3021. xgifb_reg_and_or(pVBInfo->Part2Port, 0x18, 0xDF, 0x00);
  3022. /* Customized LCDB Does not add */
  3023. if ((pVBInfo->VBType & VB_SIS301LV) || (pVBInfo->VBType & VB_SIS302LV))
  3024. LCDBDesPtr = XGI_GetLcdPtr(xgifb_lcddldes, ModeIdIndex,
  3025. pVBInfo);
  3026. else
  3027. LCDBDesPtr = XGI_GetLcdPtr(XGI_LCDDesDataTable, ModeIdIndex,
  3028. pVBInfo);
  3029. tempah = pVBInfo->LCDResInfo;
  3030. tempah &= PanelResInfo;
  3031. if ((tempah == Panel_1024x768) || (tempah == Panel_1024x768x75)) {
  3032. tempbx = 1024;
  3033. tempcx = 768;
  3034. } else if ((tempah == Panel_1280x1024) ||
  3035. (tempah == Panel_1280x1024x75)) {
  3036. tempbx = 1280;
  3037. tempcx = 1024;
  3038. } else if (tempah == Panel_1400x1050) {
  3039. tempbx = 1400;
  3040. tempcx = 1050;
  3041. } else {
  3042. tempbx = 1600;
  3043. tempcx = 1200;
  3044. }
  3045. if (pVBInfo->LCDInfo & EnableScalingLCD) {
  3046. tempbx = pVBInfo->HDE;
  3047. tempcx = pVBInfo->VDE;
  3048. }
  3049. pushbx = tempbx;
  3050. tempax = pVBInfo->VT;
  3051. pVBInfo->LCDHDES = LCDBDesPtr->LCDHDES;
  3052. pVBInfo->LCDHRS = LCDBDesPtr->LCDHRS;
  3053. pVBInfo->LCDVDES = LCDBDesPtr->LCDVDES;
  3054. pVBInfo->LCDVRS = LCDBDesPtr->LCDVRS;
  3055. tempbx = pVBInfo->LCDVDES;
  3056. tempcx += tempbx;
  3057. if (tempcx >= tempax)
  3058. tempcx -= tempax; /* lcdvdes */
  3059. temp = tempbx & 0x00FF; /* RVEQ1EQ=lcdvdes */
  3060. xgifb_reg_set(pVBInfo->Part2Port, 0x05, temp);
  3061. temp = tempcx & 0x00FF;
  3062. xgifb_reg_set(pVBInfo->Part2Port, 0x06, temp);
  3063. tempch = ((tempcx & 0xFF00) >> 8) & 0x07;
  3064. tempbh = ((tempbx & 0xFF00) >> 8) & 0x07;
  3065. tempah = tempch;
  3066. tempah <<= 3;
  3067. tempah |= tempbh;
  3068. xgifb_reg_set(pVBInfo->Part2Port, 0x02, tempah);
  3069. /* getlcdsync() */
  3070. XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
  3071. tempcx = tempbx;
  3072. tempax = pVBInfo->VT;
  3073. tempbx = pVBInfo->LCDVRS;
  3074. tempcx += tempbx;
  3075. if (tempcx >= tempax)
  3076. tempcx -= tempax;
  3077. temp = tempbx & 0x00FF; /* RTVACTEE=lcdvrs */
  3078. xgifb_reg_set(pVBInfo->Part2Port, 0x04, temp);
  3079. temp = (tempbx & 0xFF00) >> 8;
  3080. temp <<= 4;
  3081. temp |= (tempcx & 0x000F);
  3082. xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
  3083. tempcx = pushbx;
  3084. tempax = pVBInfo->HT;
  3085. tempbx = pVBInfo->LCDHDES;
  3086. tempbx &= 0x0FFF;
  3087. if (XGI_IsLCDDualLink(pVBInfo)) {
  3088. tempax >>= 1;
  3089. tempbx >>= 1;
  3090. tempcx >>= 1;
  3091. }
  3092. if (pVBInfo->VBType & VB_SIS302LV)
  3093. tempbx += 1;
  3094. if (pVBInfo->VBType & VB_XGI301C) /* tap4 */
  3095. tempbx += 1;
  3096. tempcx += tempbx;
  3097. if (tempcx >= tempax)
  3098. tempcx -= tempax;
  3099. temp = tempbx & 0x00FF;
  3100. xgifb_reg_set(pVBInfo->Part2Port, 0x1F, temp); /* RHBLKE=lcdhdes */
  3101. temp = ((tempbx & 0xFF00) >> 8) << 4;
  3102. xgifb_reg_set(pVBInfo->Part2Port, 0x20, temp);
  3103. temp = tempcx & 0x00FF;
  3104. xgifb_reg_set(pVBInfo->Part2Port, 0x23, temp); /* RHEQPLE=lcdhdee */
  3105. temp = (tempcx & 0xFF00) >> 8;
  3106. xgifb_reg_set(pVBInfo->Part2Port, 0x25, temp);
  3107. XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
  3108. tempcx = tempax;
  3109. tempax = pVBInfo->HT;
  3110. tempbx = pVBInfo->LCDHRS;
  3111. if (XGI_IsLCDDualLink(pVBInfo)) {
  3112. tempax >>= 1;
  3113. tempbx >>= 1;
  3114. tempcx >>= 1;
  3115. }
  3116. if (pVBInfo->VBType & VB_SIS302LV)
  3117. tempbx += 1;
  3118. tempcx += tempbx;
  3119. if (tempcx >= tempax)
  3120. tempcx -= tempax;
  3121. temp = tempbx & 0x00FF; /* RHBURSTS=lcdhrs */
  3122. xgifb_reg_set(pVBInfo->Part2Port, 0x1C, temp);
  3123. temp = (tempbx & 0xFF00) >> 8;
  3124. temp <<= 4;
  3125. xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F0, temp);
  3126. temp = tempcx & 0x00FF; /* RHSYEXP2S=lcdhre */
  3127. xgifb_reg_set(pVBInfo->Part2Port, 0x21, temp);
  3128. if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
  3129. if (pVBInfo->VGAVDE == 525) {
  3130. if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
  3131. | VB_SIS301LV | VB_SIS302LV
  3132. | VB_XGI301C)) {
  3133. temp = 0xC6;
  3134. } else
  3135. temp = 0xC4;
  3136. xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
  3137. xgifb_reg_set(pVBInfo->Part2Port, 0x30, 0xB3);
  3138. }
  3139. if (pVBInfo->VGAVDE == 420) {
  3140. if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
  3141. | VB_SIS301LV | VB_SIS302LV
  3142. | VB_XGI301C)) {
  3143. temp = 0x4F;
  3144. } else
  3145. temp = 0x4E;
  3146. xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
  3147. }
  3148. }
  3149. }
  3150. /* --------------------------------------------------------------------- */
  3151. /* Function : XGI_GetTap4Ptr */
  3152. /* Input : */
  3153. /* Output : di -> Tap4 Reg. Setting Pointer */
  3154. /* Description : */
  3155. /* --------------------------------------------------------------------- */
  3156. static struct XGI301C_Tap4TimingStruct const
  3157. *XGI_GetTap4Ptr(unsigned short tempcx, struct vb_device_info *pVBInfo)
  3158. {
  3159. unsigned short tempax, tempbx, i;
  3160. struct XGI301C_Tap4TimingStruct const *Tap4TimingPtr;
  3161. if (tempcx == 0) {
  3162. tempax = pVBInfo->VGAHDE;
  3163. tempbx = pVBInfo->HDE;
  3164. } else {
  3165. tempax = pVBInfo->VGAVDE;
  3166. tempbx = pVBInfo->VDE;
  3167. }
  3168. if (tempax <= tempbx)
  3169. return &xgifb_tap4_timing[0];
  3170. Tap4TimingPtr = xgifb_ntsc_525_tap4_timing; /* NTSC */
  3171. if (pVBInfo->TVInfo & TVSetPAL)
  3172. Tap4TimingPtr = PALTap4Timing;
  3173. if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
  3174. if ((pVBInfo->TVInfo & TVSetYPbPr525i) ||
  3175. (pVBInfo->TVInfo & TVSetYPbPr525p))
  3176. Tap4TimingPtr = xgifb_ntsc_525_tap4_timing;
  3177. if (pVBInfo->TVInfo & TVSetYPbPr750p)
  3178. Tap4TimingPtr = YPbPr750pTap4Timing;
  3179. }
  3180. if (pVBInfo->VBInfo & SetCRT2ToHiVision)
  3181. Tap4TimingPtr = xgifb_tap4_timing;
  3182. i = 0;
  3183. while (Tap4TimingPtr[i].DE != 0xFFFF) {
  3184. if (Tap4TimingPtr[i].DE == tempax)
  3185. break;
  3186. i++;
  3187. }
  3188. return &Tap4TimingPtr[i];
  3189. }
  3190. static void XGI_SetTap4Regs(struct vb_device_info *pVBInfo)
  3191. {
  3192. unsigned short i, j;
  3193. struct XGI301C_Tap4TimingStruct const *Tap4TimingPtr;
  3194. if (!(pVBInfo->VBType & VB_XGI301C))
  3195. return;
  3196. Tap4TimingPtr = XGI_GetTap4Ptr(0, pVBInfo); /* Set Horizontal Scaling */
  3197. for (i = 0x80, j = 0; i <= 0xBF; i++, j++)
  3198. xgifb_reg_set(pVBInfo->Part2Port, i, Tap4TimingPtr->Reg[j]);
  3199. if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
  3200. (!(pVBInfo->VBInfo & SetCRT2ToHiVision))) {
  3201. /* Set Vertical Scaling */
  3202. Tap4TimingPtr = XGI_GetTap4Ptr(1, pVBInfo);
  3203. for (i = 0xC0, j = 0; i < 0xFF; i++, j++)
  3204. xgifb_reg_set(pVBInfo->Part2Port,
  3205. i,
  3206. Tap4TimingPtr->Reg[j]);
  3207. }
  3208. if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
  3209. (!(pVBInfo->VBInfo & SetCRT2ToHiVision)))
  3210. /* Enable V.Scaling */
  3211. xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x04);
  3212. else
  3213. /* Enable H.Scaling */
  3214. xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x10);
  3215. }
  3216. static void XGI_SetGroup3(unsigned short ModeIdIndex,
  3217. struct vb_device_info *pVBInfo)
  3218. {
  3219. unsigned short i;
  3220. unsigned char const *tempdi;
  3221. unsigned short modeflag;
  3222. /* si+Ext_ResInfo */
  3223. modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  3224. xgifb_reg_set(pVBInfo->Part3Port, 0x00, 0x00);
  3225. if (pVBInfo->TVInfo & TVSetPAL) {
  3226. xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
  3227. xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
  3228. } else {
  3229. xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xF5);
  3230. xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xB7);
  3231. }
  3232. if (!(pVBInfo->VBInfo & SetCRT2ToTV))
  3233. return;
  3234. if (pVBInfo->TVInfo & TVSetPALM) {
  3235. xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
  3236. xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
  3237. xgifb_reg_set(pVBInfo->Part3Port, 0x3D, 0xA8);
  3238. }
  3239. if ((pVBInfo->VBInfo & SetCRT2ToHiVision) || (pVBInfo->VBInfo
  3240. & SetCRT2ToYPbPr525750)) {
  3241. if (pVBInfo->TVInfo & TVSetYPbPr525i)
  3242. return;
  3243. tempdi = XGI330_HiTVGroup3Data;
  3244. if (pVBInfo->SetFlag & TVSimuMode) {
  3245. tempdi = XGI330_HiTVGroup3Simu;
  3246. if (!(modeflag & Charx8Dot))
  3247. tempdi = XGI330_HiTVGroup3Text;
  3248. }
  3249. if (pVBInfo->TVInfo & TVSetYPbPr525p)
  3250. tempdi = XGI330_Ren525pGroup3;
  3251. if (pVBInfo->TVInfo & TVSetYPbPr750p)
  3252. tempdi = XGI330_Ren750pGroup3;
  3253. for (i = 0; i <= 0x3E; i++)
  3254. xgifb_reg_set(pVBInfo->Part3Port, i, tempdi[i]);
  3255. if (pVBInfo->VBType & VB_XGI301C) { /* Marcovision */
  3256. if (pVBInfo->TVInfo & TVSetYPbPr525p)
  3257. xgifb_reg_set(pVBInfo->Part3Port, 0x28, 0x3f);
  3258. }
  3259. }
  3260. }
  3261. static void XGI_SetGroup4(unsigned short ModeIdIndex,
  3262. unsigned short RefreshRateTableIndex,
  3263. struct vb_device_info *pVBInfo)
  3264. {
  3265. unsigned short tempax, tempcx, tempbx, modeflag, temp, temp2;
  3266. unsigned long tempebx, tempeax, templong;
  3267. /* si+Ext_ResInfo */
  3268. modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  3269. temp = pVBInfo->RVBHCFACT;
  3270. xgifb_reg_set(pVBInfo->Part4Port, 0x13, temp);
  3271. tempbx = pVBInfo->RVBHCMAX;
  3272. temp = tempbx & 0x00FF;
  3273. xgifb_reg_set(pVBInfo->Part4Port, 0x14, temp);
  3274. temp2 = ((tempbx & 0xFF00) >> 8) << 7;
  3275. tempcx = pVBInfo->VGAHT - 1;
  3276. temp = tempcx & 0x00FF;
  3277. xgifb_reg_set(pVBInfo->Part4Port, 0x16, temp);
  3278. temp = ((tempcx & 0xFF00) >> 8) << 3;
  3279. temp2 |= temp;
  3280. tempcx = pVBInfo->VGAVT - 1;
  3281. if (!(pVBInfo->VBInfo & SetCRT2ToTV))
  3282. tempcx -= 5;
  3283. temp = tempcx & 0x00FF;
  3284. xgifb_reg_set(pVBInfo->Part4Port, 0x17, temp);
  3285. temp = temp2 | ((tempcx & 0xFF00) >> 8);
  3286. xgifb_reg_set(pVBInfo->Part4Port, 0x15, temp);
  3287. xgifb_reg_or(pVBInfo->Part4Port, 0x0D, 0x08);
  3288. tempcx = pVBInfo->VBInfo;
  3289. tempbx = pVBInfo->VGAHDE;
  3290. if (modeflag & HalfDCLK)
  3291. tempbx >>= 1;
  3292. if (XGI_IsLCDDualLink(pVBInfo))
  3293. tempbx >>= 1;
  3294. if (tempcx & SetCRT2ToHiVision) {
  3295. temp = 0;
  3296. if (tempbx <= 1024)
  3297. temp = 0xA0;
  3298. if (tempbx == 1280)
  3299. temp = 0xC0;
  3300. } else if (tempcx & SetCRT2ToTV) {
  3301. temp = 0xA0;
  3302. if (tempbx <= 800)
  3303. temp = 0x80;
  3304. } else {
  3305. temp = 0x80;
  3306. if (pVBInfo->VBInfo & SetCRT2ToLCD) {
  3307. temp = 0;
  3308. if (tempbx > 800)
  3309. temp = 0x60;
  3310. }
  3311. }
  3312. if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p)) {
  3313. temp = 0x00;
  3314. if (pVBInfo->VGAHDE == 1280)
  3315. temp = 0x40;
  3316. if (pVBInfo->VGAHDE == 1024)
  3317. temp = 0x20;
  3318. }
  3319. xgifb_reg_and_or(pVBInfo->Part4Port, 0x0E, ~0xEF, temp);
  3320. tempebx = pVBInfo->VDE;
  3321. tempcx = pVBInfo->RVBHRS;
  3322. temp = tempcx & 0x00FF;
  3323. xgifb_reg_set(pVBInfo->Part4Port, 0x18, temp);
  3324. tempeax = pVBInfo->VGAVDE;
  3325. tempcx |= 0x04000;
  3326. if (tempeax <= tempebx) {
  3327. tempcx = (tempcx & (~0x4000));
  3328. tempeax = pVBInfo->VGAVDE;
  3329. } else {
  3330. tempeax -= tempebx;
  3331. }
  3332. templong = (tempeax * 256 * 1024) % tempebx;
  3333. tempeax = (tempeax * 256 * 1024) / tempebx;
  3334. tempebx = tempeax;
  3335. if (templong != 0)
  3336. tempebx++;
  3337. temp = (unsigned short) (tempebx & 0x000000FF);
  3338. xgifb_reg_set(pVBInfo->Part4Port, 0x1B, temp);
  3339. temp = (unsigned short) ((tempebx & 0x0000FF00) >> 8);
  3340. xgifb_reg_set(pVBInfo->Part4Port, 0x1A, temp);
  3341. tempbx = (unsigned short) (tempebx >> 16);
  3342. temp = tempbx & 0x00FF;
  3343. temp <<= 4;
  3344. temp |= ((tempcx & 0xFF00) >> 8);
  3345. xgifb_reg_set(pVBInfo->Part4Port, 0x19, temp);
  3346. /* 301b */
  3347. if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
  3348. | VB_SIS302LV | VB_XGI301C)) {
  3349. temp = 0x0028;
  3350. xgifb_reg_set(pVBInfo->Part4Port, 0x1C, temp);
  3351. tempax = pVBInfo->VGAHDE;
  3352. if (modeflag & HalfDCLK)
  3353. tempax >>= 1;
  3354. if (XGI_IsLCDDualLink(pVBInfo))
  3355. tempax >>= 1;
  3356. if (pVBInfo->VBInfo & SetCRT2ToLCD) {
  3357. if (tempax > 800)
  3358. tempax -= 800;
  3359. } else if (pVBInfo->VGAHDE > 800) {
  3360. if (pVBInfo->VGAHDE == 1024)
  3361. tempax = (tempax * 25 / 32) - 1;
  3362. else
  3363. tempax = (tempax * 20 / 32) - 1;
  3364. }
  3365. tempax -= 1;
  3366. temp = (tempax & 0xFF00) >> 8;
  3367. temp = (temp & 0x0003) << 4;
  3368. xgifb_reg_set(pVBInfo->Part4Port, 0x1E, temp);
  3369. temp = (tempax & 0x00FF);
  3370. xgifb_reg_set(pVBInfo->Part4Port, 0x1D, temp);
  3371. if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToHiVision)) {
  3372. if (pVBInfo->VGAHDE > 800)
  3373. xgifb_reg_or(pVBInfo->Part4Port, 0x1E, 0x08);
  3374. }
  3375. temp = 0x0036;
  3376. if (pVBInfo->VBInfo & SetCRT2ToTV) {
  3377. if (!(pVBInfo->TVInfo & (NTSC1024x768
  3378. | TVSetYPbPr525p | TVSetYPbPr750p
  3379. | TVSetHiVision))) {
  3380. temp |= 0x0001;
  3381. if ((pVBInfo->VBInfo & SetInSlaveMode)
  3382. && (!(pVBInfo->TVInfo
  3383. & TVSimuMode)))
  3384. temp &= (~0x0001);
  3385. }
  3386. }
  3387. xgifb_reg_and_or(pVBInfo->Part4Port, 0x1F, 0x00C0, temp);
  3388. tempbx = pVBInfo->HT;
  3389. if (XGI_IsLCDDualLink(pVBInfo))
  3390. tempbx >>= 1;
  3391. tempbx = (tempbx >> 1) - 2;
  3392. temp = ((tempbx & 0x0700) >> 8) << 3;
  3393. xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, 0x00C0, temp);
  3394. temp = tempbx & 0x00FF;
  3395. xgifb_reg_set(pVBInfo->Part4Port, 0x22, temp);
  3396. }
  3397. /* end 301b */
  3398. XGI_SetCRT2VCLK(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
  3399. }
  3400. static void XGINew_EnableCRT2(struct vb_device_info *pVBInfo)
  3401. {
  3402. xgifb_reg_and_or(pVBInfo->P3c4, 0x1E, 0xFF, 0x20);
  3403. }
  3404. static void XGI_SetGroup5(struct vb_device_info *pVBInfo)
  3405. {
  3406. if (pVBInfo->ModeType == ModeVGA) {
  3407. if (!(pVBInfo->VBInfo & (SetInSlaveMode | LoadDACFlag
  3408. | DisableCRT2Display))) {
  3409. XGINew_EnableCRT2(pVBInfo);
  3410. }
  3411. }
  3412. }
  3413. static void XGI_DisableGatingCRT(struct vb_device_info *pVBInfo)
  3414. {
  3415. xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x00);
  3416. }
  3417. static unsigned char XGI_XG21CheckLVDSMode(struct xgifb_video_info *xgifb_info,
  3418. unsigned short ModeNo, unsigned short ModeIdIndex)
  3419. {
  3420. unsigned short xres, yres, colordepth, modeflag, resindex;
  3421. resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  3422. xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
  3423. yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
  3424. /* si+St_ModeFlag */
  3425. modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  3426. if (!(modeflag & Charx8Dot)) {
  3427. xres /= 9;
  3428. xres *= 8;
  3429. }
  3430. if ((ModeNo > 0x13) && (modeflag & HalfDCLK))
  3431. xres *= 2;
  3432. if ((ModeNo > 0x13) && (modeflag & DoubleScanMode))
  3433. yres *= 2;
  3434. if (xres > xgifb_info->lvds_data.LVDSHDE)
  3435. return 0;
  3436. if (yres > xgifb_info->lvds_data.LVDSVDE)
  3437. return 0;
  3438. if (xres != xgifb_info->lvds_data.LVDSHDE ||
  3439. yres != xgifb_info->lvds_data.LVDSVDE) {
  3440. colordepth = XGI_GetColorDepth(ModeIdIndex);
  3441. if (colordepth > 2)
  3442. return 0;
  3443. }
  3444. return 1;
  3445. }
  3446. static void xgifb_set_lvds(struct xgifb_video_info *xgifb_info,
  3447. int chip_id,
  3448. unsigned short ModeIdIndex,
  3449. struct vb_device_info *pVBInfo)
  3450. {
  3451. unsigned char temp, Miscdata;
  3452. unsigned short xres, yres, modeflag, resindex;
  3453. unsigned short LVDSHT, LVDSHBS, LVDSHRS, LVDSHRE, LVDSHBE;
  3454. unsigned short LVDSVT, LVDSVBS, LVDSVRS, LVDSVRE, LVDSVBE;
  3455. unsigned short value;
  3456. temp = (unsigned char) ((xgifb_info->lvds_data.LVDS_Capability &
  3457. (LCDPolarity << 8)) >> 8);
  3458. temp &= LCDPolarity;
  3459. Miscdata = inb(pVBInfo->P3cc);
  3460. outb((Miscdata & 0x3F) | temp, pVBInfo->P3c2);
  3461. temp = xgifb_info->lvds_data.LVDS_Capability & LCDPolarity;
  3462. /* SR35[7] FP VSync polarity */
  3463. xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x80, temp & 0x80);
  3464. /* SR30[5] FP HSync polarity */
  3465. xgifb_reg_and_or(pVBInfo->P3c4, 0x30, ~0x20, (temp & 0x40) >> 1);
  3466. if (chip_id == XG27)
  3467. XGI_SetXG27FPBits(pVBInfo);
  3468. else
  3469. XGI_SetXG21FPBits(pVBInfo);
  3470. resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  3471. xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
  3472. yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
  3473. /* si+St_ModeFlag */
  3474. modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  3475. if (!(modeflag & Charx8Dot))
  3476. xres = xres * 8 / 9;
  3477. LVDSHT = xgifb_info->lvds_data.LVDSHT;
  3478. LVDSHBS = xres + (xgifb_info->lvds_data.LVDSHDE - xres) / 2;
  3479. if (LVDSHBS > LVDSHT)
  3480. LVDSHBS -= LVDSHT;
  3481. LVDSHRS = LVDSHBS + xgifb_info->lvds_data.LVDSHFP;
  3482. if (LVDSHRS > LVDSHT)
  3483. LVDSHRS -= LVDSHT;
  3484. LVDSHRE = LVDSHRS + xgifb_info->lvds_data.LVDSHSYNC;
  3485. if (LVDSHRE > LVDSHT)
  3486. LVDSHRE -= LVDSHT;
  3487. LVDSHBE = LVDSHBS + LVDSHT - xgifb_info->lvds_data.LVDSHDE;
  3488. LVDSVT = xgifb_info->lvds_data.LVDSVT;
  3489. LVDSVBS = yres + (xgifb_info->lvds_data.LVDSVDE - yres) / 2;
  3490. if (modeflag & DoubleScanMode)
  3491. LVDSVBS += yres / 2;
  3492. if (LVDSVBS > LVDSVT)
  3493. LVDSVBS -= LVDSVT;
  3494. LVDSVRS = LVDSVBS + xgifb_info->lvds_data.LVDSVFP;
  3495. if (LVDSVRS > LVDSVT)
  3496. LVDSVRS -= LVDSVT;
  3497. LVDSVRE = LVDSVRS + xgifb_info->lvds_data.LVDSVSYNC;
  3498. if (LVDSVRE > LVDSVT)
  3499. LVDSVRE -= LVDSVT;
  3500. LVDSVBE = LVDSVBS + LVDSVT - xgifb_info->lvds_data.LVDSVDE;
  3501. temp = xgifb_reg_get(pVBInfo->P3d4, 0x11);
  3502. xgifb_reg_set(pVBInfo->P3d4, 0x11, temp & 0x7f); /* Unlock CRTC */
  3503. if (!(modeflag & Charx8Dot))
  3504. xgifb_reg_or(pVBInfo->P3c4, 0x1, 0x1);
  3505. /* HT SR0B[1:0] CR00 */
  3506. value = (LVDSHT >> 3) - 5;
  3507. xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x03, (value & 0x300) >> 8);
  3508. xgifb_reg_set(pVBInfo->P3d4, 0x0, (value & 0xFF));
  3509. /* HBS SR0B[5:4] CR02 */
  3510. value = (LVDSHBS >> 3) - 1;
  3511. xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x30, (value & 0x300) >> 4);
  3512. xgifb_reg_set(pVBInfo->P3d4, 0x2, (value & 0xFF));
  3513. /* HBE SR0C[1:0] CR05[7] CR03[4:0] */
  3514. value = (LVDSHBE >> 3) - 1;
  3515. xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x03, (value & 0xC0) >> 6);
  3516. xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x80, (value & 0x20) << 2);
  3517. xgifb_reg_and_or(pVBInfo->P3d4, 0x03, ~0x1F, value & 0x1F);
  3518. /* HRS SR0B[7:6] CR04 */
  3519. value = (LVDSHRS >> 3) + 2;
  3520. xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0xC0, (value & 0x300) >> 2);
  3521. xgifb_reg_set(pVBInfo->P3d4, 0x4, (value & 0xFF));
  3522. /* Panel HRS SR2F[1:0] SR2E[7:0] */
  3523. value--;
  3524. xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0x03, (value & 0x300) >> 8);
  3525. xgifb_reg_set(pVBInfo->P3c4, 0x2E, (value & 0xFF));
  3526. /* HRE SR0C[2] CR05[4:0] */
  3527. value = (LVDSHRE >> 3) + 2;
  3528. xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x04, (value & 0x20) >> 3);
  3529. xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x1F, value & 0x1F);
  3530. /* Panel HRE SR2F[7:2] */
  3531. value--;
  3532. xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0xFC, value << 2);
  3533. /* VT SR0A[0] CR07[5][0] CR06 */
  3534. value = LVDSVT - 2;
  3535. xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x01, (value & 0x400) >> 10);
  3536. xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x20, (value & 0x200) >> 4);
  3537. xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x01, (value & 0x100) >> 8);
  3538. xgifb_reg_set(pVBInfo->P3d4, 0x06, (value & 0xFF));
  3539. /* VBS SR0A[2] CR09[5] CR07[3] CR15 */
  3540. value = LVDSVBS - 1;
  3541. xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x04, (value & 0x400) >> 8);
  3542. xgifb_reg_and_or(pVBInfo->P3d4, 0x09, ~0x20, (value & 0x200) >> 4);
  3543. xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x08, (value & 0x100) >> 5);
  3544. xgifb_reg_set(pVBInfo->P3d4, 0x15, (value & 0xFF));
  3545. /* VBE SR0A[4] CR16 */
  3546. value = LVDSVBE - 1;
  3547. xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x10, (value & 0x100) >> 4);
  3548. xgifb_reg_set(pVBInfo->P3d4, 0x16, (value & 0xFF));
  3549. /* VRS SR0A[3] CR7[7][2] CR10 */
  3550. value = LVDSVRS - 1;
  3551. xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x08, (value & 0x400) >> 7);
  3552. xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x80, (value & 0x200) >> 2);
  3553. xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x04, (value & 0x100) >> 6);
  3554. xgifb_reg_set(pVBInfo->P3d4, 0x10, (value & 0xFF));
  3555. if (chip_id == XG27) {
  3556. /* Panel VRS SR35[2:0] SR34[7:0] */
  3557. xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07,
  3558. (value & 0x700) >> 8);
  3559. xgifb_reg_set(pVBInfo->P3c4, 0x34, value & 0xFF);
  3560. } else {
  3561. /* Panel VRS SR3F[1:0] SR34[7:0] SR33[0] */
  3562. xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0x03,
  3563. (value & 0x600) >> 9);
  3564. xgifb_reg_set(pVBInfo->P3c4, 0x34, (value >> 1) & 0xFF);
  3565. xgifb_reg_and_or(pVBInfo->P3d4, 0x33, ~0x01, value & 0x01);
  3566. }
  3567. /* VRE SR0A[5] CR11[3:0] */
  3568. value = LVDSVRE - 1;
  3569. xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x20, (value & 0x10) << 1);
  3570. xgifb_reg_and_or(pVBInfo->P3d4, 0x11, ~0x0F, value & 0x0F);
  3571. /* Panel VRE SR3F[7:2] */
  3572. if (chip_id == XG27)
  3573. xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
  3574. (value << 2) & 0xFC);
  3575. else
  3576. /* SR3F[7] has to be 0, h/w bug */
  3577. xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
  3578. (value << 2) & 0x7C);
  3579. for (temp = 0, value = 0; temp < 3; temp++) {
  3580. xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, value);
  3581. xgifb_reg_set(pVBInfo->P3c4,
  3582. 0x2B, xgifb_info->lvds_data.VCLKData1);
  3583. xgifb_reg_set(pVBInfo->P3c4,
  3584. 0x2C, xgifb_info->lvds_data.VCLKData2);
  3585. value += 0x10;
  3586. }
  3587. if (!(modeflag & Charx8Dot)) {
  3588. inb(pVBInfo->P3da); /* reset 3da */
  3589. outb(0x13, pVBInfo->P3c0); /* set index */
  3590. /* set data, panning = 0, shift left 1 dot*/
  3591. outb(0x00, pVBInfo->P3c0);
  3592. inb(pVBInfo->P3da); /* Enable Attribute */
  3593. outb(0x20, pVBInfo->P3c0);
  3594. inb(pVBInfo->P3da); /* reset 3da */
  3595. }
  3596. }
  3597. /* --------------------------------------------------------------------- */
  3598. /* Function : XGI_IsLCDON */
  3599. /* Input : */
  3600. /* Output : 0 : Skip PSC Control */
  3601. /* 1: Disable PSC */
  3602. /* Description : */
  3603. /* --------------------------------------------------------------------- */
  3604. static unsigned char XGI_IsLCDON(struct vb_device_info *pVBInfo)
  3605. {
  3606. unsigned short tempax;
  3607. tempax = pVBInfo->VBInfo;
  3608. if (tempax & SetCRT2ToDualEdge)
  3609. return 0;
  3610. else if (tempax & (DisableCRT2Display | SwitchCRT2 | SetSimuScanMode))
  3611. return 1;
  3612. return 0;
  3613. }
  3614. static void XGI_DisableBridge(struct xgifb_video_info *xgifb_info,
  3615. struct xgi_hw_device_info *HwDeviceExtension,
  3616. struct vb_device_info *pVBInfo)
  3617. {
  3618. unsigned short tempah = 0;
  3619. if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
  3620. | VB_SIS302LV | VB_XGI301C)) {
  3621. tempah = 0x3F;
  3622. if (!(pVBInfo->VBInfo &
  3623. (DisableCRT2Display | SetSimuScanMode))) {
  3624. if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
  3625. if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
  3626. tempah = 0x7F; /* Disable Channel A */
  3627. }
  3628. }
  3629. /* disable part4_1f */
  3630. xgifb_reg_and(pVBInfo->Part4Port, 0x1F, tempah);
  3631. if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
  3632. if (((pVBInfo->VBInfo &
  3633. (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))) ||
  3634. (XGI_IsLCDON(pVBInfo)))
  3635. /* LVDS Driver power down */
  3636. xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x80);
  3637. }
  3638. if (pVBInfo->VBInfo & (DisableCRT2Display | XGI_SetCRT2ToLCDA |
  3639. SetSimuScanMode))
  3640. XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
  3641. if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
  3642. /* Power down */
  3643. xgifb_reg_and(pVBInfo->Part1Port, 0x1e, 0xdf);
  3644. /* disable TV as primary VGA swap */
  3645. xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xdf);
  3646. if ((pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToDualEdge)))
  3647. xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xdf);
  3648. if ((pVBInfo->VBInfo &
  3649. (DisableCRT2Display | SetSimuScanMode)) ||
  3650. ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) &&
  3651. (pVBInfo->VBInfo &
  3652. (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))))
  3653. xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
  3654. if ((pVBInfo->VBInfo &
  3655. (DisableCRT2Display | SetSimuScanMode)) ||
  3656. (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) ||
  3657. (pVBInfo->VBInfo &
  3658. (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))) {
  3659. /* save Part1 index 0 */
  3660. tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
  3661. /* BTDAC = 1, avoid VB reset */
  3662. xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x10);
  3663. /* disable CRT2 */
  3664. xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
  3665. /* restore Part1 index 0 */
  3666. xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
  3667. }
  3668. } else { /* {301} */
  3669. if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
  3670. xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
  3671. /* Disable CRT2 */
  3672. xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
  3673. /* Disable TV asPrimary VGA swap */
  3674. xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xDF);
  3675. }
  3676. if (pVBInfo->VBInfo & (DisableCRT2Display | XGI_SetCRT2ToLCDA
  3677. | SetSimuScanMode))
  3678. XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
  3679. }
  3680. }
  3681. /* --------------------------------------------------------------------- */
  3682. /* Function : XGI_GetTVPtrIndex */
  3683. /* Input : */
  3684. /* Output : */
  3685. /* Description : bx 0 : ExtNTSC */
  3686. /* 1 : StNTSC */
  3687. /* 2 : ExtPAL */
  3688. /* 3 : StPAL */
  3689. /* 4 : ExtHiTV */
  3690. /* 5 : StHiTV */
  3691. /* 6 : Ext525i */
  3692. /* 7 : St525i */
  3693. /* 8 : Ext525p */
  3694. /* 9 : St525p */
  3695. /* A : Ext750p */
  3696. /* B : St750p */
  3697. /* --------------------------------------------------------------------- */
  3698. static unsigned short XGI_GetTVPtrIndex(struct vb_device_info *pVBInfo)
  3699. {
  3700. unsigned short tempbx = 0;
  3701. if (pVBInfo->TVInfo & TVSetPAL)
  3702. tempbx = 2;
  3703. if (pVBInfo->TVInfo & TVSetHiVision)
  3704. tempbx = 4;
  3705. if (pVBInfo->TVInfo & TVSetYPbPr525i)
  3706. tempbx = 6;
  3707. if (pVBInfo->TVInfo & TVSetYPbPr525p)
  3708. tempbx = 8;
  3709. if (pVBInfo->TVInfo & TVSetYPbPr750p)
  3710. tempbx = 10;
  3711. if (pVBInfo->TVInfo & TVSimuMode)
  3712. tempbx++;
  3713. return tempbx;
  3714. }
  3715. /* --------------------------------------------------------------------- */
  3716. /* Function : XGI_GetTVPtrIndex2 */
  3717. /* Input : */
  3718. /* Output : bx 0 : NTSC */
  3719. /* 1 : PAL */
  3720. /* 2 : PALM */
  3721. /* 3 : PALN */
  3722. /* 4 : NTSC1024x768 */
  3723. /* 5 : PAL-M 1024x768 */
  3724. /* 6-7: reserved */
  3725. /* cl 0 : YFilter1 */
  3726. /* 1 : YFilter2 */
  3727. /* ch 0 : 301A */
  3728. /* 1 : 301B/302B/301LV/302LV */
  3729. /* Description : */
  3730. /* --------------------------------------------------------------------- */
  3731. static void XGI_GetTVPtrIndex2(unsigned short *tempbx, unsigned char *tempcl,
  3732. unsigned char *tempch, struct vb_device_info *pVBInfo)
  3733. {
  3734. *tempbx = 0;
  3735. *tempcl = 0;
  3736. *tempch = 0;
  3737. if (pVBInfo->TVInfo & TVSetPAL)
  3738. *tempbx = 1;
  3739. if (pVBInfo->TVInfo & TVSetPALM)
  3740. *tempbx = 2;
  3741. if (pVBInfo->TVInfo & TVSetPALN)
  3742. *tempbx = 3;
  3743. if (pVBInfo->TVInfo & NTSC1024x768) {
  3744. *tempbx = 4;
  3745. if (pVBInfo->TVInfo & TVSetPALM)
  3746. *tempbx = 5;
  3747. }
  3748. if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
  3749. | VB_SIS302LV | VB_XGI301C)) {
  3750. if ((!(pVBInfo->VBInfo & SetInSlaveMode)) || (pVBInfo->TVInfo
  3751. & TVSimuMode)) {
  3752. *tempbx += 8;
  3753. *tempcl += 1;
  3754. }
  3755. }
  3756. if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
  3757. | VB_SIS302LV | VB_XGI301C))
  3758. (*tempch)++;
  3759. }
  3760. static void XGI_SetDelayComp(struct vb_device_info *pVBInfo)
  3761. {
  3762. unsigned char tempah, tempbl, tempbh;
  3763. if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
  3764. | VB_SIS302LV | VB_XGI301C)) {
  3765. if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA
  3766. | SetCRT2ToTV | SetCRT2ToRAMDAC)) {
  3767. tempbh = 0;
  3768. tempbl = XGI301TVDelay;
  3769. if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
  3770. tempbl >>= 4;
  3771. if (pVBInfo->VBInfo &
  3772. (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
  3773. tempbh = XGI301LCDDelay;
  3774. if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
  3775. tempbl = tempbh;
  3776. }
  3777. tempbl &= 0x0F;
  3778. tempbh &= 0xF0;
  3779. tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2D);
  3780. if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD
  3781. | SetCRT2ToTV)) { /* Channel B */
  3782. tempah &= 0xF0;
  3783. tempah |= tempbl;
  3784. }
  3785. if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
  3786. /* Channel A */
  3787. tempah &= 0x0F;
  3788. tempah |= tempbh;
  3789. }
  3790. xgifb_reg_set(pVBInfo->Part1Port, 0x2D, tempah);
  3791. }
  3792. }
  3793. }
  3794. static void XGI_SetLCDCap_A(unsigned short tempcx,
  3795. struct vb_device_info *pVBInfo)
  3796. {
  3797. unsigned short temp;
  3798. temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
  3799. if (temp & LCDRGB18Bit) {
  3800. xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
  3801. /* Enable Dither */
  3802. (unsigned short) (0x20 | (tempcx & 0x00C0)));
  3803. xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x80);
  3804. } else {
  3805. xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
  3806. (unsigned short) (0x30 | (tempcx & 0x00C0)));
  3807. xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x00);
  3808. }
  3809. }
  3810. /* --------------------------------------------------------------------- */
  3811. /* Function : XGI_SetLCDCap_B */
  3812. /* Input : cx -> LCD Capability */
  3813. /* Output : */
  3814. /* Description : */
  3815. /* --------------------------------------------------------------------- */
  3816. static void XGI_SetLCDCap_B(unsigned short tempcx,
  3817. struct vb_device_info *pVBInfo)
  3818. {
  3819. if (tempcx & EnableLCD24bpp) /* 24bits */
  3820. xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
  3821. (unsigned short) (((tempcx & 0x00ff) >> 6)
  3822. | 0x0c));
  3823. else
  3824. xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
  3825. (unsigned short) (((tempcx & 0x00ff) >> 6)
  3826. | 0x18)); /* Enable Dither */
  3827. }
  3828. static void XGI_LongWait(struct vb_device_info *pVBInfo)
  3829. {
  3830. unsigned short i;
  3831. i = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
  3832. if (!(i & 0xC0)) {
  3833. for (i = 0; i < 0xFFFF; i++) {
  3834. if (!(inb(pVBInfo->P3da) & 0x08))
  3835. break;
  3836. }
  3837. for (i = 0; i < 0xFFFF; i++) {
  3838. if ((inb(pVBInfo->P3da) & 0x08))
  3839. break;
  3840. }
  3841. }
  3842. }
  3843. static void SetSpectrum(struct vb_device_info *pVBInfo)
  3844. {
  3845. unsigned short index;
  3846. index = XGI_GetLCDCapPtr(pVBInfo);
  3847. /* disable down spectrum D[4] */
  3848. xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x8F);
  3849. XGI_LongWait(pVBInfo);
  3850. xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x20); /* reset spectrum */
  3851. XGI_LongWait(pVBInfo);
  3852. xgifb_reg_set(pVBInfo->Part4Port, 0x31,
  3853. pVBInfo->LCDCapList[index].Spectrum_31);
  3854. xgifb_reg_set(pVBInfo->Part4Port, 0x32,
  3855. pVBInfo->LCDCapList[index].Spectrum_32);
  3856. xgifb_reg_set(pVBInfo->Part4Port, 0x33,
  3857. pVBInfo->LCDCapList[index].Spectrum_33);
  3858. xgifb_reg_set(pVBInfo->Part4Port, 0x34,
  3859. pVBInfo->LCDCapList[index].Spectrum_34);
  3860. XGI_LongWait(pVBInfo);
  3861. xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x40); /* enable spectrum */
  3862. }
  3863. static void XGI_SetLCDCap(struct vb_device_info *pVBInfo)
  3864. {
  3865. unsigned short tempcx;
  3866. tempcx = pVBInfo->LCDCapList[XGI_GetLCDCapPtr(pVBInfo)].LCD_Capability;
  3867. if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV |
  3868. VB_SIS302LV | VB_XGI301C)) {
  3869. if (pVBInfo->VBType &
  3870. (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
  3871. /* Set 301LV Capability */
  3872. xgifb_reg_set(pVBInfo->Part4Port, 0x24,
  3873. (unsigned char) (tempcx & 0x1F));
  3874. }
  3875. /* VB Driving */
  3876. xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D,
  3877. ~((EnableVBCLKDRVLOW | EnablePLLSPLOW) >> 8),
  3878. (unsigned short) ((tempcx & (EnableVBCLKDRVLOW
  3879. | EnablePLLSPLOW)) >> 8));
  3880. if (pVBInfo->VBInfo & SetCRT2ToLCD)
  3881. XGI_SetLCDCap_B(tempcx, pVBInfo);
  3882. else if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
  3883. XGI_SetLCDCap_A(tempcx, pVBInfo);
  3884. if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
  3885. if (tempcx & EnableSpectrum)
  3886. SetSpectrum(pVBInfo);
  3887. }
  3888. } else {
  3889. /* LVDS,CH7017 */
  3890. XGI_SetLCDCap_A(tempcx, pVBInfo);
  3891. }
  3892. }
  3893. /* --------------------------------------------------------------------- */
  3894. /* Function : XGI_SetAntiFlicker */
  3895. /* Input : */
  3896. /* Output : */
  3897. /* Description : Set TV Customized Param. */
  3898. /* --------------------------------------------------------------------- */
  3899. static void XGI_SetAntiFlicker(struct vb_device_info *pVBInfo)
  3900. {
  3901. unsigned short tempbx;
  3902. unsigned char tempah;
  3903. if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
  3904. return;
  3905. tempbx = XGI_GetTVPtrIndex(pVBInfo);
  3906. tempbx &= 0xFE;
  3907. tempah = TVAntiFlickList[tempbx];
  3908. tempah <<= 4;
  3909. xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0x8F, tempah);
  3910. }
  3911. static void XGI_SetEdgeEnhance(struct vb_device_info *pVBInfo)
  3912. {
  3913. unsigned short tempbx;
  3914. unsigned char tempah;
  3915. tempbx = XGI_GetTVPtrIndex(pVBInfo);
  3916. tempbx &= 0xFE;
  3917. tempah = TVEdgeList[tempbx];
  3918. tempah <<= 5;
  3919. xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, tempah);
  3920. }
  3921. static void XGI_SetPhaseIncr(struct vb_device_info *pVBInfo)
  3922. {
  3923. unsigned short tempbx;
  3924. unsigned char tempcl, tempch;
  3925. unsigned long tempData;
  3926. XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
  3927. tempData = TVPhaseList[tempbx];
  3928. xgifb_reg_set(pVBInfo->Part2Port, 0x31, (unsigned short) (tempData
  3929. & 0x000000FF));
  3930. xgifb_reg_set(pVBInfo->Part2Port, 0x32, (unsigned short) ((tempData
  3931. & 0x0000FF00) >> 8));
  3932. xgifb_reg_set(pVBInfo->Part2Port, 0x33, (unsigned short) ((tempData
  3933. & 0x00FF0000) >> 16));
  3934. xgifb_reg_set(pVBInfo->Part2Port, 0x34, (unsigned short) ((tempData
  3935. & 0xFF000000) >> 24));
  3936. }
  3937. static void XGI_SetYFilter(unsigned short ModeIdIndex,
  3938. struct vb_device_info *pVBInfo)
  3939. {
  3940. unsigned short tempbx, index;
  3941. unsigned char const *filterPtr;
  3942. unsigned char tempcl, tempch, tempal;
  3943. XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
  3944. switch (tempbx) {
  3945. case 0x00:
  3946. case 0x04:
  3947. filterPtr = NTSCYFilter1;
  3948. break;
  3949. case 0x01:
  3950. filterPtr = PALYFilter1;
  3951. break;
  3952. case 0x02:
  3953. case 0x05:
  3954. case 0x0D:
  3955. case 0x03:
  3956. filterPtr = xgifb_palmn_yfilter1;
  3957. break;
  3958. case 0x08:
  3959. case 0x0C:
  3960. case 0x0A:
  3961. case 0x0B:
  3962. case 0x09:
  3963. filterPtr = xgifb_yfilter2;
  3964. break;
  3965. default:
  3966. return;
  3967. }
  3968. tempal = XGI330_EModeIDTable[ModeIdIndex].VB_ExtTVYFilterIndex;
  3969. if (tempcl == 0)
  3970. index = tempal * 4;
  3971. else
  3972. index = tempal * 7;
  3973. if ((tempcl == 0) && (tempch == 1)) {
  3974. xgifb_reg_set(pVBInfo->Part2Port, 0x35, 0);
  3975. xgifb_reg_set(pVBInfo->Part2Port, 0x36, 0);
  3976. xgifb_reg_set(pVBInfo->Part2Port, 0x37, 0);
  3977. xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
  3978. } else {
  3979. xgifb_reg_set(pVBInfo->Part2Port, 0x35, filterPtr[index++]);
  3980. xgifb_reg_set(pVBInfo->Part2Port, 0x36, filterPtr[index++]);
  3981. xgifb_reg_set(pVBInfo->Part2Port, 0x37, filterPtr[index++]);
  3982. xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
  3983. }
  3984. if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
  3985. | VB_SIS302LV | VB_XGI301C)) {
  3986. xgifb_reg_set(pVBInfo->Part2Port, 0x48, filterPtr[index++]);
  3987. xgifb_reg_set(pVBInfo->Part2Port, 0x49, filterPtr[index++]);
  3988. xgifb_reg_set(pVBInfo->Part2Port, 0x4A, filterPtr[index++]);
  3989. }
  3990. }
  3991. /* --------------------------------------------------------------------- */
  3992. /* Function : XGI_OEM310Setting */
  3993. /* Input : */
  3994. /* Output : */
  3995. /* Description : Customized Param. for 301 */
  3996. /* --------------------------------------------------------------------- */
  3997. static void XGI_OEM310Setting(unsigned short ModeIdIndex,
  3998. struct vb_device_info *pVBInfo)
  3999. {
  4000. XGI_SetDelayComp(pVBInfo);
  4001. if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
  4002. XGI_SetLCDCap(pVBInfo);
  4003. if (pVBInfo->VBInfo & SetCRT2ToTV) {
  4004. XGI_SetPhaseIncr(pVBInfo);
  4005. XGI_SetYFilter(ModeIdIndex, pVBInfo);
  4006. XGI_SetAntiFlicker(pVBInfo);
  4007. if (pVBInfo->VBType & VB_SIS301)
  4008. XGI_SetEdgeEnhance(pVBInfo);
  4009. }
  4010. }
  4011. /* --------------------------------------------------------------------- */
  4012. /* Function : XGI_SetCRT2ModeRegs */
  4013. /* Input : */
  4014. /* Output : */
  4015. /* Description : Origin code for crt2group */
  4016. /* --------------------------------------------------------------------- */
  4017. static void XGI_SetCRT2ModeRegs(struct vb_device_info *pVBInfo)
  4018. {
  4019. unsigned short tempbl;
  4020. short tempcl;
  4021. unsigned char tempah;
  4022. tempah = 0;
  4023. if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
  4024. tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
  4025. tempah &= ~0x10; /* BTRAMDAC */
  4026. tempah |= 0x40; /* BTRAM */
  4027. if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
  4028. | SetCRT2ToLCD)) {
  4029. tempah = 0x40; /* BTDRAM */
  4030. tempcl = pVBInfo->ModeType;
  4031. tempcl -= ModeVGA;
  4032. if (tempcl >= 0) {
  4033. /* BT Color */
  4034. tempah = (0x008 >> tempcl);
  4035. if (tempah == 0)
  4036. tempah = 1;
  4037. tempah |= 0x040;
  4038. }
  4039. if (pVBInfo->VBInfo & SetInSlaveMode)
  4040. tempah ^= 0x50; /* BTDAC */
  4041. }
  4042. }
  4043. xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
  4044. tempah = 0x08;
  4045. tempbl = 0xf0;
  4046. if (pVBInfo->VBInfo & DisableCRT2Display)
  4047. goto reg_and_or;
  4048. tempah = 0x00;
  4049. tempbl = 0xff;
  4050. if (!(pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV |
  4051. SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
  4052. goto reg_and_or;
  4053. if ((pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) &&
  4054. (!(pVBInfo->VBInfo & SetSimuScanMode))) {
  4055. tempbl &= 0xf7;
  4056. tempah |= 0x01;
  4057. goto reg_and_or;
  4058. }
  4059. if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
  4060. tempbl &= 0xf7;
  4061. tempah |= 0x01;
  4062. }
  4063. if (!(pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD)))
  4064. goto reg_and_or;
  4065. tempbl &= 0xf8;
  4066. tempah = 0x01;
  4067. if (!(pVBInfo->VBInfo & SetInSlaveMode))
  4068. tempah |= 0x02;
  4069. if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
  4070. tempah = tempah ^ 0x05;
  4071. if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
  4072. tempah = tempah ^ 0x01;
  4073. }
  4074. if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
  4075. tempah |= 0x08;
  4076. reg_and_or:
  4077. xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl, tempah);
  4078. if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD
  4079. | XGI_SetCRT2ToLCDA)) {
  4080. tempah &= (~0x08);
  4081. if ((pVBInfo->ModeType == ModeVGA) && (!(pVBInfo->VBInfo
  4082. & SetInSlaveMode))) {
  4083. tempah |= 0x010;
  4084. }
  4085. tempah |= 0x080;
  4086. if (pVBInfo->VBInfo & SetCRT2ToTV) {
  4087. tempah |= 0x020;
  4088. if (pVBInfo->VBInfo & DriverMode)
  4089. tempah = tempah ^ 0x20;
  4090. }
  4091. xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D, ~0x0BF, tempah);
  4092. tempah = 0;
  4093. if (pVBInfo->LCDInfo & SetLCDDualLink)
  4094. tempah |= 0x40;
  4095. if (pVBInfo->VBInfo & SetCRT2ToTV) {
  4096. if (pVBInfo->TVInfo & RPLLDIV2XO)
  4097. tempah |= 0x40;
  4098. }
  4099. if ((pVBInfo->LCDResInfo == Panel_1280x1024)
  4100. || (pVBInfo->LCDResInfo == Panel_1280x1024x75))
  4101. tempah |= 0x80;
  4102. if (pVBInfo->LCDResInfo == Panel_1280x960)
  4103. tempah |= 0x80;
  4104. xgifb_reg_set(pVBInfo->Part4Port, 0x0C, tempah);
  4105. }
  4106. if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
  4107. | VB_SIS302LV | VB_XGI301C)) {
  4108. tempah = 0;
  4109. tempbl = 0xfb;
  4110. if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
  4111. tempbl = 0xff;
  4112. if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
  4113. tempah |= 0x04; /* shampoo 0129 */
  4114. }
  4115. xgifb_reg_and_or(pVBInfo->Part1Port, 0x13, tempbl, tempah);
  4116. tempah = 0x00;
  4117. tempbl = 0xcf;
  4118. if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
  4119. if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
  4120. tempah |= 0x30;
  4121. }
  4122. xgifb_reg_and_or(pVBInfo->Part1Port, 0x2c, tempbl, tempah);
  4123. tempah = 0;
  4124. tempbl = 0x3f;
  4125. if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
  4126. if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
  4127. tempah |= 0xc0;
  4128. }
  4129. xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, tempbl, tempah);
  4130. }
  4131. tempah = 0;
  4132. tempbl = 0x7f;
  4133. if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) {
  4134. tempbl = 0xff;
  4135. if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
  4136. tempah |= 0x80;
  4137. }
  4138. xgifb_reg_and_or(pVBInfo->Part4Port, 0x23, tempbl, tempah);
  4139. if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
  4140. if (pVBInfo->LCDInfo & SetLCDDualLink) {
  4141. xgifb_reg_or(pVBInfo->Part4Port, 0x27, 0x20);
  4142. xgifb_reg_or(pVBInfo->Part4Port, 0x34, 0x10);
  4143. }
  4144. }
  4145. }
  4146. void XGI_UnLockCRT2(struct vb_device_info *pVBInfo)
  4147. {
  4148. xgifb_reg_and_or(pVBInfo->Part1Port, 0x2f, 0xFF, 0x01);
  4149. }
  4150. void XGI_LockCRT2(struct vb_device_info *pVBInfo)
  4151. {
  4152. xgifb_reg_and_or(pVBInfo->Part1Port, 0x2F, 0xFE, 0x00);
  4153. }
  4154. unsigned short XGI_GetRatePtrCRT2(struct xgi_hw_device_info *pXGIHWDE,
  4155. unsigned short ModeNo, unsigned short ModeIdIndex,
  4156. struct vb_device_info *pVBInfo)
  4157. {
  4158. const u8 LCDARefreshIndex[] = {
  4159. 0x00, 0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x00 };
  4160. unsigned short RefreshRateTableIndex, i, index, temp;
  4161. index = xgifb_reg_get(pVBInfo->P3d4, 0x33);
  4162. index >>= pVBInfo->SelectCRT2Rate;
  4163. index &= 0x0F;
  4164. if (pVBInfo->LCDInfo & LCDNonExpanding)
  4165. index = 0;
  4166. if (index > 0)
  4167. index--;
  4168. if (pVBInfo->SetFlag & ProgrammingCRT2) {
  4169. if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
  4170. temp = LCDARefreshIndex[pVBInfo->LCDResInfo & 0x07];
  4171. if (index > temp)
  4172. index = temp;
  4173. }
  4174. }
  4175. RefreshRateTableIndex = XGI330_EModeIDTable[ModeIdIndex].REFindex;
  4176. ModeNo = XGI330_RefIndex[RefreshRateTableIndex].ModeID;
  4177. if (pXGIHWDE->jChipType >= XG20) { /* for XG20, XG21, XG27 */
  4178. if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 800) &&
  4179. (XGI330_RefIndex[RefreshRateTableIndex].YRes == 600)) {
  4180. index++;
  4181. }
  4182. /* do the similar adjustment like XGISearchCRT1Rate() */
  4183. if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 1024) &&
  4184. (XGI330_RefIndex[RefreshRateTableIndex].YRes == 768)) {
  4185. index++;
  4186. }
  4187. if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 1280) &&
  4188. (XGI330_RefIndex[RefreshRateTableIndex].YRes == 1024)) {
  4189. index++;
  4190. }
  4191. }
  4192. i = 0;
  4193. do {
  4194. if (XGI330_RefIndex[RefreshRateTableIndex + i].
  4195. ModeID != ModeNo)
  4196. break;
  4197. temp = XGI330_RefIndex[RefreshRateTableIndex + i].Ext_InfoFlag;
  4198. temp &= ModeTypeMask;
  4199. if (temp < pVBInfo->ModeType)
  4200. break;
  4201. i++;
  4202. index--;
  4203. } while (index != 0xFFFF);
  4204. if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
  4205. if (pVBInfo->VBInfo & SetInSlaveMode) {
  4206. temp = XGI330_RefIndex[RefreshRateTableIndex + i - 1].
  4207. Ext_InfoFlag;
  4208. if (temp & InterlaceMode)
  4209. i++;
  4210. }
  4211. }
  4212. i--;
  4213. if ((pVBInfo->SetFlag & ProgrammingCRT2)) {
  4214. temp = XGI_AjustCRT2Rate(ModeIdIndex, RefreshRateTableIndex,
  4215. &i, pVBInfo);
  4216. }
  4217. return RefreshRateTableIndex + i;
  4218. }
  4219. static void XGI_SetLCDAGroup(unsigned short ModeNo, unsigned short ModeIdIndex,
  4220. struct xgi_hw_device_info *HwDeviceExtension,
  4221. struct vb_device_info *pVBInfo)
  4222. {
  4223. unsigned short RefreshRateTableIndex;
  4224. pVBInfo->SetFlag |= ProgrammingCRT2;
  4225. RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
  4226. ModeIdIndex, pVBInfo);
  4227. XGI_GetLVDSResInfo(ModeIdIndex, pVBInfo);
  4228. XGI_GetLVDSData(ModeIdIndex, pVBInfo);
  4229. XGI_ModCRT1Regs(ModeIdIndex, HwDeviceExtension, pVBInfo);
  4230. XGI_SetLVDSRegs(ModeIdIndex, pVBInfo);
  4231. XGI_SetCRT2ECLK(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
  4232. }
  4233. static unsigned char XGI_SetCRT2Group301(unsigned short ModeNo,
  4234. struct xgi_hw_device_info *HwDeviceExtension,
  4235. struct vb_device_info *pVBInfo)
  4236. {
  4237. unsigned short ModeIdIndex, RefreshRateTableIndex;
  4238. pVBInfo->SetFlag |= ProgrammingCRT2;
  4239. XGI_SearchModeID(ModeNo, &ModeIdIndex);
  4240. pVBInfo->SelectCRT2Rate = 4;
  4241. RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
  4242. ModeIdIndex, pVBInfo);
  4243. XGI_SaveCRT2Info(ModeNo, pVBInfo);
  4244. XGI_GetCRT2ResInfo(ModeIdIndex, pVBInfo);
  4245. XGI_GetCRT2Data(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
  4246. XGI_PreSetGroup1(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
  4247. XGI_SetGroup1(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
  4248. XGI_SetLockRegs(ModeNo, ModeIdIndex, pVBInfo);
  4249. XGI_SetGroup2(ModeNo, ModeIdIndex, pVBInfo);
  4250. XGI_SetLCDRegs(ModeIdIndex, pVBInfo);
  4251. XGI_SetTap4Regs(pVBInfo);
  4252. XGI_SetGroup3(ModeIdIndex, pVBInfo);
  4253. XGI_SetGroup4(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
  4254. XGI_SetCRT2VCLK(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
  4255. XGI_SetGroup5(pVBInfo);
  4256. XGI_AutoThreshold(pVBInfo);
  4257. return 1;
  4258. }
  4259. void XGI_SenseCRT1(struct vb_device_info *pVBInfo)
  4260. {
  4261. unsigned char CRTCData[17] = { 0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81,
  4262. 0x0B, 0x3E, 0xE9, 0x0B, 0xDF, 0xE7, 0x04, 0x00, 0x00,
  4263. 0x05, 0x00 };
  4264. unsigned char SR01 = 0, SR1F = 0, SR07 = 0, SR06 = 0;
  4265. unsigned char CR17, CR63, SR31;
  4266. unsigned short temp;
  4267. int i;
  4268. xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
  4269. /* to fix XG42 single LCD sense to CRT+LCD */
  4270. xgifb_reg_set(pVBInfo->P3d4, 0x57, 0x4A);
  4271. xgifb_reg_set(pVBInfo->P3d4, 0x53, (xgifb_reg_get(
  4272. pVBInfo->P3d4, 0x53) | 0x02));
  4273. SR31 = xgifb_reg_get(pVBInfo->P3c4, 0x31);
  4274. CR63 = xgifb_reg_get(pVBInfo->P3d4, 0x63);
  4275. SR01 = xgifb_reg_get(pVBInfo->P3c4, 0x01);
  4276. xgifb_reg_set(pVBInfo->P3c4, 0x01, (unsigned char) (SR01 & 0xDF));
  4277. xgifb_reg_set(pVBInfo->P3d4, 0x63, (unsigned char) (CR63 & 0xBF));
  4278. CR17 = xgifb_reg_get(pVBInfo->P3d4, 0x17);
  4279. xgifb_reg_set(pVBInfo->P3d4, 0x17, (unsigned char) (CR17 | 0x80));
  4280. SR1F = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
  4281. xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) (SR1F | 0x04));
  4282. SR07 = xgifb_reg_get(pVBInfo->P3c4, 0x07);
  4283. xgifb_reg_set(pVBInfo->P3c4, 0x07, (unsigned char) (SR07 & 0xFB));
  4284. SR06 = xgifb_reg_get(pVBInfo->P3c4, 0x06);
  4285. xgifb_reg_set(pVBInfo->P3c4, 0x06, (unsigned char) (SR06 & 0xC3));
  4286. xgifb_reg_set(pVBInfo->P3d4, 0x11, 0x00);
  4287. for (i = 0; i < 8; i++)
  4288. xgifb_reg_set(pVBInfo->P3d4, (unsigned short) i, CRTCData[i]);
  4289. for (i = 8; i < 11; i++)
  4290. xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 8),
  4291. CRTCData[i]);
  4292. for (i = 11; i < 13; i++)
  4293. xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 4),
  4294. CRTCData[i]);
  4295. for (i = 13; i < 16; i++)
  4296. xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i - 3),
  4297. CRTCData[i]);
  4298. xgifb_reg_set(pVBInfo->P3c4, 0x0E, (unsigned char) (CRTCData[16]
  4299. & 0xE0));
  4300. xgifb_reg_set(pVBInfo->P3c4, 0x31, 0x00);
  4301. xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x1B);
  4302. xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE1);
  4303. outb(0x00, pVBInfo->P3c8);
  4304. for (i = 0; i < 256 * 3; i++)
  4305. outb(0x0F, (pVBInfo->P3c8 + 1)); /* DAC_TEST_PARMS */
  4306. mdelay(1);
  4307. XGI_WaitDisply(pVBInfo);
  4308. temp = inb(pVBInfo->P3c2);
  4309. if (temp & 0x10)
  4310. xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x20);
  4311. else
  4312. xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x00);
  4313. /* avoid display something, set BLACK DAC if not restore DAC */
  4314. outb(0x00, pVBInfo->P3c8);
  4315. for (i = 0; i < 256 * 3; i++)
  4316. outb(0, (pVBInfo->P3c8 + 1));
  4317. xgifb_reg_set(pVBInfo->P3c4, 0x01, SR01);
  4318. xgifb_reg_set(pVBInfo->P3d4, 0x63, CR63);
  4319. xgifb_reg_set(pVBInfo->P3c4, 0x31, SR31);
  4320. xgifb_reg_set(pVBInfo->P3d4, 0x53, (xgifb_reg_get(
  4321. pVBInfo->P3d4, 0x53) & 0xFD));
  4322. xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) SR1F);
  4323. }
  4324. static void XGI_EnableBridge(struct xgifb_video_info *xgifb_info,
  4325. struct xgi_hw_device_info *HwDeviceExtension,
  4326. struct vb_device_info *pVBInfo)
  4327. {
  4328. unsigned short tempah;
  4329. if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
  4330. | VB_SIS302LV | VB_XGI301C)) {
  4331. if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
  4332. /* Power on */
  4333. xgifb_reg_set(pVBInfo->Part1Port, 0x1E, 0x20);
  4334. if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV |
  4335. SetCRT2ToRAMDAC)) {
  4336. tempah = xgifb_reg_get(pVBInfo->P3c4, 0x32);
  4337. tempah &= 0xDF;
  4338. if (pVBInfo->VBInfo & SetInSlaveMode) {
  4339. if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC))
  4340. tempah |= 0x20;
  4341. }
  4342. xgifb_reg_set(pVBInfo->P3c4, 0x32, tempah);
  4343. xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x20);
  4344. tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2E);
  4345. if (!(tempah & 0x80))
  4346. xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80);
  4347. xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
  4348. }
  4349. if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
  4350. xgifb_reg_and_or(pVBInfo->Part2Port, 0x00, ~0xE0,
  4351. 0x20); /* shampoo 0129 */
  4352. if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
  4353. if (pVBInfo->VBInfo &
  4354. (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
  4355. /* LVDS PLL power on */
  4356. xgifb_reg_and(pVBInfo->Part4Port, 0x2A,
  4357. 0x7F);
  4358. /* LVDS Driver power on */
  4359. xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x7F);
  4360. }
  4361. }
  4362. tempah = 0x00;
  4363. if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
  4364. tempah = 0xc0;
  4365. if (!(pVBInfo->VBInfo & SetSimuScanMode) &&
  4366. (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) &&
  4367. (pVBInfo->VBInfo & SetCRT2ToDualEdge)) {
  4368. tempah = tempah & 0x40;
  4369. if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
  4370. tempah = tempah ^ 0xC0;
  4371. }
  4372. }
  4373. /* EnablePart4_1F */
  4374. xgifb_reg_or(pVBInfo->Part4Port, 0x1F, tempah);
  4375. XGI_DisableGatingCRT(pVBInfo);
  4376. XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
  4377. } /* 301 */
  4378. else { /* LVDS */
  4379. if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD
  4380. | XGI_SetCRT2ToLCDA))
  4381. /* enable CRT2 */
  4382. xgifb_reg_or(pVBInfo->Part1Port, 0x1E, 0x20);
  4383. tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2E);
  4384. if (!(tempah & 0x80))
  4385. xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80);
  4386. xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
  4387. XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
  4388. } /* End of VB */
  4389. }
  4390. static void XGI_SetCRT1Group(struct xgifb_video_info *xgifb_info,
  4391. struct xgi_hw_device_info *HwDeviceExtension,
  4392. unsigned short ModeNo, unsigned short ModeIdIndex,
  4393. struct vb_device_info *pVBInfo)
  4394. {
  4395. unsigned short RefreshRateTableIndex, temp;
  4396. XGI_SetSeqRegs(pVBInfo);
  4397. outb(XGI330_StandTable.MISC, pVBInfo->P3c2);
  4398. XGI_SetCRTCRegs(pVBInfo);
  4399. XGI_SetATTRegs(ModeIdIndex, pVBInfo);
  4400. XGI_SetGRCRegs(pVBInfo);
  4401. XGI_ClearExt1Regs(pVBInfo);
  4402. if (HwDeviceExtension->jChipType == XG27) {
  4403. if (pVBInfo->IF_DEF_LVDS == 0)
  4404. XGI_SetDefaultVCLK(pVBInfo);
  4405. }
  4406. temp = ~ProgrammingCRT2;
  4407. pVBInfo->SetFlag &= temp;
  4408. pVBInfo->SelectCRT2Rate = 0;
  4409. if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
  4410. | VB_SIS302LV | VB_XGI301C)) {
  4411. if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA
  4412. | SetInSlaveMode)) {
  4413. pVBInfo->SetFlag |= ProgrammingCRT2;
  4414. }
  4415. }
  4416. RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
  4417. ModeIdIndex, pVBInfo);
  4418. if (RefreshRateTableIndex != 0xFFFF) {
  4419. XGI_SetSync(RefreshRateTableIndex, pVBInfo);
  4420. XGI_SetCRT1CRTC(ModeIdIndex, RefreshRateTableIndex,
  4421. pVBInfo, HwDeviceExtension);
  4422. XGI_SetCRT1DE(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
  4423. XGI_SetCRT1Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
  4424. HwDeviceExtension, pVBInfo);
  4425. XGI_SetCRT1VCLK(ModeIdIndex, HwDeviceExtension,
  4426. RefreshRateTableIndex, pVBInfo);
  4427. }
  4428. if (HwDeviceExtension->jChipType >= XG21) {
  4429. temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
  4430. if (temp & 0xA0) {
  4431. if (HwDeviceExtension->jChipType == XG27)
  4432. XGI_SetXG27CRTC(RefreshRateTableIndex, pVBInfo);
  4433. else
  4434. XGI_SetXG21CRTC(RefreshRateTableIndex, pVBInfo);
  4435. XGI_UpdateXG21CRTC(ModeNo, pVBInfo,
  4436. RefreshRateTableIndex);
  4437. xgifb_set_lcd(HwDeviceExtension->jChipType,
  4438. pVBInfo, RefreshRateTableIndex);
  4439. if (pVBInfo->IF_DEF_LVDS == 1)
  4440. xgifb_set_lvds(xgifb_info,
  4441. HwDeviceExtension->jChipType,
  4442. ModeIdIndex, pVBInfo);
  4443. }
  4444. }
  4445. pVBInfo->SetFlag &= (~ProgrammingCRT2);
  4446. XGI_SetCRT1FIFO(HwDeviceExtension, pVBInfo);
  4447. XGI_SetCRT1ModeRegs(HwDeviceExtension, ModeIdIndex,
  4448. RefreshRateTableIndex, pVBInfo);
  4449. XGI_LoadDAC(pVBInfo);
  4450. }
  4451. unsigned char XGISetModeNew(struct xgifb_video_info *xgifb_info,
  4452. struct xgi_hw_device_info *HwDeviceExtension,
  4453. unsigned short ModeNo)
  4454. {
  4455. unsigned short ModeIdIndex;
  4456. struct vb_device_info VBINF;
  4457. struct vb_device_info *pVBInfo = &VBINF;
  4458. pVBInfo->IF_DEF_LVDS = 0;
  4459. if (HwDeviceExtension->jChipType >= XG20)
  4460. pVBInfo->VBType = 0; /*set VBType default 0*/
  4461. XGIRegInit(pVBInfo, xgifb_info->vga_base);
  4462. /* for x86 Linux, XG21 LVDS */
  4463. if (HwDeviceExtension->jChipType == XG21) {
  4464. if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0)
  4465. pVBInfo->IF_DEF_LVDS = 1;
  4466. }
  4467. if (HwDeviceExtension->jChipType == XG27) {
  4468. if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0) {
  4469. if (xgifb_reg_get(pVBInfo->P3d4, 0x30) & 0x20)
  4470. pVBInfo->IF_DEF_LVDS = 1;
  4471. }
  4472. }
  4473. InitTo330Pointer(HwDeviceExtension->jChipType, pVBInfo);
  4474. if (ModeNo & 0x80)
  4475. ModeNo = ModeNo & 0x7F;
  4476. xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
  4477. if (HwDeviceExtension->jChipType < XG20)
  4478. XGI_UnLockCRT2(pVBInfo);
  4479. XGI_SearchModeID(ModeNo, &ModeIdIndex);
  4480. if (HwDeviceExtension->jChipType < XG20) {
  4481. XGI_GetVBInfo(ModeIdIndex, pVBInfo);
  4482. XGI_GetTVInfo(ModeIdIndex, pVBInfo);
  4483. XGI_GetLCDInfo(ModeIdIndex, pVBInfo);
  4484. XGI_DisableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
  4485. if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA) ||
  4486. (!(pVBInfo->VBInfo & SwitchCRT2))) {
  4487. XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
  4488. ModeIdIndex, pVBInfo);
  4489. if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
  4490. XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
  4491. HwDeviceExtension, pVBInfo);
  4492. }
  4493. }
  4494. if (pVBInfo->VBInfo & (SetSimuScanMode | SwitchCRT2)) {
  4495. switch (HwDeviceExtension->ujVBChipID) {
  4496. case VB_CHIP_301: /* fall through */
  4497. case VB_CHIP_302:
  4498. XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
  4499. pVBInfo); /*add for CRT2 */
  4500. break;
  4501. default:
  4502. break;
  4503. }
  4504. }
  4505. XGI_SetCRT2ModeRegs(pVBInfo);
  4506. XGI_OEM310Setting(ModeIdIndex, pVBInfo); /*0212*/
  4507. XGI_EnableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
  4508. } /* !XG20 */
  4509. else {
  4510. if (pVBInfo->IF_DEF_LVDS == 1)
  4511. if (!XGI_XG21CheckLVDSMode(xgifb_info, ModeNo,
  4512. ModeIdIndex))
  4513. return 0;
  4514. pVBInfo->ModeType = XGI330_EModeIDTable[ModeIdIndex].
  4515. Ext_ModeFlag & ModeTypeMask;
  4516. pVBInfo->SetFlag = 0;
  4517. pVBInfo->VBInfo = DisableCRT2Display;
  4518. XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
  4519. XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
  4520. ModeIdIndex, pVBInfo);
  4521. XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
  4522. }
  4523. XGI_UpdateModeInfo(pVBInfo);
  4524. if (HwDeviceExtension->jChipType < XG20)
  4525. XGI_LockCRT2(pVBInfo);
  4526. return 1;
  4527. }