init301.c 338 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263
  1. /* $XFree86$ */
  2. /* $XdotOrg$ */
  3. /*
  4. * Mode initializing code (CRT2 section)
  5. * for SiS 300/305/540/630/730,
  6. * SiS 315/550/[M]650/651/[M]661[FGM]X/[M]74x[GX]/330/[M]76x[GX],
  7. * XGI V3XT/V5/V8, Z7
  8. * (Universal module for Linux kernel framebuffer and X.org/XFree86 4.x)
  9. *
  10. * Copyright (C) 2001-2005 by Thomas Winischhofer, Vienna, Austria
  11. *
  12. * If distributed as part of the Linux kernel, the following license terms
  13. * apply:
  14. *
  15. * * This program is free software; you can redistribute it and/or modify
  16. * * it under the terms of the GNU General Public License as published by
  17. * * the Free Software Foundation; either version 2 of the named License,
  18. * * or any later version.
  19. * *
  20. * * This program is distributed in the hope that it will be useful,
  21. * * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * * GNU General Public License for more details.
  24. * *
  25. * * You should have received a copy of the GNU General Public License
  26. * * along with this program; if not, write to the Free Software
  27. * * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
  28. *
  29. * Otherwise, the following license terms apply:
  30. *
  31. * * Redistribution and use in source and binary forms, with or without
  32. * * modification, are permitted provided that the following conditions
  33. * * are met:
  34. * * 1) Redistributions of source code must retain the above copyright
  35. * * notice, this list of conditions and the following disclaimer.
  36. * * 2) Redistributions in binary form must reproduce the above copyright
  37. * * notice, this list of conditions and the following disclaimer in the
  38. * * documentation and/or other materials provided with the distribution.
  39. * * 3) The name of the author may not be used to endorse or promote products
  40. * * derived from this software without specific prior written permission.
  41. * *
  42. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  43. * * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  44. * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  45. * * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  46. * * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  47. * * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  48. * * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  49. * * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  50. * * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  51. * * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  52. *
  53. * Author: Thomas Winischhofer <thomas@winischhofer.net>
  54. *
  55. * Formerly based on non-functional code-fragements for 300 series by SiS, Inc.
  56. * Used by permission.
  57. *
  58. */
  59. #ifdef HAVE_CONFIG_H
  60. #include "config.h"
  61. #endif
  62. #if 1
  63. #define SET_EMI /* 302LV/ELV: Set EMI values */
  64. #endif
  65. #if 1
  66. #define SET_PWD /* 301/302LV: Set PWD */
  67. #endif
  68. #define COMPAL_HACK /* Needed for Compal 1400x1050 (EMI) */
  69. #define COMPAQ_HACK /* Needed for Inventec/Compaq 1280x1024 (EMI) */
  70. #define ASUS_HACK /* Needed for Asus A2H 1024x768 (EMI) */
  71. #include "init301.h"
  72. #ifdef SIS300
  73. #include "oem300.h"
  74. #endif
  75. #ifdef SIS315H
  76. #include "oem310.h"
  77. #endif
  78. #define SiS_I2CDELAY 1000
  79. #define SiS_I2CDELAYSHORT 150
  80. static unsigned short SiS_GetBIOSLCDResInfo(struct SiS_Private *SiS_Pr);
  81. #ifdef SIS_LINUX_KERNEL
  82. static void SiS_SetCH70xx(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val);
  83. #endif
  84. /*********************************************/
  85. /* HELPER: Lock/Unlock CRT2 */
  86. /*********************************************/
  87. void
  88. SiS_UnLockCRT2(struct SiS_Private *SiS_Pr)
  89. {
  90. if(SiS_Pr->ChipType == XGI_20)
  91. return;
  92. else if(SiS_Pr->ChipType >= SIS_315H)
  93. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2f,0x01);
  94. else
  95. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x24,0x01);
  96. }
  97. #ifdef SIS_LINUX_KERNEL
  98. static
  99. #endif
  100. void
  101. SiS_LockCRT2(struct SiS_Private *SiS_Pr)
  102. {
  103. if(SiS_Pr->ChipType == XGI_20)
  104. return;
  105. else if(SiS_Pr->ChipType >= SIS_315H)
  106. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2F,0xFE);
  107. else
  108. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x24,0xFE);
  109. }
  110. /*********************************************/
  111. /* HELPER: Write SR11 */
  112. /*********************************************/
  113. static void
  114. SiS_SetRegSR11ANDOR(struct SiS_Private *SiS_Pr, unsigned short DataAND, unsigned short DataOR)
  115. {
  116. if(SiS_Pr->ChipType >= SIS_661) {
  117. DataAND &= 0x0f;
  118. DataOR &= 0x0f;
  119. }
  120. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x11,DataAND,DataOR);
  121. }
  122. /*********************************************/
  123. /* HELPER: Get Pointer to LCD structure */
  124. /*********************************************/
  125. #ifdef SIS315H
  126. static unsigned char *
  127. GetLCDStructPtr661(struct SiS_Private *SiS_Pr)
  128. {
  129. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  130. unsigned char *myptr = NULL;
  131. unsigned short romindex = 0, reg = 0, idx = 0;
  132. /* Use the BIOS tables only for LVDS panels; TMDS is unreliable
  133. * due to the variaty of panels the BIOS doesn't know about.
  134. * Exception: If the BIOS has better knowledge (such as in case
  135. * of machines with a 301C and a panel that does not support DDC)
  136. * use the BIOS data as well.
  137. */
  138. if((SiS_Pr->SiS_ROMNew) &&
  139. ((SiS_Pr->SiS_VBType & VB_SISLVDS) || (!SiS_Pr->PanelSelfDetected))) {
  140. if(SiS_Pr->ChipType < SIS_661) reg = 0x3c;
  141. else reg = 0x7d;
  142. idx = (SiS_GetReg(SiS_Pr->SiS_P3d4,reg) & 0x1f) * 26;
  143. if(idx < (8*26)) {
  144. myptr = (unsigned char *)&SiS_LCDStruct661[idx];
  145. }
  146. romindex = SISGETROMW(0x100);
  147. if(romindex) {
  148. romindex += idx;
  149. myptr = &ROMAddr[romindex];
  150. }
  151. }
  152. return myptr;
  153. }
  154. static unsigned short
  155. GetLCDStructPtr661_2(struct SiS_Private *SiS_Pr)
  156. {
  157. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  158. unsigned short romptr = 0;
  159. /* Use the BIOS tables only for LVDS panels; TMDS is unreliable
  160. * due to the variaty of panels the BIOS doesn't know about.
  161. * Exception: If the BIOS has better knowledge (such as in case
  162. * of machines with a 301C and a panel that does not support DDC)
  163. * use the BIOS data as well.
  164. */
  165. if((SiS_Pr->SiS_ROMNew) &&
  166. ((SiS_Pr->SiS_VBType & VB_SISLVDS) || (!SiS_Pr->PanelSelfDetected))) {
  167. romptr = SISGETROMW(0x102);
  168. romptr += ((SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4) * SiS_Pr->SiS661LCD2TableSize);
  169. }
  170. return romptr;
  171. }
  172. #endif
  173. /*********************************************/
  174. /* Adjust Rate for CRT2 */
  175. /*********************************************/
  176. static BOOLEAN
  177. SiS_AdjustCRT2Rate(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  178. unsigned short RRTI, unsigned short *i)
  179. {
  180. unsigned short checkmask=0, modeid, infoflag;
  181. modeid = SiS_Pr->SiS_RefIndex[RRTI + (*i)].ModeID;
  182. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  183. if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) {
  184. checkmask |= SupportRAMDAC2;
  185. if(SiS_Pr->ChipType >= SIS_315H) {
  186. checkmask |= SupportRAMDAC2_135;
  187. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  188. checkmask |= SupportRAMDAC2_162;
  189. if(SiS_Pr->SiS_VBType & VB_SISRAMDAC202) {
  190. checkmask |= SupportRAMDAC2_202;
  191. }
  192. }
  193. }
  194. } else if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  195. checkmask |= SupportLCD;
  196. if(SiS_Pr->ChipType >= SIS_315H) {
  197. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  198. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  199. if(modeid == 0x2e) checkmask |= Support64048060Hz;
  200. }
  201. }
  202. }
  203. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  204. checkmask |= SupportHiVision;
  205. } else if(SiS_Pr->SiS_VBInfo & (SetCRT2ToYPbPr525750|SetCRT2ToAVIDEO|SetCRT2ToSVIDEO|SetCRT2ToSCART)) {
  206. checkmask |= SupportTV;
  207. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  208. checkmask |= SupportTV1024;
  209. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  210. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) {
  211. checkmask |= SupportYPbPr750p;
  212. }
  213. }
  214. }
  215. }
  216. } else { /* LVDS */
  217. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  218. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  219. checkmask |= SupportCHTV;
  220. }
  221. }
  222. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  223. checkmask |= SupportLCD;
  224. }
  225. }
  226. /* Look backwards in table for matching CRT2 mode */
  227. for(; SiS_Pr->SiS_RefIndex[RRTI + (*i)].ModeID == modeid; (*i)--) {
  228. infoflag = SiS_Pr->SiS_RefIndex[RRTI + (*i)].Ext_InfoFlag;
  229. if(infoflag & checkmask) return TRUE;
  230. if((*i) == 0) break;
  231. }
  232. /* Look through the whole mode-section of the table from the beginning
  233. * for a matching CRT2 mode if no mode was found yet.
  234. */
  235. for((*i) = 0; ; (*i)++) {
  236. if(SiS_Pr->SiS_RefIndex[RRTI + (*i)].ModeID != modeid) break;
  237. infoflag = SiS_Pr->SiS_RefIndex[RRTI + (*i)].Ext_InfoFlag;
  238. if(infoflag & checkmask) return TRUE;
  239. }
  240. return FALSE;
  241. }
  242. /*********************************************/
  243. /* Get rate index */
  244. /*********************************************/
  245. unsigned short
  246. SiS_GetRatePtr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  247. {
  248. unsigned short RRTI,i,backup_i;
  249. unsigned short modeflag,index,temp,backupindex;
  250. static const unsigned short LCDRefreshIndex[] = {
  251. 0x00, 0x00, 0x01, 0x01,
  252. 0x01, 0x01, 0x01, 0x01,
  253. 0x01, 0x01, 0x01, 0x01,
  254. 0x01, 0x01, 0x01, 0x01,
  255. 0x00, 0x00, 0x00, 0x00
  256. };
  257. /* Do NOT check for UseCustomMode here, will skrew up FIFO */
  258. if(ModeNo == 0xfe) return 0;
  259. if(ModeNo <= 0x13) {
  260. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  261. } else {
  262. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  263. }
  264. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  265. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  266. if(modeflag & HalfDCLK) return 0;
  267. }
  268. }
  269. if(ModeNo < 0x14) return 0xFFFF;
  270. index = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x33) >> SiS_Pr->SiS_SelectCRT2Rate) & 0x0F;
  271. backupindex = index;
  272. if(index > 0) index--;
  273. if(SiS_Pr->SiS_SetFlag & ProgrammingCRT2) {
  274. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  275. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  276. if(SiS_Pr->SiS_VBType & VB_NoLCD) index = 0;
  277. else if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) index = backupindex = 0;
  278. }
  279. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  280. if(!(SiS_Pr->SiS_VBType & VB_NoLCD)) {
  281. temp = LCDRefreshIndex[SiS_GetBIOSLCDResInfo(SiS_Pr)];
  282. if(index > temp) index = temp;
  283. }
  284. }
  285. } else {
  286. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) index = 0;
  287. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  288. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) index = 0;
  289. }
  290. }
  291. }
  292. RRTI = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].REFindex;
  293. ModeNo = SiS_Pr->SiS_RefIndex[RRTI].ModeID;
  294. if(SiS_Pr->ChipType >= SIS_315H) {
  295. if(!(SiS_Pr->SiS_VBInfo & DriverMode)) {
  296. if( (SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_VESAID == 0x105) ||
  297. (SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_VESAID == 0x107) ) {
  298. if(backupindex <= 1) RRTI++;
  299. }
  300. }
  301. }
  302. i = 0;
  303. do {
  304. if(SiS_Pr->SiS_RefIndex[RRTI + i].ModeID != ModeNo) break;
  305. temp = SiS_Pr->SiS_RefIndex[RRTI + i].Ext_InfoFlag;
  306. temp &= ModeTypeMask;
  307. if(temp < SiS_Pr->SiS_ModeType) break;
  308. i++;
  309. index--;
  310. } while(index != 0xFFFF);
  311. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) {
  312. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  313. temp = SiS_Pr->SiS_RefIndex[RRTI + i - 1].Ext_InfoFlag;
  314. if(temp & InterlaceMode) i++;
  315. }
  316. }
  317. i--;
  318. if((SiS_Pr->SiS_SetFlag & ProgrammingCRT2) && (!(SiS_Pr->SiS_VBInfo & DisableCRT2Display))) {
  319. backup_i = i;
  320. if(!(SiS_AdjustCRT2Rate(SiS_Pr, ModeNo, ModeIdIndex, RRTI, &i))) {
  321. i = backup_i;
  322. }
  323. }
  324. return (RRTI + i);
  325. }
  326. /*********************************************/
  327. /* STORE CRT2 INFO in CR34 */
  328. /*********************************************/
  329. static void
  330. SiS_SaveCRT2Info(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
  331. {
  332. unsigned short temp1, temp2;
  333. /* Store CRT1 ModeNo in CR34 */
  334. SiS_SetReg(SiS_Pr->SiS_P3d4,0x34,ModeNo);
  335. temp1 = (SiS_Pr->SiS_VBInfo & SetInSlaveMode) >> 8;
  336. temp2 = ~(SetInSlaveMode >> 8);
  337. SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x31,temp2,temp1);
  338. }
  339. /*********************************************/
  340. /* HELPER: GET SOME DATA FROM BIOS ROM */
  341. /*********************************************/
  342. #ifdef SIS300
  343. static BOOLEAN
  344. SiS_CR36BIOSWord23b(struct SiS_Private *SiS_Pr)
  345. {
  346. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  347. unsigned short temp,temp1;
  348. if(SiS_Pr->SiS_UseROM) {
  349. if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) {
  350. temp = 1 << ((SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4) & 0x0f);
  351. temp1 = SISGETROMW(0x23b);
  352. if(temp1 & temp) return TRUE;
  353. }
  354. }
  355. return FALSE;
  356. }
  357. static BOOLEAN
  358. SiS_CR36BIOSWord23d(struct SiS_Private *SiS_Pr)
  359. {
  360. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  361. unsigned short temp,temp1;
  362. if(SiS_Pr->SiS_UseROM) {
  363. if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) {
  364. temp = 1 << ((SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4) & 0x0f);
  365. temp1 = SISGETROMW(0x23d);
  366. if(temp1 & temp) return TRUE;
  367. }
  368. }
  369. return FALSE;
  370. }
  371. #endif
  372. /*********************************************/
  373. /* HELPER: DELAY FUNCTIONS */
  374. /*********************************************/
  375. void
  376. SiS_DDC2Delay(struct SiS_Private *SiS_Pr, unsigned int delaytime)
  377. {
  378. unsigned int i, j;
  379. for(i = 0; i < delaytime; i++) {
  380. j += SiS_GetReg(SiS_Pr->SiS_P3c4,0x05);
  381. }
  382. }
  383. #if defined(SIS300) || defined(SIS315H)
  384. static void
  385. SiS_GenericDelay(struct SiS_Private *SiS_Pr, unsigned short delay)
  386. {
  387. SiS_DDC2Delay(SiS_Pr, delay * 36);
  388. }
  389. #endif
  390. #ifdef SIS315H
  391. static void
  392. SiS_LongDelay(struct SiS_Private *SiS_Pr, unsigned short delay)
  393. {
  394. while(delay--) {
  395. SiS_GenericDelay(SiS_Pr, 6623);
  396. }
  397. }
  398. #endif
  399. #if defined(SIS300) || defined(SIS315H)
  400. static void
  401. SiS_ShortDelay(struct SiS_Private *SiS_Pr, unsigned short delay)
  402. {
  403. while(delay--) {
  404. SiS_GenericDelay(SiS_Pr, 66);
  405. }
  406. }
  407. #endif
  408. static void
  409. SiS_PanelDelay(struct SiS_Private *SiS_Pr, unsigned short DelayTime)
  410. {
  411. #if defined(SIS300) || defined(SIS315H)
  412. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  413. unsigned short PanelID, DelayIndex, Delay=0;
  414. #endif
  415. if(SiS_Pr->ChipType < SIS_315H) {
  416. #ifdef SIS300
  417. PanelID = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36);
  418. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  419. if(SiS_Pr->SiS_VBType & VB_SIS301) PanelID &= 0xf7;
  420. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x18) & 0x10)) PanelID = 0x12;
  421. }
  422. DelayIndex = PanelID >> 4;
  423. if((DelayTime >= 2) && ((PanelID & 0x0f) == 1)) {
  424. Delay = 3;
  425. } else {
  426. if(DelayTime >= 2) DelayTime -= 2;
  427. if(!(DelayTime & 0x01)) {
  428. Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[0];
  429. } else {
  430. Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[1];
  431. }
  432. if(SiS_Pr->SiS_UseROM) {
  433. if(ROMAddr[0x220] & 0x40) {
  434. if(!(DelayTime & 0x01)) Delay = (unsigned short)ROMAddr[0x225];
  435. else Delay = (unsigned short)ROMAddr[0x226];
  436. }
  437. }
  438. }
  439. SiS_ShortDelay(SiS_Pr, Delay);
  440. #endif /* SIS300 */
  441. } else {
  442. #ifdef SIS315H
  443. if((SiS_Pr->ChipType >= SIS_661) ||
  444. (SiS_Pr->ChipType <= SIS_315PRO) ||
  445. (SiS_Pr->ChipType == SIS_330) ||
  446. (SiS_Pr->SiS_ROMNew)) {
  447. if(!(DelayTime & 0x01)) {
  448. SiS_DDC2Delay(SiS_Pr, 0x1000);
  449. } else {
  450. SiS_DDC2Delay(SiS_Pr, 0x4000);
  451. }
  452. } else if((SiS_Pr->SiS_IF_DEF_LVDS == 1) /* ||
  453. (SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) ||
  454. (SiS_Pr->SiS_CustomT == CUT_CLEVO1400) */ ) { /* 315 series, LVDS; Special */
  455. if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
  456. PanelID = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36);
  457. if(SiS_Pr->SiS_CustomT == CUT_CLEVO1400) {
  458. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x1b) & 0x10)) PanelID = 0x12;
  459. }
  460. if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) {
  461. DelayIndex = PanelID & 0x0f;
  462. } else {
  463. DelayIndex = PanelID >> 4;
  464. }
  465. if((DelayTime >= 2) && ((PanelID & 0x0f) == 1)) {
  466. Delay = 3;
  467. } else {
  468. if(DelayTime >= 2) DelayTime -= 2;
  469. if(!(DelayTime & 0x01)) {
  470. Delay = SiS_Pr->SiS_PanelDelayTblLVDS[DelayIndex].timer[0];
  471. } else {
  472. Delay = SiS_Pr->SiS_PanelDelayTblLVDS[DelayIndex].timer[1];
  473. }
  474. if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
  475. if(ROMAddr[0x13c] & 0x40) {
  476. if(!(DelayTime & 0x01)) {
  477. Delay = (unsigned short)ROMAddr[0x17e];
  478. } else {
  479. Delay = (unsigned short)ROMAddr[0x17f];
  480. }
  481. }
  482. }
  483. }
  484. SiS_ShortDelay(SiS_Pr, Delay);
  485. }
  486. } else if(SiS_Pr->SiS_VBType & VB_SISVB) { /* 315 series, all bridges */
  487. DelayIndex = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4;
  488. if(!(DelayTime & 0x01)) {
  489. Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[0];
  490. } else {
  491. Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[1];
  492. }
  493. Delay <<= 8;
  494. SiS_DDC2Delay(SiS_Pr, Delay);
  495. }
  496. #endif /* SIS315H */
  497. }
  498. }
  499. #ifdef SIS315H
  500. static void
  501. SiS_PanelDelayLoop(struct SiS_Private *SiS_Pr, unsigned short DelayTime, unsigned short DelayLoop)
  502. {
  503. int i;
  504. for(i = 0; i < DelayLoop; i++) {
  505. SiS_PanelDelay(SiS_Pr, DelayTime);
  506. }
  507. }
  508. #endif
  509. /*********************************************/
  510. /* HELPER: WAIT-FOR-RETRACE FUNCTIONS */
  511. /*********************************************/
  512. void
  513. SiS_WaitRetrace1(struct SiS_Private *SiS_Pr)
  514. {
  515. unsigned short watchdog;
  516. if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x1f) & 0xc0) return;
  517. if(!(SiS_GetReg(SiS_Pr->SiS_P3d4,0x17) & 0x80)) return;
  518. watchdog = 65535;
  519. while((SiS_GetRegByte(SiS_Pr->SiS_P3da) & 0x08) && --watchdog);
  520. watchdog = 65535;
  521. while((!(SiS_GetRegByte(SiS_Pr->SiS_P3da) & 0x08)) && --watchdog);
  522. }
  523. #if defined(SIS300) || defined(SIS315H)
  524. static void
  525. SiS_WaitRetrace2(struct SiS_Private *SiS_Pr, unsigned short reg)
  526. {
  527. unsigned short watchdog;
  528. watchdog = 65535;
  529. while((SiS_GetReg(SiS_Pr->SiS_Part1Port,reg) & 0x02) && --watchdog);
  530. watchdog = 65535;
  531. while((!(SiS_GetReg(SiS_Pr->SiS_Part1Port,reg) & 0x02)) && --watchdog);
  532. }
  533. #endif
  534. static void
  535. SiS_WaitVBRetrace(struct SiS_Private *SiS_Pr)
  536. {
  537. if(SiS_Pr->ChipType < SIS_315H) {
  538. #ifdef SIS300
  539. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  540. if(!(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x20)) return;
  541. }
  542. if(!(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x80)) {
  543. SiS_WaitRetrace1(SiS_Pr);
  544. } else {
  545. SiS_WaitRetrace2(SiS_Pr, 0x25);
  546. }
  547. #endif
  548. } else {
  549. #ifdef SIS315H
  550. if(!(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x40)) {
  551. SiS_WaitRetrace1(SiS_Pr);
  552. } else {
  553. SiS_WaitRetrace2(SiS_Pr, 0x30);
  554. }
  555. #endif
  556. }
  557. }
  558. static void
  559. SiS_VBWait(struct SiS_Private *SiS_Pr)
  560. {
  561. unsigned short tempal,temp,i,j;
  562. temp = 0;
  563. for(i = 0; i < 3; i++) {
  564. for(j = 0; j < 100; j++) {
  565. tempal = SiS_GetRegByte(SiS_Pr->SiS_P3da);
  566. if(temp & 0x01) {
  567. if((tempal & 0x08)) continue;
  568. else break;
  569. } else {
  570. if(!(tempal & 0x08)) continue;
  571. else break;
  572. }
  573. }
  574. temp ^= 0x01;
  575. }
  576. }
  577. static void
  578. SiS_VBLongWait(struct SiS_Private *SiS_Pr)
  579. {
  580. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  581. SiS_VBWait(SiS_Pr);
  582. } else {
  583. SiS_WaitRetrace1(SiS_Pr);
  584. }
  585. }
  586. /*********************************************/
  587. /* HELPER: MISC */
  588. /*********************************************/
  589. #ifdef SIS300
  590. static BOOLEAN
  591. SiS_Is301B(struct SiS_Private *SiS_Pr)
  592. {
  593. if(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x01) >= 0xb0) return TRUE;
  594. return FALSE;
  595. }
  596. #endif
  597. static BOOLEAN
  598. SiS_CRT2IsLCD(struct SiS_Private *SiS_Pr)
  599. {
  600. if(SiS_Pr->ChipType == SIS_730) {
  601. if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x20) return TRUE;
  602. }
  603. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x30) & 0x20) return TRUE;
  604. return FALSE;
  605. }
  606. BOOLEAN
  607. SiS_IsDualEdge(struct SiS_Private *SiS_Pr)
  608. {
  609. #ifdef SIS315H
  610. if(SiS_Pr->ChipType >= SIS_315H) {
  611. if((SiS_Pr->ChipType != SIS_650) || (SiS_GetReg(SiS_Pr->SiS_P3d4,0x5f) & 0xf0)) {
  612. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x38) & EnableDualEdge) return TRUE;
  613. }
  614. }
  615. #endif
  616. return FALSE;
  617. }
  618. BOOLEAN
  619. SiS_IsVAMode(struct SiS_Private *SiS_Pr)
  620. {
  621. #ifdef SIS315H
  622. unsigned short flag;
  623. if(SiS_Pr->ChipType >= SIS_315H) {
  624. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  625. if((flag & EnableDualEdge) && (flag & SetToLCDA)) return TRUE;
  626. }
  627. #endif
  628. return FALSE;
  629. }
  630. #ifdef SIS315H
  631. static BOOLEAN
  632. SiS_IsVAorLCD(struct SiS_Private *SiS_Pr)
  633. {
  634. if(SiS_IsVAMode(SiS_Pr)) return TRUE;
  635. if(SiS_CRT2IsLCD(SiS_Pr)) return TRUE;
  636. return FALSE;
  637. }
  638. #endif
  639. static BOOLEAN
  640. SiS_IsDualLink(struct SiS_Private *SiS_Pr)
  641. {
  642. #ifdef SIS315H
  643. if(SiS_Pr->ChipType >= SIS_315H) {
  644. if((SiS_CRT2IsLCD(SiS_Pr)) ||
  645. (SiS_IsVAMode(SiS_Pr))) {
  646. if(SiS_Pr->SiS_LCDInfo & LCDDualLink) return TRUE;
  647. }
  648. }
  649. #endif
  650. return FALSE;
  651. }
  652. #ifdef SIS315H
  653. static BOOLEAN
  654. SiS_TVEnabled(struct SiS_Private *SiS_Pr)
  655. {
  656. if((SiS_GetReg(SiS_Pr->SiS_Part2Port,0x00) & 0x0f) != 0x0c) return TRUE;
  657. if(SiS_Pr->SiS_VBType & VB_SISYPBPR) {
  658. if(SiS_GetReg(SiS_Pr->SiS_Part2Port,0x4d) & 0x10) return TRUE;
  659. }
  660. return FALSE;
  661. }
  662. #endif
  663. #ifdef SIS315H
  664. static BOOLEAN
  665. SiS_LCDAEnabled(struct SiS_Private *SiS_Pr)
  666. {
  667. if(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x13) & 0x04) return TRUE;
  668. return FALSE;
  669. }
  670. #endif
  671. #ifdef SIS315H
  672. static BOOLEAN
  673. SiS_WeHaveBacklightCtrl(struct SiS_Private *SiS_Pr)
  674. {
  675. if((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->ChipType < SIS_661)) {
  676. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x79) & 0x10) return TRUE;
  677. }
  678. return FALSE;
  679. }
  680. #endif
  681. #ifdef SIS315H
  682. static BOOLEAN
  683. SiS_IsNotM650orLater(struct SiS_Private *SiS_Pr)
  684. {
  685. unsigned short flag;
  686. if(SiS_Pr->ChipType == SIS_650) {
  687. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x5f) & 0xf0;
  688. /* Check for revision != A0 only */
  689. if((flag == 0xe0) || (flag == 0xc0) ||
  690. (flag == 0xb0) || (flag == 0x90)) return FALSE;
  691. } else if(SiS_Pr->ChipType >= SIS_661) return FALSE;
  692. return TRUE;
  693. }
  694. #endif
  695. #ifdef SIS315H
  696. static BOOLEAN
  697. SiS_IsYPbPr(struct SiS_Private *SiS_Pr)
  698. {
  699. if(SiS_Pr->ChipType >= SIS_315H) {
  700. /* YPrPb = 0x08 */
  701. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x38) & EnableCHYPbPr) return TRUE;
  702. }
  703. return FALSE;
  704. }
  705. #endif
  706. #ifdef SIS315H
  707. static BOOLEAN
  708. SiS_IsChScart(struct SiS_Private *SiS_Pr)
  709. {
  710. if(SiS_Pr->ChipType >= SIS_315H) {
  711. /* Scart = 0x04 */
  712. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x38) & EnableCHScart) return TRUE;
  713. }
  714. return FALSE;
  715. }
  716. #endif
  717. #ifdef SIS315H
  718. static BOOLEAN
  719. SiS_IsTVOrYPbPrOrScart(struct SiS_Private *SiS_Pr)
  720. {
  721. unsigned short flag;
  722. if(SiS_Pr->ChipType >= SIS_315H) {
  723. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  724. if(flag & SetCRT2ToTV) return TRUE;
  725. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  726. if(flag & EnableCHYPbPr) return TRUE; /* = YPrPb = 0x08 */
  727. if(flag & EnableCHScart) return TRUE; /* = Scart = 0x04 - TW */
  728. } else {
  729. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  730. if(flag & SetCRT2ToTV) return TRUE;
  731. }
  732. return FALSE;
  733. }
  734. #endif
  735. #ifdef SIS315H
  736. static BOOLEAN
  737. SiS_IsLCDOrLCDA(struct SiS_Private *SiS_Pr)
  738. {
  739. unsigned short flag;
  740. if(SiS_Pr->ChipType >= SIS_315H) {
  741. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  742. if(flag & SetCRT2ToLCD) return TRUE;
  743. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  744. if(flag & SetToLCDA) return TRUE;
  745. } else {
  746. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  747. if(flag & SetCRT2ToLCD) return TRUE;
  748. }
  749. return FALSE;
  750. }
  751. #endif
  752. static BOOLEAN
  753. SiS_HaveBridge(struct SiS_Private *SiS_Pr)
  754. {
  755. unsigned short flag;
  756. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  757. return TRUE;
  758. } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
  759. flag = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x00);
  760. if((flag == 1) || (flag == 2)) return TRUE;
  761. }
  762. return FALSE;
  763. }
  764. static BOOLEAN
  765. SiS_BridgeIsEnabled(struct SiS_Private *SiS_Pr)
  766. {
  767. unsigned short flag;
  768. if(SiS_HaveBridge(SiS_Pr)) {
  769. flag = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00);
  770. if(SiS_Pr->ChipType < SIS_315H) {
  771. flag &= 0xa0;
  772. if((flag == 0x80) || (flag == 0x20)) return TRUE;
  773. } else {
  774. flag &= 0x50;
  775. if((flag == 0x40) || (flag == 0x10)) return TRUE;
  776. }
  777. }
  778. return FALSE;
  779. }
  780. static BOOLEAN
  781. SiS_BridgeInSlavemode(struct SiS_Private *SiS_Pr)
  782. {
  783. unsigned short flag1;
  784. flag1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x31);
  785. if(flag1 & (SetInSlaveMode >> 8)) return TRUE;
  786. return FALSE;
  787. }
  788. /*********************************************/
  789. /* GET VIDEO BRIDGE CONFIG INFO */
  790. /*********************************************/
  791. /* Setup general purpose IO for Chrontel communication */
  792. #ifdef SIS300
  793. void
  794. SiS_SetChrontelGPIO(struct SiS_Private *SiS_Pr, unsigned short myvbinfo)
  795. {
  796. unsigned int acpibase;
  797. unsigned short temp;
  798. if(!(SiS_Pr->SiS_ChSW)) return;
  799. #ifdef SIS_LINUX_KERNEL
  800. acpibase = sisfb_read_lpc_pci_dword(SiS_Pr, 0x74);
  801. #else
  802. acpibase = pciReadLong(0x00000800, 0x74);
  803. #endif
  804. acpibase &= 0xFFFF;
  805. if(!acpibase) return;
  806. temp = SiS_GetRegShort((acpibase + 0x3c)); /* ACPI register 0x3c: GP Event 1 I/O mode select */
  807. temp &= 0xFEFF;
  808. SiS_SetRegShort((acpibase + 0x3c), temp);
  809. temp = SiS_GetRegShort((acpibase + 0x3c));
  810. temp = SiS_GetRegShort((acpibase + 0x3a)); /* ACPI register 0x3a: GP Pin Level (low/high) */
  811. temp &= 0xFEFF;
  812. if(!(myvbinfo & SetCRT2ToTV)) temp |= 0x0100;
  813. SiS_SetRegShort((acpibase + 0x3a), temp);
  814. temp = SiS_GetRegShort((acpibase + 0x3a));
  815. }
  816. #endif
  817. void
  818. SiS_GetVBInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
  819. unsigned short ModeIdIndex, int checkcrt2mode)
  820. {
  821. unsigned short tempax, tempbx, temp;
  822. unsigned short modeflag, resinfo = 0;
  823. SiS_Pr->SiS_SetFlag = 0;
  824. modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
  825. SiS_Pr->SiS_ModeType = modeflag & ModeTypeMask;
  826. if((ModeNo > 0x13) && (!SiS_Pr->UseCustomMode)) {
  827. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  828. }
  829. tempbx = 0;
  830. if(SiS_HaveBridge(SiS_Pr)) {
  831. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  832. tempbx |= temp;
  833. tempax = SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) << 8;
  834. tempax &= (DriverMode | LoadDACFlag | SetNotSimuMode | SetPALTV);
  835. tempbx |= tempax;
  836. #ifdef SIS315H
  837. if(SiS_Pr->ChipType >= SIS_315H) {
  838. if(SiS_Pr->SiS_VBType & VB_SISLCDA) {
  839. if(ModeNo == 0x03) {
  840. /* Mode 0x03 is never in driver mode */
  841. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x31,0xbf);
  842. }
  843. if(!(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & (DriverMode >> 8))) {
  844. /* Reset LCDA setting if not driver mode */
  845. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x38,0xfc);
  846. }
  847. if(IS_SIS650) {
  848. if(SiS_Pr->SiS_UseLCDA) {
  849. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x5f) & 0xF0) {
  850. if((ModeNo <= 0x13) || (!(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & (DriverMode >> 8)))) {
  851. SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x38,(EnableDualEdge | SetToLCDA));
  852. }
  853. }
  854. }
  855. }
  856. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  857. if((temp & (EnableDualEdge | SetToLCDA)) == (EnableDualEdge | SetToLCDA)) {
  858. tempbx |= SetCRT2ToLCDA;
  859. }
  860. }
  861. if(SiS_Pr->ChipType >= SIS_661) { /* New CR layout */
  862. tempbx &= ~(SetCRT2ToYPbPr525750 | SetCRT2ToHiVision);
  863. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x38) & 0x04) {
  864. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35) & 0xe0;
  865. if(temp == 0x60) tempbx |= SetCRT2ToHiVision;
  866. else if(SiS_Pr->SiS_VBType & VB_SISYPBPR) {
  867. tempbx |= SetCRT2ToYPbPr525750;
  868. }
  869. }
  870. }
  871. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  872. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  873. if(temp & SetToLCDA) {
  874. tempbx |= SetCRT2ToLCDA;
  875. }
  876. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  877. if(temp & EnableCHYPbPr) {
  878. tempbx |= SetCRT2ToCHYPbPr;
  879. }
  880. }
  881. }
  882. }
  883. #endif /* SIS315H */
  884. if(!(SiS_Pr->SiS_VBType & VB_SISVGA2)) {
  885. tempbx &= ~(SetCRT2ToRAMDAC);
  886. }
  887. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  888. temp = SetCRT2ToSVIDEO |
  889. SetCRT2ToAVIDEO |
  890. SetCRT2ToSCART |
  891. SetCRT2ToLCDA |
  892. SetCRT2ToLCD |
  893. SetCRT2ToRAMDAC |
  894. SetCRT2ToHiVision |
  895. SetCRT2ToYPbPr525750;
  896. } else {
  897. if(SiS_Pr->ChipType >= SIS_315H) {
  898. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  899. temp = SetCRT2ToAVIDEO |
  900. SetCRT2ToSVIDEO |
  901. SetCRT2ToSCART |
  902. SetCRT2ToLCDA |
  903. SetCRT2ToLCD |
  904. SetCRT2ToCHYPbPr;
  905. } else {
  906. temp = SetCRT2ToLCDA |
  907. SetCRT2ToLCD;
  908. }
  909. } else {
  910. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  911. temp = SetCRT2ToTV | SetCRT2ToLCD;
  912. } else {
  913. temp = SetCRT2ToLCD;
  914. }
  915. }
  916. }
  917. if(!(tempbx & temp)) {
  918. tempax = DisableCRT2Display;
  919. tempbx = 0;
  920. }
  921. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  922. unsigned short clearmask = ( DriverMode |
  923. DisableCRT2Display |
  924. LoadDACFlag |
  925. SetNotSimuMode |
  926. SetInSlaveMode |
  927. SetPALTV |
  928. SwitchCRT2 |
  929. SetSimuScanMode );
  930. if(tempbx & SetCRT2ToLCDA) tempbx &= (clearmask | SetCRT2ToLCDA);
  931. if(tempbx & SetCRT2ToRAMDAC) tempbx &= (clearmask | SetCRT2ToRAMDAC);
  932. if(tempbx & SetCRT2ToLCD) tempbx &= (clearmask | SetCRT2ToLCD);
  933. if(tempbx & SetCRT2ToSCART) tempbx &= (clearmask | SetCRT2ToSCART);
  934. if(tempbx & SetCRT2ToHiVision) tempbx &= (clearmask | SetCRT2ToHiVision);
  935. if(tempbx & SetCRT2ToYPbPr525750) tempbx &= (clearmask | SetCRT2ToYPbPr525750);
  936. } else {
  937. if(SiS_Pr->ChipType >= SIS_315H) {
  938. if(tempbx & SetCRT2ToLCDA) {
  939. tempbx &= (0xFF00|SwitchCRT2|SetSimuScanMode);
  940. }
  941. }
  942. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  943. if(tempbx & SetCRT2ToTV) {
  944. tempbx &= (0xFF00|SetCRT2ToTV|SwitchCRT2|SetSimuScanMode);
  945. }
  946. }
  947. if(tempbx & SetCRT2ToLCD) {
  948. tempbx &= (0xFF00|SetCRT2ToLCD|SwitchCRT2|SetSimuScanMode);
  949. }
  950. if(SiS_Pr->ChipType >= SIS_315H) {
  951. if(tempbx & SetCRT2ToLCDA) {
  952. tempbx |= SetCRT2ToLCD;
  953. }
  954. }
  955. }
  956. if(tempax & DisableCRT2Display) {
  957. if(!(tempbx & (SwitchCRT2 | SetSimuScanMode))) {
  958. tempbx = SetSimuScanMode | DisableCRT2Display;
  959. }
  960. }
  961. if(!(tempbx & DriverMode)) tempbx |= SetSimuScanMode;
  962. /* LVDS/CHRONTEL (LCD/TV) and 301BDH (LCD) can only be slave in 8bpp modes */
  963. if(SiS_Pr->SiS_ModeType <= ModeVGA) {
  964. if( (SiS_Pr->SiS_IF_DEF_LVDS == 1) ||
  965. ((SiS_Pr->SiS_VBType & VB_NoLCD) && (tempbx & SetCRT2ToLCD)) ) {
  966. modeflag &= (~CRT2Mode);
  967. }
  968. }
  969. if(!(tempbx & SetSimuScanMode)) {
  970. if(tempbx & SwitchCRT2) {
  971. if((!(modeflag & CRT2Mode)) && (checkcrt2mode)) {
  972. if(resinfo != SIS_RI_1600x1200) {
  973. tempbx |= SetSimuScanMode;
  974. }
  975. }
  976. } else {
  977. if(SiS_BridgeIsEnabled(SiS_Pr)) {
  978. if(!(tempbx & DriverMode)) {
  979. if(SiS_BridgeInSlavemode(SiS_Pr)) {
  980. tempbx |= SetSimuScanMode;
  981. }
  982. }
  983. }
  984. }
  985. }
  986. if(!(tempbx & DisableCRT2Display)) {
  987. if(tempbx & DriverMode) {
  988. if(tempbx & SetSimuScanMode) {
  989. if((!(modeflag & CRT2Mode)) && (checkcrt2mode)) {
  990. if(resinfo != SIS_RI_1600x1200) {
  991. tempbx |= SetInSlaveMode;
  992. }
  993. }
  994. }
  995. } else {
  996. tempbx |= SetInSlaveMode;
  997. }
  998. }
  999. }
  1000. SiS_Pr->SiS_VBInfo = tempbx;
  1001. #ifdef SIS300
  1002. if(SiS_Pr->ChipType == SIS_630) {
  1003. SiS_SetChrontelGPIO(SiS_Pr, SiS_Pr->SiS_VBInfo);
  1004. }
  1005. #endif
  1006. #ifdef SIS_LINUX_KERNEL
  1007. #if 0
  1008. printk(KERN_DEBUG "sisfb: (init301: VBInfo= 0x%04x, SetFlag=0x%04x)\n",
  1009. SiS_Pr->SiS_VBInfo, SiS_Pr->SiS_SetFlag);
  1010. #endif
  1011. #endif
  1012. #ifdef SIS_XORG_XF86
  1013. #ifdef TWDEBUG
  1014. xf86DrvMsg(0, X_PROBED, "(init301: VBInfo=0x%04x, SetFlag=0x%04x)\n",
  1015. SiS_Pr->SiS_VBInfo, SiS_Pr->SiS_SetFlag);
  1016. #endif
  1017. #endif
  1018. }
  1019. /*********************************************/
  1020. /* DETERMINE YPbPr MODE */
  1021. /*********************************************/
  1022. void
  1023. SiS_SetYPbPr(struct SiS_Private *SiS_Pr)
  1024. {
  1025. unsigned char temp;
  1026. /* Note: This variable is only used on 30xLV systems.
  1027. * CR38 has a different meaning on LVDS/CH7019 systems.
  1028. * On 661 and later, these bits moved to CR35.
  1029. *
  1030. * On 301, 301B, only HiVision 1080i is supported.
  1031. * On 30xLV, 301C, only YPbPr 1080i is supported.
  1032. */
  1033. SiS_Pr->SiS_YPbPr = 0;
  1034. if(SiS_Pr->ChipType >= SIS_661) return;
  1035. if(SiS_Pr->SiS_VBType) {
  1036. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  1037. SiS_Pr->SiS_YPbPr = YPbPrHiVision;
  1038. }
  1039. }
  1040. if(SiS_Pr->ChipType >= SIS_315H) {
  1041. if(SiS_Pr->SiS_VBType & VB_SISYPBPR) {
  1042. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  1043. if(temp & 0x08) {
  1044. switch((temp >> 4)) {
  1045. case 0x00: SiS_Pr->SiS_YPbPr = YPbPr525i; break;
  1046. case 0x01: SiS_Pr->SiS_YPbPr = YPbPr525p; break;
  1047. case 0x02: SiS_Pr->SiS_YPbPr = YPbPr750p; break;
  1048. case 0x03: SiS_Pr->SiS_YPbPr = YPbPrHiVision; break;
  1049. }
  1050. }
  1051. }
  1052. }
  1053. }
  1054. /*********************************************/
  1055. /* DETERMINE TVMode flag */
  1056. /*********************************************/
  1057. void
  1058. SiS_SetTVMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  1059. {
  1060. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  1061. unsigned short temp, temp1, resinfo = 0, romindex = 0;
  1062. unsigned char OutputSelect = *SiS_Pr->pSiS_OutputSelect;
  1063. SiS_Pr->SiS_TVMode = 0;
  1064. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) return;
  1065. if(SiS_Pr->UseCustomMode) return;
  1066. if(ModeNo > 0x13) {
  1067. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  1068. }
  1069. if(SiS_Pr->ChipType < SIS_661) {
  1070. if(SiS_Pr->SiS_VBInfo & SetPALTV) SiS_Pr->SiS_TVMode |= TVSetPAL;
  1071. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  1072. temp = 0;
  1073. if((SiS_Pr->ChipType == SIS_630) ||
  1074. (SiS_Pr->ChipType == SIS_730)) {
  1075. temp = 0x35;
  1076. romindex = 0xfe;
  1077. } else if(SiS_Pr->ChipType >= SIS_315H) {
  1078. temp = 0x38;
  1079. if(SiS_Pr->ChipType < XGI_20) {
  1080. romindex = 0xf3;
  1081. if(SiS_Pr->ChipType >= SIS_330) romindex = 0x11b;
  1082. }
  1083. }
  1084. if(temp) {
  1085. if(romindex && SiS_Pr->SiS_UseROM && (!(SiS_Pr->SiS_ROMNew))) {
  1086. OutputSelect = ROMAddr[romindex];
  1087. if(!(OutputSelect & EnablePALMN)) {
  1088. SiS_SetRegAND(SiS_Pr->SiS_P3d4,temp,0x3F);
  1089. }
  1090. }
  1091. temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,temp);
  1092. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  1093. if(temp1 & EnablePALM) { /* 0x40 */
  1094. SiS_Pr->SiS_TVMode |= TVSetPALM;
  1095. SiS_Pr->SiS_TVMode &= ~TVSetPAL;
  1096. } else if(temp1 & EnablePALN) { /* 0x80 */
  1097. SiS_Pr->SiS_TVMode |= TVSetPALN;
  1098. }
  1099. } else {
  1100. if(temp1 & EnableNTSCJ) { /* 0x40 */
  1101. SiS_Pr->SiS_TVMode |= TVSetNTSCJ;
  1102. }
  1103. }
  1104. }
  1105. /* Translate HiVision/YPbPr to our new flags */
  1106. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  1107. if(SiS_Pr->SiS_YPbPr == YPbPr750p) SiS_Pr->SiS_TVMode |= TVSetYPbPr750p;
  1108. else if(SiS_Pr->SiS_YPbPr == YPbPr525p) SiS_Pr->SiS_TVMode |= TVSetYPbPr525p;
  1109. else if(SiS_Pr->SiS_YPbPr == YPbPrHiVision) SiS_Pr->SiS_TVMode |= TVSetHiVision;
  1110. else SiS_Pr->SiS_TVMode |= TVSetYPbPr525i;
  1111. if(SiS_Pr->SiS_TVMode & (TVSetYPbPr750p | TVSetYPbPr525p | TVSetYPbPr525i)) {
  1112. SiS_Pr->SiS_VBInfo &= ~SetCRT2ToHiVision;
  1113. SiS_Pr->SiS_VBInfo |= SetCRT2ToYPbPr525750;
  1114. } else if(SiS_Pr->SiS_TVMode & TVSetHiVision) {
  1115. SiS_Pr->SiS_TVMode |= TVSetPAL;
  1116. }
  1117. }
  1118. } else if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  1119. if(SiS_Pr->SiS_CHOverScan) {
  1120. if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) {
  1121. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35);
  1122. if((temp & TVOverScan) || (SiS_Pr->SiS_CHOverScan == 1)) {
  1123. SiS_Pr->SiS_TVMode |= TVSetCHOverScan;
  1124. }
  1125. } else if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  1126. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x79);
  1127. if((temp & 0x80) || (SiS_Pr->SiS_CHOverScan == 1)) {
  1128. SiS_Pr->SiS_TVMode |= TVSetCHOverScan;
  1129. }
  1130. }
  1131. if(SiS_Pr->SiS_CHSOverScan) {
  1132. SiS_Pr->SiS_TVMode |= TVSetCHOverScan;
  1133. }
  1134. }
  1135. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  1136. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  1137. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  1138. if(temp & EnablePALM) SiS_Pr->SiS_TVMode |= TVSetPALM;
  1139. else if(temp & EnablePALN) SiS_Pr->SiS_TVMode |= TVSetPALN;
  1140. } else {
  1141. if(temp & EnableNTSCJ) {
  1142. SiS_Pr->SiS_TVMode |= TVSetNTSCJ;
  1143. }
  1144. }
  1145. }
  1146. }
  1147. } else { /* 661 and later */
  1148. temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35);
  1149. if(temp1 & 0x01) {
  1150. SiS_Pr->SiS_TVMode |= TVSetPAL;
  1151. if(temp1 & 0x08) {
  1152. SiS_Pr->SiS_TVMode |= TVSetPALN;
  1153. } else if(temp1 & 0x04) {
  1154. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  1155. SiS_Pr->SiS_TVMode &= ~TVSetPAL;
  1156. }
  1157. SiS_Pr->SiS_TVMode |= TVSetPALM;
  1158. }
  1159. } else {
  1160. if(temp1 & 0x02) {
  1161. SiS_Pr->SiS_TVMode |= TVSetNTSCJ;
  1162. }
  1163. }
  1164. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  1165. if(SiS_Pr->SiS_CHOverScan) {
  1166. if((temp1 & 0x10) || (SiS_Pr->SiS_CHOverScan == 1)) {
  1167. SiS_Pr->SiS_TVMode |= TVSetCHOverScan;
  1168. }
  1169. }
  1170. }
  1171. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  1172. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  1173. temp1 &= 0xe0;
  1174. if(temp1 == 0x00) SiS_Pr->SiS_TVMode |= TVSetYPbPr525i;
  1175. else if(temp1 == 0x20) SiS_Pr->SiS_TVMode |= TVSetYPbPr525p;
  1176. else if(temp1 == 0x40) SiS_Pr->SiS_TVMode |= TVSetYPbPr750p;
  1177. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  1178. SiS_Pr->SiS_TVMode |= (TVSetHiVision | TVSetPAL);
  1179. }
  1180. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToYPbPr525750 | SetCRT2ToHiVision)) {
  1181. if(resinfo == SIS_RI_800x480 || resinfo == SIS_RI_1024x576 || resinfo == SIS_RI_1280x720) {
  1182. SiS_Pr->SiS_TVMode |= TVAspect169;
  1183. } else {
  1184. temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x39);
  1185. if(temp1 & 0x02) {
  1186. if(SiS_Pr->SiS_TVMode & (TVSetYPbPr750p | TVSetHiVision)) {
  1187. SiS_Pr->SiS_TVMode |= TVAspect169;
  1188. } else {
  1189. SiS_Pr->SiS_TVMode |= TVAspect43LB;
  1190. }
  1191. } else {
  1192. SiS_Pr->SiS_TVMode |= TVAspect43;
  1193. }
  1194. }
  1195. }
  1196. }
  1197. }
  1198. if(SiS_Pr->SiS_VBInfo & SetCRT2ToSCART) SiS_Pr->SiS_TVMode |= TVSetPAL;
  1199. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  1200. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  1201. SiS_Pr->SiS_TVMode |= TVSetPAL;
  1202. SiS_Pr->SiS_TVMode &= ~(TVSetPALM | TVSetPALN | TVSetNTSCJ);
  1203. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  1204. if(SiS_Pr->SiS_TVMode & (TVSetYPbPr525i | TVSetYPbPr525p | TVSetYPbPr750p)) {
  1205. SiS_Pr->SiS_TVMode &= ~(TVSetPAL | TVSetNTSCJ | TVSetPALM | TVSetPALN);
  1206. }
  1207. }
  1208. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  1209. if(!(SiS_Pr->SiS_VBInfo & SetNotSimuMode)) {
  1210. SiS_Pr->SiS_TVMode |= TVSetTVSimuMode;
  1211. }
  1212. }
  1213. if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) {
  1214. if(resinfo == SIS_RI_1024x768) {
  1215. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) {
  1216. SiS_Pr->SiS_TVMode |= TVSet525p1024;
  1217. } else if(!(SiS_Pr->SiS_TVMode & (TVSetHiVision | TVSetYPbPr750p))) {
  1218. SiS_Pr->SiS_TVMode |= TVSetNTSC1024;
  1219. }
  1220. }
  1221. }
  1222. SiS_Pr->SiS_TVMode |= TVRPLLDIV2XO;
  1223. if((SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) &&
  1224. (SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  1225. SiS_Pr->SiS_TVMode &= ~TVRPLLDIV2XO;
  1226. } else if(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p)) {
  1227. SiS_Pr->SiS_TVMode &= ~TVRPLLDIV2XO;
  1228. } else if(!(SiS_Pr->SiS_VBType & VB_SIS30xBLV)) {
  1229. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) {
  1230. SiS_Pr->SiS_TVMode &= ~TVRPLLDIV2XO;
  1231. }
  1232. }
  1233. }
  1234. SiS_Pr->SiS_VBInfo &= ~SetPALTV;
  1235. #ifdef SIS_XORG_XF86
  1236. #ifdef TWDEBUG
  1237. xf86DrvMsg(0, X_INFO, "(init301: TVMode %x, VBInfo %x)\n", SiS_Pr->SiS_TVMode, SiS_Pr->SiS_VBInfo);
  1238. #endif
  1239. #endif
  1240. }
  1241. /*********************************************/
  1242. /* GET LCD INFO */
  1243. /*********************************************/
  1244. static unsigned short
  1245. SiS_GetBIOSLCDResInfo(struct SiS_Private *SiS_Pr)
  1246. {
  1247. unsigned short temp = SiS_Pr->SiS_LCDResInfo;
  1248. /* Translate my LCDResInfo to BIOS value */
  1249. switch(temp) {
  1250. case Panel_1280x768_2: temp = Panel_1280x768; break;
  1251. case Panel_1280x800_2: temp = Panel_1280x800; break;
  1252. case Panel_1280x854: temp = Panel661_1280x854; break;
  1253. }
  1254. return temp;
  1255. }
  1256. static void
  1257. SiS_GetLCDInfoBIOS(struct SiS_Private *SiS_Pr)
  1258. {
  1259. #ifdef SIS315H
  1260. unsigned char *ROMAddr;
  1261. unsigned short temp;
  1262. #ifdef SIS_XORG_XF86
  1263. #ifdef TWDEBUG
  1264. xf86DrvMsg(0, X_INFO, "Paneldata driver: [%d %d] [H %d %d] [V %d %d] [C %d 0x%02x 0x%02x]\n",
  1265. SiS_Pr->PanelHT, SiS_Pr->PanelVT,
  1266. SiS_Pr->PanelHRS, SiS_Pr->PanelHRE,
  1267. SiS_Pr->PanelVRS, SiS_Pr->PanelVRE,
  1268. SiS_Pr->SiS_VBVCLKData[SiS_Pr->PanelVCLKIdx315].CLOCK,
  1269. SiS_Pr->SiS_VBVCLKData[SiS_Pr->PanelVCLKIdx315].Part4_A,
  1270. SiS_Pr->SiS_VBVCLKData[SiS_Pr->PanelVCLKIdx315].Part4_B);
  1271. #endif
  1272. #endif
  1273. if((ROMAddr = GetLCDStructPtr661(SiS_Pr))) {
  1274. if((temp = SISGETROMW(6)) != SiS_Pr->PanelHT) {
  1275. SiS_Pr->SiS_NeedRomModeData = TRUE;
  1276. SiS_Pr->PanelHT = temp;
  1277. }
  1278. if((temp = SISGETROMW(8)) != SiS_Pr->PanelVT) {
  1279. SiS_Pr->SiS_NeedRomModeData = TRUE;
  1280. SiS_Pr->PanelVT = temp;
  1281. }
  1282. SiS_Pr->PanelHRS = SISGETROMW(10);
  1283. SiS_Pr->PanelHRE = SISGETROMW(12);
  1284. SiS_Pr->PanelVRS = SISGETROMW(14);
  1285. SiS_Pr->PanelVRE = SISGETROMW(16);
  1286. SiS_Pr->PanelVCLKIdx315 = VCLK_CUSTOM_315;
  1287. SiS_Pr->SiS_VCLKData[VCLK_CUSTOM_315].CLOCK =
  1288. SiS_Pr->SiS_VBVCLKData[VCLK_CUSTOM_315].CLOCK = (unsigned short)((unsigned char)ROMAddr[18]);
  1289. SiS_Pr->SiS_VCLKData[VCLK_CUSTOM_315].SR2B =
  1290. SiS_Pr->SiS_VBVCLKData[VCLK_CUSTOM_315].Part4_A = ROMAddr[19];
  1291. SiS_Pr->SiS_VCLKData[VCLK_CUSTOM_315].SR2C =
  1292. SiS_Pr->SiS_VBVCLKData[VCLK_CUSTOM_315].Part4_B = ROMAddr[20];
  1293. #ifdef SIS_XORG_XF86
  1294. #ifdef TWDEBUG
  1295. xf86DrvMsg(0, X_INFO, "Paneldata BIOS: [%d %d] [H %d %d] [V %d %d] [C %d 0x%02x 0x%02x]\n",
  1296. SiS_Pr->PanelHT, SiS_Pr->PanelVT,
  1297. SiS_Pr->PanelHRS, SiS_Pr->PanelHRE,
  1298. SiS_Pr->PanelVRS, SiS_Pr->PanelVRE,
  1299. SiS_Pr->SiS_VBVCLKData[SiS_Pr->PanelVCLKIdx315].CLOCK,
  1300. SiS_Pr->SiS_VBVCLKData[SiS_Pr->PanelVCLKIdx315].Part4_A,
  1301. SiS_Pr->SiS_VBVCLKData[SiS_Pr->PanelVCLKIdx315].Part4_B);
  1302. #endif
  1303. #endif
  1304. }
  1305. #endif
  1306. }
  1307. static void
  1308. SiS_CheckScaling(struct SiS_Private *SiS_Pr, unsigned short resinfo,
  1309. const unsigned char *nonscalingmodes)
  1310. {
  1311. int i = 0;
  1312. while(nonscalingmodes[i] != 0xff) {
  1313. if(nonscalingmodes[i++] == resinfo) {
  1314. if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) ||
  1315. (SiS_Pr->UsePanelScaler == -1)) {
  1316. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1317. }
  1318. break;
  1319. }
  1320. }
  1321. }
  1322. void
  1323. SiS_GetLCDResInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  1324. {
  1325. unsigned short temp,modeflag,resinfo=0,modexres=0,modeyres=0;
  1326. BOOLEAN panelcanscale = FALSE;
  1327. #ifdef SIS300
  1328. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  1329. static const unsigned char SiS300SeriesLCDRes[] =
  1330. { 0, 1, 2, 3, 7, 4, 5, 8,
  1331. 0, 0, 10, 0, 0, 0, 0, 15 };
  1332. #endif
  1333. #ifdef SIS315H
  1334. unsigned char *myptr = NULL;
  1335. #endif
  1336. SiS_Pr->SiS_LCDResInfo = 0;
  1337. SiS_Pr->SiS_LCDTypeInfo = 0;
  1338. SiS_Pr->SiS_LCDInfo = 0;
  1339. SiS_Pr->PanelHRS = 999; /* HSync start */
  1340. SiS_Pr->PanelHRE = 999; /* HSync end */
  1341. SiS_Pr->PanelVRS = 999; /* VSync start */
  1342. SiS_Pr->PanelVRE = 999; /* VSync end */
  1343. SiS_Pr->SiS_NeedRomModeData = FALSE;
  1344. /* Alternative 1600x1200@60 timing for 1600x1200 LCDA */
  1345. SiS_Pr->Alternate1600x1200 = FALSE;
  1346. if(!(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA))) return;
  1347. modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
  1348. if((ModeNo > 0x13) && (!SiS_Pr->UseCustomMode)) {
  1349. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  1350. modexres = SiS_Pr->SiS_ModeResInfo[resinfo].HTotal;
  1351. modeyres = SiS_Pr->SiS_ModeResInfo[resinfo].VTotal;
  1352. }
  1353. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36);
  1354. /* For broken BIOSes: Assume 1024x768 */
  1355. if(temp == 0) temp = 0x02;
  1356. if((SiS_Pr->ChipType >= SIS_661) || (SiS_Pr->SiS_ROMNew)) {
  1357. SiS_Pr->SiS_LCDTypeInfo = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x39) & 0x7c) >> 2;
  1358. } else if((SiS_Pr->ChipType < SIS_315H) || (SiS_Pr->ChipType >= SIS_661)) {
  1359. SiS_Pr->SiS_LCDTypeInfo = temp >> 4;
  1360. } else {
  1361. SiS_Pr->SiS_LCDTypeInfo = (temp & 0x0F) - 1;
  1362. }
  1363. temp &= 0x0f;
  1364. #ifdef SIS300
  1365. if(SiS_Pr->ChipType < SIS_315H) {
  1366. /* Very old BIOSes only know 7 sizes (NetVista 2179, 1.01g) */
  1367. if(SiS_Pr->SiS_VBType & VB_SIS301) {
  1368. if(temp < 0x0f) temp &= 0x07;
  1369. }
  1370. /* Translate 300 series LCDRes to 315 series for unified usage */
  1371. temp = SiS300SeriesLCDRes[temp];
  1372. }
  1373. #endif
  1374. /* Translate to our internal types */
  1375. #ifdef SIS315H
  1376. if(SiS_Pr->ChipType == SIS_550) {
  1377. if (temp == Panel310_1152x768) temp = Panel_320x240_2; /* Verified working */
  1378. else if(temp == Panel310_320x240_2) temp = Panel_320x240_2;
  1379. else if(temp == Panel310_320x240_3) temp = Panel_320x240_3;
  1380. } else if(SiS_Pr->ChipType >= SIS_661) {
  1381. if(temp == Panel661_1280x854) temp = Panel_1280x854;
  1382. }
  1383. #endif
  1384. if(SiS_Pr->SiS_VBType & VB_SISLVDS) { /* SiS LVDS */
  1385. if(temp == Panel310_1280x768) {
  1386. temp = Panel_1280x768_2;
  1387. }
  1388. if(SiS_Pr->SiS_ROMNew) {
  1389. if(temp == Panel661_1280x800) {
  1390. temp = Panel_1280x800_2;
  1391. }
  1392. }
  1393. }
  1394. SiS_Pr->SiS_LCDResInfo = temp;
  1395. #ifdef SIS300
  1396. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  1397. if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) {
  1398. SiS_Pr->SiS_LCDResInfo = Panel_Barco1366;
  1399. } else if(SiS_Pr->SiS_CustomT == CUT_PANEL848) {
  1400. SiS_Pr->SiS_LCDResInfo = Panel_848x480;
  1401. } else if(SiS_Pr->SiS_CustomT == CUT_PANEL856) {
  1402. SiS_Pr->SiS_LCDResInfo = Panel_856x480;
  1403. }
  1404. }
  1405. #endif
  1406. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  1407. if(SiS_Pr->SiS_LCDResInfo < SiS_Pr->SiS_PanelMin301)
  1408. SiS_Pr->SiS_LCDResInfo = SiS_Pr->SiS_PanelMin301;
  1409. } else {
  1410. if(SiS_Pr->SiS_LCDResInfo < SiS_Pr->SiS_PanelMinLVDS)
  1411. SiS_Pr->SiS_LCDResInfo = SiS_Pr->SiS_PanelMinLVDS;
  1412. }
  1413. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x37);
  1414. SiS_Pr->SiS_LCDInfo = temp & ~0x000e;
  1415. /* Need temp below! */
  1416. /* These must/can't scale no matter what */
  1417. switch(SiS_Pr->SiS_LCDResInfo) {
  1418. case Panel_320x240_1:
  1419. case Panel_320x240_2:
  1420. case Panel_320x240_3:
  1421. case Panel_1280x960:
  1422. SiS_Pr->SiS_LCDInfo &= ~DontExpandLCD;
  1423. break;
  1424. case Panel_640x480:
  1425. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1426. }
  1427. panelcanscale = (SiS_Pr->SiS_LCDInfo & DontExpandLCD) ? TRUE : FALSE;
  1428. if(!SiS_Pr->UsePanelScaler) SiS_Pr->SiS_LCDInfo &= ~DontExpandLCD;
  1429. else if(SiS_Pr->UsePanelScaler == 1) SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1430. /* Dual link, Pass 1:1 BIOS default, etc. */
  1431. #ifdef SIS315H
  1432. if(SiS_Pr->ChipType >= SIS_661) {
  1433. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  1434. if(temp & 0x08) SiS_Pr->SiS_LCDInfo |= LCDPass11;
  1435. }
  1436. if(SiS_Pr->SiS_VBType & VB_SISDUALLINK) {
  1437. if(SiS_Pr->SiS_ROMNew) {
  1438. if(temp & 0x02) SiS_Pr->SiS_LCDInfo |= LCDDualLink;
  1439. } else if((myptr = GetLCDStructPtr661(SiS_Pr))) {
  1440. if(myptr[2] & 0x01) SiS_Pr->SiS_LCDInfo |= LCDDualLink;
  1441. }
  1442. }
  1443. } else if(SiS_Pr->ChipType >= SIS_315H) {
  1444. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  1445. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x39) & 0x01) SiS_Pr->SiS_LCDInfo |= LCDPass11;
  1446. }
  1447. if((SiS_Pr->SiS_ROMNew) && (!(SiS_Pr->PanelSelfDetected))) {
  1448. SiS_Pr->SiS_LCDInfo &= ~(LCDRGB18Bit);
  1449. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35);
  1450. if(temp & 0x01) SiS_Pr->SiS_LCDInfo |= LCDRGB18Bit;
  1451. if(SiS_Pr->SiS_VBType & VB_SISDUALLINK) {
  1452. if(temp & 0x02) SiS_Pr->SiS_LCDInfo |= LCDDualLink;
  1453. }
  1454. } else if(!(SiS_Pr->SiS_ROMNew)) {
  1455. if(SiS_Pr->SiS_VBType & VB_SISDUALLINK) {
  1456. if((SiS_Pr->SiS_CustomT == CUT_CLEVO1024) &&
  1457. (SiS_Pr->SiS_LCDResInfo == Panel_1024x768)) {
  1458. SiS_Pr->SiS_LCDInfo |= LCDDualLink;
  1459. }
  1460. if((SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) ||
  1461. (SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) ||
  1462. (SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) ||
  1463. (SiS_Pr->SiS_LCDResInfo == Panel_1680x1050)) {
  1464. SiS_Pr->SiS_LCDInfo |= LCDDualLink;
  1465. }
  1466. }
  1467. }
  1468. }
  1469. #endif
  1470. /* Pass 1:1 */
  1471. if((SiS_Pr->SiS_IF_DEF_LVDS == 1) || (SiS_Pr->SiS_VBType & VB_NoLCD)) {
  1472. /* Always center screen on LVDS (if scaling is disabled) */
  1473. SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  1474. } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
  1475. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  1476. /* Always center screen on SiS LVDS (if scaling is disabled) */
  1477. SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  1478. } else {
  1479. /* By default, pass 1:1 on SiS TMDS (if scaling is supported) */
  1480. if(panelcanscale) SiS_Pr->SiS_LCDInfo |= LCDPass11;
  1481. if(SiS_Pr->CenterScreen == 1) SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  1482. }
  1483. }
  1484. SiS_Pr->PanelVCLKIdx300 = VCLK65_300;
  1485. SiS_Pr->PanelVCLKIdx315 = VCLK108_2_315;
  1486. switch(SiS_Pr->SiS_LCDResInfo) {
  1487. case Panel_320x240_1:
  1488. case Panel_320x240_2:
  1489. case Panel_320x240_3: SiS_Pr->PanelXRes = 640; SiS_Pr->PanelYRes = 480;
  1490. SiS_Pr->PanelVRS = 24; SiS_Pr->PanelVRE = 3;
  1491. SiS_Pr->PanelVCLKIdx300 = VCLK28;
  1492. SiS_Pr->PanelVCLKIdx315 = VCLK28;
  1493. break;
  1494. case Panel_640x480: SiS_Pr->PanelXRes = 640; SiS_Pr->PanelYRes = 480;
  1495. SiS_Pr->PanelVRE = 3;
  1496. SiS_Pr->PanelVCLKIdx300 = VCLK28;
  1497. SiS_Pr->PanelVCLKIdx315 = VCLK28;
  1498. break;
  1499. case Panel_800x600: SiS_Pr->PanelXRes = 800; SiS_Pr->PanelYRes = 600;
  1500. SiS_Pr->PanelHT = 1056; SiS_Pr->PanelVT = 628;
  1501. SiS_Pr->PanelHRS = 40; SiS_Pr->PanelHRE = 128;
  1502. SiS_Pr->PanelVRS = 1; SiS_Pr->PanelVRE = 4;
  1503. SiS_Pr->PanelVCLKIdx300 = VCLK40;
  1504. SiS_Pr->PanelVCLKIdx315 = VCLK40;
  1505. break;
  1506. case Panel_1024x600: SiS_Pr->PanelXRes = 1024; SiS_Pr->PanelYRes = 600;
  1507. SiS_Pr->PanelHT = 1344; SiS_Pr->PanelVT = 800;
  1508. SiS_Pr->PanelHRS = 24; SiS_Pr->PanelHRE = 136;
  1509. SiS_Pr->PanelVRS = 2 /* 88 */ ; SiS_Pr->PanelVRE = 6;
  1510. SiS_Pr->PanelVCLKIdx300 = VCLK65_300;
  1511. SiS_Pr->PanelVCLKIdx315 = VCLK65_315;
  1512. break;
  1513. case Panel_1024x768: SiS_Pr->PanelXRes = 1024; SiS_Pr->PanelYRes = 768;
  1514. SiS_Pr->PanelHT = 1344; SiS_Pr->PanelVT = 806;
  1515. SiS_Pr->PanelHRS = 24; SiS_Pr->PanelHRE = 136;
  1516. SiS_Pr->PanelVRS = 3; SiS_Pr->PanelVRE = 6;
  1517. if(SiS_Pr->ChipType < SIS_315H) {
  1518. SiS_Pr->PanelHRS = 23;
  1519. SiS_Pr->PanelVRE = 5;
  1520. }
  1521. SiS_Pr->PanelVCLKIdx300 = VCLK65_300;
  1522. SiS_Pr->PanelVCLKIdx315 = VCLK65_315;
  1523. SiS_GetLCDInfoBIOS(SiS_Pr);
  1524. break;
  1525. case Panel_1152x768: SiS_Pr->PanelXRes = 1152; SiS_Pr->PanelYRes = 768;
  1526. SiS_Pr->PanelHT = 1344; SiS_Pr->PanelVT = 806;
  1527. SiS_Pr->PanelHRS = 24; SiS_Pr->PanelHRE = 136;
  1528. SiS_Pr->PanelVRS = 3; SiS_Pr->PanelVRE = 6;
  1529. if(SiS_Pr->ChipType < SIS_315H) {
  1530. SiS_Pr->PanelHRS = 23;
  1531. SiS_Pr->PanelVRE = 5;
  1532. }
  1533. SiS_Pr->PanelVCLKIdx300 = VCLK65_300;
  1534. SiS_Pr->PanelVCLKIdx315 = VCLK65_315;
  1535. break;
  1536. case Panel_1152x864: SiS_Pr->PanelXRes = 1152; SiS_Pr->PanelYRes = 864;
  1537. break;
  1538. case Panel_1280x720: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 720;
  1539. SiS_Pr->PanelHT = 1650; SiS_Pr->PanelVT = 750;
  1540. SiS_Pr->PanelHRS = 110; SiS_Pr->PanelHRE = 40;
  1541. SiS_Pr->PanelVRS = 5; SiS_Pr->PanelVRE = 5;
  1542. SiS_Pr->PanelVCLKIdx315 = VCLK_1280x720;
  1543. /* Data above for TMDS (projector); get from BIOS for LVDS */
  1544. SiS_GetLCDInfoBIOS(SiS_Pr);
  1545. break;
  1546. case Panel_1280x768: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 768;
  1547. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  1548. SiS_Pr->PanelHT = 1408; SiS_Pr->PanelVT = 806;
  1549. SiS_Pr->PanelVCLKIdx300 = VCLK81_300; /* ? */
  1550. SiS_Pr->PanelVCLKIdx315 = VCLK81_315; /* ? */
  1551. } else {
  1552. SiS_Pr->PanelHT = 1688; SiS_Pr->PanelVT = 802;
  1553. SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRS = 112;
  1554. SiS_Pr->PanelVRS = 3; SiS_Pr->PanelVRE = 6;
  1555. SiS_Pr->PanelVCLKIdx300 = VCLK81_300;
  1556. SiS_Pr->PanelVCLKIdx315 = VCLK81_315;
  1557. }
  1558. break;
  1559. case Panel_1280x768_2: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 768;
  1560. SiS_Pr->PanelHT = 1660; SiS_Pr->PanelVT = 806;
  1561. SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 112;
  1562. SiS_Pr->PanelVRS = 3; SiS_Pr->PanelVRE = 6;
  1563. SiS_Pr->PanelVCLKIdx315 = VCLK_1280x768_2;
  1564. SiS_GetLCDInfoBIOS(SiS_Pr);
  1565. break;
  1566. case Panel_1280x800: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 800;
  1567. SiS_Pr->PanelHT = 1408; SiS_Pr->PanelVT = 816;
  1568. SiS_Pr->PanelHRS = 21; SiS_Pr->PanelHRE = 24;
  1569. SiS_Pr->PanelVRS = 4; SiS_Pr->PanelVRE = 3;
  1570. SiS_Pr->PanelVCLKIdx315 = VCLK_1280x800_315;
  1571. SiS_GetLCDInfoBIOS(SiS_Pr);
  1572. break;
  1573. case Panel_1280x800_2: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 800;
  1574. SiS_Pr->PanelHT = 1552; SiS_Pr->PanelVT = 812;
  1575. SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 112;
  1576. SiS_Pr->PanelVRS = 4; SiS_Pr->PanelVRE = 3;
  1577. SiS_Pr->PanelVCLKIdx315 = VCLK_1280x800_315_2;
  1578. SiS_GetLCDInfoBIOS(SiS_Pr);
  1579. break;
  1580. case Panel_1280x854: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 854;
  1581. SiS_Pr->PanelHT = 1664; SiS_Pr->PanelVT = 861;
  1582. SiS_Pr->PanelHRS = 16; SiS_Pr->PanelHRE = 112;
  1583. SiS_Pr->PanelVRS = 1; SiS_Pr->PanelVRE = 3;
  1584. SiS_Pr->PanelVCLKIdx315 = VCLK_1280x854;
  1585. SiS_GetLCDInfoBIOS(SiS_Pr);
  1586. break;
  1587. case Panel_1280x960: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 960;
  1588. SiS_Pr->PanelHT = 1800; SiS_Pr->PanelVT = 1000;
  1589. SiS_Pr->PanelVCLKIdx300 = VCLK108_3_300;
  1590. SiS_Pr->PanelVCLKIdx315 = VCLK108_3_315;
  1591. if(resinfo == SIS_RI_1280x1024) {
  1592. SiS_Pr->PanelVCLKIdx300 = VCLK100_300;
  1593. SiS_Pr->PanelVCLKIdx315 = VCLK100_315;
  1594. }
  1595. break;
  1596. case Panel_1280x1024: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 1024;
  1597. SiS_Pr->PanelHT = 1688; SiS_Pr->PanelVT = 1066;
  1598. SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 112;
  1599. SiS_Pr->PanelVRS = 1; SiS_Pr->PanelVRE = 3;
  1600. SiS_Pr->PanelVCLKIdx300 = VCLK108_3_300;
  1601. SiS_Pr->PanelVCLKIdx315 = VCLK108_2_315;
  1602. SiS_GetLCDInfoBIOS(SiS_Pr);
  1603. break;
  1604. case Panel_1400x1050: SiS_Pr->PanelXRes = 1400; SiS_Pr->PanelYRes = 1050;
  1605. SiS_Pr->PanelHT = 1688; SiS_Pr->PanelVT = 1066;
  1606. SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 112;
  1607. SiS_Pr->PanelVRS = 1; SiS_Pr->PanelVRE = 3;
  1608. SiS_Pr->PanelVCLKIdx315 = VCLK108_2_315;
  1609. SiS_GetLCDInfoBIOS(SiS_Pr);
  1610. break;
  1611. case Panel_1600x1200: SiS_Pr->PanelXRes = 1600; SiS_Pr->PanelYRes = 1200;
  1612. SiS_Pr->PanelHT = 2160; SiS_Pr->PanelVT = 1250;
  1613. SiS_Pr->PanelHRS = 64; SiS_Pr->PanelHRE = 192;
  1614. SiS_Pr->PanelVRS = 1; SiS_Pr->PanelVRE = 3;
  1615. SiS_Pr->PanelVCLKIdx315 = VCLK162_315;
  1616. if(SiS_Pr->SiS_VBType & VB_SISTMDSLCDA) {
  1617. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  1618. SiS_Pr->PanelHT = 1760; SiS_Pr->PanelVT = 1235;
  1619. SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 32;
  1620. SiS_Pr->PanelVRS = 2; SiS_Pr->PanelVRE = 4;
  1621. SiS_Pr->PanelVCLKIdx315 = VCLK130_315;
  1622. SiS_Pr->Alternate1600x1200 = TRUE;
  1623. }
  1624. } else if(SiS_Pr->SiS_IF_DEF_LVDS) {
  1625. SiS_Pr->PanelHT = 2048; SiS_Pr->PanelVT = 1320;
  1626. SiS_Pr->PanelHRS = SiS_Pr->PanelHRE = 999;
  1627. SiS_Pr->PanelVRS = SiS_Pr->PanelVRE = 999;
  1628. }
  1629. SiS_GetLCDInfoBIOS(SiS_Pr);
  1630. break;
  1631. case Panel_1680x1050: SiS_Pr->PanelXRes = 1680; SiS_Pr->PanelYRes = 1050;
  1632. SiS_Pr->PanelHT = 1900; SiS_Pr->PanelVT = 1066;
  1633. SiS_Pr->PanelHRS = 26; SiS_Pr->PanelHRE = 76;
  1634. SiS_Pr->PanelVRS = 3; SiS_Pr->PanelVRE = 6;
  1635. SiS_Pr->PanelVCLKIdx315 = VCLK121_315;
  1636. SiS_GetLCDInfoBIOS(SiS_Pr);
  1637. break;
  1638. case Panel_Barco1366: SiS_Pr->PanelXRes = 1360; SiS_Pr->PanelYRes = 1024;
  1639. SiS_Pr->PanelHT = 1688; SiS_Pr->PanelVT = 1066;
  1640. break;
  1641. case Panel_848x480: SiS_Pr->PanelXRes = 848; SiS_Pr->PanelYRes = 480;
  1642. SiS_Pr->PanelHT = 1088; SiS_Pr->PanelVT = 525;
  1643. break;
  1644. case Panel_856x480: SiS_Pr->PanelXRes = 856; SiS_Pr->PanelYRes = 480;
  1645. SiS_Pr->PanelHT = 1088; SiS_Pr->PanelVT = 525;
  1646. break;
  1647. case Panel_Custom: SiS_Pr->PanelXRes = SiS_Pr->CP_MaxX;
  1648. SiS_Pr->PanelYRes = SiS_Pr->CP_MaxY;
  1649. SiS_Pr->PanelHT = SiS_Pr->CHTotal;
  1650. SiS_Pr->PanelVT = SiS_Pr->CVTotal;
  1651. if(SiS_Pr->CP_PreferredIndex != -1) {
  1652. SiS_Pr->PanelXRes = SiS_Pr->CP_HDisplay[SiS_Pr->CP_PreferredIndex];
  1653. SiS_Pr->PanelYRes = SiS_Pr->CP_VDisplay[SiS_Pr->CP_PreferredIndex];
  1654. SiS_Pr->PanelHT = SiS_Pr->CP_HTotal[SiS_Pr->CP_PreferredIndex];
  1655. SiS_Pr->PanelVT = SiS_Pr->CP_VTotal[SiS_Pr->CP_PreferredIndex];
  1656. SiS_Pr->PanelHRS = SiS_Pr->CP_HSyncStart[SiS_Pr->CP_PreferredIndex];
  1657. SiS_Pr->PanelHRE = SiS_Pr->CP_HSyncEnd[SiS_Pr->CP_PreferredIndex];
  1658. SiS_Pr->PanelVRS = SiS_Pr->CP_VSyncStart[SiS_Pr->CP_PreferredIndex];
  1659. SiS_Pr->PanelVRE = SiS_Pr->CP_VSyncEnd[SiS_Pr->CP_PreferredIndex];
  1660. SiS_Pr->PanelHRS -= SiS_Pr->PanelXRes;
  1661. SiS_Pr->PanelHRE -= SiS_Pr->PanelHRS;
  1662. SiS_Pr->PanelVRS -= SiS_Pr->PanelYRes;
  1663. SiS_Pr->PanelVRE -= SiS_Pr->PanelVRS;
  1664. if(SiS_Pr->CP_PrefClock) {
  1665. int idx;
  1666. SiS_Pr->PanelVCLKIdx315 = VCLK_CUSTOM_315;
  1667. SiS_Pr->PanelVCLKIdx300 = VCLK_CUSTOM_300;
  1668. if(SiS_Pr->ChipType < SIS_315H) idx = VCLK_CUSTOM_300;
  1669. else idx = VCLK_CUSTOM_315;
  1670. SiS_Pr->SiS_VCLKData[idx].CLOCK =
  1671. SiS_Pr->SiS_VBVCLKData[idx].CLOCK = SiS_Pr->CP_PrefClock;
  1672. SiS_Pr->SiS_VCLKData[idx].SR2B =
  1673. SiS_Pr->SiS_VBVCLKData[idx].Part4_A = SiS_Pr->CP_PrefSR2B;
  1674. SiS_Pr->SiS_VCLKData[idx].SR2C =
  1675. SiS_Pr->SiS_VBVCLKData[idx].Part4_B = SiS_Pr->CP_PrefSR2C;
  1676. }
  1677. }
  1678. break;
  1679. default: SiS_Pr->PanelXRes = 1024; SiS_Pr->PanelYRes = 768;
  1680. SiS_Pr->PanelHT = 1344; SiS_Pr->PanelVT = 806;
  1681. break;
  1682. }
  1683. /* Special cases */
  1684. if( (SiS_Pr->SiS_IF_DEF_FSTN) ||
  1685. (SiS_Pr->SiS_IF_DEF_DSTN) ||
  1686. (SiS_Pr->SiS_CustomT == CUT_BARCO1366) ||
  1687. (SiS_Pr->SiS_CustomT == CUT_BARCO1024) ||
  1688. (SiS_Pr->SiS_CustomT == CUT_PANEL848) ||
  1689. (SiS_Pr->SiS_CustomT == CUT_PANEL856) ) {
  1690. SiS_Pr->PanelHRS = 999;
  1691. SiS_Pr->PanelHRE = 999;
  1692. }
  1693. if( (SiS_Pr->SiS_CustomT == CUT_BARCO1366) ||
  1694. (SiS_Pr->SiS_CustomT == CUT_BARCO1024) ||
  1695. (SiS_Pr->SiS_CustomT == CUT_PANEL848) ||
  1696. (SiS_Pr->SiS_CustomT == CUT_PANEL856) ) {
  1697. SiS_Pr->PanelVRS = 999;
  1698. SiS_Pr->PanelVRE = 999;
  1699. }
  1700. /* DontExpand overrule */
  1701. if((SiS_Pr->SiS_VBType & VB_SISVB) && (!(SiS_Pr->SiS_VBType & VB_NoLCD))) {
  1702. if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && (modeflag & NoSupportLCDScale)) {
  1703. /* No scaling for this mode on any panel (LCD=CRT2)*/
  1704. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1705. }
  1706. switch(SiS_Pr->SiS_LCDResInfo) {
  1707. case Panel_Custom:
  1708. case Panel_1152x864:
  1709. case Panel_1280x768: /* TMDS only */
  1710. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1711. break;
  1712. case Panel_800x600: {
  1713. static const unsigned char nonscalingmodes[] = {
  1714. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, 0xff
  1715. };
  1716. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1717. break;
  1718. }
  1719. case Panel_1024x768: {
  1720. static const unsigned char nonscalingmodes[] = {
  1721. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1722. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1723. 0xff
  1724. };
  1725. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1726. break;
  1727. }
  1728. case Panel_1280x720: {
  1729. static const unsigned char nonscalingmodes[] = {
  1730. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1731. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1732. 0xff
  1733. };
  1734. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1735. if(SiS_Pr->PanelHT == 1650) {
  1736. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1737. }
  1738. break;
  1739. }
  1740. case Panel_1280x768_2: { /* LVDS only */
  1741. static const unsigned char nonscalingmodes[] = {
  1742. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1743. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1744. SIS_RI_1152x768,0xff
  1745. };
  1746. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1747. switch(resinfo) {
  1748. case SIS_RI_1280x720: if(SiS_Pr->UsePanelScaler == -1) {
  1749. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1750. }
  1751. break;
  1752. }
  1753. break;
  1754. }
  1755. case Panel_1280x800: { /* SiS TMDS special (Averatec 6200 series) */
  1756. static const unsigned char nonscalingmodes[] = {
  1757. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1758. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1759. SIS_RI_1152x768,SIS_RI_1280x720,SIS_RI_1280x768,0xff
  1760. };
  1761. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1762. break;
  1763. }
  1764. case Panel_1280x800_2: { /* SiS LVDS */
  1765. static const unsigned char nonscalingmodes[] = {
  1766. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1767. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1768. SIS_RI_1152x768,0xff
  1769. };
  1770. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1771. switch(resinfo) {
  1772. case SIS_RI_1280x720:
  1773. case SIS_RI_1280x768: if(SiS_Pr->UsePanelScaler == -1) {
  1774. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1775. }
  1776. break;
  1777. }
  1778. break;
  1779. }
  1780. case Panel_1280x854: { /* SiS LVDS */
  1781. static const unsigned char nonscalingmodes[] = {
  1782. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1783. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1784. SIS_RI_1152x768,0xff
  1785. };
  1786. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1787. switch(resinfo) {
  1788. case SIS_RI_1280x720:
  1789. case SIS_RI_1280x768:
  1790. case SIS_RI_1280x800: if(SiS_Pr->UsePanelScaler == -1) {
  1791. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1792. }
  1793. break;
  1794. }
  1795. break;
  1796. }
  1797. case Panel_1280x960: {
  1798. static const unsigned char nonscalingmodes[] = {
  1799. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1800. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1801. SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x720,SIS_RI_1280x768,SIS_RI_1280x800,
  1802. SIS_RI_1280x854,0xff
  1803. };
  1804. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1805. break;
  1806. }
  1807. case Panel_1280x1024: {
  1808. static const unsigned char nonscalingmodes[] = {
  1809. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1810. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1811. SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x720,SIS_RI_1280x768,SIS_RI_1280x800,
  1812. SIS_RI_1280x854,SIS_RI_1280x960,0xff
  1813. };
  1814. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1815. break;
  1816. }
  1817. case Panel_1400x1050: {
  1818. static const unsigned char nonscalingmodes[] = {
  1819. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1820. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1821. SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x768,SIS_RI_1280x800,SIS_RI_1280x854,
  1822. SIS_RI_1280x960,0xff
  1823. };
  1824. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1825. switch(resinfo) {
  1826. case SIS_RI_1280x720: if(SiS_Pr->UsePanelScaler == -1) {
  1827. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1828. }
  1829. break;
  1830. case SIS_RI_1280x1024: SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1831. break;
  1832. }
  1833. break;
  1834. }
  1835. case Panel_1600x1200: {
  1836. static const unsigned char nonscalingmodes[] = {
  1837. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1838. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1839. SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x720,SIS_RI_1280x768,SIS_RI_1280x800,
  1840. SIS_RI_1280x854,SIS_RI_1280x960,SIS_RI_1360x768,SIS_RI_1360x1024,0xff
  1841. };
  1842. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1843. break;
  1844. }
  1845. case Panel_1680x1050: {
  1846. static const unsigned char nonscalingmodes[] = {
  1847. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1848. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1849. SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x854,SIS_RI_1280x960,SIS_RI_1360x768,
  1850. SIS_RI_1360x1024,0xff
  1851. };
  1852. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1853. break;
  1854. }
  1855. }
  1856. }
  1857. #ifdef SIS300
  1858. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  1859. if(SiS_Pr->SiS_CustomT == CUT_PANEL848 || SiS_Pr->SiS_CustomT == CUT_PANEL856) {
  1860. SiS_Pr->SiS_LCDInfo = 0x80 | 0x40 | 0x20; /* neg h/v sync, RGB24(D0 = 0) */
  1861. }
  1862. }
  1863. if(SiS_Pr->ChipType < SIS_315H) {
  1864. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  1865. if(SiS_Pr->SiS_UseROM) {
  1866. if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) {
  1867. if(!(ROMAddr[0x235] & 0x02)) {
  1868. SiS_Pr->SiS_LCDInfo &= (~DontExpandLCD);
  1869. }
  1870. }
  1871. }
  1872. } else if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  1873. if((SiS_Pr->SiS_SetFlag & SetDOSMode) && ((ModeNo == 0x03) || (ModeNo == 0x10))) {
  1874. SiS_Pr->SiS_LCDInfo &= (~DontExpandLCD);
  1875. }
  1876. }
  1877. }
  1878. #endif
  1879. /* Special cases */
  1880. if(modexres == SiS_Pr->PanelXRes && modeyres == SiS_Pr->PanelYRes) {
  1881. SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  1882. }
  1883. if(SiS_Pr->SiS_IF_DEF_TRUMPION) {
  1884. SiS_Pr->SiS_LCDInfo |= (DontExpandLCD | LCDPass11);
  1885. }
  1886. switch(SiS_Pr->SiS_LCDResInfo) {
  1887. case Panel_640x480:
  1888. SiS_Pr->SiS_LCDInfo |= (DontExpandLCD | LCDPass11);
  1889. break;
  1890. case Panel_1280x800:
  1891. /* Don't pass 1:1 by default (TMDS special) */
  1892. if(SiS_Pr->CenterScreen == -1) SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  1893. break;
  1894. case Panel_1280x960:
  1895. SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  1896. break;
  1897. case Panel_Custom:
  1898. if((!SiS_Pr->CP_PrefClock) ||
  1899. (modexres > SiS_Pr->PanelXRes) || (modeyres > SiS_Pr->PanelYRes)) {
  1900. SiS_Pr->SiS_LCDInfo |= LCDPass11;
  1901. }
  1902. break;
  1903. }
  1904. if((SiS_Pr->UseCustomMode) || (SiS_Pr->SiS_CustomT == CUT_UNKNOWNLCD)) {
  1905. SiS_Pr->SiS_LCDInfo |= (DontExpandLCD | LCDPass11);
  1906. }
  1907. /* (In)validate LCDPass11 flag */
  1908. if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
  1909. SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  1910. }
  1911. /* LVDS DDA */
  1912. if(!((SiS_Pr->ChipType < SIS_315H) && (SiS_Pr->SiS_SetFlag & SetDOSMode))) {
  1913. if((SiS_Pr->SiS_IF_DEF_LVDS == 1) || (SiS_Pr->SiS_VBType & VB_NoLCD)) {
  1914. if(SiS_Pr->SiS_IF_DEF_TRUMPION == 0) {
  1915. if(ModeNo == 0x12) {
  1916. if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
  1917. SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
  1918. }
  1919. } else if(ModeNo > 0x13) {
  1920. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x600) {
  1921. if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
  1922. if((resinfo == SIS_RI_800x600) || (resinfo == SIS_RI_400x300)) {
  1923. SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
  1924. }
  1925. }
  1926. }
  1927. }
  1928. }
  1929. }
  1930. if(modeflag & HalfDCLK) {
  1931. if(SiS_Pr->SiS_IF_DEF_TRUMPION == 1) {
  1932. SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
  1933. } else if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  1934. SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
  1935. } else if(SiS_Pr->SiS_LCDResInfo == Panel_640x480) {
  1936. SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
  1937. } else if(ModeNo > 0x13) {
  1938. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  1939. if(resinfo == SIS_RI_512x384) SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
  1940. } else if(SiS_Pr->SiS_LCDResInfo == Panel_800x600) {
  1941. if(resinfo == SIS_RI_400x300) SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
  1942. }
  1943. }
  1944. }
  1945. }
  1946. /* VESA timing */
  1947. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  1948. if(SiS_Pr->SiS_VBInfo & SetNotSimuMode) {
  1949. SiS_Pr->SiS_SetFlag |= LCDVESATiming;
  1950. }
  1951. } else {
  1952. SiS_Pr->SiS_SetFlag |= LCDVESATiming;
  1953. }
  1954. #ifdef SIS_LINUX_KERNEL
  1955. #if 0
  1956. printk(KERN_DEBUG "sisfb: (LCDInfo=0x%04x LCDResInfo=0x%02x LCDTypeInfo=0x%02x)\n",
  1957. SiS_Pr->SiS_LCDInfo, SiS_Pr->SiS_LCDResInfo, SiS_Pr->SiS_LCDTypeInfo);
  1958. #endif
  1959. #endif
  1960. #ifdef SIS_XORG_XF86
  1961. xf86DrvMsgVerb(0, X_PROBED, 4,
  1962. "(init301: LCDInfo=0x%04x LCDResInfo=0x%02x LCDTypeInfo=0x%02x SetFlag=0x%04x)\n",
  1963. SiS_Pr->SiS_LCDInfo, SiS_Pr->SiS_LCDResInfo, SiS_Pr->SiS_LCDTypeInfo, SiS_Pr->SiS_SetFlag);
  1964. #endif
  1965. }
  1966. /*********************************************/
  1967. /* GET VCLK */
  1968. /*********************************************/
  1969. unsigned short
  1970. SiS_GetVCLK2Ptr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  1971. unsigned short RefreshRateTableIndex)
  1972. {
  1973. unsigned short CRT2Index, VCLKIndex = 0, VCLKIndexGEN = 0, VCLKIndexGENCRT = 0;
  1974. unsigned short modeflag, resinfo, tempbx;
  1975. const unsigned char *CHTVVCLKPtr = NULL;
  1976. if(ModeNo <= 0x13) {
  1977. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  1978. resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
  1979. CRT2Index = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  1980. VCLKIndexGEN = (SiS_GetRegByte((SiS_Pr->SiS_P3ca+0x02)) >> 2) & 0x03;
  1981. VCLKIndexGENCRT = VCLKIndexGEN;
  1982. } else {
  1983. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  1984. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  1985. CRT2Index = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  1986. VCLKIndexGEN = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
  1987. VCLKIndexGENCRT = SiS_GetRefCRTVCLK(SiS_Pr, RefreshRateTableIndex,
  1988. (SiS_Pr->SiS_SetFlag & ProgrammingCRT2) ? SiS_Pr->SiS_UseWideCRT2 : SiS_Pr->SiS_UseWide);
  1989. }
  1990. if(SiS_Pr->SiS_VBType & VB_SISVB) { /* 30x/B/LV */
  1991. if(SiS_Pr->SiS_SetFlag & ProgrammingCRT2) {
  1992. CRT2Index >>= 6;
  1993. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { /* LCD */
  1994. if(SiS_Pr->ChipType < SIS_315H) {
  1995. VCLKIndex = SiS_Pr->PanelVCLKIdx300;
  1996. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  1997. VCLKIndex = VCLKIndexGEN;
  1998. }
  1999. } else {
  2000. VCLKIndex = SiS_Pr->PanelVCLKIdx315;
  2001. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  2002. switch(resinfo) {
  2003. /* Correct those whose IndexGEN doesn't match VBVCLK array */
  2004. case SIS_RI_720x480: VCLKIndex = VCLK_720x480; break;
  2005. case SIS_RI_720x576: VCLKIndex = VCLK_720x576; break;
  2006. case SIS_RI_768x576: VCLKIndex = VCLK_768x576; break;
  2007. case SIS_RI_848x480: VCLKIndex = VCLK_848x480; break;
  2008. case SIS_RI_856x480: VCLKIndex = VCLK_856x480; break;
  2009. case SIS_RI_800x480: VCLKIndex = VCLK_800x480; break;
  2010. case SIS_RI_1024x576: VCLKIndex = VCLK_1024x576; break;
  2011. case SIS_RI_1152x864: VCLKIndex = VCLK_1152x864; break;
  2012. case SIS_RI_1280x720: VCLKIndex = VCLK_1280x720; break;
  2013. case SIS_RI_1360x768: VCLKIndex = VCLK_1360x768; break;
  2014. default: VCLKIndex = VCLKIndexGEN;
  2015. }
  2016. if(ModeNo <= 0x13) {
  2017. if(SiS_Pr->ChipType <= SIS_315PRO) {
  2018. if(SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC == 1) VCLKIndex = 0x42;
  2019. } else {
  2020. if(SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC == 1) VCLKIndex = 0x00;
  2021. }
  2022. }
  2023. if(SiS_Pr->ChipType <= SIS_315PRO) {
  2024. if(VCLKIndex == 0) VCLKIndex = 0x41;
  2025. if(VCLKIndex == 1) VCLKIndex = 0x43;
  2026. if(VCLKIndex == 4) VCLKIndex = 0x44;
  2027. }
  2028. }
  2029. }
  2030. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { /* TV */
  2031. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  2032. if(SiS_Pr->SiS_TVMode & TVRPLLDIV2XO) VCLKIndex = HiTVVCLKDIV2;
  2033. else VCLKIndex = HiTVVCLK;
  2034. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) VCLKIndex = HiTVSimuVCLK;
  2035. } else if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) VCLKIndex = YPbPr750pVCLK;
  2036. else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) VCLKIndex = TVVCLKDIV2;
  2037. else if(SiS_Pr->SiS_TVMode & TVRPLLDIV2XO) VCLKIndex = TVVCLKDIV2;
  2038. else VCLKIndex = TVVCLK;
  2039. if(SiS_Pr->ChipType < SIS_315H) VCLKIndex += TVCLKBASE_300;
  2040. else VCLKIndex += TVCLKBASE_315;
  2041. } else { /* VGA2 */
  2042. VCLKIndex = VCLKIndexGENCRT;
  2043. if(SiS_Pr->ChipType < SIS_315H) {
  2044. if(ModeNo > 0x13) {
  2045. if( (SiS_Pr->ChipType == SIS_630) &&
  2046. (SiS_Pr->ChipRevision >= 0x30)) {
  2047. if(VCLKIndex == 0x14) VCLKIndex = 0x34;
  2048. }
  2049. /* Better VGA2 clock for 1280x1024@75 */
  2050. if(VCLKIndex == 0x17) VCLKIndex = 0x45;
  2051. }
  2052. }
  2053. }
  2054. } else { /* If not programming CRT2 */
  2055. VCLKIndex = VCLKIndexGENCRT;
  2056. if(SiS_Pr->ChipType < SIS_315H) {
  2057. if(ModeNo > 0x13) {
  2058. if( (SiS_Pr->ChipType != SIS_630) &&
  2059. (SiS_Pr->ChipType != SIS_300) ) {
  2060. if(VCLKIndex == 0x1b) VCLKIndex = 0x48;
  2061. }
  2062. }
  2063. }
  2064. }
  2065. } else { /* LVDS */
  2066. VCLKIndex = CRT2Index;
  2067. if(SiS_Pr->SiS_SetFlag & ProgrammingCRT2) {
  2068. if( (SiS_Pr->SiS_IF_DEF_CH70xx != 0) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV) ) {
  2069. VCLKIndex &= 0x1f;
  2070. tempbx = 0;
  2071. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx += 1;
  2072. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  2073. tempbx += 2;
  2074. if(SiS_Pr->SiS_ModeType > ModeVGA) {
  2075. if(SiS_Pr->SiS_CHSOverScan) tempbx = 8;
  2076. }
  2077. if(SiS_Pr->SiS_TVMode & TVSetPALM) {
  2078. tempbx = 4;
  2079. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx += 1;
  2080. } else if(SiS_Pr->SiS_TVMode & TVSetPALN) {
  2081. tempbx = 6;
  2082. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx += 1;
  2083. }
  2084. }
  2085. switch(tempbx) {
  2086. case 0: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKUNTSC; break;
  2087. case 1: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKONTSC; break;
  2088. case 2: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKUPAL; break;
  2089. case 3: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKOPAL; break;
  2090. case 4: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKUPALM; break;
  2091. case 5: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKOPALM; break;
  2092. case 6: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKUPALN; break;
  2093. case 7: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKOPALN; break;
  2094. case 8: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKSOPAL; break;
  2095. default: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKOPAL; break;
  2096. }
  2097. VCLKIndex = CHTVVCLKPtr[VCLKIndex];
  2098. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  2099. if(SiS_Pr->ChipType < SIS_315H) {
  2100. VCLKIndex = SiS_Pr->PanelVCLKIdx300;
  2101. } else {
  2102. VCLKIndex = SiS_Pr->PanelVCLKIdx315;
  2103. }
  2104. #ifdef SIS300
  2105. /* Special Timing: Barco iQ Pro R series */
  2106. if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) VCLKIndex = 0x44;
  2107. /* Special Timing: 848x480 and 856x480 parallel lvds panels */
  2108. if(SiS_Pr->SiS_CustomT == CUT_PANEL848 || SiS_Pr->SiS_CustomT == CUT_PANEL856) {
  2109. if(SiS_Pr->ChipType < SIS_315H) {
  2110. VCLKIndex = VCLK34_300;
  2111. /* if(resinfo == SIS_RI_1360x768) VCLKIndex = ?; */
  2112. } else {
  2113. VCLKIndex = VCLK34_315;
  2114. /* if(resinfo == SIS_RI_1360x768) VCLKIndex = ?; */
  2115. }
  2116. }
  2117. #endif
  2118. } else {
  2119. VCLKIndex = VCLKIndexGENCRT;
  2120. if(SiS_Pr->ChipType < SIS_315H) {
  2121. if(ModeNo > 0x13) {
  2122. if( (SiS_Pr->ChipType == SIS_630) &&
  2123. (SiS_Pr->ChipRevision >= 0x30) ) {
  2124. if(VCLKIndex == 0x14) VCLKIndex = 0x2e;
  2125. }
  2126. }
  2127. }
  2128. }
  2129. } else { /* if not programming CRT2 */
  2130. VCLKIndex = VCLKIndexGENCRT;
  2131. if(SiS_Pr->ChipType < SIS_315H) {
  2132. if(ModeNo > 0x13) {
  2133. if( (SiS_Pr->ChipType != SIS_630) &&
  2134. (SiS_Pr->ChipType != SIS_300) ) {
  2135. if(VCLKIndex == 0x1b) VCLKIndex = 0x48;
  2136. }
  2137. #if 0
  2138. if(SiS_Pr->ChipType == SIS_730) {
  2139. if(VCLKIndex == 0x0b) VCLKIndex = 0x40; /* 1024x768-70 */
  2140. if(VCLKIndex == 0x0d) VCLKIndex = 0x41; /* 1024x768-75 */
  2141. }
  2142. #endif
  2143. }
  2144. }
  2145. }
  2146. }
  2147. #ifdef SIS_XORG_XF86
  2148. #ifdef TWDEBUG
  2149. xf86DrvMsg(0, X_INFO, "VCLKIndex %d (0x%x)\n", VCLKIndex, VCLKIndex);
  2150. #endif
  2151. #endif
  2152. return VCLKIndex;
  2153. }
  2154. /*********************************************/
  2155. /* SET CRT2 MODE TYPE REGISTERS */
  2156. /*********************************************/
  2157. static void
  2158. SiS_SetCRT2ModeRegs(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  2159. {
  2160. unsigned short i, j, modeflag, tempah=0;
  2161. short tempcl;
  2162. #if defined(SIS300) || defined(SIS315H)
  2163. unsigned short tempbl;
  2164. #endif
  2165. #ifdef SIS315H
  2166. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  2167. unsigned short tempah2, tempbl2;
  2168. #endif
  2169. modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
  2170. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  2171. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x00,0xAF,0x40);
  2172. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2E,0xF7);
  2173. } else {
  2174. for(i=0,j=4; i<3; i++,j++) SiS_SetReg(SiS_Pr->SiS_Part1Port,j,0);
  2175. if(SiS_Pr->ChipType >= SIS_315H) {
  2176. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x02,0x7F);
  2177. }
  2178. tempcl = SiS_Pr->SiS_ModeType;
  2179. if(SiS_Pr->ChipType < SIS_315H) {
  2180. #ifdef SIS300 /* ---- 300 series ---- */
  2181. /* For 301BDH: (with LCD via LVDS) */
  2182. if(SiS_Pr->SiS_VBType & VB_NoLCD) {
  2183. tempbl = SiS_GetReg(SiS_Pr->SiS_P3c4,0x32);
  2184. tempbl &= 0xef;
  2185. tempbl |= 0x02;
  2186. if((SiS_Pr->SiS_VBInfo & SetCRT2ToTV) || (SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) {
  2187. tempbl |= 0x10;
  2188. tempbl &= 0xfd;
  2189. }
  2190. SiS_SetReg(SiS_Pr->SiS_P3c4,0x32,tempbl);
  2191. }
  2192. if(ModeNo > 0x13) {
  2193. tempcl -= ModeVGA;
  2194. if(tempcl >= 0) {
  2195. tempah = ((0x10 >> tempcl) | 0x80);
  2196. }
  2197. } else tempah = 0x80;
  2198. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) tempah ^= 0xA0;
  2199. #endif /* SIS300 */
  2200. } else {
  2201. #ifdef SIS315H /* ------- 315/330 series ------ */
  2202. if(ModeNo > 0x13) {
  2203. tempcl -= ModeVGA;
  2204. if(tempcl >= 0) {
  2205. tempah = (0x08 >> tempcl);
  2206. if (tempah == 0) tempah = 1;
  2207. tempah |= 0x40;
  2208. }
  2209. } else tempah = 0x40;
  2210. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) tempah ^= 0x50;
  2211. #endif /* SIS315H */
  2212. }
  2213. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 0;
  2214. if(SiS_Pr->ChipType < SIS_315H) {
  2215. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,tempah);
  2216. } else {
  2217. #ifdef SIS315H
  2218. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  2219. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x00,0xa0,tempah);
  2220. } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
  2221. if(IS_SIS740) {
  2222. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,tempah);
  2223. } else {
  2224. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x00,0xa0,tempah);
  2225. }
  2226. }
  2227. #endif
  2228. }
  2229. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  2230. tempah = 0x01;
  2231. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  2232. tempah |= 0x02;
  2233. }
  2234. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) {
  2235. tempah ^= 0x05;
  2236. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) {
  2237. tempah ^= 0x01;
  2238. }
  2239. }
  2240. if(SiS_Pr->ChipType < SIS_315H) {
  2241. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 0;
  2242. tempah = (tempah << 5) & 0xFF;
  2243. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x01,tempah);
  2244. tempah = (tempah >> 5) & 0xFF;
  2245. } else {
  2246. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 0x08;
  2247. else if(!(SiS_IsDualEdge(SiS_Pr))) tempah |= 0x08;
  2248. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2E,0xF0,tempah);
  2249. tempah &= ~0x08;
  2250. }
  2251. if((SiS_Pr->SiS_ModeType == ModeVGA) && (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode))) {
  2252. tempah |= 0x10;
  2253. }
  2254. tempah |= 0x80;
  2255. if(SiS_Pr->SiS_VBType & VB_SIS301) {
  2256. if(SiS_Pr->PanelXRes < 1280 && SiS_Pr->PanelYRes < 960) tempah &= ~0x80;
  2257. }
  2258. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  2259. if(!(SiS_Pr->SiS_TVMode & (TVSetYPbPr750p | TVSetYPbPr525p))) {
  2260. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  2261. tempah |= 0x20;
  2262. }
  2263. }
  2264. }
  2265. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x0D,0x40,tempah);
  2266. tempah = 0x80;
  2267. if(SiS_Pr->SiS_VBType & VB_SIS301) {
  2268. if(SiS_Pr->PanelXRes < 1280 && SiS_Pr->PanelYRes < 960) tempah = 0;
  2269. }
  2270. if(SiS_IsDualLink(SiS_Pr)) tempah |= 0x40;
  2271. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  2272. if(SiS_Pr->SiS_TVMode & TVRPLLDIV2XO) {
  2273. tempah |= 0x40;
  2274. }
  2275. }
  2276. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0C,tempah);
  2277. } else { /* LVDS */
  2278. if(SiS_Pr->ChipType >= SIS_315H) {
  2279. #ifdef SIS315H
  2280. /* LVDS can only be slave in 8bpp modes */
  2281. tempah = 0x80;
  2282. if((modeflag & CRT2Mode) && (SiS_Pr->SiS_ModeType > ModeVGA)) {
  2283. if(SiS_Pr->SiS_VBInfo & DriverMode) {
  2284. tempah |= 0x02;
  2285. }
  2286. }
  2287. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) tempah |= 0x02;
  2288. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) tempah ^= 0x01;
  2289. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 1;
  2290. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2e,0xF0,tempah);
  2291. #endif
  2292. } else {
  2293. #ifdef SIS300
  2294. tempah = 0;
  2295. if( (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) && (SiS_Pr->SiS_ModeType > ModeVGA) ) {
  2296. tempah |= 0x02;
  2297. }
  2298. tempah <<= 5;
  2299. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 0;
  2300. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x01,tempah);
  2301. #endif
  2302. }
  2303. }
  2304. } /* LCDA */
  2305. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  2306. if(SiS_Pr->ChipType >= SIS_315H) {
  2307. #ifdef SIS315H
  2308. /* unsigned char bridgerev = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x01); */
  2309. /* The following is nearly unpreditable and varies from machine
  2310. * to machine. Especially the 301DH seems to be a real trouble
  2311. * maker. Some BIOSes simply set the registers (like in the
  2312. * NoLCD-if-statements here), some set them according to the
  2313. * LCDA stuff. It is very likely that some machines are not
  2314. * treated correctly in the following, very case-orientated
  2315. * code. What do I do then...?
  2316. */
  2317. /* 740 variants match for 30xB, 301B-DH, 30xLV */
  2318. if(!(IS_SIS740)) {
  2319. tempah = 0x04; /* For all bridges */
  2320. tempbl = 0xfb;
  2321. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  2322. tempah = 0x00;
  2323. if(SiS_IsDualEdge(SiS_Pr)) {
  2324. tempbl = 0xff;
  2325. }
  2326. }
  2327. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,tempbl,tempah);
  2328. }
  2329. /* The following two are responsible for eventually wrong colors
  2330. * in TV output. The DH (VB_NoLCD) conditions are unknown; the
  2331. * b0 was found in some 651 machine (Pim; P4_23=0xe5); the b1 version
  2332. * in a 650 box (Jake). What is the criteria?
  2333. * Addendum: Another combination 651+301B-DH(b1) (Rapo) needs same
  2334. * treatment like the 651+301B-DH(b0) case. Seems more to be the
  2335. * chipset than the bridge revision.
  2336. */
  2337. if((IS_SIS740) || (SiS_Pr->ChipType >= SIS_661) || (SiS_Pr->SiS_ROMNew)) {
  2338. tempah = 0x30;
  2339. tempbl = 0xc0;
  2340. if((SiS_Pr->SiS_VBInfo & DisableCRT2Display) ||
  2341. ((SiS_Pr->SiS_ROMNew) && (!(ROMAddr[0x5b] & 0x04)))) {
  2342. tempah = 0x00;
  2343. tempbl = 0x00;
  2344. }
  2345. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2c,0xcf,tempah);
  2346. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x21,0x3f,tempbl);
  2347. } else if(SiS_Pr->SiS_VBType & VB_SIS301) {
  2348. /* Fixes "TV-blue-bug" on 315+301 */
  2349. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2c,0xcf); /* For 301 */
  2350. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x21,0x3f);
  2351. } else if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  2352. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2c,0x30); /* For 30xLV */
  2353. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x21,0xc0);
  2354. } else if(SiS_Pr->SiS_VBType & VB_NoLCD) { /* For 301B-DH */
  2355. tempah = 0x30; tempah2 = 0xc0;
  2356. tempbl = 0xcf; tempbl2 = 0x3f;
  2357. if(SiS_Pr->SiS_TVBlue == 0) {
  2358. tempah = tempah2 = 0x00;
  2359. } else if(SiS_Pr->SiS_TVBlue == -1) {
  2360. /* Set on 651/M650, clear on 315/650 */
  2361. if(!(IS_SIS65x)) /* (bridgerev != 0xb0) */ {
  2362. tempah = tempah2 = 0x00;
  2363. }
  2364. }
  2365. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2c,tempbl,tempah);
  2366. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x21,tempbl2,tempah2);
  2367. } else {
  2368. tempah = 0x30; tempah2 = 0xc0; /* For 30xB, 301C */
  2369. tempbl = 0xcf; tempbl2 = 0x3f;
  2370. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  2371. tempah = tempah2 = 0x00;
  2372. if(SiS_IsDualEdge(SiS_Pr)) {
  2373. tempbl = tempbl2 = 0xff;
  2374. }
  2375. }
  2376. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2c,tempbl,tempah);
  2377. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x21,tempbl2,tempah2);
  2378. }
  2379. if(IS_SIS740) {
  2380. tempah = 0x80;
  2381. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 0x00;
  2382. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x23,0x7f,tempah);
  2383. } else {
  2384. tempah = 0x00;
  2385. tempbl = 0x7f;
  2386. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  2387. tempbl = 0xff;
  2388. if(!(SiS_IsDualEdge(SiS_Pr))) tempah = 0x80;
  2389. }
  2390. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x23,tempbl,tempah);
  2391. }
  2392. #endif /* SIS315H */
  2393. } else if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  2394. #ifdef SIS300
  2395. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x21,0x3f);
  2396. if((SiS_Pr->SiS_VBInfo & DisableCRT2Display) ||
  2397. ((SiS_Pr->SiS_VBType & VB_NoLCD) &&
  2398. (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD))) {
  2399. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x23,0x7F);
  2400. } else {
  2401. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x23,0x80);
  2402. }
  2403. #endif
  2404. }
  2405. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  2406. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x0D,0x80);
  2407. if(SiS_Pr->SiS_VBType & VB_SIS30xCLV) {
  2408. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x3A,0xC0);
  2409. }
  2410. }
  2411. } else { /* LVDS */
  2412. #ifdef SIS315H
  2413. if(SiS_Pr->ChipType >= SIS_315H) {
  2414. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  2415. tempah = 0x04;
  2416. tempbl = 0xfb;
  2417. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  2418. tempah = 0x00;
  2419. if(SiS_IsDualEdge(SiS_Pr)) tempbl = 0xff;
  2420. }
  2421. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,tempbl,tempah);
  2422. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) {
  2423. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xfb);
  2424. }
  2425. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2c,0x30);
  2426. } else if(SiS_Pr->ChipType == SIS_550) {
  2427. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xfb);
  2428. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2c,0x30);
  2429. }
  2430. }
  2431. #endif
  2432. }
  2433. }
  2434. /*********************************************/
  2435. /* GET RESOLUTION DATA */
  2436. /*********************************************/
  2437. unsigned short
  2438. SiS_GetResInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  2439. {
  2440. if(ModeNo <= 0x13)
  2441. return ((unsigned short)SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo);
  2442. else
  2443. return ((unsigned short)SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO);
  2444. }
  2445. static void
  2446. SiS_GetCRT2ResInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  2447. {
  2448. unsigned short xres, yres, modeflag=0, resindex;
  2449. if(SiS_Pr->UseCustomMode) {
  2450. xres = SiS_Pr->CHDisplay;
  2451. if(SiS_Pr->CModeFlag & HalfDCLK) xres <<= 1;
  2452. SiS_Pr->SiS_VGAHDE = SiS_Pr->SiS_HDE = xres;
  2453. /* DoubleScanMode-check done in CheckCalcCustomMode()! */
  2454. SiS_Pr->SiS_VGAVDE = SiS_Pr->SiS_VDE = SiS_Pr->CVDisplay;
  2455. return;
  2456. }
  2457. resindex = SiS_GetResInfo(SiS_Pr,ModeNo,ModeIdIndex);
  2458. if(ModeNo <= 0x13) {
  2459. xres = SiS_Pr->SiS_StResInfo[resindex].HTotal;
  2460. yres = SiS_Pr->SiS_StResInfo[resindex].VTotal;
  2461. } else {
  2462. xres = SiS_Pr->SiS_ModeResInfo[resindex].HTotal;
  2463. yres = SiS_Pr->SiS_ModeResInfo[resindex].VTotal;
  2464. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  2465. }
  2466. if(!SiS_Pr->SiS_IF_DEF_DSTN && !SiS_Pr->SiS_IF_DEF_FSTN) {
  2467. if((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->SiS_IF_DEF_LVDS == 1)) {
  2468. if((ModeNo != 0x03) && (SiS_Pr->SiS_SetFlag & SetDOSMode)) {
  2469. if(yres == 350) yres = 400;
  2470. }
  2471. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x3a) & 0x01) {
  2472. if(ModeNo == 0x12) yres = 400;
  2473. }
  2474. }
  2475. if(modeflag & HalfDCLK) xres <<= 1;
  2476. if(modeflag & DoubleScanMode) yres <<= 1;
  2477. }
  2478. if((SiS_Pr->SiS_VBType & VB_SISVB) && (!(SiS_Pr->SiS_VBType & VB_NoLCD))) {
  2479. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  2480. switch(SiS_Pr->SiS_LCDResInfo) {
  2481. case Panel_1024x768:
  2482. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
  2483. if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
  2484. if(yres == 350) yres = 357;
  2485. if(yres == 400) yres = 420;
  2486. if(yres == 480) yres = 525;
  2487. }
  2488. }
  2489. break;
  2490. case Panel_1280x1024:
  2491. if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
  2492. /* BIOS bug - does this regardless of scaling */
  2493. if(yres == 400) yres = 405;
  2494. }
  2495. if(yres == 350) yres = 360;
  2496. if(SiS_Pr->SiS_SetFlag & LCDVESATiming) {
  2497. if(yres == 360) yres = 375;
  2498. }
  2499. break;
  2500. case Panel_1600x1200:
  2501. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
  2502. if(yres == 1024) yres = 1056;
  2503. }
  2504. break;
  2505. }
  2506. }
  2507. } else {
  2508. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  2509. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToHiVision)) {
  2510. if(xres == 720) xres = 640;
  2511. }
  2512. } else if(xres == 720) xres = 640;
  2513. if(SiS_Pr->SiS_SetFlag & SetDOSMode) {
  2514. yres = 400;
  2515. if(SiS_Pr->ChipType >= SIS_315H) {
  2516. if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x17) & 0x80) yres = 480;
  2517. } else {
  2518. if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x80) yres = 480;
  2519. }
  2520. if(SiS_Pr->SiS_IF_DEF_DSTN || SiS_Pr->SiS_IF_DEF_FSTN) yres = 480;
  2521. }
  2522. }
  2523. SiS_Pr->SiS_VGAHDE = SiS_Pr->SiS_HDE = xres;
  2524. SiS_Pr->SiS_VGAVDE = SiS_Pr->SiS_VDE = yres;
  2525. }
  2526. /*********************************************/
  2527. /* GET CRT2 TIMING DATA */
  2528. /*********************************************/
  2529. static void
  2530. SiS_GetCRT2Ptr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  2531. unsigned short RefreshRateTableIndex, unsigned short *CRT2Index,
  2532. unsigned short *ResIndex)
  2533. {
  2534. unsigned short tempbx=0, tempal=0, resinfo=0;
  2535. if(ModeNo <= 0x13) {
  2536. tempal = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  2537. } else {
  2538. tempal = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  2539. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  2540. }
  2541. if((SiS_Pr->SiS_VBType & VB_SISVB) && (SiS_Pr->SiS_IF_DEF_LVDS == 0)) {
  2542. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { /* LCD */
  2543. tempbx = SiS_Pr->SiS_LCDResInfo;
  2544. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) tempbx += 32;
  2545. /* patch index */
  2546. if(SiS_Pr->SiS_LCDResInfo == Panel_1680x1050) {
  2547. if (resinfo == SIS_RI_1280x800) tempal = 9;
  2548. else if(resinfo == SIS_RI_1400x1050) tempal = 11;
  2549. } else if((SiS_Pr->SiS_LCDResInfo == Panel_1280x800) ||
  2550. (SiS_Pr->SiS_LCDResInfo == Panel_1280x800_2) ||
  2551. (SiS_Pr->SiS_LCDResInfo == Panel_1280x854)) {
  2552. if (resinfo == SIS_RI_1280x768) tempal = 9;
  2553. }
  2554. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  2555. /* Pass 1:1 only (center-screen handled outside) */
  2556. /* This is never called for the panel's native resolution */
  2557. /* since Pass1:1 will not be set in this case */
  2558. tempbx = 100;
  2559. if(ModeNo >= 0x13) {
  2560. tempal = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC_NS;
  2561. }
  2562. }
  2563. #ifdef SIS315H
  2564. if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) {
  2565. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) {
  2566. if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
  2567. tempbx = 200;
  2568. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) tempbx++;
  2569. }
  2570. }
  2571. }
  2572. #endif
  2573. } else { /* TV */
  2574. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  2575. /* if(SiS_Pr->SiS_VGAVDE > 480) SiS_Pr->SiS_TVMode &= (~TVSetTVSimuMode); */
  2576. tempbx = 2;
  2577. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  2578. tempbx = 13;
  2579. if(!(SiS_Pr->SiS_TVMode & TVSetTVSimuMode)) tempbx = 14;
  2580. }
  2581. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  2582. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) tempbx = 7;
  2583. else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) tempbx = 6;
  2584. else tempbx = 5;
  2585. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) tempbx += 5;
  2586. } else {
  2587. if(SiS_Pr->SiS_TVMode & TVSetPAL) tempbx = 3;
  2588. else tempbx = 4;
  2589. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) tempbx += 5;
  2590. }
  2591. }
  2592. tempal &= 0x3F;
  2593. if(ModeNo > 0x13) {
  2594. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoHiVision) {
  2595. switch(resinfo) {
  2596. case SIS_RI_720x480:
  2597. tempal = 6;
  2598. if(SiS_Pr->SiS_TVMode & (TVSetPAL | TVSetPALN)) tempal = 9;
  2599. break;
  2600. case SIS_RI_720x576:
  2601. case SIS_RI_768x576:
  2602. case SIS_RI_1024x576: /* Not in NTSC or YPBPR mode (except 1080i)! */
  2603. tempal = 6;
  2604. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  2605. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) tempal = 8;
  2606. }
  2607. break;
  2608. case SIS_RI_800x480:
  2609. tempal = 4;
  2610. break;
  2611. case SIS_RI_512x384:
  2612. case SIS_RI_1024x768:
  2613. tempal = 7;
  2614. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  2615. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) tempal = 8;
  2616. }
  2617. break;
  2618. case SIS_RI_1280x720:
  2619. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  2620. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) tempal = 9;
  2621. }
  2622. break;
  2623. }
  2624. }
  2625. }
  2626. *CRT2Index = tempbx;
  2627. *ResIndex = tempal;
  2628. } else { /* LVDS, 301B-DH (if running on LCD) */
  2629. tempbx = 0;
  2630. if((SiS_Pr->SiS_IF_DEF_CH70xx) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
  2631. tempbx = 90;
  2632. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  2633. tempbx = 92;
  2634. if(SiS_Pr->SiS_ModeType > ModeVGA) {
  2635. if(SiS_Pr->SiS_CHSOverScan) tempbx = 99;
  2636. }
  2637. if(SiS_Pr->SiS_TVMode & TVSetPALM) tempbx = 94;
  2638. else if(SiS_Pr->SiS_TVMode & TVSetPALN) tempbx = 96;
  2639. }
  2640. if(tempbx != 99) {
  2641. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx++;
  2642. }
  2643. } else {
  2644. switch(SiS_Pr->SiS_LCDResInfo) {
  2645. case Panel_640x480: tempbx = 12; break;
  2646. case Panel_320x240_1: tempbx = 10; break;
  2647. case Panel_320x240_2:
  2648. case Panel_320x240_3: tempbx = 14; break;
  2649. case Panel_800x600: tempbx = 16; break;
  2650. case Panel_1024x600: tempbx = 18; break;
  2651. case Panel_1152x768:
  2652. case Panel_1024x768: tempbx = 20; break;
  2653. case Panel_1280x768: tempbx = 22; break;
  2654. case Panel_1280x1024: tempbx = 24; break;
  2655. case Panel_1400x1050: tempbx = 26; break;
  2656. case Panel_1600x1200: tempbx = 28; break;
  2657. #ifdef SIS300
  2658. case Panel_Barco1366: tempbx = 80; break;
  2659. #endif
  2660. }
  2661. switch(SiS_Pr->SiS_LCDResInfo) {
  2662. case Panel_320x240_1:
  2663. case Panel_320x240_2:
  2664. case Panel_320x240_3:
  2665. case Panel_640x480:
  2666. break;
  2667. default:
  2668. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++;
  2669. }
  2670. if(SiS_Pr->SiS_LCDInfo & LCDPass11) tempbx = 30;
  2671. #ifdef SIS300
  2672. if(SiS_Pr->SiS_CustomT == CUT_BARCO1024) {
  2673. tempbx = 82;
  2674. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++;
  2675. } else if(SiS_Pr->SiS_CustomT == CUT_PANEL848 || SiS_Pr->SiS_CustomT == CUT_PANEL856) {
  2676. tempbx = 84;
  2677. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++;
  2678. }
  2679. #endif
  2680. }
  2681. (*CRT2Index) = tempbx;
  2682. (*ResIndex) = tempal & 0x1F;
  2683. }
  2684. }
  2685. static void
  2686. SiS_GetRAMDAC2DATA(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  2687. unsigned short RefreshRateTableIndex)
  2688. {
  2689. unsigned short tempax=0, tempbx=0, index, dotclock;
  2690. unsigned short temp1=0, modeflag=0, tempcx=0;
  2691. SiS_Pr->SiS_RVBHCMAX = 1;
  2692. SiS_Pr->SiS_RVBHCFACT = 1;
  2693. if(ModeNo <= 0x13) {
  2694. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  2695. index = SiS_GetModePtr(SiS_Pr,ModeNo,ModeIdIndex);
  2696. tempax = SiS_Pr->SiS_StandTable[index].CRTC[0];
  2697. tempbx = SiS_Pr->SiS_StandTable[index].CRTC[6];
  2698. temp1 = SiS_Pr->SiS_StandTable[index].CRTC[7];
  2699. dotclock = (modeflag & Charx8Dot) ? 8 : 9;
  2700. } else {
  2701. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  2702. index = SiS_GetRefCRT1CRTC(SiS_Pr, RefreshRateTableIndex, SiS_Pr->SiS_UseWideCRT2);
  2703. tempax = SiS_Pr->SiS_CRT1Table[index].CR[0];
  2704. tempax |= (SiS_Pr->SiS_CRT1Table[index].CR[14] << 8);
  2705. tempax &= 0x03FF;
  2706. tempbx = SiS_Pr->SiS_CRT1Table[index].CR[6];
  2707. tempcx = SiS_Pr->SiS_CRT1Table[index].CR[13] << 8;
  2708. tempcx &= 0x0100;
  2709. tempcx <<= 2;
  2710. tempbx |= tempcx;
  2711. temp1 = SiS_Pr->SiS_CRT1Table[index].CR[7];
  2712. dotclock = 8;
  2713. }
  2714. if(temp1 & 0x01) tempbx |= 0x0100;
  2715. if(temp1 & 0x20) tempbx |= 0x0200;
  2716. tempax += 5;
  2717. tempax *= dotclock;
  2718. if(modeflag & HalfDCLK) tempax <<= 1;
  2719. tempbx++;
  2720. SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_HT = tempax;
  2721. SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_VT = tempbx;
  2722. }
  2723. static void
  2724. SiS_CalcPanelLinkTiming(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
  2725. unsigned short ModeIdIndex, unsigned short RefreshRateTableIndex)
  2726. {
  2727. unsigned short ResIndex;
  2728. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  2729. if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
  2730. if(SiS_Pr->UseCustomMode) {
  2731. ResIndex = SiS_Pr->CHTotal;
  2732. if(SiS_Pr->CModeFlag & HalfDCLK) ResIndex <<= 1;
  2733. SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_HT = ResIndex;
  2734. SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_VT = SiS_Pr->CVTotal;
  2735. } else {
  2736. if(ModeNo < 0x13) {
  2737. ResIndex = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  2738. } else {
  2739. ResIndex = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC_NS;
  2740. }
  2741. if(ResIndex == 0x09) {
  2742. if(SiS_Pr->Alternate1600x1200) ResIndex = 0x20; /* 1600x1200 LCDA */
  2743. else if(SiS_Pr->SiS_IF_DEF_LVDS == 1) ResIndex = 0x21; /* 1600x1200 LVDS */
  2744. }
  2745. SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_NoScaleData[ResIndex].VGAHT;
  2746. SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_NoScaleData[ResIndex].VGAVT;
  2747. SiS_Pr->SiS_HT = SiS_Pr->SiS_NoScaleData[ResIndex].LCDHT;
  2748. SiS_Pr->SiS_VT = SiS_Pr->SiS_NoScaleData[ResIndex].LCDVT;
  2749. }
  2750. } else {
  2751. SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_HT = SiS_Pr->PanelHT;
  2752. SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_VT = SiS_Pr->PanelVT;
  2753. }
  2754. } else {
  2755. /* This handles custom modes and custom panels */
  2756. SiS_Pr->SiS_HDE = SiS_Pr->PanelXRes;
  2757. SiS_Pr->SiS_VDE = SiS_Pr->PanelYRes;
  2758. SiS_Pr->SiS_HT = SiS_Pr->PanelHT;
  2759. SiS_Pr->SiS_VT = SiS_Pr->PanelVT;
  2760. SiS_Pr->SiS_VGAHT = SiS_Pr->PanelHT - (SiS_Pr->PanelXRes - SiS_Pr->SiS_VGAHDE);
  2761. SiS_Pr->SiS_VGAVT = SiS_Pr->PanelVT - (SiS_Pr->PanelYRes - SiS_Pr->SiS_VGAVDE);
  2762. }
  2763. }
  2764. static void
  2765. SiS_GetCRT2DataLVDS(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  2766. unsigned short RefreshRateTableIndex)
  2767. {
  2768. unsigned short CRT2Index, ResIndex, backup;
  2769. const struct SiS_LVDSData *LVDSData = NULL;
  2770. SiS_GetCRT2ResInfo(SiS_Pr, ModeNo, ModeIdIndex);
  2771. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  2772. SiS_Pr->SiS_RVBHCMAX = 1;
  2773. SiS_Pr->SiS_RVBHCFACT = 1;
  2774. SiS_Pr->SiS_NewFlickerMode = 0;
  2775. SiS_Pr->SiS_RVBHRS = 50;
  2776. SiS_Pr->SiS_RY1COE = 0;
  2777. SiS_Pr->SiS_RY2COE = 0;
  2778. SiS_Pr->SiS_RY3COE = 0;
  2779. SiS_Pr->SiS_RY4COE = 0;
  2780. SiS_Pr->SiS_RVBHRS2 = 0;
  2781. }
  2782. if((SiS_Pr->SiS_VBType & VB_SISVB) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  2783. #ifdef SIS315H
  2784. SiS_CalcPanelLinkTiming(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  2785. SiS_CalcLCDACRT1Timing(SiS_Pr, ModeNo, ModeIdIndex);
  2786. #endif
  2787. } else {
  2788. /* 301BDH needs LVDS Data */
  2789. backup = SiS_Pr->SiS_IF_DEF_LVDS;
  2790. if((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) {
  2791. SiS_Pr->SiS_IF_DEF_LVDS = 1;
  2792. }
  2793. SiS_GetCRT2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex,
  2794. &CRT2Index, &ResIndex);
  2795. SiS_Pr->SiS_IF_DEF_LVDS = backup;
  2796. switch(CRT2Index) {
  2797. case 10: LVDSData = SiS_Pr->SiS_LVDS320x240Data_1; break;
  2798. case 14: LVDSData = SiS_Pr->SiS_LVDS320x240Data_2; break;
  2799. case 12: LVDSData = SiS_Pr->SiS_LVDS640x480Data_1; break;
  2800. case 16: LVDSData = SiS_Pr->SiS_LVDS800x600Data_1; break;
  2801. case 18: LVDSData = SiS_Pr->SiS_LVDS1024x600Data_1; break;
  2802. case 20: LVDSData = SiS_Pr->SiS_LVDS1024x768Data_1; break;
  2803. #ifdef SIS300
  2804. case 80: LVDSData = SiS_Pr->SiS_LVDSBARCO1366Data_1; break;
  2805. case 81: LVDSData = SiS_Pr->SiS_LVDSBARCO1366Data_2; break;
  2806. case 82: LVDSData = SiS_Pr->SiS_LVDSBARCO1024Data_1; break;
  2807. case 84: LVDSData = SiS_Pr->SiS_LVDS848x480Data_1; break;
  2808. case 85: LVDSData = SiS_Pr->SiS_LVDS848x480Data_2; break;
  2809. #endif
  2810. case 90: LVDSData = SiS_Pr->SiS_CHTVUNTSCData; break;
  2811. case 91: LVDSData = SiS_Pr->SiS_CHTVONTSCData; break;
  2812. case 92: LVDSData = SiS_Pr->SiS_CHTVUPALData; break;
  2813. case 93: LVDSData = SiS_Pr->SiS_CHTVOPALData; break;
  2814. case 94: LVDSData = SiS_Pr->SiS_CHTVUPALMData; break;
  2815. case 95: LVDSData = SiS_Pr->SiS_CHTVOPALMData; break;
  2816. case 96: LVDSData = SiS_Pr->SiS_CHTVUPALNData; break;
  2817. case 97: LVDSData = SiS_Pr->SiS_CHTVOPALNData; break;
  2818. case 99: LVDSData = SiS_Pr->SiS_CHTVSOPALData; break;
  2819. }
  2820. if(LVDSData) {
  2821. SiS_Pr->SiS_VGAHT = (LVDSData+ResIndex)->VGAHT;
  2822. SiS_Pr->SiS_VGAVT = (LVDSData+ResIndex)->VGAVT;
  2823. SiS_Pr->SiS_HT = (LVDSData+ResIndex)->LCDHT;
  2824. SiS_Pr->SiS_VT = (LVDSData+ResIndex)->LCDVT;
  2825. } else {
  2826. SiS_CalcPanelLinkTiming(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  2827. }
  2828. if( (!(SiS_Pr->SiS_VBType & VB_SISVB)) &&
  2829. (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) &&
  2830. (!(SiS_Pr->SiS_LCDInfo & LCDPass11)) ) {
  2831. if( (!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) ||
  2832. (SiS_Pr->SiS_SetFlag & SetDOSMode) ) {
  2833. SiS_Pr->SiS_HDE = SiS_Pr->PanelXRes;
  2834. SiS_Pr->SiS_VDE = SiS_Pr->PanelYRes;
  2835. #ifdef SIS300
  2836. if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) {
  2837. if(ResIndex < 0x08) {
  2838. SiS_Pr->SiS_HDE = 1280;
  2839. SiS_Pr->SiS_VDE = 1024;
  2840. }
  2841. }
  2842. #endif
  2843. }
  2844. }
  2845. }
  2846. }
  2847. static void
  2848. SiS_GetCRT2Data301(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  2849. unsigned short RefreshRateTableIndex)
  2850. {
  2851. unsigned char *ROMAddr = NULL;
  2852. unsigned short tempax, tempbx, modeflag, romptr=0;
  2853. unsigned short resinfo, CRT2Index, ResIndex;
  2854. const struct SiS_LCDData *LCDPtr = NULL;
  2855. const struct SiS_TVData *TVPtr = NULL;
  2856. #ifdef SIS315H
  2857. short resinfo661;
  2858. #endif
  2859. if(ModeNo <= 0x13) {
  2860. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  2861. resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
  2862. } else if(SiS_Pr->UseCustomMode) {
  2863. modeflag = SiS_Pr->CModeFlag;
  2864. resinfo = 0;
  2865. } else {
  2866. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  2867. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  2868. #ifdef SIS315H
  2869. resinfo661 = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].ROMMODEIDX661;
  2870. if( (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) &&
  2871. (SiS_Pr->SiS_SetFlag & LCDVESATiming) &&
  2872. (resinfo661 >= 0) &&
  2873. (SiS_Pr->SiS_NeedRomModeData) ) {
  2874. if((ROMAddr = GetLCDStructPtr661(SiS_Pr))) {
  2875. if((romptr = (SISGETROMW(21)))) {
  2876. romptr += (resinfo661 * 10);
  2877. ROMAddr = SiS_Pr->VirtualRomBase;
  2878. }
  2879. }
  2880. }
  2881. #endif
  2882. }
  2883. SiS_Pr->SiS_NewFlickerMode = 0;
  2884. SiS_Pr->SiS_RVBHRS = 50;
  2885. SiS_Pr->SiS_RY1COE = 0;
  2886. SiS_Pr->SiS_RY2COE = 0;
  2887. SiS_Pr->SiS_RY3COE = 0;
  2888. SiS_Pr->SiS_RY4COE = 0;
  2889. SiS_Pr->SiS_RVBHRS2 = 0;
  2890. SiS_GetCRT2ResInfo(SiS_Pr,ModeNo,ModeIdIndex);
  2891. if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) {
  2892. if(SiS_Pr->UseCustomMode) {
  2893. SiS_Pr->SiS_RVBHCMAX = 1;
  2894. SiS_Pr->SiS_RVBHCFACT = 1;
  2895. SiS_Pr->SiS_HDE = SiS_Pr->SiS_VGAHDE;
  2896. SiS_Pr->SiS_VDE = SiS_Pr->SiS_VGAVDE;
  2897. tempax = SiS_Pr->CHTotal;
  2898. if(modeflag & HalfDCLK) tempax <<= 1;
  2899. SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_HT = tempax;
  2900. SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_VT = SiS_Pr->CVTotal;
  2901. } else {
  2902. SiS_GetRAMDAC2DATA(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  2903. }
  2904. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  2905. SiS_GetCRT2Ptr(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex,
  2906. &CRT2Index,&ResIndex);
  2907. switch(CRT2Index) {
  2908. case 2: TVPtr = SiS_Pr->SiS_ExtHiTVData; break;
  2909. case 3: TVPtr = SiS_Pr->SiS_ExtPALData; break;
  2910. case 4: TVPtr = SiS_Pr->SiS_ExtNTSCData; break;
  2911. case 5: TVPtr = SiS_Pr->SiS_Ext525iData; break;
  2912. case 6: TVPtr = SiS_Pr->SiS_Ext525pData; break;
  2913. case 7: TVPtr = SiS_Pr->SiS_Ext750pData; break;
  2914. case 8: TVPtr = SiS_Pr->SiS_StPALData; break;
  2915. case 9: TVPtr = SiS_Pr->SiS_StNTSCData; break;
  2916. case 10: TVPtr = SiS_Pr->SiS_St525iData; break;
  2917. case 11: TVPtr = SiS_Pr->SiS_St525pData; break;
  2918. case 12: TVPtr = SiS_Pr->SiS_St750pData; break;
  2919. case 13: TVPtr = SiS_Pr->SiS_St1HiTVData; break;
  2920. case 14: TVPtr = SiS_Pr->SiS_St2HiTVData; break;
  2921. default: TVPtr = SiS_Pr->SiS_StPALData; break;
  2922. }
  2923. SiS_Pr->SiS_RVBHCMAX = (TVPtr+ResIndex)->RVBHCMAX;
  2924. SiS_Pr->SiS_RVBHCFACT = (TVPtr+ResIndex)->RVBHCFACT;
  2925. SiS_Pr->SiS_VGAHT = (TVPtr+ResIndex)->VGAHT;
  2926. SiS_Pr->SiS_VGAVT = (TVPtr+ResIndex)->VGAVT;
  2927. SiS_Pr->SiS_HDE = (TVPtr+ResIndex)->TVHDE;
  2928. SiS_Pr->SiS_VDE = (TVPtr+ResIndex)->TVVDE;
  2929. SiS_Pr->SiS_RVBHRS2 = (TVPtr+ResIndex)->RVBHRS2 & 0x0fff;
  2930. if(modeflag & HalfDCLK) {
  2931. SiS_Pr->SiS_RVBHRS = (TVPtr+ResIndex)->HALFRVBHRS;
  2932. if(SiS_Pr->SiS_RVBHRS2) {
  2933. SiS_Pr->SiS_RVBHRS2 = ((SiS_Pr->SiS_RVBHRS2 + 3) >> 1) - 3;
  2934. tempax = ((TVPtr+ResIndex)->RVBHRS2 >> 12) & 0x07;
  2935. if((TVPtr+ResIndex)->RVBHRS2 & 0x8000) SiS_Pr->SiS_RVBHRS2 -= tempax;
  2936. else SiS_Pr->SiS_RVBHRS2 += tempax;
  2937. }
  2938. } else {
  2939. SiS_Pr->SiS_RVBHRS = (TVPtr+ResIndex)->RVBHRS;
  2940. }
  2941. SiS_Pr->SiS_NewFlickerMode = ((TVPtr+ResIndex)->FlickerMode) << 7;
  2942. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  2943. if((resinfo == SIS_RI_960x600) ||
  2944. (resinfo == SIS_RI_1024x768) ||
  2945. (resinfo == SIS_RI_1280x1024) ||
  2946. (resinfo == SIS_RI_1280x720)) {
  2947. SiS_Pr->SiS_NewFlickerMode = 0x40;
  2948. }
  2949. if(SiS_Pr->SiS_VGAVDE == 350) SiS_Pr->SiS_TVMode |= TVSetTVSimuMode;
  2950. SiS_Pr->SiS_HT = ExtHiTVHT;
  2951. SiS_Pr->SiS_VT = ExtHiTVVT;
  2952. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  2953. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) {
  2954. SiS_Pr->SiS_HT = StHiTVHT;
  2955. SiS_Pr->SiS_VT = StHiTVVT;
  2956. }
  2957. }
  2958. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  2959. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) {
  2960. SiS_Pr->SiS_HT = 1650;
  2961. SiS_Pr->SiS_VT = 750;
  2962. } else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) {
  2963. SiS_Pr->SiS_HT = NTSCHT;
  2964. if(SiS_Pr->SiS_TVMode & TVSet525p1024) SiS_Pr->SiS_HT = NTSC2HT;
  2965. SiS_Pr->SiS_VT = NTSCVT;
  2966. } else {
  2967. SiS_Pr->SiS_HT = NTSCHT;
  2968. if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) SiS_Pr->SiS_HT = NTSC2HT;
  2969. SiS_Pr->SiS_VT = NTSCVT;
  2970. }
  2971. } else {
  2972. SiS_Pr->SiS_RY1COE = (TVPtr+ResIndex)->RY1COE;
  2973. SiS_Pr->SiS_RY2COE = (TVPtr+ResIndex)->RY2COE;
  2974. SiS_Pr->SiS_RY3COE = (TVPtr+ResIndex)->RY3COE;
  2975. SiS_Pr->SiS_RY4COE = (TVPtr+ResIndex)->RY4COE;
  2976. if(modeflag & HalfDCLK) {
  2977. SiS_Pr->SiS_RY1COE = 0x00;
  2978. SiS_Pr->SiS_RY2COE = 0xf4;
  2979. SiS_Pr->SiS_RY3COE = 0x10;
  2980. SiS_Pr->SiS_RY4COE = 0x38;
  2981. }
  2982. if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) {
  2983. SiS_Pr->SiS_HT = NTSCHT;
  2984. if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) SiS_Pr->SiS_HT = NTSC2HT;
  2985. SiS_Pr->SiS_VT = NTSCVT;
  2986. } else {
  2987. SiS_Pr->SiS_HT = PALHT;
  2988. SiS_Pr->SiS_VT = PALVT;
  2989. }
  2990. }
  2991. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  2992. SiS_Pr->SiS_RVBHCMAX = 1;
  2993. SiS_Pr->SiS_RVBHCFACT = 1;
  2994. if(SiS_Pr->UseCustomMode) {
  2995. SiS_Pr->SiS_HDE = SiS_Pr->SiS_VGAHDE;
  2996. SiS_Pr->SiS_VDE = SiS_Pr->SiS_VGAVDE;
  2997. tempax = SiS_Pr->CHTotal;
  2998. if(modeflag & HalfDCLK) tempax <<= 1;
  2999. SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_HT = tempax;
  3000. SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_VT = SiS_Pr->CVTotal;
  3001. } else {
  3002. BOOLEAN gotit = FALSE;
  3003. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
  3004. SiS_Pr->SiS_VGAHT = SiS_Pr->PanelHT;
  3005. SiS_Pr->SiS_VGAVT = SiS_Pr->PanelVT;
  3006. SiS_Pr->SiS_HT = SiS_Pr->PanelHT;
  3007. SiS_Pr->SiS_VT = SiS_Pr->PanelVT;
  3008. gotit = TRUE;
  3009. } else if( (!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) && (romptr) && (ROMAddr) ) {
  3010. #ifdef SIS315H
  3011. SiS_Pr->SiS_RVBHCMAX = ROMAddr[romptr];
  3012. SiS_Pr->SiS_RVBHCFACT = ROMAddr[romptr+1];
  3013. SiS_Pr->SiS_VGAHT = ROMAddr[romptr+2] | ((ROMAddr[romptr+3] & 0x0f) << 8);
  3014. SiS_Pr->SiS_VGAVT = (ROMAddr[romptr+4] << 4) | ((ROMAddr[romptr+3] & 0xf0) >> 4);
  3015. SiS_Pr->SiS_HT = ROMAddr[romptr+5] | ((ROMAddr[romptr+6] & 0x0f) << 8);
  3016. SiS_Pr->SiS_VT = (ROMAddr[romptr+7] << 4) | ((ROMAddr[romptr+6] & 0xf0) >> 4);
  3017. SiS_Pr->SiS_RVBHRS2 = ROMAddr[romptr+8] | ((ROMAddr[romptr+9] & 0x0f) << 8);
  3018. if((SiS_Pr->SiS_RVBHRS2) && (modeflag & HalfDCLK)) {
  3019. SiS_Pr->SiS_RVBHRS2 = ((SiS_Pr->SiS_RVBHRS2 + 3) >> 1) - 3;
  3020. tempax = (ROMAddr[romptr+9] >> 4) & 0x07;
  3021. if(ROMAddr[romptr+9] & 0x80) SiS_Pr->SiS_RVBHRS2 -= tempax;
  3022. else SiS_Pr->SiS_RVBHRS2 += tempax;
  3023. }
  3024. if(SiS_Pr->SiS_VGAHT) gotit = TRUE;
  3025. else {
  3026. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  3027. SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  3028. SiS_Pr->SiS_RVBHCMAX = 1;
  3029. SiS_Pr->SiS_RVBHCFACT = 1;
  3030. SiS_Pr->SiS_VGAHT = SiS_Pr->PanelHT;
  3031. SiS_Pr->SiS_VGAVT = SiS_Pr->PanelVT;
  3032. SiS_Pr->SiS_HT = SiS_Pr->PanelHT;
  3033. SiS_Pr->SiS_VT = SiS_Pr->PanelVT;
  3034. SiS_Pr->SiS_RVBHRS2 = 0;
  3035. gotit = TRUE;
  3036. }
  3037. #endif
  3038. }
  3039. if(!gotit) {
  3040. SiS_GetCRT2Ptr(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex,
  3041. &CRT2Index,&ResIndex);
  3042. switch(CRT2Index) {
  3043. case Panel_1024x768 : LCDPtr = SiS_Pr->SiS_ExtLCD1024x768Data; break;
  3044. case Panel_1024x768 + 32: LCDPtr = SiS_Pr->SiS_St2LCD1024x768Data; break;
  3045. case Panel_1280x720 :
  3046. case Panel_1280x720 + 32: LCDPtr = SiS_Pr->SiS_LCD1280x720Data; break;
  3047. case Panel_1280x768_2 : LCDPtr = SiS_Pr->SiS_ExtLCD1280x768_2Data; break;
  3048. case Panel_1280x768_2+ 32: LCDPtr = SiS_Pr->SiS_StLCD1280x768_2Data; break;
  3049. case Panel_1280x800 :
  3050. case Panel_1280x800 + 32: LCDPtr = SiS_Pr->SiS_LCD1280x800Data; break;
  3051. case Panel_1280x800_2 :
  3052. case Panel_1280x800_2+ 32: LCDPtr = SiS_Pr->SiS_LCD1280x800_2Data; break;
  3053. case Panel_1280x854 :
  3054. case Panel_1280x854 + 32: LCDPtr = SiS_Pr->SiS_LCD1280x854Data; break;
  3055. case Panel_1280x960 :
  3056. case Panel_1280x960 + 32: LCDPtr = SiS_Pr->SiS_LCD1280x960Data; break;
  3057. case Panel_1280x1024 : LCDPtr = SiS_Pr->SiS_ExtLCD1280x1024Data; break;
  3058. case Panel_1280x1024 + 32: LCDPtr = SiS_Pr->SiS_St2LCD1280x1024Data; break;
  3059. case Panel_1400x1050 : LCDPtr = SiS_Pr->SiS_ExtLCD1400x1050Data; break;
  3060. case Panel_1400x1050 + 32: LCDPtr = SiS_Pr->SiS_StLCD1400x1050Data; break;
  3061. case Panel_1600x1200 : LCDPtr = SiS_Pr->SiS_ExtLCD1600x1200Data; break;
  3062. case Panel_1600x1200 + 32: LCDPtr = SiS_Pr->SiS_StLCD1600x1200Data; break;
  3063. case Panel_1680x1050 :
  3064. case Panel_1680x1050 + 32: LCDPtr = SiS_Pr->SiS_LCD1680x1050Data; break;
  3065. case 100 : LCDPtr = SiS_Pr->SiS_NoScaleData; break;
  3066. #ifdef SIS315H
  3067. case 200 : LCDPtr = SiS310_ExtCompaq1280x1024Data; break;
  3068. case 201 : LCDPtr = SiS_Pr->SiS_St2LCD1280x1024Data; break;
  3069. #endif
  3070. default : LCDPtr = SiS_Pr->SiS_ExtLCD1024x768Data; break;
  3071. }
  3072. #ifdef SIS_XORG_XF86
  3073. #ifdef TWDEBUG
  3074. xf86DrvMsg(0, X_INFO, "GetCRT2Data: Index %d ResIndex %d\n", CRT2Index, ResIndex);
  3075. #endif
  3076. #endif
  3077. SiS_Pr->SiS_RVBHCMAX = (LCDPtr+ResIndex)->RVBHCMAX;
  3078. SiS_Pr->SiS_RVBHCFACT = (LCDPtr+ResIndex)->RVBHCFACT;
  3079. SiS_Pr->SiS_VGAHT = (LCDPtr+ResIndex)->VGAHT;
  3080. SiS_Pr->SiS_VGAVT = (LCDPtr+ResIndex)->VGAVT;
  3081. SiS_Pr->SiS_HT = (LCDPtr+ResIndex)->LCDHT;
  3082. SiS_Pr->SiS_VT = (LCDPtr+ResIndex)->LCDVT;
  3083. }
  3084. tempax = SiS_Pr->PanelXRes;
  3085. tempbx = SiS_Pr->PanelYRes;
  3086. switch(SiS_Pr->SiS_LCDResInfo) {
  3087. case Panel_1024x768:
  3088. if(SiS_Pr->SiS_SetFlag & LCDVESATiming) {
  3089. if(SiS_Pr->ChipType < SIS_315H) {
  3090. if (SiS_Pr->SiS_VGAVDE == 350) tempbx = 560;
  3091. else if(SiS_Pr->SiS_VGAVDE == 400) tempbx = 640;
  3092. }
  3093. } else {
  3094. if (SiS_Pr->SiS_VGAVDE == 357) tempbx = 527;
  3095. else if(SiS_Pr->SiS_VGAVDE == 420) tempbx = 620;
  3096. else if(SiS_Pr->SiS_VGAVDE == 525) tempbx = 775;
  3097. else if(SiS_Pr->SiS_VGAVDE == 600) tempbx = 775;
  3098. else if(SiS_Pr->SiS_VGAVDE == 350) tempbx = 560;
  3099. else if(SiS_Pr->SiS_VGAVDE == 400) tempbx = 640;
  3100. }
  3101. break;
  3102. case Panel_1280x960:
  3103. if (SiS_Pr->SiS_VGAVDE == 350) tempbx = 700;
  3104. else if(SiS_Pr->SiS_VGAVDE == 400) tempbx = 800;
  3105. else if(SiS_Pr->SiS_VGAVDE == 1024) tempbx = 960;
  3106. break;
  3107. case Panel_1280x1024:
  3108. if (SiS_Pr->SiS_VGAVDE == 360) tempbx = 768;
  3109. else if(SiS_Pr->SiS_VGAVDE == 375) tempbx = 800;
  3110. else if(SiS_Pr->SiS_VGAVDE == 405) tempbx = 864;
  3111. break;
  3112. case Panel_1600x1200:
  3113. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
  3114. if (SiS_Pr->SiS_VGAVDE == 350) tempbx = 875;
  3115. else if(SiS_Pr->SiS_VGAVDE == 400) tempbx = 1000;
  3116. }
  3117. break;
  3118. }
  3119. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  3120. tempax = SiS_Pr->SiS_VGAHDE;
  3121. tempbx = SiS_Pr->SiS_VGAVDE;
  3122. }
  3123. SiS_Pr->SiS_HDE = tempax;
  3124. SiS_Pr->SiS_VDE = tempbx;
  3125. }
  3126. }
  3127. }
  3128. static void
  3129. SiS_GetCRT2Data(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  3130. unsigned short RefreshRateTableIndex)
  3131. {
  3132. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  3133. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  3134. SiS_GetCRT2DataLVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  3135. } else {
  3136. if((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) {
  3137. /* Need LVDS Data for LCD on 301B-DH */
  3138. SiS_GetCRT2DataLVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  3139. } else {
  3140. SiS_GetCRT2Data301(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  3141. }
  3142. }
  3143. } else {
  3144. SiS_GetCRT2DataLVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  3145. }
  3146. }
  3147. /*********************************************/
  3148. /* GET LVDS DES (SKEW) DATA */
  3149. /*********************************************/
  3150. static const struct SiS_LVDSDes *
  3151. SiS_GetLVDSDesPtr(struct SiS_Private *SiS_Pr)
  3152. {
  3153. const struct SiS_LVDSDes *PanelDesPtr = NULL;
  3154. #ifdef SIS300
  3155. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  3156. if(SiS_Pr->ChipType < SIS_315H) {
  3157. if(SiS_Pr->SiS_LCDTypeInfo == 4) {
  3158. if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) {
  3159. PanelDesPtr = SiS_Pr->SiS_PanelType04_1a;
  3160. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  3161. PanelDesPtr = SiS_Pr->SiS_PanelType04_2a;
  3162. }
  3163. } else if(SiS_Pr->SiS_CustomT == CUT_BARCO1024) {
  3164. PanelDesPtr = SiS_Pr->SiS_PanelType04_1b;
  3165. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  3166. PanelDesPtr = SiS_Pr->SiS_PanelType04_2b;
  3167. }
  3168. }
  3169. }
  3170. }
  3171. }
  3172. #endif
  3173. return PanelDesPtr;
  3174. }
  3175. static void
  3176. SiS_GetLVDSDesData(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  3177. unsigned short RefreshRateTableIndex)
  3178. {
  3179. unsigned short modeflag, ResIndex;
  3180. const struct SiS_LVDSDes *PanelDesPtr = NULL;
  3181. SiS_Pr->SiS_LCDHDES = 0;
  3182. SiS_Pr->SiS_LCDVDES = 0;
  3183. /* Some special cases */
  3184. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  3185. /* Trumpion */
  3186. if(SiS_Pr->SiS_IF_DEF_TRUMPION) {
  3187. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  3188. if(SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) {
  3189. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3190. }
  3191. }
  3192. return;
  3193. }
  3194. /* 640x480 on LVDS */
  3195. if(SiS_Pr->ChipType < SIS_315H) {
  3196. if(SiS_Pr->SiS_LCDResInfo == Panel_640x480 && SiS_Pr->SiS_LCDTypeInfo == 3) {
  3197. SiS_Pr->SiS_LCDHDES = 8;
  3198. if (SiS_Pr->SiS_VGAVDE >= 480) SiS_Pr->SiS_LCDVDES = 512;
  3199. else if(SiS_Pr->SiS_VGAVDE >= 400) SiS_Pr->SiS_LCDVDES = 436;
  3200. else if(SiS_Pr->SiS_VGAVDE >= 350) SiS_Pr->SiS_LCDVDES = 440;
  3201. return;
  3202. }
  3203. }
  3204. } /* LCD */
  3205. if( (SiS_Pr->UseCustomMode) ||
  3206. (SiS_Pr->SiS_LCDResInfo == Panel_Custom) ||
  3207. (SiS_Pr->SiS_CustomT == CUT_PANEL848) ||
  3208. (SiS_Pr->SiS_CustomT == CUT_PANEL856) ||
  3209. (SiS_Pr->SiS_LCDInfo & LCDPass11) ) {
  3210. return;
  3211. }
  3212. if(ModeNo <= 0x13) ResIndex = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  3213. else ResIndex = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  3214. if((SiS_Pr->SiS_VBType & VB_SIS30xBLV) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  3215. #ifdef SIS315H
  3216. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  3217. /* non-pass 1:1 only, see above */
  3218. if(SiS_Pr->SiS_VGAHDE != SiS_Pr->PanelXRes) {
  3219. SiS_Pr->SiS_LCDHDES = SiS_Pr->SiS_HT - ((SiS_Pr->PanelXRes - SiS_Pr->SiS_VGAHDE) / 2);
  3220. }
  3221. if(SiS_Pr->SiS_VGAVDE != SiS_Pr->PanelYRes) {
  3222. SiS_Pr->SiS_LCDVDES = SiS_Pr->SiS_VT - ((SiS_Pr->PanelYRes - SiS_Pr->SiS_VGAVDE) / 2);
  3223. }
  3224. }
  3225. if(SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) {
  3226. switch(SiS_Pr->SiS_CustomT) {
  3227. case CUT_UNIWILL1024:
  3228. case CUT_UNIWILL10242:
  3229. case CUT_CLEVO1400:
  3230. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  3231. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3232. }
  3233. break;
  3234. }
  3235. switch(SiS_Pr->SiS_LCDResInfo) {
  3236. case Panel_1280x1024:
  3237. if(SiS_Pr->SiS_CustomT != CUT_COMPAQ1280) {
  3238. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3239. }
  3240. break;
  3241. case Panel_1280x800: /* Verified for Averatec 6240 */
  3242. case Panel_1280x800_2: /* Verified for Asus A4L */
  3243. case Panel_1280x854: /* Not verified yet FIXME */
  3244. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3245. break;
  3246. }
  3247. }
  3248. #endif
  3249. } else {
  3250. if((SiS_Pr->SiS_IF_DEF_CH70xx != 0) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
  3251. if((SiS_Pr->SiS_TVMode & TVSetPAL) && (!(SiS_Pr->SiS_TVMode & TVSetPALM))) {
  3252. if(ResIndex <= 3) SiS_Pr->SiS_LCDHDES = 256;
  3253. }
  3254. } else if((PanelDesPtr = SiS_GetLVDSDesPtr(SiS_Pr))) {
  3255. SiS_Pr->SiS_LCDHDES = (PanelDesPtr+ResIndex)->LCDHDES;
  3256. SiS_Pr->SiS_LCDVDES = (PanelDesPtr+ResIndex)->LCDVDES;
  3257. } else if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  3258. if(SiS_Pr->SiS_VGAHDE != SiS_Pr->PanelXRes) {
  3259. SiS_Pr->SiS_LCDHDES = SiS_Pr->SiS_HT - ((SiS_Pr->PanelXRes - SiS_Pr->SiS_VGAHDE) / 2);
  3260. }
  3261. if(SiS_Pr->SiS_VGAVDE != SiS_Pr->PanelYRes) {
  3262. SiS_Pr->SiS_LCDVDES = SiS_Pr->SiS_VT - ((SiS_Pr->PanelYRes - SiS_Pr->SiS_VGAVDE) / 2);
  3263. } else {
  3264. if(SiS_Pr->ChipType < SIS_315H) {
  3265. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3266. } else {
  3267. switch(SiS_Pr->SiS_LCDResInfo) {
  3268. case Panel_800x600:
  3269. case Panel_1024x768:
  3270. case Panel_1280x1024:
  3271. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT;
  3272. break;
  3273. case Panel_1400x1050:
  3274. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3275. break;
  3276. }
  3277. }
  3278. }
  3279. } else {
  3280. if(SiS_Pr->ChipType < SIS_315H) {
  3281. #ifdef SIS300
  3282. switch(SiS_Pr->SiS_LCDResInfo) {
  3283. case Panel_800x600:
  3284. if(SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) {
  3285. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3286. } else {
  3287. SiS_Pr->SiS_LCDHDES = SiS_Pr->PanelHT + 3;
  3288. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT;
  3289. if(SiS_Pr->SiS_VGAVDE == 400) SiS_Pr->SiS_LCDVDES -= 2;
  3290. else SiS_Pr->SiS_LCDVDES -= 4;
  3291. }
  3292. break;
  3293. case Panel_1024x768:
  3294. if(SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) {
  3295. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3296. } else {
  3297. SiS_Pr->SiS_LCDHDES = SiS_Pr->PanelHT - 1;
  3298. if(SiS_Pr->SiS_VGAVDE <= 400) SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 8;
  3299. if(SiS_Pr->SiS_VGAVDE <= 350) SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 12;
  3300. }
  3301. break;
  3302. case Panel_1024x600:
  3303. default:
  3304. if( (SiS_Pr->SiS_VGAHDE == SiS_Pr->PanelXRes) &&
  3305. (SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) ) {
  3306. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3307. } else {
  3308. SiS_Pr->SiS_LCDHDES = SiS_Pr->PanelHT - 1;
  3309. }
  3310. break;
  3311. }
  3312. switch(SiS_Pr->SiS_LCDTypeInfo) {
  3313. case 1:
  3314. SiS_Pr->SiS_LCDHDES = SiS_Pr->SiS_LCDVDES = 0;
  3315. break;
  3316. case 3: /* 640x480 only? */
  3317. SiS_Pr->SiS_LCDHDES = 8;
  3318. if (SiS_Pr->SiS_VGAVDE >= 480) SiS_Pr->SiS_LCDVDES = 512;
  3319. else if(SiS_Pr->SiS_VGAVDE >= 400) SiS_Pr->SiS_LCDVDES = 436;
  3320. else if(SiS_Pr->SiS_VGAVDE >= 350) SiS_Pr->SiS_LCDVDES = 440;
  3321. break;
  3322. }
  3323. #endif
  3324. } else {
  3325. #ifdef SIS315H
  3326. switch(SiS_Pr->SiS_LCDResInfo) {
  3327. case Panel_1024x768:
  3328. case Panel_1280x1024:
  3329. if(SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) {
  3330. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3331. }
  3332. break;
  3333. case Panel_320x240_1:
  3334. case Panel_320x240_2:
  3335. case Panel_320x240_3:
  3336. SiS_Pr->SiS_LCDVDES = 524;
  3337. break;
  3338. }
  3339. #endif
  3340. }
  3341. }
  3342. if((ModeNo <= 0x13) && (SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
  3343. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  3344. if((SiS_Pr->SiS_VBType & VB_SIS30xBLV) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  3345. if(!(modeflag & HalfDCLK)) SiS_Pr->SiS_LCDHDES = 632;
  3346. } else if(!(SiS_Pr->SiS_SetFlag & SetDOSMode)) {
  3347. if(SiS_Pr->SiS_LCDResInfo != Panel_1280x1024) {
  3348. if(SiS_Pr->SiS_LCDResInfo >= Panel_1024x768) {
  3349. if(SiS_Pr->ChipType < SIS_315H) {
  3350. if(!(modeflag & HalfDCLK)) SiS_Pr->SiS_LCDHDES = 320;
  3351. } else {
  3352. #ifdef SIS315H
  3353. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) SiS_Pr->SiS_LCDHDES = 480;
  3354. if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) SiS_Pr->SiS_LCDHDES = 804;
  3355. if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) SiS_Pr->SiS_LCDHDES = 704;
  3356. if(!(modeflag & HalfDCLK)) {
  3357. SiS_Pr->SiS_LCDHDES = 320;
  3358. if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) SiS_Pr->SiS_LCDHDES = 632;
  3359. if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) SiS_Pr->SiS_LCDHDES = 542;
  3360. }
  3361. #endif
  3362. }
  3363. }
  3364. }
  3365. }
  3366. }
  3367. }
  3368. }
  3369. /*********************************************/
  3370. /* DISABLE VIDEO BRIDGE */
  3371. /*********************************************/
  3372. #ifdef SIS315H
  3373. static int
  3374. SiS_HandlePWD(struct SiS_Private *SiS_Pr)
  3375. {
  3376. int ret = 0;
  3377. #ifdef SET_PWD
  3378. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  3379. unsigned short romptr = GetLCDStructPtr661_2(SiS_Pr);
  3380. unsigned char drivermode = SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & 0x40;
  3381. unsigned short temp;
  3382. if( (SiS_Pr->SiS_VBType & VB_SISPWD) &&
  3383. (romptr) &&
  3384. (SiS_Pr->SiS_PWDOffset) ) {
  3385. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2b,ROMAddr[romptr + SiS_Pr->SiS_PWDOffset + 0]);
  3386. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2c,ROMAddr[romptr + SiS_Pr->SiS_PWDOffset + 1]);
  3387. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2d,ROMAddr[romptr + SiS_Pr->SiS_PWDOffset + 2]);
  3388. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2e,ROMAddr[romptr + SiS_Pr->SiS_PWDOffset + 3]);
  3389. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2f,ROMAddr[romptr + SiS_Pr->SiS_PWDOffset + 4]);
  3390. temp = 0x00;
  3391. if((ROMAddr[romptr + 2] & (0x06 << 1)) && !drivermode) {
  3392. temp = 0x80;
  3393. ret = 1;
  3394. }
  3395. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x27,0x7f,temp);
  3396. #ifdef SIS_XORG_XF86
  3397. #ifdef TWDEBUG
  3398. xf86DrvMsg(0, 0, "Setting PWD %x\n", temp);
  3399. #endif
  3400. #endif
  3401. }
  3402. #endif
  3403. return ret;
  3404. }
  3405. #endif
  3406. /* NEVER use any variables (VBInfo), this will be called
  3407. * from outside the context of modeswitch!
  3408. * MUST call getVBType before calling this
  3409. */
  3410. void
  3411. SiS_DisableBridge(struct SiS_Private *SiS_Pr)
  3412. {
  3413. #ifdef SIS315H
  3414. unsigned short tempah, pushax=0, modenum;
  3415. #endif
  3416. unsigned short temp=0;
  3417. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  3418. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) { /* ===== For 30xB/C/LV ===== */
  3419. if(SiS_Pr->ChipType < SIS_315H) {
  3420. #ifdef SIS300 /* 300 series */
  3421. if(!(SiS_CR36BIOSWord23b(SiS_Pr))) {
  3422. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3423. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFE);
  3424. } else {
  3425. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x08);
  3426. }
  3427. SiS_PanelDelay(SiS_Pr, 3);
  3428. }
  3429. if(SiS_Is301B(SiS_Pr)) {
  3430. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1f,0x3f);
  3431. SiS_ShortDelay(SiS_Pr,1);
  3432. }
  3433. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xDF);
  3434. SiS_DisplayOff(SiS_Pr);
  3435. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF);
  3436. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF);
  3437. SiS_UnLockCRT2(SiS_Pr);
  3438. if(!(SiS_Pr->SiS_VBType & VB_SISLVDS)) {
  3439. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x01,0x80);
  3440. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x02,0x40);
  3441. }
  3442. if( (!(SiS_CRT2IsLCD(SiS_Pr))) ||
  3443. (!(SiS_CR36BIOSWord23d(SiS_Pr))) ) {
  3444. SiS_PanelDelay(SiS_Pr, 2);
  3445. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3446. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFD);
  3447. } else {
  3448. SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x04);
  3449. }
  3450. }
  3451. #endif /* SIS300 */
  3452. } else {
  3453. #ifdef SIS315H /* 315 series */
  3454. int didpwd = 0;
  3455. BOOLEAN custom1 = ((SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) ||
  3456. (SiS_Pr->SiS_CustomT == CUT_CLEVO1400)) ? TRUE : FALSE;
  3457. modenum = SiS_GetReg(SiS_Pr->SiS_P3d4,0x34) & 0x7f;
  3458. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3459. #ifdef SET_EMI
  3460. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  3461. if(SiS_Pr->SiS_CustomT != CUT_CLEVO1400) {
  3462. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
  3463. }
  3464. }
  3465. #endif
  3466. didpwd = SiS_HandlePWD(SiS_Pr);
  3467. if( (modenum <= 0x13) ||
  3468. (SiS_IsVAMode(SiS_Pr)) ||
  3469. (!(SiS_IsDualEdge(SiS_Pr))) ) {
  3470. if(!didpwd) {
  3471. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xfe);
  3472. if(custom1) SiS_PanelDelay(SiS_Pr, 3);
  3473. } else {
  3474. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xfc);
  3475. }
  3476. }
  3477. if(!custom1) {
  3478. SiS_DDC2Delay(SiS_Pr,0xff00);
  3479. SiS_DDC2Delay(SiS_Pr,0xe000);
  3480. SiS_SetRegByte(SiS_Pr->SiS_P3c6,0x00);
  3481. pushax = SiS_GetReg(SiS_Pr->SiS_P3c4,0x06);
  3482. if(IS_SIS740) {
  3483. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x06,0xE3);
  3484. }
  3485. SiS_PanelDelay(SiS_Pr, 3);
  3486. }
  3487. }
  3488. if(!(SiS_IsNotM650orLater(SiS_Pr))) {
  3489. /* if(SiS_Pr->ChipType < SIS_340) {*/
  3490. tempah = 0xef;
  3491. if(SiS_IsVAMode(SiS_Pr)) tempah = 0xf7;
  3492. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x4c,tempah);
  3493. /*}*/
  3494. }
  3495. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3496. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1F,~0x10);
  3497. }
  3498. tempah = 0x3f;
  3499. if(SiS_IsDualEdge(SiS_Pr)) {
  3500. tempah = 0x7f;
  3501. if(!(SiS_IsVAMode(SiS_Pr))) tempah = 0xbf;
  3502. }
  3503. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1F,tempah);
  3504. if((SiS_IsVAMode(SiS_Pr)) ||
  3505. ((SiS_Pr->SiS_VBType & VB_SISLVDS) && (modenum <= 0x13))) {
  3506. SiS_DisplayOff(SiS_Pr);
  3507. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3508. SiS_PanelDelay(SiS_Pr, 2);
  3509. }
  3510. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF);
  3511. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1E,0xDF);
  3512. }
  3513. if((!(SiS_IsVAMode(SiS_Pr))) ||
  3514. ((SiS_Pr->SiS_VBType & VB_SISLVDS) && (modenum <= 0x13))) {
  3515. if(!(SiS_IsDualEdge(SiS_Pr))) {
  3516. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xdf);
  3517. SiS_DisplayOff(SiS_Pr);
  3518. }
  3519. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x80);
  3520. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3521. SiS_PanelDelay(SiS_Pr, 2);
  3522. }
  3523. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF);
  3524. temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00);
  3525. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x10);
  3526. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF);
  3527. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,temp);
  3528. }
  3529. if(SiS_IsNotM650orLater(SiS_Pr)) {
  3530. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0x7f);
  3531. }
  3532. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3533. if( (!(SiS_IsVAMode(SiS_Pr))) &&
  3534. (!(SiS_CRT2IsLCD(SiS_Pr))) &&
  3535. (!(SiS_IsDualEdge(SiS_Pr))) ) {
  3536. if(custom1) SiS_PanelDelay(SiS_Pr, 2);
  3537. if(!didpwd) {
  3538. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFD);
  3539. }
  3540. if(custom1) SiS_PanelDelay(SiS_Pr, 4);
  3541. }
  3542. if(!custom1) {
  3543. SiS_SetReg(SiS_Pr->SiS_P3c4,0x06,pushax);
  3544. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  3545. if(SiS_IsVAorLCD(SiS_Pr)) {
  3546. SiS_PanelDelayLoop(SiS_Pr, 3, 20);
  3547. }
  3548. }
  3549. }
  3550. }
  3551. #endif /* SIS315H */
  3552. }
  3553. } else { /* ============ For 301 ================ */
  3554. if(SiS_Pr->ChipType < SIS_315H) {
  3555. #ifdef SIS300
  3556. if(!(SiS_CR36BIOSWord23b(SiS_Pr))) {
  3557. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x08);
  3558. SiS_PanelDelay(SiS_Pr, 3);
  3559. }
  3560. #endif
  3561. }
  3562. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xDF); /* disable VB */
  3563. SiS_DisplayOff(SiS_Pr);
  3564. if(SiS_Pr->ChipType >= SIS_315H) {
  3565. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x80);
  3566. }
  3567. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF); /* disable lock mode */
  3568. if(SiS_Pr->ChipType >= SIS_315H) {
  3569. temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00);
  3570. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x10);
  3571. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);
  3572. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,temp);
  3573. } else {
  3574. #ifdef SIS300
  3575. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF); /* disable CRT2 */
  3576. if( (!(SiS_CRT2IsLCD(SiS_Pr))) ||
  3577. (!(SiS_CR36BIOSWord23d(SiS_Pr))) ) {
  3578. SiS_PanelDelay(SiS_Pr, 2);
  3579. SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x04);
  3580. }
  3581. #endif
  3582. }
  3583. }
  3584. } else { /* ============ For LVDS =============*/
  3585. if(SiS_Pr->ChipType < SIS_315H) {
  3586. #ifdef SIS300 /* 300 series */
  3587. if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) {
  3588. SiS_SetCH700x(SiS_Pr,0x0E,0x09);
  3589. }
  3590. if(SiS_Pr->ChipType == SIS_730) {
  3591. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x11) & 0x08)) {
  3592. SiS_WaitVBRetrace(SiS_Pr);
  3593. }
  3594. if(!(SiS_CR36BIOSWord23b(SiS_Pr))) {
  3595. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x08);
  3596. SiS_PanelDelay(SiS_Pr, 3);
  3597. }
  3598. } else {
  3599. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x11) & 0x08)) {
  3600. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x40)) {
  3601. if(!(SiS_CR36BIOSWord23b(SiS_Pr))) {
  3602. SiS_WaitVBRetrace(SiS_Pr);
  3603. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x06) & 0x1c)) {
  3604. SiS_DisplayOff(SiS_Pr);
  3605. }
  3606. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x08);
  3607. SiS_PanelDelay(SiS_Pr, 3);
  3608. }
  3609. }
  3610. }
  3611. }
  3612. SiS_DisplayOff(SiS_Pr);
  3613. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF);
  3614. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF);
  3615. SiS_UnLockCRT2(SiS_Pr);
  3616. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x01,0x80);
  3617. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x02,0x40);
  3618. if( (!(SiS_CRT2IsLCD(SiS_Pr))) ||
  3619. (!(SiS_CR36BIOSWord23d(SiS_Pr))) ) {
  3620. SiS_PanelDelay(SiS_Pr, 2);
  3621. SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x04);
  3622. }
  3623. #endif /* SIS300 */
  3624. } else {
  3625. #ifdef SIS315H /* 315 series */
  3626. if(!(SiS_IsNotM650orLater(SiS_Pr))) {
  3627. /*if(SiS_Pr->ChipType < SIS_340) { */ /* XGI needs this */
  3628. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x4c,~0x18);
  3629. /* } */
  3630. }
  3631. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  3632. if(SiS_Pr->ChipType == SIS_740) {
  3633. temp = SiS_GetCH701x(SiS_Pr,0x61);
  3634. if(temp < 1) {
  3635. SiS_SetCH701x(SiS_Pr,0x76,0xac);
  3636. SiS_SetCH701x(SiS_Pr,0x66,0x00);
  3637. }
  3638. if( (!(SiS_IsDualEdge(SiS_Pr))) ||
  3639. (SiS_IsTVOrYPbPrOrScart(SiS_Pr)) ) {
  3640. SiS_SetCH701x(SiS_Pr,0x49,0x3e);
  3641. }
  3642. }
  3643. if( (!(SiS_IsDualEdge(SiS_Pr))) ||
  3644. (SiS_IsVAMode(SiS_Pr)) ) {
  3645. SiS_Chrontel701xBLOff(SiS_Pr);
  3646. SiS_Chrontel701xOff(SiS_Pr);
  3647. }
  3648. if(SiS_Pr->ChipType != SIS_740) {
  3649. if( (!(SiS_IsDualEdge(SiS_Pr))) ||
  3650. (SiS_IsTVOrYPbPrOrScart(SiS_Pr)) ) {
  3651. SiS_SetCH701x(SiS_Pr,0x49,0x01);
  3652. }
  3653. }
  3654. }
  3655. if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
  3656. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x08);
  3657. SiS_PanelDelay(SiS_Pr, 3);
  3658. }
  3659. if( (SiS_Pr->SiS_IF_DEF_CH70xx == 0) ||
  3660. (!(SiS_IsDualEdge(SiS_Pr))) ||
  3661. (!(SiS_IsTVOrYPbPrOrScart(SiS_Pr))) ) {
  3662. SiS_DisplayOff(SiS_Pr);
  3663. }
  3664. if( (SiS_Pr->SiS_IF_DEF_CH70xx == 0) ||
  3665. (!(SiS_IsDualEdge(SiS_Pr))) ||
  3666. (!(SiS_IsVAMode(SiS_Pr))) ) {
  3667. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x80);
  3668. }
  3669. if(SiS_Pr->ChipType == SIS_740) {
  3670. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0x7f);
  3671. }
  3672. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF);
  3673. if( (SiS_Pr->SiS_IF_DEF_CH70xx == 0) ||
  3674. (!(SiS_IsDualEdge(SiS_Pr))) ||
  3675. (!(SiS_IsVAMode(SiS_Pr))) ) {
  3676. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF);
  3677. }
  3678. if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
  3679. if(SiS_CRT2IsLCD(SiS_Pr)) {
  3680. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xdf);
  3681. if(SiS_Pr->ChipType == SIS_550) {
  3682. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xbf);
  3683. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xef);
  3684. }
  3685. }
  3686. } else {
  3687. if(SiS_Pr->ChipType == SIS_740) {
  3688. if(SiS_IsLCDOrLCDA(SiS_Pr)) {
  3689. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xdf);
  3690. }
  3691. } else if(SiS_IsVAMode(SiS_Pr)) {
  3692. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xdf);
  3693. }
  3694. }
  3695. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  3696. if(SiS_IsDualEdge(SiS_Pr)) {
  3697. /* SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xff); */
  3698. } else {
  3699. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xfb);
  3700. }
  3701. }
  3702. SiS_UnLockCRT2(SiS_Pr);
  3703. if(SiS_Pr->ChipType == SIS_550) {
  3704. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x01,0x80); /* DirectDVD PAL?*/
  3705. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x02,0x40); /* VB clock / 4 ? */
  3706. } else if( (SiS_Pr->SiS_IF_DEF_CH70xx == 0) ||
  3707. (!(SiS_IsDualEdge(SiS_Pr))) ||
  3708. (!(SiS_IsVAMode(SiS_Pr))) ) {
  3709. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0xf7);
  3710. }
  3711. if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
  3712. if(SiS_CRT2IsLCD(SiS_Pr)) {
  3713. if(!(SiS_WeHaveBacklightCtrl(SiS_Pr))) {
  3714. SiS_PanelDelay(SiS_Pr, 2);
  3715. SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x04);
  3716. }
  3717. }
  3718. }
  3719. #endif /* SIS315H */
  3720. } /* 315 series */
  3721. } /* LVDS */
  3722. }
  3723. /*********************************************/
  3724. /* ENABLE VIDEO BRIDGE */
  3725. /*********************************************/
  3726. /* NEVER use any variables (VBInfo), this will be called
  3727. * from outside the context of a mode switch!
  3728. * MUST call getVBType before calling this
  3729. */
  3730. #ifdef SIS_LINUX_KERNEL
  3731. static
  3732. #endif
  3733. void
  3734. SiS_EnableBridge(struct SiS_Private *SiS_Pr)
  3735. {
  3736. unsigned short temp=0, tempah;
  3737. #ifdef SIS315H
  3738. unsigned short temp1, pushax=0;
  3739. BOOLEAN delaylong = FALSE;
  3740. #endif
  3741. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  3742. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) { /* ====== For 301B et al ====== */
  3743. if(SiS_Pr->ChipType < SIS_315H) {
  3744. #ifdef SIS300 /* 300 series */
  3745. if(SiS_CRT2IsLCD(SiS_Pr)) {
  3746. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3747. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x02);
  3748. } else if(SiS_Pr->SiS_VBType & VB_NoLCD) {
  3749. SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x00);
  3750. }
  3751. if(SiS_Pr->SiS_VBType & (VB_SISLVDS | VB_NoLCD)) {
  3752. if(!(SiS_CR36BIOSWord23d(SiS_Pr))) {
  3753. SiS_PanelDelay(SiS_Pr, 0);
  3754. }
  3755. }
  3756. }
  3757. if((SiS_Pr->SiS_VBType & VB_NoLCD) &&
  3758. (SiS_CRT2IsLCD(SiS_Pr))) {
  3759. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20); /* Enable CRT2 */
  3760. SiS_DisplayOn(SiS_Pr);
  3761. SiS_UnLockCRT2(SiS_Pr);
  3762. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x02,0xBF);
  3763. if(SiS_BridgeInSlavemode(SiS_Pr)) {
  3764. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x01,0x1F);
  3765. } else {
  3766. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x01,0x1F,0x40);
  3767. }
  3768. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x40)) {
  3769. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x16) & 0x10)) {
  3770. if(!(SiS_CR36BIOSWord23b(SiS_Pr))) {
  3771. SiS_PanelDelay(SiS_Pr, 1);
  3772. }
  3773. SiS_WaitVBRetrace(SiS_Pr);
  3774. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x00);
  3775. }
  3776. }
  3777. } else {
  3778. temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x32) & 0xDF; /* lock mode */
  3779. if(SiS_BridgeInSlavemode(SiS_Pr)) {
  3780. tempah = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  3781. if(!(tempah & SetCRT2ToRAMDAC)) temp |= 0x20;
  3782. }
  3783. SiS_SetReg(SiS_Pr->SiS_P3c4,0x32,temp);
  3784. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);
  3785. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x00,0x1F,0x20); /* enable VB processor */
  3786. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x1F,0xC0);
  3787. SiS_DisplayOn(SiS_Pr);
  3788. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3789. if(SiS_CRT2IsLCD(SiS_Pr)) {
  3790. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x16) & 0x10)) {
  3791. if(!(SiS_CR36BIOSWord23b(SiS_Pr))) {
  3792. SiS_PanelDelay(SiS_Pr, 1);
  3793. }
  3794. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x01);
  3795. }
  3796. }
  3797. }
  3798. }
  3799. #endif /* SIS300 */
  3800. } else {
  3801. #ifdef SIS315H /* 315 series */
  3802. #ifdef SET_EMI
  3803. unsigned char r30=0, r31=0, r32=0, r33=0, cr36=0;
  3804. int didpwd = 0;
  3805. /* unsigned short emidelay=0; */
  3806. #endif
  3807. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3808. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1f,0xef);
  3809. #ifdef SET_EMI
  3810. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  3811. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
  3812. }
  3813. #endif
  3814. }
  3815. if(!(SiS_IsNotM650orLater(SiS_Pr))) {
  3816. /*if(SiS_Pr->ChipType < SIS_340) { */
  3817. tempah = 0x10;
  3818. if(SiS_LCDAEnabled(SiS_Pr)) {
  3819. if(SiS_TVEnabled(SiS_Pr)) tempah = 0x18;
  3820. else tempah = 0x08;
  3821. }
  3822. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x4c,tempah);
  3823. /*}*/
  3824. }
  3825. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3826. SiS_SetRegByte(SiS_Pr->SiS_P3c6,0x00);
  3827. SiS_DisplayOff(SiS_Pr);
  3828. pushax = SiS_GetReg(SiS_Pr->SiS_P3c4,0x06);
  3829. if(IS_SIS740) {
  3830. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x06,0xE3);
  3831. }
  3832. didpwd = SiS_HandlePWD(SiS_Pr);
  3833. if(SiS_IsVAorLCD(SiS_Pr)) {
  3834. if(!didpwd) {
  3835. if(!(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x26) & 0x02)) {
  3836. SiS_PanelDelayLoop(SiS_Pr, 3, 2);
  3837. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x02);
  3838. SiS_PanelDelayLoop(SiS_Pr, 3, 2);
  3839. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  3840. SiS_GenericDelay(SiS_Pr, 17664);
  3841. }
  3842. }
  3843. } else {
  3844. SiS_PanelDelayLoop(SiS_Pr, 3, 2);
  3845. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  3846. SiS_GenericDelay(SiS_Pr, 17664);
  3847. }
  3848. }
  3849. }
  3850. if(!(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & 0x40)) {
  3851. SiS_PanelDelayLoop(SiS_Pr, 3, 10);
  3852. delaylong = TRUE;
  3853. }
  3854. }
  3855. if(!(SiS_IsVAMode(SiS_Pr))) {
  3856. temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x32) & 0xDF;
  3857. if(SiS_BridgeInSlavemode(SiS_Pr)) {
  3858. tempah = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  3859. if(!(tempah & SetCRT2ToRAMDAC)) {
  3860. if(!(SiS_LCDAEnabled(SiS_Pr))) temp |= 0x20;
  3861. }
  3862. }
  3863. SiS_SetReg(SiS_Pr->SiS_P3c4,0x32,temp);
  3864. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20); /* enable CRT2 */
  3865. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0x7f);
  3866. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2e,0x80);
  3867. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3868. SiS_PanelDelay(SiS_Pr, 2);
  3869. }
  3870. } else {
  3871. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1e,0x20);
  3872. }
  3873. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x00,0x1f,0x20);
  3874. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2e,0x80);
  3875. if(SiS_Pr->SiS_VBType & VB_SISPOWER) {
  3876. if( (SiS_LCDAEnabled(SiS_Pr)) ||
  3877. (SiS_CRT2IsLCD(SiS_Pr)) ) {
  3878. /* Enable "LVDS PLL power on" (even on 301C) */
  3879. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x2a,0x7f);
  3880. /* Enable "LVDS Driver Power on" (even on 301C) */
  3881. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x7f);
  3882. }
  3883. }
  3884. tempah = 0xc0;
  3885. if(SiS_IsDualEdge(SiS_Pr)) {
  3886. tempah = 0x80;
  3887. if(!(SiS_IsVAMode(SiS_Pr))) tempah = 0x40;
  3888. }
  3889. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x1F,tempah);
  3890. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3891. SiS_PanelDelay(SiS_Pr, 2);
  3892. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x1f,0x10);
  3893. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2e,0x80);
  3894. if(SiS_Pr->SiS_CustomT != CUT_CLEVO1400) {
  3895. #ifdef SET_EMI
  3896. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  3897. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
  3898. SiS_GenericDelay(SiS_Pr, 2048);
  3899. }
  3900. #endif
  3901. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x27,0x0c);
  3902. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  3903. #ifdef SET_EMI
  3904. cr36 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36);
  3905. if(SiS_Pr->SiS_ROMNew) {
  3906. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  3907. unsigned short romptr = GetLCDStructPtr661_2(SiS_Pr);
  3908. if(romptr) {
  3909. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x30,0x20); /* Reset */
  3910. SiS_Pr->EMI_30 = 0;
  3911. SiS_Pr->EMI_31 = ROMAddr[romptr + SiS_Pr->SiS_EMIOffset + 0];
  3912. SiS_Pr->EMI_32 = ROMAddr[romptr + SiS_Pr->SiS_EMIOffset + 1];
  3913. SiS_Pr->EMI_33 = ROMAddr[romptr + SiS_Pr->SiS_EMIOffset + 2];
  3914. if(ROMAddr[romptr + 1] & 0x10) SiS_Pr->EMI_30 = 0x40;
  3915. /* emidelay = SISGETROMW((romptr + 0x22)); */
  3916. SiS_Pr->HaveEMI = SiS_Pr->HaveEMILCD = SiS_Pr->OverruleEMI = TRUE;
  3917. }
  3918. }
  3919. /* (P4_30|0x40) */
  3920. /* Compal 1400x1050: 0x05, 0x60, 0x00 YES (1.10.7w; CR36=69) */
  3921. /* Compal 1400x1050: 0x0d, 0x70, 0x40 YES (1.10.7x; CR36=69) */
  3922. /* Acer 1280x1024: 0x12, 0xd0, 0x6b NO (1.10.9k; CR36=73) */
  3923. /* Compaq 1280x1024: 0x0d, 0x70, 0x6b YES (1.12.04b; CR36=03) */
  3924. /* Clevo 1024x768: 0x05, 0x60, 0x33 NO (1.10.8e; CR36=12, DL!) */
  3925. /* Clevo 1024x768: 0x0d, 0x70, 0x40 (if type == 3) YES (1.10.8y; CR36=?2) */
  3926. /* Clevo 1024x768: 0x05, 0x60, 0x33 (if type != 3) YES (1.10.8y; CR36=?2) */
  3927. /* Asus 1024x768: ? ? (1.10.8o; CR36=?2) */
  3928. /* Asus 1024x768: 0x08, 0x10, 0x3c (problematic) YES (1.10.8q; CR36=22) */
  3929. if(SiS_Pr->HaveEMI) {
  3930. r30 = SiS_Pr->EMI_30; r31 = SiS_Pr->EMI_31;
  3931. r32 = SiS_Pr->EMI_32; r33 = SiS_Pr->EMI_33;
  3932. } else {
  3933. r30 = 0;
  3934. }
  3935. /* EMI_30 is read at driver start; however, the BIOS sets this
  3936. * (if it is used) only if the LCD is in use. In case we caught
  3937. * the machine while on TV output, this bit is not set and we
  3938. * don't know if it should be set - hence our detection is wrong.
  3939. * Work-around this here:
  3940. */
  3941. if((!SiS_Pr->HaveEMI) || (!SiS_Pr->HaveEMILCD)) {
  3942. switch((cr36 & 0x0f)) {
  3943. case 2:
  3944. r30 |= 0x40;
  3945. if(SiS_Pr->SiS_CustomT == CUT_CLEVO1024) r30 &= ~0x40;
  3946. if(!SiS_Pr->HaveEMI) {
  3947. r31 = 0x05; r32 = 0x60; r33 = 0x33;
  3948. if((cr36 & 0xf0) == 0x30) {
  3949. r31 = 0x0d; r32 = 0x70; r33 = 0x40;
  3950. }
  3951. }
  3952. break;
  3953. case 3: /* 1280x1024 */
  3954. if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) r30 |= 0x40;
  3955. if(!SiS_Pr->HaveEMI) {
  3956. r31 = 0x12; r32 = 0xd0; r33 = 0x6b;
  3957. if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) {
  3958. r31 = 0x0d; r32 = 0x70; r33 = 0x6b;
  3959. }
  3960. }
  3961. break;
  3962. case 9: /* 1400x1050 */
  3963. r30 |= 0x40;
  3964. if(!SiS_Pr->HaveEMI) {
  3965. r31 = 0x05; r32 = 0x60; r33 = 0x00;
  3966. if(SiS_Pr->SiS_CustomT == CUT_COMPAL1400_2) {
  3967. r31 = 0x0d; r32 = 0x70; r33 = 0x40; /* BIOS values */
  3968. }
  3969. }
  3970. break;
  3971. case 11: /* 1600x1200 - unknown */
  3972. r30 |= 0x40;
  3973. if(!SiS_Pr->HaveEMI) {
  3974. r31 = 0x05; r32 = 0x60; r33 = 0x00;
  3975. }
  3976. }
  3977. }
  3978. /* BIOS values don't work so well sometimes */
  3979. if(!SiS_Pr->OverruleEMI) {
  3980. #ifdef COMPAL_HACK
  3981. if(SiS_Pr->SiS_CustomT == CUT_COMPAL1400_2) {
  3982. if((cr36 & 0x0f) == 0x09) {
  3983. r30 = 0x60; r31 = 0x05; r32 = 0x60; r33 = 0x00;
  3984. }
  3985. }
  3986. #endif
  3987. #ifdef COMPAQ_HACK
  3988. if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) {
  3989. if((cr36 & 0x0f) == 0x03) {
  3990. r30 = 0x20; r31 = 0x12; r32 = 0xd0; r33 = 0x6b;
  3991. }
  3992. }
  3993. #endif
  3994. #ifdef ASUS_HACK
  3995. if(SiS_Pr->SiS_CustomT == CUT_ASUSA2H_2) {
  3996. if((cr36 & 0x0f) == 0x02) {
  3997. /* r30 = 0x60; r31 = 0x05; r32 = 0x60; r33 = 0x33; */ /* rev 2 */
  3998. /* r30 = 0x20; r31 = 0x05; r32 = 0x60; r33 = 0x33; */ /* rev 3 */
  3999. /* r30 = 0x60; r31 = 0x0d; r32 = 0x70; r33 = 0x40; */ /* rev 4 */
  4000. /* r30 = 0x20; r31 = 0x0d; r32 = 0x70; r33 = 0x40; */ /* rev 5 */
  4001. }
  4002. }
  4003. #endif
  4004. }
  4005. if(!(SiS_Pr->OverruleEMI && (!r30) && (!r31) && (!r32) && (!r33))) {
  4006. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x30,0x20); /* Reset */
  4007. SiS_GenericDelay(SiS_Pr, 2048);
  4008. }
  4009. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x31,r31);
  4010. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x32,r32);
  4011. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x33,r33);
  4012. #endif /* SET_EMI */
  4013. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x34,0x10);
  4014. #ifdef SET_EMI
  4015. if( (SiS_LCDAEnabled(SiS_Pr)) ||
  4016. (SiS_CRT2IsLCD(SiS_Pr)) ) {
  4017. if(r30 & 0x40) {
  4018. /*SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x2a,0x80);*/
  4019. SiS_PanelDelayLoop(SiS_Pr, 3, 5);
  4020. if(delaylong) {
  4021. SiS_PanelDelayLoop(SiS_Pr, 3, 5);
  4022. delaylong = FALSE;
  4023. }
  4024. SiS_WaitVBRetrace(SiS_Pr);
  4025. SiS_WaitVBRetrace(SiS_Pr);
  4026. if(SiS_Pr->SiS_CustomT == CUT_ASUSA2H_2) {
  4027. SiS_GenericDelay(SiS_Pr, 1280);
  4028. }
  4029. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x30,0x40); /* Enable */
  4030. /*SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x2a,0x7f);*/
  4031. }
  4032. }
  4033. #endif
  4034. }
  4035. }
  4036. if(!(SiS_WeHaveBacklightCtrl(SiS_Pr))) {
  4037. if(SiS_IsVAorLCD(SiS_Pr)) {
  4038. SiS_PanelDelayLoop(SiS_Pr, 3, 10);
  4039. if(delaylong) {
  4040. SiS_PanelDelayLoop(SiS_Pr, 3, 10);
  4041. }
  4042. SiS_WaitVBRetrace(SiS_Pr);
  4043. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  4044. SiS_GenericDelay(SiS_Pr, 2048);
  4045. SiS_WaitVBRetrace(SiS_Pr);
  4046. }
  4047. if(!didpwd) {
  4048. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x01);
  4049. } else {
  4050. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x03);
  4051. }
  4052. }
  4053. }
  4054. SiS_SetReg(SiS_Pr->SiS_P3c4,0x06,pushax);
  4055. SiS_DisplayOn(SiS_Pr);
  4056. SiS_SetRegByte(SiS_Pr->SiS_P3c6,0xff);
  4057. }
  4058. if(!(SiS_WeHaveBacklightCtrl(SiS_Pr))) {
  4059. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x00,0x7f);
  4060. }
  4061. #endif /* SIS315H */
  4062. }
  4063. } else { /* ============ For 301 ================ */
  4064. if(SiS_Pr->ChipType < SIS_315H) {
  4065. if(SiS_CRT2IsLCD(SiS_Pr)) {
  4066. SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x00);
  4067. SiS_PanelDelay(SiS_Pr, 0);
  4068. }
  4069. }
  4070. temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x32) & 0xDF; /* lock mode */
  4071. if(SiS_BridgeInSlavemode(SiS_Pr)) {
  4072. tempah = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  4073. if(!(tempah & SetCRT2ToRAMDAC)) temp |= 0x20;
  4074. }
  4075. SiS_SetReg(SiS_Pr->SiS_P3c4,0x32,temp);
  4076. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20); /* enable CRT2 */
  4077. if(SiS_Pr->ChipType >= SIS_315H) {
  4078. temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x2E);
  4079. if(!(temp & 0x80)) {
  4080. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2E,0x80); /* BVBDOENABLE=1 */
  4081. }
  4082. }
  4083. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x00,0x1F,0x20); /* enable VB processor */
  4084. SiS_VBLongWait(SiS_Pr);
  4085. SiS_DisplayOn(SiS_Pr);
  4086. if(SiS_Pr->ChipType >= SIS_315H) {
  4087. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x00,0x7f);
  4088. }
  4089. SiS_VBLongWait(SiS_Pr);
  4090. if(SiS_Pr->ChipType < SIS_315H) {
  4091. if(SiS_CRT2IsLCD(SiS_Pr)) {
  4092. SiS_PanelDelay(SiS_Pr, 1);
  4093. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x00);
  4094. }
  4095. }
  4096. }
  4097. } else { /* =================== For LVDS ================== */
  4098. if(SiS_Pr->ChipType < SIS_315H) {
  4099. #ifdef SIS300 /* 300 series */
  4100. if(SiS_CRT2IsLCD(SiS_Pr)) {
  4101. if(SiS_Pr->ChipType == SIS_730) {
  4102. SiS_PanelDelay(SiS_Pr, 1);
  4103. SiS_PanelDelay(SiS_Pr, 1);
  4104. SiS_PanelDelay(SiS_Pr, 1);
  4105. }
  4106. SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x00);
  4107. if(!(SiS_CR36BIOSWord23d(SiS_Pr))) {
  4108. SiS_PanelDelay(SiS_Pr, 0);
  4109. }
  4110. }
  4111. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);
  4112. SiS_DisplayOn(SiS_Pr);
  4113. SiS_UnLockCRT2(SiS_Pr);
  4114. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x02,0xBF);
  4115. if(SiS_BridgeInSlavemode(SiS_Pr)) {
  4116. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x01,0x1F);
  4117. } else {
  4118. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x01,0x1F,0x40);
  4119. }
  4120. if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) {
  4121. if(!(SiS_CRT2IsLCD(SiS_Pr))) {
  4122. SiS_WaitVBRetrace(SiS_Pr);
  4123. SiS_SetCH700x(SiS_Pr,0x0E,0x0B);
  4124. }
  4125. }
  4126. if(SiS_CRT2IsLCD(SiS_Pr)) {
  4127. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x40)) {
  4128. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x16) & 0x10)) {
  4129. if(!(SiS_CR36BIOSWord23b(SiS_Pr))) {
  4130. SiS_PanelDelay(SiS_Pr, 1);
  4131. SiS_PanelDelay(SiS_Pr, 1);
  4132. }
  4133. SiS_WaitVBRetrace(SiS_Pr);
  4134. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x00);
  4135. }
  4136. }
  4137. }
  4138. #endif /* SIS300 */
  4139. } else {
  4140. #ifdef SIS315H /* 315 series */
  4141. if(!(SiS_IsNotM650orLater(SiS_Pr))) {
  4142. /*if(SiS_Pr->ChipType < SIS_340) {*/ /* XGI needs this */
  4143. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x4c,0x18);
  4144. /*}*/
  4145. }
  4146. if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
  4147. if(SiS_CRT2IsLCD(SiS_Pr)) {
  4148. SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x00);
  4149. SiS_PanelDelay(SiS_Pr, 0);
  4150. }
  4151. }
  4152. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);
  4153. SiS_UnLockCRT2(SiS_Pr);
  4154. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0xf7);
  4155. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  4156. temp = SiS_GetCH701x(SiS_Pr,0x66);
  4157. temp &= 0x20;
  4158. SiS_Chrontel701xBLOff(SiS_Pr);
  4159. }
  4160. if(SiS_Pr->ChipType != SIS_550) {
  4161. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0x7f);
  4162. }
  4163. if(SiS_Pr->ChipType == SIS_740) {
  4164. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  4165. if(SiS_IsLCDOrLCDA(SiS_Pr)) {
  4166. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x20);
  4167. }
  4168. }
  4169. }
  4170. temp1 = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x2E);
  4171. if(!(temp1 & 0x80)) {
  4172. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2E,0x80);
  4173. }
  4174. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  4175. if(temp) {
  4176. SiS_Chrontel701xBLOn(SiS_Pr);
  4177. }
  4178. }
  4179. if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
  4180. if(SiS_CRT2IsLCD(SiS_Pr)) {
  4181. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x20);
  4182. if(SiS_Pr->ChipType == SIS_550) {
  4183. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x40);
  4184. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x10);
  4185. }
  4186. }
  4187. } else if(SiS_IsVAMode(SiS_Pr)) {
  4188. if(SiS_Pr->ChipType != SIS_740) {
  4189. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x20);
  4190. }
  4191. }
  4192. if(!(SiS_WeHaveBacklightCtrl(SiS_Pr))) {
  4193. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x00,0x7f);
  4194. }
  4195. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  4196. if(SiS_IsTVOrYPbPrOrScart(SiS_Pr)) {
  4197. SiS_Chrontel701xOn(SiS_Pr);
  4198. }
  4199. if( (SiS_IsVAMode(SiS_Pr)) ||
  4200. (SiS_IsLCDOrLCDA(SiS_Pr)) ) {
  4201. SiS_ChrontelDoSomething1(SiS_Pr);
  4202. }
  4203. }
  4204. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  4205. if(!(SiS_WeHaveBacklightCtrl(SiS_Pr))) {
  4206. if( (SiS_IsVAMode(SiS_Pr)) ||
  4207. (SiS_IsLCDOrLCDA(SiS_Pr)) ) {
  4208. SiS_Chrontel701xBLOn(SiS_Pr);
  4209. SiS_ChrontelInitTVVSync(SiS_Pr);
  4210. }
  4211. }
  4212. } else if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
  4213. if(!(SiS_WeHaveBacklightCtrl(SiS_Pr))) {
  4214. if(SiS_CRT2IsLCD(SiS_Pr)) {
  4215. SiS_PanelDelay(SiS_Pr, 1);
  4216. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x00);
  4217. }
  4218. }
  4219. }
  4220. #endif /* SIS315H */
  4221. } /* 310 series */
  4222. } /* LVDS */
  4223. }
  4224. /*********************************************/
  4225. /* SET PART 1 REGISTER GROUP */
  4226. /*********************************************/
  4227. /* Set CRT2 OFFSET / PITCH */
  4228. static void
  4229. SiS_SetCRT2Offset(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  4230. unsigned short RRTI)
  4231. {
  4232. unsigned short offset;
  4233. unsigned char temp;
  4234. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) return;
  4235. offset = SiS_GetOffset(SiS_Pr,ModeNo,ModeIdIndex,RRTI);
  4236. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x07,(offset & 0xFF));
  4237. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x09,(offset >> 8));
  4238. temp = (unsigned char)(((offset >> 3) & 0xFF) + 1);
  4239. if(offset & 0x07) temp++;
  4240. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x03,temp);
  4241. }
  4242. /* Set CRT2 sync and PanelLink mode */
  4243. static void
  4244. SiS_SetCRT2Sync(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short RefreshRateTableIndex)
  4245. {
  4246. unsigned short tempah=0, tempbl, infoflag;
  4247. tempbl = 0xC0;
  4248. if(SiS_Pr->UseCustomMode) {
  4249. infoflag = SiS_Pr->CInfoFlag;
  4250. } else {
  4251. infoflag = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
  4252. }
  4253. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { /* LVDS */
  4254. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  4255. tempah = 0;
  4256. } else if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && (SiS_Pr->SiS_LCDInfo & LCDSync)) {
  4257. tempah = SiS_Pr->SiS_LCDInfo;
  4258. } else tempah = infoflag >> 8;
  4259. tempah &= 0xC0;
  4260. tempah |= 0x20;
  4261. if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10;
  4262. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  4263. if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) ||
  4264. (SiS_Pr->SiS_CustomT == CUT_BARCO1024)) {
  4265. tempah |= 0xf0;
  4266. }
  4267. if( (SiS_Pr->SiS_IF_DEF_FSTN) ||
  4268. (SiS_Pr->SiS_IF_DEF_DSTN) ||
  4269. (SiS_Pr->SiS_IF_DEF_TRUMPION) ||
  4270. (SiS_Pr->SiS_CustomT == CUT_PANEL848) ||
  4271. (SiS_Pr->SiS_CustomT == CUT_PANEL856) ) {
  4272. tempah |= 0x30;
  4273. }
  4274. if( (SiS_Pr->SiS_IF_DEF_FSTN) ||
  4275. (SiS_Pr->SiS_IF_DEF_DSTN) ) {
  4276. tempah &= ~0xc0;
  4277. }
  4278. }
  4279. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  4280. if(SiS_Pr->ChipType >= SIS_315H) {
  4281. tempah >>= 3;
  4282. tempah &= 0x18;
  4283. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,0xE7,tempah);
  4284. /* Don't care about 12/18/24 bit mode - TV is via VGA, not PL */
  4285. } else {
  4286. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,0xe0);
  4287. }
  4288. } else {
  4289. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah);
  4290. }
  4291. } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
  4292. if(SiS_Pr->ChipType < SIS_315H) {
  4293. #ifdef SIS300 /* ---- 300 series --- */
  4294. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) { /* 630 - 301B(-DH) */
  4295. tempah = infoflag >> 8;
  4296. tempbl = 0;
  4297. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  4298. if(SiS_Pr->SiS_LCDInfo & LCDSync) {
  4299. tempah = SiS_Pr->SiS_LCDInfo;
  4300. tempbl = (tempah >> 6) & 0x03;
  4301. }
  4302. }
  4303. tempah &= 0xC0;
  4304. tempah |= 0x20;
  4305. if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10;
  4306. tempah |= 0xc0;
  4307. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah);
  4308. if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && (!(SiS_Pr->SiS_VBType & VB_NoLCD))) {
  4309. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1a,0xf0,tempbl);
  4310. }
  4311. } else { /* 630 - 301 */
  4312. tempah = ((infoflag >> 8) & 0xc0) | 0x20;
  4313. if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10;
  4314. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah);
  4315. }
  4316. #endif /* SIS300 */
  4317. } else {
  4318. #ifdef SIS315H /* ------- 315 series ------ */
  4319. if(SiS_Pr->SiS_VBType & VB_SISLVDS) { /* 315 - LVDS */
  4320. tempbl = 0;
  4321. if((SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) &&
  4322. (SiS_Pr->SiS_LCDResInfo == Panel_1280x1024)) {
  4323. tempah = infoflag >> 8;
  4324. if(SiS_Pr->SiS_LCDInfo & LCDSync) {
  4325. tempbl = ((SiS_Pr->SiS_LCDInfo & 0xc0) >> 6);
  4326. }
  4327. } else if((SiS_Pr->SiS_CustomT == CUT_CLEVO1400) &&
  4328. (SiS_Pr->SiS_LCDResInfo == Panel_1400x1050)) {
  4329. tempah = infoflag >> 8;
  4330. tempbl = 0x03;
  4331. } else {
  4332. tempah = SiS_GetReg(SiS_Pr->SiS_P3d4,0x37);
  4333. tempbl = (tempah >> 6) & 0x03;
  4334. tempbl |= 0x08;
  4335. if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempbl |= 0x04;
  4336. }
  4337. tempah &= 0xC0;
  4338. tempah |= 0x20;
  4339. if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10;
  4340. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) tempah |= 0xc0;
  4341. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah);
  4342. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  4343. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  4344. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1a,0xf0,tempbl);
  4345. }
  4346. }
  4347. } else { /* 315 - TMDS */
  4348. tempah = tempbl = infoflag >> 8;
  4349. if(!SiS_Pr->UseCustomMode) {
  4350. tempbl = 0;
  4351. if((SiS_Pr->SiS_VBType & VB_SIS30xC) && (SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) {
  4352. if(ModeNo <= 0x13) {
  4353. tempah = SiS_GetRegByte((SiS_Pr->SiS_P3ca+0x02));
  4354. }
  4355. }
  4356. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4357. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  4358. if(SiS_Pr->SiS_LCDInfo & LCDSync) {
  4359. tempah = SiS_Pr->SiS_LCDInfo;
  4360. tempbl = (tempah >> 6) & 0x03;
  4361. }
  4362. }
  4363. }
  4364. }
  4365. tempah &= 0xC0;
  4366. tempah |= 0x20;
  4367. if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10;
  4368. if(SiS_Pr->SiS_VBType & VB_NoLCD) {
  4369. /* Imitate BIOS bug */
  4370. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) tempah |= 0xc0;
  4371. }
  4372. if((SiS_Pr->SiS_VBType & VB_SIS30xC) && (SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) {
  4373. tempah >>= 3;
  4374. tempah &= 0x18;
  4375. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,0xe7,tempah);
  4376. } else {
  4377. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah);
  4378. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  4379. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  4380. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1a,0xf0,tempbl);
  4381. }
  4382. }
  4383. }
  4384. }
  4385. #endif /* SIS315H */
  4386. }
  4387. }
  4388. }
  4389. /* Set CRT2 FIFO on 300/540/630/730 */
  4390. #ifdef SIS300
  4391. static void
  4392. SiS_SetCRT2FIFO_300(struct SiS_Private *SiS_Pr,unsigned short ModeNo)
  4393. {
  4394. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  4395. unsigned short temp, index, modeidindex, refreshratetableindex;
  4396. unsigned short VCLK = 0, MCLK, colorth = 0, data2 = 0;
  4397. unsigned short tempbx, tempcl, CRT1ModeNo, CRT2ModeNo, SelectRate_backup;
  4398. unsigned int data, pci50, pciA0;
  4399. static const unsigned char colortharray[] = {
  4400. 1, 1, 2, 2, 3, 4
  4401. };
  4402. SelectRate_backup = SiS_Pr->SiS_SelectCRT2Rate;
  4403. if(!SiS_Pr->CRT1UsesCustomMode) {
  4404. CRT1ModeNo = SiS_Pr->SiS_CRT1Mode; /* get CRT1 ModeNo */
  4405. SiS_SearchModeID(SiS_Pr, &CRT1ModeNo, &modeidindex);
  4406. SiS_Pr->SiS_SetFlag &= (~ProgrammingCRT2);
  4407. SiS_Pr->SiS_SelectCRT2Rate = 0;
  4408. refreshratetableindex = SiS_GetRatePtr(SiS_Pr, CRT1ModeNo, modeidindex);
  4409. if(CRT1ModeNo >= 0x13) {
  4410. /* Get VCLK */
  4411. index = SiS_GetRefCRTVCLK(SiS_Pr, refreshratetableindex, SiS_Pr->SiS_UseWide);
  4412. VCLK = SiS_Pr->SiS_VCLKData[index].CLOCK;
  4413. /* Get colordepth */
  4414. colorth = SiS_GetColorDepth(SiS_Pr,CRT1ModeNo,modeidindex) >> 1;
  4415. if(!colorth) colorth++;
  4416. }
  4417. } else {
  4418. CRT1ModeNo = 0xfe;
  4419. /* Get VCLK */
  4420. VCLK = SiS_Pr->CSRClock_CRT1;
  4421. /* Get color depth */
  4422. colorth = colortharray[((SiS_Pr->CModeFlag_CRT1 & ModeTypeMask) - 2)];
  4423. }
  4424. if(CRT1ModeNo >= 0x13) {
  4425. /* Get MCLK */
  4426. if(SiS_Pr->ChipType == SIS_300) {
  4427. index = SiS_GetReg(SiS_Pr->SiS_P3c4,0x3A);
  4428. } else {
  4429. index = SiS_GetReg(SiS_Pr->SiS_P3c4,0x1A);
  4430. }
  4431. index &= 0x07;
  4432. MCLK = SiS_Pr->SiS_MCLKData_0[index].CLOCK;
  4433. temp = ((SiS_GetReg(SiS_Pr->SiS_P3c4,0x14) >> 6) & 0x03) << 1;
  4434. if(!temp) temp++;
  4435. temp <<= 2;
  4436. data2 = temp - ((colorth * VCLK) / MCLK);
  4437. temp = (28 * 16) % data2;
  4438. data2 = (28 * 16) / data2;
  4439. if(temp) data2++;
  4440. if(SiS_Pr->ChipType == SIS_300) {
  4441. SiS_GetFIFOThresholdIndex300(SiS_Pr, &tempbx, &tempcl);
  4442. data = SiS_GetFIFOThresholdB300(tempbx, tempcl);
  4443. } else {
  4444. #ifdef SIS_LINUX_KERNEL
  4445. pci50 = sisfb_read_nbridge_pci_dword(SiS_Pr, 0x50);
  4446. pciA0 = sisfb_read_nbridge_pci_dword(SiS_Pr, 0xa0);
  4447. #else
  4448. pci50 = pciReadLong(0x00000000, 0x50);
  4449. pciA0 = pciReadLong(0x00000000, 0xA0);
  4450. #endif
  4451. if(SiS_Pr->ChipType == SIS_730) {
  4452. index = (unsigned short)(((pciA0 >> 28) & 0x0f) * 3);
  4453. index += (unsigned short)(((pci50 >> 9)) & 0x03);
  4454. /* BIOS BUG (2.04.5d, 2.04.6a use ah here, which is unset!) */
  4455. index = 0; /* -- do it like the BIOS anyway... */
  4456. } else {
  4457. pci50 >>= 24;
  4458. pciA0 >>= 24;
  4459. index = (pci50 >> 1) & 0x07;
  4460. if(pci50 & 0x01) index += 6;
  4461. if(!(pciA0 & 0x01)) index += 24;
  4462. if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x14) & 0x80) index += 12;
  4463. }
  4464. data = SiS_GetLatencyFactor630(SiS_Pr, index) + 15;
  4465. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x14) & 0x80)) data += 5;
  4466. }
  4467. data += data2; /* CRT1 Request Period */
  4468. SiS_Pr->SiS_SetFlag |= ProgrammingCRT2;
  4469. SiS_Pr->SiS_SelectCRT2Rate = SelectRate_backup;
  4470. if(!SiS_Pr->UseCustomMode) {
  4471. CRT2ModeNo = ModeNo;
  4472. SiS_SearchModeID(SiS_Pr, &CRT2ModeNo, &modeidindex);
  4473. refreshratetableindex = SiS_GetRatePtr(SiS_Pr, CRT2ModeNo, modeidindex);
  4474. /* Get VCLK */
  4475. index = SiS_GetVCLK2Ptr(SiS_Pr, CRT2ModeNo, modeidindex, refreshratetableindex);
  4476. VCLK = SiS_Pr->SiS_VCLKData[index].CLOCK;
  4477. if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) || (SiS_Pr->SiS_CustomT == CUT_BARCO1024)) {
  4478. if(SiS_Pr->SiS_UseROM) {
  4479. if(ROMAddr[0x220] & 0x01) {
  4480. VCLK = ROMAddr[0x229] | (ROMAddr[0x22a] << 8);
  4481. }
  4482. }
  4483. }
  4484. } else {
  4485. /* Get VCLK */
  4486. CRT2ModeNo = 0xfe;
  4487. VCLK = SiS_Pr->CSRClock;
  4488. }
  4489. /* Get colordepth */
  4490. colorth = SiS_GetColorDepth(SiS_Pr,CRT2ModeNo,modeidindex) >> 1;
  4491. if(!colorth) colorth++;
  4492. data = data * VCLK * colorth;
  4493. temp = data % (MCLK << 4);
  4494. data = data / (MCLK << 4);
  4495. if(temp) data++;
  4496. if(data < 6) data = 6;
  4497. else if(data > 0x14) data = 0x14;
  4498. if(SiS_Pr->ChipType == SIS_300) {
  4499. temp = 0x16;
  4500. if((data <= 0x0f) || (SiS_Pr->SiS_LCDResInfo == Panel_1280x1024))
  4501. temp = 0x13;
  4502. } else {
  4503. temp = 0x16;
  4504. if(( (SiS_Pr->ChipType == SIS_630) ||
  4505. (SiS_Pr->ChipType == SIS_730) ) &&
  4506. (SiS_Pr->ChipRevision >= 0x30))
  4507. temp = 0x1b;
  4508. }
  4509. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x01,0xe0,temp);
  4510. if((SiS_Pr->ChipType == SIS_630) &&
  4511. (SiS_Pr->ChipRevision >= 0x30)) {
  4512. if(data > 0x13) data = 0x13;
  4513. }
  4514. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x02,0xe0,data);
  4515. } else { /* If mode <= 0x13, we just restore everything */
  4516. SiS_Pr->SiS_SetFlag |= ProgrammingCRT2;
  4517. SiS_Pr->SiS_SelectCRT2Rate = SelectRate_backup;
  4518. }
  4519. }
  4520. #endif
  4521. /* Set CRT2 FIFO on 315/330 series */
  4522. #ifdef SIS315H
  4523. static void
  4524. SiS_SetCRT2FIFO_310(struct SiS_Private *SiS_Pr)
  4525. {
  4526. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x01,0x3B);
  4527. if( (SiS_Pr->ChipType == SIS_760) &&
  4528. (SiS_Pr->SiS_SysFlags & SF_760LFB) &&
  4529. (SiS_Pr->SiS_ModeType == Mode32Bpp) &&
  4530. (SiS_Pr->SiS_VGAHDE >= 1280) &&
  4531. (SiS_Pr->SiS_VGAVDE >= 1024) ) {
  4532. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2f,0x03);
  4533. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x01,0x3b);
  4534. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x4d,0xc0);
  4535. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2f,0x01);
  4536. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x4d,0xc0);
  4537. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x02,0x6e);
  4538. } else {
  4539. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x02,~0x3f,0x04);
  4540. }
  4541. }
  4542. #endif
  4543. static unsigned short
  4544. SiS_GetVGAHT2(struct SiS_Private *SiS_Pr)
  4545. {
  4546. unsigned int tempax,tempbx;
  4547. tempbx = (SiS_Pr->SiS_VGAVT - SiS_Pr->SiS_VGAVDE) * SiS_Pr->SiS_RVBHCMAX;
  4548. tempax = (SiS_Pr->SiS_VT - SiS_Pr->SiS_VDE) * SiS_Pr->SiS_RVBHCFACT;
  4549. tempax = (tempax * SiS_Pr->SiS_HT) / tempbx;
  4550. return (unsigned short)tempax;
  4551. }
  4552. /* Set Part 1 / SiS bridge slave mode */
  4553. static void
  4554. SiS_SetGroup1_301(struct SiS_Private *SiS_Pr, unsigned short ModeNo,unsigned short ModeIdIndex,
  4555. unsigned short RefreshRateTableIndex)
  4556. {
  4557. unsigned short temp, modeflag, i, j, xres=0, VGAVDE;
  4558. static const unsigned short CRTranslation[] = {
  4559. /* CR0 CR1 CR2 CR3 CR4 CR5 CR6 CR7 */
  4560. 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a,
  4561. /* CR8 CR9 SR0A SR0B SR0C SR0D SR0E CR0F */
  4562. 0x00, 0x0b, 0x17, 0x18, 0x19, 0x00, 0x1a, 0x00,
  4563. /* CR10 CR11 CR12 CR13 CR14 CR15 CR16 CR17 */
  4564. 0x0c, 0x0d, 0x0e, 0x00, 0x0f, 0x10, 0x11, 0x00
  4565. };
  4566. if(ModeNo <= 0x13) {
  4567. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  4568. } else if(SiS_Pr->UseCustomMode) {
  4569. modeflag = SiS_Pr->CModeFlag;
  4570. xres = SiS_Pr->CHDisplay;
  4571. } else {
  4572. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  4573. xres = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].XRes;
  4574. }
  4575. /* The following is only done if bridge is in slave mode: */
  4576. if(SiS_Pr->ChipType >= SIS_315H) {
  4577. if(xres >= 1600) { /* BIOS: == 1600 */
  4578. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x31,0x04);
  4579. }
  4580. }
  4581. SiS_Pr->CHTotal = 8224; /* Max HT, 0x2020, results in 0x3ff in registers */
  4582. SiS_Pr->CHDisplay = SiS_Pr->SiS_VGAHDE;
  4583. if(modeflag & HalfDCLK) SiS_Pr->CHDisplay >>= 1;
  4584. SiS_Pr->CHBlankStart = SiS_Pr->CHDisplay;
  4585. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  4586. SiS_Pr->CHBlankStart += 16;
  4587. }
  4588. SiS_Pr->CHBlankEnd = 32;
  4589. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  4590. if(xres == 1600) SiS_Pr->CHBlankEnd += 80;
  4591. }
  4592. temp = SiS_Pr->SiS_VGAHT - 96;
  4593. if(!(modeflag & HalfDCLK)) temp -= 32;
  4594. if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
  4595. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x04);
  4596. temp |= ((SiS_GetReg(SiS_Pr->SiS_P3c4,0x0b) & 0xc0) << 2);
  4597. temp -= 3;
  4598. temp <<= 3;
  4599. } else {
  4600. if(SiS_Pr->SiS_RVBHRS2) temp = SiS_Pr->SiS_RVBHRS2;
  4601. }
  4602. SiS_Pr->CHSyncStart = temp;
  4603. SiS_Pr->CHSyncEnd = 0xffe8; /* results in 0x2000 in registers */
  4604. SiS_Pr->CVTotal = 2049; /* Max VT, 0x0801, results in 0x7ff in registers */
  4605. VGAVDE = SiS_Pr->SiS_VGAVDE;
  4606. if (VGAVDE == 357) VGAVDE = 350;
  4607. else if(VGAVDE == 360) VGAVDE = 350;
  4608. else if(VGAVDE == 375) VGAVDE = 350;
  4609. else if(VGAVDE == 405) VGAVDE = 400;
  4610. else if(VGAVDE == 420) VGAVDE = 400;
  4611. else if(VGAVDE == 525) VGAVDE = 480;
  4612. else if(VGAVDE == 1056) VGAVDE = 1024;
  4613. SiS_Pr->CVDisplay = VGAVDE;
  4614. SiS_Pr->CVBlankStart = SiS_Pr->CVDisplay;
  4615. SiS_Pr->CVBlankEnd = 1;
  4616. if(ModeNo == 0x3c) SiS_Pr->CVBlankEnd = 226;
  4617. temp = (SiS_Pr->SiS_VGAVT - VGAVDE) >> 1;
  4618. SiS_Pr->CVSyncStart = VGAVDE + temp;
  4619. temp >>= 3;
  4620. SiS_Pr->CVSyncEnd = SiS_Pr->CVSyncStart + temp;
  4621. SiS_CalcCRRegisters(SiS_Pr, 0);
  4622. SiS_Pr->CCRT1CRTC[16] &= ~0xE0;
  4623. for(i = 0; i <= 7; i++) {
  4624. SiS_SetReg(SiS_Pr->SiS_Part1Port,CRTranslation[i],SiS_Pr->CCRT1CRTC[i]);
  4625. }
  4626. for(i = 0x10, j = 8; i <= 0x12; i++, j++) {
  4627. SiS_SetReg(SiS_Pr->SiS_Part1Port,CRTranslation[i],SiS_Pr->CCRT1CRTC[j]);
  4628. }
  4629. for(i = 0x15, j = 11; i <= 0x16; i++, j++) {
  4630. SiS_SetReg(SiS_Pr->SiS_Part1Port,CRTranslation[i],SiS_Pr->CCRT1CRTC[j]);
  4631. }
  4632. for(i = 0x0a, j = 13; i <= 0x0c; i++, j++) {
  4633. SiS_SetReg(SiS_Pr->SiS_Part1Port,CRTranslation[i],SiS_Pr->CCRT1CRTC[j]);
  4634. }
  4635. temp = SiS_Pr->CCRT1CRTC[16] & 0xE0;
  4636. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,CRTranslation[0x0E],0x1F,temp);
  4637. temp = (SiS_Pr->CCRT1CRTC[16] & 0x01) << 5;
  4638. if(modeflag & DoubleScanMode) temp |= 0x80;
  4639. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,CRTranslation[0x09],0x5F,temp);
  4640. temp = 0;
  4641. temp |= (SiS_GetReg(SiS_Pr->SiS_P3c4,0x01) & 0x01);
  4642. if(modeflag & HalfDCLK) temp |= 0x08;
  4643. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x16,temp); /* SR01: HalfDCLK[3], 8/9 div dotclock[0] */
  4644. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0F,0x00); /* CR14: (text mode: underline location) */
  4645. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x12,0x00); /* CR17: n/a */
  4646. temp = 0;
  4647. if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) {
  4648. temp = (SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x01) << 7;
  4649. }
  4650. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1A,temp); /* SR0E, dither[7] */
  4651. temp = SiS_GetRegByte((SiS_Pr->SiS_P3ca+0x02));
  4652. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,temp); /* ? */
  4653. #ifdef SIS_XORG_XF86
  4654. #ifdef TWDEBUG
  4655. xf86DrvMsg(0, X_INFO, "%d %d %d %d %d %d %d %d (%d %d %d %d)\n",
  4656. SiS_Pr->CHDisplay, SiS_Pr->CHSyncStart, SiS_Pr->CHSyncEnd, SiS_Pr->CHTotal,
  4657. SiS_Pr->CVDisplay, SiS_Pr->CVSyncStart, SiS_Pr->CVSyncEnd, SiS_Pr->CVTotal,
  4658. SiS_Pr->CHBlankStart, SiS_Pr->CHBlankEnd, SiS_Pr->CVBlankStart, SiS_Pr->CVBlankEnd);
  4659. xf86DrvMsg(0, X_INFO, " {{0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,\n",
  4660. SiS_Pr->CCRT1CRTC[0], SiS_Pr->CCRT1CRTC[1],
  4661. SiS_Pr->CCRT1CRTC[2], SiS_Pr->CCRT1CRTC[3],
  4662. SiS_Pr->CCRT1CRTC[4], SiS_Pr->CCRT1CRTC[5],
  4663. SiS_Pr->CCRT1CRTC[6], SiS_Pr->CCRT1CRTC[7]);
  4664. xf86DrvMsg(0, X_INFO, " 0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,\n",
  4665. SiS_Pr->CCRT1CRTC[8], SiS_Pr->CCRT1CRTC[9],
  4666. SiS_Pr->CCRT1CRTC[10], SiS_Pr->CCRT1CRTC[11],
  4667. SiS_Pr->CCRT1CRTC[12], SiS_Pr->CCRT1CRTC[13],
  4668. SiS_Pr->CCRT1CRTC[14], SiS_Pr->CCRT1CRTC[15]);
  4669. xf86DrvMsg(0, X_INFO, " 0x%02x}},\n", SiS_Pr->CCRT1CRTC[16]);
  4670. #endif
  4671. #endif
  4672. }
  4673. /* Setup panel link
  4674. * This is used for LVDS, LCDA and Chrontel TV output
  4675. * 300/LVDS+TV, 300/301B-DH, 315/LVDS+TV, 315/LCDA
  4676. */
  4677. static void
  4678. SiS_SetGroup1_LVDS(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  4679. unsigned short RefreshRateTableIndex)
  4680. {
  4681. unsigned short modeflag, resinfo = 0;
  4682. unsigned short push2, tempax, tempbx, tempcx, temp;
  4683. unsigned int tempeax = 0, tempebx, tempecx, tempvcfact = 0;
  4684. BOOLEAN islvds = FALSE, issis = FALSE, chkdclkfirst = FALSE;
  4685. #ifdef SIS300
  4686. unsigned short crt2crtc = 0;
  4687. #endif
  4688. #ifdef SIS315H
  4689. unsigned short pushcx;
  4690. #endif
  4691. if(ModeNo <= 0x13) {
  4692. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  4693. resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
  4694. #ifdef SIS300
  4695. crt2crtc = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  4696. #endif
  4697. } else if(SiS_Pr->UseCustomMode) {
  4698. modeflag = SiS_Pr->CModeFlag;
  4699. } else {
  4700. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  4701. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  4702. #ifdef SIS300
  4703. crt2crtc = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  4704. #endif
  4705. }
  4706. /* is lvds if really LVDS, or 301B-DH with external LVDS transmitter */
  4707. if((SiS_Pr->SiS_IF_DEF_LVDS == 1) || (SiS_Pr->SiS_VBType & VB_NoLCD)) {
  4708. islvds = TRUE;
  4709. }
  4710. /* is really sis if sis bridge, but not 301B-DH */
  4711. if((SiS_Pr->SiS_VBType & VB_SISVB) && (!(SiS_Pr->SiS_VBType & VB_NoLCD))) {
  4712. issis = TRUE;
  4713. }
  4714. if((SiS_Pr->ChipType >= SIS_315H) && (islvds) && (!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA))) {
  4715. if((!SiS_Pr->SiS_IF_DEF_FSTN) && (!SiS_Pr->SiS_IF_DEF_DSTN)) {
  4716. chkdclkfirst = TRUE;
  4717. }
  4718. }
  4719. #ifdef SIS315H
  4720. if((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  4721. if(IS_SIS330) {
  4722. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x10);
  4723. } else if(IS_SIS740) {
  4724. if(islvds) {
  4725. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,0xfb,0x04);
  4726. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x03);
  4727. } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
  4728. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x10);
  4729. }
  4730. } else {
  4731. if(islvds) {
  4732. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,0xfb,0x04);
  4733. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x00);
  4734. } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
  4735. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2D,0x0f);
  4736. if(SiS_Pr->SiS_VBType & VB_SIS30xC) {
  4737. if((SiS_Pr->SiS_LCDResInfo == Panel_1024x768) ||
  4738. (SiS_Pr->SiS_LCDResInfo == Panel_1280x1024)) {
  4739. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x20);
  4740. }
  4741. }
  4742. }
  4743. }
  4744. }
  4745. #endif
  4746. /* Horizontal */
  4747. tempax = SiS_Pr->SiS_LCDHDES;
  4748. if(islvds) {
  4749. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4750. if(!SiS_Pr->SiS_IF_DEF_FSTN && !SiS_Pr->SiS_IF_DEF_DSTN) {
  4751. if((SiS_Pr->SiS_LCDResInfo == Panel_640x480) &&
  4752. (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode))) {
  4753. tempax -= 8;
  4754. }
  4755. }
  4756. }
  4757. }
  4758. temp = (tempax & 0x0007);
  4759. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1A,temp); /* BPLHDESKEW[2:0] */
  4760. temp = (tempax >> 3) & 0x00FF;
  4761. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x16,temp); /* BPLHDESKEW[10:3] */
  4762. tempbx = SiS_Pr->SiS_HDE;
  4763. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4764. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  4765. tempbx = SiS_Pr->PanelXRes;
  4766. }
  4767. if((SiS_Pr->SiS_LCDResInfo == Panel_320x240_1) ||
  4768. (SiS_Pr->SiS_LCDResInfo == Panel_320x240_2) ||
  4769. (SiS_Pr->SiS_LCDResInfo == Panel_320x240_3)) {
  4770. tempbx >>= 1;
  4771. }
  4772. }
  4773. tempax += tempbx;
  4774. if(tempax >= SiS_Pr->SiS_HT) tempax -= SiS_Pr->SiS_HT;
  4775. temp = tempax;
  4776. if(temp & 0x07) temp += 8;
  4777. temp >>= 3;
  4778. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x17,temp); /* BPLHDEE */
  4779. tempcx = (SiS_Pr->SiS_HT - tempbx) >> 2;
  4780. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4781. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  4782. if(SiS_Pr->PanelHRS != 999) tempcx = SiS_Pr->PanelHRS;
  4783. }
  4784. }
  4785. tempcx += tempax;
  4786. if(tempcx >= SiS_Pr->SiS_HT) tempcx -= SiS_Pr->SiS_HT;
  4787. temp = (tempcx >> 3) & 0x00FF;
  4788. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4789. if(SiS_Pr->SiS_IF_DEF_TRUMPION) {
  4790. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  4791. switch(ModeNo) {
  4792. case 0x04:
  4793. case 0x05:
  4794. case 0x0d: temp = 0x56; break;
  4795. case 0x10: temp = 0x60; break;
  4796. case 0x13: temp = 0x5f; break;
  4797. case 0x40:
  4798. case 0x41:
  4799. case 0x4f:
  4800. case 0x43:
  4801. case 0x44:
  4802. case 0x62:
  4803. case 0x56:
  4804. case 0x53:
  4805. case 0x5d:
  4806. case 0x5e: temp = 0x54; break;
  4807. }
  4808. }
  4809. }
  4810. }
  4811. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x14,temp); /* BPLHRS */
  4812. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4813. temp += 2;
  4814. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  4815. temp += 8;
  4816. if(SiS_Pr->PanelHRE != 999) {
  4817. temp = tempcx + SiS_Pr->PanelHRE;
  4818. if(temp >= SiS_Pr->SiS_HT) temp -= SiS_Pr->SiS_HT;
  4819. temp >>= 3;
  4820. }
  4821. }
  4822. } else {
  4823. temp += 10;
  4824. }
  4825. temp &= 0x1F;
  4826. temp |= ((tempcx & 0x07) << 5);
  4827. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x15,temp); /* BPLHRE */
  4828. /* Vertical */
  4829. tempax = SiS_Pr->SiS_VGAVDE;
  4830. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4831. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  4832. tempax = SiS_Pr->PanelYRes;
  4833. }
  4834. }
  4835. tempbx = SiS_Pr->SiS_LCDVDES + tempax;
  4836. if(tempbx >= SiS_Pr->SiS_VT) tempbx -= SiS_Pr->SiS_VT;
  4837. push2 = tempbx;
  4838. tempcx = SiS_Pr->SiS_VGAVT - SiS_Pr->SiS_VGAVDE;
  4839. if(SiS_Pr->ChipType < SIS_315H) {
  4840. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4841. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  4842. tempcx = SiS_Pr->SiS_VGAVT - SiS_Pr->PanelYRes;
  4843. }
  4844. }
  4845. }
  4846. if(islvds) tempcx >>= 1;
  4847. else tempcx >>= 2;
  4848. if( (SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) &&
  4849. (!(SiS_Pr->SiS_LCDInfo & LCDPass11)) &&
  4850. (SiS_Pr->PanelVRS != 999) ) {
  4851. tempcx = SiS_Pr->PanelVRS;
  4852. tempbx += tempcx;
  4853. if(issis) tempbx++;
  4854. } else {
  4855. tempbx += tempcx;
  4856. if(SiS_Pr->ChipType < SIS_315H) tempbx++;
  4857. else if(issis) tempbx++;
  4858. }
  4859. if(tempbx >= SiS_Pr->SiS_VT) tempbx -= SiS_Pr->SiS_VT;
  4860. temp = tempbx & 0x00FF;
  4861. if(SiS_Pr->SiS_IF_DEF_TRUMPION) {
  4862. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  4863. if(ModeNo == 0x10) temp = 0xa9;
  4864. }
  4865. }
  4866. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,temp); /* BPLVRS */
  4867. tempcx >>= 3;
  4868. tempcx++;
  4869. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4870. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  4871. if(SiS_Pr->PanelVRE != 999) tempcx = SiS_Pr->PanelVRE;
  4872. }
  4873. }
  4874. tempcx += tempbx;
  4875. temp = tempcx & 0x000F;
  4876. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0xF0,temp); /* BPLVRE */
  4877. temp = ((tempbx >> 8) & 0x07) << 3;
  4878. if(SiS_Pr->SiS_IF_DEF_FSTN || SiS_Pr->SiS_IF_DEF_DSTN) {
  4879. if(SiS_Pr->SiS_HDE != 640) {
  4880. if(SiS_Pr->SiS_VGAVDE != SiS_Pr->SiS_VDE) temp |= 0x40;
  4881. }
  4882. } else if(SiS_Pr->SiS_VGAVDE != SiS_Pr->SiS_VDE) temp |= 0x40;
  4883. if(SiS_Pr->SiS_SetFlag & EnableLVDSDDA) temp |= 0x40;
  4884. tempbx = 0x87;
  4885. if((SiS_Pr->ChipType >= SIS_315H) ||
  4886. (SiS_Pr->ChipRevision >= 0x30)) {
  4887. tempbx = 0x07;
  4888. if((SiS_Pr->SiS_IF_DEF_CH70xx == 1) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
  4889. if(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x03) temp |= 0x80;
  4890. }
  4891. /* Chrontel 701x operates in 24bit mode (8-8-8, 2x12bit multiplexed) via VGA2 */
  4892. if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) {
  4893. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  4894. if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x06) & 0x10) temp |= 0x80;
  4895. } else {
  4896. if(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x01) temp |= 0x80;
  4897. }
  4898. }
  4899. }
  4900. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x1A,tempbx,temp);
  4901. tempbx = push2; /* BPLVDEE */
  4902. tempcx = SiS_Pr->SiS_LCDVDES; /* BPLVDES */
  4903. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4904. switch(SiS_Pr->SiS_LCDResInfo) {
  4905. case Panel_640x480:
  4906. tempbx = SiS_Pr->SiS_VGAVDE - 1;
  4907. tempcx = SiS_Pr->SiS_VGAVDE;
  4908. break;
  4909. case Panel_800x600:
  4910. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  4911. if(resinfo == SIS_RI_800x600) tempcx++;
  4912. }
  4913. break;
  4914. case Panel_1024x600:
  4915. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  4916. if(resinfo == SIS_RI_1024x600) tempcx++;
  4917. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  4918. if(resinfo == SIS_RI_800x600) tempcx++;
  4919. }
  4920. }
  4921. break;
  4922. case Panel_1024x768:
  4923. if(SiS_Pr->ChipType < SIS_315H) {
  4924. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  4925. if(resinfo == SIS_RI_1024x768) tempcx++;
  4926. }
  4927. }
  4928. break;
  4929. }
  4930. }
  4931. temp = ((tempbx >> 8) & 0x07) << 3;
  4932. temp |= ((tempcx >> 8) & 0x07);
  4933. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1D,temp);
  4934. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1C,tempbx);
  4935. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1B,tempcx);
  4936. /* Vertical scaling */
  4937. if(SiS_Pr->ChipType < SIS_315H) {
  4938. #ifdef SIS300 /* 300 series */
  4939. tempeax = SiS_Pr->SiS_VGAVDE << 6;
  4940. temp = (tempeax % (unsigned int)SiS_Pr->SiS_VDE);
  4941. tempeax = tempeax / (unsigned int)SiS_Pr->SiS_VDE;
  4942. if(temp) tempeax++;
  4943. if(SiS_Pr->SiS_SetFlag & EnableLVDSDDA) tempeax = 0x3F;
  4944. temp = (unsigned short)(tempeax & 0x00FF);
  4945. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1E,temp); /* BPLVCFACT */
  4946. tempvcfact = temp;
  4947. #endif /* SIS300 */
  4948. } else {
  4949. #ifdef SIS315H /* 315 series */
  4950. tempeax = SiS_Pr->SiS_VGAVDE << 18;
  4951. tempebx = SiS_Pr->SiS_VDE;
  4952. temp = (tempeax % tempebx);
  4953. tempeax = tempeax / tempebx;
  4954. if(temp) tempeax++;
  4955. tempvcfact = tempeax;
  4956. temp = (unsigned short)(tempeax & 0x00FF);
  4957. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x37,temp);
  4958. temp = (unsigned short)((tempeax & 0x00FF00) >> 8);
  4959. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x36,temp);
  4960. temp = (unsigned short)((tempeax & 0x00030000) >> 16);
  4961. if(SiS_Pr->SiS_VDE == SiS_Pr->SiS_VGAVDE) temp |= 0x04;
  4962. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x35,temp);
  4963. if(SiS_Pr->SiS_VBType & VB_SISPART4SCALER) {
  4964. temp = (unsigned short)(tempeax & 0x00FF);
  4965. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x3c,temp);
  4966. temp = (unsigned short)((tempeax & 0x00FF00) >> 8);
  4967. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x3b,temp);
  4968. temp = (unsigned short)(((tempeax & 0x00030000) >> 16) << 6);
  4969. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x3a,0x3f,temp);
  4970. temp = 0;
  4971. if(SiS_Pr->SiS_VDE != SiS_Pr->SiS_VGAVDE) temp |= 0x08;
  4972. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x30,0xf3,temp);
  4973. }
  4974. #endif
  4975. }
  4976. /* Horizontal scaling */
  4977. tempeax = SiS_Pr->SiS_VGAHDE; /* 1f = ( (VGAHDE * 65536) / ( (VGAHDE * 65536) / HDE ) ) - 1*/
  4978. if(chkdclkfirst) {
  4979. if(modeflag & HalfDCLK) tempeax >>= 1;
  4980. }
  4981. tempebx = tempeax << 16;
  4982. if(SiS_Pr->SiS_HDE == tempeax) {
  4983. tempecx = 0xFFFF;
  4984. } else {
  4985. tempecx = tempebx / SiS_Pr->SiS_HDE;
  4986. if(SiS_Pr->ChipType >= SIS_315H) {
  4987. if(tempebx % SiS_Pr->SiS_HDE) tempecx++;
  4988. }
  4989. }
  4990. if(SiS_Pr->ChipType >= SIS_315H) {
  4991. tempeax = (tempebx / tempecx) - 1;
  4992. } else {
  4993. tempeax = ((SiS_Pr->SiS_VGAHT << 16) / tempecx) - 1;
  4994. }
  4995. tempecx = (tempecx << 16) | (tempeax & 0xFFFF);
  4996. temp = (unsigned short)(tempecx & 0x00FF);
  4997. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1F,temp);
  4998. if(SiS_Pr->ChipType >= SIS_315H) {
  4999. tempeax = (SiS_Pr->SiS_VGAVDE << 18) / tempvcfact;
  5000. tempbx = (unsigned short)(tempeax & 0xFFFF);
  5001. } else {
  5002. tempeax = SiS_Pr->SiS_VGAVDE << 6;
  5003. tempbx = tempvcfact & 0x3f;
  5004. if(tempbx == 0) tempbx = 64;
  5005. tempeax /= tempbx;
  5006. tempbx = (unsigned short)(tempeax & 0xFFFF);
  5007. }
  5008. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) tempbx--;
  5009. if(SiS_Pr->SiS_SetFlag & EnableLVDSDDA) {
  5010. if((!SiS_Pr->SiS_IF_DEF_FSTN) && (!SiS_Pr->SiS_IF_DEF_DSTN)) tempbx = 1;
  5011. else if(SiS_Pr->SiS_LCDResInfo != Panel_640x480) tempbx = 1;
  5012. }
  5013. temp = ((tempbx >> 8) & 0x07) << 3;
  5014. temp = temp | ((tempecx >> 8) & 0x07);
  5015. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x20,temp);
  5016. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x21,tempbx);
  5017. tempecx >>= 16; /* BPLHCFACT */
  5018. if(!chkdclkfirst) {
  5019. if(modeflag & HalfDCLK) tempecx >>= 1;
  5020. }
  5021. temp = (unsigned short)((tempecx & 0xFF00) >> 8);
  5022. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x22,temp);
  5023. temp = (unsigned short)(tempecx & 0x00FF);
  5024. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x23,temp);
  5025. #ifdef SIS315H
  5026. if(SiS_Pr->ChipType >= SIS_315H) {
  5027. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  5028. if((islvds) || (SiS_Pr->SiS_VBInfo & VB_SISLVDS)) {
  5029. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1e,0x20);
  5030. }
  5031. } else {
  5032. if(islvds) {
  5033. if(SiS_Pr->ChipType == SIS_740) {
  5034. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1e,0x03);
  5035. } else {
  5036. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1e,0x23);
  5037. }
  5038. }
  5039. }
  5040. }
  5041. #endif
  5042. #ifdef SIS300
  5043. if(SiS_Pr->SiS_IF_DEF_TRUMPION) {
  5044. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  5045. unsigned char *trumpdata;
  5046. int i, j = crt2crtc;
  5047. unsigned char TrumpMode13[4] = { 0x01, 0x10, 0x2c, 0x00 };
  5048. unsigned char TrumpMode10_1[4] = { 0x01, 0x10, 0x27, 0x00 };
  5049. unsigned char TrumpMode10_2[4] = { 0x01, 0x16, 0x10, 0x00 };
  5050. if(SiS_Pr->SiS_UseROM) {
  5051. trumpdata = &ROMAddr[0x8001 + (j * 80)];
  5052. } else {
  5053. if(SiS_Pr->SiS_LCDTypeInfo == 0x0e) j += 7;
  5054. trumpdata = &SiS300_TrumpionData[j][0];
  5055. }
  5056. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x02,0xbf);
  5057. for(i=0; i<5; i++) {
  5058. SiS_SetTrumpionBlock(SiS_Pr, trumpdata);
  5059. }
  5060. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  5061. if(ModeNo == 0x13) {
  5062. for(i=0; i<4; i++) {
  5063. SiS_SetTrumpionBlock(SiS_Pr, &TrumpMode13[0]);
  5064. }
  5065. } else if(ModeNo == 0x10) {
  5066. for(i=0; i<4; i++) {
  5067. SiS_SetTrumpionBlock(SiS_Pr, &TrumpMode10_1[0]);
  5068. SiS_SetTrumpionBlock(SiS_Pr, &TrumpMode10_2[0]);
  5069. }
  5070. }
  5071. }
  5072. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x02,0x40);
  5073. }
  5074. #endif
  5075. #ifdef SIS315H
  5076. if(SiS_Pr->SiS_IF_DEF_FSTN || SiS_Pr->SiS_IF_DEF_DSTN) {
  5077. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x25,0x00);
  5078. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x26,0x00);
  5079. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x27,0x00);
  5080. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x28,0x87);
  5081. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x29,0x5A);
  5082. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2A,0x4B);
  5083. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x44,~0x07,0x03);
  5084. tempax = SiS_Pr->SiS_HDE; /* Blps = lcdhdee(lcdhdes+HDE) + 64 */
  5085. if(SiS_Pr->SiS_LCDResInfo == Panel_320x240_1 ||
  5086. SiS_Pr->SiS_LCDResInfo == Panel_320x240_2 ||
  5087. SiS_Pr->SiS_LCDResInfo == Panel_320x240_3) tempax >>= 1;
  5088. tempax += 64;
  5089. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x38,tempax & 0xff);
  5090. temp = (tempax >> 8) << 3;
  5091. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x35,~0x078,temp);
  5092. tempax += 32; /* Blpe = lBlps+32 */
  5093. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x39,tempax & 0xff);
  5094. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3A,0x00); /* Bflml = 0 */
  5095. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x3C,~0x007);
  5096. tempax = SiS_Pr->SiS_VDE;
  5097. if(SiS_Pr->SiS_LCDResInfo == Panel_320x240_1 ||
  5098. SiS_Pr->SiS_LCDResInfo == Panel_320x240_2 ||
  5099. SiS_Pr->SiS_LCDResInfo == Panel_320x240_3) tempax >>= 1;
  5100. tempax >>= 1;
  5101. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3B,tempax & 0xff);
  5102. temp = (tempax >> 8) << 3;
  5103. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x3C,~0x038,temp);
  5104. tempeax = SiS_Pr->SiS_HDE;
  5105. if(SiS_Pr->SiS_LCDResInfo == Panel_320x240_1 ||
  5106. SiS_Pr->SiS_LCDResInfo == Panel_320x240_2 ||
  5107. SiS_Pr->SiS_LCDResInfo == Panel_320x240_3) tempeax >>= 1;
  5108. tempeax <<= 2; /* BDxFIFOSTOP = (HDE*4)/128 */
  5109. temp = tempeax & 0x7f;
  5110. tempeax >>= 7;
  5111. if(temp) tempeax++;
  5112. temp = tempeax & 0x3f;
  5113. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x45,temp);
  5114. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3F,0x00); /* BDxWadrst0 */
  5115. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3E,0x00);
  5116. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3D,0x10);
  5117. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x3C,~0x040);
  5118. tempax = SiS_Pr->SiS_HDE;
  5119. if(SiS_Pr->SiS_LCDResInfo == Panel_320x240_1 ||
  5120. SiS_Pr->SiS_LCDResInfo == Panel_320x240_2 ||
  5121. SiS_Pr->SiS_LCDResInfo == Panel_320x240_3) tempax >>= 1;
  5122. tempax >>= 4; /* BDxWadroff = HDE*4/8/8 */
  5123. pushcx = tempax;
  5124. temp = tempax & 0x00FF;
  5125. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x43,temp);
  5126. temp = ((tempax & 0xFF00) >> 8) << 3;
  5127. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x44,~0x0F8,temp);
  5128. tempax = SiS_Pr->SiS_VDE; /* BDxWadrst1 = BDxWadrst0 + BDxWadroff * VDE */
  5129. if(SiS_Pr->SiS_LCDResInfo == Panel_320x240_1 ||
  5130. SiS_Pr->SiS_LCDResInfo == Panel_320x240_2 ||
  5131. SiS_Pr->SiS_LCDResInfo == Panel_320x240_3) tempax >>= 1;
  5132. tempeax = tempax * pushcx;
  5133. temp = tempeax & 0xFF;
  5134. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x42,temp);
  5135. temp = (tempeax & 0xFF00) >> 8;
  5136. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x41,temp);
  5137. temp = ((tempeax & 0xFF0000) >> 16) | 0x10;
  5138. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x40,temp);
  5139. temp = ((tempeax & 0x01000000) >> 24) << 7;
  5140. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x3C,~0x080,temp);
  5141. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2F,0x03);
  5142. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x03,0x50);
  5143. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x04,0x00);
  5144. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2F,0x01);
  5145. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x19,0x38);
  5146. if(SiS_Pr->SiS_IF_DEF_FSTN) {
  5147. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2b,0x02);
  5148. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2c,0x00);
  5149. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2d,0x00);
  5150. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x35,0x0c);
  5151. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x36,0x00);
  5152. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x37,0x00);
  5153. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x38,0x80);
  5154. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x39,0xA0);
  5155. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3a,0x00);
  5156. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3b,0xf0);
  5157. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3c,0x00);
  5158. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3d,0x10);
  5159. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3e,0x00);
  5160. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3f,0x00);
  5161. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x40,0x10);
  5162. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x41,0x25);
  5163. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x42,0x80);
  5164. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x43,0x14);
  5165. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x44,0x03);
  5166. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x45,0x0a);
  5167. }
  5168. }
  5169. #endif /* SIS315H */
  5170. }
  5171. /* Set Part 1 */
  5172. static void
  5173. SiS_SetGroup1(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  5174. unsigned short RefreshRateTableIndex)
  5175. {
  5176. #if defined(SIS300) || defined(SIS315H)
  5177. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  5178. #endif
  5179. unsigned short temp=0, tempax=0, tempbx=0, tempcx=0, bridgeadd=0;
  5180. unsigned short pushbx=0, CRT1Index=0, modeflag, resinfo=0;
  5181. #ifdef SIS315H
  5182. unsigned short tempbl=0;
  5183. #endif
  5184. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  5185. SiS_SetGroup1_LVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  5186. return;
  5187. }
  5188. if(ModeNo <= 0x13) {
  5189. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  5190. } else if(SiS_Pr->UseCustomMode) {
  5191. modeflag = SiS_Pr->CModeFlag;
  5192. } else {
  5193. CRT1Index = SiS_GetRefCRT1CRTC(SiS_Pr, RefreshRateTableIndex, SiS_Pr->SiS_UseWideCRT2);
  5194. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  5195. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  5196. }
  5197. SiS_SetCRT2Offset(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  5198. if( ! ((SiS_Pr->ChipType >= SIS_315H) &&
  5199. (SiS_Pr->SiS_IF_DEF_LVDS == 1) &&
  5200. (SiS_Pr->SiS_VBInfo & SetInSlaveMode)) ) {
  5201. if(SiS_Pr->ChipType < SIS_315H ) {
  5202. #ifdef SIS300
  5203. SiS_SetCRT2FIFO_300(SiS_Pr, ModeNo);
  5204. #endif
  5205. } else {
  5206. #ifdef SIS315H
  5207. SiS_SetCRT2FIFO_310(SiS_Pr);
  5208. #endif
  5209. }
  5210. /* 1. Horizontal setup */
  5211. if(SiS_Pr->ChipType < SIS_315H ) {
  5212. #ifdef SIS300 /* ------------- 300 series --------------*/
  5213. temp = (SiS_Pr->SiS_VGAHT - 1) & 0x0FF; /* BTVGA2HT 0x08,0x09 */
  5214. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x08,temp); /* CRT2 Horizontal Total */
  5215. temp = (((SiS_Pr->SiS_VGAHT - 1) & 0xFF00) >> 8) << 4;
  5216. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x09,0x0f,temp); /* CRT2 Horizontal Total Overflow [7:4] */
  5217. temp = (SiS_Pr->SiS_VGAHDE + 12) & 0x0FF; /* BTVGA2HDEE 0x0A,0x0C */
  5218. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0A,temp); /* CRT2 Horizontal Display Enable End */
  5219. pushbx = SiS_Pr->SiS_VGAHDE + 12; /* bx BTVGA2HRS 0x0B,0x0C */
  5220. tempcx = (SiS_Pr->SiS_VGAHT - SiS_Pr->SiS_VGAHDE) >> 2;
  5221. tempbx = pushbx + tempcx;
  5222. tempcx <<= 1;
  5223. tempcx += tempbx;
  5224. bridgeadd = 12;
  5225. #endif /* SIS300 */
  5226. } else {
  5227. #ifdef SIS315H /* ------------------- 315/330 series --------------- */
  5228. tempcx = SiS_Pr->SiS_VGAHT; /* BTVGA2HT 0x08,0x09 */
  5229. if(modeflag & HalfDCLK) {
  5230. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  5231. tempcx >>= 1;
  5232. } else {
  5233. tempax = SiS_Pr->SiS_VGAHDE >> 1;
  5234. tempcx = SiS_Pr->SiS_HT - SiS_Pr->SiS_HDE + tempax;
  5235. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  5236. tempcx = SiS_Pr->SiS_HT - tempax;
  5237. }
  5238. }
  5239. }
  5240. tempcx--;
  5241. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x08,tempcx); /* CRT2 Horizontal Total */
  5242. temp = (tempcx >> 4) & 0xF0;
  5243. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x09,0x0F,temp); /* CRT2 Horizontal Total Overflow [7:4] */
  5244. tempcx = SiS_Pr->SiS_VGAHT; /* BTVGA2HDEE 0x0A,0x0C */
  5245. tempbx = SiS_Pr->SiS_VGAHDE;
  5246. tempcx -= tempbx;
  5247. tempcx >>= 2;
  5248. if(modeflag & HalfDCLK) {
  5249. tempbx >>= 1;
  5250. tempcx >>= 1;
  5251. }
  5252. tempbx += 16;
  5253. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0A,tempbx); /* CRT2 Horizontal Display Enable End */
  5254. pushbx = tempbx;
  5255. tempcx >>= 1;
  5256. tempbx += tempcx;
  5257. tempcx += tempbx;
  5258. bridgeadd = 16;
  5259. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  5260. if(SiS_Pr->ChipType >= SIS_661) {
  5261. if((SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) ||
  5262. (SiS_Pr->SiS_LCDResInfo == Panel_1280x1024)) {
  5263. if(resinfo == SIS_RI_1280x1024) {
  5264. tempcx = (tempcx & 0xff00) | 0x30;
  5265. } else if(resinfo == SIS_RI_1600x1200) {
  5266. tempcx = (tempcx & 0xff00) | 0xff;
  5267. }
  5268. }
  5269. }
  5270. }
  5271. #endif /* SIS315H */
  5272. } /* 315/330 series */
  5273. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  5274. if(SiS_Pr->UseCustomMode) {
  5275. tempbx = SiS_Pr->CHSyncStart + bridgeadd;
  5276. tempcx = SiS_Pr->CHSyncEnd + bridgeadd;
  5277. tempax = SiS_Pr->SiS_VGAHT;
  5278. if(modeflag & HalfDCLK) tempax >>= 1;
  5279. tempax--;
  5280. if(tempcx > tempax) tempcx = tempax;
  5281. }
  5282. if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) {
  5283. unsigned char cr4, cr14, cr5, cr15;
  5284. if(SiS_Pr->UseCustomMode) {
  5285. cr4 = SiS_Pr->CCRT1CRTC[4];
  5286. cr14 = SiS_Pr->CCRT1CRTC[14];
  5287. cr5 = SiS_Pr->CCRT1CRTC[5];
  5288. cr15 = SiS_Pr->CCRT1CRTC[15];
  5289. } else {
  5290. cr4 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[4];
  5291. cr14 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[14];
  5292. cr5 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[5];
  5293. cr15 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[15];
  5294. }
  5295. tempbx = ((cr4 | ((cr14 & 0xC0) << 2)) - 3) << 3; /* (VGAHRS-3)*8 */
  5296. tempcx = (((cr5 & 0x1f) | ((cr15 & 0x04) << (5-2))) - 3) << 3; /* (VGAHRE-3)*8 */
  5297. tempcx &= 0x00FF;
  5298. tempcx |= (tempbx & 0xFF00);
  5299. tempbx += bridgeadd;
  5300. tempcx += bridgeadd;
  5301. tempax = SiS_Pr->SiS_VGAHT;
  5302. if(modeflag & HalfDCLK) tempax >>= 1;
  5303. tempax--;
  5304. if(tempcx > tempax) tempcx = tempax;
  5305. }
  5306. if(SiS_Pr->SiS_TVMode & (TVSetNTSC1024 | TVSet525p1024)) {
  5307. tempbx = 1040;
  5308. tempcx = 1044; /* HWCursor bug! */
  5309. }
  5310. }
  5311. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0B,tempbx); /* CRT2 Horizontal Retrace Start */
  5312. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0D,tempcx); /* CRT2 Horizontal Retrace End */
  5313. temp = ((tempbx >> 8) & 0x0F) | ((pushbx >> 4) & 0xF0);
  5314. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0C,temp); /* Overflow */
  5315. /* 2. Vertical setup */
  5316. tempcx = SiS_Pr->SiS_VGAVT - 1;
  5317. temp = tempcx & 0x00FF;
  5318. if(SiS_Pr->ChipType < SIS_661) {
  5319. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  5320. if(SiS_Pr->ChipType < SIS_315H) {
  5321. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  5322. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToSVIDEO | SetCRT2ToAVIDEO)) {
  5323. temp--;
  5324. }
  5325. }
  5326. } else {
  5327. temp--;
  5328. }
  5329. } else if(SiS_Pr->ChipType >= SIS_315H) {
  5330. temp--;
  5331. }
  5332. }
  5333. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0E,temp); /* CRT2 Vertical Total */
  5334. tempbx = SiS_Pr->SiS_VGAVDE - 1;
  5335. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0F,tempbx); /* CRT2 Vertical Display Enable End */
  5336. temp = ((tempbx >> 5) & 0x38) | ((tempcx >> 8) & 0x07);
  5337. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x12,temp); /* Overflow */
  5338. if((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->ChipType < SIS_661)) {
  5339. tempbx++;
  5340. tempax = tempbx;
  5341. tempcx++;
  5342. tempcx -= tempax;
  5343. tempcx >>= 2;
  5344. tempbx += tempcx;
  5345. if(tempcx < 4) tempcx = 4;
  5346. tempcx >>= 2;
  5347. tempcx += tempbx;
  5348. tempcx++;
  5349. } else {
  5350. tempbx = (SiS_Pr->SiS_VGAVT + SiS_Pr->SiS_VGAVDE) >> 1; /* BTVGA2VRS 0x10,0x11 */
  5351. tempcx = ((SiS_Pr->SiS_VGAVT - SiS_Pr->SiS_VGAVDE) >> 4) + tempbx + 1; /* BTVGA2VRE 0x11 */
  5352. }
  5353. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  5354. if(SiS_Pr->UseCustomMode) {
  5355. tempbx = SiS_Pr->CVSyncStart;
  5356. tempcx = SiS_Pr->CVSyncEnd;
  5357. }
  5358. if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) {
  5359. unsigned char cr8, cr7, cr13;
  5360. if(SiS_Pr->UseCustomMode) {
  5361. cr8 = SiS_Pr->CCRT1CRTC[8];
  5362. cr7 = SiS_Pr->CCRT1CRTC[7];
  5363. cr13 = SiS_Pr->CCRT1CRTC[13];
  5364. tempcx = SiS_Pr->CCRT1CRTC[9];
  5365. } else {
  5366. cr8 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[8];
  5367. cr7 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[7];
  5368. cr13 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[13];
  5369. tempcx = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[9];
  5370. }
  5371. tempbx = cr8;
  5372. if(cr7 & 0x04) tempbx |= 0x0100;
  5373. if(cr7 & 0x80) tempbx |= 0x0200;
  5374. if(cr13 & 0x08) tempbx |= 0x0400;
  5375. }
  5376. }
  5377. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x10,tempbx); /* CRT2 Vertical Retrace Start */
  5378. temp = ((tempbx >> 4) & 0x70) | (tempcx & 0x0F);
  5379. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x11,temp); /* CRT2 Vert. Retrace End; Overflow */
  5380. /* 3. Panel delay compensation */
  5381. if(SiS_Pr->ChipType < SIS_315H) {
  5382. #ifdef SIS300 /* ---------- 300 series -------------- */
  5383. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  5384. temp = 0x20;
  5385. if(SiS_Pr->ChipType == SIS_300) {
  5386. temp = 0x10;
  5387. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) temp = 0x2c;
  5388. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) temp = 0x20;
  5389. }
  5390. if(SiS_Pr->SiS_VBType & VB_SIS301) {
  5391. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) temp = 0x20;
  5392. }
  5393. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x960) temp = 0x24;
  5394. if(SiS_Pr->SiS_LCDResInfo == Panel_Custom) temp = 0x2c;
  5395. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) temp = 0x08;
  5396. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  5397. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) temp = 0x2c;
  5398. else temp = 0x20;
  5399. }
  5400. if(SiS_Pr->SiS_UseROM) {
  5401. if(ROMAddr[0x220] & 0x80) {
  5402. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoYPbPrHiVision)
  5403. temp = ROMAddr[0x221];
  5404. else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision)
  5405. temp = ROMAddr[0x222];
  5406. else if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024)
  5407. temp = ROMAddr[0x223];
  5408. else
  5409. temp = ROMAddr[0x224];
  5410. }
  5411. }
  5412. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  5413. if(SiS_Pr->PDC != -1) temp = SiS_Pr->PDC;
  5414. }
  5415. } else {
  5416. temp = 0x20;
  5417. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
  5418. if(SiS_Pr->SiS_LCDResInfo == Panel_640x480) temp = 0x04;
  5419. }
  5420. if(SiS_Pr->SiS_UseROM) {
  5421. if(ROMAddr[0x220] & 0x80) {
  5422. temp = ROMAddr[0x220];
  5423. }
  5424. }
  5425. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  5426. if(SiS_Pr->PDC != -1) temp = SiS_Pr->PDC;
  5427. }
  5428. }
  5429. temp &= 0x3c;
  5430. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,~0x3C,temp); /* Panel Link Delay Compensation; (Software Command Reset; Power Saving) */
  5431. #endif /* SIS300 */
  5432. } else {
  5433. #ifdef SIS315H /* --------------- 315/330 series ---------------*/
  5434. if(SiS_Pr->ChipType < SIS_661) {
  5435. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  5436. if(SiS_Pr->ChipType == SIS_740) temp = 0x03;
  5437. else temp = 0x00;
  5438. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) temp = 0x0a;
  5439. tempbl = 0xF0;
  5440. if(SiS_Pr->ChipType == SIS_650) {
  5441. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  5442. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) tempbl = 0x0F;
  5443. }
  5444. }
  5445. if(SiS_Pr->SiS_IF_DEF_DSTN || SiS_Pr->SiS_IF_DEF_FSTN) {
  5446. temp = 0x08;
  5447. tempbl = 0;
  5448. if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
  5449. if(ROMAddr[0x13c] & 0x80) tempbl = 0xf0;
  5450. }
  5451. }
  5452. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,tempbl,temp); /* Panel Link Delay Compensation */
  5453. }
  5454. } /* < 661 */
  5455. tempax = 0;
  5456. if(modeflag & DoubleScanMode) tempax |= 0x80;
  5457. if(modeflag & HalfDCLK) tempax |= 0x40;
  5458. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2C,0x3f,tempax);
  5459. #endif /* SIS315H */
  5460. }
  5461. } /* Slavemode */
  5462. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  5463. if((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) {
  5464. /* For 301BDH with LCD, we set up the Panel Link */
  5465. SiS_SetGroup1_LVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  5466. } else if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  5467. SiS_SetGroup1_301(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  5468. }
  5469. } else {
  5470. if(SiS_Pr->ChipType < SIS_315H) {
  5471. SiS_SetGroup1_LVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  5472. } else {
  5473. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  5474. if((!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) || (SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  5475. SiS_SetGroup1_LVDS(SiS_Pr, ModeNo,ModeIdIndex,RefreshRateTableIndex);
  5476. }
  5477. } else {
  5478. SiS_SetGroup1_LVDS(SiS_Pr, ModeNo,ModeIdIndex,RefreshRateTableIndex);
  5479. }
  5480. }
  5481. }
  5482. }
  5483. /*********************************************/
  5484. /* SET PART 2 REGISTER GROUP */
  5485. /*********************************************/
  5486. #ifdef SIS315H
  5487. static unsigned char *
  5488. SiS_GetGroup2CLVXPtr(struct SiS_Private *SiS_Pr, int tabletype)
  5489. {
  5490. const unsigned char *tableptr = NULL;
  5491. unsigned short a, b, p = 0;
  5492. a = SiS_Pr->SiS_VGAHDE;
  5493. b = SiS_Pr->SiS_HDE;
  5494. if(tabletype) {
  5495. a = SiS_Pr->SiS_VGAVDE;
  5496. b = SiS_Pr->SiS_VDE;
  5497. }
  5498. if(a < b) {
  5499. tableptr = SiS_Part2CLVX_1;
  5500. } else if(a == b) {
  5501. tableptr = SiS_Part2CLVX_2;
  5502. } else {
  5503. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  5504. tableptr = SiS_Part2CLVX_4;
  5505. } else {
  5506. tableptr = SiS_Part2CLVX_3;
  5507. }
  5508. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  5509. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525i) tableptr = SiS_Part2CLVX_3;
  5510. else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) tableptr = SiS_Part2CLVX_3;
  5511. else tableptr = SiS_Part2CLVX_5;
  5512. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  5513. tableptr = SiS_Part2CLVX_6;
  5514. }
  5515. do {
  5516. if((tableptr[p] | tableptr[p+1] << 8) == a) break;
  5517. p += 0x42;
  5518. } while((tableptr[p] | tableptr[p+1] << 8) != 0xffff);
  5519. if((tableptr[p] | tableptr[p+1] << 8) == 0xffff) p -= 0x42;
  5520. }
  5521. p += 2;
  5522. return ((unsigned char *)&tableptr[p]);
  5523. }
  5524. static void
  5525. SiS_SetGroup2_C_ELV(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  5526. unsigned short RefreshRateTableIndex)
  5527. {
  5528. unsigned char *tableptr;
  5529. unsigned char temp;
  5530. int i, j;
  5531. if(!(SiS_Pr->SiS_VBType & VB_SISTAP4SCALER)) return;
  5532. tableptr = SiS_GetGroup2CLVXPtr(SiS_Pr, 0);
  5533. for(i = 0x80, j = 0; i <= 0xbf; i++, j++) {
  5534. SiS_SetReg(SiS_Pr->SiS_Part2Port, i, tableptr[j]);
  5535. }
  5536. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  5537. tableptr = SiS_GetGroup2CLVXPtr(SiS_Pr, 1);
  5538. for(i = 0xc0, j = 0; i <= 0xff; i++, j++) {
  5539. SiS_SetReg(SiS_Pr->SiS_Part2Port, i, tableptr[j]);
  5540. }
  5541. }
  5542. temp = 0x10;
  5543. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) temp |= 0x04;
  5544. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x4e,0xeb,temp);
  5545. }
  5546. static BOOLEAN
  5547. SiS_GetCRT2Part2Ptr(struct SiS_Private *SiS_Pr,unsigned short ModeNo,unsigned short ModeIdIndex,
  5548. unsigned short RefreshRateTableIndex,unsigned short *CRT2Index,
  5549. unsigned short *ResIndex)
  5550. {
  5551. if(SiS_Pr->ChipType < SIS_315H) return FALSE;
  5552. if(ModeNo <= 0x13)
  5553. (*ResIndex) = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  5554. else
  5555. (*ResIndex) = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  5556. (*ResIndex) &= 0x3f;
  5557. (*CRT2Index) = 0;
  5558. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  5559. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
  5560. (*CRT2Index) = 200;
  5561. }
  5562. }
  5563. if(SiS_Pr->SiS_CustomT == CUT_ASUSA2H_2) {
  5564. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  5565. if(SiS_Pr->SiS_SetFlag & LCDVESATiming) (*CRT2Index) = 206;
  5566. }
  5567. }
  5568. return (((*CRT2Index) != 0));
  5569. }
  5570. #endif
  5571. #ifdef SIS300
  5572. static void
  5573. SiS_Group2LCDSpecial(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short crt2crtc)
  5574. {
  5575. unsigned short tempcx;
  5576. static const unsigned char atable[] = {
  5577. 0xc3,0x9e,0xc3,0x9e,0x02,0x02,0x02,
  5578. 0xab,0x87,0xab,0x9e,0xe7,0x02,0x02
  5579. };
  5580. if(!SiS_Pr->UseCustomMode) {
  5581. if( ( ( (SiS_Pr->ChipType == SIS_630) ||
  5582. (SiS_Pr->ChipType == SIS_730) ) &&
  5583. (SiS_Pr->ChipRevision > 2) ) &&
  5584. (SiS_Pr->SiS_LCDResInfo == Panel_1024x768) &&
  5585. (!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) &&
  5586. (!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) ) {
  5587. if(ModeNo == 0x13) {
  5588. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,0xB9);
  5589. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x05,0xCC);
  5590. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x06,0xA6);
  5591. } else if((crt2crtc & 0x3F) == 4) {
  5592. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x2B);
  5593. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x13);
  5594. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,0xE5);
  5595. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x05,0x08);
  5596. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x06,0xE2);
  5597. }
  5598. }
  5599. if(SiS_Pr->ChipType < SIS_315H) {
  5600. if(SiS_Pr->SiS_LCDTypeInfo == 0x0c) {
  5601. crt2crtc &= 0x1f;
  5602. tempcx = 0;
  5603. if(!(SiS_Pr->SiS_VBInfo & SetNotSimuMode)) {
  5604. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  5605. tempcx += 7;
  5606. }
  5607. }
  5608. tempcx += crt2crtc;
  5609. if(crt2crtc >= 4) {
  5610. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x06,0xff);
  5611. }
  5612. if(!(SiS_Pr->SiS_VBInfo & SetNotSimuMode)) {
  5613. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  5614. if(crt2crtc == 4) {
  5615. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x28);
  5616. }
  5617. }
  5618. }
  5619. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x18);
  5620. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,atable[tempcx]);
  5621. }
  5622. }
  5623. }
  5624. }
  5625. /* For ECS A907. Highly preliminary. */
  5626. static void
  5627. SiS_Set300Part2Regs(struct SiS_Private *SiS_Pr, unsigned short ModeIdIndex, unsigned short RefreshRateTableIndex,
  5628. unsigned short ModeNo)
  5629. {
  5630. const struct SiS_Part2PortTbl *CRT2Part2Ptr = NULL;
  5631. unsigned short crt2crtc, resindex;
  5632. int i, j;
  5633. if(SiS_Pr->ChipType != SIS_300) return;
  5634. if(!(SiS_Pr->SiS_VBType & VB_SIS30xBLV)) return;
  5635. if(SiS_Pr->UseCustomMode) return;
  5636. if(ModeNo <= 0x13) {
  5637. crt2crtc = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  5638. } else {
  5639. crt2crtc = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  5640. }
  5641. resindex = crt2crtc & 0x3F;
  5642. if(SiS_Pr->SiS_SetFlag & LCDVESATiming) CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1024x768_1;
  5643. else CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1024x768_2;
  5644. /* The BIOS code (1.16.51,56) is obviously a fragment! */
  5645. if(ModeNo > 0x13) {
  5646. CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1024x768_1;
  5647. resindex = 4;
  5648. }
  5649. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x01,0x80,(CRT2Part2Ptr+resindex)->CR[0]);
  5650. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x02,0x80,(CRT2Part2Ptr+resindex)->CR[1]);
  5651. for(i = 2, j = 0x04; j <= 0x06; i++, j++ ) {
  5652. SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]);
  5653. }
  5654. for(j = 0x1c; j <= 0x1d; i++, j++ ) {
  5655. SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]);
  5656. }
  5657. for(j = 0x1f; j <= 0x21; i++, j++ ) {
  5658. SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]);
  5659. }
  5660. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x23,(CRT2Part2Ptr+resindex)->CR[10]);
  5661. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x25,0x0f,(CRT2Part2Ptr+resindex)->CR[11]);
  5662. }
  5663. #endif
  5664. static void
  5665. SiS_SetTVSpecial(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
  5666. {
  5667. if(!(SiS_Pr->SiS_VBType & VB_SIS30xBLV)) return;
  5668. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoHiVision)) return;
  5669. if(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p)) return;
  5670. if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) {
  5671. if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) {
  5672. const unsigned char specialtv[] = {
  5673. 0xa7,0x07,0xf2,0x6e,0x17,0x8b,0x73,0x53,
  5674. 0x13,0x40,0x34,0xf4,0x63,0xbb,0xcc,0x7a,
  5675. 0x58,0xe4,0x73,0xda,0x13
  5676. };
  5677. int i, j;
  5678. for(i = 0x1c, j = 0; i <= 0x30; i++, j++) {
  5679. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,specialtv[j]);
  5680. }
  5681. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x43,0x72);
  5682. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750)) {
  5683. if(SiS_Pr->SiS_TVMode & TVSetPALM) {
  5684. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x14);
  5685. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x1b);
  5686. } else {
  5687. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x14); /* 15 */
  5688. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x1a); /* 1b */
  5689. }
  5690. }
  5691. }
  5692. } else {
  5693. if((ModeNo == 0x38) || (ModeNo == 0x4a) || (ModeNo == 0x64) ||
  5694. (ModeNo == 0x52) || (ModeNo == 0x58) || (ModeNo == 0x5c)) {
  5695. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x1b); /* 21 */
  5696. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x54); /* 5a */
  5697. } else {
  5698. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x1a); /* 21 */
  5699. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x53); /* 5a */
  5700. }
  5701. }
  5702. }
  5703. static void
  5704. SiS_SetGroup2_Tail(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
  5705. {
  5706. unsigned short temp;
  5707. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
  5708. if(SiS_Pr->SiS_VGAVDE == 525) {
  5709. temp = 0xc3;
  5710. if(SiS_Pr->SiS_ModeType <= ModeVGA) {
  5711. temp++;
  5712. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) temp += 2;
  5713. }
  5714. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2f,temp);
  5715. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x30,0xb3);
  5716. } else if(SiS_Pr->SiS_VGAVDE == 420) {
  5717. temp = 0x4d;
  5718. if(SiS_Pr->SiS_ModeType <= ModeVGA) {
  5719. temp++;
  5720. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) temp++;
  5721. }
  5722. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2f,temp);
  5723. }
  5724. }
  5725. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  5726. if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) {
  5727. if(SiS_Pr->SiS_VBType & VB_SIS30xB) {
  5728. SiS_SetRegOR(SiS_Pr->SiS_Part2Port,0x1a,0x03);
  5729. /* Not always for LV, see SetGrp2 */
  5730. }
  5731. temp = 1;
  5732. if(ModeNo <= 0x13) temp = 3;
  5733. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x0b,temp);
  5734. }
  5735. #if 0
  5736. /* 651+301C, for 1280x768 - do I really need that? */
  5737. if((SiS_Pr->SiS_PanelXRes == 1280) && (SiS_Pr->SiS_PanelYRes == 768)) {
  5738. if(SiS_Pr->SiS_VBInfo & SetSimuScanMode) {
  5739. if(((SiS_Pr->SiS_HDE == 640) && (SiS_Pr->SiS_VDE == 480)) ||
  5740. ((SiS_Pr->SiS_HDE == 320) && (SiS_Pr->SiS_VDE == 240))) {
  5741. SiS_SetReg(SiS_Part2Port,0x01,0x2b);
  5742. SiS_SetReg(SiS_Part2Port,0x02,0x13);
  5743. SiS_SetReg(SiS_Part2Port,0x04,0xe5);
  5744. SiS_SetReg(SiS_Part2Port,0x05,0x08);
  5745. SiS_SetReg(SiS_Part2Port,0x06,0xe2);
  5746. SiS_SetReg(SiS_Part2Port,0x1c,0x21);
  5747. SiS_SetReg(SiS_Part2Port,0x1d,0x45);
  5748. SiS_SetReg(SiS_Part2Port,0x1f,0x0b);
  5749. SiS_SetReg(SiS_Part2Port,0x20,0x00);
  5750. SiS_SetReg(SiS_Part2Port,0x21,0xa9);
  5751. SiS_SetReg(SiS_Part2Port,0x23,0x0b);
  5752. SiS_SetReg(SiS_Part2Port,0x25,0x04);
  5753. }
  5754. }
  5755. }
  5756. #endif
  5757. }
  5758. }
  5759. static void
  5760. SiS_SetGroup2(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  5761. unsigned short RefreshRateTableIndex)
  5762. {
  5763. unsigned short i, j, tempax, tempbx, tempcx, tempch, tempcl, temp;
  5764. unsigned short push2, modeflag, crt2crtc, bridgeoffset;
  5765. unsigned int longtemp, PhaseIndex;
  5766. BOOLEAN newtvphase;
  5767. const unsigned char *TimingPoint;
  5768. #ifdef SIS315H
  5769. unsigned short resindex, CRT2Index;
  5770. const struct SiS_Part2PortTbl *CRT2Part2Ptr = NULL;
  5771. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) return;
  5772. #endif
  5773. if(ModeNo <= 0x13) {
  5774. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  5775. crt2crtc = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  5776. } else if(SiS_Pr->UseCustomMode) {
  5777. modeflag = SiS_Pr->CModeFlag;
  5778. crt2crtc = 0;
  5779. } else {
  5780. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  5781. crt2crtc = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  5782. }
  5783. temp = 0;
  5784. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToAVIDEO)) temp |= 0x08;
  5785. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToSVIDEO)) temp |= 0x04;
  5786. if(SiS_Pr->SiS_VBInfo & SetCRT2ToSCART) temp |= 0x02;
  5787. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) temp |= 0x01;
  5788. if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) temp |= 0x10;
  5789. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x00,temp);
  5790. PhaseIndex = 0x01; /* SiS_PALPhase */
  5791. TimingPoint = SiS_Pr->SiS_PALTiming;
  5792. newtvphase = FALSE;
  5793. if( (SiS_Pr->SiS_VBType & VB_SIS30xBLV) &&
  5794. ( (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) ||
  5795. (SiS_Pr->SiS_TVMode & TVSetTVSimuMode) ) ) {
  5796. newtvphase = TRUE;
  5797. }
  5798. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  5799. TimingPoint = SiS_Pr->SiS_HiTVExtTiming;
  5800. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  5801. TimingPoint = SiS_Pr->SiS_HiTVSt2Timing;
  5802. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) {
  5803. TimingPoint = SiS_Pr->SiS_HiTVSt1Timing;
  5804. }
  5805. }
  5806. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  5807. i = 0;
  5808. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) i = 2;
  5809. else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) i = 1;
  5810. TimingPoint = &SiS_YPbPrTable[i][0];
  5811. PhaseIndex = 0x00; /* SiS_NTSCPhase */
  5812. } else if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  5813. if(newtvphase) PhaseIndex = 0x09; /* SiS_PALPhase2 */
  5814. } else {
  5815. TimingPoint = SiS_Pr->SiS_NTSCTiming;
  5816. PhaseIndex = (SiS_Pr->SiS_TVMode & TVSetNTSCJ) ? 0x01 : 0x00; /* SiS_PALPhase : SiS_NTSCPhase */
  5817. if(newtvphase) PhaseIndex += 8; /* SiS_PALPhase2 : SiS_NTSCPhase2 */
  5818. }
  5819. if(SiS_Pr->SiS_TVMode & (TVSetPALM | TVSetPALN)) {
  5820. PhaseIndex = (SiS_Pr->SiS_TVMode & TVSetPALM) ? 0x02 : 0x03; /* SiS_PALMPhase : SiS_PALNPhase */
  5821. if(newtvphase) PhaseIndex += 8; /* SiS_PALMPhase2 : SiS_PALNPhase2 */
  5822. }
  5823. if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) {
  5824. if(SiS_Pr->SiS_TVMode & TVSetPALM) {
  5825. PhaseIndex = 0x05; /* SiS_SpecialPhaseM */
  5826. } else if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) {
  5827. PhaseIndex = 0x11; /* SiS_SpecialPhaseJ */
  5828. } else {
  5829. PhaseIndex = 0x10; /* SiS_SpecialPhase */
  5830. }
  5831. }
  5832. for(i = 0x31, j = 0; i <= 0x34; i++, j++) {
  5833. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS_TVPhase[(PhaseIndex * 4) + j]);
  5834. }
  5835. for(i = 0x01, j = 0; i <= 0x2D; i++, j++) {
  5836. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,TimingPoint[j]);
  5837. }
  5838. for(i = 0x39; i <= 0x45; i++, j++) {
  5839. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,TimingPoint[j]);
  5840. }
  5841. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  5842. if(SiS_Pr->SiS_ModeType != ModeText) {
  5843. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x3A,0x1F);
  5844. }
  5845. }
  5846. SiS_SetRegOR(SiS_Pr->SiS_Part2Port,0x0A,SiS_Pr->SiS_NewFlickerMode);
  5847. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x35,SiS_Pr->SiS_RY1COE);
  5848. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x36,SiS_Pr->SiS_RY2COE);
  5849. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x37,SiS_Pr->SiS_RY3COE);
  5850. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x38,SiS_Pr->SiS_RY4COE);
  5851. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) tempax = 950;
  5852. else if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) tempax = 680;
  5853. else if(SiS_Pr->SiS_TVMode & TVSetPAL) tempax = 520;
  5854. else tempax = 440; /* NTSC, YPbPr 525 */
  5855. if( ((SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) && (SiS_Pr->SiS_VDE <= tempax)) ||
  5856. ( (SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoHiVision) &&
  5857. ((SiS_Pr->SiS_VGAHDE == 1024) || (SiS_Pr->SiS_VDE <= tempax)) ) ) {
  5858. tempax -= SiS_Pr->SiS_VDE;
  5859. tempax >>= 1;
  5860. if(!(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p))) {
  5861. tempax >>= 1;
  5862. }
  5863. tempax &= 0x00ff;
  5864. temp = tempax + (unsigned short)TimingPoint[0];
  5865. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,temp);
  5866. temp = tempax + (unsigned short)TimingPoint[1];
  5867. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,temp);
  5868. if((SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoYPbPrHiVision) && (SiS_Pr->SiS_VGAHDE >= 1024)) {
  5869. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  5870. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x1b);
  5871. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x54);
  5872. } else {
  5873. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x17);
  5874. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x1d);
  5875. }
  5876. }
  5877. }
  5878. tempcx = SiS_Pr->SiS_HT;
  5879. if(SiS_IsDualLink(SiS_Pr)) tempcx >>= 1;
  5880. tempcx--;
  5881. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) tempcx--;
  5882. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x1B,tempcx);
  5883. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1D,0xF0,((tempcx >> 8) & 0x0f));
  5884. tempcx = SiS_Pr->SiS_HT >> 1;
  5885. if(SiS_IsDualLink(SiS_Pr)) tempcx >>= 1;
  5886. tempcx += 7;
  5887. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) tempcx -= 4;
  5888. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x22,0x0F,((tempcx << 4) & 0xf0));
  5889. tempbx = TimingPoint[j] | (TimingPoint[j+1] << 8);
  5890. tempbx += tempcx;
  5891. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x24,tempbx);
  5892. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x25,0x0F,((tempbx >> 4) & 0xf0));
  5893. tempbx += 8;
  5894. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  5895. tempbx -= 4;
  5896. tempcx = tempbx;
  5897. }
  5898. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x29,0x0F,((tempbx << 4) & 0xf0));
  5899. j += 2;
  5900. tempcx += (TimingPoint[j] | (TimingPoint[j+1] << 8));
  5901. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x27,tempcx);
  5902. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x28,0x0F,((tempcx >> 4) & 0xf0));
  5903. tempcx += 8;
  5904. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) tempcx -= 4;
  5905. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2A,0x0F,((tempcx << 4) & 0xf0));
  5906. tempcx = SiS_Pr->SiS_HT >> 1;
  5907. if(SiS_IsDualLink(SiS_Pr)) tempcx >>= 1;
  5908. j += 2;
  5909. tempcx -= (TimingPoint[j] | ((TimingPoint[j+1]) << 8));
  5910. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2D,0x0F,((tempcx << 4) & 0xf0));
  5911. tempcx -= 11;
  5912. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
  5913. tempcx = SiS_GetVGAHT2(SiS_Pr) - 1;
  5914. }
  5915. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2E,tempcx);
  5916. tempbx = SiS_Pr->SiS_VDE;
  5917. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  5918. if(SiS_Pr->SiS_VGAVDE == 360) tempbx = 746;
  5919. if(SiS_Pr->SiS_VGAVDE == 375) tempbx = 746;
  5920. if(SiS_Pr->SiS_VGAVDE == 405) tempbx = 853;
  5921. } else if( (SiS_Pr->SiS_VBInfo & SetCRT2ToTV) &&
  5922. (!(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p|TVSetYPbPr750p))) ) {
  5923. tempbx >>= 1;
  5924. if(SiS_Pr->ChipType >= SIS_315H) {
  5925. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) {
  5926. if((ModeNo <= 0x13) && (crt2crtc == 1)) tempbx++;
  5927. } else if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  5928. if(SiS_Pr->SiS_ModeType <= ModeVGA) {
  5929. if(crt2crtc == 4) tempbx++;
  5930. }
  5931. }
  5932. }
  5933. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  5934. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  5935. if((ModeNo == 0x2f) || (ModeNo == 0x5d) || (ModeNo == 0x5e)) tempbx++;
  5936. }
  5937. if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) {
  5938. if(ModeNo == 0x03) tempbx++; /* From 1.10.7w - doesn't make sense */
  5939. }
  5940. }
  5941. }
  5942. tempbx -= 2;
  5943. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2F,tempbx);
  5944. temp = (tempcx >> 8) & 0x0F;
  5945. temp |= ((tempbx >> 2) & 0xC0);
  5946. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToSVIDEO | SetCRT2ToAVIDEO)) {
  5947. temp |= 0x10;
  5948. if(SiS_Pr->SiS_VBInfo & SetCRT2ToAVIDEO) temp |= 0x20;
  5949. }
  5950. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x30,temp);
  5951. if(SiS_Pr->SiS_VBType & VB_SISPART4OVERFLOW) {
  5952. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x10,0xdf,((tempbx & 0x0400) >> 5));
  5953. }
  5954. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  5955. tempbx = SiS_Pr->SiS_VDE;
  5956. if( (SiS_Pr->SiS_VBInfo & SetCRT2ToTV) &&
  5957. (!(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p))) ) {
  5958. tempbx >>= 1;
  5959. }
  5960. tempbx -= 3;
  5961. temp = ((tempbx >> 3) & 0x60) | 0x18;
  5962. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x46,temp);
  5963. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x47,tempbx);
  5964. if(SiS_Pr->SiS_VBType & VB_SISPART4OVERFLOW) {
  5965. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x10,0xbf,((tempbx & 0x0400) >> 4));
  5966. }
  5967. }
  5968. tempbx = 0;
  5969. if(!(modeflag & HalfDCLK)) {
  5970. if(SiS_Pr->SiS_VGAHDE >= SiS_Pr->SiS_HDE) {
  5971. tempax = 0;
  5972. tempbx |= 0x20;
  5973. }
  5974. }
  5975. tempch = tempcl = 0x01;
  5976. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  5977. if(SiS_Pr->SiS_VGAHDE >= 960) {
  5978. if((!(modeflag & HalfDCLK)) || (SiS_Pr->ChipType < SIS_315H)) {
  5979. tempcl = 0x20;
  5980. if(SiS_Pr->SiS_VGAHDE >= 1280) {
  5981. tempch = 20;
  5982. tempbx &= ~0x20;
  5983. } else if(SiS_Pr->SiS_VGAHDE >= 1024) {
  5984. tempch = 25;
  5985. } else {
  5986. tempch = 25; /* OK */
  5987. }
  5988. }
  5989. }
  5990. }
  5991. if(!(tempbx & 0x20)) {
  5992. if(modeflag & HalfDCLK) tempcl <<= 1;
  5993. longtemp = ((SiS_Pr->SiS_VGAHDE * tempch) / tempcl) << 13;
  5994. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) longtemp <<= 3;
  5995. tempax = longtemp / SiS_Pr->SiS_HDE;
  5996. if(longtemp % SiS_Pr->SiS_HDE) tempax++;
  5997. tempbx |= ((tempax >> 8) & 0x1F);
  5998. tempcx = tempax >> 13;
  5999. }
  6000. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x44,tempax);
  6001. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x45,0xC0,tempbx);
  6002. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  6003. tempcx &= 0x07;
  6004. if(tempbx & 0x20) tempcx = 0;
  6005. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x46,0xF8,tempcx);
  6006. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  6007. tempbx = 0x0382;
  6008. tempcx = 0x007e;
  6009. } else {
  6010. tempbx = 0x0369;
  6011. tempcx = 0x0061;
  6012. }
  6013. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x4B,tempbx);
  6014. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x4C,tempcx);
  6015. temp = (tempcx & 0x0300) >> 6;
  6016. temp |= ((tempbx >> 8) & 0x03);
  6017. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  6018. temp |= 0x10;
  6019. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) temp |= 0x20;
  6020. else if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) temp |= 0x40;
  6021. }
  6022. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x4D,temp);
  6023. temp = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x43);
  6024. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x43,(temp - 3));
  6025. SiS_SetTVSpecial(SiS_Pr, ModeNo);
  6026. if(SiS_Pr->SiS_VBType & VB_SIS30xCLV) {
  6027. temp = 0;
  6028. if(SiS_Pr->SiS_TVMode & TVSetPALM) temp = 8;
  6029. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x4e,0xf7,temp);
  6030. }
  6031. }
  6032. if(SiS_Pr->SiS_TVMode & TVSetPALM) {
  6033. if(!(SiS_Pr->SiS_TVMode & TVSetNTSC1024)) {
  6034. temp = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x01);
  6035. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,(temp - 1));
  6036. }
  6037. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xEF);
  6038. }
  6039. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  6040. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  6041. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x0B,0x00);
  6042. }
  6043. }
  6044. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) return;
  6045. /* From here: Part2 LCD setup */
  6046. tempbx = SiS_Pr->SiS_HDE;
  6047. if(SiS_IsDualLink(SiS_Pr)) tempbx >>= 1;
  6048. tempbx--; /* RHACTE = HDE - 1 */
  6049. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2C,tempbx);
  6050. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2B,0x0F,((tempbx >> 4) & 0xf0));
  6051. temp = 0x01;
  6052. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) {
  6053. if(SiS_Pr->SiS_ModeType == ModeEGA) {
  6054. if(SiS_Pr->SiS_VGAHDE >= 1024) {
  6055. temp = 0x02;
  6056. if(SiS_Pr->SiS_SetFlag & LCDVESATiming) {
  6057. temp = 0x01;
  6058. }
  6059. }
  6060. }
  6061. }
  6062. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x0B,temp);
  6063. tempbx = SiS_Pr->SiS_VDE - 1;
  6064. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x03,tempbx);
  6065. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x0C,0xF8,((tempbx >> 8) & 0x07));
  6066. tempcx = SiS_Pr->SiS_VT - 1;
  6067. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x19,tempcx);
  6068. temp = (tempcx >> 3) & 0xE0;
  6069. if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) {
  6070. /* Enable dithering; only do this for 32bpp mode */
  6071. if(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x01) {
  6072. temp |= 0x10;
  6073. }
  6074. }
  6075. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1A,0x0f,temp);
  6076. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x09,0xF0);
  6077. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x0A,0xF0);
  6078. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x17,0xFB);
  6079. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x18,0xDF);
  6080. #ifdef SIS315H
  6081. if(SiS_GetCRT2Part2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex,
  6082. &CRT2Index, &resindex)) {
  6083. switch(CRT2Index) {
  6084. case 206: CRT2Part2Ptr = SiS310_CRT2Part2_Asus1024x768_3; break;
  6085. default:
  6086. case 200: CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1024x768_1; break;
  6087. }
  6088. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x01,0x80,(CRT2Part2Ptr+resindex)->CR[0]);
  6089. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x02,0x80,(CRT2Part2Ptr+resindex)->CR[1]);
  6090. for(i = 2, j = 0x04; j <= 0x06; i++, j++ ) {
  6091. SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]);
  6092. }
  6093. for(j = 0x1c; j <= 0x1d; i++, j++ ) {
  6094. SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]);
  6095. }
  6096. for(j = 0x1f; j <= 0x21; i++, j++ ) {
  6097. SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]);
  6098. }
  6099. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x23,(CRT2Part2Ptr+resindex)->CR[10]);
  6100. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x25,0x0f,(CRT2Part2Ptr+resindex)->CR[11]);
  6101. SiS_SetGroup2_Tail(SiS_Pr, ModeNo);
  6102. } else {
  6103. #endif
  6104. /* Checked for 1024x768, 1280x1024, 1400x1050, 1600x1200 */
  6105. /* Clevo dual-link 1024x768 */
  6106. /* Compaq 1280x1024 has HT 1696 sometimes (calculation OK, if given HT is correct) */
  6107. /* Acer: OK, but uses different setting for VESA timing at 640/800/1024 and 640x400 */
  6108. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  6109. if((SiS_Pr->SiS_LCDInfo & LCDPass11) || (SiS_Pr->PanelYRes == SiS_Pr->SiS_VDE)) {
  6110. tempbx = SiS_Pr->SiS_VDE - 1;
  6111. tempcx = SiS_Pr->SiS_VT - 1;
  6112. } else {
  6113. tempbx = SiS_Pr->SiS_VDE + ((SiS_Pr->PanelYRes - SiS_Pr->SiS_VDE) / 2);
  6114. tempcx = SiS_Pr->SiS_VT - ((SiS_Pr->PanelYRes - SiS_Pr->SiS_VDE) / 2);
  6115. }
  6116. } else {
  6117. tempbx = SiS_Pr->PanelYRes;
  6118. tempcx = SiS_Pr->SiS_VT;
  6119. tempax = 1;
  6120. if(SiS_Pr->PanelYRes != SiS_Pr->SiS_VDE) {
  6121. tempax = SiS_Pr->PanelYRes;
  6122. /* if(SiS_Pr->SiS_VGAVDE == 525) tempax += 0x3c; */ /* 651+301C */
  6123. if(SiS_Pr->PanelYRes < SiS_Pr->SiS_VDE) {
  6124. tempax = tempcx = 0;
  6125. } else {
  6126. tempax -= SiS_Pr->SiS_VDE;
  6127. }
  6128. tempax >>= 1;
  6129. }
  6130. tempcx -= tempax; /* lcdvdes */
  6131. tempbx -= tempax; /* lcdvdee */
  6132. }
  6133. /* Non-expanding: lcdvdes = tempcx = VT-1; lcdvdee = tempbx = VDE-1 */
  6134. #ifdef SIS_XORG_XF86
  6135. #ifdef TWDEBUG
  6136. xf86DrvMsg(0, X_INFO, "lcdvdes 0x%x lcdvdee 0x%x\n", tempcx, tempbx);
  6137. #endif
  6138. #endif
  6139. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x05,tempcx); /* lcdvdes */
  6140. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x06,tempbx); /* lcdvdee */
  6141. temp = (tempbx >> 5) & 0x38;
  6142. temp |= ((tempcx >> 8) & 0x07);
  6143. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,temp);
  6144. tempax = SiS_Pr->SiS_VDE;
  6145. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
  6146. tempax = SiS_Pr->PanelYRes;
  6147. }
  6148. tempcx = (SiS_Pr->SiS_VT - tempax) >> 4;
  6149. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
  6150. if(SiS_Pr->PanelYRes != SiS_Pr->SiS_VDE) {
  6151. tempcx = (SiS_Pr->SiS_VT - tempax) / 10;
  6152. }
  6153. }
  6154. tempbx = ((SiS_Pr->SiS_VT + SiS_Pr->SiS_VDE) >> 1) - 1;
  6155. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  6156. if(SiS_Pr->PanelYRes != SiS_Pr->SiS_VDE) {
  6157. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) { /* ? */
  6158. tempax = SiS_Pr->SiS_VT - SiS_Pr->PanelYRes;
  6159. if(tempax % 4) { tempax >>= 2; tempax++; }
  6160. else { tempax >>= 2; }
  6161. tempbx -= (tempax - 1);
  6162. } else {
  6163. tempbx -= 10;
  6164. if(tempbx <= SiS_Pr->SiS_VDE) tempbx = SiS_Pr->SiS_VDE + 1;
  6165. }
  6166. }
  6167. }
  6168. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  6169. tempbx++;
  6170. if((!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) || (crt2crtc == 6)) {
  6171. if(SiS_Pr->SiS_SetFlag & LCDVESATiming) {
  6172. tempbx = 770;
  6173. tempcx = 3;
  6174. }
  6175. }
  6176. }
  6177. /* non-expanding: lcdvrs = ((VT + VDE) / 2) - 10 */
  6178. if(SiS_Pr->UseCustomMode) {
  6179. tempbx = SiS_Pr->CVSyncStart;
  6180. }
  6181. #ifdef SIS_XORG_XF86
  6182. #ifdef TWDEBUG
  6183. xf86DrvMsg(0, X_INFO, "lcdvrs 0x%x\n", tempbx);
  6184. #endif
  6185. #endif
  6186. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,tempbx); /* lcdvrs */
  6187. temp = (tempbx >> 4) & 0xF0;
  6188. tempbx += (tempcx + 1);
  6189. temp |= (tempbx & 0x0F);
  6190. if(SiS_Pr->UseCustomMode) {
  6191. temp &= 0xf0;
  6192. temp |= (SiS_Pr->CVSyncEnd & 0x0f);
  6193. }
  6194. #ifdef SIS_XORG_XF86
  6195. #ifdef TWDEBUG
  6196. xf86DrvMsg(0, X_INFO, "lcdvre[3:0] 0x%x\n", (temp & 0x0f));
  6197. #endif
  6198. #endif
  6199. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,temp);
  6200. #ifdef SIS300
  6201. SiS_Group2LCDSpecial(SiS_Pr, ModeNo, crt2crtc);
  6202. #endif
  6203. bridgeoffset = 7;
  6204. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) bridgeoffset += 2;
  6205. if(SiS_Pr->SiS_VBType & VB_SIS30xCLV) bridgeoffset += 2; /* OK for Averatec 1280x800 (301C) */
  6206. if(SiS_IsDualLink(SiS_Pr)) bridgeoffset++;
  6207. else if(SiS_Pr->SiS_VBType & VB_SIS302LV) bridgeoffset++; /* OK for Asus A4L 1280x800 */
  6208. /* Higher bridgeoffset shifts to the LEFT */
  6209. temp = 0;
  6210. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
  6211. if(SiS_Pr->PanelXRes != SiS_Pr->SiS_HDE) {
  6212. temp = SiS_Pr->SiS_HT - ((SiS_Pr->PanelXRes - SiS_Pr->SiS_HDE) / 2);
  6213. if(SiS_IsDualLink(SiS_Pr)) temp >>= 1;
  6214. }
  6215. }
  6216. temp += bridgeoffset;
  6217. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x1F,temp); /* lcdhdes */
  6218. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x20,0x0F,((temp >> 4) & 0xf0));
  6219. tempcx = SiS_Pr->SiS_HT;
  6220. tempax = tempbx = SiS_Pr->SiS_HDE;
  6221. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
  6222. if(SiS_Pr->PanelXRes != SiS_Pr->SiS_HDE) {
  6223. tempax = SiS_Pr->PanelXRes;
  6224. tempbx = SiS_Pr->PanelXRes - ((SiS_Pr->PanelXRes - SiS_Pr->SiS_HDE) / 2);
  6225. }
  6226. }
  6227. if(SiS_IsDualLink(SiS_Pr)) {
  6228. tempcx >>= 1;
  6229. tempbx >>= 1;
  6230. tempax >>= 1;
  6231. }
  6232. #ifdef SIS_XORG_XF86
  6233. #ifdef TWDEBUG
  6234. xf86DrvMsg(0, X_INFO, "lcdhdee 0x%x\n", tempbx);
  6235. #endif
  6236. #endif
  6237. tempbx += bridgeoffset;
  6238. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x23,tempbx); /* lcdhdee */
  6239. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x25,0xF0,((tempbx >> 8) & 0x0f));
  6240. tempcx = (tempcx - tempax) >> 2;
  6241. tempbx += tempcx;
  6242. push2 = tempbx;
  6243. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) {
  6244. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  6245. if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
  6246. if(SiS_Pr->SiS_HDE == 1280) tempbx = (tempbx & 0xff00) | 0x47;
  6247. }
  6248. }
  6249. }
  6250. if(SiS_Pr->UseCustomMode) {
  6251. tempbx = SiS_Pr->CHSyncStart;
  6252. if(modeflag & HalfDCLK) tempbx <<= 1;
  6253. if(SiS_IsDualLink(SiS_Pr)) tempbx >>= 1;
  6254. tempbx += bridgeoffset;
  6255. }
  6256. #ifdef SIS_XORG_XF86
  6257. #ifdef TWDEBUG
  6258. xf86DrvMsg(0, X_INFO, "lcdhrs 0x%x\n", tempbx);
  6259. #endif
  6260. #endif
  6261. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x1C,tempbx); /* lcdhrs */
  6262. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1D,0x0F,((tempbx >> 4) & 0xf0));
  6263. tempbx = push2;
  6264. tempcx <<= 1;
  6265. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
  6266. if(SiS_Pr->PanelXRes != SiS_Pr->SiS_HDE) tempcx >>= 2;
  6267. }
  6268. tempbx += tempcx;
  6269. if(SiS_Pr->UseCustomMode) {
  6270. tempbx = SiS_Pr->CHSyncEnd;
  6271. if(modeflag & HalfDCLK) tempbx <<= 1;
  6272. if(SiS_IsDualLink(SiS_Pr)) tempbx >>= 1;
  6273. tempbx += bridgeoffset;
  6274. }
  6275. #ifdef SIS_XORG_XF86
  6276. #ifdef TWDEBUG
  6277. xf86DrvMsg(0, X_INFO, "lcdhre 0x%x\n", tempbx);
  6278. #endif
  6279. #endif
  6280. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x21,tempbx); /* lcdhre */
  6281. SiS_SetGroup2_Tail(SiS_Pr, ModeNo);
  6282. #ifdef SIS300
  6283. SiS_Set300Part2Regs(SiS_Pr, ModeIdIndex, RefreshRateTableIndex, ModeNo);
  6284. #endif
  6285. #ifdef SIS315H
  6286. } /* CRT2-LCD from table */
  6287. #endif
  6288. }
  6289. /*********************************************/
  6290. /* SET PART 3 REGISTER GROUP */
  6291. /*********************************************/
  6292. static void
  6293. SiS_SetGroup3(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  6294. {
  6295. unsigned short i;
  6296. const unsigned char *tempdi;
  6297. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) return;
  6298. #ifndef SIS_CP
  6299. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x00,0x00);
  6300. #else
  6301. SIS_CP_INIT301_CP
  6302. #endif
  6303. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  6304. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x13,0xFA);
  6305. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x14,0xC8);
  6306. } else {
  6307. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x13,0xF5);
  6308. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x14,0xB7);
  6309. }
  6310. if(SiS_Pr->SiS_TVMode & TVSetPALM) {
  6311. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x13,0xFA);
  6312. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x14,0xC8);
  6313. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x3D,0xA8);
  6314. }
  6315. tempdi = NULL;
  6316. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  6317. tempdi = SiS_Pr->SiS_HiTVGroup3Data;
  6318. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) {
  6319. tempdi = SiS_Pr->SiS_HiTVGroup3Simu;
  6320. }
  6321. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  6322. if(!(SiS_Pr->SiS_TVMode & TVSetYPbPr525i)) {
  6323. tempdi = SiS_HiTVGroup3_1;
  6324. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) tempdi = SiS_HiTVGroup3_2;
  6325. }
  6326. }
  6327. if(tempdi) {
  6328. for(i=0; i<=0x3E; i++) {
  6329. SiS_SetReg(SiS_Pr->SiS_Part3Port,i,tempdi[i]);
  6330. }
  6331. if(SiS_Pr->SiS_VBType & VB_SIS30xCLV) {
  6332. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) {
  6333. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x28,0x3f);
  6334. }
  6335. }
  6336. }
  6337. #ifdef SIS_CP
  6338. SIS_CP_INIT301_CP2
  6339. #endif
  6340. }
  6341. /*********************************************/
  6342. /* SET PART 4 REGISTER GROUP */
  6343. /*********************************************/
  6344. #ifdef SIS315H
  6345. #if 0
  6346. static void
  6347. SiS_ShiftXPos(struct SiS_Private *SiS_Pr, int shift)
  6348. {
  6349. unsigned short temp, temp1, temp2;
  6350. temp1 = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x1f);
  6351. temp2 = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x20);
  6352. temp = (unsigned short)((int)((temp1 | ((temp2 & 0xf0) << 4))) + shift);
  6353. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x1f,temp);
  6354. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x20,0x0f,((temp >> 4) & 0xf0));
  6355. temp = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x2b) & 0x0f;
  6356. temp = (unsigned short)((int)(temp) + shift);
  6357. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2b,0xf0,(temp & 0x0f));
  6358. temp1 = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x43);
  6359. temp2 = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x42);
  6360. temp = (unsigned short)((int)((temp1 | ((temp2 & 0xf0) << 4))) + shift);
  6361. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x43,temp);
  6362. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x42,0x0f,((temp >> 4) & 0xf0));
  6363. }
  6364. #endif
  6365. static void
  6366. SiS_SetGroup4_C_ELV(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  6367. {
  6368. unsigned short temp, temp1, resinfo = 0;
  6369. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  6370. if(!(SiS_Pr->SiS_VBType & VB_SIS30xCLV)) return;
  6371. if(!(SiS_Pr->SiS_VBInfo & (SetCRT2ToHiVision | SetCRT2ToYPbPr525750))) return;
  6372. if(SiS_Pr->ChipType >= XGI_20) return;
  6373. if((SiS_Pr->ChipType >= SIS_661) && (SiS_Pr->SiS_ROMNew)) {
  6374. if(!(ROMAddr[0x61] & 0x04)) return;
  6375. }
  6376. if(ModeNo > 0x13) {
  6377. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  6378. }
  6379. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x3a,0x08);
  6380. temp = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x3a);
  6381. if(!(temp & 0x01)) {
  6382. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x3a,0xdf);
  6383. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x25,0xfc);
  6384. if((SiS_Pr->ChipType < SIS_661) && (!(SiS_Pr->SiS_ROMNew))) {
  6385. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x25,0xf8);
  6386. }
  6387. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x0f,0xfb);
  6388. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) temp = 0x0000;
  6389. else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) temp = 0x0002;
  6390. else if(SiS_Pr->SiS_TVMode & TVSetHiVision) temp = 0x0400;
  6391. else temp = 0x0402;
  6392. if((SiS_Pr->ChipType >= SIS_661) || (SiS_Pr->SiS_ROMNew)) {
  6393. temp1 = 0;
  6394. if(SiS_Pr->SiS_TVMode & TVAspect43) temp1 = 4;
  6395. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x0f,0xfb,temp1);
  6396. if(SiS_Pr->SiS_TVMode & TVAspect43LB) temp |= 0x01;
  6397. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x26,0x7c,(temp & 0xff));
  6398. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x3a,0xfb,(temp >> 8));
  6399. if(ModeNo > 0x13) {
  6400. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x39,0xfd);
  6401. }
  6402. } else {
  6403. temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x3b) & 0x03;
  6404. if(temp1 == 0x01) temp |= 0x01;
  6405. if(temp1 == 0x03) temp |= 0x04; /* ? why not 0x10? */
  6406. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x26,0xf8,(temp & 0xff));
  6407. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x3a,0xfb,(temp >> 8));
  6408. if(ModeNo > 0x13) {
  6409. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x3b,0xfd);
  6410. }
  6411. }
  6412. #if 0
  6413. if(SiS_Pr->ChipType >= SIS_661) { /* ? */
  6414. if(SiS_Pr->SiS_TVMode & TVAspect43) {
  6415. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) {
  6416. if(resinfo == SIS_RI_1024x768) {
  6417. SiS_ShiftXPos(SiS_Pr, 97);
  6418. } else {
  6419. SiS_ShiftXPos(SiS_Pr, 111);
  6420. }
  6421. } else if(SiS_Pr->SiS_TVMode & TVSetHiVision) {
  6422. SiS_ShiftXPos(SiS_Pr, 136);
  6423. }
  6424. }
  6425. }
  6426. #endif
  6427. }
  6428. }
  6429. #endif
  6430. static void
  6431. SiS_SetCRT2VCLK(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  6432. unsigned short RefreshRateTableIndex)
  6433. {
  6434. unsigned short vclkindex, temp, reg1, reg2;
  6435. if(SiS_Pr->UseCustomMode) {
  6436. reg1 = SiS_Pr->CSR2B;
  6437. reg2 = SiS_Pr->CSR2C;
  6438. } else {
  6439. vclkindex = SiS_GetVCLK2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  6440. reg1 = SiS_Pr->SiS_VBVCLKData[vclkindex].Part4_A;
  6441. reg2 = SiS_Pr->SiS_VBVCLKData[vclkindex].Part4_B;
  6442. }
  6443. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  6444. if(SiS_Pr->SiS_TVMode & (TVSetNTSC1024 | TVSet525p1024)) {
  6445. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0a,0x57);
  6446. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0b,0x46);
  6447. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1f,0xf6);
  6448. } else {
  6449. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0a,reg1);
  6450. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0b,reg2);
  6451. }
  6452. } else {
  6453. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0a,0x01);
  6454. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0b,reg2);
  6455. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0a,reg1);
  6456. }
  6457. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x12,0x00);
  6458. temp = 0x08;
  6459. if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) temp |= 0x20;
  6460. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x12,temp);
  6461. }
  6462. static void
  6463. SiS_SetDualLinkEtc(struct SiS_Private *SiS_Pr)
  6464. {
  6465. if(SiS_Pr->ChipType >= SIS_315H) {
  6466. if(SiS_Pr->SiS_VBType & VB_SISDUALLINK) {
  6467. if((SiS_CRT2IsLCD(SiS_Pr)) ||
  6468. (SiS_IsVAMode(SiS_Pr))) {
  6469. if(SiS_Pr->SiS_LCDInfo & LCDDualLink) {
  6470. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x27,0x2c);
  6471. } else {
  6472. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x27,~0x20);
  6473. }
  6474. }
  6475. }
  6476. }
  6477. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  6478. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2a,0x00);
  6479. #ifdef SET_EMI
  6480. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
  6481. #endif
  6482. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x34,0x10);
  6483. }
  6484. }
  6485. static void
  6486. SiS_SetGroup4(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  6487. unsigned short RefreshRateTableIndex)
  6488. {
  6489. unsigned short tempax, tempcx, tempbx, modeflag, temp, resinfo;
  6490. unsigned int tempebx, tempeax, templong;
  6491. if(ModeNo <= 0x13) {
  6492. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  6493. resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
  6494. } else if(SiS_Pr->UseCustomMode) {
  6495. modeflag = SiS_Pr->CModeFlag;
  6496. resinfo = 0;
  6497. } else {
  6498. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  6499. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  6500. }
  6501. if(SiS_Pr->ChipType >= SIS_315H) {
  6502. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  6503. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  6504. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x24,0x0e);
  6505. }
  6506. }
  6507. }
  6508. if(SiS_Pr->SiS_VBType & (VB_SIS30xCLV | VB_SIS302LV)) {
  6509. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  6510. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x10,0x9f);
  6511. }
  6512. }
  6513. if(SiS_Pr->ChipType >= SIS_315H) {
  6514. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  6515. SiS_SetDualLinkEtc(SiS_Pr);
  6516. return;
  6517. }
  6518. }
  6519. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x13,SiS_Pr->SiS_RVBHCFACT);
  6520. tempbx = SiS_Pr->SiS_RVBHCMAX;
  6521. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x14,tempbx);
  6522. temp = (tempbx >> 1) & 0x80;
  6523. tempcx = SiS_Pr->SiS_VGAHT - 1;
  6524. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x16,tempcx);
  6525. temp |= ((tempcx >> 5) & 0x78);
  6526. tempcx = SiS_Pr->SiS_VGAVT - 1;
  6527. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) tempcx -= 5;
  6528. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x17,tempcx);
  6529. temp |= ((tempcx >> 8) & 0x07);
  6530. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x15,temp);
  6531. tempbx = SiS_Pr->SiS_VGAHDE;
  6532. if(modeflag & HalfDCLK) tempbx >>= 1;
  6533. if(SiS_IsDualLink(SiS_Pr)) tempbx >>= 1;
  6534. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  6535. temp = 0;
  6536. if(tempbx > 800) temp = 0x60;
  6537. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  6538. temp = 0;
  6539. if(tempbx > 1024) temp = 0xC0;
  6540. else if(tempbx >= 960) temp = 0xA0;
  6541. } else if(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p)) {
  6542. temp = 0;
  6543. if(tempbx >= 1280) temp = 0x40;
  6544. else if(tempbx >= 1024) temp = 0x20;
  6545. } else {
  6546. temp = 0x80;
  6547. if(tempbx >= 1024) temp = 0xA0;
  6548. }
  6549. temp |= SiS_Pr->Init_P4_0E;
  6550. if(SiS_Pr->SiS_VBType & VB_SIS301) {
  6551. if(SiS_Pr->SiS_LCDResInfo != Panel_1280x1024) {
  6552. temp &= 0xf0;
  6553. temp |= 0x0A;
  6554. }
  6555. }
  6556. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x0E,0x10,temp);
  6557. tempeax = SiS_Pr->SiS_VGAVDE;
  6558. tempebx = SiS_Pr->SiS_VDE;
  6559. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  6560. if(!(temp & 0xE0)) tempebx >>=1;
  6561. }
  6562. tempcx = SiS_Pr->SiS_RVBHRS;
  6563. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x18,tempcx);
  6564. tempcx >>= 8;
  6565. tempcx |= 0x40;
  6566. if(tempeax <= tempebx) {
  6567. tempcx ^= 0x40;
  6568. } else {
  6569. tempeax -= tempebx;
  6570. }
  6571. tempeax *= (256 * 1024);
  6572. templong = tempeax % tempebx;
  6573. tempeax /= tempebx;
  6574. if(templong) tempeax++;
  6575. temp = (unsigned short)(tempeax & 0x000000FF);
  6576. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1B,temp);
  6577. temp = (unsigned short)((tempeax & 0x0000FF00) >> 8);
  6578. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1A,temp);
  6579. temp = (unsigned short)((tempeax >> 12) & 0x70); /* sic! */
  6580. temp |= (tempcx & 0x4F);
  6581. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x19,temp);
  6582. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  6583. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1C,0x28);
  6584. /* Calc Linebuffer max address and set/clear decimode */
  6585. tempbx = 0;
  6586. if(SiS_Pr->SiS_TVMode & (TVSetHiVision | TVSetYPbPr750p)) tempbx = 0x08;
  6587. tempax = SiS_Pr->SiS_VGAHDE;
  6588. if(modeflag & HalfDCLK) tempax >>= 1;
  6589. if(SiS_IsDualLink(SiS_Pr)) tempax >>= 1;
  6590. if(tempax > 800) {
  6591. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  6592. tempax -= 800;
  6593. } else {
  6594. tempbx = 0x08;
  6595. if(tempax == 960) tempax *= 25; /* Correct */
  6596. else if(tempax == 1024) tempax *= 25;
  6597. else tempax *= 20;
  6598. temp = tempax % 32;
  6599. tempax /= 32;
  6600. if(temp) tempax++;
  6601. tempax++;
  6602. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  6603. if(resinfo == SIS_RI_1024x768 ||
  6604. resinfo == SIS_RI_1024x576 ||
  6605. resinfo == SIS_RI_1280x1024 ||
  6606. resinfo == SIS_RI_1280x720) {
  6607. /* Otherwise white line or garbage at right edge */
  6608. tempax = (tempax & 0xff00) | 0x20;
  6609. }
  6610. }
  6611. }
  6612. }
  6613. tempax--;
  6614. temp = ((tempax >> 4) & 0x30) | tempbx;
  6615. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1D,tempax);
  6616. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1E,temp);
  6617. temp = 0x0036; tempbx = 0xD0;
  6618. if((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->SiS_VBType & VB_SISLVDS)) {
  6619. temp = 0x0026; tempbx = 0xC0; /* See En/DisableBridge() */
  6620. }
  6621. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  6622. if(!(SiS_Pr->SiS_TVMode & (TVSetNTSC1024 | TVSetHiVision | TVSetYPbPr750p | TVSetYPbPr525p))) {
  6623. temp |= 0x01;
  6624. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  6625. if(!(SiS_Pr->SiS_TVMode & TVSetTVSimuMode)) {
  6626. temp &= ~0x01;
  6627. }
  6628. }
  6629. }
  6630. }
  6631. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x1F,tempbx,temp);
  6632. tempbx = SiS_Pr->SiS_HT >> 1;
  6633. if(SiS_IsDualLink(SiS_Pr)) tempbx >>= 1;
  6634. tempbx -= 2;
  6635. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x22,tempbx);
  6636. temp = (tempbx >> 5) & 0x38;
  6637. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x21,0xC0,temp);
  6638. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  6639. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  6640. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x24,0x0e);
  6641. /* LCD-too-dark-error-source, see FinalizeLCD() */
  6642. }
  6643. }
  6644. SiS_SetDualLinkEtc(SiS_Pr);
  6645. } /* 301B */
  6646. SiS_SetCRT2VCLK(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  6647. }
  6648. /*********************************************/
  6649. /* SET PART 5 REGISTER GROUP */
  6650. /*********************************************/
  6651. static void
  6652. SiS_SetGroup5(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  6653. {
  6654. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) return;
  6655. if(SiS_Pr->SiS_ModeType == ModeVGA) {
  6656. if(!(SiS_Pr->SiS_VBInfo & (SetInSlaveMode | LoadDACFlag))) {
  6657. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);
  6658. SiS_LoadDAC(SiS_Pr, ModeNo, ModeIdIndex);
  6659. }
  6660. }
  6661. }
  6662. /*********************************************/
  6663. /* MODIFY CRT1 GROUP FOR SLAVE MODE */
  6664. /*********************************************/
  6665. static BOOLEAN
  6666. SiS_GetLVDSCRT1Ptr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  6667. unsigned short RefreshRateTableIndex, unsigned short *ResIndex,
  6668. unsigned short *DisplayType)
  6669. {
  6670. unsigned short modeflag = 0;
  6671. BOOLEAN checkhd = TRUE;
  6672. /* Pass 1:1 not supported here */
  6673. if(ModeNo <= 0x13) {
  6674. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  6675. (*ResIndex) = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  6676. } else {
  6677. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  6678. (*ResIndex) = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  6679. }
  6680. (*ResIndex) &= 0x3F;
  6681. if((SiS_Pr->SiS_IF_DEF_CH70xx) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
  6682. (*DisplayType) = 80;
  6683. if((SiS_Pr->SiS_TVMode & TVSetPAL) && (!(SiS_Pr->SiS_TVMode & TVSetPALM))) {
  6684. (*DisplayType) = 82;
  6685. if(SiS_Pr->SiS_ModeType > ModeVGA) {
  6686. if(SiS_Pr->SiS_CHSOverScan) (*DisplayType) = 84;
  6687. }
  6688. }
  6689. if((*DisplayType) != 84) {
  6690. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) (*DisplayType)++;
  6691. }
  6692. } else {
  6693. (*DisplayType = 0);
  6694. switch(SiS_Pr->SiS_LCDResInfo) {
  6695. case Panel_320x240_1: (*DisplayType) = 50;
  6696. checkhd = FALSE;
  6697. break;
  6698. case Panel_320x240_2: (*DisplayType) = 14;
  6699. break;
  6700. case Panel_320x240_3: (*DisplayType) = 18;
  6701. break;
  6702. case Panel_640x480: (*DisplayType) = 10;
  6703. break;
  6704. case Panel_1024x600: (*DisplayType) = 26;
  6705. break;
  6706. default: return TRUE;
  6707. }
  6708. if(checkhd) {
  6709. if(modeflag & HalfDCLK) (*DisplayType)++;
  6710. }
  6711. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x600) {
  6712. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) (*DisplayType) += 2;
  6713. }
  6714. }
  6715. return TRUE;
  6716. }
  6717. static void
  6718. SiS_ModCRT1CRTC(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  6719. unsigned short RefreshRateTableIndex)
  6720. {
  6721. unsigned short tempah, i, modeflag, j, ResIndex, DisplayType;
  6722. const struct SiS_LVDSCRT1Data *LVDSCRT1Ptr=NULL;
  6723. static const unsigned short CRIdx[] = {
  6724. 0x00, 0x02, 0x03, 0x04, 0x05, 0x06,
  6725. 0x07, 0x10, 0x11, 0x15, 0x16
  6726. };
  6727. if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) ||
  6728. (SiS_Pr->SiS_CustomT == CUT_BARCO1024) ||
  6729. (SiS_Pr->SiS_CustomT == CUT_PANEL848) ||
  6730. (SiS_Pr->SiS_CustomT == CUT_PANEL856) )
  6731. return;
  6732. if(SiS_Pr->SiS_IF_DEF_LVDS) {
  6733. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  6734. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) return;
  6735. }
  6736. } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
  6737. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) return;
  6738. } else return;
  6739. if(SiS_Pr->SiS_LCDInfo & LCDPass11) return;
  6740. if(SiS_Pr->ChipType < SIS_315H) {
  6741. if(SiS_Pr->SiS_SetFlag & SetDOSMode) return;
  6742. }
  6743. if(!(SiS_GetLVDSCRT1Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex,
  6744. &ResIndex, &DisplayType))) {
  6745. return;
  6746. }
  6747. switch(DisplayType) {
  6748. case 50: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1320x240_1; break; /* xSTN */
  6749. case 14: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1320x240_2; break; /* xSTN */
  6750. case 15: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1320x240_2_H; break; /* xSTN */
  6751. case 18: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1320x240_3; break; /* xSTN */
  6752. case 19: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1320x240_3_H; break; /* xSTN */
  6753. case 10: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1640x480_1; break;
  6754. case 11: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1640x480_1_H; break;
  6755. #if 0 /* Works better with calculated numbers */
  6756. case 26: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x600_1; break;
  6757. case 27: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x600_1_H; break;
  6758. case 28: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x600_2; break;
  6759. case 29: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x600_2_H; break;
  6760. #endif
  6761. case 80: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1UNTSC; break;
  6762. case 81: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1ONTSC; break;
  6763. case 82: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1UPAL; break;
  6764. case 83: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1OPAL; break;
  6765. case 84: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1SOPAL; break;
  6766. }
  6767. if(LVDSCRT1Ptr) {
  6768. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x11,0x7f);
  6769. for(i = 0; i <= 10; i++) {
  6770. tempah = (LVDSCRT1Ptr + ResIndex)->CR[i];
  6771. SiS_SetReg(SiS_Pr->SiS_P3d4,CRIdx[i],tempah);
  6772. }
  6773. for(i = 0x0A, j = 11; i <= 0x0C; i++, j++) {
  6774. tempah = (LVDSCRT1Ptr + ResIndex)->CR[j];
  6775. SiS_SetReg(SiS_Pr->SiS_P3c4,i,tempah);
  6776. }
  6777. tempah = (LVDSCRT1Ptr + ResIndex)->CR[14] & 0xE0;
  6778. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0E,0x1f,tempah);
  6779. if(ModeNo <= 0x13) modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  6780. else modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  6781. tempah = ((LVDSCRT1Ptr + ResIndex)->CR[14] & 0x01) << 5;
  6782. if(modeflag & DoubleScanMode) tempah |= 0x80;
  6783. SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x09,~0x020,tempah);
  6784. } else {
  6785. SiS_CalcLCDACRT1Timing(SiS_Pr, ModeNo, ModeIdIndex);
  6786. }
  6787. }
  6788. /*********************************************/
  6789. /* SET CRT2 ECLK */
  6790. /*********************************************/
  6791. static void
  6792. SiS_SetCRT2ECLK(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  6793. unsigned short RefreshRateTableIndex)
  6794. {
  6795. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  6796. unsigned short clkbase, vclkindex = 0;
  6797. unsigned char sr2b, sr2c;
  6798. if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
  6799. SiS_Pr->SiS_SetFlag &= (~ProgrammingCRT2);
  6800. if(SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK == 2) {
  6801. RefreshRateTableIndex--;
  6802. }
  6803. vclkindex = SiS_GetVCLK2Ptr(SiS_Pr, ModeNo, ModeIdIndex,
  6804. RefreshRateTableIndex);
  6805. SiS_Pr->SiS_SetFlag |= ProgrammingCRT2;
  6806. } else {
  6807. vclkindex = SiS_GetVCLK2Ptr(SiS_Pr, ModeNo, ModeIdIndex,
  6808. RefreshRateTableIndex);
  6809. }
  6810. sr2b = SiS_Pr->SiS_VCLKData[vclkindex].SR2B;
  6811. sr2c = SiS_Pr->SiS_VCLKData[vclkindex].SR2C;
  6812. if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) || (SiS_Pr->SiS_CustomT == CUT_BARCO1024)) {
  6813. if(SiS_Pr->SiS_UseROM) {
  6814. if(ROMAddr[0x220] & 0x01) {
  6815. sr2b = ROMAddr[0x227];
  6816. sr2c = ROMAddr[0x228];
  6817. }
  6818. }
  6819. }
  6820. clkbase = 0x02B;
  6821. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  6822. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  6823. clkbase += 3;
  6824. }
  6825. }
  6826. SiS_SetReg(SiS_Pr->SiS_P3c4,0x31,0x20);
  6827. SiS_SetReg(SiS_Pr->SiS_P3c4,clkbase,sr2b);
  6828. SiS_SetReg(SiS_Pr->SiS_P3c4,clkbase+1,sr2c);
  6829. SiS_SetReg(SiS_Pr->SiS_P3c4,0x31,0x10);
  6830. SiS_SetReg(SiS_Pr->SiS_P3c4,clkbase,sr2b);
  6831. SiS_SetReg(SiS_Pr->SiS_P3c4,clkbase+1,sr2c);
  6832. SiS_SetReg(SiS_Pr->SiS_P3c4,0x31,0x00);
  6833. SiS_SetReg(SiS_Pr->SiS_P3c4,clkbase,sr2b);
  6834. SiS_SetReg(SiS_Pr->SiS_P3c4,clkbase+1,sr2c);
  6835. }
  6836. /*********************************************/
  6837. /* SET UP CHRONTEL CHIPS */
  6838. /*********************************************/
  6839. static void
  6840. SiS_SetCHTVReg(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  6841. unsigned short RefreshRateTableIndex)
  6842. {
  6843. unsigned short TVType, resindex;
  6844. const struct SiS_CHTVRegData *CHTVRegData = NULL;
  6845. if(ModeNo <= 0x13)
  6846. resindex = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  6847. else
  6848. resindex = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  6849. resindex &= 0x3F;
  6850. TVType = 0;
  6851. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) TVType += 1;
  6852. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  6853. TVType += 2;
  6854. if(SiS_Pr->SiS_ModeType > ModeVGA) {
  6855. if(SiS_Pr->SiS_CHSOverScan) TVType = 8;
  6856. }
  6857. if(SiS_Pr->SiS_TVMode & TVSetPALM) {
  6858. TVType = 4;
  6859. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) TVType += 1;
  6860. } else if(SiS_Pr->SiS_TVMode & TVSetPALN) {
  6861. TVType = 6;
  6862. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) TVType += 1;
  6863. }
  6864. }
  6865. switch(TVType) {
  6866. case 0: CHTVRegData = SiS_Pr->SiS_CHTVReg_UNTSC; break;
  6867. case 1: CHTVRegData = SiS_Pr->SiS_CHTVReg_ONTSC; break;
  6868. case 2: CHTVRegData = SiS_Pr->SiS_CHTVReg_UPAL; break;
  6869. case 3: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPAL; break;
  6870. case 4: CHTVRegData = SiS_Pr->SiS_CHTVReg_UPALM; break;
  6871. case 5: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPALM; break;
  6872. case 6: CHTVRegData = SiS_Pr->SiS_CHTVReg_UPALN; break;
  6873. case 7: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPALN; break;
  6874. case 8: CHTVRegData = SiS_Pr->SiS_CHTVReg_SOPAL; break;
  6875. default: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPAL; break;
  6876. }
  6877. if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) {
  6878. #ifdef SIS300
  6879. /* Chrontel 7005 - I assume that it does not come with a 315 series chip */
  6880. /* We don't support modes >800x600 */
  6881. if (resindex > 5) return;
  6882. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  6883. SiS_SetCH700x(SiS_Pr,0x04,0x43); /* 0x40=76uA (PAL); 0x03=15bit non-multi RGB*/
  6884. SiS_SetCH700x(SiS_Pr,0x09,0x69); /* Black level for PAL (105)*/
  6885. } else {
  6886. SiS_SetCH700x(SiS_Pr,0x04,0x03); /* upper nibble=71uA (NTSC), 0x03=15bit non-multi RGB*/
  6887. SiS_SetCH700x(SiS_Pr,0x09,0x71); /* Black level for NTSC (113)*/
  6888. }
  6889. SiS_SetCH700x(SiS_Pr,0x00,CHTVRegData[resindex].Reg[0]); /* Mode register */
  6890. SiS_SetCH700x(SiS_Pr,0x07,CHTVRegData[resindex].Reg[1]); /* Start active video register */
  6891. SiS_SetCH700x(SiS_Pr,0x08,CHTVRegData[resindex].Reg[2]); /* Position overflow register */
  6892. SiS_SetCH700x(SiS_Pr,0x0a,CHTVRegData[resindex].Reg[3]); /* Horiz Position register */
  6893. SiS_SetCH700x(SiS_Pr,0x0b,CHTVRegData[resindex].Reg[4]); /* Vertical Position register */
  6894. /* Set minimum flicker filter for Luma channel (SR1-0=00),
  6895. minimum text enhancement (S3-2=10),
  6896. maximum flicker filter for Chroma channel (S5-4=10)
  6897. =00101000=0x28 (When reading, S1-0->S3-2, and S3-2->S1-0!)
  6898. */
  6899. SiS_SetCH700x(SiS_Pr,0x01,0x28);
  6900. /* Set video bandwidth
  6901. High bandwidth Luma composite video filter(S0=1)
  6902. low bandwidth Luma S-video filter (S2-1=00)
  6903. disable peak filter in S-video channel (S3=0)
  6904. high bandwidth Chroma Filter (S5-4=11)
  6905. =00110001=0x31
  6906. */
  6907. SiS_SetCH700x(SiS_Pr,0x03,0xb1); /* old: 3103 */
  6908. /* Register 0x3D does not exist in non-macrovision register map
  6909. (Maybe this is a macrovision register?)
  6910. */
  6911. #ifndef SIS_CP
  6912. SiS_SetCH70xx(SiS_Pr,0x3d,0x00);
  6913. #endif
  6914. /* Register 0x10 only contains 1 writable bit (S0) for sensing,
  6915. all other bits a read-only. Macrovision?
  6916. */
  6917. SiS_SetCH70xxANDOR(SiS_Pr,0x10,0x00,0x1F);
  6918. /* Register 0x11 only contains 3 writable bits (S0-S2) for
  6919. contrast enhancement (set to 010 -> gain 1 Yout = 17/16*(Yin-30) )
  6920. */
  6921. SiS_SetCH70xxANDOR(SiS_Pr,0x11,0x02,0xF8);
  6922. /* Clear DSEN
  6923. */
  6924. SiS_SetCH70xxANDOR(SiS_Pr,0x1c,0x00,0xEF);
  6925. if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) { /* ---- NTSC ---- */
  6926. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) {
  6927. if(resindex == 0x04) { /* 640x480 overscan: Mode 16 */
  6928. SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x00,0xEF); /* loop filter off */
  6929. SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x01,0xFE); /* ACIV on, no need to set FSCI */
  6930. } else if(resindex == 0x05) { /* 800x600 overscan: Mode 23 */
  6931. SiS_SetCH70xxANDOR(SiS_Pr,0x18,0x01,0xF0); /* 0x18-0x1f: FSCI 469,762,048 */
  6932. SiS_SetCH70xxANDOR(SiS_Pr,0x19,0x0C,0xF0);
  6933. SiS_SetCH70xxANDOR(SiS_Pr,0x1a,0x00,0xF0);
  6934. SiS_SetCH70xxANDOR(SiS_Pr,0x1b,0x00,0xF0);
  6935. SiS_SetCH70xxANDOR(SiS_Pr,0x1c,0x00,0xF0);
  6936. SiS_SetCH70xxANDOR(SiS_Pr,0x1d,0x00,0xF0);
  6937. SiS_SetCH70xxANDOR(SiS_Pr,0x1e,0x00,0xF0);
  6938. SiS_SetCH70xxANDOR(SiS_Pr,0x1f,0x00,0xF0);
  6939. SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x01,0xEF); /* Loop filter on for mode 23 */
  6940. SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x00,0xFE); /* ACIV off, need to set FSCI */
  6941. }
  6942. } else {
  6943. if(resindex == 0x04) { /* ----- 640x480 underscan; Mode 17 */
  6944. SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x00,0xEF); /* loop filter off */
  6945. SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x01,0xFE);
  6946. } else if(resindex == 0x05) { /* ----- 800x600 underscan: Mode 24 */
  6947. #if 0
  6948. SiS_SetCH70xxANDOR(SiS_Pr,0x18,0x01,0xF0); /* (FSCI was 0x1f1c71c7 - this is for mode 22) */
  6949. SiS_SetCH70xxANDOR(SiS_Pr,0x19,0x09,0xF0); /* FSCI for mode 24 is 428,554,851 */
  6950. SiS_SetCH70xxANDOR(SiS_Pr,0x1a,0x08,0xF0); /* 198b3a63 */
  6951. SiS_SetCH70xxANDOR(SiS_Pr,0x1b,0x0b,0xF0);
  6952. SiS_SetCH70xxANDOR(SiS_Pr,0x1c,0x04,0xF0);
  6953. SiS_SetCH70xxANDOR(SiS_Pr,0x1d,0x01,0xF0);
  6954. SiS_SetCH70xxANDOR(SiS_Pr,0x1e,0x06,0xF0);
  6955. SiS_SetCH70xxANDOR(SiS_Pr,0x1f,0x05,0xF0);
  6956. SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x00,0xEF); /* loop filter off for mode 24 */
  6957. SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x00,0xFE); * ACIV off, need to set FSCI */
  6958. #endif /* All alternatives wrong (datasheet wrong?), don't use FSCI */
  6959. SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x00,0xEF); /* loop filter off */
  6960. SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x01,0xFE);
  6961. }
  6962. }
  6963. } else { /* ---- PAL ---- */
  6964. /* We don't play around with FSCI in PAL mode */
  6965. if(resindex == 0x04) {
  6966. SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x00,0xEF); /* loop filter off */
  6967. SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x01,0xFE); /* ACIV on */
  6968. } else {
  6969. SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x00,0xEF); /* loop filter off */
  6970. SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x01,0xFE); /* ACIV on */
  6971. }
  6972. }
  6973. #endif /* 300 */
  6974. } else {
  6975. /* Chrontel 7019 - assumed that it does not come with a 300 series chip */
  6976. #ifdef SIS315H
  6977. unsigned short temp;
  6978. /* We don't support modes >1024x768 */
  6979. if (resindex > 6) return;
  6980. temp = CHTVRegData[resindex].Reg[0];
  6981. if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) temp |= 0x10;
  6982. SiS_SetCH701x(SiS_Pr,0x00,temp);
  6983. SiS_SetCH701x(SiS_Pr,0x01,CHTVRegData[resindex].Reg[1]);
  6984. SiS_SetCH701x(SiS_Pr,0x02,CHTVRegData[resindex].Reg[2]);
  6985. SiS_SetCH701x(SiS_Pr,0x04,CHTVRegData[resindex].Reg[3]);
  6986. SiS_SetCH701x(SiS_Pr,0x03,CHTVRegData[resindex].Reg[4]);
  6987. SiS_SetCH701x(SiS_Pr,0x05,CHTVRegData[resindex].Reg[5]);
  6988. SiS_SetCH701x(SiS_Pr,0x06,CHTVRegData[resindex].Reg[6]);
  6989. temp = CHTVRegData[resindex].Reg[7];
  6990. if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) temp = 0x66;
  6991. SiS_SetCH701x(SiS_Pr,0x07,temp);
  6992. SiS_SetCH701x(SiS_Pr,0x08,CHTVRegData[resindex].Reg[8]);
  6993. SiS_SetCH701x(SiS_Pr,0x15,CHTVRegData[resindex].Reg[9]);
  6994. SiS_SetCH701x(SiS_Pr,0x1f,CHTVRegData[resindex].Reg[10]);
  6995. SiS_SetCH701x(SiS_Pr,0x0c,CHTVRegData[resindex].Reg[11]);
  6996. SiS_SetCH701x(SiS_Pr,0x0d,CHTVRegData[resindex].Reg[12]);
  6997. SiS_SetCH701x(SiS_Pr,0x0e,CHTVRegData[resindex].Reg[13]);
  6998. SiS_SetCH701x(SiS_Pr,0x0f,CHTVRegData[resindex].Reg[14]);
  6999. SiS_SetCH701x(SiS_Pr,0x10,CHTVRegData[resindex].Reg[15]);
  7000. temp = SiS_GetCH701x(SiS_Pr,0x21) & ~0x02;
  7001. /* D1 should be set for PAL, PAL-N and NTSC-J,
  7002. but I won't do that for PAL unless somebody
  7003. tells me to do so. Since the BIOS uses
  7004. non-default CIV values and blacklevels,
  7005. this might be compensated anyway.
  7006. */
  7007. if(SiS_Pr->SiS_TVMode & (TVSetPALN | TVSetNTSCJ)) temp |= 0x02;
  7008. SiS_SetCH701x(SiS_Pr,0x21,temp);
  7009. #endif /* 315 */
  7010. }
  7011. #ifdef SIS_CP
  7012. SIS_CP_INIT301_CP3
  7013. #endif
  7014. }
  7015. #ifdef SIS315H /* ----------- 315 series only ---------- */
  7016. void
  7017. SiS_Chrontel701xBLOn(struct SiS_Private *SiS_Pr)
  7018. {
  7019. unsigned short temp;
  7020. /* Enable Chrontel 7019 LCD panel backlight */
  7021. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  7022. if(SiS_Pr->ChipType == SIS_740) {
  7023. SiS_SetCH701x(SiS_Pr,0x66,0x65);
  7024. } else {
  7025. temp = SiS_GetCH701x(SiS_Pr,0x66);
  7026. temp |= 0x20;
  7027. SiS_SetCH701x(SiS_Pr,0x66,temp);
  7028. }
  7029. }
  7030. }
  7031. void
  7032. SiS_Chrontel701xBLOff(struct SiS_Private *SiS_Pr)
  7033. {
  7034. unsigned short temp;
  7035. /* Disable Chrontel 7019 LCD panel backlight */
  7036. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  7037. temp = SiS_GetCH701x(SiS_Pr,0x66);
  7038. temp &= 0xDF;
  7039. SiS_SetCH701x(SiS_Pr,0x66,temp);
  7040. }
  7041. }
  7042. static void
  7043. SiS_ChrontelPowerSequencing(struct SiS_Private *SiS_Pr)
  7044. {
  7045. static const unsigned char regtable[] = { 0x67, 0x68, 0x69, 0x6a, 0x6b };
  7046. static const unsigned char table1024_740[] = { 0x01, 0x02, 0x01, 0x01, 0x01 };
  7047. static const unsigned char table1400_740[] = { 0x01, 0x6e, 0x01, 0x01, 0x01 };
  7048. static const unsigned char asus1024_740[] = { 0x19, 0x6e, 0x01, 0x19, 0x09 };
  7049. static const unsigned char asus1400_740[] = { 0x19, 0x6e, 0x01, 0x19, 0x09 };
  7050. static const unsigned char table1024_650[] = { 0x01, 0x02, 0x01, 0x01, 0x02 };
  7051. static const unsigned char table1400_650[] = { 0x01, 0x02, 0x01, 0x01, 0x02 };
  7052. const unsigned char *tableptr = NULL;
  7053. int i;
  7054. /* Set up Power up/down timing */
  7055. if(SiS_Pr->ChipType == SIS_740) {
  7056. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  7057. if(SiS_Pr->SiS_CustomT == CUT_ASUSL3000D) tableptr = asus1024_740;
  7058. else tableptr = table1024_740;
  7059. } else if((SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) ||
  7060. (SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) ||
  7061. (SiS_Pr->SiS_LCDResInfo == Panel_1600x1200)) {
  7062. if(SiS_Pr->SiS_CustomT == CUT_ASUSL3000D) tableptr = asus1400_740;
  7063. else tableptr = table1400_740;
  7064. } else return;
  7065. } else {
  7066. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  7067. tableptr = table1024_650;
  7068. } else if((SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) ||
  7069. (SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) ||
  7070. (SiS_Pr->SiS_LCDResInfo == Panel_1600x1200)) {
  7071. tableptr = table1400_650;
  7072. } else return;
  7073. }
  7074. for(i=0; i<5; i++) {
  7075. SiS_SetCH701x(SiS_Pr, regtable[i], tableptr[i]);
  7076. }
  7077. }
  7078. static void
  7079. SiS_SetCH701xForLCD(struct SiS_Private *SiS_Pr)
  7080. {
  7081. const unsigned char *tableptr = NULL;
  7082. unsigned short tempbh;
  7083. int i;
  7084. static const unsigned char regtable[] = {
  7085. 0x1c, 0x5f, 0x64, 0x6f, 0x70, 0x71,
  7086. 0x72, 0x73, 0x74, 0x76, 0x78, 0x7d, 0x66
  7087. };
  7088. static const unsigned char table1024_740[] = {
  7089. 0x60, 0x02, 0x00, 0x07, 0x40, 0xed,
  7090. 0xa3, 0xc8, 0xc7, 0xac, 0xe0, 0x02, 0x44
  7091. };
  7092. static const unsigned char table1280_740[] = {
  7093. 0x60, 0x03, 0x11, 0x00, 0x40, 0xe3,
  7094. 0xad, 0xdb, 0xf6, 0xac, 0xe0, 0x02, 0x44
  7095. };
  7096. static const unsigned char table1400_740[] = {
  7097. 0x60, 0x03, 0x11, 0x00, 0x40, 0xe3,
  7098. 0xad, 0xdb, 0xf6, 0xac, 0xe0, 0x02, 0x44
  7099. };
  7100. static const unsigned char table1600_740[] = {
  7101. 0x60, 0x04, 0x11, 0x00, 0x40, 0xe3,
  7102. 0xad, 0xde, 0xf6, 0xac, 0x60, 0x1a, 0x44
  7103. };
  7104. static const unsigned char table1024_650[] = {
  7105. 0x60, 0x02, 0x00, 0x07, 0x40, 0xed,
  7106. 0xa3, 0xc8, 0xc7, 0xac, 0x60, 0x02
  7107. };
  7108. static const unsigned char table1280_650[] = {
  7109. 0x60, 0x03, 0x11, 0x00, 0x40, 0xe3,
  7110. 0xad, 0xdb, 0xf6, 0xac, 0xe0, 0x02
  7111. };
  7112. static const unsigned char table1400_650[] = {
  7113. 0x60, 0x03, 0x11, 0x00, 0x40, 0xef,
  7114. 0xad, 0xdb, 0xf6, 0xac, 0x60, 0x02
  7115. };
  7116. static const unsigned char table1600_650[] = {
  7117. 0x60, 0x04, 0x11, 0x00, 0x40, 0xe3,
  7118. 0xad, 0xde, 0xf6, 0xac, 0x60, 0x1a
  7119. };
  7120. if(SiS_Pr->ChipType == SIS_740) {
  7121. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) tableptr = table1024_740;
  7122. else if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) tableptr = table1280_740;
  7123. else if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) tableptr = table1400_740;
  7124. else if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) tableptr = table1600_740;
  7125. else return;
  7126. } else {
  7127. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) tableptr = table1024_650;
  7128. else if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) tableptr = table1280_650;
  7129. else if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) tableptr = table1400_650;
  7130. else if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) tableptr = table1600_650;
  7131. else return;
  7132. }
  7133. tempbh = SiS_GetCH701x(SiS_Pr,0x74);
  7134. if((tempbh == 0xf6) || (tempbh == 0xc7)) {
  7135. tempbh = SiS_GetCH701x(SiS_Pr,0x73);
  7136. if(tempbh == 0xc8) {
  7137. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) return;
  7138. } else if(tempbh == 0xdb) {
  7139. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) return;
  7140. if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) return;
  7141. } else if(tempbh == 0xde) {
  7142. if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) return;
  7143. }
  7144. }
  7145. if(SiS_Pr->ChipType == SIS_740) tempbh = 0x0d;
  7146. else tempbh = 0x0c;
  7147. for(i = 0; i < tempbh; i++) {
  7148. SiS_SetCH701x(SiS_Pr, regtable[i], tableptr[i]);
  7149. }
  7150. SiS_ChrontelPowerSequencing(SiS_Pr);
  7151. tempbh = SiS_GetCH701x(SiS_Pr,0x1e);
  7152. tempbh |= 0xc0;
  7153. SiS_SetCH701x(SiS_Pr,0x1e,tempbh);
  7154. if(SiS_Pr->ChipType == SIS_740) {
  7155. tempbh = SiS_GetCH701x(SiS_Pr,0x1c);
  7156. tempbh &= 0xfb;
  7157. SiS_SetCH701x(SiS_Pr,0x1c,tempbh);
  7158. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2d,0x03);
  7159. tempbh = SiS_GetCH701x(SiS_Pr,0x64);
  7160. tempbh |= 0x40;
  7161. SiS_SetCH701x(SiS_Pr,0x64,tempbh);
  7162. tempbh = SiS_GetCH701x(SiS_Pr,0x03);
  7163. tempbh &= 0x3f;
  7164. SiS_SetCH701x(SiS_Pr,0x03,tempbh);
  7165. }
  7166. }
  7167. static void
  7168. SiS_ChrontelResetVSync(struct SiS_Private *SiS_Pr)
  7169. {
  7170. unsigned char temp, temp1;
  7171. temp1 = SiS_GetCH701x(SiS_Pr,0x49);
  7172. SiS_SetCH701x(SiS_Pr,0x49,0x3e);
  7173. temp = SiS_GetCH701x(SiS_Pr,0x47);
  7174. temp &= 0x7f; /* Use external VSYNC */
  7175. SiS_SetCH701x(SiS_Pr,0x47,temp);
  7176. SiS_LongDelay(SiS_Pr, 3);
  7177. temp = SiS_GetCH701x(SiS_Pr,0x47);
  7178. temp |= 0x80; /* Use internal VSYNC */
  7179. SiS_SetCH701x(SiS_Pr,0x47,temp);
  7180. SiS_SetCH701x(SiS_Pr,0x49,temp1);
  7181. }
  7182. static void
  7183. SiS_Chrontel701xOn(struct SiS_Private *SiS_Pr)
  7184. {
  7185. unsigned short temp;
  7186. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  7187. if(SiS_Pr->ChipType == SIS_740) {
  7188. temp = SiS_GetCH701x(SiS_Pr,0x1c);
  7189. temp |= 0x04; /* Invert XCLK phase */
  7190. SiS_SetCH701x(SiS_Pr,0x1c,temp);
  7191. }
  7192. if(SiS_IsYPbPr(SiS_Pr)) {
  7193. temp = SiS_GetCH701x(SiS_Pr,0x01);
  7194. temp &= 0x3f;
  7195. temp |= 0x80; /* Enable YPrPb (HDTV) */
  7196. SiS_SetCH701x(SiS_Pr,0x01,temp);
  7197. }
  7198. if(SiS_IsChScart(SiS_Pr)) {
  7199. temp = SiS_GetCH701x(SiS_Pr,0x01);
  7200. temp &= 0x3f;
  7201. temp |= 0xc0; /* Enable SCART + CVBS */
  7202. SiS_SetCH701x(SiS_Pr,0x01,temp);
  7203. }
  7204. if(SiS_Pr->ChipType == SIS_740) {
  7205. SiS_ChrontelResetVSync(SiS_Pr);
  7206. SiS_SetCH701x(SiS_Pr,0x49,0x20); /* Enable TV path */
  7207. } else {
  7208. SiS_SetCH701x(SiS_Pr,0x49,0x20); /* Enable TV path */
  7209. temp = SiS_GetCH701x(SiS_Pr,0x49);
  7210. if(SiS_IsYPbPr(SiS_Pr)) {
  7211. temp = SiS_GetCH701x(SiS_Pr,0x73);
  7212. temp |= 0x60;
  7213. SiS_SetCH701x(SiS_Pr,0x73,temp);
  7214. }
  7215. temp = SiS_GetCH701x(SiS_Pr,0x47);
  7216. temp &= 0x7f;
  7217. SiS_SetCH701x(SiS_Pr,0x47,temp);
  7218. SiS_LongDelay(SiS_Pr, 2);
  7219. temp = SiS_GetCH701x(SiS_Pr,0x47);
  7220. temp |= 0x80;
  7221. SiS_SetCH701x(SiS_Pr,0x47,temp);
  7222. }
  7223. }
  7224. }
  7225. static void
  7226. SiS_Chrontel701xOff(struct SiS_Private *SiS_Pr)
  7227. {
  7228. unsigned short temp;
  7229. /* Complete power down of LVDS */
  7230. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  7231. if(SiS_Pr->ChipType == SIS_740) {
  7232. SiS_LongDelay(SiS_Pr, 1);
  7233. SiS_GenericDelay(SiS_Pr, 5887);
  7234. SiS_SetCH701x(SiS_Pr,0x76,0xac);
  7235. SiS_SetCH701x(SiS_Pr,0x66,0x00);
  7236. } else {
  7237. SiS_LongDelay(SiS_Pr, 2);
  7238. temp = SiS_GetCH701x(SiS_Pr,0x76);
  7239. temp &= 0xfc;
  7240. SiS_SetCH701x(SiS_Pr,0x76,temp);
  7241. SiS_SetCH701x(SiS_Pr,0x66,0x00);
  7242. }
  7243. }
  7244. }
  7245. static void
  7246. SiS_ChrontelResetDB(struct SiS_Private *SiS_Pr)
  7247. {
  7248. unsigned short temp;
  7249. if(SiS_Pr->ChipType == SIS_740) {
  7250. temp = SiS_GetCH701x(SiS_Pr,0x4a); /* Version ID */
  7251. temp &= 0x01;
  7252. if(!temp) {
  7253. if(SiS_WeHaveBacklightCtrl(SiS_Pr)) {
  7254. temp = SiS_GetCH701x(SiS_Pr,0x49);
  7255. SiS_SetCH701x(SiS_Pr,0x49,0x3e);
  7256. }
  7257. /* Reset Chrontel 7019 datapath */
  7258. SiS_SetCH701x(SiS_Pr,0x48,0x10);
  7259. SiS_LongDelay(SiS_Pr, 1);
  7260. SiS_SetCH701x(SiS_Pr,0x48,0x18);
  7261. if(SiS_WeHaveBacklightCtrl(SiS_Pr)) {
  7262. SiS_ChrontelResetVSync(SiS_Pr);
  7263. SiS_SetCH701x(SiS_Pr,0x49,temp);
  7264. }
  7265. } else {
  7266. /* Clear/set/clear GPIO */
  7267. temp = SiS_GetCH701x(SiS_Pr,0x5c);
  7268. temp &= 0xef;
  7269. SiS_SetCH701x(SiS_Pr,0x5c,temp);
  7270. temp = SiS_GetCH701x(SiS_Pr,0x5c);
  7271. temp |= 0x10;
  7272. SiS_SetCH701x(SiS_Pr,0x5c,temp);
  7273. temp = SiS_GetCH701x(SiS_Pr,0x5c);
  7274. temp &= 0xef;
  7275. SiS_SetCH701x(SiS_Pr,0x5c,temp);
  7276. temp = SiS_GetCH701x(SiS_Pr,0x61);
  7277. if(!temp) {
  7278. SiS_SetCH701xForLCD(SiS_Pr);
  7279. }
  7280. }
  7281. } else { /* 650 */
  7282. /* Reset Chrontel 7019 datapath */
  7283. SiS_SetCH701x(SiS_Pr,0x48,0x10);
  7284. SiS_LongDelay(SiS_Pr, 1);
  7285. SiS_SetCH701x(SiS_Pr,0x48,0x18);
  7286. }
  7287. }
  7288. static void
  7289. SiS_ChrontelInitTVVSync(struct SiS_Private *SiS_Pr)
  7290. {
  7291. unsigned short temp;
  7292. if(SiS_Pr->ChipType == SIS_740) {
  7293. if(SiS_WeHaveBacklightCtrl(SiS_Pr)) {
  7294. SiS_ChrontelResetVSync(SiS_Pr);
  7295. }
  7296. } else {
  7297. SiS_SetCH701x(SiS_Pr,0x76,0xaf); /* Power up LVDS block */
  7298. temp = SiS_GetCH701x(SiS_Pr,0x49);
  7299. temp &= 1;
  7300. if(temp != 1) { /* TV block powered? (0 = yes, 1 = no) */
  7301. temp = SiS_GetCH701x(SiS_Pr,0x47);
  7302. temp &= 0x70;
  7303. SiS_SetCH701x(SiS_Pr,0x47,temp); /* enable VSYNC */
  7304. SiS_LongDelay(SiS_Pr, 3);
  7305. temp = SiS_GetCH701x(SiS_Pr,0x47);
  7306. temp |= 0x80;
  7307. SiS_SetCH701x(SiS_Pr,0x47,temp); /* disable VSYNC */
  7308. }
  7309. }
  7310. }
  7311. static void
  7312. SiS_ChrontelDoSomething3(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
  7313. {
  7314. unsigned short temp,temp1;
  7315. if(SiS_Pr->ChipType == SIS_740) {
  7316. temp = SiS_GetCH701x(SiS_Pr,0x61);
  7317. if(temp < 1) {
  7318. temp++;
  7319. SiS_SetCH701x(SiS_Pr,0x61,temp);
  7320. }
  7321. SiS_SetCH701x(SiS_Pr,0x66,0x45); /* Panel power on */
  7322. SiS_SetCH701x(SiS_Pr,0x76,0xaf); /* All power on */
  7323. SiS_LongDelay(SiS_Pr, 1);
  7324. SiS_GenericDelay(SiS_Pr, 5887);
  7325. } else { /* 650 */
  7326. temp1 = 0;
  7327. temp = SiS_GetCH701x(SiS_Pr,0x61);
  7328. if(temp < 2) {
  7329. temp++;
  7330. SiS_SetCH701x(SiS_Pr,0x61,temp);
  7331. temp1 = 1;
  7332. }
  7333. SiS_SetCH701x(SiS_Pr,0x76,0xac);
  7334. temp = SiS_GetCH701x(SiS_Pr,0x66);
  7335. temp |= 0x5f;
  7336. SiS_SetCH701x(SiS_Pr,0x66,temp);
  7337. if(ModeNo > 0x13) {
  7338. if(SiS_WeHaveBacklightCtrl(SiS_Pr)) {
  7339. SiS_GenericDelay(SiS_Pr, 1023);
  7340. } else {
  7341. SiS_GenericDelay(SiS_Pr, 767);
  7342. }
  7343. } else {
  7344. if(!temp1)
  7345. SiS_GenericDelay(SiS_Pr, 767);
  7346. }
  7347. temp = SiS_GetCH701x(SiS_Pr,0x76);
  7348. temp |= 0x03;
  7349. SiS_SetCH701x(SiS_Pr,0x76,temp);
  7350. temp = SiS_GetCH701x(SiS_Pr,0x66);
  7351. temp &= 0x7f;
  7352. SiS_SetCH701x(SiS_Pr,0x66,temp);
  7353. SiS_LongDelay(SiS_Pr, 1);
  7354. }
  7355. }
  7356. static void
  7357. SiS_ChrontelDoSomething2(struct SiS_Private *SiS_Pr)
  7358. {
  7359. unsigned short temp;
  7360. SiS_LongDelay(SiS_Pr, 1);
  7361. do {
  7362. temp = SiS_GetCH701x(SiS_Pr,0x66);
  7363. temp &= 0x04; /* PLL stable? -> bail out */
  7364. if(temp == 0x04) break;
  7365. if(SiS_Pr->ChipType == SIS_740) {
  7366. /* Power down LVDS output, PLL normal operation */
  7367. SiS_SetCH701x(SiS_Pr,0x76,0xac);
  7368. }
  7369. SiS_SetCH701xForLCD(SiS_Pr);
  7370. temp = SiS_GetCH701x(SiS_Pr,0x76);
  7371. temp &= 0xfb; /* Reset PLL */
  7372. SiS_SetCH701x(SiS_Pr,0x76,temp);
  7373. SiS_LongDelay(SiS_Pr, 2);
  7374. temp = SiS_GetCH701x(SiS_Pr,0x76);
  7375. temp |= 0x04; /* PLL normal operation */
  7376. SiS_SetCH701x(SiS_Pr,0x76,temp);
  7377. if(SiS_Pr->ChipType == SIS_740) {
  7378. SiS_SetCH701x(SiS_Pr,0x78,0xe0); /* PLL loop filter */
  7379. } else {
  7380. SiS_SetCH701x(SiS_Pr,0x78,0x60);
  7381. }
  7382. SiS_LongDelay(SiS_Pr, 2);
  7383. } while(0);
  7384. SiS_SetCH701x(SiS_Pr,0x77,0x00); /* MV? */
  7385. }
  7386. static void
  7387. SiS_ChrontelDoSomething1(struct SiS_Private *SiS_Pr)
  7388. {
  7389. unsigned short temp;
  7390. temp = SiS_GetCH701x(SiS_Pr,0x03);
  7391. temp |= 0x80; /* Set datapath 1 to TV */
  7392. temp &= 0xbf; /* Set datapath 2 to LVDS */
  7393. SiS_SetCH701x(SiS_Pr,0x03,temp);
  7394. if(SiS_Pr->ChipType == SIS_740) {
  7395. temp = SiS_GetCH701x(SiS_Pr,0x1c);
  7396. temp &= 0xfb; /* Normal XCLK phase */
  7397. SiS_SetCH701x(SiS_Pr,0x1c,temp);
  7398. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2d,0x03);
  7399. temp = SiS_GetCH701x(SiS_Pr,0x64);
  7400. temp |= 0x40; /* ? Bit not defined */
  7401. SiS_SetCH701x(SiS_Pr,0x64,temp);
  7402. temp = SiS_GetCH701x(SiS_Pr,0x03);
  7403. temp &= 0x3f; /* D1 input to both LVDS and TV */
  7404. SiS_SetCH701x(SiS_Pr,0x03,temp);
  7405. if(SiS_Pr->SiS_CustomT == CUT_ASUSL3000D) {
  7406. SiS_SetCH701x(SiS_Pr,0x63,0x40); /* LVDS off */
  7407. SiS_LongDelay(SiS_Pr, 1);
  7408. SiS_SetCH701x(SiS_Pr,0x63,0x00); /* LVDS on */
  7409. SiS_ChrontelResetDB(SiS_Pr);
  7410. SiS_ChrontelDoSomething2(SiS_Pr);
  7411. SiS_ChrontelDoSomething3(SiS_Pr, 0);
  7412. } else {
  7413. temp = SiS_GetCH701x(SiS_Pr,0x66);
  7414. if(temp != 0x45) {
  7415. SiS_ChrontelResetDB(SiS_Pr);
  7416. SiS_ChrontelDoSomething2(SiS_Pr);
  7417. SiS_ChrontelDoSomething3(SiS_Pr, 0);
  7418. }
  7419. }
  7420. } else { /* 650 */
  7421. SiS_ChrontelResetDB(SiS_Pr);
  7422. SiS_ChrontelDoSomething2(SiS_Pr);
  7423. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x34);
  7424. SiS_ChrontelDoSomething3(SiS_Pr,temp);
  7425. SiS_SetCH701x(SiS_Pr,0x76,0xaf); /* All power on, LVDS normal operation */
  7426. }
  7427. }
  7428. #endif /* 315 series */
  7429. /*********************************************/
  7430. /* MAIN: SET CRT2 REGISTER GROUP */
  7431. /*********************************************/
  7432. BOOLEAN
  7433. SiS_SetCRT2Group(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
  7434. {
  7435. #ifdef SIS300
  7436. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  7437. #endif
  7438. unsigned short ModeIdIndex, RefreshRateTableIndex;
  7439. SiS_Pr->SiS_SetFlag |= ProgrammingCRT2;
  7440. if(!SiS_Pr->UseCustomMode) {
  7441. SiS_SearchModeID(SiS_Pr, &ModeNo, &ModeIdIndex);
  7442. } else {
  7443. ModeIdIndex = 0;
  7444. }
  7445. /* Used for shifting CR33 */
  7446. SiS_Pr->SiS_SelectCRT2Rate = 4;
  7447. SiS_UnLockCRT2(SiS_Pr);
  7448. RefreshRateTableIndex = SiS_GetRatePtr(SiS_Pr, ModeNo, ModeIdIndex);
  7449. SiS_SaveCRT2Info(SiS_Pr,ModeNo);
  7450. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7451. SiS_DisableBridge(SiS_Pr);
  7452. if((SiS_Pr->SiS_IF_DEF_LVDS == 1) && (SiS_Pr->ChipType == SIS_730)) {
  7453. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,0x80);
  7454. }
  7455. SiS_SetCRT2ModeRegs(SiS_Pr, ModeNo, ModeIdIndex);
  7456. }
  7457. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) {
  7458. SiS_LockCRT2(SiS_Pr);
  7459. SiS_DisplayOn(SiS_Pr);
  7460. return TRUE;
  7461. }
  7462. SiS_GetCRT2Data(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7463. /* Set up Panel Link for LVDS and LCDA */
  7464. SiS_Pr->SiS_LCDHDES = SiS_Pr->SiS_LCDVDES = 0;
  7465. if( (SiS_Pr->SiS_IF_DEF_LVDS == 1) ||
  7466. ((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) ||
  7467. ((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->SiS_VBType & VB_SIS30xBLV)) ) {
  7468. SiS_GetLVDSDesData(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7469. }
  7470. #ifdef SIS_XORG_XF86
  7471. #ifdef TWDEBUG
  7472. xf86DrvMsg(0, X_INFO, "(init301: LCDHDES 0x%03x LCDVDES 0x%03x)\n", SiS_Pr->SiS_LCDHDES, SiS_Pr->SiS_LCDVDES);
  7473. xf86DrvMsg(0, X_INFO, "(init301: HDE 0x%03x VDE 0x%03x)\n", SiS_Pr->SiS_HDE, SiS_Pr->SiS_VDE);
  7474. xf86DrvMsg(0, X_INFO, "(init301: VGAHDE 0x%03x VGAVDE 0x%03x)\n", SiS_Pr->SiS_VGAHDE, SiS_Pr->SiS_VGAVDE);
  7475. xf86DrvMsg(0, X_INFO, "(init301: HT 0x%03x VT 0x%03x)\n", SiS_Pr->SiS_HT, SiS_Pr->SiS_VT);
  7476. xf86DrvMsg(0, X_INFO, "(init301: VGAHT 0x%03x VGAVT 0x%03x)\n", SiS_Pr->SiS_VGAHT, SiS_Pr->SiS_VGAVT);
  7477. #endif
  7478. #endif
  7479. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7480. SiS_SetGroup1(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7481. }
  7482. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  7483. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7484. SiS_SetGroup2(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7485. #ifdef SIS315H
  7486. SiS_SetGroup2_C_ELV(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7487. #endif
  7488. SiS_SetGroup3(SiS_Pr, ModeNo, ModeIdIndex);
  7489. SiS_SetGroup4(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7490. #ifdef SIS315H
  7491. SiS_SetGroup4_C_ELV(SiS_Pr, ModeNo, ModeIdIndex);
  7492. #endif
  7493. SiS_SetGroup5(SiS_Pr, ModeNo, ModeIdIndex);
  7494. SiS_SetCRT2Sync(SiS_Pr, ModeNo, RefreshRateTableIndex);
  7495. /* For 301BDH (Panel link initialization): */
  7496. if((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) {
  7497. if(!((SiS_Pr->SiS_SetFlag & SetDOSMode) && ((ModeNo == 0x03) || (ModeNo == 0x10)))) {
  7498. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  7499. SiS_ModCRT1CRTC(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7500. }
  7501. }
  7502. SiS_SetCRT2ECLK(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7503. }
  7504. }
  7505. } else {
  7506. SiS_SetCRT2Sync(SiS_Pr, ModeNo, RefreshRateTableIndex);
  7507. SiS_ModCRT1CRTC(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex);
  7508. SiS_SetCRT2ECLK(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex);
  7509. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7510. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  7511. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  7512. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  7513. #ifdef SIS315H
  7514. SiS_SetCH701xForLCD(SiS_Pr);
  7515. #endif
  7516. }
  7517. }
  7518. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  7519. SiS_SetCHTVReg(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex);
  7520. }
  7521. }
  7522. }
  7523. }
  7524. #ifdef SIS300
  7525. if(SiS_Pr->ChipType < SIS_315H) {
  7526. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7527. if(SiS_Pr->SiS_UseOEM) {
  7528. if((SiS_Pr->SiS_UseROM) && (SiS_Pr->SiS_UseOEM == -1)) {
  7529. if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) {
  7530. SiS_OEM300Setting(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7531. }
  7532. } else {
  7533. SiS_OEM300Setting(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7534. }
  7535. }
  7536. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  7537. if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) ||
  7538. (SiS_Pr->SiS_CustomT == CUT_BARCO1024)) {
  7539. SetOEMLCDData2(SiS_Pr, ModeNo, ModeIdIndex,RefreshRateTableIndex);
  7540. }
  7541. SiS_DisplayOn(SiS_Pr);
  7542. }
  7543. }
  7544. }
  7545. #endif
  7546. #ifdef SIS315H
  7547. if(SiS_Pr->ChipType >= SIS_315H) {
  7548. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7549. if(SiS_Pr->ChipType < SIS_661) {
  7550. SiS_FinalizeLCD(SiS_Pr, ModeNo, ModeIdIndex);
  7551. SiS_OEM310Setting(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7552. } else {
  7553. SiS_OEM661Setting(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7554. }
  7555. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x01,0x40);
  7556. }
  7557. }
  7558. #endif
  7559. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7560. SiS_EnableBridge(SiS_Pr);
  7561. }
  7562. SiS_DisplayOn(SiS_Pr);
  7563. if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) {
  7564. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  7565. /* Disable LCD panel when using TV */
  7566. SiS_SetRegSR11ANDOR(SiS_Pr,0xFF,0x0C);
  7567. } else {
  7568. /* Disable TV when using LCD */
  7569. SiS_SetCH70xxANDOR(SiS_Pr,0x0e,0x01,0xf8);
  7570. }
  7571. }
  7572. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7573. SiS_LockCRT2(SiS_Pr);
  7574. }
  7575. return TRUE;
  7576. }
  7577. /*********************************************/
  7578. /* ENABLE/DISABLE LCD BACKLIGHT (SIS) */
  7579. /*********************************************/
  7580. void
  7581. SiS_SiS30xBLOn(struct SiS_Private *SiS_Pr)
  7582. {
  7583. /* Switch on LCD backlight on SiS30xLV */
  7584. SiS_DDC2Delay(SiS_Pr,0xff00);
  7585. if(!(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x26) & 0x02)) {
  7586. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x02);
  7587. SiS_WaitVBRetrace(SiS_Pr);
  7588. }
  7589. if(!(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x26) & 0x01)) {
  7590. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x01);
  7591. }
  7592. }
  7593. void
  7594. SiS_SiS30xBLOff(struct SiS_Private *SiS_Pr)
  7595. {
  7596. /* Switch off LCD backlight on SiS30xLV */
  7597. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFE);
  7598. SiS_DDC2Delay(SiS_Pr,0xff00);
  7599. }
  7600. /*********************************************/
  7601. /* DDC RELATED FUNCTIONS */
  7602. /*********************************************/
  7603. static void
  7604. SiS_SetupDDCN(struct SiS_Private *SiS_Pr)
  7605. {
  7606. SiS_Pr->SiS_DDC_NData = ~SiS_Pr->SiS_DDC_Data;
  7607. SiS_Pr->SiS_DDC_NClk = ~SiS_Pr->SiS_DDC_Clk;
  7608. if((SiS_Pr->SiS_DDC_Index == 0x11) && (SiS_Pr->SiS_SensibleSR11)) {
  7609. SiS_Pr->SiS_DDC_NData &= 0x0f;
  7610. SiS_Pr->SiS_DDC_NClk &= 0x0f;
  7611. }
  7612. }
  7613. #ifdef SIS300
  7614. static unsigned char *
  7615. SiS_SetTrumpBlockLoop(struct SiS_Private *SiS_Pr, unsigned char *dataptr)
  7616. {
  7617. int i, j, num;
  7618. unsigned short tempah,temp;
  7619. unsigned char *mydataptr;
  7620. for(i=0; i<20; i++) { /* Do 20 attempts to write */
  7621. mydataptr = dataptr;
  7622. num = *mydataptr++;
  7623. if(!num) return mydataptr;
  7624. if(i) {
  7625. SiS_SetStop(SiS_Pr);
  7626. SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT * 2);
  7627. }
  7628. if(SiS_SetStart(SiS_Pr)) continue; /* Set start condition */
  7629. tempah = SiS_Pr->SiS_DDC_DeviceAddr;
  7630. temp = SiS_WriteDDC2Data(SiS_Pr,tempah); /* Write DAB (S0=0=write) */
  7631. if(temp) continue; /* (ERROR: no ack) */
  7632. tempah = *mydataptr++;
  7633. temp = SiS_WriteDDC2Data(SiS_Pr,tempah); /* Write register number */
  7634. if(temp) continue; /* (ERROR: no ack) */
  7635. for(j=0; j<num; j++) {
  7636. tempah = *mydataptr++;
  7637. temp = SiS_WriteDDC2Data(SiS_Pr,tempah);/* Write DAB (S0=0=write) */
  7638. if(temp) break;
  7639. }
  7640. if(temp) continue;
  7641. if(SiS_SetStop(SiS_Pr)) continue;
  7642. return mydataptr;
  7643. }
  7644. return NULL;
  7645. }
  7646. static BOOLEAN
  7647. SiS_SetTrumpionBlock(struct SiS_Private *SiS_Pr, unsigned char *dataptr)
  7648. {
  7649. SiS_Pr->SiS_DDC_DeviceAddr = 0xF0; /* DAB (Device Address Byte) */
  7650. SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */
  7651. SiS_Pr->SiS_DDC_Data = 0x02; /* Bitmask in IndexReg for Data */
  7652. SiS_Pr->SiS_DDC_Clk = 0x01; /* Bitmask in IndexReg for Clk */
  7653. SiS_SetupDDCN(SiS_Pr);
  7654. SiS_SetSwitchDDC2(SiS_Pr);
  7655. while(*dataptr) {
  7656. dataptr = SiS_SetTrumpBlockLoop(SiS_Pr, dataptr);
  7657. if(!dataptr) return FALSE;
  7658. }
  7659. #ifdef SIS_XORG_XF86
  7660. #ifdef TWDEBUG
  7661. xf86DrvMsg(0, X_INFO, "Trumpion block success\n");
  7662. #endif
  7663. #endif
  7664. return TRUE;
  7665. }
  7666. #endif
  7667. /* The Chrontel 700x is connected to the 630/730 via
  7668. * the 630/730's DDC/I2C port.
  7669. *
  7670. * On 630(S)T chipset, the index changed from 0x11 to
  7671. * 0x0a, possibly for working around the DDC problems
  7672. */
  7673. static BOOLEAN
  7674. SiS_SetChReg(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val, unsigned short myor)
  7675. {
  7676. unsigned short temp, i;
  7677. for(i=0; i<20; i++) { /* Do 20 attempts to write */
  7678. if(i) {
  7679. SiS_SetStop(SiS_Pr);
  7680. SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT * 4);
  7681. }
  7682. if(SiS_SetStart(SiS_Pr)) continue; /* Set start condition */
  7683. temp = SiS_WriteDDC2Data(SiS_Pr, SiS_Pr->SiS_DDC_DeviceAddr); /* Write DAB (S0=0=write) */
  7684. if(temp) continue; /* (ERROR: no ack) */
  7685. temp = SiS_WriteDDC2Data(SiS_Pr, (reg | myor)); /* Write RAB (700x: set bit 7, see datasheet) */
  7686. if(temp) continue; /* (ERROR: no ack) */
  7687. temp = SiS_WriteDDC2Data(SiS_Pr, val); /* Write data */
  7688. if(temp) continue; /* (ERROR: no ack) */
  7689. if(SiS_SetStop(SiS_Pr)) continue; /* Set stop condition */
  7690. SiS_Pr->SiS_ChrontelInit = 1;
  7691. return TRUE;
  7692. }
  7693. return FALSE;
  7694. }
  7695. /* Write to Chrontel 700x */
  7696. void
  7697. SiS_SetCH700x(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val)
  7698. {
  7699. SiS_Pr->SiS_DDC_DeviceAddr = 0xEA; /* DAB (Device Address Byte) */
  7700. SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT);
  7701. if(!(SiS_Pr->SiS_ChrontelInit)) {
  7702. SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */
  7703. SiS_Pr->SiS_DDC_Data = 0x02; /* Bitmask in IndexReg for Data */
  7704. SiS_Pr->SiS_DDC_Clk = 0x01; /* Bitmask in IndexReg for Clk */
  7705. SiS_SetupDDCN(SiS_Pr);
  7706. }
  7707. if( (!(SiS_SetChReg(SiS_Pr, reg, val, 0x80))) &&
  7708. (!(SiS_Pr->SiS_ChrontelInit)) ) {
  7709. SiS_Pr->SiS_DDC_Index = 0x0a;
  7710. SiS_Pr->SiS_DDC_Data = 0x80;
  7711. SiS_Pr->SiS_DDC_Clk = 0x40;
  7712. SiS_SetupDDCN(SiS_Pr);
  7713. SiS_SetChReg(SiS_Pr, reg, val, 0x80);
  7714. }
  7715. }
  7716. /* Write to Chrontel 701x */
  7717. /* Parameter is [Data (S15-S8) | Register no (S7-S0)] */
  7718. void
  7719. SiS_SetCH701x(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val)
  7720. {
  7721. SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */
  7722. SiS_Pr->SiS_DDC_Data = 0x08; /* Bitmask in IndexReg for Data */
  7723. SiS_Pr->SiS_DDC_Clk = 0x04; /* Bitmask in IndexReg for Clk */
  7724. SiS_SetupDDCN(SiS_Pr);
  7725. SiS_Pr->SiS_DDC_DeviceAddr = 0xEA; /* DAB (Device Address Byte) */
  7726. SiS_SetChReg(SiS_Pr, reg, val, 0);
  7727. }
  7728. #ifdef SIS_LINUX_KERNEL
  7729. static
  7730. #endif
  7731. void
  7732. SiS_SetCH70xx(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val)
  7733. {
  7734. if(SiS_Pr->SiS_IF_DEF_CH70xx == 1)
  7735. SiS_SetCH700x(SiS_Pr, reg, val);
  7736. else
  7737. SiS_SetCH701x(SiS_Pr, reg, val);
  7738. }
  7739. static unsigned short
  7740. SiS_GetChReg(struct SiS_Private *SiS_Pr, unsigned short myor)
  7741. {
  7742. unsigned short tempah, temp, i;
  7743. for(i=0; i<20; i++) { /* Do 20 attempts to read */
  7744. if(i) {
  7745. SiS_SetStop(SiS_Pr);
  7746. SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT * 4);
  7747. }
  7748. if(SiS_SetStart(SiS_Pr)) continue; /* Set start condition */
  7749. temp = SiS_WriteDDC2Data(SiS_Pr,SiS_Pr->SiS_DDC_DeviceAddr); /* Write DAB (S0=0=write) */
  7750. if(temp) continue; /* (ERROR: no ack) */
  7751. temp = SiS_WriteDDC2Data(SiS_Pr,SiS_Pr->SiS_DDC_ReadAddr | myor); /* Write RAB (700x: | 0x80) */
  7752. if(temp) continue; /* (ERROR: no ack) */
  7753. if (SiS_SetStart(SiS_Pr)) continue; /* Re-start */
  7754. temp = SiS_WriteDDC2Data(SiS_Pr,SiS_Pr->SiS_DDC_DeviceAddr | 0x01);/* DAB (S0=1=read) */
  7755. if(temp) continue; /* (ERROR: no ack) */
  7756. tempah = SiS_ReadDDC2Data(SiS_Pr); /* Read byte */
  7757. if(SiS_SetStop(SiS_Pr)) continue; /* Stop condition */
  7758. SiS_Pr->SiS_ChrontelInit = 1;
  7759. return tempah;
  7760. }
  7761. return 0xFFFF;
  7762. }
  7763. /* Read from Chrontel 700x */
  7764. /* Parameter is [Register no (S7-S0)] */
  7765. unsigned short
  7766. SiS_GetCH700x(struct SiS_Private *SiS_Pr, unsigned short tempbx)
  7767. {
  7768. unsigned short result;
  7769. SiS_Pr->SiS_DDC_DeviceAddr = 0xEA; /* DAB */
  7770. SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT);
  7771. if(!(SiS_Pr->SiS_ChrontelInit)) {
  7772. SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */
  7773. SiS_Pr->SiS_DDC_Data = 0x02; /* Bitmask in IndexReg for Data */
  7774. SiS_Pr->SiS_DDC_Clk = 0x01; /* Bitmask in IndexReg for Clk */
  7775. SiS_SetupDDCN(SiS_Pr);
  7776. }
  7777. SiS_Pr->SiS_DDC_ReadAddr = tempbx;
  7778. if( ((result = SiS_GetChReg(SiS_Pr,0x80)) == 0xFFFF) &&
  7779. (!SiS_Pr->SiS_ChrontelInit) ) {
  7780. SiS_Pr->SiS_DDC_Index = 0x0a;
  7781. SiS_Pr->SiS_DDC_Data = 0x80;
  7782. SiS_Pr->SiS_DDC_Clk = 0x40;
  7783. SiS_SetupDDCN(SiS_Pr);
  7784. result = SiS_GetChReg(SiS_Pr,0x80);
  7785. }
  7786. return result;
  7787. }
  7788. /* Read from Chrontel 701x */
  7789. /* Parameter is [Register no (S7-S0)] */
  7790. unsigned short
  7791. SiS_GetCH701x(struct SiS_Private *SiS_Pr, unsigned short tempbx)
  7792. {
  7793. SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */
  7794. SiS_Pr->SiS_DDC_Data = 0x08; /* Bitmask in IndexReg for Data */
  7795. SiS_Pr->SiS_DDC_Clk = 0x04; /* Bitmask in IndexReg for Clk */
  7796. SiS_SetupDDCN(SiS_Pr);
  7797. SiS_Pr->SiS_DDC_DeviceAddr = 0xEA; /* DAB */
  7798. SiS_Pr->SiS_DDC_ReadAddr = tempbx;
  7799. return SiS_GetChReg(SiS_Pr,0);
  7800. }
  7801. /* Read from Chrontel 70xx */
  7802. /* Parameter is [Register no (S7-S0)] */
  7803. #ifdef SIS_LINUX_KERNEL
  7804. static
  7805. #endif
  7806. unsigned short
  7807. SiS_GetCH70xx(struct SiS_Private *SiS_Pr, unsigned short tempbx)
  7808. {
  7809. if(SiS_Pr->SiS_IF_DEF_CH70xx == 1)
  7810. return SiS_GetCH700x(SiS_Pr, tempbx);
  7811. else
  7812. return SiS_GetCH701x(SiS_Pr, tempbx);
  7813. }
  7814. void
  7815. SiS_SetCH70xxANDOR(struct SiS_Private *SiS_Pr, unsigned short reg,
  7816. unsigned char myor, unsigned short myand)
  7817. {
  7818. unsigned short tempbl;
  7819. tempbl = (SiS_GetCH70xx(SiS_Pr, (reg & 0xFF)) & myand) | myor;
  7820. SiS_SetCH70xx(SiS_Pr, reg, tempbl);
  7821. }
  7822. /* Our own DDC functions */
  7823. #ifndef SIS_XORG_XF86
  7824. static
  7825. #endif
  7826. unsigned short
  7827. SiS_InitDDCRegs(struct SiS_Private *SiS_Pr, unsigned int VBFlags, int VGAEngine,
  7828. unsigned short adaptnum, unsigned short DDCdatatype, BOOLEAN checkcr32,
  7829. unsigned int VBFlags2)
  7830. {
  7831. unsigned char ddcdtype[] = { 0xa0, 0xa0, 0xa0, 0xa2, 0xa6 };
  7832. unsigned char flag, cr32;
  7833. unsigned short temp = 0, myadaptnum = adaptnum;
  7834. if(adaptnum != 0) {
  7835. if(!(VBFlags2 & VB2_SISTMDSBRIDGE)) return 0xFFFF;
  7836. if((VBFlags2 & VB2_30xBDH) && (adaptnum == 1)) return 0xFFFF;
  7837. }
  7838. /* adapternum for SiS bridges: 0 = CRT1, 1 = LCD, 2 = VGA2 */
  7839. SiS_Pr->SiS_ChrontelInit = 0; /* force re-detection! */
  7840. SiS_Pr->SiS_DDC_SecAddr = 0;
  7841. SiS_Pr->SiS_DDC_DeviceAddr = ddcdtype[DDCdatatype];
  7842. SiS_Pr->SiS_DDC_Port = SiS_Pr->SiS_P3c4;
  7843. SiS_Pr->SiS_DDC_Index = 0x11;
  7844. flag = 0xff;
  7845. cr32 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x32);
  7846. #if 0
  7847. if(VBFlags2 & VB2_SISBRIDGE) {
  7848. if(myadaptnum == 0) {
  7849. if(!(cr32 & 0x20)) {
  7850. myadaptnum = 2;
  7851. if(!(cr32 & 0x10)) {
  7852. myadaptnum = 1;
  7853. if(!(cr32 & 0x08)) {
  7854. myadaptnum = 0;
  7855. }
  7856. }
  7857. }
  7858. }
  7859. }
  7860. #endif
  7861. if(VGAEngine == SIS_300_VGA) { /* 300 series */
  7862. if(myadaptnum != 0) {
  7863. flag = 0;
  7864. if(VBFlags2 & VB2_SISBRIDGE) {
  7865. SiS_Pr->SiS_DDC_Port = SiS_Pr->SiS_Part4Port;
  7866. SiS_Pr->SiS_DDC_Index = 0x0f;
  7867. }
  7868. }
  7869. if(!(VBFlags2 & VB2_301)) {
  7870. if((cr32 & 0x80) && (checkcr32)) {
  7871. if(myadaptnum >= 1) {
  7872. if(!(cr32 & 0x08)) {
  7873. myadaptnum = 1;
  7874. if(!(cr32 & 0x10)) return 0xFFFF;
  7875. }
  7876. }
  7877. }
  7878. }
  7879. temp = 4 - (myadaptnum * 2);
  7880. if(flag) temp = 0;
  7881. } else { /* 315/330 series */
  7882. /* here we simplify: 0 = CRT1, 1 = CRT2 (VGA, LCD) */
  7883. if(VBFlags2 & VB2_SISBRIDGE) {
  7884. if(myadaptnum == 2) {
  7885. myadaptnum = 1;
  7886. }
  7887. }
  7888. if(myadaptnum == 1) {
  7889. flag = 0;
  7890. if(VBFlags2 & VB2_SISBRIDGE) {
  7891. SiS_Pr->SiS_DDC_Port = SiS_Pr->SiS_Part4Port;
  7892. SiS_Pr->SiS_DDC_Index = 0x0f;
  7893. }
  7894. }
  7895. if((cr32 & 0x80) && (checkcr32)) {
  7896. if(myadaptnum >= 1) {
  7897. if(!(cr32 & 0x08)) {
  7898. myadaptnum = 1;
  7899. if(!(cr32 & 0x10)) return 0xFFFF;
  7900. }
  7901. }
  7902. }
  7903. temp = myadaptnum;
  7904. if(myadaptnum == 1) {
  7905. temp = 0;
  7906. if(VBFlags2 & VB2_LVDS) flag = 0xff;
  7907. }
  7908. if(flag) temp = 0;
  7909. }
  7910. SiS_Pr->SiS_DDC_Data = 0x02 << temp;
  7911. SiS_Pr->SiS_DDC_Clk = 0x01 << temp;
  7912. SiS_SetupDDCN(SiS_Pr);
  7913. #ifdef SIS_XORG_XF86
  7914. #ifdef TWDEBUG
  7915. xf86DrvMsg(0, X_INFO, "DDC Port %x Index %x Shift %d\n",
  7916. SiS_Pr->SiS_DDC_Port, SiS_Pr->SiS_DDC_Index, temp);
  7917. #endif
  7918. #endif
  7919. return 0;
  7920. }
  7921. static unsigned short
  7922. SiS_WriteDABDDC(struct SiS_Private *SiS_Pr)
  7923. {
  7924. if(SiS_SetStart(SiS_Pr)) return 0xFFFF;
  7925. if(SiS_WriteDDC2Data(SiS_Pr, SiS_Pr->SiS_DDC_DeviceAddr)) {
  7926. return 0xFFFF;
  7927. }
  7928. if(SiS_WriteDDC2Data(SiS_Pr, SiS_Pr->SiS_DDC_SecAddr)) {
  7929. return 0xFFFF;
  7930. }
  7931. return 0;
  7932. }
  7933. static unsigned short
  7934. SiS_PrepareReadDDC(struct SiS_Private *SiS_Pr)
  7935. {
  7936. if(SiS_SetStart(SiS_Pr)) return 0xFFFF;
  7937. if(SiS_WriteDDC2Data(SiS_Pr, (SiS_Pr->SiS_DDC_DeviceAddr | 0x01))) {
  7938. return 0xFFFF;
  7939. }
  7940. return 0;
  7941. }
  7942. static unsigned short
  7943. SiS_PrepareDDC(struct SiS_Private *SiS_Pr)
  7944. {
  7945. if(SiS_WriteDABDDC(SiS_Pr)) SiS_WriteDABDDC(SiS_Pr);
  7946. if(SiS_PrepareReadDDC(SiS_Pr)) return (SiS_PrepareReadDDC(SiS_Pr));
  7947. return 0;
  7948. }
  7949. static void
  7950. SiS_SendACK(struct SiS_Private *SiS_Pr, unsigned short yesno)
  7951. {
  7952. SiS_SetSCLKLow(SiS_Pr);
  7953. if(yesno) {
  7954. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  7955. SiS_Pr->SiS_DDC_Index,
  7956. SiS_Pr->SiS_DDC_NData,
  7957. SiS_Pr->SiS_DDC_Data);
  7958. } else {
  7959. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  7960. SiS_Pr->SiS_DDC_Index,
  7961. SiS_Pr->SiS_DDC_NData,
  7962. 0);
  7963. }
  7964. SiS_SetSCLKHigh(SiS_Pr);
  7965. }
  7966. static unsigned short
  7967. SiS_DoProbeDDC(struct SiS_Private *SiS_Pr)
  7968. {
  7969. unsigned char mask, value;
  7970. unsigned short temp, ret=0;
  7971. BOOLEAN failed = FALSE;
  7972. SiS_SetSwitchDDC2(SiS_Pr);
  7973. if(SiS_PrepareDDC(SiS_Pr)) {
  7974. SiS_SetStop(SiS_Pr);
  7975. #ifdef SIS_XORG_XF86
  7976. #ifdef TWDEBUG
  7977. xf86DrvMsg(0, X_INFO, "Probe: Prepare failed\n");
  7978. #endif
  7979. #endif
  7980. return 0xFFFF;
  7981. }
  7982. mask = 0xf0;
  7983. value = 0x20;
  7984. if(SiS_Pr->SiS_DDC_DeviceAddr == 0xa0) {
  7985. temp = (unsigned char)SiS_ReadDDC2Data(SiS_Pr);
  7986. SiS_SendACK(SiS_Pr, 0);
  7987. if(temp == 0) {
  7988. mask = 0xff;
  7989. value = 0xff;
  7990. } else {
  7991. failed = TRUE;
  7992. ret = 0xFFFF;
  7993. #ifdef SIS_XORG_XF86
  7994. #ifdef TWDEBUG
  7995. xf86DrvMsg(0, X_INFO, "Probe: Read 1 failed\n");
  7996. #endif
  7997. #endif
  7998. }
  7999. }
  8000. if(failed == FALSE) {
  8001. temp = (unsigned char)SiS_ReadDDC2Data(SiS_Pr);
  8002. SiS_SendACK(SiS_Pr, 1);
  8003. temp &= mask;
  8004. if(temp == value) ret = 0;
  8005. else {
  8006. ret = 0xFFFF;
  8007. #ifdef SIS_XORG_XF86
  8008. #ifdef TWDEBUG
  8009. xf86DrvMsg(0, X_INFO, "Probe: Read 2 failed\n");
  8010. #endif
  8011. #endif
  8012. if(SiS_Pr->SiS_DDC_DeviceAddr == 0xa0) {
  8013. if(temp == 0x30) ret = 0;
  8014. }
  8015. }
  8016. }
  8017. SiS_SetStop(SiS_Pr);
  8018. return ret;
  8019. }
  8020. #ifndef SIS_XORG_XF86
  8021. static
  8022. #endif
  8023. unsigned short
  8024. SiS_ProbeDDC(struct SiS_Private *SiS_Pr)
  8025. {
  8026. unsigned short flag;
  8027. flag = 0x180;
  8028. SiS_Pr->SiS_DDC_DeviceAddr = 0xa0;
  8029. if(!(SiS_DoProbeDDC(SiS_Pr))) flag |= 0x02;
  8030. SiS_Pr->SiS_DDC_DeviceAddr = 0xa2;
  8031. if(!(SiS_DoProbeDDC(SiS_Pr))) flag |= 0x08;
  8032. SiS_Pr->SiS_DDC_DeviceAddr = 0xa6;
  8033. if(!(SiS_DoProbeDDC(SiS_Pr))) flag |= 0x10;
  8034. if(!(flag & 0x1a)) flag = 0;
  8035. return flag;
  8036. }
  8037. #ifndef SIS_XORG_XF86
  8038. static
  8039. #endif
  8040. unsigned short
  8041. SiS_ReadDDC(struct SiS_Private *SiS_Pr, unsigned short DDCdatatype, unsigned char *buffer)
  8042. {
  8043. unsigned short flag, length, i;
  8044. unsigned char chksum,gotcha;
  8045. if(DDCdatatype > 4) return 0xFFFF;
  8046. flag = 0;
  8047. SiS_SetSwitchDDC2(SiS_Pr);
  8048. if(!(SiS_PrepareDDC(SiS_Pr))) {
  8049. length = 127;
  8050. if(DDCdatatype != 1) length = 255;
  8051. chksum = 0;
  8052. gotcha = 0;
  8053. for(i=0; i<length; i++) {
  8054. buffer[i] = (unsigned char)SiS_ReadDDC2Data(SiS_Pr);
  8055. chksum += buffer[i];
  8056. gotcha |= buffer[i];
  8057. SiS_SendACK(SiS_Pr, 0);
  8058. }
  8059. buffer[i] = (unsigned char)SiS_ReadDDC2Data(SiS_Pr);
  8060. chksum += buffer[i];
  8061. SiS_SendACK(SiS_Pr, 1);
  8062. if(gotcha) flag = (unsigned short)chksum;
  8063. else flag = 0xFFFF;
  8064. } else {
  8065. flag = 0xFFFF;
  8066. }
  8067. SiS_SetStop(SiS_Pr);
  8068. return flag;
  8069. }
  8070. /* Our private DDC functions
  8071. It complies somewhat with the corresponding VESA function
  8072. in arguments and return values.
  8073. Since this is probably called before the mode is changed,
  8074. we use our pre-detected pSiS-values instead of SiS_Pr as
  8075. regards chipset and video bridge type.
  8076. Arguments:
  8077. adaptnum: 0=CRT1(analog), 1=CRT2/LCD(digital), 2=CRT2/VGA2(analog)
  8078. CRT2 DDC is only supported on SiS301, 301B, 301C, 302B.
  8079. LCDA is CRT1, but DDC is read from CRT2 port.
  8080. DDCdatatype: 0=Probe, 1=EDID, 2=EDID+VDIF, 3=EDID V2 (P&D), 4=EDID V2 (FPDI-2)
  8081. buffer: ptr to 256 data bytes which will be filled with read data.
  8082. Returns 0xFFFF if error, otherwise
  8083. if DDCdatatype > 0: Returns 0 if reading OK (included a correct checksum)
  8084. if DDCdatatype = 0: Returns supported DDC modes
  8085. */
  8086. unsigned short
  8087. SiS_HandleDDC(struct SiS_Private *SiS_Pr, unsigned int VBFlags, int VGAEngine,
  8088. unsigned short adaptnum, unsigned short DDCdatatype, unsigned char *buffer,
  8089. unsigned int VBFlags2)
  8090. {
  8091. unsigned char sr1f, cr17=1;
  8092. unsigned short result;
  8093. if(adaptnum > 2)
  8094. return 0xFFFF;
  8095. if(DDCdatatype > 4)
  8096. return 0xFFFF;
  8097. if((!(VBFlags2 & VB2_VIDEOBRIDGE)) && (adaptnum > 0))
  8098. return 0xFFFF;
  8099. if(SiS_InitDDCRegs(SiS_Pr, VBFlags, VGAEngine, adaptnum, DDCdatatype, FALSE, VBFlags2) == 0xFFFF)
  8100. return 0xFFFF;
  8101. sr1f = SiS_GetReg(SiS_Pr->SiS_P3c4,0x1f);
  8102. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x1f,0x3f,0x04);
  8103. if(VGAEngine == SIS_300_VGA) {
  8104. cr17 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x17) & 0x80;
  8105. if(!cr17) {
  8106. SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x17,0x80);
  8107. SiS_SetReg(SiS_Pr->SiS_P3c4,0x00,0x01);
  8108. SiS_SetReg(SiS_Pr->SiS_P3c4,0x00,0x03);
  8109. }
  8110. }
  8111. if((sr1f) || (!cr17)) {
  8112. SiS_WaitRetrace1(SiS_Pr);
  8113. SiS_WaitRetrace1(SiS_Pr);
  8114. SiS_WaitRetrace1(SiS_Pr);
  8115. SiS_WaitRetrace1(SiS_Pr);
  8116. }
  8117. if(DDCdatatype == 0) {
  8118. result = SiS_ProbeDDC(SiS_Pr);
  8119. } else {
  8120. result = SiS_ReadDDC(SiS_Pr, DDCdatatype, buffer);
  8121. if((!result) && (DDCdatatype == 1)) {
  8122. if((buffer[0] == 0x00) && (buffer[1] == 0xff) &&
  8123. (buffer[2] == 0xff) && (buffer[3] == 0xff) &&
  8124. (buffer[4] == 0xff) && (buffer[5] == 0xff) &&
  8125. (buffer[6] == 0xff) && (buffer[7] == 0x00) &&
  8126. (buffer[0x12] == 1)) {
  8127. if(!SiS_Pr->DDCPortMixup) {
  8128. if(adaptnum == 1) {
  8129. if(!(buffer[0x14] & 0x80)) result = 0xFFFE;
  8130. } else {
  8131. if(buffer[0x14] & 0x80) result = 0xFFFE;
  8132. }
  8133. }
  8134. }
  8135. }
  8136. }
  8137. SiS_SetReg(SiS_Pr->SiS_P3c4,0x1f,sr1f);
  8138. if(VGAEngine == SIS_300_VGA) {
  8139. SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x17,0x7f,cr17);
  8140. }
  8141. return result;
  8142. }
  8143. /* Generic I2C functions for Chrontel & DDC --------- */
  8144. static void
  8145. SiS_SetSwitchDDC2(struct SiS_Private *SiS_Pr)
  8146. {
  8147. SiS_SetSCLKHigh(SiS_Pr);
  8148. SiS_WaitRetrace1(SiS_Pr);
  8149. SiS_SetSCLKLow(SiS_Pr);
  8150. SiS_WaitRetrace1(SiS_Pr);
  8151. }
  8152. unsigned short
  8153. SiS_ReadDDC1Bit(struct SiS_Private *SiS_Pr)
  8154. {
  8155. SiS_WaitRetrace1(SiS_Pr);
  8156. return ((SiS_GetReg(SiS_Pr->SiS_P3c4,0x11) & 0x02) >> 1);
  8157. }
  8158. /* Set I2C start condition */
  8159. /* This is done by a SD high-to-low transition while SC is high */
  8160. static unsigned short
  8161. SiS_SetStart(struct SiS_Private *SiS_Pr)
  8162. {
  8163. if(SiS_SetSCLKLow(SiS_Pr)) return 0xFFFF; /* (SC->low) */
  8164. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8165. SiS_Pr->SiS_DDC_Index,
  8166. SiS_Pr->SiS_DDC_NData,
  8167. SiS_Pr->SiS_DDC_Data); /* SD->high */
  8168. if(SiS_SetSCLKHigh(SiS_Pr)) return 0xFFFF; /* SC->high */
  8169. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8170. SiS_Pr->SiS_DDC_Index,
  8171. SiS_Pr->SiS_DDC_NData,
  8172. 0x00); /* SD->low = start condition */
  8173. if(SiS_SetSCLKHigh(SiS_Pr)) return 0xFFFF; /* (SC->low) */
  8174. return 0;
  8175. }
  8176. /* Set I2C stop condition */
  8177. /* This is done by a SD low-to-high transition while SC is high */
  8178. static unsigned short
  8179. SiS_SetStop(struct SiS_Private *SiS_Pr)
  8180. {
  8181. if(SiS_SetSCLKLow(SiS_Pr)) return 0xFFFF; /* (SC->low) */
  8182. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8183. SiS_Pr->SiS_DDC_Index,
  8184. SiS_Pr->SiS_DDC_NData,
  8185. 0x00); /* SD->low */
  8186. if(SiS_SetSCLKHigh(SiS_Pr)) return 0xFFFF; /* SC->high */
  8187. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8188. SiS_Pr->SiS_DDC_Index,
  8189. SiS_Pr->SiS_DDC_NData,
  8190. SiS_Pr->SiS_DDC_Data); /* SD->high = stop condition */
  8191. if(SiS_SetSCLKHigh(SiS_Pr)) return 0xFFFF; /* (SC->high) */
  8192. return 0;
  8193. }
  8194. /* Write 8 bits of data */
  8195. static unsigned short
  8196. SiS_WriteDDC2Data(struct SiS_Private *SiS_Pr, unsigned short tempax)
  8197. {
  8198. unsigned short i,flag,temp;
  8199. flag = 0x80;
  8200. for(i = 0; i < 8; i++) {
  8201. SiS_SetSCLKLow(SiS_Pr); /* SC->low */
  8202. if(tempax & flag) {
  8203. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8204. SiS_Pr->SiS_DDC_Index,
  8205. SiS_Pr->SiS_DDC_NData,
  8206. SiS_Pr->SiS_DDC_Data); /* Write bit (1) to SD */
  8207. } else {
  8208. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8209. SiS_Pr->SiS_DDC_Index,
  8210. SiS_Pr->SiS_DDC_NData,
  8211. 0x00); /* Write bit (0) to SD */
  8212. }
  8213. SiS_SetSCLKHigh(SiS_Pr); /* SC->high */
  8214. flag >>= 1;
  8215. }
  8216. temp = SiS_CheckACK(SiS_Pr); /* Check acknowledge */
  8217. return temp;
  8218. }
  8219. static unsigned short
  8220. SiS_ReadDDC2Data(struct SiS_Private *SiS_Pr)
  8221. {
  8222. unsigned short i, temp, getdata;
  8223. getdata = 0;
  8224. for(i = 0; i < 8; i++) {
  8225. getdata <<= 1;
  8226. SiS_SetSCLKLow(SiS_Pr);
  8227. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8228. SiS_Pr->SiS_DDC_Index,
  8229. SiS_Pr->SiS_DDC_NData,
  8230. SiS_Pr->SiS_DDC_Data);
  8231. SiS_SetSCLKHigh(SiS_Pr);
  8232. temp = SiS_GetReg(SiS_Pr->SiS_DDC_Port,SiS_Pr->SiS_DDC_Index);
  8233. if(temp & SiS_Pr->SiS_DDC_Data) getdata |= 0x01;
  8234. }
  8235. return getdata;
  8236. }
  8237. static unsigned short
  8238. SiS_SetSCLKLow(struct SiS_Private *SiS_Pr)
  8239. {
  8240. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8241. SiS_Pr->SiS_DDC_Index,
  8242. SiS_Pr->SiS_DDC_NClk,
  8243. 0x00); /* SetSCLKLow() */
  8244. SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT);
  8245. return 0;
  8246. }
  8247. static unsigned short
  8248. SiS_SetSCLKHigh(struct SiS_Private *SiS_Pr)
  8249. {
  8250. unsigned short temp, watchdog=1000;
  8251. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8252. SiS_Pr->SiS_DDC_Index,
  8253. SiS_Pr->SiS_DDC_NClk,
  8254. SiS_Pr->SiS_DDC_Clk); /* SetSCLKHigh() */
  8255. do {
  8256. temp = SiS_GetReg(SiS_Pr->SiS_DDC_Port,SiS_Pr->SiS_DDC_Index);
  8257. } while((!(temp & SiS_Pr->SiS_DDC_Clk)) && --watchdog);
  8258. if (!watchdog) {
  8259. #ifdef SIS_XORG_XF86
  8260. #ifdef TWDEBUG
  8261. xf86DrvMsg(0, X_INFO, "SetClkHigh failed\n");
  8262. #endif
  8263. #endif
  8264. return 0xFFFF;
  8265. }
  8266. SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT);
  8267. return 0;
  8268. }
  8269. /* Check I2C acknowledge */
  8270. /* Returns 0 if ack ok, non-0 if ack not ok */
  8271. static unsigned short
  8272. SiS_CheckACK(struct SiS_Private *SiS_Pr)
  8273. {
  8274. unsigned short tempah;
  8275. SiS_SetSCLKLow(SiS_Pr); /* (SC->low) */
  8276. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8277. SiS_Pr->SiS_DDC_Index,
  8278. SiS_Pr->SiS_DDC_NData,
  8279. SiS_Pr->SiS_DDC_Data); /* (SD->high) */
  8280. SiS_SetSCLKHigh(SiS_Pr); /* SC->high = clock impulse for ack */
  8281. tempah = SiS_GetReg(SiS_Pr->SiS_DDC_Port,SiS_Pr->SiS_DDC_Index); /* Read SD */
  8282. SiS_SetSCLKLow(SiS_Pr); /* SC->low = end of clock impulse */
  8283. if(tempah & SiS_Pr->SiS_DDC_Data) return 1; /* Ack OK if bit = 0 */
  8284. return 0;
  8285. }
  8286. /* End of I2C functions ----------------------- */
  8287. /* =============== SiS 315/330 O.E.M. ================= */
  8288. #ifdef SIS315H
  8289. static unsigned short
  8290. GetRAMDACromptr(struct SiS_Private *SiS_Pr)
  8291. {
  8292. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  8293. unsigned short romptr;
  8294. if(SiS_Pr->ChipType < SIS_330) {
  8295. romptr = SISGETROMW(0x128);
  8296. if(SiS_Pr->SiS_VBType & VB_SIS30xB)
  8297. romptr = SISGETROMW(0x12a);
  8298. } else {
  8299. romptr = SISGETROMW(0x1a8);
  8300. if(SiS_Pr->SiS_VBType & VB_SIS30xB)
  8301. romptr = SISGETROMW(0x1aa);
  8302. }
  8303. return romptr;
  8304. }
  8305. static unsigned short
  8306. GetLCDromptr(struct SiS_Private *SiS_Pr)
  8307. {
  8308. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  8309. unsigned short romptr;
  8310. if(SiS_Pr->ChipType < SIS_330) {
  8311. romptr = SISGETROMW(0x120);
  8312. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV)
  8313. romptr = SISGETROMW(0x122);
  8314. } else {
  8315. romptr = SISGETROMW(0x1a0);
  8316. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV)
  8317. romptr = SISGETROMW(0x1a2);
  8318. }
  8319. return romptr;
  8320. }
  8321. static unsigned short
  8322. GetTVromptr(struct SiS_Private *SiS_Pr)
  8323. {
  8324. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  8325. unsigned short romptr;
  8326. if(SiS_Pr->ChipType < SIS_330) {
  8327. romptr = SISGETROMW(0x114);
  8328. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV)
  8329. romptr = SISGETROMW(0x11a);
  8330. } else {
  8331. romptr = SISGETROMW(0x194);
  8332. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV)
  8333. romptr = SISGETROMW(0x19a);
  8334. }
  8335. return romptr;
  8336. }
  8337. static unsigned short
  8338. GetLCDPtrIndexBIOS(struct SiS_Private *SiS_Pr)
  8339. {
  8340. unsigned short index;
  8341. if((IS_SIS650) && (SiS_Pr->SiS_VBType & VB_SISLVDS)) {
  8342. if(!(SiS_IsNotM650orLater(SiS_Pr))) {
  8343. if((index = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) & 0xf0)) {
  8344. index >>= 4;
  8345. index *= 3;
  8346. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) index += 2;
  8347. else if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) index++;
  8348. return index;
  8349. }
  8350. }
  8351. }
  8352. index = SiS_GetBIOSLCDResInfo(SiS_Pr) & 0x0F;
  8353. if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) index -= 5;
  8354. if(SiS_Pr->SiS_VBType & VB_SIS301C) { /* 1.15.20 and later (not VB specific) */
  8355. if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) index -= 5;
  8356. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x768) index -= 5;
  8357. } else {
  8358. if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) index -= 6;
  8359. }
  8360. index--;
  8361. index *= 3;
  8362. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) index += 2;
  8363. else if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) index++;
  8364. return index;
  8365. }
  8366. static unsigned short
  8367. GetLCDPtrIndex(struct SiS_Private *SiS_Pr)
  8368. {
  8369. unsigned short index;
  8370. index = ((SiS_GetBIOSLCDResInfo(SiS_Pr) & 0x0F) - 1) * 3;
  8371. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) index += 2;
  8372. else if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) index++;
  8373. return index;
  8374. }
  8375. static unsigned short
  8376. GetTVPtrIndex(struct SiS_Private *SiS_Pr)
  8377. {
  8378. unsigned short index;
  8379. index = 0;
  8380. if(SiS_Pr->SiS_TVMode & TVSetPAL) index = 1;
  8381. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) index = 2;
  8382. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) index = 0;
  8383. index <<= 1;
  8384. if((SiS_Pr->SiS_VBInfo & SetInSlaveMode) &&
  8385. (SiS_Pr->SiS_TVMode & TVSetTVSimuMode)) {
  8386. index++;
  8387. }
  8388. return index;
  8389. }
  8390. static unsigned int
  8391. GetOEMTVPtr661_2_GEN(struct SiS_Private *SiS_Pr, int addme)
  8392. {
  8393. unsigned short index = 0, temp = 0;
  8394. if(SiS_Pr->SiS_TVMode & TVSetPAL) index = 1;
  8395. if(SiS_Pr->SiS_TVMode & TVSetPALM) index = 2;
  8396. if(SiS_Pr->SiS_TVMode & TVSetPALN) index = 3;
  8397. if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) index = 6;
  8398. if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) {
  8399. index = 4;
  8400. if(SiS_Pr->SiS_TVMode & TVSetPALM) index++;
  8401. if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) index = 7;
  8402. }
  8403. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  8404. if((!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) ||
  8405. (SiS_Pr->SiS_TVMode & TVSetTVSimuMode)) {
  8406. index += addme;
  8407. temp++;
  8408. }
  8409. temp += 0x0100;
  8410. }
  8411. return (unsigned int)(index | (temp << 16));
  8412. }
  8413. static unsigned int
  8414. GetOEMTVPtr661_2_OLD(struct SiS_Private *SiS_Pr)
  8415. {
  8416. return (GetOEMTVPtr661_2_GEN(SiS_Pr, 8));
  8417. }
  8418. #if 0
  8419. static unsigned int
  8420. GetOEMTVPtr661_2_NEW(struct SiS_Private *SiS_Pr)
  8421. {
  8422. return (GetOEMTVPtr661_2_GEN(SiS_Pr, 6));
  8423. }
  8424. #endif
  8425. static int
  8426. GetOEMTVPtr661(struct SiS_Private *SiS_Pr)
  8427. {
  8428. int index = 0;
  8429. if(SiS_Pr->SiS_TVMode & TVSetPAL) index = 2;
  8430. if(SiS_Pr->SiS_ROMNew) {
  8431. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525i) index = 4;
  8432. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) index = 6;
  8433. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) index = 8;
  8434. if(SiS_Pr->SiS_TVMode & TVSetHiVision) index = 10;
  8435. } else {
  8436. if(SiS_Pr->SiS_TVMode & TVSetHiVision) index = 4;
  8437. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525i) index = 6;
  8438. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) index = 8;
  8439. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) index = 10;
  8440. }
  8441. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) index++;
  8442. return index;
  8443. }
  8444. static void
  8445. SetDelayComp(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
  8446. {
  8447. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  8448. unsigned short delay=0,index,myindex,temp,romptr=0;
  8449. BOOLEAN dochiptest = TRUE;
  8450. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  8451. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x20,0xbf);
  8452. } else {
  8453. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x35,0x7f);
  8454. }
  8455. /* Find delay (from ROM, internal tables, PCI subsystem) */
  8456. if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) { /* ------------ VGA */
  8457. if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
  8458. romptr = GetRAMDACromptr(SiS_Pr);
  8459. }
  8460. if(romptr) delay = ROMAddr[romptr];
  8461. else {
  8462. delay = 0x04;
  8463. if(SiS_Pr->SiS_VBType & VB_SIS30xB) {
  8464. if(IS_SIS650) {
  8465. delay = 0x0a;
  8466. } else if(IS_SIS740) {
  8467. delay = 0x00;
  8468. } else if(SiS_Pr->ChipType < SIS_330) {
  8469. delay = 0x0c;
  8470. } else {
  8471. delay = 0x0c;
  8472. }
  8473. } else if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  8474. delay = 0x00;
  8475. }
  8476. }
  8477. } else if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD|SetCRT2ToLCDA)) { /* ---------- LCD/LCDA */
  8478. BOOLEAN gotitfrompci = FALSE;
  8479. /* Could we detect a PDC for LCD or did we get a user-defined? If yes, use it */
  8480. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  8481. if(SiS_Pr->PDC != -1) {
  8482. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0xf0,((SiS_Pr->PDC >> 1) & 0x0f));
  8483. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x35,0x7f,((SiS_Pr->PDC & 0x01) << 7));
  8484. return;
  8485. }
  8486. } else {
  8487. if(SiS_Pr->PDCA != -1) {
  8488. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0x0f,((SiS_Pr->PDCA << 3) & 0xf0));
  8489. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x20,0xbf,((SiS_Pr->PDCA & 0x01) << 6));
  8490. return;
  8491. }
  8492. }
  8493. /* Custom Panel? */
  8494. if(SiS_Pr->SiS_LCDResInfo == Panel_Custom) {
  8495. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  8496. delay = 0x00;
  8497. if((SiS_Pr->PanelXRes <= 1280) && (SiS_Pr->PanelYRes <= 1024)) {
  8498. delay = 0x20;
  8499. }
  8500. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0x0f,delay);
  8501. } else {
  8502. delay = 0x0c;
  8503. if(SiS_Pr->SiS_VBType & VB_SIS301C) {
  8504. delay = 0x03;
  8505. if((SiS_Pr->PanelXRes > 1280) && (SiS_Pr->PanelYRes > 1024)) {
  8506. delay = 0x00;
  8507. }
  8508. } else if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  8509. if(IS_SIS740) delay = 0x01;
  8510. else delay = 0x03;
  8511. }
  8512. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0xf0,delay);
  8513. }
  8514. return;
  8515. }
  8516. /* This is a piece of typical SiS crap: They code the OEM LCD
  8517. * delay into the code, at no defined place in the BIOS.
  8518. * We now have to start doing a PCI subsystem check here.
  8519. */
  8520. switch(SiS_Pr->SiS_CustomT) {
  8521. case CUT_COMPAQ1280:
  8522. case CUT_COMPAQ12802:
  8523. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) {
  8524. gotitfrompci = TRUE;
  8525. dochiptest = FALSE;
  8526. delay = 0x03;
  8527. }
  8528. break;
  8529. case CUT_CLEVO1400:
  8530. case CUT_CLEVO14002:
  8531. gotitfrompci = TRUE;
  8532. dochiptest = FALSE;
  8533. delay = 0x02;
  8534. break;
  8535. case CUT_CLEVO1024:
  8536. case CUT_CLEVO10242:
  8537. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  8538. gotitfrompci = TRUE;
  8539. dochiptest = FALSE;
  8540. delay = 0x33;
  8541. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2D,delay);
  8542. delay &= 0x0f;
  8543. }
  8544. break;
  8545. }
  8546. /* Could we find it through the PCI ID? If no, use ROM or table */
  8547. if(!gotitfrompci) {
  8548. index = GetLCDPtrIndexBIOS(SiS_Pr);
  8549. myindex = GetLCDPtrIndex(SiS_Pr);
  8550. if(IS_SIS650 && (SiS_Pr->SiS_VBType & VB_SISLVDS)) {
  8551. if(SiS_IsNotM650orLater(SiS_Pr)) {
  8552. if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
  8553. /* Always use the second pointer on 650; some BIOSes */
  8554. /* still carry old 301 data at the first location */
  8555. /* romptr = SISGETROMW(0x120); */
  8556. /* if(SiS_Pr->SiS_VBType & VB_SIS302LV) */
  8557. romptr = SISGETROMW(0x122);
  8558. if(!romptr) return;
  8559. delay = ROMAddr[(romptr + index)];
  8560. } else {
  8561. delay = SiS310_LCDDelayCompensation_650301LV[myindex];
  8562. }
  8563. } else {
  8564. delay = SiS310_LCDDelayCompensation_651301LV[myindex];
  8565. if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV))
  8566. delay = SiS310_LCDDelayCompensation_651302LV[myindex];
  8567. }
  8568. } else if(SiS_Pr->SiS_UseROM &&
  8569. (!(SiS_Pr->SiS_ROMNew)) &&
  8570. (SiS_Pr->SiS_LCDResInfo != Panel_1280x1024) &&
  8571. (SiS_Pr->SiS_LCDResInfo != Panel_1280x768) &&
  8572. (SiS_Pr->SiS_LCDResInfo != Panel_1280x960) &&
  8573. (SiS_Pr->SiS_LCDResInfo != Panel_1600x1200) &&
  8574. ((romptr = GetLCDromptr(SiS_Pr)))) {
  8575. /* Data for 1280x1024 wrong in 301B BIOS */
  8576. /* Data for 1600x1200 wrong in 301C BIOS */
  8577. delay = ROMAddr[(romptr + index)];
  8578. } else if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  8579. if(IS_SIS740) delay = 0x03;
  8580. else delay = 0x00;
  8581. } else {
  8582. delay = SiS310_LCDDelayCompensation_301[myindex];
  8583. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  8584. if(IS_SIS740) delay = 0x01;
  8585. else if(SiS_Pr->ChipType <= SIS_315PRO) delay = SiS310_LCDDelayCompensation_3xx301LV[myindex];
  8586. else delay = SiS310_LCDDelayCompensation_650301LV[myindex];
  8587. } else if(SiS_Pr->SiS_VBType & VB_SIS301C) {
  8588. if(IS_SIS740) delay = 0x01; /* ? */
  8589. else delay = 0x03;
  8590. if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) delay = 0x00; /* experience */
  8591. } else if(SiS_Pr->SiS_VBType & VB_SIS30xB) {
  8592. if(IS_SIS740) delay = 0x01;
  8593. else delay = SiS310_LCDDelayCompensation_3xx301B[myindex];
  8594. }
  8595. }
  8596. } /* got it from PCI */
  8597. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  8598. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,0x0F,((delay << 4) & 0xf0));
  8599. dochiptest = FALSE;
  8600. }
  8601. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { /* ------------ TV */
  8602. index = GetTVPtrIndex(SiS_Pr);
  8603. if(IS_SIS650 && (SiS_Pr->SiS_VBType & VB_SISLVDS)) {
  8604. if(SiS_IsNotM650orLater(SiS_Pr)) {
  8605. if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
  8606. /* Always use the second pointer on 650; some BIOSes */
  8607. /* still carry old 301 data at the first location */
  8608. /* romptr = SISGETROMW(0x114); */
  8609. /* if(SiS_Pr->SiS_VBType & VB_SIS302LV) */
  8610. romptr = SISGETROMW(0x11a);
  8611. if(!romptr) return;
  8612. delay = ROMAddr[romptr + index];
  8613. } else {
  8614. delay = SiS310_TVDelayCompensation_301B[index];
  8615. }
  8616. } else {
  8617. switch(SiS_Pr->SiS_CustomT) {
  8618. case CUT_COMPAQ1280:
  8619. case CUT_COMPAQ12802:
  8620. case CUT_CLEVO1400:
  8621. case CUT_CLEVO14002:
  8622. delay = 0x02;
  8623. dochiptest = FALSE;
  8624. break;
  8625. case CUT_CLEVO1024:
  8626. case CUT_CLEVO10242:
  8627. delay = 0x03;
  8628. dochiptest = FALSE;
  8629. break;
  8630. default:
  8631. delay = SiS310_TVDelayCompensation_651301LV[index];
  8632. if(SiS_Pr->SiS_VBType & VB_SIS302LV) {
  8633. delay = SiS310_TVDelayCompensation_651302LV[index];
  8634. }
  8635. }
  8636. }
  8637. } else if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
  8638. romptr = GetTVromptr(SiS_Pr);
  8639. if(!romptr) return;
  8640. delay = ROMAddr[romptr + index];
  8641. } else if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  8642. delay = SiS310_TVDelayCompensation_LVDS[index];
  8643. } else {
  8644. delay = SiS310_TVDelayCompensation_301[index];
  8645. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  8646. if(IS_SIS740) {
  8647. delay = SiS310_TVDelayCompensation_740301B[index];
  8648. /* LV: use 301 data? BIOS bug? */
  8649. } else {
  8650. delay = SiS310_TVDelayCompensation_301B[index];
  8651. if(SiS_Pr->SiS_VBType & VB_SIS301C) delay = 0x02;
  8652. }
  8653. }
  8654. }
  8655. if(SiS_LCDAEnabled(SiS_Pr)) {
  8656. delay &= 0x0f;
  8657. dochiptest = FALSE;
  8658. }
  8659. } else return;
  8660. /* Write delay */
  8661. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  8662. if(IS_SIS650 && (SiS_Pr->SiS_VBType & VB_SISLVDS) && dochiptest) {
  8663. temp = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) & 0xf0) >> 4;
  8664. if(temp == 8) { /* 1400x1050 BIOS (COMPAL) */
  8665. delay &= 0x0f;
  8666. delay |= 0xb0;
  8667. } else if(temp == 6) {
  8668. delay &= 0x0f;
  8669. delay |= 0xc0;
  8670. } else if(temp > 7) { /* 1280x1024 BIOS (which one?) */
  8671. delay = 0x35;
  8672. }
  8673. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2D,delay);
  8674. } else {
  8675. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,0xF0,delay);
  8676. }
  8677. } else { /* LVDS */
  8678. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  8679. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,0xF0,delay);
  8680. } else {
  8681. if(IS_SIS650 && (SiS_Pr->SiS_IF_DEF_CH70xx != 0)) {
  8682. delay <<= 4;
  8683. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,0x0F,delay);
  8684. } else {
  8685. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,0xF0,delay);
  8686. }
  8687. }
  8688. }
  8689. }
  8690. static void
  8691. SetAntiFlicker(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  8692. {
  8693. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  8694. unsigned short index,temp,temp1,romptr=0;
  8695. if(SiS_Pr->SiS_TVMode & (TVSetYPbPr750p|TVSetYPbPr525p)) return;
  8696. if(ModeNo<=0x13)
  8697. index = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].VB_StTVFlickerIndex;
  8698. else
  8699. index = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].VB_ExtTVFlickerIndex;
  8700. temp = GetTVPtrIndex(SiS_Pr);
  8701. temp >>= 1; /* 0: NTSC/YPbPr, 1: PAL, 2: HiTV */
  8702. temp1 = temp;
  8703. if(SiS_Pr->SiS_UseROM && (!(SiS_Pr->SiS_ROMNew))) {
  8704. if(SiS_Pr->ChipType >= SIS_661) {
  8705. temp1 = GetOEMTVPtr661(SiS_Pr);
  8706. temp1 >>= 1;
  8707. romptr = SISGETROMW(0x260);
  8708. if(SiS_Pr->ChipType >= SIS_760) {
  8709. romptr = SISGETROMW(0x360);
  8710. }
  8711. } else if(SiS_Pr->ChipType >= SIS_330) {
  8712. romptr = SISGETROMW(0x192);
  8713. } else {
  8714. romptr = SISGETROMW(0x112);
  8715. }
  8716. }
  8717. if(romptr) {
  8718. temp1 <<= 1;
  8719. temp = ROMAddr[romptr + temp1 + index];
  8720. } else {
  8721. temp = SiS310_TVAntiFlick1[temp][index];
  8722. }
  8723. temp <<= 4;
  8724. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x0A,0x8f,temp); /* index 0A D[6:4] */
  8725. }
  8726. static void
  8727. SetEdgeEnhance(struct SiS_Private *SiS_Pr, unsigned short ModeNo,unsigned short ModeIdIndex)
  8728. {
  8729. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  8730. unsigned short index,temp,temp1,romptr=0;
  8731. temp = temp1 = GetTVPtrIndex(SiS_Pr) >> 1; /* 0: NTSC/YPbPr, 1: PAL, 2: HiTV */
  8732. if(ModeNo <= 0x13)
  8733. index = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].VB_StTVEdgeIndex;
  8734. else
  8735. index = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].VB_ExtTVEdgeIndex;
  8736. if(SiS_Pr->SiS_UseROM && (!(SiS_Pr->SiS_ROMNew))) {
  8737. if(SiS_Pr->ChipType >= SIS_661) {
  8738. romptr = SISGETROMW(0x26c);
  8739. if(SiS_Pr->ChipType >= SIS_760) {
  8740. romptr = SISGETROMW(0x36c);
  8741. }
  8742. temp1 = GetOEMTVPtr661(SiS_Pr);
  8743. temp1 >>= 1;
  8744. } else if(SiS_Pr->ChipType >= SIS_330) {
  8745. romptr = SISGETROMW(0x1a4);
  8746. } else {
  8747. romptr = SISGETROMW(0x124);
  8748. }
  8749. }
  8750. if(romptr) {
  8751. temp1 <<= 1;
  8752. temp = ROMAddr[romptr + temp1 + index];
  8753. } else {
  8754. temp = SiS310_TVEdge1[temp][index];
  8755. }
  8756. temp <<= 5;
  8757. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x3A,0x1F,temp); /* index 0A D[7:5] */
  8758. }
  8759. static void
  8760. SetYFilter(struct SiS_Private *SiS_Pr, unsigned short ModeNo,unsigned short ModeIdIndex)
  8761. {
  8762. unsigned short index, temp, i, j;
  8763. if(ModeNo <= 0x13) {
  8764. index = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].VB_StTVYFilterIndex;
  8765. } else {
  8766. index = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].VB_ExtTVYFilterIndex;
  8767. }
  8768. temp = GetTVPtrIndex(SiS_Pr) >> 1; /* 0: NTSC/YPbPr, 1: PAL, 2: HiTV */
  8769. if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) temp = 1; /* NTSC-J uses PAL */
  8770. else if(SiS_Pr->SiS_TVMode & TVSetPALM) temp = 3; /* PAL-M */
  8771. else if(SiS_Pr->SiS_TVMode & TVSetPALN) temp = 4; /* PAL-N */
  8772. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) temp = 1; /* HiVision uses PAL */
  8773. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  8774. for(i=0x35, j=0; i<=0x38; i++, j++) {
  8775. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVYFilter2[temp][index][j]);
  8776. }
  8777. for(i=0x48; i<=0x4A; i++, j++) {
  8778. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVYFilter2[temp][index][j]);
  8779. }
  8780. } else {
  8781. for(i=0x35, j=0; i<=0x38; i++, j++) {
  8782. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVYFilter1[temp][index][j]);
  8783. }
  8784. }
  8785. }
  8786. static void
  8787. SetPhaseIncr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  8788. {
  8789. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  8790. unsigned short index,temp,i,j,resinfo,romptr=0;
  8791. unsigned int lindex;
  8792. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) return;
  8793. /* NTSC-J data not in BIOS, and already set in SetGroup2 */
  8794. if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) return;
  8795. if((SiS_Pr->ChipType >= SIS_661) || SiS_Pr->SiS_ROMNew) {
  8796. lindex = GetOEMTVPtr661_2_OLD(SiS_Pr) & 0xffff;
  8797. lindex <<= 2;
  8798. for(j=0, i=0x31; i<=0x34; i++, j++) {
  8799. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS_TVPhase[lindex + j]);
  8800. }
  8801. return;
  8802. }
  8803. /* PAL-M, PAL-N not in BIOS, and already set in SetGroup2 */
  8804. if(SiS_Pr->SiS_TVMode & (TVSetPALM | TVSetPALN)) return;
  8805. if(ModeNo<=0x13) {
  8806. resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
  8807. } else {
  8808. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  8809. }
  8810. temp = GetTVPtrIndex(SiS_Pr);
  8811. /* 0: NTSC Graphics, 1: NTSC Text, 2: PAL Graphics,
  8812. * 3: PAL Text, 4: HiTV Graphics 5: HiTV Text
  8813. */
  8814. if(SiS_Pr->SiS_UseROM) {
  8815. romptr = SISGETROMW(0x116);
  8816. if(SiS_Pr->ChipType >= SIS_330) {
  8817. romptr = SISGETROMW(0x196);
  8818. }
  8819. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  8820. romptr = SISGETROMW(0x11c);
  8821. if(SiS_Pr->ChipType >= SIS_330) {
  8822. romptr = SISGETROMW(0x19c);
  8823. }
  8824. if((SiS_Pr->SiS_VBInfo & SetInSlaveMode) && (!(SiS_Pr->SiS_TVMode & TVSetTVSimuMode))) {
  8825. romptr = SISGETROMW(0x116);
  8826. if(SiS_Pr->ChipType >= SIS_330) {
  8827. romptr = SISGETROMW(0x196);
  8828. }
  8829. }
  8830. }
  8831. }
  8832. if(romptr) {
  8833. romptr += (temp << 2);
  8834. for(j=0, i=0x31; i<=0x34; i++, j++) {
  8835. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,ROMAddr[romptr + j]);
  8836. }
  8837. } else {
  8838. index = temp % 2;
  8839. temp >>= 1; /* 0:NTSC, 1:PAL, 2:HiTV */
  8840. for(j=0, i=0x31; i<=0x34; i++, j++) {
  8841. if(!(SiS_Pr->SiS_VBType & VB_SIS30xBLV))
  8842. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVPhaseIncr1[temp][index][j]);
  8843. else if((!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) || (SiS_Pr->SiS_TVMode & TVSetTVSimuMode))
  8844. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVPhaseIncr2[temp][index][j]);
  8845. else
  8846. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVPhaseIncr1[temp][index][j]);
  8847. }
  8848. }
  8849. if((SiS_Pr->SiS_VBType & VB_SIS30xBLV) && (!(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision))) {
  8850. if((!(SiS_Pr->SiS_TVMode & (TVSetPAL | TVSetYPbPr525p | TVSetYPbPr750p))) && (ModeNo > 0x13)) {
  8851. if((resinfo == SIS_RI_640x480) ||
  8852. (resinfo == SIS_RI_800x600)) {
  8853. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x31,0x21);
  8854. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x32,0xf0);
  8855. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x33,0xf5);
  8856. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x34,0x7f);
  8857. } else if(resinfo == SIS_RI_1024x768) {
  8858. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x31,0x1e);
  8859. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x32,0x8b);
  8860. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x33,0xfb);
  8861. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x34,0x7b);
  8862. }
  8863. }
  8864. }
  8865. }
  8866. static void
  8867. SetDelayComp661(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
  8868. unsigned short ModeIdIndex, unsigned short RTI)
  8869. {
  8870. unsigned short delay = 0, romptr = 0, index, lcdpdcindex;
  8871. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  8872. if(!(SiS_Pr->SiS_VBInfo & (SetCRT2ToTV | SetCRT2ToLCD | SetCRT2ToLCDA | SetCRT2ToRAMDAC)))
  8873. return;
  8874. /* 1. New ROM: VGA2 and LCD/LCDA-Pass1:1 */
  8875. /* (If a custom mode is used, Pass1:1 is always set; hence we do this:) */
  8876. if(SiS_Pr->SiS_ROMNew) {
  8877. if((SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) ||
  8878. ((SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) &&
  8879. (SiS_Pr->SiS_LCDInfo & LCDPass11))) {
  8880. index = 25;
  8881. if(SiS_Pr->UseCustomMode) {
  8882. index = SiS_Pr->CSRClock;
  8883. } else if(ModeNo > 0x13) {
  8884. index = SiS_GetVCLK2Ptr(SiS_Pr,ModeNo,ModeIdIndex,RTI);
  8885. index = SiS_Pr->SiS_VCLKData[index].CLOCK;
  8886. }
  8887. if(index < 25) index = 25;
  8888. index = ((index / 25) - 1) << 1;
  8889. if((ROMAddr[0x5b] & 0x80) || (SiS_Pr->SiS_VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD))) {
  8890. index++;
  8891. }
  8892. romptr = SISGETROMW(0x104);
  8893. delay = ROMAddr[romptr + index];
  8894. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD)) {
  8895. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0xf0,((delay >> 1) & 0x0f));
  8896. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x35,0x7f,((delay & 0x01) << 7));
  8897. } else {
  8898. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0x0f,((delay << 3) & 0xf0));
  8899. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x20,0xbf,((delay & 0x01) << 6));
  8900. }
  8901. return;
  8902. }
  8903. }
  8904. /* 2. Old ROM: VGA2 and LCD/LCDA-Pass 1:1 */
  8905. if(SiS_Pr->UseCustomMode) delay = 0x04;
  8906. else if(ModeNo <= 0x13) delay = 0x04;
  8907. else delay = (SiS_Pr->SiS_RefIndex[RTI].Ext_PDC >> 4);
  8908. delay |= (delay << 8);
  8909. if(SiS_Pr->ChipType >= XGI_20) {
  8910. delay = 0x0606;
  8911. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  8912. delay = 0x0404;
  8913. if(SiS_Pr->SiS_XGIROM) {
  8914. index = GetTVPtrIndex(SiS_Pr);
  8915. if((romptr = SISGETROMW(0x35e))) {
  8916. delay = (ROMAddr[romptr + index] & 0x0f) << 1;
  8917. delay |= (delay << 8);
  8918. }
  8919. }
  8920. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  8921. if(SiS_Pr->ChipType == XGI_40 && SiS_Pr->ChipRevision == 0x02) {
  8922. delay -= 0x0404;
  8923. }
  8924. }
  8925. }
  8926. } else if(SiS_Pr->ChipType >= SIS_340) {
  8927. delay = 0x0606;
  8928. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  8929. delay = 0x0404;
  8930. }
  8931. /* TODO (eventually) */
  8932. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  8933. /* 3. TV */
  8934. index = GetOEMTVPtr661(SiS_Pr);
  8935. if(SiS_Pr->SiS_ROMNew) {
  8936. romptr = SISGETROMW(0x106);
  8937. if(SiS_Pr->SiS_VBType & VB_UMC) romptr += 12;
  8938. delay = ROMAddr[romptr + index];
  8939. } else {
  8940. delay = 0x04;
  8941. if(index > 3) delay = 0;
  8942. }
  8943. } else if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  8944. /* 4. LCD, LCDA (for new ROM only LV and non-Pass 1:1) */
  8945. if( (SiS_Pr->SiS_LCDResInfo != Panel_Custom) &&
  8946. ((romptr = GetLCDStructPtr661_2(SiS_Pr))) ) {
  8947. lcdpdcindex = (SiS_Pr->SiS_VBType & VB_UMC) ? 14 : 12;
  8948. /* For LVDS (and sometimes TMDS), the BIOS must know about the correct value */
  8949. delay = ROMAddr[romptr + lcdpdcindex + 1]; /* LCD */
  8950. delay |= (ROMAddr[romptr + lcdpdcindex] << 8); /* LCDA */
  8951. } else {
  8952. /* TMDS: Set our own, since BIOS has no idea */
  8953. /* (This is done on >=661 only, since <661 is calling this only for LVDS) */
  8954. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  8955. switch(SiS_Pr->SiS_LCDResInfo) {
  8956. case Panel_1024x768: delay = 0x0008; break;
  8957. case Panel_1280x720: delay = 0x0004; break;
  8958. case Panel_1280x768:
  8959. case Panel_1280x768_2:delay = 0x0004; break;
  8960. case Panel_1280x800:
  8961. case Panel_1280x800_2:delay = 0x0004; break; /* Verified for 1280x800 */
  8962. case Panel_1280x854: delay = 0x0004; break; /* FIXME */
  8963. case Panel_1280x1024: delay = 0x1e04; break;
  8964. case Panel_1400x1050: delay = 0x0004; break;
  8965. case Panel_1600x1200: delay = 0x0400; break;
  8966. case Panel_1680x1050: delay = 0x0e04; break;
  8967. default:
  8968. if((SiS_Pr->PanelXRes <= 1024) && (SiS_Pr->PanelYRes <= 768)) {
  8969. delay = 0x0008;
  8970. } else if((SiS_Pr->PanelXRes == 1280) && (SiS_Pr->PanelYRes == 1024)) {
  8971. delay = 0x1e04;
  8972. } else if((SiS_Pr->PanelXRes <= 1400) && (SiS_Pr->PanelYRes <= 1050)) {
  8973. delay = 0x0004;
  8974. } else if((SiS_Pr->PanelXRes <= 1600) && (SiS_Pr->PanelYRes <= 1200)) {
  8975. delay = 0x0400;
  8976. } else
  8977. delay = 0x0e04;
  8978. break;
  8979. }
  8980. }
  8981. /* Override by detected or user-set values */
  8982. /* (but only if, for some reason, we can't read value from BIOS) */
  8983. if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && (SiS_Pr->PDC != -1)) {
  8984. delay = SiS_Pr->PDC & 0x1f;
  8985. }
  8986. if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) && (SiS_Pr->PDCA != -1)) {
  8987. delay = (SiS_Pr->PDCA & 0x1f) << 8;
  8988. }
  8989. }
  8990. }
  8991. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  8992. delay >>= 8;
  8993. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0x0f,((delay << 3) & 0xf0));
  8994. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x20,0xbf,((delay & 0x01) << 6));
  8995. } else {
  8996. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0xf0,((delay >> 1) & 0x0f));
  8997. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x35,0x7f,((delay & 0x01) << 7));
  8998. }
  8999. }
  9000. static void
  9001. SetCRT2SyncDither661(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short RTI)
  9002. {
  9003. unsigned short infoflag;
  9004. unsigned char temp;
  9005. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  9006. if(ModeNo <= 0x13) {
  9007. infoflag = SiS_GetRegByte(SiS_Pr->SiS_P3ca+2);
  9008. } else if(SiS_Pr->UseCustomMode) {
  9009. infoflag = SiS_Pr->CInfoFlag;
  9010. } else {
  9011. infoflag = SiS_Pr->SiS_RefIndex[RTI].Ext_InfoFlag;
  9012. }
  9013. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  9014. infoflag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x37); /* No longer check D5 */
  9015. }
  9016. infoflag &= 0xc0;
  9017. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  9018. temp = (infoflag >> 6) | 0x0c;
  9019. if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) {
  9020. temp ^= 0x04;
  9021. if(SiS_Pr->SiS_ModeType >= Mode24Bpp) temp |= 0x10;
  9022. }
  9023. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1a,0xe0,temp);
  9024. } else {
  9025. temp = 0x30;
  9026. if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) temp = 0x20;
  9027. temp |= infoflag;
  9028. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0f,temp);
  9029. temp = 0;
  9030. if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) {
  9031. if(SiS_Pr->SiS_ModeType >= Mode24Bpp) temp |= 0x80;
  9032. }
  9033. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x1a,0x7f,temp);
  9034. }
  9035. }
  9036. }
  9037. static void
  9038. SetPanelParms661(struct SiS_Private *SiS_Pr)
  9039. {
  9040. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  9041. unsigned short romptr, temp1, temp2;
  9042. if(SiS_Pr->SiS_VBType & (VB_SISLVDS | VB_SIS30xC)) {
  9043. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x24,0x0f);
  9044. }
  9045. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  9046. if(SiS_Pr->LVDSHL != -1) {
  9047. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,0xfc,SiS_Pr->LVDSHL);
  9048. }
  9049. }
  9050. if(SiS_Pr->SiS_ROMNew) {
  9051. if((romptr = GetLCDStructPtr661_2(SiS_Pr))) {
  9052. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  9053. temp1 = (ROMAddr[romptr] & 0x03) | 0x0c;
  9054. temp2 = 0xfc;
  9055. if(SiS_Pr->LVDSHL != -1) {
  9056. temp1 &= 0xfc;
  9057. temp2 = 0xf3;
  9058. }
  9059. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,temp2,temp1);
  9060. }
  9061. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  9062. temp1 = (ROMAddr[romptr + 1] & 0x80) >> 1;
  9063. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x0d,0xbf,temp1);
  9064. }
  9065. }
  9066. }
  9067. }
  9068. static void
  9069. SiS_OEM310Setting(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex, unsigned short RRTI)
  9070. {
  9071. if((SiS_Pr->SiS_ROMNew) && (SiS_Pr->SiS_VBType & VB_SISLVDS)) {
  9072. SetDelayComp661(SiS_Pr, ModeNo, ModeIdIndex, RRTI);
  9073. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  9074. SetCRT2SyncDither661(SiS_Pr, ModeNo, RRTI);
  9075. SetPanelParms661(SiS_Pr);
  9076. }
  9077. } else {
  9078. SetDelayComp(SiS_Pr,ModeNo);
  9079. }
  9080. if((SiS_Pr->SiS_VBType & VB_SISVB) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
  9081. SetAntiFlicker(SiS_Pr,ModeNo,ModeIdIndex);
  9082. SetPhaseIncr(SiS_Pr,ModeNo,ModeIdIndex);
  9083. SetYFilter(SiS_Pr,ModeNo,ModeIdIndex);
  9084. if(SiS_Pr->SiS_VBType & VB_SIS301) {
  9085. SetEdgeEnhance(SiS_Pr,ModeNo,ModeIdIndex);
  9086. }
  9087. }
  9088. }
  9089. static void
  9090. SiS_OEM661Setting(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
  9091. unsigned short ModeIdIndex, unsigned short RRTI)
  9092. {
  9093. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  9094. SetDelayComp661(SiS_Pr, ModeNo, ModeIdIndex, RRTI);
  9095. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  9096. SetCRT2SyncDither661(SiS_Pr, ModeNo, RRTI);
  9097. SetPanelParms661(SiS_Pr);
  9098. }
  9099. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  9100. SetPhaseIncr(SiS_Pr, ModeNo, ModeIdIndex);
  9101. SetYFilter(SiS_Pr, ModeNo, ModeIdIndex);
  9102. SetAntiFlicker(SiS_Pr, ModeNo, ModeIdIndex);
  9103. if(SiS_Pr->SiS_VBType & VB_SIS301) {
  9104. SetEdgeEnhance(SiS_Pr, ModeNo, ModeIdIndex);
  9105. }
  9106. }
  9107. }
  9108. }
  9109. /* FinalizeLCD
  9110. * This finalizes some CRT2 registers for the very panel used.
  9111. * If we have a backup if these registers, we use it; otherwise
  9112. * we set the register according to most BIOSes. However, this
  9113. * function looks quite different in every BIOS, so you better
  9114. * pray that we have a backup...
  9115. */
  9116. static void
  9117. SiS_FinalizeLCD(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  9118. {
  9119. unsigned short tempcl,tempch,tempbl,tempbh,tempbx,tempax,temp;
  9120. unsigned short resinfo,modeflag;
  9121. if(!(SiS_Pr->SiS_VBType & VB_SISLVDS)) return;
  9122. if(SiS_Pr->SiS_ROMNew) return;
  9123. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  9124. if(SiS_Pr->LVDSHL != -1) {
  9125. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,0xfc,SiS_Pr->LVDSHL);
  9126. }
  9127. }
  9128. if(SiS_Pr->SiS_LCDResInfo == Panel_Custom) return;
  9129. if(SiS_Pr->UseCustomMode) return;
  9130. switch(SiS_Pr->SiS_CustomT) {
  9131. case CUT_COMPAQ1280:
  9132. case CUT_COMPAQ12802:
  9133. case CUT_CLEVO1400:
  9134. case CUT_CLEVO14002:
  9135. return;
  9136. }
  9137. if(ModeNo <= 0x13) {
  9138. resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
  9139. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  9140. } else {
  9141. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  9142. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  9143. }
  9144. if(IS_SIS650) {
  9145. if(!(SiS_GetReg(SiS_Pr->SiS_P3d4, 0x5f) & 0xf0)) {
  9146. if(SiS_Pr->SiS_CustomT == CUT_CLEVO1024) {
  9147. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1e,0x02);
  9148. } else {
  9149. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1e,0x03);
  9150. }
  9151. }
  9152. }
  9153. if(SiS_Pr->SiS_CustomT == CUT_CLEVO1024) {
  9154. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  9155. /* Maybe all panels? */
  9156. if(SiS_Pr->LVDSHL == -1) {
  9157. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,0xfc,0x01);
  9158. }
  9159. return;
  9160. }
  9161. }
  9162. if(SiS_Pr->SiS_CustomT == CUT_CLEVO10242) {
  9163. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  9164. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  9165. if(SiS_Pr->LVDSHL == -1) {
  9166. /* Maybe all panels? */
  9167. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,0xfc,0x01);
  9168. }
  9169. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  9170. tempch = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4;
  9171. if(tempch == 3) {
  9172. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x02);
  9173. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,0x25);
  9174. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1c,0x00);
  9175. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1d,0x1b);
  9176. }
  9177. }
  9178. return;
  9179. }
  9180. }
  9181. }
  9182. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  9183. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  9184. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  9185. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2a,0x00);
  9186. #ifdef SET_EMI
  9187. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
  9188. #endif
  9189. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x34,0x10);
  9190. }
  9191. } else if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) {
  9192. if(SiS_Pr->LVDSHL == -1) {
  9193. /* Maybe ACER only? */
  9194. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,0xfc,0x01);
  9195. }
  9196. }
  9197. tempch = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4;
  9198. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  9199. if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) {
  9200. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1f,0x76);
  9201. } else if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  9202. if(tempch == 0x03) {
  9203. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x02);
  9204. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,0x25);
  9205. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1c,0x00);
  9206. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1d,0x1b);
  9207. }
  9208. if((SiS_Pr->Backup == TRUE) && (SiS_Pr->Backup_Mode == ModeNo)) {
  9209. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x14,SiS_Pr->Backup_14);
  9210. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x15,SiS_Pr->Backup_15);
  9211. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x16,SiS_Pr->Backup_16);
  9212. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x17,SiS_Pr->Backup_17);
  9213. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,SiS_Pr->Backup_18);
  9214. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x19,SiS_Pr->Backup_19);
  9215. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1a,SiS_Pr->Backup_1a);
  9216. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,SiS_Pr->Backup_1b);
  9217. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1c,SiS_Pr->Backup_1c);
  9218. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1d,SiS_Pr->Backup_1d);
  9219. } else if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) { /* 1.10.8w */
  9220. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x14,0x90);
  9221. if(ModeNo <= 0x13) {
  9222. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x11);
  9223. if((resinfo == 0) || (resinfo == 2)) return;
  9224. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x18);
  9225. if((resinfo == 1) || (resinfo == 3)) return;
  9226. }
  9227. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x02);
  9228. if((ModeNo > 0x13) && (resinfo == SIS_RI_1024x768)) {
  9229. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x02); /* 1.10.7u */
  9230. #if 0
  9231. tempbx = 806; /* 0x326 */ /* other older BIOSes */
  9232. tempbx--;
  9233. temp = tempbx & 0xff;
  9234. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,temp);
  9235. temp = (tempbx >> 8) & 0x03;
  9236. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x1d,0xf8,temp);
  9237. #endif
  9238. }
  9239. } else if(ModeNo <= 0x13) {
  9240. if(ModeNo <= 1) {
  9241. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x70);
  9242. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x19,0xff);
  9243. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,0x48);
  9244. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1d,0x12);
  9245. }
  9246. if(!(modeflag & HalfDCLK)) {
  9247. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x14,0x20);
  9248. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x15,0x1a);
  9249. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x16,0x28);
  9250. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x17,0x00);
  9251. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x4c);
  9252. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x19,0xdc);
  9253. if(ModeNo == 0x12) {
  9254. switch(tempch) {
  9255. case 0:
  9256. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x95);
  9257. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x19,0xdc);
  9258. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1a,0x10);
  9259. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,0x95);
  9260. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1c,0x48);
  9261. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1d,0x12);
  9262. break;
  9263. case 2:
  9264. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x95);
  9265. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,0x48);
  9266. break;
  9267. case 3:
  9268. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,0x95);
  9269. break;
  9270. }
  9271. }
  9272. }
  9273. }
  9274. }
  9275. } else {
  9276. tempcl = tempbh = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x01);
  9277. tempcl &= 0x0f;
  9278. tempbh &= 0x70;
  9279. tempbh >>= 4;
  9280. tempbl = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x04);
  9281. tempbx = (tempbh << 8) | tempbl;
  9282. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  9283. if((resinfo == SIS_RI_1024x768) || (!(SiS_Pr->SiS_LCDInfo & DontExpandLCD))) {
  9284. if(SiS_Pr->SiS_SetFlag & LCDVESATiming) {
  9285. tempbx = 770;
  9286. } else {
  9287. if(tempbx > 770) tempbx = 770;
  9288. if(SiS_Pr->SiS_VGAVDE < 600) {
  9289. tempax = 768 - SiS_Pr->SiS_VGAVDE;
  9290. tempax >>= 4; /* 1.10.7w; 1.10.6s: 3; */
  9291. if(SiS_Pr->SiS_VGAVDE <= 480) tempax >>= 4; /* 1.10.7w; 1.10.6s: < 480; >>=1; */
  9292. tempbx -= tempax;
  9293. }
  9294. }
  9295. } else return;
  9296. }
  9297. temp = tempbx & 0xff;
  9298. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,temp);
  9299. temp = ((tempbx & 0xff00) >> 4) | tempcl;
  9300. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x01,0x80,temp);
  9301. }
  9302. }
  9303. }
  9304. #endif
  9305. /* ================= SiS 300 O.E.M. ================== */
  9306. #ifdef SIS300
  9307. static void
  9308. SetOEMLCDData2(struct SiS_Private *SiS_Pr, unsigned short ModeNo,unsigned short ModeIdIndex,
  9309. unsigned short RefTabIndex)
  9310. {
  9311. unsigned short crt2crtc=0, modeflag, myindex=0;
  9312. unsigned char temp;
  9313. int i;
  9314. if(ModeNo <= 0x13) {
  9315. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  9316. crt2crtc = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  9317. } else {
  9318. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  9319. crt2crtc = SiS_Pr->SiS_RefIndex[RefTabIndex].Ext_CRT2CRTC;
  9320. }
  9321. crt2crtc &= 0x3f;
  9322. if(SiS_Pr->SiS_CustomT == CUT_BARCO1024) {
  9323. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xdf);
  9324. }
  9325. if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) {
  9326. if(modeflag & HalfDCLK) myindex = 1;
  9327. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  9328. for(i=0; i<7; i++) {
  9329. if(barco_p1[myindex][crt2crtc][i][0]) {
  9330. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,
  9331. barco_p1[myindex][crt2crtc][i][0],
  9332. barco_p1[myindex][crt2crtc][i][2],
  9333. barco_p1[myindex][crt2crtc][i][1]);
  9334. }
  9335. }
  9336. }
  9337. temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00);
  9338. if(temp & 0x80) {
  9339. temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x18);
  9340. temp++;
  9341. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,temp);
  9342. }
  9343. }
  9344. }
  9345. static unsigned short
  9346. GetOEMLCDPtr(struct SiS_Private *SiS_Pr, int Flag)
  9347. {
  9348. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  9349. unsigned short tempbx=0,romptr=0;
  9350. static const unsigned char customtable300[] = {
  9351. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  9352. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
  9353. };
  9354. static const unsigned char customtable630[] = {
  9355. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  9356. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
  9357. };
  9358. if(SiS_Pr->ChipType == SIS_300) {
  9359. tempbx = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) & 0x0f;
  9360. if(SiS_Pr->SiS_VBType & VB_SIS301) tempbx &= 0x07;
  9361. tempbx -= 2;
  9362. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) tempbx += 4;
  9363. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  9364. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx += 3;
  9365. }
  9366. if(SiS_Pr->SiS_UseROM) {
  9367. if(ROMAddr[0x235] & 0x80) {
  9368. tempbx = SiS_Pr->SiS_LCDTypeInfo;
  9369. if(Flag) {
  9370. romptr = SISGETROMW(0x255);
  9371. if(romptr) tempbx = ROMAddr[romptr + SiS_Pr->SiS_LCDTypeInfo];
  9372. else tempbx = customtable300[SiS_Pr->SiS_LCDTypeInfo];
  9373. if(tempbx == 0xFF) return 0xFFFF;
  9374. }
  9375. tempbx <<= 1;
  9376. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) tempbx++;
  9377. }
  9378. }
  9379. } else {
  9380. if(Flag) {
  9381. if(SiS_Pr->SiS_UseROM) {
  9382. romptr = SISGETROMW(0x255);
  9383. if(romptr) tempbx = ROMAddr[romptr + SiS_Pr->SiS_LCDTypeInfo];
  9384. else tempbx = 0xff;
  9385. } else {
  9386. tempbx = customtable630[SiS_Pr->SiS_LCDTypeInfo];
  9387. }
  9388. if(tempbx == 0xFF) return 0xFFFF;
  9389. tempbx <<= 2;
  9390. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) tempbx += 2;
  9391. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++;
  9392. return tempbx;
  9393. }
  9394. tempbx = SiS_Pr->SiS_LCDTypeInfo << 2;
  9395. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) tempbx += 2;
  9396. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++;
  9397. }
  9398. return tempbx;
  9399. }
  9400. static void
  9401. SetOEMLCDDelay(struct SiS_Private *SiS_Pr, unsigned short ModeNo,unsigned short ModeIdIndex)
  9402. {
  9403. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  9404. unsigned short index,temp,romptr=0;
  9405. if(SiS_Pr->SiS_LCDResInfo == Panel_Custom) return;
  9406. if(SiS_Pr->SiS_UseROM) {
  9407. if(!(ROMAddr[0x237] & 0x01)) return;
  9408. if(!(ROMAddr[0x237] & 0x02)) return;
  9409. romptr = SISGETROMW(0x24b);
  9410. }
  9411. /* The Panel Compensation Delay should be set according to tables
  9412. * here. Unfortunately, various BIOS versions don't care about
  9413. * a uniform way using eg. ROM byte 0x220, but use different
  9414. * hard coded delays (0x04, 0x20, 0x18) in SetGroup1().
  9415. * Thus we don't set this if the user selected a custom pdc or if
  9416. * we otherwise detected a valid pdc.
  9417. */
  9418. if(SiS_Pr->PDC != -1) return;
  9419. temp = GetOEMLCDPtr(SiS_Pr, 0);
  9420. if(SiS_Pr->UseCustomMode)
  9421. index = 0;
  9422. else
  9423. index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].VB_LCDDelayIndex;
  9424. if(SiS_Pr->ChipType != SIS_300) {
  9425. if(romptr) {
  9426. romptr += (temp * 2);
  9427. romptr = SISGETROMW(romptr);
  9428. romptr += index;
  9429. temp = ROMAddr[romptr];
  9430. } else {
  9431. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  9432. temp = SiS300_OEMLCDDelay2[temp][index];
  9433. } else {
  9434. temp = SiS300_OEMLCDDelay3[temp][index];
  9435. }
  9436. }
  9437. } else {
  9438. if(SiS_Pr->SiS_UseROM && (ROMAddr[0x235] & 0x80)) {
  9439. if(romptr) {
  9440. romptr += (temp * 2);
  9441. romptr = SISGETROMW(romptr);
  9442. romptr += index;
  9443. temp = ROMAddr[romptr];
  9444. } else {
  9445. temp = SiS300_OEMLCDDelay5[temp][index];
  9446. }
  9447. } else {
  9448. if(SiS_Pr->SiS_UseROM) {
  9449. romptr = ROMAddr[0x249] | (ROMAddr[0x24a] << 8);
  9450. if(romptr) {
  9451. romptr += (temp * 2);
  9452. romptr = SISGETROMW(romptr);
  9453. romptr += index;
  9454. temp = ROMAddr[romptr];
  9455. } else {
  9456. temp = SiS300_OEMLCDDelay4[temp][index];
  9457. }
  9458. } else {
  9459. temp = SiS300_OEMLCDDelay4[temp][index];
  9460. }
  9461. }
  9462. }
  9463. temp &= 0x3c;
  9464. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,~0x3C,temp); /* index 0A D[6:4] */
  9465. }
  9466. static void
  9467. SetOEMLCDData(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  9468. {
  9469. #if 0 /* Unfinished; Data table missing */
  9470. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  9471. unsigned short index,temp;
  9472. if((SiS_Pr->SiS_UseROM) {
  9473. if(!(ROMAddr[0x237] & 0x01)) return;
  9474. if(!(ROMAddr[0x237] & 0x04)) return;
  9475. /* No rom pointer in BIOS header! */
  9476. }
  9477. temp = GetOEMLCDPtr(SiS_Pr, 1);
  9478. if(temp == 0xFFFF) return;
  9479. index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex]._VB_LCDHIndex;
  9480. for(i=0x14, j=0; i<=0x17; i++, j++) {
  9481. SiS_SetReg(SiS_Pr->SiS_Part1Port,i,SiS300_LCDHData[temp][index][j]);
  9482. }
  9483. SiS_SetRegANDOR(SiS_SiS_Part1Port,0x1a, 0xf8, (SiS300_LCDHData[temp][index][j] & 0x07));
  9484. index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex]._VB_LCDVIndex;
  9485. SiS_SetReg(SiS_SiS_Part1Port,0x18, SiS300_LCDVData[temp][index][0]);
  9486. SiS_SetRegANDOR(SiS_SiS_Part1Port,0x19, 0xF0, SiS300_LCDVData[temp][index][1]);
  9487. SiS_SetRegANDOR(SiS_SiS_Part1Port,0x1A, 0xC7, (SiS300_LCDVData[temp][index][2] & 0x38));
  9488. for(i=0x1b, j=3; i<=0x1d; i++, j++) {
  9489. SiS_SetReg(SiS_Pr->SiS_Part1Port,i,SiS300_LCDVData[temp][index][j]);
  9490. }
  9491. #endif
  9492. }
  9493. static unsigned short
  9494. GetOEMTVPtr(struct SiS_Private *SiS_Pr)
  9495. {
  9496. unsigned short index;
  9497. index = 0;
  9498. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) index += 4;
  9499. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  9500. if(SiS_Pr->SiS_VBInfo & SetCRT2ToSCART) index += 2;
  9501. else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) index += 3;
  9502. else if(SiS_Pr->SiS_TVMode & TVSetPAL) index += 1;
  9503. } else {
  9504. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) index += 2;
  9505. if(SiS_Pr->SiS_TVMode & TVSetPAL) index += 1;
  9506. }
  9507. return index;
  9508. }
  9509. static void
  9510. SetOEMTVDelay(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  9511. {
  9512. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  9513. unsigned short index,temp,romptr=0;
  9514. if(SiS_Pr->SiS_UseROM) {
  9515. if(!(ROMAddr[0x238] & 0x01)) return;
  9516. if(!(ROMAddr[0x238] & 0x02)) return;
  9517. romptr = SISGETROMW(0x241);
  9518. }
  9519. temp = GetOEMTVPtr(SiS_Pr);
  9520. index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].VB_TVDelayIndex;
  9521. if(romptr) {
  9522. romptr += (temp * 2);
  9523. romptr = SISGETROMW(romptr);
  9524. romptr += index;
  9525. temp = ROMAddr[romptr];
  9526. } else {
  9527. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  9528. temp = SiS300_OEMTVDelay301[temp][index];
  9529. } else {
  9530. temp = SiS300_OEMTVDelayLVDS[temp][index];
  9531. }
  9532. }
  9533. temp &= 0x3c;
  9534. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,~0x3C,temp);
  9535. }
  9536. static void
  9537. SetOEMAntiFlicker(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  9538. {
  9539. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  9540. unsigned short index,temp,romptr=0;
  9541. if(SiS_Pr->SiS_UseROM) {
  9542. if(!(ROMAddr[0x238] & 0x01)) return;
  9543. if(!(ROMAddr[0x238] & 0x04)) return;
  9544. romptr = SISGETROMW(0x243);
  9545. }
  9546. temp = GetOEMTVPtr(SiS_Pr);
  9547. index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].VB_TVFlickerIndex;
  9548. if(romptr) {
  9549. romptr += (temp * 2);
  9550. romptr = SISGETROMW(romptr);
  9551. romptr += index;
  9552. temp = ROMAddr[romptr];
  9553. } else {
  9554. temp = SiS300_OEMTVFlicker[temp][index];
  9555. }
  9556. temp &= 0x70;
  9557. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x0A,0x8F,temp);
  9558. }
  9559. static void
  9560. SetOEMPhaseIncr(struct SiS_Private *SiS_Pr, unsigned short ModeNo,unsigned short ModeIdIndex)
  9561. {
  9562. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  9563. unsigned short index,i,j,temp,romptr=0;
  9564. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) return;
  9565. if(SiS_Pr->SiS_TVMode & (TVSetNTSC1024 | TVSetNTSCJ | TVSetPALM | TVSetPALN)) return;
  9566. if(SiS_Pr->SiS_UseROM) {
  9567. if(!(ROMAddr[0x238] & 0x01)) return;
  9568. if(!(ROMAddr[0x238] & 0x08)) return;
  9569. romptr = SISGETROMW(0x245);
  9570. }
  9571. temp = GetOEMTVPtr(SiS_Pr);
  9572. index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].VB_TVPhaseIndex;
  9573. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  9574. for(i=0x31, j=0; i<=0x34; i++, j++) {
  9575. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS300_Phase2[temp][index][j]);
  9576. }
  9577. } else {
  9578. if(romptr) {
  9579. romptr += (temp * 2);
  9580. romptr = SISGETROMW(romptr);
  9581. romptr += (index * 4);
  9582. for(i=0x31, j=0; i<=0x34; i++, j++) {
  9583. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,ROMAddr[romptr + j]);
  9584. }
  9585. } else {
  9586. for(i=0x31, j=0; i<=0x34; i++, j++) {
  9587. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS300_Phase1[temp][index][j]);
  9588. }
  9589. }
  9590. }
  9591. }
  9592. static void
  9593. SetOEMYFilter(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  9594. {
  9595. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  9596. unsigned short index,temp,i,j,romptr=0;
  9597. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToSCART | SetCRT2ToHiVision | SetCRT2ToYPbPr525750)) return;
  9598. if(SiS_Pr->SiS_UseROM) {
  9599. if(!(ROMAddr[0x238] & 0x01)) return;
  9600. if(!(ROMAddr[0x238] & 0x10)) return;
  9601. romptr = SISGETROMW(0x247);
  9602. }
  9603. temp = GetOEMTVPtr(SiS_Pr);
  9604. if(SiS_Pr->SiS_TVMode & TVSetPALM) temp = 8;
  9605. else if(SiS_Pr->SiS_TVMode & TVSetPALN) temp = 9;
  9606. /* NTSCJ uses NTSC filters */
  9607. index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].VB_TVYFilterIndex;
  9608. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  9609. for(i=0x35, j=0; i<=0x38; i++, j++) {
  9610. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS300_Filter2[temp][index][j]);
  9611. }
  9612. for(i=0x48; i<=0x4A; i++, j++) {
  9613. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS300_Filter2[temp][index][j]);
  9614. }
  9615. } else {
  9616. if((romptr) && (!(SiS_Pr->SiS_TVMode & (TVSetPALM|TVSetPALN)))) {
  9617. romptr += (temp * 2);
  9618. romptr = SISGETROMW(romptr);
  9619. romptr += (index * 4);
  9620. for(i=0x35, j=0; i<=0x38; i++, j++) {
  9621. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,ROMAddr[romptr + j]);
  9622. }
  9623. } else {
  9624. for(i=0x35, j=0; i<=0x38; i++, j++) {
  9625. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS300_Filter1[temp][index][j]);
  9626. }
  9627. }
  9628. }
  9629. }
  9630. static unsigned short
  9631. SiS_SearchVBModeID(struct SiS_Private *SiS_Pr, unsigned short *ModeNo)
  9632. {
  9633. unsigned short ModeIdIndex;
  9634. unsigned char VGAINFO = SiS_Pr->SiS_VGAINFO;
  9635. if(*ModeNo <= 5) *ModeNo |= 1;
  9636. for(ModeIdIndex=0; ; ModeIdIndex++) {
  9637. if(SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].ModeID == *ModeNo) break;
  9638. if(SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].ModeID == 0xFF) return 0;
  9639. }
  9640. if(*ModeNo != 0x07) {
  9641. if(*ModeNo > 0x03) return ModeIdIndex;
  9642. if(VGAINFO & 0x80) return ModeIdIndex;
  9643. ModeIdIndex++;
  9644. }
  9645. if(VGAINFO & 0x10) ModeIdIndex++; /* 400 lines */
  9646. /* else 350 lines */
  9647. return ModeIdIndex;
  9648. }
  9649. static void
  9650. SiS_OEM300Setting(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  9651. unsigned short RefTableIndex)
  9652. {
  9653. unsigned short OEMModeIdIndex = 0;
  9654. if(!SiS_Pr->UseCustomMode) {
  9655. OEMModeIdIndex = SiS_SearchVBModeID(SiS_Pr,&ModeNo);
  9656. if(!(OEMModeIdIndex)) return;
  9657. }
  9658. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  9659. SetOEMLCDDelay(SiS_Pr, ModeNo, OEMModeIdIndex);
  9660. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  9661. SetOEMLCDData(SiS_Pr, ModeNo, OEMModeIdIndex);
  9662. }
  9663. }
  9664. if(SiS_Pr->UseCustomMode) return;
  9665. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  9666. SetOEMTVDelay(SiS_Pr, ModeNo,OEMModeIdIndex);
  9667. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  9668. SetOEMAntiFlicker(SiS_Pr, ModeNo, OEMModeIdIndex);
  9669. SetOEMPhaseIncr(SiS_Pr, ModeNo, OEMModeIdIndex);
  9670. SetOEMYFilter(SiS_Pr, ModeNo, OEMModeIdIndex);
  9671. }
  9672. }
  9673. }
  9674. #endif