init301.c 351 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380
  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. #if 1
  60. #define SET_EMI /* 302LV/ELV: Set EMI values */
  61. #endif
  62. #if 1
  63. #define SET_PWD /* 301/302LV: Set PWD */
  64. #endif
  65. #define COMPAL_HACK /* Needed for Compal 1400x1050 (EMI) */
  66. #define COMPAQ_HACK /* Needed for Inventec/Compaq 1280x1024 (EMI) */
  67. #define ASUS_HACK /* Needed for Asus A2H 1024x768 (EMI) */
  68. #include "init301.h"
  69. #ifdef CONFIG_FB_SIS_300
  70. #include "oem300.h"
  71. #endif
  72. #ifdef CONFIG_FB_SIS_315
  73. #include "oem310.h"
  74. #endif
  75. #define SiS_I2CDELAY 1000
  76. #define SiS_I2CDELAYSHORT 150
  77. static const unsigned char SiS_YPbPrTable[3][64] = {
  78. {
  79. 0x17,0x1d,0x03,0x09,0x05,0x06,0x0c,0x0c,
  80. 0x94,0x49,0x01,0x0a,0x06,0x0d,0x04,0x0a,
  81. 0x06,0x14,0x0d,0x04,0x0a,0x00,0x85,0x1b,
  82. 0x0c,0x50,0x00,0x97,0x00,0xda,0x4a,0x17,
  83. 0x7d,0x05,0x4b,0x00,0x00,0xe2,0x00,0x02,
  84. 0x03,0x0a,0x65,0x9d /*0x8d*/,0x08,0x92,0x8f,0x40,
  85. 0x60,0x80,0x14,0x90,0x8c,0x60,0x14,0x53 /*0x50*/,
  86. 0x00,0x40,0x44,0x00,0xdb,0x02,0x3b,0x00
  87. },
  88. {
  89. 0x33,0x06,0x06,0x09,0x0b,0x0c,0x0c,0x0c,
  90. 0x98,0x0a,0x01,0x0d,0x06,0x0d,0x04,0x0a,
  91. 0x06,0x14,0x0d,0x04,0x0a,0x00,0x85,0x3f,
  92. 0x0c,0x50,0xb2,0x9f,0x16,0x59,0x4f,0x13,
  93. 0xad,0x11,0xad,0x1d,0x40,0x8a,0x3d,0xb8,
  94. 0x51,0x5e,0x60,0x49,0x7d,0x92,0x0f,0x40,
  95. 0x60,0x80,0x14,0x90,0x8c,0x60,0x14,0x4e,
  96. 0x43,0x41,0x11,0x00,0xfc,0xff,0x32,0x00
  97. },
  98. {
  99. #if 0 /* OK, but sticks to left edge */
  100. 0x13,0x1d,0xe8,0x09,0x09,0xed,0x0c,0x0c,
  101. 0x98,0x0a,0x01,0x0c,0x06,0x0d,0x04,0x0a,
  102. 0x06,0x14,0x0d,0x04,0x0a,0x00,0x85,0x3f,
  103. 0xed,0x50,0x70,0x9f,0x16,0x59,0x21 /*0x2b*/,0x13,
  104. 0x27,0x0b,0x27,0xfc,0x30,0x27,0x1c,0xb0,
  105. 0x4b,0x4b,0x65 /*0x6f*/,0x2f,0x63,0x92,0x0f,0x40,
  106. 0x60,0x80,0x14,0x90,0x8c,0x60,0x14,0x27,
  107. 0x00,0x40,0x11,0x00,0xfc,0xff,0x32,0x00
  108. #endif
  109. #if 1 /* Perfect */
  110. 0x23,0x2d,0xe8,0x09,0x09,0xed,0x0c,0x0c,
  111. 0x98,0x0a,0x01,0x0c,0x06,0x0d,0x04,0x0a,
  112. 0x06,0x14,0x0d,0x04,0x0a,0x00,0x85,0x3f,
  113. 0xed,0x50,0x70,0x9f,0x16,0x59,0x60,0x13,
  114. 0x27,0x0b,0x27,0xfc,0x30,0x27,0x1c,0xb0,
  115. 0x4b,0x4b,0x6f,0x2f,0x63,0x92,0x0f,0x40,
  116. 0x60,0x80,0x14,0x90,0x8c,0x60,0x14,0x73,
  117. 0x00,0x40,0x11,0x00,0xfc,0xff,0x32,0x00
  118. #endif
  119. }
  120. };
  121. static const unsigned char SiS_TVPhase[] =
  122. {
  123. 0x21,0xED,0xBA,0x08, /* 0x00 SiS_NTSCPhase */
  124. 0x2A,0x05,0xE3,0x00, /* 0x01 SiS_PALPhase */
  125. 0x21,0xE4,0x2E,0x9B, /* 0x02 SiS_PALMPhase */
  126. 0x21,0xF4,0x3E,0xBA, /* 0x03 SiS_PALNPhase */
  127. 0x1E,0x8B,0xA2,0xA7,
  128. 0x1E,0x83,0x0A,0xE0, /* 0x05 SiS_SpecialPhaseM */
  129. 0x00,0x00,0x00,0x00,
  130. 0x00,0x00,0x00,0x00,
  131. 0x21,0xF0,0x7B,0xD6, /* 0x08 SiS_NTSCPhase2 */
  132. 0x2A,0x09,0x86,0xE9, /* 0x09 SiS_PALPhase2 */
  133. 0x21,0xE6,0xEF,0xA4, /* 0x0a SiS_PALMPhase2 */
  134. 0x21,0xF6,0x94,0x46, /* 0x0b SiS_PALNPhase2 */
  135. 0x1E,0x8B,0xA2,0xA7,
  136. 0x1E,0x83,0x0A,0xE0, /* 0x0d SiS_SpecialPhaseM */
  137. 0x00,0x00,0x00,0x00,
  138. 0x00,0x00,0x00,0x00,
  139. 0x1e,0x8c,0x5c,0x7a, /* 0x10 SiS_SpecialPhase */
  140. 0x25,0xd4,0xfd,0x5e /* 0x11 SiS_SpecialPhaseJ */
  141. };
  142. static const unsigned char SiS_HiTVGroup3_1[] = {
  143. 0x00, 0x14, 0x15, 0x25, 0x55, 0x15, 0x0b, 0x13,
  144. 0xb1, 0x41, 0x62, 0x62, 0xff, 0xf4, 0x45, 0xa6,
  145. 0x25, 0x2f, 0x67, 0xf6, 0xbf, 0xff, 0x8e, 0x20,
  146. 0xac, 0xda, 0x60, 0xfe, 0x6a, 0x9a, 0x06, 0x10,
  147. 0xd1, 0x04, 0x18, 0x0a, 0xff, 0x80, 0x00, 0x80,
  148. 0x3b, 0x77, 0x00, 0xef, 0xe0, 0x10, 0xb0, 0xe0,
  149. 0x10, 0x4f, 0x0f, 0x0f, 0x05, 0x0f, 0x08, 0x6e,
  150. 0x1a, 0x1f, 0x25, 0x2a, 0x4c, 0xaa, 0x01
  151. };
  152. static const unsigned char SiS_HiTVGroup3_2[] = {
  153. 0x00, 0x14, 0x15, 0x25, 0x55, 0x15, 0x0b, 0x7a,
  154. 0x54, 0x41, 0xe7, 0xe7, 0xff, 0xf4, 0x45, 0xa6,
  155. 0x25, 0x2f, 0x67, 0xf6, 0xbf, 0xff, 0x8e, 0x20,
  156. 0xac, 0x6a, 0x60, 0x2b, 0x52, 0xcd, 0x61, 0x10,
  157. 0x51, 0x04, 0x18, 0x0a, 0x1f, 0x80, 0x00, 0x80,
  158. 0xff, 0xa4, 0x04, 0x2b, 0x94, 0x21, 0x72, 0x94,
  159. 0x26, 0x05, 0x01, 0x0f, 0xed, 0x0f, 0x0a, 0x64,
  160. 0x18, 0x1d, 0x23, 0x28, 0x4c, 0xaa, 0x01
  161. };
  162. /* 301C / 302ELV extended Part2 TV registers (4 tap scaler) */
  163. static const unsigned char SiS_Part2CLVX_1[] = {
  164. 0x00,0x00,
  165. 0x00,0x20,0x00,0x00,0x7F,0x20,0x02,0x7F,0x7D,0x20,0x04,0x7F,0x7D,0x1F,0x06,0x7E,
  166. 0x7C,0x1D,0x09,0x7E,0x7C,0x1B,0x0B,0x7E,0x7C,0x19,0x0E,0x7D,0x7C,0x17,0x11,0x7C,
  167. 0x7C,0x14,0x14,0x7C,0x7C,0x11,0x17,0x7C,0x7D,0x0E,0x19,0x7C,0x7E,0x0B,0x1B,0x7C,
  168. 0x7E,0x09,0x1D,0x7C,0x7F,0x06,0x1F,0x7C,0x7F,0x04,0x20,0x7D,0x00,0x02,0x20,0x7E
  169. };
  170. static const unsigned char SiS_Part2CLVX_2[] = {
  171. 0x00,0x00,
  172. 0x00,0x20,0x00,0x00,0x7F,0x20,0x02,0x7F,0x7D,0x20,0x04,0x7F,0x7D,0x1F,0x06,0x7E,
  173. 0x7C,0x1D,0x09,0x7E,0x7C,0x1B,0x0B,0x7E,0x7C,0x19,0x0E,0x7D,0x7C,0x17,0x11,0x7C,
  174. 0x7C,0x14,0x14,0x7C,0x7C,0x11,0x17,0x7C,0x7D,0x0E,0x19,0x7C,0x7E,0x0B,0x1B,0x7C,
  175. 0x7E,0x09,0x1D,0x7C,0x7F,0x06,0x1F,0x7C,0x7F,0x04,0x20,0x7D,0x00,0x02,0x20,0x7E
  176. };
  177. static const unsigned char SiS_Part2CLVX_3[] = { /* NTSC, 525i, 525p */
  178. 0xE0,0x01,
  179. 0x04,0x1A,0x04,0x7E,0x03,0x1A,0x06,0x7D,0x01,0x1A,0x08,0x7D,0x00,0x19,0x0A,0x7D,
  180. 0x7F,0x19,0x0C,0x7C,0x7E,0x18,0x0E,0x7C,0x7E,0x17,0x10,0x7B,0x7D,0x15,0x12,0x7C,
  181. 0x7D,0x13,0x13,0x7D,0x7C,0x12,0x15,0x7D,0x7C,0x10,0x17,0x7D,0x7C,0x0E,0x18,0x7E,
  182. 0x7D,0x0C,0x19,0x7E,0x7D,0x0A,0x19,0x00,0x7D,0x08,0x1A,0x01,0x7E,0x06,0x1A,0x02,
  183. 0x58,0x02,
  184. 0x07,0x14,0x07,0x7E,0x06,0x14,0x09,0x7D,0x05,0x14,0x0A,0x7D,0x04,0x13,0x0B,0x7E,
  185. 0x03,0x13,0x0C,0x7E,0x02,0x12,0x0D,0x7F,0x01,0x12,0x0E,0x7F,0x01,0x11,0x0F,0x7F,
  186. 0x00,0x10,0x10,0x00,0x7F,0x0F,0x11,0x01,0x7F,0x0E,0x12,0x01,0x7E,0x0D,0x12,0x03,
  187. 0x7E,0x0C,0x13,0x03,0x7E,0x0B,0x13,0x04,0x7E,0x0A,0x14,0x04,0x7D,0x09,0x14,0x06,
  188. 0x00,0x03,
  189. 0x09,0x0F,0x09,0x7F,0x08,0x0F,0x09,0x00,0x07,0x0F,0x0A,0x00,0x06,0x0F,0x0A,0x01,
  190. 0x06,0x0E,0x0B,0x01,0x05,0x0E,0x0B,0x02,0x04,0x0E,0x0C,0x02,0x04,0x0D,0x0C,0x03,
  191. 0x03,0x0D,0x0D,0x03,0x02,0x0C,0x0D,0x05,0x02,0x0C,0x0E,0x04,0x01,0x0B,0x0E,0x06,
  192. 0x01,0x0B,0x0E,0x06,0x00,0x0A,0x0F,0x07,0x00,0x0A,0x0F,0x07,0x00,0x09,0x0F,0x08,
  193. 0xFF,0xFF
  194. };
  195. static const unsigned char SiS_Part2CLVX_4[] = { /* PAL */
  196. 0x58,0x02,
  197. 0x05,0x19,0x05,0x7D,0x03,0x19,0x06,0x7E,0x02,0x19,0x08,0x7D,0x01,0x18,0x0A,0x7D,
  198. 0x00,0x18,0x0C,0x7C,0x7F,0x17,0x0E,0x7C,0x7E,0x16,0x0F,0x7D,0x7E,0x14,0x11,0x7D,
  199. 0x7D,0x13,0x13,0x7D,0x7D,0x11,0x14,0x7E,0x7D,0x0F,0x16,0x7E,0x7D,0x0E,0x17,0x7E,
  200. 0x7D,0x0C,0x18,0x7F,0x7D,0x0A,0x18,0x01,0x7D,0x08,0x19,0x02,0x7D,0x06,0x19,0x04,
  201. 0x00,0x03,
  202. 0x08,0x12,0x08,0x7E,0x07,0x12,0x09,0x7E,0x06,0x12,0x0A,0x7E,0x05,0x11,0x0B,0x7F,
  203. 0x04,0x11,0x0C,0x7F,0x03,0x11,0x0C,0x00,0x03,0x10,0x0D,0x00,0x02,0x0F,0x0E,0x01,
  204. 0x01,0x0F,0x0F,0x01,0x01,0x0E,0x0F,0x02,0x00,0x0D,0x10,0x03,0x7F,0x0C,0x11,0x04,
  205. 0x7F,0x0C,0x11,0x04,0x7F,0x0B,0x11,0x05,0x7E,0x0A,0x12,0x06,0x7E,0x09,0x12,0x07,
  206. 0x40,0x02,
  207. 0x04,0x1A,0x04,0x7E,0x02,0x1B,0x05,0x7E,0x01,0x1A,0x07,0x7E,0x00,0x1A,0x09,0x7D,
  208. 0x7F,0x19,0x0B,0x7D,0x7E,0x18,0x0D,0x7D,0x7D,0x17,0x10,0x7C,0x7D,0x15,0x12,0x7C,
  209. 0x7C,0x14,0x14,0x7C,0x7C,0x12,0x15,0x7D,0x7C,0x10,0x17,0x7D,0x7C,0x0D,0x18,0x7F,
  210. 0x7D,0x0B,0x19,0x7F,0x7D,0x09,0x1A,0x00,0x7D,0x07,0x1A,0x02,0x7E,0x05,0x1B,0x02,
  211. 0xFF,0xFF
  212. };
  213. static const unsigned char SiS_Part2CLVX_5[] = { /* 750p */
  214. 0x00,0x03,
  215. 0x05,0x19,0x05,0x7D,0x03,0x19,0x06,0x7E,0x02,0x19,0x08,0x7D,0x01,0x18,0x0A,0x7D,
  216. 0x00,0x18,0x0C,0x7C,0x7F,0x17,0x0E,0x7C,0x7E,0x16,0x0F,0x7D,0x7E,0x14,0x11,0x7D,
  217. 0x7D,0x13,0x13,0x7D,0x7D,0x11,0x14,0x7E,0x7D,0x0F,0x16,0x7E,0x7D,0x0E,0x17,0x7E,
  218. 0x7D,0x0C,0x18,0x7F,0x7D,0x0A,0x18,0x01,0x7D,0x08,0x19,0x02,0x7D,0x06,0x19,0x04,
  219. 0xFF,0xFF
  220. };
  221. static const unsigned char SiS_Part2CLVX_6[] = { /* 1080i */
  222. 0x00,0x04,
  223. 0x04,0x1A,0x04,0x7E,0x02,0x1B,0x05,0x7E,0x01,0x1A,0x07,0x7E,0x00,0x1A,0x09,0x7D,
  224. 0x7F,0x19,0x0B,0x7D,0x7E,0x18,0x0D,0x7D,0x7D,0x17,0x10,0x7C,0x7D,0x15,0x12,0x7C,
  225. 0x7C,0x14,0x14,0x7C,0x7C,0x12,0x15,0x7D,0x7C,0x10,0x17,0x7D,0x7C,0x0D,0x18,0x7F,
  226. 0x7D,0x0B,0x19,0x7F,0x7D,0x09,0x1A,0x00,0x7D,0x07,0x1A,0x02,0x7E,0x05,0x1B,0x02,
  227. 0xFF,0xFF,
  228. };
  229. #ifdef CONFIG_FB_SIS_315
  230. /* 661 et al LCD data structure (2.03.00) */
  231. static const unsigned char SiS_LCDStruct661[] = {
  232. /* 1024x768 */
  233. /* type|CR37| HDE | VDE | HT | VT | hss | hse */
  234. 0x02,0xC0,0x00,0x04,0x00,0x03,0x40,0x05,0x26,0x03,0x10,0x00,0x88,
  235. 0x00,0x02,0x00,0x06,0x00,0x41,0x5A,0x64,0x00,0x00,0x00,0x00,0x04,
  236. /* | vss | vse |clck| clock |CRT2DataP|CRT2DataP|idx */
  237. /* VESA non-VESA noscale */
  238. /* 1280x1024 */
  239. 0x03,0xC0,0x00,0x05,0x00,0x04,0x98,0x06,0x2A,0x04,0x30,0x00,0x70,
  240. 0x00,0x01,0x00,0x03,0x00,0x6C,0xF8,0x2F,0x00,0x00,0x00,0x00,0x08,
  241. /* 1400x1050 */
  242. 0x09,0x20,0x78,0x05,0x1A,0x04,0x98,0x06,0x2A,0x04,0x18,0x00,0x38,
  243. 0x00,0x01,0x00,0x03,0x00,0x6C,0xF8,0x2F,0x00,0x00,0x00,0x00,0x09,
  244. /* 1600x1200 */
  245. 0x0B,0xE0,0x40,0x06,0xB0,0x04,0x70,0x08,0xE2,0x04,0x40,0x00,0xC0,
  246. 0x00,0x01,0x00,0x03,0x00,0xA2,0x70,0x24,0x00,0x00,0x00,0x00,0x0A,
  247. /* 1280x768 (_2) */
  248. 0x0A,0xE0,0x00,0x05,0x00,0x03,0x7C,0x06,0x26,0x03,0x30,0x00,0x70,
  249. 0x00,0x03,0x00,0x06,0x00,0x4D,0xC8,0x48,0x00,0x00,0x00,0x00,0x06,
  250. /* 1280x720 */
  251. 0x0E,0xE0,0x00,0x05,0xD0,0x02,0x80,0x05,0x26,0x03,0x10,0x00,0x20,
  252. 0x00,0x01,0x00,0x06,0x00,0x45,0x9C,0x62,0x00,0x00,0x00,0x00,0x05,
  253. /* 1280x800 (_2) */
  254. 0x0C,0xE0,0x00,0x05,0x20,0x03,0x10,0x06,0x2C,0x03,0x30,0x00,0x70,
  255. 0x00,0x04,0x00,0x03,0x00,0x49,0xCE,0x1E,0x00,0x00,0x00,0x00,0x09,
  256. /* 1680x1050 */
  257. 0x0D,0xE0,0x90,0x06,0x1A,0x04,0x6C,0x07,0x2A,0x04,0x1A,0x00,0x4C,
  258. 0x00,0x03,0x00,0x06,0x00,0x79,0xBE,0x44,0x00,0x00,0x00,0x00,0x06,
  259. /* 1280x800_3 */
  260. 0x0C,0xE0,0x00,0x05,0x20,0x03,0xAA,0x05,0x2E,0x03,0x30,0x00,0x50,
  261. 0x00,0x04,0x00,0x03,0x00,0x47,0xA9,0x10,0x00,0x00,0x00,0x00,0x07,
  262. /* 800x600 */
  263. 0x01,0xC0,0x20,0x03,0x58,0x02,0x20,0x04,0x74,0x02,0x2A,0x00,0x80,
  264. 0x00,0x06,0x00,0x04,0x00,0x28,0x63,0x4B,0x00,0x00,0x00,0x00,0x00,
  265. /* 1280x854 */
  266. 0x08,0xE0,0x00,0x05,0x56,0x03,0x80,0x06,0x5d,0x03,0x10,0x00,0x70,
  267. 0x00,0x01,0x00,0x03,0x00,0x54,0x75,0x13,0x00,0x00,0x00,0x00,0x08
  268. };
  269. #endif
  270. #ifdef CONFIG_FB_SIS_300
  271. static unsigned char SiS300_TrumpionData[14][80] = {
  272. { 0x02,0x0A,0x0A,0x01,0x04,0x01,0x00,0x03,0x0D,0x00,0x0D,0x10,0x7F,0x00,0x80,0x02,
  273. 0x20,0x03,0x0B,0x00,0x90,0x01,0xC1,0x01,0x60,0x0C,0x30,0x10,0x00,0x00,0x04,0x23,
  274. 0x00,0x00,0x03,0x28,0x03,0x10,0x05,0x08,0x40,0x10,0x00,0x10,0x04,0x23,0x00,0x23,
  275. 0x03,0x11,0x60,0xBC,0x01,0xFF,0x03,0xFF,0x19,0x01,0x00,0x05,0x09,0x04,0x04,0x05,
  276. 0x04,0x0C,0x09,0x05,0x02,0xB0,0x00,0x00,0x02,0xBA,0xF0,0x5A,0x01,0xBE,0x01,0x00 },
  277. { 0x02,0x0A,0x0A,0x01,0x04,0x01,0x00,0x03,0x0D,0x00,0x0D,0x10,0x27,0x00,0x80,0x02,
  278. 0x20,0x03,0x07,0x00,0x5E,0x01,0x0D,0x02,0x60,0x0C,0x30,0x11,0x00,0x00,0x04,0x23,
  279. 0x00,0x00,0x03,0x80,0x03,0x28,0x06,0x08,0x40,0x11,0x00,0x11,0x04,0x23,0x00,0x23,
  280. 0x03,0x11,0x60,0x90,0x01,0xFF,0x0F,0xF4,0x19,0x01,0x00,0x05,0x01,0x00,0x04,0x05,
  281. 0x04,0x0C,0x02,0x01,0x02,0xB0,0x00,0x00,0x02,0xBA,0xEC,0x57,0x01,0xBE,0x01,0x00 },
  282. { 0x02,0x0A,0x0A,0x01,0x04,0x01,0x00,0x03,0x0D,0x00,0x0D,0x10,0x8A,0x00,0xD8,0x02,
  283. 0x84,0x03,0x16,0x00,0x90,0x01,0xC1,0x01,0x60,0x0C,0x30,0x1C,0x00,0x20,0x04,0x23,
  284. 0x00,0x01,0x03,0x53,0x03,0x28,0x06,0x08,0x40,0x1C,0x00,0x16,0x04,0x23,0x00,0x23,
  285. 0x03,0x11,0x60,0xD9,0x01,0xFF,0x0F,0xF4,0x18,0x07,0x05,0x05,0x13,0x04,0x04,0x05,
  286. 0x01,0x0B,0x13,0x0A,0x02,0xB0,0x00,0x00,0x02,0xBA,0xF0,0x59,0x01,0xBE,0x01,0x00 },
  287. { 0x02,0x0A,0x0A,0x01,0x04,0x01,0x00,0x03,0x0D,0x00,0x0D,0x10,0x72,0x00,0xD8,0x02,
  288. 0x84,0x03,0x16,0x00,0x90,0x01,0xC1,0x01,0x60,0x0C,0x30,0x1C,0x00,0x20,0x04,0x23,
  289. 0x00,0x01,0x03,0x53,0x03,0x28,0x06,0x08,0x40,0x1C,0x00,0x16,0x04,0x23,0x00,0x23,
  290. 0x03,0x11,0x60,0xDA,0x01,0xFF,0x0F,0xF4,0x18,0x07,0x05,0x05,0x13,0x04,0x04,0x05,
  291. 0x01,0x0B,0x13,0x0A,0x02,0xB0,0x00,0x00,0x02,0xBA,0xF0,0x55,0x01,0xBE,0x01,0x00 },
  292. { 0x02,0x0A,0x02,0x00,0x04,0x01,0x00,0x03,0x0D,0x00,0x0D,0x10,0x7F,0x00,0x80,0x02,
  293. 0x20,0x03,0x16,0x00,0xE0,0x01,0x0D,0x02,0x60,0x0C,0x30,0x98,0x00,0x00,0x04,0x23,
  294. 0x00,0x01,0x03,0x45,0x03,0x48,0x06,0x08,0x40,0x98,0x00,0x98,0x04,0x23,0x00,0x23,
  295. 0x03,0x11,0x60,0xF4,0x01,0xFF,0x0F,0xF4,0x18,0x01,0x00,0x05,0x01,0x00,0x05,0x05,
  296. 0x04,0x0C,0x08,0x05,0x02,0xB0,0x00,0x00,0x02,0xBA,0xF0,0x5B,0x01,0xBE,0x01,0x00 },
  297. { 0x02,0x0A,0x02,0x01,0x04,0x01,0x00,0x03,0x0D,0x00,0x0D,0x10,0xBF,0x00,0x20,0x03,
  298. 0x20,0x04,0x0D,0x00,0x58,0x02,0x71,0x02,0x80,0x0C,0x30,0x9A,0x00,0xFA,0x03,0x1D,
  299. 0x00,0x01,0x03,0x22,0x03,0x28,0x06,0x08,0x40,0x98,0x00,0x98,0x04,0x1D,0x00,0x1D,
  300. 0x03,0x11,0x60,0x39,0x03,0x40,0x05,0xF4,0x18,0x07,0x02,0x06,0x04,0x01,0x06,0x0B,
  301. 0x02,0x0A,0x20,0x19,0x02,0xB0,0x00,0x00,0x02,0xBA,0xF0,0x5B,0x01,0xBE,0x01,0x00 },
  302. { 0x02,0x0A,0x0A,0x01,0x04,0x01,0x00,0x03,0x0D,0x00,0x0D,0x10,0xEF,0x00,0x00,0x04,
  303. 0x40,0x05,0x13,0x00,0x00,0x03,0x26,0x03,0x88,0x0C,0x30,0x90,0x00,0x00,0x04,0x23,
  304. 0x00,0x01,0x03,0x24,0x03,0x28,0x06,0x08,0x40,0x90,0x00,0x90,0x04,0x23,0x00,0x23,
  305. 0x03,0x11,0x60,0x40,0x05,0xFF,0x0F,0xF4,0x18,0x01,0x00,0x08,0x01,0x00,0x08,0x01,
  306. 0x00,0x08,0x01,0x01,0x02,0xB0,0x00,0x00,0x02,0xBA,0xF0,0x5B,0x01,0xBE,0x01,0x00 },
  307. /* variant 2 */
  308. { 0x02,0x0A,0x0A,0x01,0x04,0x01,0x00,0x03,0x11,0x00,0x0D,0x10,0x7F,0x00,0x80,0x02,
  309. 0x20,0x03,0x15,0x00,0x90,0x01,0xC1,0x01,0x60,0x0C,0x30,0x18,0x00,0x00,0x04,0x23,
  310. 0x00,0x01,0x03,0x44,0x03,0x28,0x06,0x08,0x40,0x18,0x00,0x18,0x04,0x23,0x00,0x23,
  311. 0x03,0x11,0x60,0xA6,0x01,0xFF,0x03,0xFF,0x19,0x01,0x00,0x05,0x13,0x04,0x04,0x05,
  312. 0x04,0x0C,0x13,0x0A,0x02,0xB0,0x00,0x00,0x02,0xBA,0xF0,0x55,0x01,0xBE,0x01,0x00 },
  313. { 0x02,0x0A,0x0A,0x01,0x04,0x01,0x00,0x03,0x11,0x00,0x0D,0x10,0x7F,0x00,0x80,0x02,
  314. 0x20,0x03,0x15,0x00,0x90,0x01,0xC1,0x01,0x60,0x0C,0x30,0x18,0x00,0x00,0x04,0x23,
  315. 0x00,0x01,0x03,0x44,0x03,0x28,0x06,0x08,0x40,0x18,0x00,0x18,0x04,0x23,0x00,0x23,
  316. 0x03,0x11,0x60,0xA6,0x01,0xFF,0x03,0xFF,0x19,0x01,0x00,0x05,0x13,0x04,0x04,0x05,
  317. 0x04,0x0C,0x13,0x0A,0x02,0xB0,0x00,0x00,0x02,0xBA,0xF0,0x55,0x01,0xBE,0x01,0x00 },
  318. { 0x02,0x0A,0x0A,0x01,0x04,0x01,0x00,0x03,0x11,0x00,0x0D,0x10,0x8A,0x00,0xD8,0x02,
  319. 0x84,0x03,0x16,0x00,0x90,0x01,0xC1,0x01,0x60,0x0C,0x30,0x1C,0x00,0x20,0x04,0x23,
  320. 0x00,0x01,0x03,0x53,0x03,0x28,0x06,0x08,0x40,0x1C,0x00,0x16,0x04,0x23,0x00,0x23,
  321. 0x03,0x11,0x60,0xDA,0x01,0xFF,0x0F,0xF4,0x18,0x07,0x05,0x05,0x13,0x04,0x04,0x05,
  322. 0x01,0x0B,0x13,0x0A,0x02,0xB0,0x00,0x00,0x02,0xBA,0xF0,0x55,0x01,0xBE,0x01,0x00 },
  323. { 0x02,0x0A,0x0A,0x01,0x04,0x01,0x00,0x03,0x11,0x00,0x0D,0x10,0x72,0x00,0xD8,0x02,
  324. 0x84,0x03,0x16,0x00,0x90,0x01,0xC1,0x01,0x60,0x0C,0x30,0x1C,0x00,0x20,0x04,0x23,
  325. 0x00,0x01,0x03,0x53,0x03,0x28,0x06,0x08,0x40,0x1C,0x00,0x16,0x04,0x23,0x00,0x23,
  326. 0x03,0x11,0x60,0xDA,0x01,0xFF,0x0F,0xF4,0x18,0x07,0x05,0x05,0x13,0x04,0x04,0x05,
  327. 0x01,0x0B,0x13,0x0A,0x02,0xB0,0x00,0x00,0x02,0xBA,0xF0,0x55,0x01,0xBE,0x01,0x00 },
  328. { 0x02,0x0A,0x02,0x00,0x04,0x01,0x00,0x03,0x11,0x00,0x0D,0x10,0x7F,0x00,0x80,0x02,
  329. 0x20,0x03,0x16,0x00,0xE0,0x01,0x0D,0x02,0x60,0x0C,0x30,0x98,0x00,0x00,0x04,0x23,
  330. 0x00,0x01,0x03,0x45,0x03,0x48,0x06,0x08,0x40,0x98,0x00,0x98,0x04,0x23,0x00,0x23,
  331. 0x03,0x11,0x60,0xF4,0x01,0xFF,0x0F,0xF4,0x18,0x01,0x00,0x05,0x01,0x00,0x05,0x05,
  332. 0x04,0x0C,0x08,0x05,0x02,0xB0,0x00,0x00,0x02,0xBA,0xEA,0x58,0x01,0xBE,0x01,0x00 },
  333. { 0x02,0x0A,0x02,0x01,0x04,0x01,0x00,0x03,0x11,0x00,0x0D,0x10,0xBF,0x00,0x20,0x03,
  334. 0x20,0x04,0x0D,0x00,0x58,0x02,0x71,0x02,0x80,0x0C,0x30,0x9A,0x00,0xFA,0x03,0x1D,
  335. 0x00,0x01,0x03,0x22,0x03,0x28,0x06,0x08,0x40,0x98,0x00,0x98,0x04,0x1D,0x00,0x1D,
  336. 0x03,0x11,0x60,0x39,0x03,0x40,0x05,0xF4,0x18,0x07,0x02,0x06,0x04,0x01,0x06,0x0B,
  337. 0x02,0x0A,0x20,0x19,0x02,0xB0,0x00,0x00,0x02,0xBA,0xEA,0x58,0x01,0xBE,0x01,0x00 },
  338. { 0x02,0x0A,0x0A,0x01,0x04,0x01,0x00,0x03,0x11,0x00,0x0D,0x10,0xEF,0x00,0x00,0x04,
  339. 0x40,0x05,0x13,0x00,0x00,0x03,0x26,0x03,0x88,0x0C,0x30,0x90,0x00,0x00,0x04,0x23,
  340. 0x00,0x01,0x03,0x24,0x03,0x28,0x06,0x08,0x40,0x90,0x00,0x90,0x04,0x23,0x00,0x23,
  341. 0x03,0x11,0x60,0x40,0x05,0xFF,0x0F,0xF4,0x18,0x01,0x00,0x08,0x01,0x00,0x08,0x01,
  342. 0x00,0x08,0x01,0x01,0x02,0xB0,0x00,0x00,0x02,0xBA,0xEA,0x58,0x01,0xBE,0x01,0x00 }
  343. };
  344. #endif
  345. #ifdef CONFIG_FB_SIS_315
  346. static void SiS_Chrontel701xOn(struct SiS_Private *SiS_Pr);
  347. static void SiS_Chrontel701xOff(struct SiS_Private *SiS_Pr);
  348. static void SiS_ChrontelInitTVVSync(struct SiS_Private *SiS_Pr);
  349. static void SiS_ChrontelDoSomething1(struct SiS_Private *SiS_Pr);
  350. #endif /* 315 */
  351. #ifdef CONFIG_FB_SIS_300
  352. static bool SiS_SetTrumpionBlock(struct SiS_Private *SiS_Pr, unsigned char *dataptr);
  353. #endif
  354. static unsigned short SiS_InitDDCRegs(struct SiS_Private *SiS_Pr, unsigned int VBFlags,
  355. int VGAEngine, unsigned short adaptnum, unsigned short DDCdatatype,
  356. bool checkcr32, unsigned int VBFlags2);
  357. static unsigned short SiS_ProbeDDC(struct SiS_Private *SiS_Pr);
  358. static unsigned short SiS_ReadDDC(struct SiS_Private *SiS_Pr, unsigned short DDCdatatype,
  359. unsigned char *buffer);
  360. static void SiS_SetSwitchDDC2(struct SiS_Private *SiS_Pr);
  361. static unsigned short SiS_SetStart(struct SiS_Private *SiS_Pr);
  362. static unsigned short SiS_SetStop(struct SiS_Private *SiS_Pr);
  363. static unsigned short SiS_SetSCLKLow(struct SiS_Private *SiS_Pr);
  364. static unsigned short SiS_SetSCLKHigh(struct SiS_Private *SiS_Pr);
  365. static unsigned short SiS_ReadDDC2Data(struct SiS_Private *SiS_Pr);
  366. static unsigned short SiS_WriteDDC2Data(struct SiS_Private *SiS_Pr, unsigned short tempax);
  367. static unsigned short SiS_CheckACK(struct SiS_Private *SiS_Pr);
  368. static unsigned short SiS_WriteDABDDC(struct SiS_Private *SiS_Pr);
  369. static unsigned short SiS_PrepareReadDDC(struct SiS_Private *SiS_Pr);
  370. static unsigned short SiS_PrepareDDC(struct SiS_Private *SiS_Pr);
  371. static void SiS_SendACK(struct SiS_Private *SiS_Pr, unsigned short yesno);
  372. static unsigned short SiS_DoProbeDDC(struct SiS_Private *SiS_Pr);
  373. #ifdef CONFIG_FB_SIS_300
  374. static void SiS_OEM300Setting(struct SiS_Private *SiS_Pr,
  375. unsigned short ModeNo, unsigned short ModeIdIndex, unsigned short RefTabindex);
  376. static void SetOEMLCDData2(struct SiS_Private *SiS_Pr,
  377. unsigned short ModeNo, unsigned short ModeIdIndex,unsigned short RefTableIndex);
  378. #endif
  379. #ifdef CONFIG_FB_SIS_315
  380. static void SiS_OEM310Setting(struct SiS_Private *SiS_Pr,
  381. unsigned short ModeNo,unsigned short ModeIdIndex, unsigned short RRTI);
  382. static void SiS_OEM661Setting(struct SiS_Private *SiS_Pr,
  383. unsigned short ModeNo,unsigned short ModeIdIndex, unsigned short RRTI);
  384. static void SiS_FinalizeLCD(struct SiS_Private *, unsigned short, unsigned short);
  385. #endif
  386. static unsigned short SiS_GetBIOSLCDResInfo(struct SiS_Private *SiS_Pr);
  387. static void SiS_SetCH70xx(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val);
  388. /*********************************************/
  389. /* HELPER: Lock/Unlock CRT2 */
  390. /*********************************************/
  391. void
  392. SiS_UnLockCRT2(struct SiS_Private *SiS_Pr)
  393. {
  394. if(SiS_Pr->ChipType == XGI_20)
  395. return;
  396. else if(SiS_Pr->ChipType >= SIS_315H)
  397. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2f,0x01);
  398. else
  399. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x24,0x01);
  400. }
  401. static
  402. void
  403. SiS_LockCRT2(struct SiS_Private *SiS_Pr)
  404. {
  405. if(SiS_Pr->ChipType == XGI_20)
  406. return;
  407. else if(SiS_Pr->ChipType >= SIS_315H)
  408. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2F,0xFE);
  409. else
  410. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x24,0xFE);
  411. }
  412. /*********************************************/
  413. /* HELPER: Write SR11 */
  414. /*********************************************/
  415. static void
  416. SiS_SetRegSR11ANDOR(struct SiS_Private *SiS_Pr, unsigned short DataAND, unsigned short DataOR)
  417. {
  418. if(SiS_Pr->ChipType >= SIS_661) {
  419. DataAND &= 0x0f;
  420. DataOR &= 0x0f;
  421. }
  422. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x11,DataAND,DataOR);
  423. }
  424. /*********************************************/
  425. /* HELPER: Get Pointer to LCD structure */
  426. /*********************************************/
  427. #ifdef CONFIG_FB_SIS_315
  428. static unsigned char *
  429. GetLCDStructPtr661(struct SiS_Private *SiS_Pr)
  430. {
  431. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  432. unsigned char *myptr = NULL;
  433. unsigned short romindex = 0, reg = 0, idx = 0;
  434. /* Use the BIOS tables only for LVDS panels; TMDS is unreliable
  435. * due to the variaty of panels the BIOS doesn't know about.
  436. * Exception: If the BIOS has better knowledge (such as in case
  437. * of machines with a 301C and a panel that does not support DDC)
  438. * use the BIOS data as well.
  439. */
  440. if((SiS_Pr->SiS_ROMNew) &&
  441. ((SiS_Pr->SiS_VBType & VB_SISLVDS) || (!SiS_Pr->PanelSelfDetected))) {
  442. if(SiS_Pr->ChipType < SIS_661) reg = 0x3c;
  443. else reg = 0x7d;
  444. idx = (SiS_GetReg(SiS_Pr->SiS_P3d4,reg) & 0x1f) * 26;
  445. if(idx < (8*26)) {
  446. myptr = (unsigned char *)&SiS_LCDStruct661[idx];
  447. }
  448. romindex = SISGETROMW(0x100);
  449. if(romindex) {
  450. romindex += idx;
  451. myptr = &ROMAddr[romindex];
  452. }
  453. }
  454. return myptr;
  455. }
  456. static unsigned short
  457. GetLCDStructPtr661_2(struct SiS_Private *SiS_Pr)
  458. {
  459. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  460. unsigned short romptr = 0;
  461. /* Use the BIOS tables only for LVDS panels; TMDS is unreliable
  462. * due to the variaty of panels the BIOS doesn't know about.
  463. * Exception: If the BIOS has better knowledge (such as in case
  464. * of machines with a 301C and a panel that does not support DDC)
  465. * use the BIOS data as well.
  466. */
  467. if((SiS_Pr->SiS_ROMNew) &&
  468. ((SiS_Pr->SiS_VBType & VB_SISLVDS) || (!SiS_Pr->PanelSelfDetected))) {
  469. romptr = SISGETROMW(0x102);
  470. romptr += ((SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4) * SiS_Pr->SiS661LCD2TableSize);
  471. }
  472. return romptr;
  473. }
  474. #endif
  475. /*********************************************/
  476. /* Adjust Rate for CRT2 */
  477. /*********************************************/
  478. static bool
  479. SiS_AdjustCRT2Rate(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  480. unsigned short RRTI, unsigned short *i)
  481. {
  482. unsigned short checkmask=0, modeid, infoflag;
  483. modeid = SiS_Pr->SiS_RefIndex[RRTI + (*i)].ModeID;
  484. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  485. if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) {
  486. checkmask |= SupportRAMDAC2;
  487. if(SiS_Pr->ChipType >= SIS_315H) {
  488. checkmask |= SupportRAMDAC2_135;
  489. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  490. checkmask |= SupportRAMDAC2_162;
  491. if(SiS_Pr->SiS_VBType & VB_SISRAMDAC202) {
  492. checkmask |= SupportRAMDAC2_202;
  493. }
  494. }
  495. }
  496. } else if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  497. checkmask |= SupportLCD;
  498. if(SiS_Pr->ChipType >= SIS_315H) {
  499. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  500. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  501. if(modeid == 0x2e) checkmask |= Support64048060Hz;
  502. }
  503. }
  504. }
  505. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  506. checkmask |= SupportHiVision;
  507. } else if(SiS_Pr->SiS_VBInfo & (SetCRT2ToYPbPr525750|SetCRT2ToAVIDEO|SetCRT2ToSVIDEO|SetCRT2ToSCART)) {
  508. checkmask |= SupportTV;
  509. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  510. checkmask |= SupportTV1024;
  511. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  512. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) {
  513. checkmask |= SupportYPbPr750p;
  514. }
  515. }
  516. }
  517. }
  518. } else { /* LVDS */
  519. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  520. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  521. checkmask |= SupportCHTV;
  522. }
  523. }
  524. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  525. checkmask |= SupportLCD;
  526. }
  527. }
  528. /* Look backwards in table for matching CRT2 mode */
  529. for(; SiS_Pr->SiS_RefIndex[RRTI + (*i)].ModeID == modeid; (*i)--) {
  530. infoflag = SiS_Pr->SiS_RefIndex[RRTI + (*i)].Ext_InfoFlag;
  531. if(infoflag & checkmask) return true;
  532. if((*i) == 0) break;
  533. }
  534. /* Look through the whole mode-section of the table from the beginning
  535. * for a matching CRT2 mode if no mode was found yet.
  536. */
  537. for((*i) = 0; ; (*i)++) {
  538. if(SiS_Pr->SiS_RefIndex[RRTI + (*i)].ModeID != modeid) break;
  539. infoflag = SiS_Pr->SiS_RefIndex[RRTI + (*i)].Ext_InfoFlag;
  540. if(infoflag & checkmask) return true;
  541. }
  542. return false;
  543. }
  544. /*********************************************/
  545. /* Get rate index */
  546. /*********************************************/
  547. unsigned short
  548. SiS_GetRatePtr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  549. {
  550. unsigned short RRTI,i,backup_i;
  551. unsigned short modeflag,index,temp,backupindex;
  552. static const unsigned short LCDRefreshIndex[] = {
  553. 0x00, 0x00, 0x01, 0x01,
  554. 0x01, 0x01, 0x01, 0x01,
  555. 0x01, 0x01, 0x01, 0x01,
  556. 0x01, 0x01, 0x01, 0x01,
  557. 0x00, 0x00, 0x00, 0x00
  558. };
  559. /* Do NOT check for UseCustomMode here, will skrew up FIFO */
  560. if(ModeNo == 0xfe) return 0;
  561. if(ModeNo <= 0x13) {
  562. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  563. } else {
  564. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  565. }
  566. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  567. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  568. if(modeflag & HalfDCLK) return 0;
  569. }
  570. }
  571. if(ModeNo < 0x14) return 0xFFFF;
  572. index = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x33) >> SiS_Pr->SiS_SelectCRT2Rate) & 0x0F;
  573. backupindex = index;
  574. if(index > 0) index--;
  575. if(SiS_Pr->SiS_SetFlag & ProgrammingCRT2) {
  576. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  577. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  578. if(SiS_Pr->SiS_VBType & VB_NoLCD) index = 0;
  579. else if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) index = backupindex = 0;
  580. }
  581. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  582. if(!(SiS_Pr->SiS_VBType & VB_NoLCD)) {
  583. temp = LCDRefreshIndex[SiS_GetBIOSLCDResInfo(SiS_Pr)];
  584. if(index > temp) index = temp;
  585. }
  586. }
  587. } else {
  588. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) index = 0;
  589. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  590. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) index = 0;
  591. }
  592. }
  593. }
  594. RRTI = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].REFindex;
  595. ModeNo = SiS_Pr->SiS_RefIndex[RRTI].ModeID;
  596. if(SiS_Pr->ChipType >= SIS_315H) {
  597. if(!(SiS_Pr->SiS_VBInfo & DriverMode)) {
  598. if( (SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_VESAID == 0x105) ||
  599. (SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_VESAID == 0x107) ) {
  600. if(backupindex <= 1) RRTI++;
  601. }
  602. }
  603. }
  604. i = 0;
  605. do {
  606. if(SiS_Pr->SiS_RefIndex[RRTI + i].ModeID != ModeNo) break;
  607. temp = SiS_Pr->SiS_RefIndex[RRTI + i].Ext_InfoFlag;
  608. temp &= ModeTypeMask;
  609. if(temp < SiS_Pr->SiS_ModeType) break;
  610. i++;
  611. index--;
  612. } while(index != 0xFFFF);
  613. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) {
  614. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  615. temp = SiS_Pr->SiS_RefIndex[RRTI + i - 1].Ext_InfoFlag;
  616. if(temp & InterlaceMode) i++;
  617. }
  618. }
  619. i--;
  620. if((SiS_Pr->SiS_SetFlag & ProgrammingCRT2) && (!(SiS_Pr->SiS_VBInfo & DisableCRT2Display))) {
  621. backup_i = i;
  622. if(!(SiS_AdjustCRT2Rate(SiS_Pr, ModeNo, ModeIdIndex, RRTI, &i))) {
  623. i = backup_i;
  624. }
  625. }
  626. return (RRTI + i);
  627. }
  628. /*********************************************/
  629. /* STORE CRT2 INFO in CR34 */
  630. /*********************************************/
  631. static void
  632. SiS_SaveCRT2Info(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
  633. {
  634. unsigned short temp1, temp2;
  635. /* Store CRT1 ModeNo in CR34 */
  636. SiS_SetReg(SiS_Pr->SiS_P3d4,0x34,ModeNo);
  637. temp1 = (SiS_Pr->SiS_VBInfo & SetInSlaveMode) >> 8;
  638. temp2 = ~(SetInSlaveMode >> 8);
  639. SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x31,temp2,temp1);
  640. }
  641. /*********************************************/
  642. /* HELPER: GET SOME DATA FROM BIOS ROM */
  643. /*********************************************/
  644. #ifdef CONFIG_FB_SIS_300
  645. static bool
  646. SiS_CR36BIOSWord23b(struct SiS_Private *SiS_Pr)
  647. {
  648. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  649. unsigned short temp,temp1;
  650. if(SiS_Pr->SiS_UseROM) {
  651. if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) {
  652. temp = 1 << ((SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4) & 0x0f);
  653. temp1 = SISGETROMW(0x23b);
  654. if(temp1 & temp) return true;
  655. }
  656. }
  657. return false;
  658. }
  659. static bool
  660. SiS_CR36BIOSWord23d(struct SiS_Private *SiS_Pr)
  661. {
  662. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  663. unsigned short temp,temp1;
  664. if(SiS_Pr->SiS_UseROM) {
  665. if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) {
  666. temp = 1 << ((SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4) & 0x0f);
  667. temp1 = SISGETROMW(0x23d);
  668. if(temp1 & temp) return true;
  669. }
  670. }
  671. return false;
  672. }
  673. #endif
  674. /*********************************************/
  675. /* HELPER: DELAY FUNCTIONS */
  676. /*********************************************/
  677. void
  678. SiS_DDC2Delay(struct SiS_Private *SiS_Pr, unsigned int delaytime)
  679. {
  680. while (delaytime-- > 0)
  681. SiS_GetReg(SiS_Pr->SiS_P3c4, 0x05);
  682. }
  683. #if defined(CONFIG_FB_SIS_300) || defined(CONFIG_FB_SIS_315)
  684. static void
  685. SiS_GenericDelay(struct SiS_Private *SiS_Pr, unsigned short delay)
  686. {
  687. SiS_DDC2Delay(SiS_Pr, delay * 36);
  688. }
  689. #endif
  690. #ifdef CONFIG_FB_SIS_315
  691. static void
  692. SiS_LongDelay(struct SiS_Private *SiS_Pr, unsigned short delay)
  693. {
  694. while(delay--) {
  695. SiS_GenericDelay(SiS_Pr, 6623);
  696. }
  697. }
  698. #endif
  699. #if defined(CONFIG_FB_SIS_300) || defined(CONFIG_FB_SIS_315)
  700. static void
  701. SiS_ShortDelay(struct SiS_Private *SiS_Pr, unsigned short delay)
  702. {
  703. while(delay--) {
  704. SiS_GenericDelay(SiS_Pr, 66);
  705. }
  706. }
  707. #endif
  708. static void
  709. SiS_PanelDelay(struct SiS_Private *SiS_Pr, unsigned short DelayTime)
  710. {
  711. #if defined(CONFIG_FB_SIS_300) || defined(CONFIG_FB_SIS_315)
  712. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  713. unsigned short PanelID, DelayIndex, Delay=0;
  714. #endif
  715. if(SiS_Pr->ChipType < SIS_315H) {
  716. #ifdef CONFIG_FB_SIS_300
  717. PanelID = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36);
  718. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  719. if(SiS_Pr->SiS_VBType & VB_SIS301) PanelID &= 0xf7;
  720. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x18) & 0x10)) PanelID = 0x12;
  721. }
  722. DelayIndex = PanelID >> 4;
  723. if((DelayTime >= 2) && ((PanelID & 0x0f) == 1)) {
  724. Delay = 3;
  725. } else {
  726. if(DelayTime >= 2) DelayTime -= 2;
  727. if(!(DelayTime & 0x01)) {
  728. Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[0];
  729. } else {
  730. Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[1];
  731. }
  732. if(SiS_Pr->SiS_UseROM) {
  733. if(ROMAddr[0x220] & 0x40) {
  734. if(!(DelayTime & 0x01)) Delay = (unsigned short)ROMAddr[0x225];
  735. else Delay = (unsigned short)ROMAddr[0x226];
  736. }
  737. }
  738. }
  739. SiS_ShortDelay(SiS_Pr, Delay);
  740. #endif /* CONFIG_FB_SIS_300 */
  741. } else {
  742. #ifdef CONFIG_FB_SIS_315
  743. if((SiS_Pr->ChipType >= SIS_661) ||
  744. (SiS_Pr->ChipType <= SIS_315PRO) ||
  745. (SiS_Pr->ChipType == SIS_330) ||
  746. (SiS_Pr->SiS_ROMNew)) {
  747. if(!(DelayTime & 0x01)) {
  748. SiS_DDC2Delay(SiS_Pr, 0x1000);
  749. } else {
  750. SiS_DDC2Delay(SiS_Pr, 0x4000);
  751. }
  752. } else if (SiS_Pr->SiS_IF_DEF_LVDS == 1) { /* 315 series, LVDS; Special */
  753. if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
  754. PanelID = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36);
  755. if(SiS_Pr->SiS_CustomT == CUT_CLEVO1400) {
  756. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x1b) & 0x10)) PanelID = 0x12;
  757. }
  758. if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) {
  759. DelayIndex = PanelID & 0x0f;
  760. } else {
  761. DelayIndex = PanelID >> 4;
  762. }
  763. if((DelayTime >= 2) && ((PanelID & 0x0f) == 1)) {
  764. Delay = 3;
  765. } else {
  766. if(DelayTime >= 2) DelayTime -= 2;
  767. if(!(DelayTime & 0x01)) {
  768. Delay = SiS_Pr->SiS_PanelDelayTblLVDS[DelayIndex].timer[0];
  769. } else {
  770. Delay = SiS_Pr->SiS_PanelDelayTblLVDS[DelayIndex].timer[1];
  771. }
  772. if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
  773. if(ROMAddr[0x13c] & 0x40) {
  774. if(!(DelayTime & 0x01)) {
  775. Delay = (unsigned short)ROMAddr[0x17e];
  776. } else {
  777. Delay = (unsigned short)ROMAddr[0x17f];
  778. }
  779. }
  780. }
  781. }
  782. SiS_ShortDelay(SiS_Pr, Delay);
  783. }
  784. } else if(SiS_Pr->SiS_VBType & VB_SISVB) { /* 315 series, all bridges */
  785. DelayIndex = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4;
  786. if(!(DelayTime & 0x01)) {
  787. Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[0];
  788. } else {
  789. Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[1];
  790. }
  791. Delay <<= 8;
  792. SiS_DDC2Delay(SiS_Pr, Delay);
  793. }
  794. #endif /* CONFIG_FB_SIS_315 */
  795. }
  796. }
  797. #ifdef CONFIG_FB_SIS_315
  798. static void
  799. SiS_PanelDelayLoop(struct SiS_Private *SiS_Pr, unsigned short DelayTime, unsigned short DelayLoop)
  800. {
  801. int i;
  802. for(i = 0; i < DelayLoop; i++) {
  803. SiS_PanelDelay(SiS_Pr, DelayTime);
  804. }
  805. }
  806. #endif
  807. /*********************************************/
  808. /* HELPER: WAIT-FOR-RETRACE FUNCTIONS */
  809. /*********************************************/
  810. void
  811. SiS_WaitRetrace1(struct SiS_Private *SiS_Pr)
  812. {
  813. unsigned short watchdog;
  814. if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x1f) & 0xc0) return;
  815. if(!(SiS_GetReg(SiS_Pr->SiS_P3d4,0x17) & 0x80)) return;
  816. watchdog = 65535;
  817. while((SiS_GetRegByte(SiS_Pr->SiS_P3da) & 0x08) && --watchdog);
  818. watchdog = 65535;
  819. while((!(SiS_GetRegByte(SiS_Pr->SiS_P3da) & 0x08)) && --watchdog);
  820. }
  821. #if defined(CONFIG_FB_SIS_300) || defined(CONFIG_FB_SIS_315)
  822. static void
  823. SiS_WaitRetrace2(struct SiS_Private *SiS_Pr, unsigned short reg)
  824. {
  825. unsigned short watchdog;
  826. watchdog = 65535;
  827. while((SiS_GetReg(SiS_Pr->SiS_Part1Port,reg) & 0x02) && --watchdog);
  828. watchdog = 65535;
  829. while((!(SiS_GetReg(SiS_Pr->SiS_Part1Port,reg) & 0x02)) && --watchdog);
  830. }
  831. #endif
  832. static void
  833. SiS_WaitVBRetrace(struct SiS_Private *SiS_Pr)
  834. {
  835. if(SiS_Pr->ChipType < SIS_315H) {
  836. #ifdef CONFIG_FB_SIS_300
  837. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  838. if(!(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x20)) return;
  839. }
  840. if(!(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x80)) {
  841. SiS_WaitRetrace1(SiS_Pr);
  842. } else {
  843. SiS_WaitRetrace2(SiS_Pr, 0x25);
  844. }
  845. #endif
  846. } else {
  847. #ifdef CONFIG_FB_SIS_315
  848. if(!(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x40)) {
  849. SiS_WaitRetrace1(SiS_Pr);
  850. } else {
  851. SiS_WaitRetrace2(SiS_Pr, 0x30);
  852. }
  853. #endif
  854. }
  855. }
  856. static void
  857. SiS_VBWait(struct SiS_Private *SiS_Pr)
  858. {
  859. unsigned short tempal,temp,i,j;
  860. temp = 0;
  861. for(i = 0; i < 3; i++) {
  862. for(j = 0; j < 100; j++) {
  863. tempal = SiS_GetRegByte(SiS_Pr->SiS_P3da);
  864. if(temp & 0x01) {
  865. if((tempal & 0x08)) continue;
  866. else break;
  867. } else {
  868. if(!(tempal & 0x08)) continue;
  869. else break;
  870. }
  871. }
  872. temp ^= 0x01;
  873. }
  874. }
  875. static void
  876. SiS_VBLongWait(struct SiS_Private *SiS_Pr)
  877. {
  878. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  879. SiS_VBWait(SiS_Pr);
  880. } else {
  881. SiS_WaitRetrace1(SiS_Pr);
  882. }
  883. }
  884. /*********************************************/
  885. /* HELPER: MISC */
  886. /*********************************************/
  887. #ifdef CONFIG_FB_SIS_300
  888. static bool
  889. SiS_Is301B(struct SiS_Private *SiS_Pr)
  890. {
  891. if(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x01) >= 0xb0) return true;
  892. return false;
  893. }
  894. #endif
  895. static bool
  896. SiS_CRT2IsLCD(struct SiS_Private *SiS_Pr)
  897. {
  898. if(SiS_Pr->ChipType == SIS_730) {
  899. if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x20) return true;
  900. }
  901. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x30) & 0x20) return true;
  902. return false;
  903. }
  904. bool
  905. SiS_IsDualEdge(struct SiS_Private *SiS_Pr)
  906. {
  907. #ifdef CONFIG_FB_SIS_315
  908. if(SiS_Pr->ChipType >= SIS_315H) {
  909. if((SiS_Pr->ChipType != SIS_650) || (SiS_GetReg(SiS_Pr->SiS_P3d4,0x5f) & 0xf0)) {
  910. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x38) & EnableDualEdge) return true;
  911. }
  912. }
  913. #endif
  914. return false;
  915. }
  916. bool
  917. SiS_IsVAMode(struct SiS_Private *SiS_Pr)
  918. {
  919. #ifdef CONFIG_FB_SIS_315
  920. unsigned short flag;
  921. if(SiS_Pr->ChipType >= SIS_315H) {
  922. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  923. if((flag & EnableDualEdge) && (flag & SetToLCDA)) return true;
  924. }
  925. #endif
  926. return false;
  927. }
  928. #ifdef CONFIG_FB_SIS_315
  929. static bool
  930. SiS_IsVAorLCD(struct SiS_Private *SiS_Pr)
  931. {
  932. if(SiS_IsVAMode(SiS_Pr)) return true;
  933. if(SiS_CRT2IsLCD(SiS_Pr)) return true;
  934. return false;
  935. }
  936. #endif
  937. static bool
  938. SiS_IsDualLink(struct SiS_Private *SiS_Pr)
  939. {
  940. #ifdef CONFIG_FB_SIS_315
  941. if(SiS_Pr->ChipType >= SIS_315H) {
  942. if((SiS_CRT2IsLCD(SiS_Pr)) ||
  943. (SiS_IsVAMode(SiS_Pr))) {
  944. if(SiS_Pr->SiS_LCDInfo & LCDDualLink) return true;
  945. }
  946. }
  947. #endif
  948. return false;
  949. }
  950. #ifdef CONFIG_FB_SIS_315
  951. static bool
  952. SiS_TVEnabled(struct SiS_Private *SiS_Pr)
  953. {
  954. if((SiS_GetReg(SiS_Pr->SiS_Part2Port,0x00) & 0x0f) != 0x0c) return true;
  955. if(SiS_Pr->SiS_VBType & VB_SISYPBPR) {
  956. if(SiS_GetReg(SiS_Pr->SiS_Part2Port,0x4d) & 0x10) return true;
  957. }
  958. return false;
  959. }
  960. #endif
  961. #ifdef CONFIG_FB_SIS_315
  962. static bool
  963. SiS_LCDAEnabled(struct SiS_Private *SiS_Pr)
  964. {
  965. if(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x13) & 0x04) return true;
  966. return false;
  967. }
  968. #endif
  969. #ifdef CONFIG_FB_SIS_315
  970. static bool
  971. SiS_WeHaveBacklightCtrl(struct SiS_Private *SiS_Pr)
  972. {
  973. if((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->ChipType < SIS_661)) {
  974. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x79) & 0x10) return true;
  975. }
  976. return false;
  977. }
  978. #endif
  979. #ifdef CONFIG_FB_SIS_315
  980. static bool
  981. SiS_IsNotM650orLater(struct SiS_Private *SiS_Pr)
  982. {
  983. unsigned short flag;
  984. if(SiS_Pr->ChipType == SIS_650) {
  985. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x5f) & 0xf0;
  986. /* Check for revision != A0 only */
  987. if((flag == 0xe0) || (flag == 0xc0) ||
  988. (flag == 0xb0) || (flag == 0x90)) return false;
  989. } else if(SiS_Pr->ChipType >= SIS_661) return false;
  990. return true;
  991. }
  992. #endif
  993. #ifdef CONFIG_FB_SIS_315
  994. static bool
  995. SiS_IsYPbPr(struct SiS_Private *SiS_Pr)
  996. {
  997. if(SiS_Pr->ChipType >= SIS_315H) {
  998. /* YPrPb = 0x08 */
  999. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x38) & EnableCHYPbPr) return true;
  1000. }
  1001. return false;
  1002. }
  1003. #endif
  1004. #ifdef CONFIG_FB_SIS_315
  1005. static bool
  1006. SiS_IsChScart(struct SiS_Private *SiS_Pr)
  1007. {
  1008. if(SiS_Pr->ChipType >= SIS_315H) {
  1009. /* Scart = 0x04 */
  1010. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x38) & EnableCHScart) return true;
  1011. }
  1012. return false;
  1013. }
  1014. #endif
  1015. #ifdef CONFIG_FB_SIS_315
  1016. static bool
  1017. SiS_IsTVOrYPbPrOrScart(struct SiS_Private *SiS_Pr)
  1018. {
  1019. unsigned short flag;
  1020. if(SiS_Pr->ChipType >= SIS_315H) {
  1021. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  1022. if(flag & SetCRT2ToTV) return true;
  1023. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  1024. if(flag & EnableCHYPbPr) return true; /* = YPrPb = 0x08 */
  1025. if(flag & EnableCHScart) return true; /* = Scart = 0x04 - TW */
  1026. } else {
  1027. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  1028. if(flag & SetCRT2ToTV) return true;
  1029. }
  1030. return false;
  1031. }
  1032. #endif
  1033. #ifdef CONFIG_FB_SIS_315
  1034. static bool
  1035. SiS_IsLCDOrLCDA(struct SiS_Private *SiS_Pr)
  1036. {
  1037. unsigned short flag;
  1038. if(SiS_Pr->ChipType >= SIS_315H) {
  1039. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  1040. if(flag & SetCRT2ToLCD) return true;
  1041. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  1042. if(flag & SetToLCDA) return true;
  1043. } else {
  1044. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  1045. if(flag & SetCRT2ToLCD) return true;
  1046. }
  1047. return false;
  1048. }
  1049. #endif
  1050. static bool
  1051. SiS_HaveBridge(struct SiS_Private *SiS_Pr)
  1052. {
  1053. unsigned short flag;
  1054. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  1055. return true;
  1056. } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
  1057. flag = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x00);
  1058. if((flag == 1) || (flag == 2)) return true;
  1059. }
  1060. return false;
  1061. }
  1062. static bool
  1063. SiS_BridgeIsEnabled(struct SiS_Private *SiS_Pr)
  1064. {
  1065. unsigned short flag;
  1066. if(SiS_HaveBridge(SiS_Pr)) {
  1067. flag = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00);
  1068. if(SiS_Pr->ChipType < SIS_315H) {
  1069. flag &= 0xa0;
  1070. if((flag == 0x80) || (flag == 0x20)) return true;
  1071. } else {
  1072. flag &= 0x50;
  1073. if((flag == 0x40) || (flag == 0x10)) return true;
  1074. }
  1075. }
  1076. return false;
  1077. }
  1078. static bool
  1079. SiS_BridgeInSlavemode(struct SiS_Private *SiS_Pr)
  1080. {
  1081. unsigned short flag1;
  1082. flag1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x31);
  1083. if(flag1 & (SetInSlaveMode >> 8)) return true;
  1084. return false;
  1085. }
  1086. /*********************************************/
  1087. /* GET VIDEO BRIDGE CONFIG INFO */
  1088. /*********************************************/
  1089. /* Setup general purpose IO for Chrontel communication */
  1090. #ifdef CONFIG_FB_SIS_300
  1091. void
  1092. SiS_SetChrontelGPIO(struct SiS_Private *SiS_Pr, unsigned short myvbinfo)
  1093. {
  1094. unsigned int acpibase;
  1095. unsigned short temp;
  1096. if(!(SiS_Pr->SiS_ChSW)) return;
  1097. acpibase = sisfb_read_lpc_pci_dword(SiS_Pr, 0x74);
  1098. acpibase &= 0xFFFF;
  1099. if(!acpibase) return;
  1100. temp = SiS_GetRegShort((acpibase + 0x3c)); /* ACPI register 0x3c: GP Event 1 I/O mode select */
  1101. temp &= 0xFEFF;
  1102. SiS_SetRegShort((acpibase + 0x3c), temp);
  1103. temp = SiS_GetRegShort((acpibase + 0x3c));
  1104. temp = SiS_GetRegShort((acpibase + 0x3a)); /* ACPI register 0x3a: GP Pin Level (low/high) */
  1105. temp &= 0xFEFF;
  1106. if(!(myvbinfo & SetCRT2ToTV)) temp |= 0x0100;
  1107. SiS_SetRegShort((acpibase + 0x3a), temp);
  1108. temp = SiS_GetRegShort((acpibase + 0x3a));
  1109. }
  1110. #endif
  1111. void
  1112. SiS_GetVBInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
  1113. unsigned short ModeIdIndex, int checkcrt2mode)
  1114. {
  1115. unsigned short tempax, tempbx, temp;
  1116. unsigned short modeflag, resinfo = 0;
  1117. SiS_Pr->SiS_SetFlag = 0;
  1118. modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
  1119. SiS_Pr->SiS_ModeType = modeflag & ModeTypeMask;
  1120. if((ModeNo > 0x13) && (!SiS_Pr->UseCustomMode)) {
  1121. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  1122. }
  1123. tempbx = 0;
  1124. if(SiS_HaveBridge(SiS_Pr)) {
  1125. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  1126. tempbx |= temp;
  1127. tempax = SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) << 8;
  1128. tempax &= (DriverMode | LoadDACFlag | SetNotSimuMode | SetPALTV);
  1129. tempbx |= tempax;
  1130. #ifdef CONFIG_FB_SIS_315
  1131. if(SiS_Pr->ChipType >= SIS_315H) {
  1132. if(SiS_Pr->SiS_VBType & VB_SISLCDA) {
  1133. if(ModeNo == 0x03) {
  1134. /* Mode 0x03 is never in driver mode */
  1135. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x31,0xbf);
  1136. }
  1137. if(!(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & (DriverMode >> 8))) {
  1138. /* Reset LCDA setting if not driver mode */
  1139. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x38,0xfc);
  1140. }
  1141. if(IS_SIS650) {
  1142. if(SiS_Pr->SiS_UseLCDA) {
  1143. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x5f) & 0xF0) {
  1144. if((ModeNo <= 0x13) || (!(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & (DriverMode >> 8)))) {
  1145. SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x38,(EnableDualEdge | SetToLCDA));
  1146. }
  1147. }
  1148. }
  1149. }
  1150. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  1151. if((temp & (EnableDualEdge | SetToLCDA)) == (EnableDualEdge | SetToLCDA)) {
  1152. tempbx |= SetCRT2ToLCDA;
  1153. }
  1154. }
  1155. if(SiS_Pr->ChipType >= SIS_661) { /* New CR layout */
  1156. tempbx &= ~(SetCRT2ToYPbPr525750 | SetCRT2ToHiVision);
  1157. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x38) & 0x04) {
  1158. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35) & 0xe0;
  1159. if(temp == 0x60) tempbx |= SetCRT2ToHiVision;
  1160. else if(SiS_Pr->SiS_VBType & VB_SISYPBPR) {
  1161. tempbx |= SetCRT2ToYPbPr525750;
  1162. }
  1163. }
  1164. }
  1165. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  1166. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  1167. if(temp & SetToLCDA) {
  1168. tempbx |= SetCRT2ToLCDA;
  1169. }
  1170. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  1171. if(temp & EnableCHYPbPr) {
  1172. tempbx |= SetCRT2ToCHYPbPr;
  1173. }
  1174. }
  1175. }
  1176. }
  1177. #endif /* CONFIG_FB_SIS_315 */
  1178. if(!(SiS_Pr->SiS_VBType & VB_SISVGA2)) {
  1179. tempbx &= ~(SetCRT2ToRAMDAC);
  1180. }
  1181. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  1182. temp = SetCRT2ToSVIDEO |
  1183. SetCRT2ToAVIDEO |
  1184. SetCRT2ToSCART |
  1185. SetCRT2ToLCDA |
  1186. SetCRT2ToLCD |
  1187. SetCRT2ToRAMDAC |
  1188. SetCRT2ToHiVision |
  1189. SetCRT2ToYPbPr525750;
  1190. } else {
  1191. if(SiS_Pr->ChipType >= SIS_315H) {
  1192. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  1193. temp = SetCRT2ToAVIDEO |
  1194. SetCRT2ToSVIDEO |
  1195. SetCRT2ToSCART |
  1196. SetCRT2ToLCDA |
  1197. SetCRT2ToLCD |
  1198. SetCRT2ToCHYPbPr;
  1199. } else {
  1200. temp = SetCRT2ToLCDA |
  1201. SetCRT2ToLCD;
  1202. }
  1203. } else {
  1204. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  1205. temp = SetCRT2ToTV | SetCRT2ToLCD;
  1206. } else {
  1207. temp = SetCRT2ToLCD;
  1208. }
  1209. }
  1210. }
  1211. if(!(tempbx & temp)) {
  1212. tempax = DisableCRT2Display;
  1213. tempbx = 0;
  1214. }
  1215. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  1216. unsigned short clearmask = ( DriverMode |
  1217. DisableCRT2Display |
  1218. LoadDACFlag |
  1219. SetNotSimuMode |
  1220. SetInSlaveMode |
  1221. SetPALTV |
  1222. SwitchCRT2 |
  1223. SetSimuScanMode );
  1224. if(tempbx & SetCRT2ToLCDA) tempbx &= (clearmask | SetCRT2ToLCDA);
  1225. if(tempbx & SetCRT2ToRAMDAC) tempbx &= (clearmask | SetCRT2ToRAMDAC);
  1226. if(tempbx & SetCRT2ToLCD) tempbx &= (clearmask | SetCRT2ToLCD);
  1227. if(tempbx & SetCRT2ToSCART) tempbx &= (clearmask | SetCRT2ToSCART);
  1228. if(tempbx & SetCRT2ToHiVision) tempbx &= (clearmask | SetCRT2ToHiVision);
  1229. if(tempbx & SetCRT2ToYPbPr525750) tempbx &= (clearmask | SetCRT2ToYPbPr525750);
  1230. } else {
  1231. if(SiS_Pr->ChipType >= SIS_315H) {
  1232. if(tempbx & SetCRT2ToLCDA) {
  1233. tempbx &= (0xFF00|SwitchCRT2|SetSimuScanMode);
  1234. }
  1235. }
  1236. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  1237. if(tempbx & SetCRT2ToTV) {
  1238. tempbx &= (0xFF00|SetCRT2ToTV|SwitchCRT2|SetSimuScanMode);
  1239. }
  1240. }
  1241. if(tempbx & SetCRT2ToLCD) {
  1242. tempbx &= (0xFF00|SetCRT2ToLCD|SwitchCRT2|SetSimuScanMode);
  1243. }
  1244. if(SiS_Pr->ChipType >= SIS_315H) {
  1245. if(tempbx & SetCRT2ToLCDA) {
  1246. tempbx |= SetCRT2ToLCD;
  1247. }
  1248. }
  1249. }
  1250. if(tempax & DisableCRT2Display) {
  1251. if(!(tempbx & (SwitchCRT2 | SetSimuScanMode))) {
  1252. tempbx = SetSimuScanMode | DisableCRT2Display;
  1253. }
  1254. }
  1255. if(!(tempbx & DriverMode)) tempbx |= SetSimuScanMode;
  1256. /* LVDS/CHRONTEL (LCD/TV) and 301BDH (LCD) can only be slave in 8bpp modes */
  1257. if(SiS_Pr->SiS_ModeType <= ModeVGA) {
  1258. if( (SiS_Pr->SiS_IF_DEF_LVDS == 1) ||
  1259. ((SiS_Pr->SiS_VBType & VB_NoLCD) && (tempbx & SetCRT2ToLCD)) ) {
  1260. modeflag &= (~CRT2Mode);
  1261. }
  1262. }
  1263. if(!(tempbx & SetSimuScanMode)) {
  1264. if(tempbx & SwitchCRT2) {
  1265. if((!(modeflag & CRT2Mode)) && (checkcrt2mode)) {
  1266. if(resinfo != SIS_RI_1600x1200) {
  1267. tempbx |= SetSimuScanMode;
  1268. }
  1269. }
  1270. } else {
  1271. if(SiS_BridgeIsEnabled(SiS_Pr)) {
  1272. if(!(tempbx & DriverMode)) {
  1273. if(SiS_BridgeInSlavemode(SiS_Pr)) {
  1274. tempbx |= SetSimuScanMode;
  1275. }
  1276. }
  1277. }
  1278. }
  1279. }
  1280. if(!(tempbx & DisableCRT2Display)) {
  1281. if(tempbx & DriverMode) {
  1282. if(tempbx & SetSimuScanMode) {
  1283. if((!(modeflag & CRT2Mode)) && (checkcrt2mode)) {
  1284. if(resinfo != SIS_RI_1600x1200) {
  1285. tempbx |= SetInSlaveMode;
  1286. }
  1287. }
  1288. }
  1289. } else {
  1290. tempbx |= SetInSlaveMode;
  1291. }
  1292. }
  1293. }
  1294. SiS_Pr->SiS_VBInfo = tempbx;
  1295. #ifdef CONFIG_FB_SIS_300
  1296. if(SiS_Pr->ChipType == SIS_630) {
  1297. SiS_SetChrontelGPIO(SiS_Pr, SiS_Pr->SiS_VBInfo);
  1298. }
  1299. #endif
  1300. #if 0
  1301. printk(KERN_DEBUG "sisfb: (init301: VBInfo= 0x%04x, SetFlag=0x%04x)\n",
  1302. SiS_Pr->SiS_VBInfo, SiS_Pr->SiS_SetFlag);
  1303. #endif
  1304. }
  1305. /*********************************************/
  1306. /* DETERMINE YPbPr MODE */
  1307. /*********************************************/
  1308. void
  1309. SiS_SetYPbPr(struct SiS_Private *SiS_Pr)
  1310. {
  1311. unsigned char temp;
  1312. /* Note: This variable is only used on 30xLV systems.
  1313. * CR38 has a different meaning on LVDS/CH7019 systems.
  1314. * On 661 and later, these bits moved to CR35.
  1315. *
  1316. * On 301, 301B, only HiVision 1080i is supported.
  1317. * On 30xLV, 301C, only YPbPr 1080i is supported.
  1318. */
  1319. SiS_Pr->SiS_YPbPr = 0;
  1320. if(SiS_Pr->ChipType >= SIS_661) return;
  1321. if(SiS_Pr->SiS_VBType) {
  1322. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  1323. SiS_Pr->SiS_YPbPr = YPbPrHiVision;
  1324. }
  1325. }
  1326. if(SiS_Pr->ChipType >= SIS_315H) {
  1327. if(SiS_Pr->SiS_VBType & VB_SISYPBPR) {
  1328. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  1329. if(temp & 0x08) {
  1330. switch((temp >> 4)) {
  1331. case 0x00: SiS_Pr->SiS_YPbPr = YPbPr525i; break;
  1332. case 0x01: SiS_Pr->SiS_YPbPr = YPbPr525p; break;
  1333. case 0x02: SiS_Pr->SiS_YPbPr = YPbPr750p; break;
  1334. case 0x03: SiS_Pr->SiS_YPbPr = YPbPrHiVision; break;
  1335. }
  1336. }
  1337. }
  1338. }
  1339. }
  1340. /*********************************************/
  1341. /* DETERMINE TVMode flag */
  1342. /*********************************************/
  1343. void
  1344. SiS_SetTVMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  1345. {
  1346. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  1347. unsigned short temp, temp1, resinfo = 0, romindex = 0;
  1348. unsigned char OutputSelect = *SiS_Pr->pSiS_OutputSelect;
  1349. SiS_Pr->SiS_TVMode = 0;
  1350. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) return;
  1351. if(SiS_Pr->UseCustomMode) return;
  1352. if(ModeNo > 0x13) {
  1353. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  1354. }
  1355. if(SiS_Pr->ChipType < SIS_661) {
  1356. if(SiS_Pr->SiS_VBInfo & SetPALTV) SiS_Pr->SiS_TVMode |= TVSetPAL;
  1357. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  1358. temp = 0;
  1359. if((SiS_Pr->ChipType == SIS_630) ||
  1360. (SiS_Pr->ChipType == SIS_730)) {
  1361. temp = 0x35;
  1362. romindex = 0xfe;
  1363. } else if(SiS_Pr->ChipType >= SIS_315H) {
  1364. temp = 0x38;
  1365. if(SiS_Pr->ChipType < XGI_20) {
  1366. romindex = 0xf3;
  1367. if(SiS_Pr->ChipType >= SIS_330) romindex = 0x11b;
  1368. }
  1369. }
  1370. if(temp) {
  1371. if(romindex && SiS_Pr->SiS_UseROM && (!(SiS_Pr->SiS_ROMNew))) {
  1372. OutputSelect = ROMAddr[romindex];
  1373. if(!(OutputSelect & EnablePALMN)) {
  1374. SiS_SetRegAND(SiS_Pr->SiS_P3d4,temp,0x3F);
  1375. }
  1376. }
  1377. temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,temp);
  1378. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  1379. if(temp1 & EnablePALM) { /* 0x40 */
  1380. SiS_Pr->SiS_TVMode |= TVSetPALM;
  1381. SiS_Pr->SiS_TVMode &= ~TVSetPAL;
  1382. } else if(temp1 & EnablePALN) { /* 0x80 */
  1383. SiS_Pr->SiS_TVMode |= TVSetPALN;
  1384. }
  1385. } else {
  1386. if(temp1 & EnableNTSCJ) { /* 0x40 */
  1387. SiS_Pr->SiS_TVMode |= TVSetNTSCJ;
  1388. }
  1389. }
  1390. }
  1391. /* Translate HiVision/YPbPr to our new flags */
  1392. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  1393. if(SiS_Pr->SiS_YPbPr == YPbPr750p) SiS_Pr->SiS_TVMode |= TVSetYPbPr750p;
  1394. else if(SiS_Pr->SiS_YPbPr == YPbPr525p) SiS_Pr->SiS_TVMode |= TVSetYPbPr525p;
  1395. else if(SiS_Pr->SiS_YPbPr == YPbPrHiVision) SiS_Pr->SiS_TVMode |= TVSetHiVision;
  1396. else SiS_Pr->SiS_TVMode |= TVSetYPbPr525i;
  1397. if(SiS_Pr->SiS_TVMode & (TVSetYPbPr750p | TVSetYPbPr525p | TVSetYPbPr525i)) {
  1398. SiS_Pr->SiS_VBInfo &= ~SetCRT2ToHiVision;
  1399. SiS_Pr->SiS_VBInfo |= SetCRT2ToYPbPr525750;
  1400. } else if(SiS_Pr->SiS_TVMode & TVSetHiVision) {
  1401. SiS_Pr->SiS_TVMode |= TVSetPAL;
  1402. }
  1403. }
  1404. } else if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  1405. if(SiS_Pr->SiS_CHOverScan) {
  1406. if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) {
  1407. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35);
  1408. if((temp & TVOverScan) || (SiS_Pr->SiS_CHOverScan == 1)) {
  1409. SiS_Pr->SiS_TVMode |= TVSetCHOverScan;
  1410. }
  1411. } else if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  1412. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x79);
  1413. if((temp & 0x80) || (SiS_Pr->SiS_CHOverScan == 1)) {
  1414. SiS_Pr->SiS_TVMode |= TVSetCHOverScan;
  1415. }
  1416. }
  1417. if(SiS_Pr->SiS_CHSOverScan) {
  1418. SiS_Pr->SiS_TVMode |= TVSetCHOverScan;
  1419. }
  1420. }
  1421. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  1422. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  1423. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  1424. if(temp & EnablePALM) SiS_Pr->SiS_TVMode |= TVSetPALM;
  1425. else if(temp & EnablePALN) SiS_Pr->SiS_TVMode |= TVSetPALN;
  1426. } else {
  1427. if(temp & EnableNTSCJ) {
  1428. SiS_Pr->SiS_TVMode |= TVSetNTSCJ;
  1429. }
  1430. }
  1431. }
  1432. }
  1433. } else { /* 661 and later */
  1434. temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35);
  1435. if(temp1 & 0x01) {
  1436. SiS_Pr->SiS_TVMode |= TVSetPAL;
  1437. if(temp1 & 0x08) {
  1438. SiS_Pr->SiS_TVMode |= TVSetPALN;
  1439. } else if(temp1 & 0x04) {
  1440. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  1441. SiS_Pr->SiS_TVMode &= ~TVSetPAL;
  1442. }
  1443. SiS_Pr->SiS_TVMode |= TVSetPALM;
  1444. }
  1445. } else {
  1446. if(temp1 & 0x02) {
  1447. SiS_Pr->SiS_TVMode |= TVSetNTSCJ;
  1448. }
  1449. }
  1450. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  1451. if(SiS_Pr->SiS_CHOverScan) {
  1452. if((temp1 & 0x10) || (SiS_Pr->SiS_CHOverScan == 1)) {
  1453. SiS_Pr->SiS_TVMode |= TVSetCHOverScan;
  1454. }
  1455. }
  1456. }
  1457. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  1458. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  1459. temp1 &= 0xe0;
  1460. if(temp1 == 0x00) SiS_Pr->SiS_TVMode |= TVSetYPbPr525i;
  1461. else if(temp1 == 0x20) SiS_Pr->SiS_TVMode |= TVSetYPbPr525p;
  1462. else if(temp1 == 0x40) SiS_Pr->SiS_TVMode |= TVSetYPbPr750p;
  1463. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  1464. SiS_Pr->SiS_TVMode |= (TVSetHiVision | TVSetPAL);
  1465. }
  1466. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToYPbPr525750 | SetCRT2ToHiVision)) {
  1467. if(resinfo == SIS_RI_800x480 || resinfo == SIS_RI_1024x576 || resinfo == SIS_RI_1280x720) {
  1468. SiS_Pr->SiS_TVMode |= TVAspect169;
  1469. } else {
  1470. temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x39);
  1471. if(temp1 & 0x02) {
  1472. if(SiS_Pr->SiS_TVMode & (TVSetYPbPr750p | TVSetHiVision)) {
  1473. SiS_Pr->SiS_TVMode |= TVAspect169;
  1474. } else {
  1475. SiS_Pr->SiS_TVMode |= TVAspect43LB;
  1476. }
  1477. } else {
  1478. SiS_Pr->SiS_TVMode |= TVAspect43;
  1479. }
  1480. }
  1481. }
  1482. }
  1483. }
  1484. if(SiS_Pr->SiS_VBInfo & SetCRT2ToSCART) SiS_Pr->SiS_TVMode |= TVSetPAL;
  1485. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  1486. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  1487. SiS_Pr->SiS_TVMode |= TVSetPAL;
  1488. SiS_Pr->SiS_TVMode &= ~(TVSetPALM | TVSetPALN | TVSetNTSCJ);
  1489. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  1490. if(SiS_Pr->SiS_TVMode & (TVSetYPbPr525i | TVSetYPbPr525p | TVSetYPbPr750p)) {
  1491. SiS_Pr->SiS_TVMode &= ~(TVSetPAL | TVSetNTSCJ | TVSetPALM | TVSetPALN);
  1492. }
  1493. }
  1494. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  1495. if(!(SiS_Pr->SiS_VBInfo & SetNotSimuMode)) {
  1496. SiS_Pr->SiS_TVMode |= TVSetTVSimuMode;
  1497. }
  1498. }
  1499. if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) {
  1500. if(resinfo == SIS_RI_1024x768) {
  1501. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) {
  1502. SiS_Pr->SiS_TVMode |= TVSet525p1024;
  1503. } else if(!(SiS_Pr->SiS_TVMode & (TVSetHiVision | TVSetYPbPr750p))) {
  1504. SiS_Pr->SiS_TVMode |= TVSetNTSC1024;
  1505. }
  1506. }
  1507. }
  1508. SiS_Pr->SiS_TVMode |= TVRPLLDIV2XO;
  1509. if((SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) &&
  1510. (SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  1511. SiS_Pr->SiS_TVMode &= ~TVRPLLDIV2XO;
  1512. } else if(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p)) {
  1513. SiS_Pr->SiS_TVMode &= ~TVRPLLDIV2XO;
  1514. } else if(!(SiS_Pr->SiS_VBType & VB_SIS30xBLV)) {
  1515. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) {
  1516. SiS_Pr->SiS_TVMode &= ~TVRPLLDIV2XO;
  1517. }
  1518. }
  1519. }
  1520. SiS_Pr->SiS_VBInfo &= ~SetPALTV;
  1521. }
  1522. /*********************************************/
  1523. /* GET LCD INFO */
  1524. /*********************************************/
  1525. static unsigned short
  1526. SiS_GetBIOSLCDResInfo(struct SiS_Private *SiS_Pr)
  1527. {
  1528. unsigned short temp = SiS_Pr->SiS_LCDResInfo;
  1529. /* Translate my LCDResInfo to BIOS value */
  1530. switch(temp) {
  1531. case Panel_1280x768_2: temp = Panel_1280x768; break;
  1532. case Panel_1280x800_2: temp = Panel_1280x800; break;
  1533. case Panel_1280x854: temp = Panel661_1280x854; break;
  1534. }
  1535. return temp;
  1536. }
  1537. static void
  1538. SiS_GetLCDInfoBIOS(struct SiS_Private *SiS_Pr)
  1539. {
  1540. #ifdef CONFIG_FB_SIS_315
  1541. unsigned char *ROMAddr;
  1542. unsigned short temp;
  1543. if((ROMAddr = GetLCDStructPtr661(SiS_Pr))) {
  1544. if((temp = SISGETROMW(6)) != SiS_Pr->PanelHT) {
  1545. SiS_Pr->SiS_NeedRomModeData = true;
  1546. SiS_Pr->PanelHT = temp;
  1547. }
  1548. if((temp = SISGETROMW(8)) != SiS_Pr->PanelVT) {
  1549. SiS_Pr->SiS_NeedRomModeData = true;
  1550. SiS_Pr->PanelVT = temp;
  1551. }
  1552. SiS_Pr->PanelHRS = SISGETROMW(10);
  1553. SiS_Pr->PanelHRE = SISGETROMW(12);
  1554. SiS_Pr->PanelVRS = SISGETROMW(14);
  1555. SiS_Pr->PanelVRE = SISGETROMW(16);
  1556. SiS_Pr->PanelVCLKIdx315 = VCLK_CUSTOM_315;
  1557. SiS_Pr->SiS_VCLKData[VCLK_CUSTOM_315].CLOCK =
  1558. SiS_Pr->SiS_VBVCLKData[VCLK_CUSTOM_315].CLOCK = (unsigned short)((unsigned char)ROMAddr[18]);
  1559. SiS_Pr->SiS_VCLKData[VCLK_CUSTOM_315].SR2B =
  1560. SiS_Pr->SiS_VBVCLKData[VCLK_CUSTOM_315].Part4_A = ROMAddr[19];
  1561. SiS_Pr->SiS_VCLKData[VCLK_CUSTOM_315].SR2C =
  1562. SiS_Pr->SiS_VBVCLKData[VCLK_CUSTOM_315].Part4_B = ROMAddr[20];
  1563. }
  1564. #endif
  1565. }
  1566. static void
  1567. SiS_CheckScaling(struct SiS_Private *SiS_Pr, unsigned short resinfo,
  1568. const unsigned char *nonscalingmodes)
  1569. {
  1570. int i = 0;
  1571. while(nonscalingmodes[i] != 0xff) {
  1572. if(nonscalingmodes[i++] == resinfo) {
  1573. if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) ||
  1574. (SiS_Pr->UsePanelScaler == -1)) {
  1575. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1576. }
  1577. break;
  1578. }
  1579. }
  1580. }
  1581. void
  1582. SiS_GetLCDResInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  1583. {
  1584. unsigned short temp,modeflag,resinfo=0,modexres=0,modeyres=0;
  1585. bool panelcanscale = false;
  1586. #ifdef CONFIG_FB_SIS_300
  1587. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  1588. static const unsigned char SiS300SeriesLCDRes[] =
  1589. { 0, 1, 2, 3, 7, 4, 5, 8,
  1590. 0, 0, 10, 0, 0, 0, 0, 15 };
  1591. #endif
  1592. #ifdef CONFIG_FB_SIS_315
  1593. unsigned char *myptr = NULL;
  1594. #endif
  1595. SiS_Pr->SiS_LCDResInfo = 0;
  1596. SiS_Pr->SiS_LCDTypeInfo = 0;
  1597. SiS_Pr->SiS_LCDInfo = 0;
  1598. SiS_Pr->PanelHRS = 999; /* HSync start */
  1599. SiS_Pr->PanelHRE = 999; /* HSync end */
  1600. SiS_Pr->PanelVRS = 999; /* VSync start */
  1601. SiS_Pr->PanelVRE = 999; /* VSync end */
  1602. SiS_Pr->SiS_NeedRomModeData = false;
  1603. /* Alternative 1600x1200@60 timing for 1600x1200 LCDA */
  1604. SiS_Pr->Alternate1600x1200 = false;
  1605. if(!(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA))) return;
  1606. modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
  1607. if((ModeNo > 0x13) && (!SiS_Pr->UseCustomMode)) {
  1608. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  1609. modexres = SiS_Pr->SiS_ModeResInfo[resinfo].HTotal;
  1610. modeyres = SiS_Pr->SiS_ModeResInfo[resinfo].VTotal;
  1611. }
  1612. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36);
  1613. /* For broken BIOSes: Assume 1024x768 */
  1614. if(temp == 0) temp = 0x02;
  1615. if((SiS_Pr->ChipType >= SIS_661) || (SiS_Pr->SiS_ROMNew)) {
  1616. SiS_Pr->SiS_LCDTypeInfo = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x39) & 0x7c) >> 2;
  1617. } else if((SiS_Pr->ChipType < SIS_315H) || (SiS_Pr->ChipType >= SIS_661)) {
  1618. SiS_Pr->SiS_LCDTypeInfo = temp >> 4;
  1619. } else {
  1620. SiS_Pr->SiS_LCDTypeInfo = (temp & 0x0F) - 1;
  1621. }
  1622. temp &= 0x0f;
  1623. #ifdef CONFIG_FB_SIS_300
  1624. if(SiS_Pr->ChipType < SIS_315H) {
  1625. /* Very old BIOSes only know 7 sizes (NetVista 2179, 1.01g) */
  1626. if(SiS_Pr->SiS_VBType & VB_SIS301) {
  1627. if(temp < 0x0f) temp &= 0x07;
  1628. }
  1629. /* Translate 300 series LCDRes to 315 series for unified usage */
  1630. temp = SiS300SeriesLCDRes[temp];
  1631. }
  1632. #endif
  1633. /* Translate to our internal types */
  1634. #ifdef CONFIG_FB_SIS_315
  1635. if(SiS_Pr->ChipType == SIS_550) {
  1636. if (temp == Panel310_1152x768) temp = Panel_320x240_2; /* Verified working */
  1637. else if(temp == Panel310_320x240_2) temp = Panel_320x240_2;
  1638. else if(temp == Panel310_320x240_3) temp = Panel_320x240_3;
  1639. } else if(SiS_Pr->ChipType >= SIS_661) {
  1640. if(temp == Panel661_1280x854) temp = Panel_1280x854;
  1641. }
  1642. #endif
  1643. if(SiS_Pr->SiS_VBType & VB_SISLVDS) { /* SiS LVDS */
  1644. if(temp == Panel310_1280x768) {
  1645. temp = Panel_1280x768_2;
  1646. }
  1647. if(SiS_Pr->SiS_ROMNew) {
  1648. if(temp == Panel661_1280x800) {
  1649. temp = Panel_1280x800_2;
  1650. }
  1651. }
  1652. }
  1653. SiS_Pr->SiS_LCDResInfo = temp;
  1654. #ifdef CONFIG_FB_SIS_300
  1655. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  1656. if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) {
  1657. SiS_Pr->SiS_LCDResInfo = Panel_Barco1366;
  1658. } else if(SiS_Pr->SiS_CustomT == CUT_PANEL848) {
  1659. SiS_Pr->SiS_LCDResInfo = Panel_848x480;
  1660. } else if(SiS_Pr->SiS_CustomT == CUT_PANEL856) {
  1661. SiS_Pr->SiS_LCDResInfo = Panel_856x480;
  1662. }
  1663. }
  1664. #endif
  1665. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  1666. if(SiS_Pr->SiS_LCDResInfo < SiS_Pr->SiS_PanelMin301)
  1667. SiS_Pr->SiS_LCDResInfo = SiS_Pr->SiS_PanelMin301;
  1668. } else {
  1669. if(SiS_Pr->SiS_LCDResInfo < SiS_Pr->SiS_PanelMinLVDS)
  1670. SiS_Pr->SiS_LCDResInfo = SiS_Pr->SiS_PanelMinLVDS;
  1671. }
  1672. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x37);
  1673. SiS_Pr->SiS_LCDInfo = temp & ~0x000e;
  1674. /* Need temp below! */
  1675. /* These must/can't scale no matter what */
  1676. switch(SiS_Pr->SiS_LCDResInfo) {
  1677. case Panel_320x240_1:
  1678. case Panel_320x240_2:
  1679. case Panel_320x240_3:
  1680. case Panel_1280x960:
  1681. SiS_Pr->SiS_LCDInfo &= ~DontExpandLCD;
  1682. break;
  1683. case Panel_640x480:
  1684. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1685. }
  1686. panelcanscale = (bool)(SiS_Pr->SiS_LCDInfo & DontExpandLCD);
  1687. if(!SiS_Pr->UsePanelScaler) SiS_Pr->SiS_LCDInfo &= ~DontExpandLCD;
  1688. else if(SiS_Pr->UsePanelScaler == 1) SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1689. /* Dual link, Pass 1:1 BIOS default, etc. */
  1690. #ifdef CONFIG_FB_SIS_315
  1691. if(SiS_Pr->ChipType >= SIS_661) {
  1692. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  1693. if(temp & 0x08) SiS_Pr->SiS_LCDInfo |= LCDPass11;
  1694. }
  1695. if(SiS_Pr->SiS_VBType & VB_SISDUALLINK) {
  1696. if(SiS_Pr->SiS_ROMNew) {
  1697. if(temp & 0x02) SiS_Pr->SiS_LCDInfo |= LCDDualLink;
  1698. } else if((myptr = GetLCDStructPtr661(SiS_Pr))) {
  1699. if(myptr[2] & 0x01) SiS_Pr->SiS_LCDInfo |= LCDDualLink;
  1700. }
  1701. }
  1702. } else if(SiS_Pr->ChipType >= SIS_315H) {
  1703. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  1704. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x39) & 0x01) SiS_Pr->SiS_LCDInfo |= LCDPass11;
  1705. }
  1706. if((SiS_Pr->SiS_ROMNew) && (!(SiS_Pr->PanelSelfDetected))) {
  1707. SiS_Pr->SiS_LCDInfo &= ~(LCDRGB18Bit);
  1708. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35);
  1709. if(temp & 0x01) SiS_Pr->SiS_LCDInfo |= LCDRGB18Bit;
  1710. if(SiS_Pr->SiS_VBType & VB_SISDUALLINK) {
  1711. if(temp & 0x02) SiS_Pr->SiS_LCDInfo |= LCDDualLink;
  1712. }
  1713. } else if(!(SiS_Pr->SiS_ROMNew)) {
  1714. if(SiS_Pr->SiS_VBType & VB_SISDUALLINK) {
  1715. if((SiS_Pr->SiS_CustomT == CUT_CLEVO1024) &&
  1716. (SiS_Pr->SiS_LCDResInfo == Panel_1024x768)) {
  1717. SiS_Pr->SiS_LCDInfo |= LCDDualLink;
  1718. }
  1719. if((SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) ||
  1720. (SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) ||
  1721. (SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) ||
  1722. (SiS_Pr->SiS_LCDResInfo == Panel_1680x1050)) {
  1723. SiS_Pr->SiS_LCDInfo |= LCDDualLink;
  1724. }
  1725. }
  1726. }
  1727. }
  1728. #endif
  1729. /* Pass 1:1 */
  1730. if((SiS_Pr->SiS_IF_DEF_LVDS == 1) || (SiS_Pr->SiS_VBType & VB_NoLCD)) {
  1731. /* Always center screen on LVDS (if scaling is disabled) */
  1732. SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  1733. } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
  1734. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  1735. /* Always center screen on SiS LVDS (if scaling is disabled) */
  1736. SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  1737. } else {
  1738. /* By default, pass 1:1 on SiS TMDS (if scaling is supported) */
  1739. if(panelcanscale) SiS_Pr->SiS_LCDInfo |= LCDPass11;
  1740. if(SiS_Pr->CenterScreen == 1) SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  1741. }
  1742. }
  1743. SiS_Pr->PanelVCLKIdx300 = VCLK65_300;
  1744. SiS_Pr->PanelVCLKIdx315 = VCLK108_2_315;
  1745. switch(SiS_Pr->SiS_LCDResInfo) {
  1746. case Panel_320x240_1:
  1747. case Panel_320x240_2:
  1748. case Panel_320x240_3: SiS_Pr->PanelXRes = 640; SiS_Pr->PanelYRes = 480;
  1749. SiS_Pr->PanelVRS = 24; SiS_Pr->PanelVRE = 3;
  1750. SiS_Pr->PanelVCLKIdx300 = VCLK28;
  1751. SiS_Pr->PanelVCLKIdx315 = VCLK28;
  1752. break;
  1753. case Panel_640x480: SiS_Pr->PanelXRes = 640; SiS_Pr->PanelYRes = 480;
  1754. SiS_Pr->PanelVRE = 3;
  1755. SiS_Pr->PanelVCLKIdx300 = VCLK28;
  1756. SiS_Pr->PanelVCLKIdx315 = VCLK28;
  1757. break;
  1758. case Panel_800x600: SiS_Pr->PanelXRes = 800; SiS_Pr->PanelYRes = 600;
  1759. SiS_Pr->PanelHT = 1056; SiS_Pr->PanelVT = 628;
  1760. SiS_Pr->PanelHRS = 40; SiS_Pr->PanelHRE = 128;
  1761. SiS_Pr->PanelVRS = 1; SiS_Pr->PanelVRE = 4;
  1762. SiS_Pr->PanelVCLKIdx300 = VCLK40;
  1763. SiS_Pr->PanelVCLKIdx315 = VCLK40;
  1764. break;
  1765. case Panel_1024x600: SiS_Pr->PanelXRes = 1024; SiS_Pr->PanelYRes = 600;
  1766. SiS_Pr->PanelHT = 1344; SiS_Pr->PanelVT = 800;
  1767. SiS_Pr->PanelHRS = 24; SiS_Pr->PanelHRE = 136;
  1768. SiS_Pr->PanelVRS = 2 /* 88 */ ; SiS_Pr->PanelVRE = 6;
  1769. SiS_Pr->PanelVCLKIdx300 = VCLK65_300;
  1770. SiS_Pr->PanelVCLKIdx315 = VCLK65_315;
  1771. break;
  1772. case Panel_1024x768: SiS_Pr->PanelXRes = 1024; SiS_Pr->PanelYRes = 768;
  1773. SiS_Pr->PanelHT = 1344; SiS_Pr->PanelVT = 806;
  1774. SiS_Pr->PanelHRS = 24; SiS_Pr->PanelHRE = 136;
  1775. SiS_Pr->PanelVRS = 3; SiS_Pr->PanelVRE = 6;
  1776. if(SiS_Pr->ChipType < SIS_315H) {
  1777. SiS_Pr->PanelHRS = 23;
  1778. SiS_Pr->PanelVRE = 5;
  1779. }
  1780. SiS_Pr->PanelVCLKIdx300 = VCLK65_300;
  1781. SiS_Pr->PanelVCLKIdx315 = VCLK65_315;
  1782. SiS_GetLCDInfoBIOS(SiS_Pr);
  1783. break;
  1784. case Panel_1152x768: SiS_Pr->PanelXRes = 1152; SiS_Pr->PanelYRes = 768;
  1785. SiS_Pr->PanelHT = 1344; SiS_Pr->PanelVT = 806;
  1786. SiS_Pr->PanelHRS = 24; SiS_Pr->PanelHRE = 136;
  1787. SiS_Pr->PanelVRS = 3; SiS_Pr->PanelVRE = 6;
  1788. if(SiS_Pr->ChipType < SIS_315H) {
  1789. SiS_Pr->PanelHRS = 23;
  1790. SiS_Pr->PanelVRE = 5;
  1791. }
  1792. SiS_Pr->PanelVCLKIdx300 = VCLK65_300;
  1793. SiS_Pr->PanelVCLKIdx315 = VCLK65_315;
  1794. break;
  1795. case Panel_1152x864: SiS_Pr->PanelXRes = 1152; SiS_Pr->PanelYRes = 864;
  1796. break;
  1797. case Panel_1280x720: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 720;
  1798. SiS_Pr->PanelHT = 1650; SiS_Pr->PanelVT = 750;
  1799. SiS_Pr->PanelHRS = 110; SiS_Pr->PanelHRE = 40;
  1800. SiS_Pr->PanelVRS = 5; SiS_Pr->PanelVRE = 5;
  1801. SiS_Pr->PanelVCLKIdx315 = VCLK_1280x720;
  1802. /* Data above for TMDS (projector); get from BIOS for LVDS */
  1803. SiS_GetLCDInfoBIOS(SiS_Pr);
  1804. break;
  1805. case Panel_1280x768: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 768;
  1806. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  1807. SiS_Pr->PanelHT = 1408; SiS_Pr->PanelVT = 806;
  1808. SiS_Pr->PanelVCLKIdx300 = VCLK81_300; /* ? */
  1809. SiS_Pr->PanelVCLKIdx315 = VCLK81_315; /* ? */
  1810. } else {
  1811. SiS_Pr->PanelHT = 1688; SiS_Pr->PanelVT = 802;
  1812. SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 112;
  1813. SiS_Pr->PanelVRS = 3; SiS_Pr->PanelVRE = 6;
  1814. SiS_Pr->PanelVCLKIdx300 = VCLK81_300;
  1815. SiS_Pr->PanelVCLKIdx315 = VCLK81_315;
  1816. }
  1817. break;
  1818. case Panel_1280x768_2: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 768;
  1819. SiS_Pr->PanelHT = 1660; SiS_Pr->PanelVT = 806;
  1820. SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 112;
  1821. SiS_Pr->PanelVRS = 3; SiS_Pr->PanelVRE = 6;
  1822. SiS_Pr->PanelVCLKIdx315 = VCLK_1280x768_2;
  1823. SiS_GetLCDInfoBIOS(SiS_Pr);
  1824. break;
  1825. case Panel_1280x800: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 800;
  1826. SiS_Pr->PanelHT = 1408; SiS_Pr->PanelVT = 816;
  1827. SiS_Pr->PanelHRS = 21; SiS_Pr->PanelHRE = 24;
  1828. SiS_Pr->PanelVRS = 4; SiS_Pr->PanelVRE = 3;
  1829. SiS_Pr->PanelVCLKIdx315 = VCLK_1280x800_315;
  1830. SiS_GetLCDInfoBIOS(SiS_Pr);
  1831. break;
  1832. case Panel_1280x800_2: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 800;
  1833. SiS_Pr->PanelHT = 1552; SiS_Pr->PanelVT = 812;
  1834. SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 112;
  1835. SiS_Pr->PanelVRS = 4; SiS_Pr->PanelVRE = 3;
  1836. SiS_Pr->PanelVCLKIdx315 = VCLK_1280x800_315_2;
  1837. SiS_GetLCDInfoBIOS(SiS_Pr);
  1838. break;
  1839. case Panel_1280x854: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 854;
  1840. SiS_Pr->PanelHT = 1664; SiS_Pr->PanelVT = 861;
  1841. SiS_Pr->PanelHRS = 16; SiS_Pr->PanelHRE = 112;
  1842. SiS_Pr->PanelVRS = 1; SiS_Pr->PanelVRE = 3;
  1843. SiS_Pr->PanelVCLKIdx315 = VCLK_1280x854;
  1844. SiS_GetLCDInfoBIOS(SiS_Pr);
  1845. break;
  1846. case Panel_1280x960: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 960;
  1847. SiS_Pr->PanelHT = 1800; SiS_Pr->PanelVT = 1000;
  1848. SiS_Pr->PanelVCLKIdx300 = VCLK108_3_300;
  1849. SiS_Pr->PanelVCLKIdx315 = VCLK108_3_315;
  1850. if(resinfo == SIS_RI_1280x1024) {
  1851. SiS_Pr->PanelVCLKIdx300 = VCLK100_300;
  1852. SiS_Pr->PanelVCLKIdx315 = VCLK100_315;
  1853. }
  1854. break;
  1855. case Panel_1280x1024: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 1024;
  1856. SiS_Pr->PanelHT = 1688; SiS_Pr->PanelVT = 1066;
  1857. SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 112;
  1858. SiS_Pr->PanelVRS = 1; SiS_Pr->PanelVRE = 3;
  1859. SiS_Pr->PanelVCLKIdx300 = VCLK108_3_300;
  1860. SiS_Pr->PanelVCLKIdx315 = VCLK108_2_315;
  1861. SiS_GetLCDInfoBIOS(SiS_Pr);
  1862. break;
  1863. case Panel_1400x1050: SiS_Pr->PanelXRes = 1400; SiS_Pr->PanelYRes = 1050;
  1864. SiS_Pr->PanelHT = 1688; SiS_Pr->PanelVT = 1066;
  1865. SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 112;
  1866. SiS_Pr->PanelVRS = 1; SiS_Pr->PanelVRE = 3;
  1867. SiS_Pr->PanelVCLKIdx315 = VCLK108_2_315;
  1868. SiS_GetLCDInfoBIOS(SiS_Pr);
  1869. break;
  1870. case Panel_1600x1200: SiS_Pr->PanelXRes = 1600; SiS_Pr->PanelYRes = 1200;
  1871. SiS_Pr->PanelHT = 2160; SiS_Pr->PanelVT = 1250;
  1872. SiS_Pr->PanelHRS = 64; SiS_Pr->PanelHRE = 192;
  1873. SiS_Pr->PanelVRS = 1; SiS_Pr->PanelVRE = 3;
  1874. SiS_Pr->PanelVCLKIdx315 = VCLK162_315;
  1875. if(SiS_Pr->SiS_VBType & VB_SISTMDSLCDA) {
  1876. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  1877. SiS_Pr->PanelHT = 1760; SiS_Pr->PanelVT = 1235;
  1878. SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 32;
  1879. SiS_Pr->PanelVRS = 2; SiS_Pr->PanelVRE = 4;
  1880. SiS_Pr->PanelVCLKIdx315 = VCLK130_315;
  1881. SiS_Pr->Alternate1600x1200 = true;
  1882. }
  1883. } else if(SiS_Pr->SiS_IF_DEF_LVDS) {
  1884. SiS_Pr->PanelHT = 2048; SiS_Pr->PanelVT = 1320;
  1885. SiS_Pr->PanelHRS = SiS_Pr->PanelHRE = 999;
  1886. SiS_Pr->PanelVRS = SiS_Pr->PanelVRE = 999;
  1887. }
  1888. SiS_GetLCDInfoBIOS(SiS_Pr);
  1889. break;
  1890. case Panel_1680x1050: SiS_Pr->PanelXRes = 1680; SiS_Pr->PanelYRes = 1050;
  1891. SiS_Pr->PanelHT = 1900; SiS_Pr->PanelVT = 1066;
  1892. SiS_Pr->PanelHRS = 26; SiS_Pr->PanelHRE = 76;
  1893. SiS_Pr->PanelVRS = 3; SiS_Pr->PanelVRE = 6;
  1894. SiS_Pr->PanelVCLKIdx315 = VCLK121_315;
  1895. SiS_GetLCDInfoBIOS(SiS_Pr);
  1896. break;
  1897. case Panel_Barco1366: SiS_Pr->PanelXRes = 1360; SiS_Pr->PanelYRes = 1024;
  1898. SiS_Pr->PanelHT = 1688; SiS_Pr->PanelVT = 1066;
  1899. break;
  1900. case Panel_848x480: SiS_Pr->PanelXRes = 848; SiS_Pr->PanelYRes = 480;
  1901. SiS_Pr->PanelHT = 1088; SiS_Pr->PanelVT = 525;
  1902. break;
  1903. case Panel_856x480: SiS_Pr->PanelXRes = 856; SiS_Pr->PanelYRes = 480;
  1904. SiS_Pr->PanelHT = 1088; SiS_Pr->PanelVT = 525;
  1905. break;
  1906. case Panel_Custom: SiS_Pr->PanelXRes = SiS_Pr->CP_MaxX;
  1907. SiS_Pr->PanelYRes = SiS_Pr->CP_MaxY;
  1908. SiS_Pr->PanelHT = SiS_Pr->CHTotal;
  1909. SiS_Pr->PanelVT = SiS_Pr->CVTotal;
  1910. if(SiS_Pr->CP_PreferredIndex != -1) {
  1911. SiS_Pr->PanelXRes = SiS_Pr->CP_HDisplay[SiS_Pr->CP_PreferredIndex];
  1912. SiS_Pr->PanelYRes = SiS_Pr->CP_VDisplay[SiS_Pr->CP_PreferredIndex];
  1913. SiS_Pr->PanelHT = SiS_Pr->CP_HTotal[SiS_Pr->CP_PreferredIndex];
  1914. SiS_Pr->PanelVT = SiS_Pr->CP_VTotal[SiS_Pr->CP_PreferredIndex];
  1915. SiS_Pr->PanelHRS = SiS_Pr->CP_HSyncStart[SiS_Pr->CP_PreferredIndex];
  1916. SiS_Pr->PanelHRE = SiS_Pr->CP_HSyncEnd[SiS_Pr->CP_PreferredIndex];
  1917. SiS_Pr->PanelVRS = SiS_Pr->CP_VSyncStart[SiS_Pr->CP_PreferredIndex];
  1918. SiS_Pr->PanelVRE = SiS_Pr->CP_VSyncEnd[SiS_Pr->CP_PreferredIndex];
  1919. SiS_Pr->PanelHRS -= SiS_Pr->PanelXRes;
  1920. SiS_Pr->PanelHRE -= SiS_Pr->PanelHRS;
  1921. SiS_Pr->PanelVRS -= SiS_Pr->PanelYRes;
  1922. SiS_Pr->PanelVRE -= SiS_Pr->PanelVRS;
  1923. if(SiS_Pr->CP_PrefClock) {
  1924. int idx;
  1925. SiS_Pr->PanelVCLKIdx315 = VCLK_CUSTOM_315;
  1926. SiS_Pr->PanelVCLKIdx300 = VCLK_CUSTOM_300;
  1927. if(SiS_Pr->ChipType < SIS_315H) idx = VCLK_CUSTOM_300;
  1928. else idx = VCLK_CUSTOM_315;
  1929. SiS_Pr->SiS_VCLKData[idx].CLOCK =
  1930. SiS_Pr->SiS_VBVCLKData[idx].CLOCK = SiS_Pr->CP_PrefClock;
  1931. SiS_Pr->SiS_VCLKData[idx].SR2B =
  1932. SiS_Pr->SiS_VBVCLKData[idx].Part4_A = SiS_Pr->CP_PrefSR2B;
  1933. SiS_Pr->SiS_VCLKData[idx].SR2C =
  1934. SiS_Pr->SiS_VBVCLKData[idx].Part4_B = SiS_Pr->CP_PrefSR2C;
  1935. }
  1936. }
  1937. break;
  1938. default: SiS_Pr->PanelXRes = 1024; SiS_Pr->PanelYRes = 768;
  1939. SiS_Pr->PanelHT = 1344; SiS_Pr->PanelVT = 806;
  1940. break;
  1941. }
  1942. /* Special cases */
  1943. if( (SiS_Pr->SiS_IF_DEF_FSTN) ||
  1944. (SiS_Pr->SiS_IF_DEF_DSTN) ||
  1945. (SiS_Pr->SiS_CustomT == CUT_BARCO1366) ||
  1946. (SiS_Pr->SiS_CustomT == CUT_BARCO1024) ||
  1947. (SiS_Pr->SiS_CustomT == CUT_PANEL848) ||
  1948. (SiS_Pr->SiS_CustomT == CUT_PANEL856) ) {
  1949. SiS_Pr->PanelHRS = 999;
  1950. SiS_Pr->PanelHRE = 999;
  1951. }
  1952. if( (SiS_Pr->SiS_CustomT == CUT_BARCO1366) ||
  1953. (SiS_Pr->SiS_CustomT == CUT_BARCO1024) ||
  1954. (SiS_Pr->SiS_CustomT == CUT_PANEL848) ||
  1955. (SiS_Pr->SiS_CustomT == CUT_PANEL856) ) {
  1956. SiS_Pr->PanelVRS = 999;
  1957. SiS_Pr->PanelVRE = 999;
  1958. }
  1959. /* DontExpand overrule */
  1960. if((SiS_Pr->SiS_VBType & VB_SISVB) && (!(SiS_Pr->SiS_VBType & VB_NoLCD))) {
  1961. if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && (modeflag & NoSupportLCDScale)) {
  1962. /* No scaling for this mode on any panel (LCD=CRT2)*/
  1963. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1964. }
  1965. switch(SiS_Pr->SiS_LCDResInfo) {
  1966. case Panel_Custom:
  1967. case Panel_1152x864:
  1968. case Panel_1280x768: /* TMDS only */
  1969. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1970. break;
  1971. case Panel_800x600: {
  1972. static const unsigned char nonscalingmodes[] = {
  1973. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, 0xff
  1974. };
  1975. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1976. break;
  1977. }
  1978. case Panel_1024x768: {
  1979. static const unsigned char nonscalingmodes[] = {
  1980. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1981. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1982. 0xff
  1983. };
  1984. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1985. break;
  1986. }
  1987. case Panel_1280x720: {
  1988. static const unsigned char nonscalingmodes[] = {
  1989. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1990. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1991. 0xff
  1992. };
  1993. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1994. if(SiS_Pr->PanelHT == 1650) {
  1995. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1996. }
  1997. break;
  1998. }
  1999. case Panel_1280x768_2: { /* LVDS only */
  2000. static const unsigned char nonscalingmodes[] = {
  2001. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  2002. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  2003. SIS_RI_1152x768,0xff
  2004. };
  2005. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  2006. switch(resinfo) {
  2007. case SIS_RI_1280x720: if(SiS_Pr->UsePanelScaler == -1) {
  2008. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  2009. }
  2010. break;
  2011. }
  2012. break;
  2013. }
  2014. case Panel_1280x800: { /* SiS TMDS special (Averatec 6200 series) */
  2015. static const unsigned char nonscalingmodes[] = {
  2016. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  2017. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  2018. SIS_RI_1152x768,SIS_RI_1280x720,SIS_RI_1280x768,0xff
  2019. };
  2020. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  2021. break;
  2022. }
  2023. case Panel_1280x800_2: { /* SiS LVDS */
  2024. static const unsigned char nonscalingmodes[] = {
  2025. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  2026. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  2027. SIS_RI_1152x768,0xff
  2028. };
  2029. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  2030. switch(resinfo) {
  2031. case SIS_RI_1280x720:
  2032. case SIS_RI_1280x768: if(SiS_Pr->UsePanelScaler == -1) {
  2033. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  2034. }
  2035. break;
  2036. }
  2037. break;
  2038. }
  2039. case Panel_1280x854: { /* SiS LVDS */
  2040. static const unsigned char nonscalingmodes[] = {
  2041. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  2042. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  2043. SIS_RI_1152x768,0xff
  2044. };
  2045. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  2046. switch(resinfo) {
  2047. case SIS_RI_1280x720:
  2048. case SIS_RI_1280x768:
  2049. case SIS_RI_1280x800: if(SiS_Pr->UsePanelScaler == -1) {
  2050. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  2051. }
  2052. break;
  2053. }
  2054. break;
  2055. }
  2056. case Panel_1280x960: {
  2057. static const unsigned char nonscalingmodes[] = {
  2058. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  2059. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  2060. SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x720,SIS_RI_1280x768,SIS_RI_1280x800,
  2061. SIS_RI_1280x854,0xff
  2062. };
  2063. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  2064. break;
  2065. }
  2066. case Panel_1280x1024: {
  2067. static const unsigned char nonscalingmodes[] = {
  2068. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  2069. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  2070. SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x720,SIS_RI_1280x768,SIS_RI_1280x800,
  2071. SIS_RI_1280x854,SIS_RI_1280x960,0xff
  2072. };
  2073. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  2074. break;
  2075. }
  2076. case Panel_1400x1050: {
  2077. static const unsigned char nonscalingmodes[] = {
  2078. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  2079. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  2080. SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x768,SIS_RI_1280x800,SIS_RI_1280x854,
  2081. SIS_RI_1280x960,0xff
  2082. };
  2083. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  2084. switch(resinfo) {
  2085. case SIS_RI_1280x720: if(SiS_Pr->UsePanelScaler == -1) {
  2086. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  2087. }
  2088. break;
  2089. case SIS_RI_1280x1024: SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  2090. break;
  2091. }
  2092. break;
  2093. }
  2094. case Panel_1600x1200: {
  2095. static const unsigned char nonscalingmodes[] = {
  2096. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  2097. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  2098. SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x720,SIS_RI_1280x768,SIS_RI_1280x800,
  2099. SIS_RI_1280x854,SIS_RI_1280x960,SIS_RI_1360x768,SIS_RI_1360x1024,0xff
  2100. };
  2101. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  2102. break;
  2103. }
  2104. case Panel_1680x1050: {
  2105. static const unsigned char nonscalingmodes[] = {
  2106. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  2107. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  2108. SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x854,SIS_RI_1280x960,SIS_RI_1360x768,
  2109. SIS_RI_1360x1024,0xff
  2110. };
  2111. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  2112. break;
  2113. }
  2114. }
  2115. }
  2116. #ifdef CONFIG_FB_SIS_300
  2117. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  2118. if(SiS_Pr->SiS_CustomT == CUT_PANEL848 || SiS_Pr->SiS_CustomT == CUT_PANEL856) {
  2119. SiS_Pr->SiS_LCDInfo = 0x80 | 0x40 | 0x20; /* neg h/v sync, RGB24(D0 = 0) */
  2120. }
  2121. }
  2122. if(SiS_Pr->ChipType < SIS_315H) {
  2123. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  2124. if(SiS_Pr->SiS_UseROM) {
  2125. if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) {
  2126. if(!(ROMAddr[0x235] & 0x02)) {
  2127. SiS_Pr->SiS_LCDInfo &= (~DontExpandLCD);
  2128. }
  2129. }
  2130. }
  2131. } else if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  2132. if((SiS_Pr->SiS_SetFlag & SetDOSMode) && ((ModeNo == 0x03) || (ModeNo == 0x10))) {
  2133. SiS_Pr->SiS_LCDInfo &= (~DontExpandLCD);
  2134. }
  2135. }
  2136. }
  2137. #endif
  2138. /* Special cases */
  2139. if(modexres == SiS_Pr->PanelXRes && modeyres == SiS_Pr->PanelYRes) {
  2140. SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  2141. }
  2142. if(SiS_Pr->SiS_IF_DEF_TRUMPION) {
  2143. SiS_Pr->SiS_LCDInfo |= (DontExpandLCD | LCDPass11);
  2144. }
  2145. switch(SiS_Pr->SiS_LCDResInfo) {
  2146. case Panel_640x480:
  2147. SiS_Pr->SiS_LCDInfo |= (DontExpandLCD | LCDPass11);
  2148. break;
  2149. case Panel_1280x800:
  2150. /* Don't pass 1:1 by default (TMDS special) */
  2151. if(SiS_Pr->CenterScreen == -1) SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  2152. break;
  2153. case Panel_1280x960:
  2154. SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  2155. break;
  2156. case Panel_Custom:
  2157. if((!SiS_Pr->CP_PrefClock) ||
  2158. (modexres > SiS_Pr->PanelXRes) || (modeyres > SiS_Pr->PanelYRes)) {
  2159. SiS_Pr->SiS_LCDInfo |= LCDPass11;
  2160. }
  2161. break;
  2162. }
  2163. if((SiS_Pr->UseCustomMode) || (SiS_Pr->SiS_CustomT == CUT_UNKNOWNLCD)) {
  2164. SiS_Pr->SiS_LCDInfo |= (DontExpandLCD | LCDPass11);
  2165. }
  2166. /* (In)validate LCDPass11 flag */
  2167. if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
  2168. SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  2169. }
  2170. /* LVDS DDA */
  2171. if(!((SiS_Pr->ChipType < SIS_315H) && (SiS_Pr->SiS_SetFlag & SetDOSMode))) {
  2172. if((SiS_Pr->SiS_IF_DEF_LVDS == 1) || (SiS_Pr->SiS_VBType & VB_NoLCD)) {
  2173. if(SiS_Pr->SiS_IF_DEF_TRUMPION == 0) {
  2174. if(ModeNo == 0x12) {
  2175. if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
  2176. SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
  2177. }
  2178. } else if(ModeNo > 0x13) {
  2179. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x600) {
  2180. if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
  2181. if((resinfo == SIS_RI_800x600) || (resinfo == SIS_RI_400x300)) {
  2182. SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
  2183. }
  2184. }
  2185. }
  2186. }
  2187. }
  2188. }
  2189. if(modeflag & HalfDCLK) {
  2190. if(SiS_Pr->SiS_IF_DEF_TRUMPION == 1) {
  2191. SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
  2192. } else if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  2193. SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
  2194. } else if(SiS_Pr->SiS_LCDResInfo == Panel_640x480) {
  2195. SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
  2196. } else if(ModeNo > 0x13) {
  2197. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  2198. if(resinfo == SIS_RI_512x384) SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
  2199. } else if(SiS_Pr->SiS_LCDResInfo == Panel_800x600) {
  2200. if(resinfo == SIS_RI_400x300) SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
  2201. }
  2202. }
  2203. }
  2204. }
  2205. /* VESA timing */
  2206. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  2207. if(SiS_Pr->SiS_VBInfo & SetNotSimuMode) {
  2208. SiS_Pr->SiS_SetFlag |= LCDVESATiming;
  2209. }
  2210. } else {
  2211. SiS_Pr->SiS_SetFlag |= LCDVESATiming;
  2212. }
  2213. #if 0
  2214. printk(KERN_DEBUG "sisfb: (LCDInfo=0x%04x LCDResInfo=0x%02x LCDTypeInfo=0x%02x)\n",
  2215. SiS_Pr->SiS_LCDInfo, SiS_Pr->SiS_LCDResInfo, SiS_Pr->SiS_LCDTypeInfo);
  2216. #endif
  2217. }
  2218. /*********************************************/
  2219. /* GET VCLK */
  2220. /*********************************************/
  2221. unsigned short
  2222. SiS_GetVCLK2Ptr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  2223. unsigned short RefreshRateTableIndex)
  2224. {
  2225. unsigned short CRT2Index, VCLKIndex = 0, VCLKIndexGEN = 0, VCLKIndexGENCRT = 0;
  2226. unsigned short resinfo, tempbx;
  2227. const unsigned char *CHTVVCLKPtr = NULL;
  2228. if(ModeNo <= 0x13) {
  2229. resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
  2230. CRT2Index = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  2231. VCLKIndexGEN = (SiS_GetRegByte((SiS_Pr->SiS_P3ca+0x02)) >> 2) & 0x03;
  2232. VCLKIndexGENCRT = VCLKIndexGEN;
  2233. } else {
  2234. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  2235. CRT2Index = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  2236. VCLKIndexGEN = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
  2237. VCLKIndexGENCRT = SiS_GetRefCRTVCLK(SiS_Pr, RefreshRateTableIndex,
  2238. (SiS_Pr->SiS_SetFlag & ProgrammingCRT2) ? SiS_Pr->SiS_UseWideCRT2 : SiS_Pr->SiS_UseWide);
  2239. }
  2240. if(SiS_Pr->SiS_VBType & VB_SISVB) { /* 30x/B/LV */
  2241. if(SiS_Pr->SiS_SetFlag & ProgrammingCRT2) {
  2242. CRT2Index >>= 6;
  2243. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { /* LCD */
  2244. if(SiS_Pr->ChipType < SIS_315H) {
  2245. VCLKIndex = SiS_Pr->PanelVCLKIdx300;
  2246. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  2247. VCLKIndex = VCLKIndexGEN;
  2248. }
  2249. } else {
  2250. VCLKIndex = SiS_Pr->PanelVCLKIdx315;
  2251. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  2252. switch(resinfo) {
  2253. /* Correct those whose IndexGEN doesn't match VBVCLK array */
  2254. case SIS_RI_720x480: VCLKIndex = VCLK_720x480; break;
  2255. case SIS_RI_720x576: VCLKIndex = VCLK_720x576; break;
  2256. case SIS_RI_768x576: VCLKIndex = VCLK_768x576; break;
  2257. case SIS_RI_848x480: VCLKIndex = VCLK_848x480; break;
  2258. case SIS_RI_856x480: VCLKIndex = VCLK_856x480; break;
  2259. case SIS_RI_800x480: VCLKIndex = VCLK_800x480; break;
  2260. case SIS_RI_1024x576: VCLKIndex = VCLK_1024x576; break;
  2261. case SIS_RI_1152x864: VCLKIndex = VCLK_1152x864; break;
  2262. case SIS_RI_1280x720: VCLKIndex = VCLK_1280x720; break;
  2263. case SIS_RI_1360x768: VCLKIndex = VCLK_1360x768; break;
  2264. default: VCLKIndex = VCLKIndexGEN;
  2265. }
  2266. if(ModeNo <= 0x13) {
  2267. if(SiS_Pr->ChipType <= SIS_315PRO) {
  2268. if(SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC == 1) VCLKIndex = 0x42;
  2269. } else {
  2270. if(SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC == 1) VCLKIndex = 0x00;
  2271. }
  2272. }
  2273. if(SiS_Pr->ChipType <= SIS_315PRO) {
  2274. if(VCLKIndex == 0) VCLKIndex = 0x41;
  2275. if(VCLKIndex == 1) VCLKIndex = 0x43;
  2276. if(VCLKIndex == 4) VCLKIndex = 0x44;
  2277. }
  2278. }
  2279. }
  2280. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { /* TV */
  2281. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  2282. if(SiS_Pr->SiS_TVMode & TVRPLLDIV2XO) VCLKIndex = HiTVVCLKDIV2;
  2283. else VCLKIndex = HiTVVCLK;
  2284. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) VCLKIndex = HiTVSimuVCLK;
  2285. } else if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) VCLKIndex = YPbPr750pVCLK;
  2286. else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) VCLKIndex = TVVCLKDIV2;
  2287. else if(SiS_Pr->SiS_TVMode & TVRPLLDIV2XO) VCLKIndex = TVVCLKDIV2;
  2288. else VCLKIndex = TVVCLK;
  2289. if(SiS_Pr->ChipType < SIS_315H) VCLKIndex += TVCLKBASE_300;
  2290. else VCLKIndex += TVCLKBASE_315;
  2291. } else { /* VGA2 */
  2292. VCLKIndex = VCLKIndexGENCRT;
  2293. if(SiS_Pr->ChipType < SIS_315H) {
  2294. if(ModeNo > 0x13) {
  2295. if( (SiS_Pr->ChipType == SIS_630) &&
  2296. (SiS_Pr->ChipRevision >= 0x30)) {
  2297. if(VCLKIndex == 0x14) VCLKIndex = 0x34;
  2298. }
  2299. /* Better VGA2 clock for 1280x1024@75 */
  2300. if(VCLKIndex == 0x17) VCLKIndex = 0x45;
  2301. }
  2302. }
  2303. }
  2304. } else { /* If not programming CRT2 */
  2305. VCLKIndex = VCLKIndexGENCRT;
  2306. if(SiS_Pr->ChipType < SIS_315H) {
  2307. if(ModeNo > 0x13) {
  2308. if( (SiS_Pr->ChipType != SIS_630) &&
  2309. (SiS_Pr->ChipType != SIS_300) ) {
  2310. if(VCLKIndex == 0x1b) VCLKIndex = 0x48;
  2311. }
  2312. }
  2313. }
  2314. }
  2315. } else { /* LVDS */
  2316. VCLKIndex = CRT2Index;
  2317. if(SiS_Pr->SiS_SetFlag & ProgrammingCRT2) {
  2318. if( (SiS_Pr->SiS_IF_DEF_CH70xx != 0) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV) ) {
  2319. VCLKIndex &= 0x1f;
  2320. tempbx = 0;
  2321. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx += 1;
  2322. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  2323. tempbx += 2;
  2324. if(SiS_Pr->SiS_ModeType > ModeVGA) {
  2325. if(SiS_Pr->SiS_CHSOverScan) tempbx = 8;
  2326. }
  2327. if(SiS_Pr->SiS_TVMode & TVSetPALM) {
  2328. tempbx = 4;
  2329. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx += 1;
  2330. } else if(SiS_Pr->SiS_TVMode & TVSetPALN) {
  2331. tempbx = 6;
  2332. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx += 1;
  2333. }
  2334. }
  2335. switch(tempbx) {
  2336. case 0: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKUNTSC; break;
  2337. case 1: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKONTSC; break;
  2338. case 2: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKUPAL; break;
  2339. case 3: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKOPAL; break;
  2340. case 4: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKUPALM; break;
  2341. case 5: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKOPALM; break;
  2342. case 6: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKUPALN; break;
  2343. case 7: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKOPALN; break;
  2344. case 8: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKSOPAL; break;
  2345. default: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKOPAL; break;
  2346. }
  2347. VCLKIndex = CHTVVCLKPtr[VCLKIndex];
  2348. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  2349. if(SiS_Pr->ChipType < SIS_315H) {
  2350. VCLKIndex = SiS_Pr->PanelVCLKIdx300;
  2351. } else {
  2352. VCLKIndex = SiS_Pr->PanelVCLKIdx315;
  2353. }
  2354. #ifdef CONFIG_FB_SIS_300
  2355. /* Special Timing: Barco iQ Pro R series */
  2356. if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) VCLKIndex = 0x44;
  2357. /* Special Timing: 848x480 and 856x480 parallel lvds panels */
  2358. if(SiS_Pr->SiS_CustomT == CUT_PANEL848 || SiS_Pr->SiS_CustomT == CUT_PANEL856) {
  2359. if(SiS_Pr->ChipType < SIS_315H) {
  2360. VCLKIndex = VCLK34_300;
  2361. /* if(resinfo == SIS_RI_1360x768) VCLKIndex = ?; */
  2362. } else {
  2363. VCLKIndex = VCLK34_315;
  2364. /* if(resinfo == SIS_RI_1360x768) VCLKIndex = ?; */
  2365. }
  2366. }
  2367. #endif
  2368. } else {
  2369. VCLKIndex = VCLKIndexGENCRT;
  2370. if(SiS_Pr->ChipType < SIS_315H) {
  2371. if(ModeNo > 0x13) {
  2372. if( (SiS_Pr->ChipType == SIS_630) &&
  2373. (SiS_Pr->ChipRevision >= 0x30) ) {
  2374. if(VCLKIndex == 0x14) VCLKIndex = 0x2e;
  2375. }
  2376. }
  2377. }
  2378. }
  2379. } else { /* if not programming CRT2 */
  2380. VCLKIndex = VCLKIndexGENCRT;
  2381. if(SiS_Pr->ChipType < SIS_315H) {
  2382. if(ModeNo > 0x13) {
  2383. if( (SiS_Pr->ChipType != SIS_630) &&
  2384. (SiS_Pr->ChipType != SIS_300) ) {
  2385. if(VCLKIndex == 0x1b) VCLKIndex = 0x48;
  2386. }
  2387. #if 0
  2388. if(SiS_Pr->ChipType == SIS_730) {
  2389. if(VCLKIndex == 0x0b) VCLKIndex = 0x40; /* 1024x768-70 */
  2390. if(VCLKIndex == 0x0d) VCLKIndex = 0x41; /* 1024x768-75 */
  2391. }
  2392. #endif
  2393. }
  2394. }
  2395. }
  2396. }
  2397. return VCLKIndex;
  2398. }
  2399. /*********************************************/
  2400. /* SET CRT2 MODE TYPE REGISTERS */
  2401. /*********************************************/
  2402. static void
  2403. SiS_SetCRT2ModeRegs(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  2404. {
  2405. unsigned short i, j, modeflag, tempah=0;
  2406. short tempcl;
  2407. #if defined(CONFIG_FB_SIS_300) || defined(CONFIG_FB_SIS_315)
  2408. unsigned short tempbl;
  2409. #endif
  2410. #ifdef CONFIG_FB_SIS_315
  2411. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  2412. unsigned short tempah2, tempbl2;
  2413. #endif
  2414. modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
  2415. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  2416. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x00,0xAF,0x40);
  2417. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2E,0xF7);
  2418. } else {
  2419. for(i=0,j=4; i<3; i++,j++) SiS_SetReg(SiS_Pr->SiS_Part1Port,j,0);
  2420. if(SiS_Pr->ChipType >= SIS_315H) {
  2421. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x02,0x7F);
  2422. }
  2423. tempcl = SiS_Pr->SiS_ModeType;
  2424. if(SiS_Pr->ChipType < SIS_315H) {
  2425. #ifdef CONFIG_FB_SIS_300 /* ---- 300 series ---- */
  2426. /* For 301BDH: (with LCD via LVDS) */
  2427. if(SiS_Pr->SiS_VBType & VB_NoLCD) {
  2428. tempbl = SiS_GetReg(SiS_Pr->SiS_P3c4,0x32);
  2429. tempbl &= 0xef;
  2430. tempbl |= 0x02;
  2431. if((SiS_Pr->SiS_VBInfo & SetCRT2ToTV) || (SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) {
  2432. tempbl |= 0x10;
  2433. tempbl &= 0xfd;
  2434. }
  2435. SiS_SetReg(SiS_Pr->SiS_P3c4,0x32,tempbl);
  2436. }
  2437. if(ModeNo > 0x13) {
  2438. tempcl -= ModeVGA;
  2439. if(tempcl >= 0) {
  2440. tempah = ((0x10 >> tempcl) | 0x80);
  2441. }
  2442. } else tempah = 0x80;
  2443. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) tempah ^= 0xA0;
  2444. #endif /* CONFIG_FB_SIS_300 */
  2445. } else {
  2446. #ifdef CONFIG_FB_SIS_315 /* ------- 315/330 series ------ */
  2447. if(ModeNo > 0x13) {
  2448. tempcl -= ModeVGA;
  2449. if(tempcl >= 0) {
  2450. tempah = (0x08 >> tempcl);
  2451. if (tempah == 0) tempah = 1;
  2452. tempah |= 0x40;
  2453. }
  2454. } else tempah = 0x40;
  2455. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) tempah ^= 0x50;
  2456. #endif /* CONFIG_FB_SIS_315 */
  2457. }
  2458. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 0;
  2459. if(SiS_Pr->ChipType < SIS_315H) {
  2460. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,tempah);
  2461. } else {
  2462. #ifdef CONFIG_FB_SIS_315
  2463. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  2464. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x00,0xa0,tempah);
  2465. } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
  2466. if(IS_SIS740) {
  2467. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,tempah);
  2468. } else {
  2469. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x00,0xa0,tempah);
  2470. }
  2471. }
  2472. #endif
  2473. }
  2474. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  2475. tempah = 0x01;
  2476. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  2477. tempah |= 0x02;
  2478. }
  2479. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) {
  2480. tempah ^= 0x05;
  2481. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) {
  2482. tempah ^= 0x01;
  2483. }
  2484. }
  2485. if(SiS_Pr->ChipType < SIS_315H) {
  2486. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 0;
  2487. tempah = (tempah << 5) & 0xFF;
  2488. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x01,tempah);
  2489. tempah = (tempah >> 5) & 0xFF;
  2490. } else {
  2491. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 0x08;
  2492. else if(!(SiS_IsDualEdge(SiS_Pr))) tempah |= 0x08;
  2493. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2E,0xF0,tempah);
  2494. tempah &= ~0x08;
  2495. }
  2496. if((SiS_Pr->SiS_ModeType == ModeVGA) && (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode))) {
  2497. tempah |= 0x10;
  2498. }
  2499. tempah |= 0x80;
  2500. if(SiS_Pr->SiS_VBType & VB_SIS301) {
  2501. if(SiS_Pr->PanelXRes < 1280 && SiS_Pr->PanelYRes < 960) tempah &= ~0x80;
  2502. }
  2503. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  2504. if(!(SiS_Pr->SiS_TVMode & (TVSetYPbPr750p | TVSetYPbPr525p))) {
  2505. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  2506. tempah |= 0x20;
  2507. }
  2508. }
  2509. }
  2510. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x0D,0x40,tempah);
  2511. tempah = 0x80;
  2512. if(SiS_Pr->SiS_VBType & VB_SIS301) {
  2513. if(SiS_Pr->PanelXRes < 1280 && SiS_Pr->PanelYRes < 960) tempah = 0;
  2514. }
  2515. if(SiS_IsDualLink(SiS_Pr)) tempah |= 0x40;
  2516. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  2517. if(SiS_Pr->SiS_TVMode & TVRPLLDIV2XO) {
  2518. tempah |= 0x40;
  2519. }
  2520. }
  2521. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0C,tempah);
  2522. } else { /* LVDS */
  2523. if(SiS_Pr->ChipType >= SIS_315H) {
  2524. #ifdef CONFIG_FB_SIS_315
  2525. /* LVDS can only be slave in 8bpp modes */
  2526. tempah = 0x80;
  2527. if((modeflag & CRT2Mode) && (SiS_Pr->SiS_ModeType > ModeVGA)) {
  2528. if(SiS_Pr->SiS_VBInfo & DriverMode) {
  2529. tempah |= 0x02;
  2530. }
  2531. }
  2532. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) tempah |= 0x02;
  2533. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) tempah ^= 0x01;
  2534. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 1;
  2535. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2e,0xF0,tempah);
  2536. #endif
  2537. } else {
  2538. #ifdef CONFIG_FB_SIS_300
  2539. tempah = 0;
  2540. if( (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) && (SiS_Pr->SiS_ModeType > ModeVGA) ) {
  2541. tempah |= 0x02;
  2542. }
  2543. tempah <<= 5;
  2544. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 0;
  2545. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x01,tempah);
  2546. #endif
  2547. }
  2548. }
  2549. } /* LCDA */
  2550. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  2551. if(SiS_Pr->ChipType >= SIS_315H) {
  2552. #ifdef CONFIG_FB_SIS_315
  2553. /* unsigned char bridgerev = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x01); */
  2554. /* The following is nearly unpreditable and varies from machine
  2555. * to machine. Especially the 301DH seems to be a real trouble
  2556. * maker. Some BIOSes simply set the registers (like in the
  2557. * NoLCD-if-statements here), some set them according to the
  2558. * LCDA stuff. It is very likely that some machines are not
  2559. * treated correctly in the following, very case-orientated
  2560. * code. What do I do then...?
  2561. */
  2562. /* 740 variants match for 30xB, 301B-DH, 30xLV */
  2563. if(!(IS_SIS740)) {
  2564. tempah = 0x04; /* For all bridges */
  2565. tempbl = 0xfb;
  2566. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  2567. tempah = 0x00;
  2568. if(SiS_IsDualEdge(SiS_Pr)) {
  2569. tempbl = 0xff;
  2570. }
  2571. }
  2572. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,tempbl,tempah);
  2573. }
  2574. /* The following two are responsible for eventually wrong colors
  2575. * in TV output. The DH (VB_NoLCD) conditions are unknown; the
  2576. * b0 was found in some 651 machine (Pim; P4_23=0xe5); the b1 version
  2577. * in a 650 box (Jake). What is the criteria?
  2578. * Addendum: Another combination 651+301B-DH(b1) (Rapo) needs same
  2579. * treatment like the 651+301B-DH(b0) case. Seems more to be the
  2580. * chipset than the bridge revision.
  2581. */
  2582. if((IS_SIS740) || (SiS_Pr->ChipType >= SIS_661) || (SiS_Pr->SiS_ROMNew)) {
  2583. tempah = 0x30;
  2584. tempbl = 0xc0;
  2585. if((SiS_Pr->SiS_VBInfo & DisableCRT2Display) ||
  2586. ((SiS_Pr->SiS_ROMNew) && (!(ROMAddr[0x5b] & 0x04)))) {
  2587. tempah = 0x00;
  2588. tempbl = 0x00;
  2589. }
  2590. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2c,0xcf,tempah);
  2591. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x21,0x3f,tempbl);
  2592. } else if(SiS_Pr->SiS_VBType & VB_SIS301) {
  2593. /* Fixes "TV-blue-bug" on 315+301 */
  2594. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2c,0xcf); /* For 301 */
  2595. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x21,0x3f);
  2596. } else if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  2597. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2c,0x30); /* For 30xLV */
  2598. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x21,0xc0);
  2599. } else if(SiS_Pr->SiS_VBType & VB_NoLCD) { /* For 301B-DH */
  2600. tempah = 0x30; tempah2 = 0xc0;
  2601. tempbl = 0xcf; tempbl2 = 0x3f;
  2602. if(SiS_Pr->SiS_TVBlue == 0) {
  2603. tempah = tempah2 = 0x00;
  2604. } else if(SiS_Pr->SiS_TVBlue == -1) {
  2605. /* Set on 651/M650, clear on 315/650 */
  2606. if(!(IS_SIS65x)) /* (bridgerev != 0xb0) */ {
  2607. tempah = tempah2 = 0x00;
  2608. }
  2609. }
  2610. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2c,tempbl,tempah);
  2611. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x21,tempbl2,tempah2);
  2612. } else {
  2613. tempah = 0x30; tempah2 = 0xc0; /* For 30xB, 301C */
  2614. tempbl = 0xcf; tempbl2 = 0x3f;
  2615. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  2616. tempah = tempah2 = 0x00;
  2617. if(SiS_IsDualEdge(SiS_Pr)) {
  2618. tempbl = tempbl2 = 0xff;
  2619. }
  2620. }
  2621. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2c,tempbl,tempah);
  2622. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x21,tempbl2,tempah2);
  2623. }
  2624. if(IS_SIS740) {
  2625. tempah = 0x80;
  2626. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 0x00;
  2627. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x23,0x7f,tempah);
  2628. } else {
  2629. tempah = 0x00;
  2630. tempbl = 0x7f;
  2631. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  2632. tempbl = 0xff;
  2633. if(!(SiS_IsDualEdge(SiS_Pr))) tempah = 0x80;
  2634. }
  2635. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x23,tempbl,tempah);
  2636. }
  2637. #endif /* CONFIG_FB_SIS_315 */
  2638. } else if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  2639. #ifdef CONFIG_FB_SIS_300
  2640. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x21,0x3f);
  2641. if((SiS_Pr->SiS_VBInfo & DisableCRT2Display) ||
  2642. ((SiS_Pr->SiS_VBType & VB_NoLCD) &&
  2643. (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD))) {
  2644. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x23,0x7F);
  2645. } else {
  2646. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x23,0x80);
  2647. }
  2648. #endif
  2649. }
  2650. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  2651. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x0D,0x80);
  2652. if(SiS_Pr->SiS_VBType & VB_SIS30xCLV) {
  2653. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x3A,0xC0);
  2654. }
  2655. }
  2656. } else { /* LVDS */
  2657. #ifdef CONFIG_FB_SIS_315
  2658. if(SiS_Pr->ChipType >= SIS_315H) {
  2659. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  2660. tempah = 0x04;
  2661. tempbl = 0xfb;
  2662. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  2663. tempah = 0x00;
  2664. if(SiS_IsDualEdge(SiS_Pr)) tempbl = 0xff;
  2665. }
  2666. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,tempbl,tempah);
  2667. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) {
  2668. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xfb);
  2669. }
  2670. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2c,0x30);
  2671. } else if(SiS_Pr->ChipType == SIS_550) {
  2672. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xfb);
  2673. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2c,0x30);
  2674. }
  2675. }
  2676. #endif
  2677. }
  2678. }
  2679. /*********************************************/
  2680. /* GET RESOLUTION DATA */
  2681. /*********************************************/
  2682. unsigned short
  2683. SiS_GetResInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  2684. {
  2685. if(ModeNo <= 0x13)
  2686. return ((unsigned short)SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo);
  2687. else
  2688. return ((unsigned short)SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO);
  2689. }
  2690. static void
  2691. SiS_GetCRT2ResInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  2692. {
  2693. unsigned short xres, yres, modeflag=0, resindex;
  2694. if(SiS_Pr->UseCustomMode) {
  2695. xres = SiS_Pr->CHDisplay;
  2696. if(SiS_Pr->CModeFlag & HalfDCLK) xres <<= 1;
  2697. SiS_Pr->SiS_VGAHDE = SiS_Pr->SiS_HDE = xres;
  2698. /* DoubleScanMode-check done in CheckCalcCustomMode()! */
  2699. SiS_Pr->SiS_VGAVDE = SiS_Pr->SiS_VDE = SiS_Pr->CVDisplay;
  2700. return;
  2701. }
  2702. resindex = SiS_GetResInfo(SiS_Pr,ModeNo,ModeIdIndex);
  2703. if(ModeNo <= 0x13) {
  2704. xres = SiS_Pr->SiS_StResInfo[resindex].HTotal;
  2705. yres = SiS_Pr->SiS_StResInfo[resindex].VTotal;
  2706. } else {
  2707. xres = SiS_Pr->SiS_ModeResInfo[resindex].HTotal;
  2708. yres = SiS_Pr->SiS_ModeResInfo[resindex].VTotal;
  2709. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  2710. }
  2711. if(!SiS_Pr->SiS_IF_DEF_DSTN && !SiS_Pr->SiS_IF_DEF_FSTN) {
  2712. if((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->SiS_IF_DEF_LVDS == 1)) {
  2713. if((ModeNo != 0x03) && (SiS_Pr->SiS_SetFlag & SetDOSMode)) {
  2714. if(yres == 350) yres = 400;
  2715. }
  2716. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x3a) & 0x01) {
  2717. if(ModeNo == 0x12) yres = 400;
  2718. }
  2719. }
  2720. if(modeflag & HalfDCLK) xres <<= 1;
  2721. if(modeflag & DoubleScanMode) yres <<= 1;
  2722. }
  2723. if((SiS_Pr->SiS_VBType & VB_SISVB) && (!(SiS_Pr->SiS_VBType & VB_NoLCD))) {
  2724. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  2725. switch(SiS_Pr->SiS_LCDResInfo) {
  2726. case Panel_1024x768:
  2727. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
  2728. if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
  2729. if(yres == 350) yres = 357;
  2730. if(yres == 400) yres = 420;
  2731. if(yres == 480) yres = 525;
  2732. }
  2733. }
  2734. break;
  2735. case Panel_1280x1024:
  2736. if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
  2737. /* BIOS bug - does this regardless of scaling */
  2738. if(yres == 400) yres = 405;
  2739. }
  2740. if(yres == 350) yres = 360;
  2741. if(SiS_Pr->SiS_SetFlag & LCDVESATiming) {
  2742. if(yres == 360) yres = 375;
  2743. }
  2744. break;
  2745. case Panel_1600x1200:
  2746. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
  2747. if(yres == 1024) yres = 1056;
  2748. }
  2749. break;
  2750. }
  2751. }
  2752. } else {
  2753. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  2754. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToHiVision)) {
  2755. if(xres == 720) xres = 640;
  2756. }
  2757. } else if(xres == 720) xres = 640;
  2758. if(SiS_Pr->SiS_SetFlag & SetDOSMode) {
  2759. yres = 400;
  2760. if(SiS_Pr->ChipType >= SIS_315H) {
  2761. if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x17) & 0x80) yres = 480;
  2762. } else {
  2763. if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x80) yres = 480;
  2764. }
  2765. if(SiS_Pr->SiS_IF_DEF_DSTN || SiS_Pr->SiS_IF_DEF_FSTN) yres = 480;
  2766. }
  2767. }
  2768. SiS_Pr->SiS_VGAHDE = SiS_Pr->SiS_HDE = xres;
  2769. SiS_Pr->SiS_VGAVDE = SiS_Pr->SiS_VDE = yres;
  2770. }
  2771. /*********************************************/
  2772. /* GET CRT2 TIMING DATA */
  2773. /*********************************************/
  2774. static void
  2775. SiS_GetCRT2Ptr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  2776. unsigned short RefreshRateTableIndex, unsigned short *CRT2Index,
  2777. unsigned short *ResIndex)
  2778. {
  2779. unsigned short tempbx=0, tempal=0, resinfo=0;
  2780. if(ModeNo <= 0x13) {
  2781. tempal = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  2782. } else {
  2783. tempal = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  2784. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  2785. }
  2786. if((SiS_Pr->SiS_VBType & VB_SISVB) && (SiS_Pr->SiS_IF_DEF_LVDS == 0)) {
  2787. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { /* LCD */
  2788. tempbx = SiS_Pr->SiS_LCDResInfo;
  2789. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) tempbx += 32;
  2790. /* patch index */
  2791. if(SiS_Pr->SiS_LCDResInfo == Panel_1680x1050) {
  2792. if (resinfo == SIS_RI_1280x800) tempal = 9;
  2793. else if(resinfo == SIS_RI_1400x1050) tempal = 11;
  2794. } else if((SiS_Pr->SiS_LCDResInfo == Panel_1280x800) ||
  2795. (SiS_Pr->SiS_LCDResInfo == Panel_1280x800_2) ||
  2796. (SiS_Pr->SiS_LCDResInfo == Panel_1280x854)) {
  2797. if (resinfo == SIS_RI_1280x768) tempal = 9;
  2798. }
  2799. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  2800. /* Pass 1:1 only (center-screen handled outside) */
  2801. /* This is never called for the panel's native resolution */
  2802. /* since Pass1:1 will not be set in this case */
  2803. tempbx = 100;
  2804. if(ModeNo >= 0x13) {
  2805. tempal = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC_NS;
  2806. }
  2807. }
  2808. #ifdef CONFIG_FB_SIS_315
  2809. if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) {
  2810. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) {
  2811. if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
  2812. tempbx = 200;
  2813. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) tempbx++;
  2814. }
  2815. }
  2816. }
  2817. #endif
  2818. } else { /* TV */
  2819. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  2820. /* if(SiS_Pr->SiS_VGAVDE > 480) SiS_Pr->SiS_TVMode &= (~TVSetTVSimuMode); */
  2821. tempbx = 2;
  2822. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  2823. tempbx = 13;
  2824. if(!(SiS_Pr->SiS_TVMode & TVSetTVSimuMode)) tempbx = 14;
  2825. }
  2826. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  2827. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) tempbx = 7;
  2828. else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) tempbx = 6;
  2829. else tempbx = 5;
  2830. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) tempbx += 5;
  2831. } else {
  2832. if(SiS_Pr->SiS_TVMode & TVSetPAL) tempbx = 3;
  2833. else tempbx = 4;
  2834. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) tempbx += 5;
  2835. }
  2836. }
  2837. tempal &= 0x3F;
  2838. if(ModeNo > 0x13) {
  2839. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoHiVision) {
  2840. switch(resinfo) {
  2841. case SIS_RI_720x480:
  2842. tempal = 6;
  2843. if(SiS_Pr->SiS_TVMode & (TVSetPAL | TVSetPALN)) tempal = 9;
  2844. break;
  2845. case SIS_RI_720x576:
  2846. case SIS_RI_768x576:
  2847. case SIS_RI_1024x576: /* Not in NTSC or YPBPR mode (except 1080i)! */
  2848. tempal = 6;
  2849. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  2850. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) tempal = 8;
  2851. }
  2852. break;
  2853. case SIS_RI_800x480:
  2854. tempal = 4;
  2855. break;
  2856. case SIS_RI_512x384:
  2857. case SIS_RI_1024x768:
  2858. tempal = 7;
  2859. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  2860. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) tempal = 8;
  2861. }
  2862. break;
  2863. case SIS_RI_1280x720:
  2864. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  2865. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) tempal = 9;
  2866. }
  2867. break;
  2868. }
  2869. }
  2870. }
  2871. *CRT2Index = tempbx;
  2872. *ResIndex = tempal;
  2873. } else { /* LVDS, 301B-DH (if running on LCD) */
  2874. tempbx = 0;
  2875. if((SiS_Pr->SiS_IF_DEF_CH70xx) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
  2876. tempbx = 90;
  2877. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  2878. tempbx = 92;
  2879. if(SiS_Pr->SiS_ModeType > ModeVGA) {
  2880. if(SiS_Pr->SiS_CHSOverScan) tempbx = 99;
  2881. }
  2882. if(SiS_Pr->SiS_TVMode & TVSetPALM) tempbx = 94;
  2883. else if(SiS_Pr->SiS_TVMode & TVSetPALN) tempbx = 96;
  2884. }
  2885. if(tempbx != 99) {
  2886. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx++;
  2887. }
  2888. } else {
  2889. switch(SiS_Pr->SiS_LCDResInfo) {
  2890. case Panel_640x480: tempbx = 12; break;
  2891. case Panel_320x240_1: tempbx = 10; break;
  2892. case Panel_320x240_2:
  2893. case Panel_320x240_3: tempbx = 14; break;
  2894. case Panel_800x600: tempbx = 16; break;
  2895. case Panel_1024x600: tempbx = 18; break;
  2896. case Panel_1152x768:
  2897. case Panel_1024x768: tempbx = 20; break;
  2898. case Panel_1280x768: tempbx = 22; break;
  2899. case Panel_1280x1024: tempbx = 24; break;
  2900. case Panel_1400x1050: tempbx = 26; break;
  2901. case Panel_1600x1200: tempbx = 28; break;
  2902. #ifdef CONFIG_FB_SIS_300
  2903. case Panel_Barco1366: tempbx = 80; break;
  2904. #endif
  2905. }
  2906. switch(SiS_Pr->SiS_LCDResInfo) {
  2907. case Panel_320x240_1:
  2908. case Panel_320x240_2:
  2909. case Panel_320x240_3:
  2910. case Panel_640x480:
  2911. break;
  2912. default:
  2913. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++;
  2914. }
  2915. if(SiS_Pr->SiS_LCDInfo & LCDPass11) tempbx = 30;
  2916. #ifdef CONFIG_FB_SIS_300
  2917. if(SiS_Pr->SiS_CustomT == CUT_BARCO1024) {
  2918. tempbx = 82;
  2919. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++;
  2920. } else if(SiS_Pr->SiS_CustomT == CUT_PANEL848 || SiS_Pr->SiS_CustomT == CUT_PANEL856) {
  2921. tempbx = 84;
  2922. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++;
  2923. }
  2924. #endif
  2925. }
  2926. (*CRT2Index) = tempbx;
  2927. (*ResIndex) = tempal & 0x1F;
  2928. }
  2929. }
  2930. static void
  2931. SiS_GetRAMDAC2DATA(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  2932. unsigned short RefreshRateTableIndex)
  2933. {
  2934. unsigned short tempax=0, tempbx=0, index, dotclock;
  2935. unsigned short temp1=0, modeflag=0, tempcx=0;
  2936. SiS_Pr->SiS_RVBHCMAX = 1;
  2937. SiS_Pr->SiS_RVBHCFACT = 1;
  2938. if(ModeNo <= 0x13) {
  2939. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  2940. index = SiS_GetModePtr(SiS_Pr,ModeNo,ModeIdIndex);
  2941. tempax = SiS_Pr->SiS_StandTable[index].CRTC[0];
  2942. tempbx = SiS_Pr->SiS_StandTable[index].CRTC[6];
  2943. temp1 = SiS_Pr->SiS_StandTable[index].CRTC[7];
  2944. dotclock = (modeflag & Charx8Dot) ? 8 : 9;
  2945. } else {
  2946. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  2947. index = SiS_GetRefCRT1CRTC(SiS_Pr, RefreshRateTableIndex, SiS_Pr->SiS_UseWideCRT2);
  2948. tempax = SiS_Pr->SiS_CRT1Table[index].CR[0];
  2949. tempax |= (SiS_Pr->SiS_CRT1Table[index].CR[14] << 8);
  2950. tempax &= 0x03FF;
  2951. tempbx = SiS_Pr->SiS_CRT1Table[index].CR[6];
  2952. tempcx = SiS_Pr->SiS_CRT1Table[index].CR[13] << 8;
  2953. tempcx &= 0x0100;
  2954. tempcx <<= 2;
  2955. tempbx |= tempcx;
  2956. temp1 = SiS_Pr->SiS_CRT1Table[index].CR[7];
  2957. dotclock = 8;
  2958. }
  2959. if(temp1 & 0x01) tempbx |= 0x0100;
  2960. if(temp1 & 0x20) tempbx |= 0x0200;
  2961. tempax += 5;
  2962. tempax *= dotclock;
  2963. if(modeflag & HalfDCLK) tempax <<= 1;
  2964. tempbx++;
  2965. SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_HT = tempax;
  2966. SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_VT = tempbx;
  2967. }
  2968. static void
  2969. SiS_CalcPanelLinkTiming(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
  2970. unsigned short ModeIdIndex, unsigned short RefreshRateTableIndex)
  2971. {
  2972. unsigned short ResIndex;
  2973. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  2974. if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
  2975. if(SiS_Pr->UseCustomMode) {
  2976. ResIndex = SiS_Pr->CHTotal;
  2977. if(SiS_Pr->CModeFlag & HalfDCLK) ResIndex <<= 1;
  2978. SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_HT = ResIndex;
  2979. SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_VT = SiS_Pr->CVTotal;
  2980. } else {
  2981. if(ModeNo < 0x13) {
  2982. ResIndex = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  2983. } else {
  2984. ResIndex = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC_NS;
  2985. }
  2986. if(ResIndex == 0x09) {
  2987. if(SiS_Pr->Alternate1600x1200) ResIndex = 0x20; /* 1600x1200 LCDA */
  2988. else if(SiS_Pr->SiS_IF_DEF_LVDS == 1) ResIndex = 0x21; /* 1600x1200 LVDS */
  2989. }
  2990. SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_NoScaleData[ResIndex].VGAHT;
  2991. SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_NoScaleData[ResIndex].VGAVT;
  2992. SiS_Pr->SiS_HT = SiS_Pr->SiS_NoScaleData[ResIndex].LCDHT;
  2993. SiS_Pr->SiS_VT = SiS_Pr->SiS_NoScaleData[ResIndex].LCDVT;
  2994. }
  2995. } else {
  2996. SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_HT = SiS_Pr->PanelHT;
  2997. SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_VT = SiS_Pr->PanelVT;
  2998. }
  2999. } else {
  3000. /* This handles custom modes and custom panels */
  3001. SiS_Pr->SiS_HDE = SiS_Pr->PanelXRes;
  3002. SiS_Pr->SiS_VDE = SiS_Pr->PanelYRes;
  3003. SiS_Pr->SiS_HT = SiS_Pr->PanelHT;
  3004. SiS_Pr->SiS_VT = SiS_Pr->PanelVT;
  3005. SiS_Pr->SiS_VGAHT = SiS_Pr->PanelHT - (SiS_Pr->PanelXRes - SiS_Pr->SiS_VGAHDE);
  3006. SiS_Pr->SiS_VGAVT = SiS_Pr->PanelVT - (SiS_Pr->PanelYRes - SiS_Pr->SiS_VGAVDE);
  3007. }
  3008. }
  3009. static void
  3010. SiS_GetCRT2DataLVDS(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  3011. unsigned short RefreshRateTableIndex)
  3012. {
  3013. unsigned short CRT2Index, ResIndex, backup;
  3014. const struct SiS_LVDSData *LVDSData = NULL;
  3015. SiS_GetCRT2ResInfo(SiS_Pr, ModeNo, ModeIdIndex);
  3016. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  3017. SiS_Pr->SiS_RVBHCMAX = 1;
  3018. SiS_Pr->SiS_RVBHCFACT = 1;
  3019. SiS_Pr->SiS_NewFlickerMode = 0;
  3020. SiS_Pr->SiS_RVBHRS = 50;
  3021. SiS_Pr->SiS_RY1COE = 0;
  3022. SiS_Pr->SiS_RY2COE = 0;
  3023. SiS_Pr->SiS_RY3COE = 0;
  3024. SiS_Pr->SiS_RY4COE = 0;
  3025. SiS_Pr->SiS_RVBHRS2 = 0;
  3026. }
  3027. if((SiS_Pr->SiS_VBType & VB_SISVB) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  3028. #ifdef CONFIG_FB_SIS_315
  3029. SiS_CalcPanelLinkTiming(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  3030. SiS_CalcLCDACRT1Timing(SiS_Pr, ModeNo, ModeIdIndex);
  3031. #endif
  3032. } else {
  3033. /* 301BDH needs LVDS Data */
  3034. backup = SiS_Pr->SiS_IF_DEF_LVDS;
  3035. if((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) {
  3036. SiS_Pr->SiS_IF_DEF_LVDS = 1;
  3037. }
  3038. SiS_GetCRT2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex,
  3039. &CRT2Index, &ResIndex);
  3040. SiS_Pr->SiS_IF_DEF_LVDS = backup;
  3041. switch(CRT2Index) {
  3042. case 10: LVDSData = SiS_Pr->SiS_LVDS320x240Data_1; break;
  3043. case 14: LVDSData = SiS_Pr->SiS_LVDS320x240Data_2; break;
  3044. case 12: LVDSData = SiS_Pr->SiS_LVDS640x480Data_1; break;
  3045. case 16: LVDSData = SiS_Pr->SiS_LVDS800x600Data_1; break;
  3046. case 18: LVDSData = SiS_Pr->SiS_LVDS1024x600Data_1; break;
  3047. case 20: LVDSData = SiS_Pr->SiS_LVDS1024x768Data_1; break;
  3048. #ifdef CONFIG_FB_SIS_300
  3049. case 80: LVDSData = SiS_Pr->SiS_LVDSBARCO1366Data_1; break;
  3050. case 81: LVDSData = SiS_Pr->SiS_LVDSBARCO1366Data_2; break;
  3051. case 82: LVDSData = SiS_Pr->SiS_LVDSBARCO1024Data_1; break;
  3052. case 84: LVDSData = SiS_Pr->SiS_LVDS848x480Data_1; break;
  3053. case 85: LVDSData = SiS_Pr->SiS_LVDS848x480Data_2; break;
  3054. #endif
  3055. case 90: LVDSData = SiS_Pr->SiS_CHTVUNTSCData; break;
  3056. case 91: LVDSData = SiS_Pr->SiS_CHTVONTSCData; break;
  3057. case 92: LVDSData = SiS_Pr->SiS_CHTVUPALData; break;
  3058. case 93: LVDSData = SiS_Pr->SiS_CHTVOPALData; break;
  3059. case 94: LVDSData = SiS_Pr->SiS_CHTVUPALMData; break;
  3060. case 95: LVDSData = SiS_Pr->SiS_CHTVOPALMData; break;
  3061. case 96: LVDSData = SiS_Pr->SiS_CHTVUPALNData; break;
  3062. case 97: LVDSData = SiS_Pr->SiS_CHTVOPALNData; break;
  3063. case 99: LVDSData = SiS_Pr->SiS_CHTVSOPALData; break;
  3064. }
  3065. if(LVDSData) {
  3066. SiS_Pr->SiS_VGAHT = (LVDSData+ResIndex)->VGAHT;
  3067. SiS_Pr->SiS_VGAVT = (LVDSData+ResIndex)->VGAVT;
  3068. SiS_Pr->SiS_HT = (LVDSData+ResIndex)->LCDHT;
  3069. SiS_Pr->SiS_VT = (LVDSData+ResIndex)->LCDVT;
  3070. } else {
  3071. SiS_CalcPanelLinkTiming(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  3072. }
  3073. if( (!(SiS_Pr->SiS_VBType & VB_SISVB)) &&
  3074. (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) &&
  3075. (!(SiS_Pr->SiS_LCDInfo & LCDPass11)) ) {
  3076. if( (!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) ||
  3077. (SiS_Pr->SiS_SetFlag & SetDOSMode) ) {
  3078. SiS_Pr->SiS_HDE = SiS_Pr->PanelXRes;
  3079. SiS_Pr->SiS_VDE = SiS_Pr->PanelYRes;
  3080. #ifdef CONFIG_FB_SIS_300
  3081. if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) {
  3082. if(ResIndex < 0x08) {
  3083. SiS_Pr->SiS_HDE = 1280;
  3084. SiS_Pr->SiS_VDE = 1024;
  3085. }
  3086. }
  3087. #endif
  3088. }
  3089. }
  3090. }
  3091. }
  3092. static void
  3093. SiS_GetCRT2Data301(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  3094. unsigned short RefreshRateTableIndex)
  3095. {
  3096. unsigned char *ROMAddr = NULL;
  3097. unsigned short tempax, tempbx, modeflag, romptr=0;
  3098. unsigned short resinfo, CRT2Index, ResIndex;
  3099. const struct SiS_LCDData *LCDPtr = NULL;
  3100. const struct SiS_TVData *TVPtr = NULL;
  3101. #ifdef CONFIG_FB_SIS_315
  3102. short resinfo661;
  3103. #endif
  3104. if(ModeNo <= 0x13) {
  3105. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  3106. resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
  3107. } else if(SiS_Pr->UseCustomMode) {
  3108. modeflag = SiS_Pr->CModeFlag;
  3109. resinfo = 0;
  3110. } else {
  3111. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  3112. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  3113. #ifdef CONFIG_FB_SIS_315
  3114. resinfo661 = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].ROMMODEIDX661;
  3115. if( (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) &&
  3116. (SiS_Pr->SiS_SetFlag & LCDVESATiming) &&
  3117. (resinfo661 >= 0) &&
  3118. (SiS_Pr->SiS_NeedRomModeData) ) {
  3119. if((ROMAddr = GetLCDStructPtr661(SiS_Pr))) {
  3120. if((romptr = (SISGETROMW(21)))) {
  3121. romptr += (resinfo661 * 10);
  3122. ROMAddr = SiS_Pr->VirtualRomBase;
  3123. }
  3124. }
  3125. }
  3126. #endif
  3127. }
  3128. SiS_Pr->SiS_NewFlickerMode = 0;
  3129. SiS_Pr->SiS_RVBHRS = 50;
  3130. SiS_Pr->SiS_RY1COE = 0;
  3131. SiS_Pr->SiS_RY2COE = 0;
  3132. SiS_Pr->SiS_RY3COE = 0;
  3133. SiS_Pr->SiS_RY4COE = 0;
  3134. SiS_Pr->SiS_RVBHRS2 = 0;
  3135. SiS_GetCRT2ResInfo(SiS_Pr,ModeNo,ModeIdIndex);
  3136. if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) {
  3137. if(SiS_Pr->UseCustomMode) {
  3138. SiS_Pr->SiS_RVBHCMAX = 1;
  3139. SiS_Pr->SiS_RVBHCFACT = 1;
  3140. SiS_Pr->SiS_HDE = SiS_Pr->SiS_VGAHDE;
  3141. SiS_Pr->SiS_VDE = SiS_Pr->SiS_VGAVDE;
  3142. tempax = SiS_Pr->CHTotal;
  3143. if(modeflag & HalfDCLK) tempax <<= 1;
  3144. SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_HT = tempax;
  3145. SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_VT = SiS_Pr->CVTotal;
  3146. } else {
  3147. SiS_GetRAMDAC2DATA(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  3148. }
  3149. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  3150. SiS_GetCRT2Ptr(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex,
  3151. &CRT2Index,&ResIndex);
  3152. switch(CRT2Index) {
  3153. case 2: TVPtr = SiS_Pr->SiS_ExtHiTVData; break;
  3154. case 3: TVPtr = SiS_Pr->SiS_ExtPALData; break;
  3155. case 4: TVPtr = SiS_Pr->SiS_ExtNTSCData; break;
  3156. case 5: TVPtr = SiS_Pr->SiS_Ext525iData; break;
  3157. case 6: TVPtr = SiS_Pr->SiS_Ext525pData; break;
  3158. case 7: TVPtr = SiS_Pr->SiS_Ext750pData; break;
  3159. case 8: TVPtr = SiS_Pr->SiS_StPALData; break;
  3160. case 9: TVPtr = SiS_Pr->SiS_StNTSCData; break;
  3161. case 10: TVPtr = SiS_Pr->SiS_St525iData; break;
  3162. case 11: TVPtr = SiS_Pr->SiS_St525pData; break;
  3163. case 12: TVPtr = SiS_Pr->SiS_St750pData; break;
  3164. case 13: TVPtr = SiS_Pr->SiS_St1HiTVData; break;
  3165. case 14: TVPtr = SiS_Pr->SiS_St2HiTVData; break;
  3166. default: TVPtr = SiS_Pr->SiS_StPALData; break;
  3167. }
  3168. SiS_Pr->SiS_RVBHCMAX = (TVPtr+ResIndex)->RVBHCMAX;
  3169. SiS_Pr->SiS_RVBHCFACT = (TVPtr+ResIndex)->RVBHCFACT;
  3170. SiS_Pr->SiS_VGAHT = (TVPtr+ResIndex)->VGAHT;
  3171. SiS_Pr->SiS_VGAVT = (TVPtr+ResIndex)->VGAVT;
  3172. SiS_Pr->SiS_HDE = (TVPtr+ResIndex)->TVHDE;
  3173. SiS_Pr->SiS_VDE = (TVPtr+ResIndex)->TVVDE;
  3174. SiS_Pr->SiS_RVBHRS2 = (TVPtr+ResIndex)->RVBHRS2 & 0x0fff;
  3175. if(modeflag & HalfDCLK) {
  3176. SiS_Pr->SiS_RVBHRS = (TVPtr+ResIndex)->HALFRVBHRS;
  3177. if(SiS_Pr->SiS_RVBHRS2) {
  3178. SiS_Pr->SiS_RVBHRS2 = ((SiS_Pr->SiS_RVBHRS2 + 3) >> 1) - 3;
  3179. tempax = ((TVPtr+ResIndex)->RVBHRS2 >> 12) & 0x07;
  3180. if((TVPtr+ResIndex)->RVBHRS2 & 0x8000) SiS_Pr->SiS_RVBHRS2 -= tempax;
  3181. else SiS_Pr->SiS_RVBHRS2 += tempax;
  3182. }
  3183. } else {
  3184. SiS_Pr->SiS_RVBHRS = (TVPtr+ResIndex)->RVBHRS;
  3185. }
  3186. SiS_Pr->SiS_NewFlickerMode = ((TVPtr+ResIndex)->FlickerMode) << 7;
  3187. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  3188. if((resinfo == SIS_RI_960x600) ||
  3189. (resinfo == SIS_RI_1024x768) ||
  3190. (resinfo == SIS_RI_1280x1024) ||
  3191. (resinfo == SIS_RI_1280x720)) {
  3192. SiS_Pr->SiS_NewFlickerMode = 0x40;
  3193. }
  3194. if(SiS_Pr->SiS_VGAVDE == 350) SiS_Pr->SiS_TVMode |= TVSetTVSimuMode;
  3195. SiS_Pr->SiS_HT = ExtHiTVHT;
  3196. SiS_Pr->SiS_VT = ExtHiTVVT;
  3197. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  3198. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) {
  3199. SiS_Pr->SiS_HT = StHiTVHT;
  3200. SiS_Pr->SiS_VT = StHiTVVT;
  3201. }
  3202. }
  3203. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  3204. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) {
  3205. SiS_Pr->SiS_HT = 1650;
  3206. SiS_Pr->SiS_VT = 750;
  3207. } else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) {
  3208. SiS_Pr->SiS_HT = NTSCHT;
  3209. if(SiS_Pr->SiS_TVMode & TVSet525p1024) SiS_Pr->SiS_HT = NTSC2HT;
  3210. SiS_Pr->SiS_VT = NTSCVT;
  3211. } else {
  3212. SiS_Pr->SiS_HT = NTSCHT;
  3213. if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) SiS_Pr->SiS_HT = NTSC2HT;
  3214. SiS_Pr->SiS_VT = NTSCVT;
  3215. }
  3216. } else {
  3217. SiS_Pr->SiS_RY1COE = (TVPtr+ResIndex)->RY1COE;
  3218. SiS_Pr->SiS_RY2COE = (TVPtr+ResIndex)->RY2COE;
  3219. SiS_Pr->SiS_RY3COE = (TVPtr+ResIndex)->RY3COE;
  3220. SiS_Pr->SiS_RY4COE = (TVPtr+ResIndex)->RY4COE;
  3221. if(modeflag & HalfDCLK) {
  3222. SiS_Pr->SiS_RY1COE = 0x00;
  3223. SiS_Pr->SiS_RY2COE = 0xf4;
  3224. SiS_Pr->SiS_RY3COE = 0x10;
  3225. SiS_Pr->SiS_RY4COE = 0x38;
  3226. }
  3227. if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) {
  3228. SiS_Pr->SiS_HT = NTSCHT;
  3229. if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) SiS_Pr->SiS_HT = NTSC2HT;
  3230. SiS_Pr->SiS_VT = NTSCVT;
  3231. } else {
  3232. SiS_Pr->SiS_HT = PALHT;
  3233. SiS_Pr->SiS_VT = PALVT;
  3234. }
  3235. }
  3236. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  3237. SiS_Pr->SiS_RVBHCMAX = 1;
  3238. SiS_Pr->SiS_RVBHCFACT = 1;
  3239. if(SiS_Pr->UseCustomMode) {
  3240. SiS_Pr->SiS_HDE = SiS_Pr->SiS_VGAHDE;
  3241. SiS_Pr->SiS_VDE = SiS_Pr->SiS_VGAVDE;
  3242. tempax = SiS_Pr->CHTotal;
  3243. if(modeflag & HalfDCLK) tempax <<= 1;
  3244. SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_HT = tempax;
  3245. SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_VT = SiS_Pr->CVTotal;
  3246. } else {
  3247. bool gotit = false;
  3248. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
  3249. SiS_Pr->SiS_VGAHT = SiS_Pr->PanelHT;
  3250. SiS_Pr->SiS_VGAVT = SiS_Pr->PanelVT;
  3251. SiS_Pr->SiS_HT = SiS_Pr->PanelHT;
  3252. SiS_Pr->SiS_VT = SiS_Pr->PanelVT;
  3253. gotit = true;
  3254. } else if( (!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) && (romptr) && (ROMAddr) ) {
  3255. #ifdef CONFIG_FB_SIS_315
  3256. SiS_Pr->SiS_RVBHCMAX = ROMAddr[romptr];
  3257. SiS_Pr->SiS_RVBHCFACT = ROMAddr[romptr+1];
  3258. SiS_Pr->SiS_VGAHT = ROMAddr[romptr+2] | ((ROMAddr[romptr+3] & 0x0f) << 8);
  3259. SiS_Pr->SiS_VGAVT = (ROMAddr[romptr+4] << 4) | ((ROMAddr[romptr+3] & 0xf0) >> 4);
  3260. SiS_Pr->SiS_HT = ROMAddr[romptr+5] | ((ROMAddr[romptr+6] & 0x0f) << 8);
  3261. SiS_Pr->SiS_VT = (ROMAddr[romptr+7] << 4) | ((ROMAddr[romptr+6] & 0xf0) >> 4);
  3262. SiS_Pr->SiS_RVBHRS2 = ROMAddr[romptr+8] | ((ROMAddr[romptr+9] & 0x0f) << 8);
  3263. if((SiS_Pr->SiS_RVBHRS2) && (modeflag & HalfDCLK)) {
  3264. SiS_Pr->SiS_RVBHRS2 = ((SiS_Pr->SiS_RVBHRS2 + 3) >> 1) - 3;
  3265. tempax = (ROMAddr[romptr+9] >> 4) & 0x07;
  3266. if(ROMAddr[romptr+9] & 0x80) SiS_Pr->SiS_RVBHRS2 -= tempax;
  3267. else SiS_Pr->SiS_RVBHRS2 += tempax;
  3268. }
  3269. if(SiS_Pr->SiS_VGAHT) gotit = true;
  3270. else {
  3271. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  3272. SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  3273. SiS_Pr->SiS_RVBHCMAX = 1;
  3274. SiS_Pr->SiS_RVBHCFACT = 1;
  3275. SiS_Pr->SiS_VGAHT = SiS_Pr->PanelHT;
  3276. SiS_Pr->SiS_VGAVT = SiS_Pr->PanelVT;
  3277. SiS_Pr->SiS_HT = SiS_Pr->PanelHT;
  3278. SiS_Pr->SiS_VT = SiS_Pr->PanelVT;
  3279. SiS_Pr->SiS_RVBHRS2 = 0;
  3280. gotit = true;
  3281. }
  3282. #endif
  3283. }
  3284. if(!gotit) {
  3285. SiS_GetCRT2Ptr(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex,
  3286. &CRT2Index,&ResIndex);
  3287. switch(CRT2Index) {
  3288. case Panel_1024x768 : LCDPtr = SiS_Pr->SiS_ExtLCD1024x768Data; break;
  3289. case Panel_1024x768 + 32: LCDPtr = SiS_Pr->SiS_St2LCD1024x768Data; break;
  3290. case Panel_1280x720 :
  3291. case Panel_1280x720 + 32: LCDPtr = SiS_Pr->SiS_LCD1280x720Data; break;
  3292. case Panel_1280x768_2 : LCDPtr = SiS_Pr->SiS_ExtLCD1280x768_2Data; break;
  3293. case Panel_1280x768_2+ 32: LCDPtr = SiS_Pr->SiS_StLCD1280x768_2Data; break;
  3294. case Panel_1280x800 :
  3295. case Panel_1280x800 + 32: LCDPtr = SiS_Pr->SiS_LCD1280x800Data; break;
  3296. case Panel_1280x800_2 :
  3297. case Panel_1280x800_2+ 32: LCDPtr = SiS_Pr->SiS_LCD1280x800_2Data; break;
  3298. case Panel_1280x854 :
  3299. case Panel_1280x854 + 32: LCDPtr = SiS_Pr->SiS_LCD1280x854Data; break;
  3300. case Panel_1280x960 :
  3301. case Panel_1280x960 + 32: LCDPtr = SiS_Pr->SiS_LCD1280x960Data; break;
  3302. case Panel_1280x1024 : LCDPtr = SiS_Pr->SiS_ExtLCD1280x1024Data; break;
  3303. case Panel_1280x1024 + 32: LCDPtr = SiS_Pr->SiS_St2LCD1280x1024Data; break;
  3304. case Panel_1400x1050 : LCDPtr = SiS_Pr->SiS_ExtLCD1400x1050Data; break;
  3305. case Panel_1400x1050 + 32: LCDPtr = SiS_Pr->SiS_StLCD1400x1050Data; break;
  3306. case Panel_1600x1200 : LCDPtr = SiS_Pr->SiS_ExtLCD1600x1200Data; break;
  3307. case Panel_1600x1200 + 32: LCDPtr = SiS_Pr->SiS_StLCD1600x1200Data; break;
  3308. case Panel_1680x1050 :
  3309. case Panel_1680x1050 + 32: LCDPtr = SiS_Pr->SiS_LCD1680x1050Data; break;
  3310. case 100 : LCDPtr = SiS_Pr->SiS_NoScaleData; break;
  3311. #ifdef CONFIG_FB_SIS_315
  3312. case 200 : LCDPtr = SiS310_ExtCompaq1280x1024Data; break;
  3313. case 201 : LCDPtr = SiS_Pr->SiS_St2LCD1280x1024Data; break;
  3314. #endif
  3315. default : LCDPtr = SiS_Pr->SiS_ExtLCD1024x768Data; break;
  3316. }
  3317. SiS_Pr->SiS_RVBHCMAX = (LCDPtr+ResIndex)->RVBHCMAX;
  3318. SiS_Pr->SiS_RVBHCFACT = (LCDPtr+ResIndex)->RVBHCFACT;
  3319. SiS_Pr->SiS_VGAHT = (LCDPtr+ResIndex)->VGAHT;
  3320. SiS_Pr->SiS_VGAVT = (LCDPtr+ResIndex)->VGAVT;
  3321. SiS_Pr->SiS_HT = (LCDPtr+ResIndex)->LCDHT;
  3322. SiS_Pr->SiS_VT = (LCDPtr+ResIndex)->LCDVT;
  3323. }
  3324. tempax = SiS_Pr->PanelXRes;
  3325. tempbx = SiS_Pr->PanelYRes;
  3326. switch(SiS_Pr->SiS_LCDResInfo) {
  3327. case Panel_1024x768:
  3328. if(SiS_Pr->SiS_SetFlag & LCDVESATiming) {
  3329. if(SiS_Pr->ChipType < SIS_315H) {
  3330. if (SiS_Pr->SiS_VGAVDE == 350) tempbx = 560;
  3331. else if(SiS_Pr->SiS_VGAVDE == 400) tempbx = 640;
  3332. }
  3333. } else {
  3334. if (SiS_Pr->SiS_VGAVDE == 357) tempbx = 527;
  3335. else if(SiS_Pr->SiS_VGAVDE == 420) tempbx = 620;
  3336. else if(SiS_Pr->SiS_VGAVDE == 525) tempbx = 775;
  3337. else if(SiS_Pr->SiS_VGAVDE == 600) tempbx = 775;
  3338. else if(SiS_Pr->SiS_VGAVDE == 350) tempbx = 560;
  3339. else if(SiS_Pr->SiS_VGAVDE == 400) tempbx = 640;
  3340. }
  3341. break;
  3342. case Panel_1280x960:
  3343. if (SiS_Pr->SiS_VGAVDE == 350) tempbx = 700;
  3344. else if(SiS_Pr->SiS_VGAVDE == 400) tempbx = 800;
  3345. else if(SiS_Pr->SiS_VGAVDE == 1024) tempbx = 960;
  3346. break;
  3347. case Panel_1280x1024:
  3348. if (SiS_Pr->SiS_VGAVDE == 360) tempbx = 768;
  3349. else if(SiS_Pr->SiS_VGAVDE == 375) tempbx = 800;
  3350. else if(SiS_Pr->SiS_VGAVDE == 405) tempbx = 864;
  3351. break;
  3352. case Panel_1600x1200:
  3353. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
  3354. if (SiS_Pr->SiS_VGAVDE == 350) tempbx = 875;
  3355. else if(SiS_Pr->SiS_VGAVDE == 400) tempbx = 1000;
  3356. }
  3357. break;
  3358. }
  3359. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  3360. tempax = SiS_Pr->SiS_VGAHDE;
  3361. tempbx = SiS_Pr->SiS_VGAVDE;
  3362. }
  3363. SiS_Pr->SiS_HDE = tempax;
  3364. SiS_Pr->SiS_VDE = tempbx;
  3365. }
  3366. }
  3367. }
  3368. static void
  3369. SiS_GetCRT2Data(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  3370. unsigned short RefreshRateTableIndex)
  3371. {
  3372. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  3373. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  3374. SiS_GetCRT2DataLVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  3375. } else {
  3376. if((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) {
  3377. /* Need LVDS Data for LCD on 301B-DH */
  3378. SiS_GetCRT2DataLVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  3379. } else {
  3380. SiS_GetCRT2Data301(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  3381. }
  3382. }
  3383. } else {
  3384. SiS_GetCRT2DataLVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  3385. }
  3386. }
  3387. /*********************************************/
  3388. /* GET LVDS DES (SKEW) DATA */
  3389. /*********************************************/
  3390. static const struct SiS_LVDSDes *
  3391. SiS_GetLVDSDesPtr(struct SiS_Private *SiS_Pr)
  3392. {
  3393. const struct SiS_LVDSDes *PanelDesPtr = NULL;
  3394. #ifdef CONFIG_FB_SIS_300
  3395. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  3396. if(SiS_Pr->ChipType < SIS_315H) {
  3397. if(SiS_Pr->SiS_LCDTypeInfo == 4) {
  3398. if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) {
  3399. PanelDesPtr = SiS_Pr->SiS_PanelType04_1a;
  3400. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  3401. PanelDesPtr = SiS_Pr->SiS_PanelType04_2a;
  3402. }
  3403. } else if(SiS_Pr->SiS_CustomT == CUT_BARCO1024) {
  3404. PanelDesPtr = SiS_Pr->SiS_PanelType04_1b;
  3405. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  3406. PanelDesPtr = SiS_Pr->SiS_PanelType04_2b;
  3407. }
  3408. }
  3409. }
  3410. }
  3411. }
  3412. #endif
  3413. return PanelDesPtr;
  3414. }
  3415. static void
  3416. SiS_GetLVDSDesData(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  3417. unsigned short RefreshRateTableIndex)
  3418. {
  3419. unsigned short modeflag, ResIndex;
  3420. const struct SiS_LVDSDes *PanelDesPtr = NULL;
  3421. SiS_Pr->SiS_LCDHDES = 0;
  3422. SiS_Pr->SiS_LCDVDES = 0;
  3423. /* Some special cases */
  3424. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  3425. /* Trumpion */
  3426. if(SiS_Pr->SiS_IF_DEF_TRUMPION) {
  3427. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  3428. if(SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) {
  3429. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3430. }
  3431. }
  3432. return;
  3433. }
  3434. /* 640x480 on LVDS */
  3435. if(SiS_Pr->ChipType < SIS_315H) {
  3436. if(SiS_Pr->SiS_LCDResInfo == Panel_640x480 && SiS_Pr->SiS_LCDTypeInfo == 3) {
  3437. SiS_Pr->SiS_LCDHDES = 8;
  3438. if (SiS_Pr->SiS_VGAVDE >= 480) SiS_Pr->SiS_LCDVDES = 512;
  3439. else if(SiS_Pr->SiS_VGAVDE >= 400) SiS_Pr->SiS_LCDVDES = 436;
  3440. else if(SiS_Pr->SiS_VGAVDE >= 350) SiS_Pr->SiS_LCDVDES = 440;
  3441. return;
  3442. }
  3443. }
  3444. } /* LCD */
  3445. if( (SiS_Pr->UseCustomMode) ||
  3446. (SiS_Pr->SiS_LCDResInfo == Panel_Custom) ||
  3447. (SiS_Pr->SiS_CustomT == CUT_PANEL848) ||
  3448. (SiS_Pr->SiS_CustomT == CUT_PANEL856) ||
  3449. (SiS_Pr->SiS_LCDInfo & LCDPass11) ) {
  3450. return;
  3451. }
  3452. if(ModeNo <= 0x13) ResIndex = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  3453. else ResIndex = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  3454. if((SiS_Pr->SiS_VBType & VB_SIS30xBLV) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  3455. #ifdef CONFIG_FB_SIS_315
  3456. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  3457. /* non-pass 1:1 only, see above */
  3458. if(SiS_Pr->SiS_VGAHDE != SiS_Pr->PanelXRes) {
  3459. SiS_Pr->SiS_LCDHDES = SiS_Pr->SiS_HT - ((SiS_Pr->PanelXRes - SiS_Pr->SiS_VGAHDE) / 2);
  3460. }
  3461. if(SiS_Pr->SiS_VGAVDE != SiS_Pr->PanelYRes) {
  3462. SiS_Pr->SiS_LCDVDES = SiS_Pr->SiS_VT - ((SiS_Pr->PanelYRes - SiS_Pr->SiS_VGAVDE) / 2);
  3463. }
  3464. }
  3465. if(SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) {
  3466. switch(SiS_Pr->SiS_CustomT) {
  3467. case CUT_UNIWILL1024:
  3468. case CUT_UNIWILL10242:
  3469. case CUT_CLEVO1400:
  3470. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  3471. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3472. }
  3473. break;
  3474. }
  3475. switch(SiS_Pr->SiS_LCDResInfo) {
  3476. case Panel_1280x1024:
  3477. if(SiS_Pr->SiS_CustomT != CUT_COMPAQ1280) {
  3478. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3479. }
  3480. break;
  3481. case Panel_1280x800: /* Verified for Averatec 6240 */
  3482. case Panel_1280x800_2: /* Verified for Asus A4L */
  3483. case Panel_1280x854: /* Not verified yet FIXME */
  3484. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3485. break;
  3486. }
  3487. }
  3488. #endif
  3489. } else {
  3490. if((SiS_Pr->SiS_IF_DEF_CH70xx != 0) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
  3491. if((SiS_Pr->SiS_TVMode & TVSetPAL) && (!(SiS_Pr->SiS_TVMode & TVSetPALM))) {
  3492. if(ResIndex <= 3) SiS_Pr->SiS_LCDHDES = 256;
  3493. }
  3494. } else if((PanelDesPtr = SiS_GetLVDSDesPtr(SiS_Pr))) {
  3495. SiS_Pr->SiS_LCDHDES = (PanelDesPtr+ResIndex)->LCDHDES;
  3496. SiS_Pr->SiS_LCDVDES = (PanelDesPtr+ResIndex)->LCDVDES;
  3497. } else if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  3498. if(SiS_Pr->SiS_VGAHDE != SiS_Pr->PanelXRes) {
  3499. SiS_Pr->SiS_LCDHDES = SiS_Pr->SiS_HT - ((SiS_Pr->PanelXRes - SiS_Pr->SiS_VGAHDE) / 2);
  3500. }
  3501. if(SiS_Pr->SiS_VGAVDE != SiS_Pr->PanelYRes) {
  3502. SiS_Pr->SiS_LCDVDES = SiS_Pr->SiS_VT - ((SiS_Pr->PanelYRes - SiS_Pr->SiS_VGAVDE) / 2);
  3503. } else {
  3504. if(SiS_Pr->ChipType < SIS_315H) {
  3505. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3506. } else {
  3507. switch(SiS_Pr->SiS_LCDResInfo) {
  3508. case Panel_800x600:
  3509. case Panel_1024x768:
  3510. case Panel_1280x1024:
  3511. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT;
  3512. break;
  3513. case Panel_1400x1050:
  3514. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3515. break;
  3516. }
  3517. }
  3518. }
  3519. } else {
  3520. if(SiS_Pr->ChipType < SIS_315H) {
  3521. #ifdef CONFIG_FB_SIS_300
  3522. switch(SiS_Pr->SiS_LCDResInfo) {
  3523. case Panel_800x600:
  3524. if(SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) {
  3525. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3526. } else {
  3527. SiS_Pr->SiS_LCDHDES = SiS_Pr->PanelHT + 3;
  3528. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT;
  3529. if(SiS_Pr->SiS_VGAVDE == 400) SiS_Pr->SiS_LCDVDES -= 2;
  3530. else SiS_Pr->SiS_LCDVDES -= 4;
  3531. }
  3532. break;
  3533. case Panel_1024x768:
  3534. if(SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) {
  3535. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3536. } else {
  3537. SiS_Pr->SiS_LCDHDES = SiS_Pr->PanelHT - 1;
  3538. if(SiS_Pr->SiS_VGAVDE <= 400) SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 8;
  3539. if(SiS_Pr->SiS_VGAVDE <= 350) SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 12;
  3540. }
  3541. break;
  3542. case Panel_1024x600:
  3543. default:
  3544. if( (SiS_Pr->SiS_VGAHDE == SiS_Pr->PanelXRes) &&
  3545. (SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) ) {
  3546. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3547. } else {
  3548. SiS_Pr->SiS_LCDHDES = SiS_Pr->PanelHT - 1;
  3549. }
  3550. break;
  3551. }
  3552. switch(SiS_Pr->SiS_LCDTypeInfo) {
  3553. case 1:
  3554. SiS_Pr->SiS_LCDHDES = SiS_Pr->SiS_LCDVDES = 0;
  3555. break;
  3556. case 3: /* 640x480 only? */
  3557. SiS_Pr->SiS_LCDHDES = 8;
  3558. if (SiS_Pr->SiS_VGAVDE >= 480) SiS_Pr->SiS_LCDVDES = 512;
  3559. else if(SiS_Pr->SiS_VGAVDE >= 400) SiS_Pr->SiS_LCDVDES = 436;
  3560. else if(SiS_Pr->SiS_VGAVDE >= 350) SiS_Pr->SiS_LCDVDES = 440;
  3561. break;
  3562. }
  3563. #endif
  3564. } else {
  3565. #ifdef CONFIG_FB_SIS_315
  3566. switch(SiS_Pr->SiS_LCDResInfo) {
  3567. case Panel_1024x768:
  3568. case Panel_1280x1024:
  3569. if(SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) {
  3570. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3571. }
  3572. break;
  3573. case Panel_320x240_1:
  3574. case Panel_320x240_2:
  3575. case Panel_320x240_3:
  3576. SiS_Pr->SiS_LCDVDES = 524;
  3577. break;
  3578. }
  3579. #endif
  3580. }
  3581. }
  3582. if((ModeNo <= 0x13) && (SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
  3583. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  3584. if((SiS_Pr->SiS_VBType & VB_SIS30xBLV) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  3585. if(!(modeflag & HalfDCLK)) SiS_Pr->SiS_LCDHDES = 632;
  3586. } else if(!(SiS_Pr->SiS_SetFlag & SetDOSMode)) {
  3587. if(SiS_Pr->SiS_LCDResInfo != Panel_1280x1024) {
  3588. if(SiS_Pr->SiS_LCDResInfo >= Panel_1024x768) {
  3589. if(SiS_Pr->ChipType < SIS_315H) {
  3590. if(!(modeflag & HalfDCLK)) SiS_Pr->SiS_LCDHDES = 320;
  3591. } else {
  3592. #ifdef CONFIG_FB_SIS_315
  3593. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) SiS_Pr->SiS_LCDHDES = 480;
  3594. if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) SiS_Pr->SiS_LCDHDES = 804;
  3595. if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) SiS_Pr->SiS_LCDHDES = 704;
  3596. if(!(modeflag & HalfDCLK)) {
  3597. SiS_Pr->SiS_LCDHDES = 320;
  3598. if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) SiS_Pr->SiS_LCDHDES = 632;
  3599. if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) SiS_Pr->SiS_LCDHDES = 542;
  3600. }
  3601. #endif
  3602. }
  3603. }
  3604. }
  3605. }
  3606. }
  3607. }
  3608. }
  3609. /*********************************************/
  3610. /* DISABLE VIDEO BRIDGE */
  3611. /*********************************************/
  3612. #ifdef CONFIG_FB_SIS_315
  3613. static int
  3614. SiS_HandlePWD(struct SiS_Private *SiS_Pr)
  3615. {
  3616. int ret = 0;
  3617. #ifdef SET_PWD
  3618. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  3619. unsigned short romptr = GetLCDStructPtr661_2(SiS_Pr);
  3620. unsigned char drivermode = SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & 0x40;
  3621. unsigned short temp;
  3622. if( (SiS_Pr->SiS_VBType & VB_SISPWD) &&
  3623. (romptr) &&
  3624. (SiS_Pr->SiS_PWDOffset) ) {
  3625. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2b,ROMAddr[romptr + SiS_Pr->SiS_PWDOffset + 0]);
  3626. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2c,ROMAddr[romptr + SiS_Pr->SiS_PWDOffset + 1]);
  3627. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2d,ROMAddr[romptr + SiS_Pr->SiS_PWDOffset + 2]);
  3628. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2e,ROMAddr[romptr + SiS_Pr->SiS_PWDOffset + 3]);
  3629. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2f,ROMAddr[romptr + SiS_Pr->SiS_PWDOffset + 4]);
  3630. temp = 0x00;
  3631. if((ROMAddr[romptr + 2] & (0x06 << 1)) && !drivermode) {
  3632. temp = 0x80;
  3633. ret = 1;
  3634. }
  3635. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x27,0x7f,temp);
  3636. }
  3637. #endif
  3638. return ret;
  3639. }
  3640. #endif
  3641. /* NEVER use any variables (VBInfo), this will be called
  3642. * from outside the context of modeswitch!
  3643. * MUST call getVBType before calling this
  3644. */
  3645. void
  3646. SiS_DisableBridge(struct SiS_Private *SiS_Pr)
  3647. {
  3648. #ifdef CONFIG_FB_SIS_315
  3649. unsigned short tempah, pushax=0, modenum;
  3650. #endif
  3651. unsigned short temp=0;
  3652. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  3653. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) { /* ===== For 30xB/C/LV ===== */
  3654. if(SiS_Pr->ChipType < SIS_315H) {
  3655. #ifdef CONFIG_FB_SIS_300 /* 300 series */
  3656. if(!(SiS_CR36BIOSWord23b(SiS_Pr))) {
  3657. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3658. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFE);
  3659. } else {
  3660. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x08);
  3661. }
  3662. SiS_PanelDelay(SiS_Pr, 3);
  3663. }
  3664. if(SiS_Is301B(SiS_Pr)) {
  3665. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1f,0x3f);
  3666. SiS_ShortDelay(SiS_Pr,1);
  3667. }
  3668. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xDF);
  3669. SiS_DisplayOff(SiS_Pr);
  3670. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF);
  3671. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF);
  3672. SiS_UnLockCRT2(SiS_Pr);
  3673. if(!(SiS_Pr->SiS_VBType & VB_SISLVDS)) {
  3674. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x01,0x80);
  3675. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x02,0x40);
  3676. }
  3677. if( (!(SiS_CRT2IsLCD(SiS_Pr))) ||
  3678. (!(SiS_CR36BIOSWord23d(SiS_Pr))) ) {
  3679. SiS_PanelDelay(SiS_Pr, 2);
  3680. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3681. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFD);
  3682. } else {
  3683. SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x04);
  3684. }
  3685. }
  3686. #endif /* CONFIG_FB_SIS_300 */
  3687. } else {
  3688. #ifdef CONFIG_FB_SIS_315 /* 315 series */
  3689. int didpwd = 0;
  3690. bool custom1 = (SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) ||
  3691. (SiS_Pr->SiS_CustomT == CUT_CLEVO1400);
  3692. modenum = SiS_GetReg(SiS_Pr->SiS_P3d4,0x34) & 0x7f;
  3693. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3694. #ifdef SET_EMI
  3695. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  3696. if(SiS_Pr->SiS_CustomT != CUT_CLEVO1400) {
  3697. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
  3698. }
  3699. }
  3700. #endif
  3701. didpwd = SiS_HandlePWD(SiS_Pr);
  3702. if( (modenum <= 0x13) ||
  3703. (SiS_IsVAMode(SiS_Pr)) ||
  3704. (!(SiS_IsDualEdge(SiS_Pr))) ) {
  3705. if(!didpwd) {
  3706. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xfe);
  3707. if(custom1) SiS_PanelDelay(SiS_Pr, 3);
  3708. } else {
  3709. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xfc);
  3710. }
  3711. }
  3712. if(!custom1) {
  3713. SiS_DDC2Delay(SiS_Pr,0xff00);
  3714. SiS_DDC2Delay(SiS_Pr,0xe000);
  3715. SiS_SetRegByte(SiS_Pr->SiS_P3c6,0x00);
  3716. pushax = SiS_GetReg(SiS_Pr->SiS_P3c4,0x06);
  3717. if(IS_SIS740) {
  3718. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x06,0xE3);
  3719. }
  3720. SiS_PanelDelay(SiS_Pr, 3);
  3721. }
  3722. }
  3723. if(!(SiS_IsNotM650orLater(SiS_Pr))) {
  3724. /* if(SiS_Pr->ChipType < SIS_340) {*/
  3725. tempah = 0xef;
  3726. if(SiS_IsVAMode(SiS_Pr)) tempah = 0xf7;
  3727. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x4c,tempah);
  3728. /*}*/
  3729. }
  3730. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3731. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1F,~0x10);
  3732. }
  3733. tempah = 0x3f;
  3734. if(SiS_IsDualEdge(SiS_Pr)) {
  3735. tempah = 0x7f;
  3736. if(!(SiS_IsVAMode(SiS_Pr))) tempah = 0xbf;
  3737. }
  3738. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1F,tempah);
  3739. if((SiS_IsVAMode(SiS_Pr)) ||
  3740. ((SiS_Pr->SiS_VBType & VB_SISLVDS) && (modenum <= 0x13))) {
  3741. SiS_DisplayOff(SiS_Pr);
  3742. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3743. SiS_PanelDelay(SiS_Pr, 2);
  3744. }
  3745. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF);
  3746. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1E,0xDF);
  3747. }
  3748. if((!(SiS_IsVAMode(SiS_Pr))) ||
  3749. ((SiS_Pr->SiS_VBType & VB_SISLVDS) && (modenum <= 0x13))) {
  3750. if(!(SiS_IsDualEdge(SiS_Pr))) {
  3751. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xdf);
  3752. SiS_DisplayOff(SiS_Pr);
  3753. }
  3754. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x80);
  3755. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3756. SiS_PanelDelay(SiS_Pr, 2);
  3757. }
  3758. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF);
  3759. temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00);
  3760. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x10);
  3761. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF);
  3762. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,temp);
  3763. }
  3764. if(SiS_IsNotM650orLater(SiS_Pr)) {
  3765. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0x7f);
  3766. }
  3767. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3768. if( (!(SiS_IsVAMode(SiS_Pr))) &&
  3769. (!(SiS_CRT2IsLCD(SiS_Pr))) &&
  3770. (!(SiS_IsDualEdge(SiS_Pr))) ) {
  3771. if(custom1) SiS_PanelDelay(SiS_Pr, 2);
  3772. if(!didpwd) {
  3773. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFD);
  3774. }
  3775. if(custom1) SiS_PanelDelay(SiS_Pr, 4);
  3776. }
  3777. if(!custom1) {
  3778. SiS_SetReg(SiS_Pr->SiS_P3c4,0x06,pushax);
  3779. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  3780. if(SiS_IsVAorLCD(SiS_Pr)) {
  3781. SiS_PanelDelayLoop(SiS_Pr, 3, 20);
  3782. }
  3783. }
  3784. }
  3785. }
  3786. #endif /* CONFIG_FB_SIS_315 */
  3787. }
  3788. } else { /* ============ For 301 ================ */
  3789. if(SiS_Pr->ChipType < SIS_315H) {
  3790. #ifdef CONFIG_FB_SIS_300
  3791. if(!(SiS_CR36BIOSWord23b(SiS_Pr))) {
  3792. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x08);
  3793. SiS_PanelDelay(SiS_Pr, 3);
  3794. }
  3795. #endif
  3796. }
  3797. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xDF); /* disable VB */
  3798. SiS_DisplayOff(SiS_Pr);
  3799. if(SiS_Pr->ChipType >= SIS_315H) {
  3800. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x80);
  3801. }
  3802. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF); /* disable lock mode */
  3803. if(SiS_Pr->ChipType >= SIS_315H) {
  3804. temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00);
  3805. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x10);
  3806. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);
  3807. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,temp);
  3808. } else {
  3809. #ifdef CONFIG_FB_SIS_300
  3810. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF); /* disable CRT2 */
  3811. if( (!(SiS_CRT2IsLCD(SiS_Pr))) ||
  3812. (!(SiS_CR36BIOSWord23d(SiS_Pr))) ) {
  3813. SiS_PanelDelay(SiS_Pr, 2);
  3814. SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x04);
  3815. }
  3816. #endif
  3817. }
  3818. }
  3819. } else { /* ============ For LVDS =============*/
  3820. if(SiS_Pr->ChipType < SIS_315H) {
  3821. #ifdef CONFIG_FB_SIS_300 /* 300 series */
  3822. if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) {
  3823. SiS_SetCH700x(SiS_Pr,0x0E,0x09);
  3824. }
  3825. if(SiS_Pr->ChipType == SIS_730) {
  3826. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x11) & 0x08)) {
  3827. SiS_WaitVBRetrace(SiS_Pr);
  3828. }
  3829. if(!(SiS_CR36BIOSWord23b(SiS_Pr))) {
  3830. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x08);
  3831. SiS_PanelDelay(SiS_Pr, 3);
  3832. }
  3833. } else {
  3834. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x11) & 0x08)) {
  3835. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x40)) {
  3836. if(!(SiS_CR36BIOSWord23b(SiS_Pr))) {
  3837. SiS_WaitVBRetrace(SiS_Pr);
  3838. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x06) & 0x1c)) {
  3839. SiS_DisplayOff(SiS_Pr);
  3840. }
  3841. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x08);
  3842. SiS_PanelDelay(SiS_Pr, 3);
  3843. }
  3844. }
  3845. }
  3846. }
  3847. SiS_DisplayOff(SiS_Pr);
  3848. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF);
  3849. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF);
  3850. SiS_UnLockCRT2(SiS_Pr);
  3851. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x01,0x80);
  3852. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x02,0x40);
  3853. if( (!(SiS_CRT2IsLCD(SiS_Pr))) ||
  3854. (!(SiS_CR36BIOSWord23d(SiS_Pr))) ) {
  3855. SiS_PanelDelay(SiS_Pr, 2);
  3856. SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x04);
  3857. }
  3858. #endif /* CONFIG_FB_SIS_300 */
  3859. } else {
  3860. #ifdef CONFIG_FB_SIS_315 /* 315 series */
  3861. if(!(SiS_IsNotM650orLater(SiS_Pr))) {
  3862. /*if(SiS_Pr->ChipType < SIS_340) { */ /* XGI needs this */
  3863. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x4c,~0x18);
  3864. /* } */
  3865. }
  3866. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  3867. if(SiS_Pr->ChipType == SIS_740) {
  3868. temp = SiS_GetCH701x(SiS_Pr,0x61);
  3869. if(temp < 1) {
  3870. SiS_SetCH701x(SiS_Pr,0x76,0xac);
  3871. SiS_SetCH701x(SiS_Pr,0x66,0x00);
  3872. }
  3873. if( (!(SiS_IsDualEdge(SiS_Pr))) ||
  3874. (SiS_IsTVOrYPbPrOrScart(SiS_Pr)) ) {
  3875. SiS_SetCH701x(SiS_Pr,0x49,0x3e);
  3876. }
  3877. }
  3878. if( (!(SiS_IsDualEdge(SiS_Pr))) ||
  3879. (SiS_IsVAMode(SiS_Pr)) ) {
  3880. SiS_Chrontel701xBLOff(SiS_Pr);
  3881. SiS_Chrontel701xOff(SiS_Pr);
  3882. }
  3883. if(SiS_Pr->ChipType != SIS_740) {
  3884. if( (!(SiS_IsDualEdge(SiS_Pr))) ||
  3885. (SiS_IsTVOrYPbPrOrScart(SiS_Pr)) ) {
  3886. SiS_SetCH701x(SiS_Pr,0x49,0x01);
  3887. }
  3888. }
  3889. }
  3890. if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
  3891. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x08);
  3892. SiS_PanelDelay(SiS_Pr, 3);
  3893. }
  3894. if( (SiS_Pr->SiS_IF_DEF_CH70xx == 0) ||
  3895. (!(SiS_IsDualEdge(SiS_Pr))) ||
  3896. (!(SiS_IsTVOrYPbPrOrScart(SiS_Pr))) ) {
  3897. SiS_DisplayOff(SiS_Pr);
  3898. }
  3899. if( (SiS_Pr->SiS_IF_DEF_CH70xx == 0) ||
  3900. (!(SiS_IsDualEdge(SiS_Pr))) ||
  3901. (!(SiS_IsVAMode(SiS_Pr))) ) {
  3902. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x80);
  3903. }
  3904. if(SiS_Pr->ChipType == SIS_740) {
  3905. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0x7f);
  3906. }
  3907. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF);
  3908. if( (SiS_Pr->SiS_IF_DEF_CH70xx == 0) ||
  3909. (!(SiS_IsDualEdge(SiS_Pr))) ||
  3910. (!(SiS_IsVAMode(SiS_Pr))) ) {
  3911. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF);
  3912. }
  3913. if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
  3914. if(SiS_CRT2IsLCD(SiS_Pr)) {
  3915. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xdf);
  3916. if(SiS_Pr->ChipType == SIS_550) {
  3917. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xbf);
  3918. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xef);
  3919. }
  3920. }
  3921. } else {
  3922. if(SiS_Pr->ChipType == SIS_740) {
  3923. if(SiS_IsLCDOrLCDA(SiS_Pr)) {
  3924. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xdf);
  3925. }
  3926. } else if(SiS_IsVAMode(SiS_Pr)) {
  3927. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xdf);
  3928. }
  3929. }
  3930. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  3931. if(SiS_IsDualEdge(SiS_Pr)) {
  3932. /* SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xff); */
  3933. } else {
  3934. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xfb);
  3935. }
  3936. }
  3937. SiS_UnLockCRT2(SiS_Pr);
  3938. if(SiS_Pr->ChipType == SIS_550) {
  3939. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x01,0x80); /* DirectDVD PAL?*/
  3940. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x02,0x40); /* VB clock / 4 ? */
  3941. } else if( (SiS_Pr->SiS_IF_DEF_CH70xx == 0) ||
  3942. (!(SiS_IsDualEdge(SiS_Pr))) ||
  3943. (!(SiS_IsVAMode(SiS_Pr))) ) {
  3944. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0xf7);
  3945. }
  3946. if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
  3947. if(SiS_CRT2IsLCD(SiS_Pr)) {
  3948. if(!(SiS_WeHaveBacklightCtrl(SiS_Pr))) {
  3949. SiS_PanelDelay(SiS_Pr, 2);
  3950. SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x04);
  3951. }
  3952. }
  3953. }
  3954. #endif /* CONFIG_FB_SIS_315 */
  3955. } /* 315 series */
  3956. } /* LVDS */
  3957. }
  3958. /*********************************************/
  3959. /* ENABLE VIDEO BRIDGE */
  3960. /*********************************************/
  3961. /* NEVER use any variables (VBInfo), this will be called
  3962. * from outside the context of a mode switch!
  3963. * MUST call getVBType before calling this
  3964. */
  3965. static
  3966. void
  3967. SiS_EnableBridge(struct SiS_Private *SiS_Pr)
  3968. {
  3969. unsigned short temp=0, tempah;
  3970. #ifdef CONFIG_FB_SIS_315
  3971. unsigned short temp1, pushax=0;
  3972. bool delaylong = false;
  3973. #endif
  3974. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  3975. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) { /* ====== For 301B et al ====== */
  3976. if(SiS_Pr->ChipType < SIS_315H) {
  3977. #ifdef CONFIG_FB_SIS_300 /* 300 series */
  3978. if(SiS_CRT2IsLCD(SiS_Pr)) {
  3979. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3980. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x02);
  3981. } else if(SiS_Pr->SiS_VBType & VB_NoLCD) {
  3982. SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x00);
  3983. }
  3984. if(SiS_Pr->SiS_VBType & (VB_SISLVDS | VB_NoLCD)) {
  3985. if(!(SiS_CR36BIOSWord23d(SiS_Pr))) {
  3986. SiS_PanelDelay(SiS_Pr, 0);
  3987. }
  3988. }
  3989. }
  3990. if((SiS_Pr->SiS_VBType & VB_NoLCD) &&
  3991. (SiS_CRT2IsLCD(SiS_Pr))) {
  3992. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20); /* Enable CRT2 */
  3993. SiS_DisplayOn(SiS_Pr);
  3994. SiS_UnLockCRT2(SiS_Pr);
  3995. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x02,0xBF);
  3996. if(SiS_BridgeInSlavemode(SiS_Pr)) {
  3997. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x01,0x1F);
  3998. } else {
  3999. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x01,0x1F,0x40);
  4000. }
  4001. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x40)) {
  4002. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x16) & 0x10)) {
  4003. if(!(SiS_CR36BIOSWord23b(SiS_Pr))) {
  4004. SiS_PanelDelay(SiS_Pr, 1);
  4005. }
  4006. SiS_WaitVBRetrace(SiS_Pr);
  4007. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x00);
  4008. }
  4009. }
  4010. } else {
  4011. temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x32) & 0xDF; /* lock mode */
  4012. if(SiS_BridgeInSlavemode(SiS_Pr)) {
  4013. tempah = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  4014. if(!(tempah & SetCRT2ToRAMDAC)) temp |= 0x20;
  4015. }
  4016. SiS_SetReg(SiS_Pr->SiS_P3c4,0x32,temp);
  4017. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);
  4018. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x00,0x1F,0x20); /* enable VB processor */
  4019. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x1F,0xC0);
  4020. SiS_DisplayOn(SiS_Pr);
  4021. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  4022. if(SiS_CRT2IsLCD(SiS_Pr)) {
  4023. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x16) & 0x10)) {
  4024. if(!(SiS_CR36BIOSWord23b(SiS_Pr))) {
  4025. SiS_PanelDelay(SiS_Pr, 1);
  4026. }
  4027. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x01);
  4028. }
  4029. }
  4030. }
  4031. }
  4032. #endif /* CONFIG_FB_SIS_300 */
  4033. } else {
  4034. #ifdef CONFIG_FB_SIS_315 /* 315 series */
  4035. #ifdef SET_EMI
  4036. unsigned char r30=0, r31=0, r32=0, r33=0, cr36=0;
  4037. int didpwd = 0;
  4038. /* unsigned short emidelay=0; */
  4039. #endif
  4040. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  4041. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1f,0xef);
  4042. #ifdef SET_EMI
  4043. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  4044. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
  4045. }
  4046. #endif
  4047. }
  4048. if(!(SiS_IsNotM650orLater(SiS_Pr))) {
  4049. /*if(SiS_Pr->ChipType < SIS_340) { */
  4050. tempah = 0x10;
  4051. if(SiS_LCDAEnabled(SiS_Pr)) {
  4052. if(SiS_TVEnabled(SiS_Pr)) tempah = 0x18;
  4053. else tempah = 0x08;
  4054. }
  4055. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x4c,tempah);
  4056. /*}*/
  4057. }
  4058. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  4059. SiS_SetRegByte(SiS_Pr->SiS_P3c6,0x00);
  4060. SiS_DisplayOff(SiS_Pr);
  4061. pushax = SiS_GetReg(SiS_Pr->SiS_P3c4,0x06);
  4062. if(IS_SIS740) {
  4063. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x06,0xE3);
  4064. }
  4065. didpwd = SiS_HandlePWD(SiS_Pr);
  4066. if(SiS_IsVAorLCD(SiS_Pr)) {
  4067. if(!didpwd) {
  4068. if(!(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x26) & 0x02)) {
  4069. SiS_PanelDelayLoop(SiS_Pr, 3, 2);
  4070. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x02);
  4071. SiS_PanelDelayLoop(SiS_Pr, 3, 2);
  4072. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  4073. SiS_GenericDelay(SiS_Pr, 17664);
  4074. }
  4075. }
  4076. } else {
  4077. SiS_PanelDelayLoop(SiS_Pr, 3, 2);
  4078. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  4079. SiS_GenericDelay(SiS_Pr, 17664);
  4080. }
  4081. }
  4082. }
  4083. if(!(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & 0x40)) {
  4084. SiS_PanelDelayLoop(SiS_Pr, 3, 10);
  4085. delaylong = true;
  4086. }
  4087. }
  4088. if(!(SiS_IsVAMode(SiS_Pr))) {
  4089. temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x32) & 0xDF;
  4090. if(SiS_BridgeInSlavemode(SiS_Pr)) {
  4091. tempah = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  4092. if(!(tempah & SetCRT2ToRAMDAC)) {
  4093. if(!(SiS_LCDAEnabled(SiS_Pr))) temp |= 0x20;
  4094. }
  4095. }
  4096. SiS_SetReg(SiS_Pr->SiS_P3c4,0x32,temp);
  4097. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20); /* enable CRT2 */
  4098. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0x7f);
  4099. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2e,0x80);
  4100. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  4101. SiS_PanelDelay(SiS_Pr, 2);
  4102. }
  4103. } else {
  4104. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1e,0x20);
  4105. }
  4106. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x00,0x1f,0x20);
  4107. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2e,0x80);
  4108. if(SiS_Pr->SiS_VBType & VB_SISPOWER) {
  4109. if( (SiS_LCDAEnabled(SiS_Pr)) ||
  4110. (SiS_CRT2IsLCD(SiS_Pr)) ) {
  4111. /* Enable "LVDS PLL power on" (even on 301C) */
  4112. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x2a,0x7f);
  4113. /* Enable "LVDS Driver Power on" (even on 301C) */
  4114. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x7f);
  4115. }
  4116. }
  4117. tempah = 0xc0;
  4118. if(SiS_IsDualEdge(SiS_Pr)) {
  4119. tempah = 0x80;
  4120. if(!(SiS_IsVAMode(SiS_Pr))) tempah = 0x40;
  4121. }
  4122. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x1F,tempah);
  4123. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  4124. SiS_PanelDelay(SiS_Pr, 2);
  4125. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x1f,0x10);
  4126. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2e,0x80);
  4127. if(SiS_Pr->SiS_CustomT != CUT_CLEVO1400) {
  4128. #ifdef SET_EMI
  4129. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  4130. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
  4131. SiS_GenericDelay(SiS_Pr, 2048);
  4132. }
  4133. #endif
  4134. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x27,0x0c);
  4135. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  4136. #ifdef SET_EMI
  4137. cr36 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36);
  4138. if(SiS_Pr->SiS_ROMNew) {
  4139. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  4140. unsigned short romptr = GetLCDStructPtr661_2(SiS_Pr);
  4141. if(romptr) {
  4142. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x30,0x20); /* Reset */
  4143. SiS_Pr->EMI_30 = 0;
  4144. SiS_Pr->EMI_31 = ROMAddr[romptr + SiS_Pr->SiS_EMIOffset + 0];
  4145. SiS_Pr->EMI_32 = ROMAddr[romptr + SiS_Pr->SiS_EMIOffset + 1];
  4146. SiS_Pr->EMI_33 = ROMAddr[romptr + SiS_Pr->SiS_EMIOffset + 2];
  4147. if(ROMAddr[romptr + 1] & 0x10) SiS_Pr->EMI_30 = 0x40;
  4148. /* emidelay = SISGETROMW((romptr + 0x22)); */
  4149. SiS_Pr->HaveEMI = SiS_Pr->HaveEMILCD = SiS_Pr->OverruleEMI = true;
  4150. }
  4151. }
  4152. /* (P4_30|0x40) */
  4153. /* Compal 1400x1050: 0x05, 0x60, 0x00 YES (1.10.7w; CR36=69) */
  4154. /* Compal 1400x1050: 0x0d, 0x70, 0x40 YES (1.10.7x; CR36=69) */
  4155. /* Acer 1280x1024: 0x12, 0xd0, 0x6b NO (1.10.9k; CR36=73) */
  4156. /* Compaq 1280x1024: 0x0d, 0x70, 0x6b YES (1.12.04b; CR36=03) */
  4157. /* Clevo 1024x768: 0x05, 0x60, 0x33 NO (1.10.8e; CR36=12, DL!) */
  4158. /* Clevo 1024x768: 0x0d, 0x70, 0x40 (if type == 3) YES (1.10.8y; CR36=?2) */
  4159. /* Clevo 1024x768: 0x05, 0x60, 0x33 (if type != 3) YES (1.10.8y; CR36=?2) */
  4160. /* Asus 1024x768: ? ? (1.10.8o; CR36=?2) */
  4161. /* Asus 1024x768: 0x08, 0x10, 0x3c (problematic) YES (1.10.8q; CR36=22) */
  4162. if(SiS_Pr->HaveEMI) {
  4163. r30 = SiS_Pr->EMI_30; r31 = SiS_Pr->EMI_31;
  4164. r32 = SiS_Pr->EMI_32; r33 = SiS_Pr->EMI_33;
  4165. } else {
  4166. r30 = 0;
  4167. }
  4168. /* EMI_30 is read at driver start; however, the BIOS sets this
  4169. * (if it is used) only if the LCD is in use. In case we caught
  4170. * the machine while on TV output, this bit is not set and we
  4171. * don't know if it should be set - hence our detection is wrong.
  4172. * Work-around this here:
  4173. */
  4174. if((!SiS_Pr->HaveEMI) || (!SiS_Pr->HaveEMILCD)) {
  4175. switch((cr36 & 0x0f)) {
  4176. case 2:
  4177. r30 |= 0x40;
  4178. if(SiS_Pr->SiS_CustomT == CUT_CLEVO1024) r30 &= ~0x40;
  4179. if(!SiS_Pr->HaveEMI) {
  4180. r31 = 0x05; r32 = 0x60; r33 = 0x33;
  4181. if((cr36 & 0xf0) == 0x30) {
  4182. r31 = 0x0d; r32 = 0x70; r33 = 0x40;
  4183. }
  4184. }
  4185. break;
  4186. case 3: /* 1280x1024 */
  4187. if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) r30 |= 0x40;
  4188. if(!SiS_Pr->HaveEMI) {
  4189. r31 = 0x12; r32 = 0xd0; r33 = 0x6b;
  4190. if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) {
  4191. r31 = 0x0d; r32 = 0x70; r33 = 0x6b;
  4192. }
  4193. }
  4194. break;
  4195. case 9: /* 1400x1050 */
  4196. r30 |= 0x40;
  4197. if(!SiS_Pr->HaveEMI) {
  4198. r31 = 0x05; r32 = 0x60; r33 = 0x00;
  4199. if(SiS_Pr->SiS_CustomT == CUT_COMPAL1400_2) {
  4200. r31 = 0x0d; r32 = 0x70; r33 = 0x40; /* BIOS values */
  4201. }
  4202. }
  4203. break;
  4204. case 11: /* 1600x1200 - unknown */
  4205. r30 |= 0x40;
  4206. if(!SiS_Pr->HaveEMI) {
  4207. r31 = 0x05; r32 = 0x60; r33 = 0x00;
  4208. }
  4209. }
  4210. }
  4211. /* BIOS values don't work so well sometimes */
  4212. if(!SiS_Pr->OverruleEMI) {
  4213. #ifdef COMPAL_HACK
  4214. if(SiS_Pr->SiS_CustomT == CUT_COMPAL1400_2) {
  4215. if((cr36 & 0x0f) == 0x09) {
  4216. r30 = 0x60; r31 = 0x05; r32 = 0x60; r33 = 0x00;
  4217. }
  4218. }
  4219. #endif
  4220. #ifdef COMPAQ_HACK
  4221. if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) {
  4222. if((cr36 & 0x0f) == 0x03) {
  4223. r30 = 0x20; r31 = 0x12; r32 = 0xd0; r33 = 0x6b;
  4224. }
  4225. }
  4226. #endif
  4227. #ifdef ASUS_HACK
  4228. if(SiS_Pr->SiS_CustomT == CUT_ASUSA2H_2) {
  4229. if((cr36 & 0x0f) == 0x02) {
  4230. /* r30 = 0x60; r31 = 0x05; r32 = 0x60; r33 = 0x33; */ /* rev 2 */
  4231. /* r30 = 0x20; r31 = 0x05; r32 = 0x60; r33 = 0x33; */ /* rev 3 */
  4232. /* r30 = 0x60; r31 = 0x0d; r32 = 0x70; r33 = 0x40; */ /* rev 4 */
  4233. /* r30 = 0x20; r31 = 0x0d; r32 = 0x70; r33 = 0x40; */ /* rev 5 */
  4234. }
  4235. }
  4236. #endif
  4237. }
  4238. if(!(SiS_Pr->OverruleEMI && (!r30) && (!r31) && (!r32) && (!r33))) {
  4239. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x30,0x20); /* Reset */
  4240. SiS_GenericDelay(SiS_Pr, 2048);
  4241. }
  4242. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x31,r31);
  4243. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x32,r32);
  4244. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x33,r33);
  4245. #endif /* SET_EMI */
  4246. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x34,0x10);
  4247. #ifdef SET_EMI
  4248. if( (SiS_LCDAEnabled(SiS_Pr)) ||
  4249. (SiS_CRT2IsLCD(SiS_Pr)) ) {
  4250. if(r30 & 0x40) {
  4251. /*SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x2a,0x80);*/
  4252. SiS_PanelDelayLoop(SiS_Pr, 3, 5);
  4253. if(delaylong) {
  4254. SiS_PanelDelayLoop(SiS_Pr, 3, 5);
  4255. delaylong = false;
  4256. }
  4257. SiS_WaitVBRetrace(SiS_Pr);
  4258. SiS_WaitVBRetrace(SiS_Pr);
  4259. if(SiS_Pr->SiS_CustomT == CUT_ASUSA2H_2) {
  4260. SiS_GenericDelay(SiS_Pr, 1280);
  4261. }
  4262. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x30,0x40); /* Enable */
  4263. /*SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x2a,0x7f);*/
  4264. }
  4265. }
  4266. #endif
  4267. }
  4268. }
  4269. if(!(SiS_WeHaveBacklightCtrl(SiS_Pr))) {
  4270. if(SiS_IsVAorLCD(SiS_Pr)) {
  4271. SiS_PanelDelayLoop(SiS_Pr, 3, 10);
  4272. if(delaylong) {
  4273. SiS_PanelDelayLoop(SiS_Pr, 3, 10);
  4274. }
  4275. SiS_WaitVBRetrace(SiS_Pr);
  4276. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  4277. SiS_GenericDelay(SiS_Pr, 2048);
  4278. SiS_WaitVBRetrace(SiS_Pr);
  4279. }
  4280. if(!didpwd) {
  4281. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x01);
  4282. } else {
  4283. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x03);
  4284. }
  4285. }
  4286. }
  4287. SiS_SetReg(SiS_Pr->SiS_P3c4,0x06,pushax);
  4288. SiS_DisplayOn(SiS_Pr);
  4289. SiS_SetRegByte(SiS_Pr->SiS_P3c6,0xff);
  4290. }
  4291. if(!(SiS_WeHaveBacklightCtrl(SiS_Pr))) {
  4292. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x00,0x7f);
  4293. }
  4294. #endif /* CONFIG_FB_SIS_315 */
  4295. }
  4296. } else { /* ============ For 301 ================ */
  4297. if(SiS_Pr->ChipType < SIS_315H) {
  4298. if(SiS_CRT2IsLCD(SiS_Pr)) {
  4299. SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x00);
  4300. SiS_PanelDelay(SiS_Pr, 0);
  4301. }
  4302. }
  4303. temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x32) & 0xDF; /* lock mode */
  4304. if(SiS_BridgeInSlavemode(SiS_Pr)) {
  4305. tempah = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  4306. if(!(tempah & SetCRT2ToRAMDAC)) temp |= 0x20;
  4307. }
  4308. SiS_SetReg(SiS_Pr->SiS_P3c4,0x32,temp);
  4309. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20); /* enable CRT2 */
  4310. if(SiS_Pr->ChipType >= SIS_315H) {
  4311. temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x2E);
  4312. if(!(temp & 0x80)) {
  4313. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2E,0x80); /* BVBDOENABLE=1 */
  4314. }
  4315. }
  4316. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x00,0x1F,0x20); /* enable VB processor */
  4317. SiS_VBLongWait(SiS_Pr);
  4318. SiS_DisplayOn(SiS_Pr);
  4319. if(SiS_Pr->ChipType >= SIS_315H) {
  4320. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x00,0x7f);
  4321. }
  4322. SiS_VBLongWait(SiS_Pr);
  4323. if(SiS_Pr->ChipType < SIS_315H) {
  4324. if(SiS_CRT2IsLCD(SiS_Pr)) {
  4325. SiS_PanelDelay(SiS_Pr, 1);
  4326. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x00);
  4327. }
  4328. }
  4329. }
  4330. } else { /* =================== For LVDS ================== */
  4331. if(SiS_Pr->ChipType < SIS_315H) {
  4332. #ifdef CONFIG_FB_SIS_300 /* 300 series */
  4333. if(SiS_CRT2IsLCD(SiS_Pr)) {
  4334. if(SiS_Pr->ChipType == SIS_730) {
  4335. SiS_PanelDelay(SiS_Pr, 1);
  4336. SiS_PanelDelay(SiS_Pr, 1);
  4337. SiS_PanelDelay(SiS_Pr, 1);
  4338. }
  4339. SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x00);
  4340. if(!(SiS_CR36BIOSWord23d(SiS_Pr))) {
  4341. SiS_PanelDelay(SiS_Pr, 0);
  4342. }
  4343. }
  4344. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);
  4345. SiS_DisplayOn(SiS_Pr);
  4346. SiS_UnLockCRT2(SiS_Pr);
  4347. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x02,0xBF);
  4348. if(SiS_BridgeInSlavemode(SiS_Pr)) {
  4349. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x01,0x1F);
  4350. } else {
  4351. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x01,0x1F,0x40);
  4352. }
  4353. if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) {
  4354. if(!(SiS_CRT2IsLCD(SiS_Pr))) {
  4355. SiS_WaitVBRetrace(SiS_Pr);
  4356. SiS_SetCH700x(SiS_Pr,0x0E,0x0B);
  4357. }
  4358. }
  4359. if(SiS_CRT2IsLCD(SiS_Pr)) {
  4360. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x40)) {
  4361. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x16) & 0x10)) {
  4362. if(!(SiS_CR36BIOSWord23b(SiS_Pr))) {
  4363. SiS_PanelDelay(SiS_Pr, 1);
  4364. SiS_PanelDelay(SiS_Pr, 1);
  4365. }
  4366. SiS_WaitVBRetrace(SiS_Pr);
  4367. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x00);
  4368. }
  4369. }
  4370. }
  4371. #endif /* CONFIG_FB_SIS_300 */
  4372. } else {
  4373. #ifdef CONFIG_FB_SIS_315 /* 315 series */
  4374. if(!(SiS_IsNotM650orLater(SiS_Pr))) {
  4375. /*if(SiS_Pr->ChipType < SIS_340) {*/ /* XGI needs this */
  4376. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x4c,0x18);
  4377. /*}*/
  4378. }
  4379. if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
  4380. if(SiS_CRT2IsLCD(SiS_Pr)) {
  4381. SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x00);
  4382. SiS_PanelDelay(SiS_Pr, 0);
  4383. }
  4384. }
  4385. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);
  4386. SiS_UnLockCRT2(SiS_Pr);
  4387. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0xf7);
  4388. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  4389. temp = SiS_GetCH701x(SiS_Pr,0x66);
  4390. temp &= 0x20;
  4391. SiS_Chrontel701xBLOff(SiS_Pr);
  4392. }
  4393. if(SiS_Pr->ChipType != SIS_550) {
  4394. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0x7f);
  4395. }
  4396. if(SiS_Pr->ChipType == SIS_740) {
  4397. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  4398. if(SiS_IsLCDOrLCDA(SiS_Pr)) {
  4399. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x20);
  4400. }
  4401. }
  4402. }
  4403. temp1 = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x2E);
  4404. if(!(temp1 & 0x80)) {
  4405. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2E,0x80);
  4406. }
  4407. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  4408. if(temp) {
  4409. SiS_Chrontel701xBLOn(SiS_Pr);
  4410. }
  4411. }
  4412. if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
  4413. if(SiS_CRT2IsLCD(SiS_Pr)) {
  4414. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x20);
  4415. if(SiS_Pr->ChipType == SIS_550) {
  4416. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x40);
  4417. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x10);
  4418. }
  4419. }
  4420. } else if(SiS_IsVAMode(SiS_Pr)) {
  4421. if(SiS_Pr->ChipType != SIS_740) {
  4422. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x20);
  4423. }
  4424. }
  4425. if(!(SiS_WeHaveBacklightCtrl(SiS_Pr))) {
  4426. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x00,0x7f);
  4427. }
  4428. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  4429. if(SiS_IsTVOrYPbPrOrScart(SiS_Pr)) {
  4430. SiS_Chrontel701xOn(SiS_Pr);
  4431. }
  4432. if( (SiS_IsVAMode(SiS_Pr)) ||
  4433. (SiS_IsLCDOrLCDA(SiS_Pr)) ) {
  4434. SiS_ChrontelDoSomething1(SiS_Pr);
  4435. }
  4436. }
  4437. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  4438. if(!(SiS_WeHaveBacklightCtrl(SiS_Pr))) {
  4439. if( (SiS_IsVAMode(SiS_Pr)) ||
  4440. (SiS_IsLCDOrLCDA(SiS_Pr)) ) {
  4441. SiS_Chrontel701xBLOn(SiS_Pr);
  4442. SiS_ChrontelInitTVVSync(SiS_Pr);
  4443. }
  4444. }
  4445. } else if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
  4446. if(!(SiS_WeHaveBacklightCtrl(SiS_Pr))) {
  4447. if(SiS_CRT2IsLCD(SiS_Pr)) {
  4448. SiS_PanelDelay(SiS_Pr, 1);
  4449. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x00);
  4450. }
  4451. }
  4452. }
  4453. #endif /* CONFIG_FB_SIS_315 */
  4454. } /* 310 series */
  4455. } /* LVDS */
  4456. }
  4457. /*********************************************/
  4458. /* SET PART 1 REGISTER GROUP */
  4459. /*********************************************/
  4460. /* Set CRT2 OFFSET / PITCH */
  4461. static void
  4462. SiS_SetCRT2Offset(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  4463. unsigned short RRTI)
  4464. {
  4465. unsigned short offset;
  4466. unsigned char temp;
  4467. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) return;
  4468. offset = SiS_GetOffset(SiS_Pr,ModeNo,ModeIdIndex,RRTI);
  4469. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x07,(offset & 0xFF));
  4470. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x09,(offset >> 8));
  4471. temp = (unsigned char)(((offset >> 3) & 0xFF) + 1);
  4472. if(offset & 0x07) temp++;
  4473. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x03,temp);
  4474. }
  4475. /* Set CRT2 sync and PanelLink mode */
  4476. static void
  4477. SiS_SetCRT2Sync(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short RefreshRateTableIndex)
  4478. {
  4479. unsigned short tempah=0, tempbl, infoflag;
  4480. tempbl = 0xC0;
  4481. if(SiS_Pr->UseCustomMode) {
  4482. infoflag = SiS_Pr->CInfoFlag;
  4483. } else {
  4484. infoflag = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
  4485. }
  4486. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { /* LVDS */
  4487. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  4488. tempah = 0;
  4489. } else if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && (SiS_Pr->SiS_LCDInfo & LCDSync)) {
  4490. tempah = SiS_Pr->SiS_LCDInfo;
  4491. } else tempah = infoflag >> 8;
  4492. tempah &= 0xC0;
  4493. tempah |= 0x20;
  4494. if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10;
  4495. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  4496. if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) ||
  4497. (SiS_Pr->SiS_CustomT == CUT_BARCO1024)) {
  4498. tempah |= 0xf0;
  4499. }
  4500. if( (SiS_Pr->SiS_IF_DEF_FSTN) ||
  4501. (SiS_Pr->SiS_IF_DEF_DSTN) ||
  4502. (SiS_Pr->SiS_IF_DEF_TRUMPION) ||
  4503. (SiS_Pr->SiS_CustomT == CUT_PANEL848) ||
  4504. (SiS_Pr->SiS_CustomT == CUT_PANEL856) ) {
  4505. tempah |= 0x30;
  4506. }
  4507. if( (SiS_Pr->SiS_IF_DEF_FSTN) ||
  4508. (SiS_Pr->SiS_IF_DEF_DSTN) ) {
  4509. tempah &= ~0xc0;
  4510. }
  4511. }
  4512. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  4513. if(SiS_Pr->ChipType >= SIS_315H) {
  4514. tempah >>= 3;
  4515. tempah &= 0x18;
  4516. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,0xE7,tempah);
  4517. /* Don't care about 12/18/24 bit mode - TV is via VGA, not PL */
  4518. } else {
  4519. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,0xe0);
  4520. }
  4521. } else {
  4522. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah);
  4523. }
  4524. } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
  4525. if(SiS_Pr->ChipType < SIS_315H) {
  4526. #ifdef CONFIG_FB_SIS_300 /* ---- 300 series --- */
  4527. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) { /* 630 - 301B(-DH) */
  4528. tempah = infoflag >> 8;
  4529. tempbl = 0;
  4530. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  4531. if(SiS_Pr->SiS_LCDInfo & LCDSync) {
  4532. tempah = SiS_Pr->SiS_LCDInfo;
  4533. tempbl = (tempah >> 6) & 0x03;
  4534. }
  4535. }
  4536. tempah &= 0xC0;
  4537. tempah |= 0x20;
  4538. if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10;
  4539. tempah |= 0xc0;
  4540. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah);
  4541. if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && (!(SiS_Pr->SiS_VBType & VB_NoLCD))) {
  4542. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1a,0xf0,tempbl);
  4543. }
  4544. } else { /* 630 - 301 */
  4545. tempah = ((infoflag >> 8) & 0xc0) | 0x20;
  4546. if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10;
  4547. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah);
  4548. }
  4549. #endif /* CONFIG_FB_SIS_300 */
  4550. } else {
  4551. #ifdef CONFIG_FB_SIS_315 /* ------- 315 series ------ */
  4552. if(SiS_Pr->SiS_VBType & VB_SISLVDS) { /* 315 - LVDS */
  4553. tempbl = 0;
  4554. if((SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) &&
  4555. (SiS_Pr->SiS_LCDResInfo == Panel_1280x1024)) {
  4556. tempah = infoflag >> 8;
  4557. if(SiS_Pr->SiS_LCDInfo & LCDSync) {
  4558. tempbl = ((SiS_Pr->SiS_LCDInfo & 0xc0) >> 6);
  4559. }
  4560. } else if((SiS_Pr->SiS_CustomT == CUT_CLEVO1400) &&
  4561. (SiS_Pr->SiS_LCDResInfo == Panel_1400x1050)) {
  4562. tempah = infoflag >> 8;
  4563. tempbl = 0x03;
  4564. } else {
  4565. tempah = SiS_GetReg(SiS_Pr->SiS_P3d4,0x37);
  4566. tempbl = (tempah >> 6) & 0x03;
  4567. tempbl |= 0x08;
  4568. if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempbl |= 0x04;
  4569. }
  4570. tempah &= 0xC0;
  4571. tempah |= 0x20;
  4572. if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10;
  4573. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) tempah |= 0xc0;
  4574. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah);
  4575. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  4576. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  4577. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1a,0xf0,tempbl);
  4578. }
  4579. }
  4580. } else { /* 315 - TMDS */
  4581. tempah = tempbl = infoflag >> 8;
  4582. if(!SiS_Pr->UseCustomMode) {
  4583. tempbl = 0;
  4584. if((SiS_Pr->SiS_VBType & VB_SIS30xC) && (SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) {
  4585. if(ModeNo <= 0x13) {
  4586. tempah = SiS_GetRegByte((SiS_Pr->SiS_P3ca+0x02));
  4587. }
  4588. }
  4589. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4590. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  4591. if(SiS_Pr->SiS_LCDInfo & LCDSync) {
  4592. tempah = SiS_Pr->SiS_LCDInfo;
  4593. tempbl = (tempah >> 6) & 0x03;
  4594. }
  4595. }
  4596. }
  4597. }
  4598. tempah &= 0xC0;
  4599. tempah |= 0x20;
  4600. if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10;
  4601. if(SiS_Pr->SiS_VBType & VB_NoLCD) {
  4602. /* Imitate BIOS bug */
  4603. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) tempah |= 0xc0;
  4604. }
  4605. if((SiS_Pr->SiS_VBType & VB_SIS30xC) && (SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) {
  4606. tempah >>= 3;
  4607. tempah &= 0x18;
  4608. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,0xe7,tempah);
  4609. } else {
  4610. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah);
  4611. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  4612. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  4613. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1a,0xf0,tempbl);
  4614. }
  4615. }
  4616. }
  4617. }
  4618. #endif /* CONFIG_FB_SIS_315 */
  4619. }
  4620. }
  4621. }
  4622. /* Set CRT2 FIFO on 300/540/630/730 */
  4623. #ifdef CONFIG_FB_SIS_300
  4624. static void
  4625. SiS_SetCRT2FIFO_300(struct SiS_Private *SiS_Pr,unsigned short ModeNo)
  4626. {
  4627. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  4628. unsigned short temp, index, modeidindex, refreshratetableindex;
  4629. unsigned short VCLK = 0, MCLK, colorth = 0, data2 = 0;
  4630. unsigned short tempbx, tempcl, CRT1ModeNo, CRT2ModeNo, SelectRate_backup;
  4631. unsigned int data, pci50, pciA0;
  4632. static const unsigned char colortharray[] = {
  4633. 1, 1, 2, 2, 3, 4
  4634. };
  4635. SelectRate_backup = SiS_Pr->SiS_SelectCRT2Rate;
  4636. if(!SiS_Pr->CRT1UsesCustomMode) {
  4637. CRT1ModeNo = SiS_Pr->SiS_CRT1Mode; /* get CRT1 ModeNo */
  4638. SiS_SearchModeID(SiS_Pr, &CRT1ModeNo, &modeidindex);
  4639. SiS_Pr->SiS_SetFlag &= (~ProgrammingCRT2);
  4640. SiS_Pr->SiS_SelectCRT2Rate = 0;
  4641. refreshratetableindex = SiS_GetRatePtr(SiS_Pr, CRT1ModeNo, modeidindex);
  4642. if(CRT1ModeNo >= 0x13) {
  4643. /* Get VCLK */
  4644. index = SiS_GetRefCRTVCLK(SiS_Pr, refreshratetableindex, SiS_Pr->SiS_UseWide);
  4645. VCLK = SiS_Pr->SiS_VCLKData[index].CLOCK;
  4646. /* Get colordepth */
  4647. colorth = SiS_GetColorDepth(SiS_Pr,CRT1ModeNo,modeidindex) >> 1;
  4648. if(!colorth) colorth++;
  4649. }
  4650. } else {
  4651. CRT1ModeNo = 0xfe;
  4652. /* Get VCLK */
  4653. VCLK = SiS_Pr->CSRClock_CRT1;
  4654. /* Get color depth */
  4655. colorth = colortharray[((SiS_Pr->CModeFlag_CRT1 & ModeTypeMask) - 2)];
  4656. }
  4657. if(CRT1ModeNo >= 0x13) {
  4658. /* Get MCLK */
  4659. if(SiS_Pr->ChipType == SIS_300) {
  4660. index = SiS_GetReg(SiS_Pr->SiS_P3c4,0x3A);
  4661. } else {
  4662. index = SiS_GetReg(SiS_Pr->SiS_P3c4,0x1A);
  4663. }
  4664. index &= 0x07;
  4665. MCLK = SiS_Pr->SiS_MCLKData_0[index].CLOCK;
  4666. temp = ((SiS_GetReg(SiS_Pr->SiS_P3c4,0x14) >> 6) & 0x03) << 1;
  4667. if(!temp) temp++;
  4668. temp <<= 2;
  4669. data2 = temp - ((colorth * VCLK) / MCLK);
  4670. temp = (28 * 16) % data2;
  4671. data2 = (28 * 16) / data2;
  4672. if(temp) data2++;
  4673. if(SiS_Pr->ChipType == SIS_300) {
  4674. SiS_GetFIFOThresholdIndex300(SiS_Pr, &tempbx, &tempcl);
  4675. data = SiS_GetFIFOThresholdB300(tempbx, tempcl);
  4676. } else {
  4677. pci50 = sisfb_read_nbridge_pci_dword(SiS_Pr, 0x50);
  4678. pciA0 = sisfb_read_nbridge_pci_dword(SiS_Pr, 0xa0);
  4679. if(SiS_Pr->ChipType == SIS_730) {
  4680. index = (unsigned short)(((pciA0 >> 28) & 0x0f) * 3);
  4681. index += (unsigned short)(((pci50 >> 9)) & 0x03);
  4682. /* BIOS BUG (2.04.5d, 2.04.6a use ah here, which is unset!) */
  4683. index = 0; /* -- do it like the BIOS anyway... */
  4684. } else {
  4685. pci50 >>= 24;
  4686. pciA0 >>= 24;
  4687. index = (pci50 >> 1) & 0x07;
  4688. if(pci50 & 0x01) index += 6;
  4689. if(!(pciA0 & 0x01)) index += 24;
  4690. if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x14) & 0x80) index += 12;
  4691. }
  4692. data = SiS_GetLatencyFactor630(SiS_Pr, index) + 15;
  4693. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x14) & 0x80)) data += 5;
  4694. }
  4695. data += data2; /* CRT1 Request Period */
  4696. SiS_Pr->SiS_SetFlag |= ProgrammingCRT2;
  4697. SiS_Pr->SiS_SelectCRT2Rate = SelectRate_backup;
  4698. if(!SiS_Pr->UseCustomMode) {
  4699. CRT2ModeNo = ModeNo;
  4700. SiS_SearchModeID(SiS_Pr, &CRT2ModeNo, &modeidindex);
  4701. refreshratetableindex = SiS_GetRatePtr(SiS_Pr, CRT2ModeNo, modeidindex);
  4702. /* Get VCLK */
  4703. index = SiS_GetVCLK2Ptr(SiS_Pr, CRT2ModeNo, modeidindex, refreshratetableindex);
  4704. VCLK = SiS_Pr->SiS_VCLKData[index].CLOCK;
  4705. if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) || (SiS_Pr->SiS_CustomT == CUT_BARCO1024)) {
  4706. if(SiS_Pr->SiS_UseROM) {
  4707. if(ROMAddr[0x220] & 0x01) {
  4708. VCLK = ROMAddr[0x229] | (ROMAddr[0x22a] << 8);
  4709. }
  4710. }
  4711. }
  4712. } else {
  4713. /* Get VCLK */
  4714. CRT2ModeNo = 0xfe;
  4715. VCLK = SiS_Pr->CSRClock;
  4716. }
  4717. /* Get colordepth */
  4718. colorth = SiS_GetColorDepth(SiS_Pr,CRT2ModeNo,modeidindex) >> 1;
  4719. if(!colorth) colorth++;
  4720. data = data * VCLK * colorth;
  4721. temp = data % (MCLK << 4);
  4722. data = data / (MCLK << 4);
  4723. if(temp) data++;
  4724. if(data < 6) data = 6;
  4725. else if(data > 0x14) data = 0x14;
  4726. if(SiS_Pr->ChipType == SIS_300) {
  4727. temp = 0x16;
  4728. if((data <= 0x0f) || (SiS_Pr->SiS_LCDResInfo == Panel_1280x1024))
  4729. temp = 0x13;
  4730. } else {
  4731. temp = 0x16;
  4732. if(( (SiS_Pr->ChipType == SIS_630) ||
  4733. (SiS_Pr->ChipType == SIS_730) ) &&
  4734. (SiS_Pr->ChipRevision >= 0x30))
  4735. temp = 0x1b;
  4736. }
  4737. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x01,0xe0,temp);
  4738. if((SiS_Pr->ChipType == SIS_630) &&
  4739. (SiS_Pr->ChipRevision >= 0x30)) {
  4740. if(data > 0x13) data = 0x13;
  4741. }
  4742. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x02,0xe0,data);
  4743. } else { /* If mode <= 0x13, we just restore everything */
  4744. SiS_Pr->SiS_SetFlag |= ProgrammingCRT2;
  4745. SiS_Pr->SiS_SelectCRT2Rate = SelectRate_backup;
  4746. }
  4747. }
  4748. #endif
  4749. /* Set CRT2 FIFO on 315/330 series */
  4750. #ifdef CONFIG_FB_SIS_315
  4751. static void
  4752. SiS_SetCRT2FIFO_310(struct SiS_Private *SiS_Pr)
  4753. {
  4754. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x01,0x3B);
  4755. if( (SiS_Pr->ChipType == SIS_760) &&
  4756. (SiS_Pr->SiS_SysFlags & SF_760LFB) &&
  4757. (SiS_Pr->SiS_ModeType == Mode32Bpp) &&
  4758. (SiS_Pr->SiS_VGAHDE >= 1280) &&
  4759. (SiS_Pr->SiS_VGAVDE >= 1024) ) {
  4760. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2f,0x03);
  4761. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x01,0x3b);
  4762. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x4d,0xc0);
  4763. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2f,0x01);
  4764. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x4d,0xc0);
  4765. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x02,0x6e);
  4766. } else {
  4767. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x02,~0x3f,0x04);
  4768. }
  4769. }
  4770. #endif
  4771. static unsigned short
  4772. SiS_GetVGAHT2(struct SiS_Private *SiS_Pr)
  4773. {
  4774. unsigned int tempax,tempbx;
  4775. tempbx = (SiS_Pr->SiS_VGAVT - SiS_Pr->SiS_VGAVDE) * SiS_Pr->SiS_RVBHCMAX;
  4776. tempax = (SiS_Pr->SiS_VT - SiS_Pr->SiS_VDE) * SiS_Pr->SiS_RVBHCFACT;
  4777. tempax = (tempax * SiS_Pr->SiS_HT) / tempbx;
  4778. return (unsigned short)tempax;
  4779. }
  4780. /* Set Part 1 / SiS bridge slave mode */
  4781. static void
  4782. SiS_SetGroup1_301(struct SiS_Private *SiS_Pr, unsigned short ModeNo,unsigned short ModeIdIndex,
  4783. unsigned short RefreshRateTableIndex)
  4784. {
  4785. unsigned short temp, modeflag, i, j, xres=0, VGAVDE;
  4786. static const unsigned short CRTranslation[] = {
  4787. /* CR0 CR1 CR2 CR3 CR4 CR5 CR6 CR7 */
  4788. 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a,
  4789. /* CR8 CR9 SR0A SR0B SR0C SR0D SR0E CR0F */
  4790. 0x00, 0x0b, 0x17, 0x18, 0x19, 0x00, 0x1a, 0x00,
  4791. /* CR10 CR11 CR12 CR13 CR14 CR15 CR16 CR17 */
  4792. 0x0c, 0x0d, 0x0e, 0x00, 0x0f, 0x10, 0x11, 0x00
  4793. };
  4794. if(ModeNo <= 0x13) {
  4795. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  4796. } else if(SiS_Pr->UseCustomMode) {
  4797. modeflag = SiS_Pr->CModeFlag;
  4798. xres = SiS_Pr->CHDisplay;
  4799. } else {
  4800. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  4801. xres = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].XRes;
  4802. }
  4803. /* The following is only done if bridge is in slave mode: */
  4804. if(SiS_Pr->ChipType >= SIS_315H) {
  4805. if(xres >= 1600) { /* BIOS: == 1600 */
  4806. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x31,0x04);
  4807. }
  4808. }
  4809. SiS_Pr->CHTotal = 8224; /* Max HT, 0x2020, results in 0x3ff in registers */
  4810. SiS_Pr->CHDisplay = SiS_Pr->SiS_VGAHDE;
  4811. if(modeflag & HalfDCLK) SiS_Pr->CHDisplay >>= 1;
  4812. SiS_Pr->CHBlankStart = SiS_Pr->CHDisplay;
  4813. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  4814. SiS_Pr->CHBlankStart += 16;
  4815. }
  4816. SiS_Pr->CHBlankEnd = 32;
  4817. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  4818. if(xres == 1600) SiS_Pr->CHBlankEnd += 80;
  4819. }
  4820. temp = SiS_Pr->SiS_VGAHT - 96;
  4821. if(!(modeflag & HalfDCLK)) temp -= 32;
  4822. if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
  4823. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x04);
  4824. temp |= ((SiS_GetReg(SiS_Pr->SiS_P3c4,0x0b) & 0xc0) << 2);
  4825. temp -= 3;
  4826. temp <<= 3;
  4827. } else {
  4828. if(SiS_Pr->SiS_RVBHRS2) temp = SiS_Pr->SiS_RVBHRS2;
  4829. }
  4830. SiS_Pr->CHSyncStart = temp;
  4831. SiS_Pr->CHSyncEnd = 0xffe8; /* results in 0x2000 in registers */
  4832. SiS_Pr->CVTotal = 2049; /* Max VT, 0x0801, results in 0x7ff in registers */
  4833. VGAVDE = SiS_Pr->SiS_VGAVDE;
  4834. if (VGAVDE == 357) VGAVDE = 350;
  4835. else if(VGAVDE == 360) VGAVDE = 350;
  4836. else if(VGAVDE == 375) VGAVDE = 350;
  4837. else if(VGAVDE == 405) VGAVDE = 400;
  4838. else if(VGAVDE == 420) VGAVDE = 400;
  4839. else if(VGAVDE == 525) VGAVDE = 480;
  4840. else if(VGAVDE == 1056) VGAVDE = 1024;
  4841. SiS_Pr->CVDisplay = VGAVDE;
  4842. SiS_Pr->CVBlankStart = SiS_Pr->CVDisplay;
  4843. SiS_Pr->CVBlankEnd = 1;
  4844. if(ModeNo == 0x3c) SiS_Pr->CVBlankEnd = 226;
  4845. temp = (SiS_Pr->SiS_VGAVT - VGAVDE) >> 1;
  4846. SiS_Pr->CVSyncStart = VGAVDE + temp;
  4847. temp >>= 3;
  4848. SiS_Pr->CVSyncEnd = SiS_Pr->CVSyncStart + temp;
  4849. SiS_CalcCRRegisters(SiS_Pr, 0);
  4850. SiS_Pr->CCRT1CRTC[16] &= ~0xE0;
  4851. for(i = 0; i <= 7; i++) {
  4852. SiS_SetReg(SiS_Pr->SiS_Part1Port,CRTranslation[i],SiS_Pr->CCRT1CRTC[i]);
  4853. }
  4854. for(i = 0x10, j = 8; i <= 0x12; i++, j++) {
  4855. SiS_SetReg(SiS_Pr->SiS_Part1Port,CRTranslation[i],SiS_Pr->CCRT1CRTC[j]);
  4856. }
  4857. for(i = 0x15, j = 11; i <= 0x16; i++, j++) {
  4858. SiS_SetReg(SiS_Pr->SiS_Part1Port,CRTranslation[i],SiS_Pr->CCRT1CRTC[j]);
  4859. }
  4860. for(i = 0x0a, j = 13; i <= 0x0c; i++, j++) {
  4861. SiS_SetReg(SiS_Pr->SiS_Part1Port,CRTranslation[i],SiS_Pr->CCRT1CRTC[j]);
  4862. }
  4863. temp = SiS_Pr->CCRT1CRTC[16] & 0xE0;
  4864. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,CRTranslation[0x0E],0x1F,temp);
  4865. temp = (SiS_Pr->CCRT1CRTC[16] & 0x01) << 5;
  4866. if(modeflag & DoubleScanMode) temp |= 0x80;
  4867. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,CRTranslation[0x09],0x5F,temp);
  4868. temp = 0;
  4869. temp |= (SiS_GetReg(SiS_Pr->SiS_P3c4,0x01) & 0x01);
  4870. if(modeflag & HalfDCLK) temp |= 0x08;
  4871. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x16,temp); /* SR01: HalfDCLK[3], 8/9 div dotclock[0] */
  4872. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0F,0x00); /* CR14: (text mode: underline location) */
  4873. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x12,0x00); /* CR17: n/a */
  4874. temp = 0;
  4875. if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) {
  4876. temp = (SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x01) << 7;
  4877. }
  4878. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1A,temp); /* SR0E, dither[7] */
  4879. temp = SiS_GetRegByte((SiS_Pr->SiS_P3ca+0x02));
  4880. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,temp); /* ? */
  4881. }
  4882. /* Setup panel link
  4883. * This is used for LVDS, LCDA and Chrontel TV output
  4884. * 300/LVDS+TV, 300/301B-DH, 315/LVDS+TV, 315/LCDA
  4885. */
  4886. static void
  4887. SiS_SetGroup1_LVDS(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  4888. unsigned short RefreshRateTableIndex)
  4889. {
  4890. unsigned short modeflag, resinfo = 0;
  4891. unsigned short push2, tempax, tempbx, tempcx, temp;
  4892. unsigned int tempeax = 0, tempebx, tempecx, tempvcfact = 0;
  4893. bool islvds = false, issis = false, chkdclkfirst = false;
  4894. #ifdef CONFIG_FB_SIS_300
  4895. unsigned short crt2crtc = 0;
  4896. #endif
  4897. #ifdef CONFIG_FB_SIS_315
  4898. unsigned short pushcx;
  4899. #endif
  4900. if(ModeNo <= 0x13) {
  4901. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  4902. resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
  4903. #ifdef CONFIG_FB_SIS_300
  4904. crt2crtc = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  4905. #endif
  4906. } else if(SiS_Pr->UseCustomMode) {
  4907. modeflag = SiS_Pr->CModeFlag;
  4908. } else {
  4909. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  4910. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  4911. #ifdef CONFIG_FB_SIS_300
  4912. crt2crtc = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  4913. #endif
  4914. }
  4915. /* is lvds if really LVDS, or 301B-DH with external LVDS transmitter */
  4916. if((SiS_Pr->SiS_IF_DEF_LVDS == 1) || (SiS_Pr->SiS_VBType & VB_NoLCD)) {
  4917. islvds = true;
  4918. }
  4919. /* is really sis if sis bridge, but not 301B-DH */
  4920. if((SiS_Pr->SiS_VBType & VB_SISVB) && (!(SiS_Pr->SiS_VBType & VB_NoLCD))) {
  4921. issis = true;
  4922. }
  4923. if((SiS_Pr->ChipType >= SIS_315H) && (islvds) && (!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA))) {
  4924. if((!SiS_Pr->SiS_IF_DEF_FSTN) && (!SiS_Pr->SiS_IF_DEF_DSTN)) {
  4925. chkdclkfirst = true;
  4926. }
  4927. }
  4928. #ifdef CONFIG_FB_SIS_315
  4929. if((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  4930. if(IS_SIS330) {
  4931. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x10);
  4932. } else if(IS_SIS740) {
  4933. if(islvds) {
  4934. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,0xfb,0x04);
  4935. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x03);
  4936. } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
  4937. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x10);
  4938. }
  4939. } else {
  4940. if(islvds) {
  4941. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,0xfb,0x04);
  4942. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x00);
  4943. } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
  4944. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2D,0x0f);
  4945. if(SiS_Pr->SiS_VBType & VB_SIS30xC) {
  4946. if((SiS_Pr->SiS_LCDResInfo == Panel_1024x768) ||
  4947. (SiS_Pr->SiS_LCDResInfo == Panel_1280x1024)) {
  4948. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x20);
  4949. }
  4950. }
  4951. }
  4952. }
  4953. }
  4954. #endif
  4955. /* Horizontal */
  4956. tempax = SiS_Pr->SiS_LCDHDES;
  4957. if(islvds) {
  4958. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4959. if(!SiS_Pr->SiS_IF_DEF_FSTN && !SiS_Pr->SiS_IF_DEF_DSTN) {
  4960. if((SiS_Pr->SiS_LCDResInfo == Panel_640x480) &&
  4961. (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode))) {
  4962. tempax -= 8;
  4963. }
  4964. }
  4965. }
  4966. }
  4967. temp = (tempax & 0x0007);
  4968. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1A,temp); /* BPLHDESKEW[2:0] */
  4969. temp = (tempax >> 3) & 0x00FF;
  4970. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x16,temp); /* BPLHDESKEW[10:3] */
  4971. tempbx = SiS_Pr->SiS_HDE;
  4972. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4973. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  4974. tempbx = SiS_Pr->PanelXRes;
  4975. }
  4976. if((SiS_Pr->SiS_LCDResInfo == Panel_320x240_1) ||
  4977. (SiS_Pr->SiS_LCDResInfo == Panel_320x240_2) ||
  4978. (SiS_Pr->SiS_LCDResInfo == Panel_320x240_3)) {
  4979. tempbx >>= 1;
  4980. }
  4981. }
  4982. tempax += tempbx;
  4983. if(tempax >= SiS_Pr->SiS_HT) tempax -= SiS_Pr->SiS_HT;
  4984. temp = tempax;
  4985. if(temp & 0x07) temp += 8;
  4986. temp >>= 3;
  4987. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x17,temp); /* BPLHDEE */
  4988. tempcx = (SiS_Pr->SiS_HT - tempbx) >> 2;
  4989. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4990. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  4991. if(SiS_Pr->PanelHRS != 999) tempcx = SiS_Pr->PanelHRS;
  4992. }
  4993. }
  4994. tempcx += tempax;
  4995. if(tempcx >= SiS_Pr->SiS_HT) tempcx -= SiS_Pr->SiS_HT;
  4996. temp = (tempcx >> 3) & 0x00FF;
  4997. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4998. if(SiS_Pr->SiS_IF_DEF_TRUMPION) {
  4999. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  5000. switch(ModeNo) {
  5001. case 0x04:
  5002. case 0x05:
  5003. case 0x0d: temp = 0x56; break;
  5004. case 0x10: temp = 0x60; break;
  5005. case 0x13: temp = 0x5f; break;
  5006. case 0x40:
  5007. case 0x41:
  5008. case 0x4f:
  5009. case 0x43:
  5010. case 0x44:
  5011. case 0x62:
  5012. case 0x56:
  5013. case 0x53:
  5014. case 0x5d:
  5015. case 0x5e: temp = 0x54; break;
  5016. }
  5017. }
  5018. }
  5019. }
  5020. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x14,temp); /* BPLHRS */
  5021. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  5022. temp += 2;
  5023. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  5024. temp += 8;
  5025. if(SiS_Pr->PanelHRE != 999) {
  5026. temp = tempcx + SiS_Pr->PanelHRE;
  5027. if(temp >= SiS_Pr->SiS_HT) temp -= SiS_Pr->SiS_HT;
  5028. temp >>= 3;
  5029. }
  5030. }
  5031. } else {
  5032. temp += 10;
  5033. }
  5034. temp &= 0x1F;
  5035. temp |= ((tempcx & 0x07) << 5);
  5036. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x15,temp); /* BPLHRE */
  5037. /* Vertical */
  5038. tempax = SiS_Pr->SiS_VGAVDE;
  5039. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  5040. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  5041. tempax = SiS_Pr->PanelYRes;
  5042. }
  5043. }
  5044. tempbx = SiS_Pr->SiS_LCDVDES + tempax;
  5045. if(tempbx >= SiS_Pr->SiS_VT) tempbx -= SiS_Pr->SiS_VT;
  5046. push2 = tempbx;
  5047. tempcx = SiS_Pr->SiS_VGAVT - SiS_Pr->SiS_VGAVDE;
  5048. if(SiS_Pr->ChipType < SIS_315H) {
  5049. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  5050. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  5051. tempcx = SiS_Pr->SiS_VGAVT - SiS_Pr->PanelYRes;
  5052. }
  5053. }
  5054. }
  5055. if(islvds) tempcx >>= 1;
  5056. else tempcx >>= 2;
  5057. if( (SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) &&
  5058. (!(SiS_Pr->SiS_LCDInfo & LCDPass11)) &&
  5059. (SiS_Pr->PanelVRS != 999) ) {
  5060. tempcx = SiS_Pr->PanelVRS;
  5061. tempbx += tempcx;
  5062. if(issis) tempbx++;
  5063. } else {
  5064. tempbx += tempcx;
  5065. if(SiS_Pr->ChipType < SIS_315H) tempbx++;
  5066. else if(issis) tempbx++;
  5067. }
  5068. if(tempbx >= SiS_Pr->SiS_VT) tempbx -= SiS_Pr->SiS_VT;
  5069. temp = tempbx & 0x00FF;
  5070. if(SiS_Pr->SiS_IF_DEF_TRUMPION) {
  5071. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  5072. if(ModeNo == 0x10) temp = 0xa9;
  5073. }
  5074. }
  5075. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,temp); /* BPLVRS */
  5076. tempcx >>= 3;
  5077. tempcx++;
  5078. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  5079. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  5080. if(SiS_Pr->PanelVRE != 999) tempcx = SiS_Pr->PanelVRE;
  5081. }
  5082. }
  5083. tempcx += tempbx;
  5084. temp = tempcx & 0x000F;
  5085. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0xF0,temp); /* BPLVRE */
  5086. temp = ((tempbx >> 8) & 0x07) << 3;
  5087. if(SiS_Pr->SiS_IF_DEF_FSTN || SiS_Pr->SiS_IF_DEF_DSTN) {
  5088. if(SiS_Pr->SiS_HDE != 640) {
  5089. if(SiS_Pr->SiS_VGAVDE != SiS_Pr->SiS_VDE) temp |= 0x40;
  5090. }
  5091. } else if(SiS_Pr->SiS_VGAVDE != SiS_Pr->SiS_VDE) temp |= 0x40;
  5092. if(SiS_Pr->SiS_SetFlag & EnableLVDSDDA) temp |= 0x40;
  5093. tempbx = 0x87;
  5094. if((SiS_Pr->ChipType >= SIS_315H) ||
  5095. (SiS_Pr->ChipRevision >= 0x30)) {
  5096. tempbx = 0x07;
  5097. if((SiS_Pr->SiS_IF_DEF_CH70xx == 1) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
  5098. if(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x03) temp |= 0x80;
  5099. }
  5100. /* Chrontel 701x operates in 24bit mode (8-8-8, 2x12bit multiplexed) via VGA2 */
  5101. if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) {
  5102. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  5103. if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x06) & 0x10) temp |= 0x80;
  5104. } else {
  5105. if(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x01) temp |= 0x80;
  5106. }
  5107. }
  5108. }
  5109. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x1A,tempbx,temp);
  5110. tempbx = push2; /* BPLVDEE */
  5111. tempcx = SiS_Pr->SiS_LCDVDES; /* BPLVDES */
  5112. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  5113. switch(SiS_Pr->SiS_LCDResInfo) {
  5114. case Panel_640x480:
  5115. tempbx = SiS_Pr->SiS_VGAVDE - 1;
  5116. tempcx = SiS_Pr->SiS_VGAVDE;
  5117. break;
  5118. case Panel_800x600:
  5119. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  5120. if(resinfo == SIS_RI_800x600) tempcx++;
  5121. }
  5122. break;
  5123. case Panel_1024x600:
  5124. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  5125. if(resinfo == SIS_RI_1024x600) tempcx++;
  5126. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  5127. if(resinfo == SIS_RI_800x600) tempcx++;
  5128. }
  5129. }
  5130. break;
  5131. case Panel_1024x768:
  5132. if(SiS_Pr->ChipType < SIS_315H) {
  5133. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  5134. if(resinfo == SIS_RI_1024x768) tempcx++;
  5135. }
  5136. }
  5137. break;
  5138. }
  5139. }
  5140. temp = ((tempbx >> 8) & 0x07) << 3;
  5141. temp |= ((tempcx >> 8) & 0x07);
  5142. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1D,temp);
  5143. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1C,tempbx);
  5144. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1B,tempcx);
  5145. /* Vertical scaling */
  5146. if(SiS_Pr->ChipType < SIS_315H) {
  5147. #ifdef CONFIG_FB_SIS_300 /* 300 series */
  5148. tempeax = SiS_Pr->SiS_VGAVDE << 6;
  5149. temp = (tempeax % (unsigned int)SiS_Pr->SiS_VDE);
  5150. tempeax = tempeax / (unsigned int)SiS_Pr->SiS_VDE;
  5151. if(temp) tempeax++;
  5152. if(SiS_Pr->SiS_SetFlag & EnableLVDSDDA) tempeax = 0x3F;
  5153. temp = (unsigned short)(tempeax & 0x00FF);
  5154. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1E,temp); /* BPLVCFACT */
  5155. tempvcfact = temp;
  5156. #endif /* CONFIG_FB_SIS_300 */
  5157. } else {
  5158. #ifdef CONFIG_FB_SIS_315 /* 315 series */
  5159. tempeax = SiS_Pr->SiS_VGAVDE << 18;
  5160. tempebx = SiS_Pr->SiS_VDE;
  5161. temp = (tempeax % tempebx);
  5162. tempeax = tempeax / tempebx;
  5163. if(temp) tempeax++;
  5164. tempvcfact = tempeax;
  5165. temp = (unsigned short)(tempeax & 0x00FF);
  5166. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x37,temp);
  5167. temp = (unsigned short)((tempeax & 0x00FF00) >> 8);
  5168. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x36,temp);
  5169. temp = (unsigned short)((tempeax & 0x00030000) >> 16);
  5170. if(SiS_Pr->SiS_VDE == SiS_Pr->SiS_VGAVDE) temp |= 0x04;
  5171. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x35,temp);
  5172. if(SiS_Pr->SiS_VBType & VB_SISPART4SCALER) {
  5173. temp = (unsigned short)(tempeax & 0x00FF);
  5174. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x3c,temp);
  5175. temp = (unsigned short)((tempeax & 0x00FF00) >> 8);
  5176. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x3b,temp);
  5177. temp = (unsigned short)(((tempeax & 0x00030000) >> 16) << 6);
  5178. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x3a,0x3f,temp);
  5179. temp = 0;
  5180. if(SiS_Pr->SiS_VDE != SiS_Pr->SiS_VGAVDE) temp |= 0x08;
  5181. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x30,0xf3,temp);
  5182. }
  5183. #endif
  5184. }
  5185. /* Horizontal scaling */
  5186. tempeax = SiS_Pr->SiS_VGAHDE; /* 1f = ( (VGAHDE * 65536) / ( (VGAHDE * 65536) / HDE ) ) - 1*/
  5187. if(chkdclkfirst) {
  5188. if(modeflag & HalfDCLK) tempeax >>= 1;
  5189. }
  5190. tempebx = tempeax << 16;
  5191. if(SiS_Pr->SiS_HDE == tempeax) {
  5192. tempecx = 0xFFFF;
  5193. } else {
  5194. tempecx = tempebx / SiS_Pr->SiS_HDE;
  5195. if(SiS_Pr->ChipType >= SIS_315H) {
  5196. if(tempebx % SiS_Pr->SiS_HDE) tempecx++;
  5197. }
  5198. }
  5199. if(SiS_Pr->ChipType >= SIS_315H) {
  5200. tempeax = (tempebx / tempecx) - 1;
  5201. } else {
  5202. tempeax = ((SiS_Pr->SiS_VGAHT << 16) / tempecx) - 1;
  5203. }
  5204. tempecx = (tempecx << 16) | (tempeax & 0xFFFF);
  5205. temp = (unsigned short)(tempecx & 0x00FF);
  5206. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1F,temp);
  5207. if(SiS_Pr->ChipType >= SIS_315H) {
  5208. tempeax = (SiS_Pr->SiS_VGAVDE << 18) / tempvcfact;
  5209. tempbx = (unsigned short)(tempeax & 0xFFFF);
  5210. } else {
  5211. tempeax = SiS_Pr->SiS_VGAVDE << 6;
  5212. tempbx = tempvcfact & 0x3f;
  5213. if(tempbx == 0) tempbx = 64;
  5214. tempeax /= tempbx;
  5215. tempbx = (unsigned short)(tempeax & 0xFFFF);
  5216. }
  5217. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) tempbx--;
  5218. if(SiS_Pr->SiS_SetFlag & EnableLVDSDDA) {
  5219. if((!SiS_Pr->SiS_IF_DEF_FSTN) && (!SiS_Pr->SiS_IF_DEF_DSTN)) tempbx = 1;
  5220. else if(SiS_Pr->SiS_LCDResInfo != Panel_640x480) tempbx = 1;
  5221. }
  5222. temp = ((tempbx >> 8) & 0x07) << 3;
  5223. temp = temp | ((tempecx >> 8) & 0x07);
  5224. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x20,temp);
  5225. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x21,tempbx);
  5226. tempecx >>= 16; /* BPLHCFACT */
  5227. if(!chkdclkfirst) {
  5228. if(modeflag & HalfDCLK) tempecx >>= 1;
  5229. }
  5230. temp = (unsigned short)((tempecx & 0xFF00) >> 8);
  5231. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x22,temp);
  5232. temp = (unsigned short)(tempecx & 0x00FF);
  5233. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x23,temp);
  5234. #ifdef CONFIG_FB_SIS_315
  5235. if(SiS_Pr->ChipType >= SIS_315H) {
  5236. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  5237. if((islvds) || (SiS_Pr->SiS_VBInfo & VB_SISLVDS)) {
  5238. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1e,0x20);
  5239. }
  5240. } else {
  5241. if(islvds) {
  5242. if(SiS_Pr->ChipType == SIS_740) {
  5243. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1e,0x03);
  5244. } else {
  5245. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1e,0x23);
  5246. }
  5247. }
  5248. }
  5249. }
  5250. #endif
  5251. #ifdef CONFIG_FB_SIS_300
  5252. if(SiS_Pr->SiS_IF_DEF_TRUMPION) {
  5253. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  5254. unsigned char *trumpdata;
  5255. int i, j = crt2crtc;
  5256. unsigned char TrumpMode13[4] = { 0x01, 0x10, 0x2c, 0x00 };
  5257. unsigned char TrumpMode10_1[4] = { 0x01, 0x10, 0x27, 0x00 };
  5258. unsigned char TrumpMode10_2[4] = { 0x01, 0x16, 0x10, 0x00 };
  5259. if(SiS_Pr->SiS_UseROM) {
  5260. trumpdata = &ROMAddr[0x8001 + (j * 80)];
  5261. } else {
  5262. if(SiS_Pr->SiS_LCDTypeInfo == 0x0e) j += 7;
  5263. trumpdata = &SiS300_TrumpionData[j][0];
  5264. }
  5265. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x02,0xbf);
  5266. for(i=0; i<5; i++) {
  5267. SiS_SetTrumpionBlock(SiS_Pr, trumpdata);
  5268. }
  5269. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  5270. if(ModeNo == 0x13) {
  5271. for(i=0; i<4; i++) {
  5272. SiS_SetTrumpionBlock(SiS_Pr, &TrumpMode13[0]);
  5273. }
  5274. } else if(ModeNo == 0x10) {
  5275. for(i=0; i<4; i++) {
  5276. SiS_SetTrumpionBlock(SiS_Pr, &TrumpMode10_1[0]);
  5277. SiS_SetTrumpionBlock(SiS_Pr, &TrumpMode10_2[0]);
  5278. }
  5279. }
  5280. }
  5281. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x02,0x40);
  5282. }
  5283. #endif
  5284. #ifdef CONFIG_FB_SIS_315
  5285. if(SiS_Pr->SiS_IF_DEF_FSTN || SiS_Pr->SiS_IF_DEF_DSTN) {
  5286. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x25,0x00);
  5287. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x26,0x00);
  5288. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x27,0x00);
  5289. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x28,0x87);
  5290. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x29,0x5A);
  5291. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2A,0x4B);
  5292. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x44,~0x07,0x03);
  5293. tempax = SiS_Pr->SiS_HDE; /* Blps = lcdhdee(lcdhdes+HDE) + 64 */
  5294. if(SiS_Pr->SiS_LCDResInfo == Panel_320x240_1 ||
  5295. SiS_Pr->SiS_LCDResInfo == Panel_320x240_2 ||
  5296. SiS_Pr->SiS_LCDResInfo == Panel_320x240_3) tempax >>= 1;
  5297. tempax += 64;
  5298. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x38,tempax & 0xff);
  5299. temp = (tempax >> 8) << 3;
  5300. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x35,~0x078,temp);
  5301. tempax += 32; /* Blpe = lBlps+32 */
  5302. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x39,tempax & 0xff);
  5303. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3A,0x00); /* Bflml = 0 */
  5304. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x3C,~0x007);
  5305. tempax = SiS_Pr->SiS_VDE;
  5306. if(SiS_Pr->SiS_LCDResInfo == Panel_320x240_1 ||
  5307. SiS_Pr->SiS_LCDResInfo == Panel_320x240_2 ||
  5308. SiS_Pr->SiS_LCDResInfo == Panel_320x240_3) tempax >>= 1;
  5309. tempax >>= 1;
  5310. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3B,tempax & 0xff);
  5311. temp = (tempax >> 8) << 3;
  5312. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x3C,~0x038,temp);
  5313. tempeax = SiS_Pr->SiS_HDE;
  5314. if(SiS_Pr->SiS_LCDResInfo == Panel_320x240_1 ||
  5315. SiS_Pr->SiS_LCDResInfo == Panel_320x240_2 ||
  5316. SiS_Pr->SiS_LCDResInfo == Panel_320x240_3) tempeax >>= 1;
  5317. tempeax <<= 2; /* BDxFIFOSTOP = (HDE*4)/128 */
  5318. temp = tempeax & 0x7f;
  5319. tempeax >>= 7;
  5320. if(temp) tempeax++;
  5321. temp = tempeax & 0x3f;
  5322. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x45,temp);
  5323. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3F,0x00); /* BDxWadrst0 */
  5324. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3E,0x00);
  5325. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3D,0x10);
  5326. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x3C,~0x040);
  5327. tempax = SiS_Pr->SiS_HDE;
  5328. if(SiS_Pr->SiS_LCDResInfo == Panel_320x240_1 ||
  5329. SiS_Pr->SiS_LCDResInfo == Panel_320x240_2 ||
  5330. SiS_Pr->SiS_LCDResInfo == Panel_320x240_3) tempax >>= 1;
  5331. tempax >>= 4; /* BDxWadroff = HDE*4/8/8 */
  5332. pushcx = tempax;
  5333. temp = tempax & 0x00FF;
  5334. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x43,temp);
  5335. temp = ((tempax & 0xFF00) >> 8) << 3;
  5336. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port, 0x44, 0x07, temp);
  5337. tempax = SiS_Pr->SiS_VDE; /* BDxWadrst1 = BDxWadrst0 + BDxWadroff * VDE */
  5338. if(SiS_Pr->SiS_LCDResInfo == Panel_320x240_1 ||
  5339. SiS_Pr->SiS_LCDResInfo == Panel_320x240_2 ||
  5340. SiS_Pr->SiS_LCDResInfo == Panel_320x240_3) tempax >>= 1;
  5341. tempeax = tempax * pushcx;
  5342. temp = tempeax & 0xFF;
  5343. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x42,temp);
  5344. temp = (tempeax & 0xFF00) >> 8;
  5345. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x41,temp);
  5346. temp = ((tempeax & 0xFF0000) >> 16) | 0x10;
  5347. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x40,temp);
  5348. temp = ((tempeax & 0x01000000) >> 24) << 7;
  5349. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port, 0x3C, 0x7F, temp);
  5350. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2F,0x03);
  5351. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x03,0x50);
  5352. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x04,0x00);
  5353. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2F,0x01);
  5354. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x19,0x38);
  5355. if(SiS_Pr->SiS_IF_DEF_FSTN) {
  5356. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2b,0x02);
  5357. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2c,0x00);
  5358. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2d,0x00);
  5359. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x35,0x0c);
  5360. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x36,0x00);
  5361. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x37,0x00);
  5362. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x38,0x80);
  5363. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x39,0xA0);
  5364. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3a,0x00);
  5365. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3b,0xf0);
  5366. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3c,0x00);
  5367. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3d,0x10);
  5368. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3e,0x00);
  5369. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3f,0x00);
  5370. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x40,0x10);
  5371. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x41,0x25);
  5372. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x42,0x80);
  5373. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x43,0x14);
  5374. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x44,0x03);
  5375. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x45,0x0a);
  5376. }
  5377. }
  5378. #endif /* CONFIG_FB_SIS_315 */
  5379. }
  5380. /* Set Part 1 */
  5381. static void
  5382. SiS_SetGroup1(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  5383. unsigned short RefreshRateTableIndex)
  5384. {
  5385. #if defined(CONFIG_FB_SIS_300) || defined(CONFIG_FB_SIS_315)
  5386. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  5387. #endif
  5388. unsigned short temp=0, tempax=0, tempbx=0, tempcx=0, bridgeadd=0;
  5389. unsigned short pushbx=0, CRT1Index=0, modeflag, resinfo=0;
  5390. #ifdef CONFIG_FB_SIS_315
  5391. unsigned short tempbl=0;
  5392. #endif
  5393. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  5394. SiS_SetGroup1_LVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  5395. return;
  5396. }
  5397. if(ModeNo <= 0x13) {
  5398. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  5399. } else if(SiS_Pr->UseCustomMode) {
  5400. modeflag = SiS_Pr->CModeFlag;
  5401. } else {
  5402. CRT1Index = SiS_GetRefCRT1CRTC(SiS_Pr, RefreshRateTableIndex, SiS_Pr->SiS_UseWideCRT2);
  5403. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  5404. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  5405. }
  5406. SiS_SetCRT2Offset(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  5407. if( ! ((SiS_Pr->ChipType >= SIS_315H) &&
  5408. (SiS_Pr->SiS_IF_DEF_LVDS == 1) &&
  5409. (SiS_Pr->SiS_VBInfo & SetInSlaveMode)) ) {
  5410. if(SiS_Pr->ChipType < SIS_315H ) {
  5411. #ifdef CONFIG_FB_SIS_300
  5412. SiS_SetCRT2FIFO_300(SiS_Pr, ModeNo);
  5413. #endif
  5414. } else {
  5415. #ifdef CONFIG_FB_SIS_315
  5416. SiS_SetCRT2FIFO_310(SiS_Pr);
  5417. #endif
  5418. }
  5419. /* 1. Horizontal setup */
  5420. if(SiS_Pr->ChipType < SIS_315H ) {
  5421. #ifdef CONFIG_FB_SIS_300 /* ------------- 300 series --------------*/
  5422. temp = (SiS_Pr->SiS_VGAHT - 1) & 0x0FF; /* BTVGA2HT 0x08,0x09 */
  5423. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x08,temp); /* CRT2 Horizontal Total */
  5424. temp = (((SiS_Pr->SiS_VGAHT - 1) & 0xFF00) >> 8) << 4;
  5425. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x09,0x0f,temp); /* CRT2 Horizontal Total Overflow [7:4] */
  5426. temp = (SiS_Pr->SiS_VGAHDE + 12) & 0x0FF; /* BTVGA2HDEE 0x0A,0x0C */
  5427. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0A,temp); /* CRT2 Horizontal Display Enable End */
  5428. pushbx = SiS_Pr->SiS_VGAHDE + 12; /* bx BTVGA2HRS 0x0B,0x0C */
  5429. tempcx = (SiS_Pr->SiS_VGAHT - SiS_Pr->SiS_VGAHDE) >> 2;
  5430. tempbx = pushbx + tempcx;
  5431. tempcx <<= 1;
  5432. tempcx += tempbx;
  5433. bridgeadd = 12;
  5434. #endif /* CONFIG_FB_SIS_300 */
  5435. } else {
  5436. #ifdef CONFIG_FB_SIS_315 /* ------------------- 315/330 series --------------- */
  5437. tempcx = SiS_Pr->SiS_VGAHT; /* BTVGA2HT 0x08,0x09 */
  5438. if(modeflag & HalfDCLK) {
  5439. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  5440. tempcx >>= 1;
  5441. } else {
  5442. tempax = SiS_Pr->SiS_VGAHDE >> 1;
  5443. tempcx = SiS_Pr->SiS_HT - SiS_Pr->SiS_HDE + tempax;
  5444. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  5445. tempcx = SiS_Pr->SiS_HT - tempax;
  5446. }
  5447. }
  5448. }
  5449. tempcx--;
  5450. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x08,tempcx); /* CRT2 Horizontal Total */
  5451. temp = (tempcx >> 4) & 0xF0;
  5452. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x09,0x0F,temp); /* CRT2 Horizontal Total Overflow [7:4] */
  5453. tempcx = SiS_Pr->SiS_VGAHT; /* BTVGA2HDEE 0x0A,0x0C */
  5454. tempbx = SiS_Pr->SiS_VGAHDE;
  5455. tempcx -= tempbx;
  5456. tempcx >>= 2;
  5457. if(modeflag & HalfDCLK) {
  5458. tempbx >>= 1;
  5459. tempcx >>= 1;
  5460. }
  5461. tempbx += 16;
  5462. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0A,tempbx); /* CRT2 Horizontal Display Enable End */
  5463. pushbx = tempbx;
  5464. tempcx >>= 1;
  5465. tempbx += tempcx;
  5466. tempcx += tempbx;
  5467. bridgeadd = 16;
  5468. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  5469. if(SiS_Pr->ChipType >= SIS_661) {
  5470. if((SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) ||
  5471. (SiS_Pr->SiS_LCDResInfo == Panel_1280x1024)) {
  5472. if(resinfo == SIS_RI_1280x1024) {
  5473. tempcx = (tempcx & 0xff00) | 0x30;
  5474. } else if(resinfo == SIS_RI_1600x1200) {
  5475. tempcx = (tempcx & 0xff00) | 0xff;
  5476. }
  5477. }
  5478. }
  5479. }
  5480. #endif /* CONFIG_FB_SIS_315 */
  5481. } /* 315/330 series */
  5482. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  5483. if(SiS_Pr->UseCustomMode) {
  5484. tempbx = SiS_Pr->CHSyncStart + bridgeadd;
  5485. tempcx = SiS_Pr->CHSyncEnd + bridgeadd;
  5486. tempax = SiS_Pr->SiS_VGAHT;
  5487. if(modeflag & HalfDCLK) tempax >>= 1;
  5488. tempax--;
  5489. if(tempcx > tempax) tempcx = tempax;
  5490. }
  5491. if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) {
  5492. unsigned char cr4, cr14, cr5, cr15;
  5493. if(SiS_Pr->UseCustomMode) {
  5494. cr4 = SiS_Pr->CCRT1CRTC[4];
  5495. cr14 = SiS_Pr->CCRT1CRTC[14];
  5496. cr5 = SiS_Pr->CCRT1CRTC[5];
  5497. cr15 = SiS_Pr->CCRT1CRTC[15];
  5498. } else {
  5499. cr4 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[4];
  5500. cr14 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[14];
  5501. cr5 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[5];
  5502. cr15 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[15];
  5503. }
  5504. tempbx = ((cr4 | ((cr14 & 0xC0) << 2)) - 3) << 3; /* (VGAHRS-3)*8 */
  5505. tempcx = (((cr5 & 0x1f) | ((cr15 & 0x04) << (5-2))) - 3) << 3; /* (VGAHRE-3)*8 */
  5506. tempcx &= 0x00FF;
  5507. tempcx |= (tempbx & 0xFF00);
  5508. tempbx += bridgeadd;
  5509. tempcx += bridgeadd;
  5510. tempax = SiS_Pr->SiS_VGAHT;
  5511. if(modeflag & HalfDCLK) tempax >>= 1;
  5512. tempax--;
  5513. if(tempcx > tempax) tempcx = tempax;
  5514. }
  5515. if(SiS_Pr->SiS_TVMode & (TVSetNTSC1024 | TVSet525p1024)) {
  5516. tempbx = 1040;
  5517. tempcx = 1044; /* HWCursor bug! */
  5518. }
  5519. }
  5520. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0B,tempbx); /* CRT2 Horizontal Retrace Start */
  5521. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0D,tempcx); /* CRT2 Horizontal Retrace End */
  5522. temp = ((tempbx >> 8) & 0x0F) | ((pushbx >> 4) & 0xF0);
  5523. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0C,temp); /* Overflow */
  5524. /* 2. Vertical setup */
  5525. tempcx = SiS_Pr->SiS_VGAVT - 1;
  5526. temp = tempcx & 0x00FF;
  5527. if(SiS_Pr->ChipType < SIS_661) {
  5528. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  5529. if(SiS_Pr->ChipType < SIS_315H) {
  5530. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  5531. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToSVIDEO | SetCRT2ToAVIDEO)) {
  5532. temp--;
  5533. }
  5534. }
  5535. } else {
  5536. temp--;
  5537. }
  5538. } else if(SiS_Pr->ChipType >= SIS_315H) {
  5539. temp--;
  5540. }
  5541. }
  5542. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0E,temp); /* CRT2 Vertical Total */
  5543. tempbx = SiS_Pr->SiS_VGAVDE - 1;
  5544. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0F,tempbx); /* CRT2 Vertical Display Enable End */
  5545. temp = ((tempbx >> 5) & 0x38) | ((tempcx >> 8) & 0x07);
  5546. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x12,temp); /* Overflow */
  5547. if((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->ChipType < SIS_661)) {
  5548. tempbx++;
  5549. tempax = tempbx;
  5550. tempcx++;
  5551. tempcx -= tempax;
  5552. tempcx >>= 2;
  5553. tempbx += tempcx;
  5554. if(tempcx < 4) tempcx = 4;
  5555. tempcx >>= 2;
  5556. tempcx += tempbx;
  5557. tempcx++;
  5558. } else {
  5559. tempbx = (SiS_Pr->SiS_VGAVT + SiS_Pr->SiS_VGAVDE) >> 1; /* BTVGA2VRS 0x10,0x11 */
  5560. tempcx = ((SiS_Pr->SiS_VGAVT - SiS_Pr->SiS_VGAVDE) >> 4) + tempbx + 1; /* BTVGA2VRE 0x11 */
  5561. }
  5562. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  5563. if(SiS_Pr->UseCustomMode) {
  5564. tempbx = SiS_Pr->CVSyncStart;
  5565. tempcx = SiS_Pr->CVSyncEnd;
  5566. }
  5567. if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) {
  5568. unsigned char cr8, cr7, cr13;
  5569. if(SiS_Pr->UseCustomMode) {
  5570. cr8 = SiS_Pr->CCRT1CRTC[8];
  5571. cr7 = SiS_Pr->CCRT1CRTC[7];
  5572. cr13 = SiS_Pr->CCRT1CRTC[13];
  5573. tempcx = SiS_Pr->CCRT1CRTC[9];
  5574. } else {
  5575. cr8 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[8];
  5576. cr7 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[7];
  5577. cr13 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[13];
  5578. tempcx = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[9];
  5579. }
  5580. tempbx = cr8;
  5581. if(cr7 & 0x04) tempbx |= 0x0100;
  5582. if(cr7 & 0x80) tempbx |= 0x0200;
  5583. if(cr13 & 0x08) tempbx |= 0x0400;
  5584. }
  5585. }
  5586. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x10,tempbx); /* CRT2 Vertical Retrace Start */
  5587. temp = ((tempbx >> 4) & 0x70) | (tempcx & 0x0F);
  5588. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x11,temp); /* CRT2 Vert. Retrace End; Overflow */
  5589. /* 3. Panel delay compensation */
  5590. if(SiS_Pr->ChipType < SIS_315H) {
  5591. #ifdef CONFIG_FB_SIS_300 /* ---------- 300 series -------------- */
  5592. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  5593. temp = 0x20;
  5594. if(SiS_Pr->ChipType == SIS_300) {
  5595. temp = 0x10;
  5596. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) temp = 0x2c;
  5597. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) temp = 0x20;
  5598. }
  5599. if(SiS_Pr->SiS_VBType & VB_SIS301) {
  5600. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) temp = 0x20;
  5601. }
  5602. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x960) temp = 0x24;
  5603. if(SiS_Pr->SiS_LCDResInfo == Panel_Custom) temp = 0x2c;
  5604. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) temp = 0x08;
  5605. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  5606. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) temp = 0x2c;
  5607. else temp = 0x20;
  5608. }
  5609. if(SiS_Pr->SiS_UseROM) {
  5610. if(ROMAddr[0x220] & 0x80) {
  5611. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoYPbPrHiVision)
  5612. temp = ROMAddr[0x221];
  5613. else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision)
  5614. temp = ROMAddr[0x222];
  5615. else if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024)
  5616. temp = ROMAddr[0x223];
  5617. else
  5618. temp = ROMAddr[0x224];
  5619. }
  5620. }
  5621. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  5622. if(SiS_Pr->PDC != -1) temp = SiS_Pr->PDC;
  5623. }
  5624. } else {
  5625. temp = 0x20;
  5626. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
  5627. if(SiS_Pr->SiS_LCDResInfo == Panel_640x480) temp = 0x04;
  5628. }
  5629. if(SiS_Pr->SiS_UseROM) {
  5630. if(ROMAddr[0x220] & 0x80) {
  5631. temp = ROMAddr[0x220];
  5632. }
  5633. }
  5634. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  5635. if(SiS_Pr->PDC != -1) temp = SiS_Pr->PDC;
  5636. }
  5637. }
  5638. temp &= 0x3c;
  5639. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,~0x3C,temp); /* Panel Link Delay Compensation; (Software Command Reset; Power Saving) */
  5640. #endif /* CONFIG_FB_SIS_300 */
  5641. } else {
  5642. #ifdef CONFIG_FB_SIS_315 /* --------------- 315/330 series ---------------*/
  5643. if(SiS_Pr->ChipType < SIS_661) {
  5644. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  5645. if(SiS_Pr->ChipType == SIS_740) temp = 0x03;
  5646. else temp = 0x00;
  5647. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) temp = 0x0a;
  5648. tempbl = 0xF0;
  5649. if(SiS_Pr->ChipType == SIS_650) {
  5650. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  5651. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) tempbl = 0x0F;
  5652. }
  5653. }
  5654. if(SiS_Pr->SiS_IF_DEF_DSTN || SiS_Pr->SiS_IF_DEF_FSTN) {
  5655. temp = 0x08;
  5656. tempbl = 0;
  5657. if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
  5658. if(ROMAddr[0x13c] & 0x80) tempbl = 0xf0;
  5659. }
  5660. }
  5661. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,tempbl,temp); /* Panel Link Delay Compensation */
  5662. }
  5663. } /* < 661 */
  5664. tempax = 0;
  5665. if(modeflag & DoubleScanMode) tempax |= 0x80;
  5666. if(modeflag & HalfDCLK) tempax |= 0x40;
  5667. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2C,0x3f,tempax);
  5668. #endif /* CONFIG_FB_SIS_315 */
  5669. }
  5670. } /* Slavemode */
  5671. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  5672. if((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) {
  5673. /* For 301BDH with LCD, we set up the Panel Link */
  5674. SiS_SetGroup1_LVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  5675. } else if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  5676. SiS_SetGroup1_301(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  5677. }
  5678. } else {
  5679. if(SiS_Pr->ChipType < SIS_315H) {
  5680. SiS_SetGroup1_LVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  5681. } else {
  5682. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  5683. if((!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) || (SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  5684. SiS_SetGroup1_LVDS(SiS_Pr, ModeNo,ModeIdIndex,RefreshRateTableIndex);
  5685. }
  5686. } else {
  5687. SiS_SetGroup1_LVDS(SiS_Pr, ModeNo,ModeIdIndex,RefreshRateTableIndex);
  5688. }
  5689. }
  5690. }
  5691. }
  5692. /*********************************************/
  5693. /* SET PART 2 REGISTER GROUP */
  5694. /*********************************************/
  5695. #ifdef CONFIG_FB_SIS_315
  5696. static unsigned char *
  5697. SiS_GetGroup2CLVXPtr(struct SiS_Private *SiS_Pr, int tabletype)
  5698. {
  5699. const unsigned char *tableptr = NULL;
  5700. unsigned short a, b, p = 0;
  5701. a = SiS_Pr->SiS_VGAHDE;
  5702. b = SiS_Pr->SiS_HDE;
  5703. if(tabletype) {
  5704. a = SiS_Pr->SiS_VGAVDE;
  5705. b = SiS_Pr->SiS_VDE;
  5706. }
  5707. if(a < b) {
  5708. tableptr = SiS_Part2CLVX_1;
  5709. } else if(a == b) {
  5710. tableptr = SiS_Part2CLVX_2;
  5711. } else {
  5712. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  5713. tableptr = SiS_Part2CLVX_4;
  5714. } else {
  5715. tableptr = SiS_Part2CLVX_3;
  5716. }
  5717. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  5718. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525i) tableptr = SiS_Part2CLVX_3;
  5719. else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) tableptr = SiS_Part2CLVX_3;
  5720. else tableptr = SiS_Part2CLVX_5;
  5721. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  5722. tableptr = SiS_Part2CLVX_6;
  5723. }
  5724. do {
  5725. if((tableptr[p] | tableptr[p+1] << 8) == a) break;
  5726. p += 0x42;
  5727. } while((tableptr[p] | tableptr[p+1] << 8) != 0xffff);
  5728. if((tableptr[p] | tableptr[p+1] << 8) == 0xffff) p -= 0x42;
  5729. }
  5730. p += 2;
  5731. return ((unsigned char *)&tableptr[p]);
  5732. }
  5733. static void
  5734. SiS_SetGroup2_C_ELV(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  5735. unsigned short RefreshRateTableIndex)
  5736. {
  5737. unsigned char *tableptr;
  5738. unsigned char temp;
  5739. int i, j;
  5740. if(!(SiS_Pr->SiS_VBType & VB_SISTAP4SCALER)) return;
  5741. tableptr = SiS_GetGroup2CLVXPtr(SiS_Pr, 0);
  5742. for(i = 0x80, j = 0; i <= 0xbf; i++, j++) {
  5743. SiS_SetReg(SiS_Pr->SiS_Part2Port, i, tableptr[j]);
  5744. }
  5745. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  5746. tableptr = SiS_GetGroup2CLVXPtr(SiS_Pr, 1);
  5747. for(i = 0xc0, j = 0; i <= 0xff; i++, j++) {
  5748. SiS_SetReg(SiS_Pr->SiS_Part2Port, i, tableptr[j]);
  5749. }
  5750. }
  5751. temp = 0x10;
  5752. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) temp |= 0x04;
  5753. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x4e,0xeb,temp);
  5754. }
  5755. static bool
  5756. SiS_GetCRT2Part2Ptr(struct SiS_Private *SiS_Pr,unsigned short ModeNo,unsigned short ModeIdIndex,
  5757. unsigned short RefreshRateTableIndex,unsigned short *CRT2Index,
  5758. unsigned short *ResIndex)
  5759. {
  5760. if(SiS_Pr->ChipType < SIS_315H) return false;
  5761. if(ModeNo <= 0x13)
  5762. (*ResIndex) = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  5763. else
  5764. (*ResIndex) = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  5765. (*ResIndex) &= 0x3f;
  5766. (*CRT2Index) = 0;
  5767. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  5768. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
  5769. (*CRT2Index) = 200;
  5770. }
  5771. }
  5772. if(SiS_Pr->SiS_CustomT == CUT_ASUSA2H_2) {
  5773. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  5774. if(SiS_Pr->SiS_SetFlag & LCDVESATiming) (*CRT2Index) = 206;
  5775. }
  5776. }
  5777. return (((*CRT2Index) != 0));
  5778. }
  5779. #endif
  5780. #ifdef CONFIG_FB_SIS_300
  5781. static void
  5782. SiS_Group2LCDSpecial(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short crt2crtc)
  5783. {
  5784. unsigned short tempcx;
  5785. static const unsigned char atable[] = {
  5786. 0xc3,0x9e,0xc3,0x9e,0x02,0x02,0x02,
  5787. 0xab,0x87,0xab,0x9e,0xe7,0x02,0x02
  5788. };
  5789. if(!SiS_Pr->UseCustomMode) {
  5790. if( ( ( (SiS_Pr->ChipType == SIS_630) ||
  5791. (SiS_Pr->ChipType == SIS_730) ) &&
  5792. (SiS_Pr->ChipRevision > 2) ) &&
  5793. (SiS_Pr->SiS_LCDResInfo == Panel_1024x768) &&
  5794. (!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) &&
  5795. (!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) ) {
  5796. if(ModeNo == 0x13) {
  5797. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,0xB9);
  5798. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x05,0xCC);
  5799. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x06,0xA6);
  5800. } else if((crt2crtc & 0x3F) == 4) {
  5801. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x2B);
  5802. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x13);
  5803. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,0xE5);
  5804. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x05,0x08);
  5805. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x06,0xE2);
  5806. }
  5807. }
  5808. if(SiS_Pr->ChipType < SIS_315H) {
  5809. if(SiS_Pr->SiS_LCDTypeInfo == 0x0c) {
  5810. crt2crtc &= 0x1f;
  5811. tempcx = 0;
  5812. if(!(SiS_Pr->SiS_VBInfo & SetNotSimuMode)) {
  5813. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  5814. tempcx += 7;
  5815. }
  5816. }
  5817. tempcx += crt2crtc;
  5818. if(crt2crtc >= 4) {
  5819. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x06,0xff);
  5820. }
  5821. if(!(SiS_Pr->SiS_VBInfo & SetNotSimuMode)) {
  5822. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  5823. if(crt2crtc == 4) {
  5824. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x28);
  5825. }
  5826. }
  5827. }
  5828. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x18);
  5829. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,atable[tempcx]);
  5830. }
  5831. }
  5832. }
  5833. }
  5834. /* For ECS A907. Highly preliminary. */
  5835. static void
  5836. SiS_Set300Part2Regs(struct SiS_Private *SiS_Pr, unsigned short ModeIdIndex, unsigned short RefreshRateTableIndex,
  5837. unsigned short ModeNo)
  5838. {
  5839. const struct SiS_Part2PortTbl *CRT2Part2Ptr = NULL;
  5840. unsigned short crt2crtc, resindex;
  5841. int i, j;
  5842. if(SiS_Pr->ChipType != SIS_300) return;
  5843. if(!(SiS_Pr->SiS_VBType & VB_SIS30xBLV)) return;
  5844. if(SiS_Pr->UseCustomMode) return;
  5845. if(ModeNo <= 0x13) {
  5846. crt2crtc = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  5847. } else {
  5848. crt2crtc = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  5849. }
  5850. resindex = crt2crtc & 0x3F;
  5851. if(SiS_Pr->SiS_SetFlag & LCDVESATiming) CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1024x768_1;
  5852. else CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1024x768_2;
  5853. /* The BIOS code (1.16.51,56) is obviously a fragment! */
  5854. if(ModeNo > 0x13) {
  5855. CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1024x768_1;
  5856. resindex = 4;
  5857. }
  5858. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x01,0x80,(CRT2Part2Ptr+resindex)->CR[0]);
  5859. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x02,0x80,(CRT2Part2Ptr+resindex)->CR[1]);
  5860. for(i = 2, j = 0x04; j <= 0x06; i++, j++ ) {
  5861. SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]);
  5862. }
  5863. for(j = 0x1c; j <= 0x1d; i++, j++ ) {
  5864. SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]);
  5865. }
  5866. for(j = 0x1f; j <= 0x21; i++, j++ ) {
  5867. SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]);
  5868. }
  5869. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x23,(CRT2Part2Ptr+resindex)->CR[10]);
  5870. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x25,0x0f,(CRT2Part2Ptr+resindex)->CR[11]);
  5871. }
  5872. #endif
  5873. static void
  5874. SiS_SetTVSpecial(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
  5875. {
  5876. if(!(SiS_Pr->SiS_VBType & VB_SIS30xBLV)) return;
  5877. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoHiVision)) return;
  5878. if(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p)) return;
  5879. if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) {
  5880. if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) {
  5881. static const unsigned char specialtv[] = {
  5882. 0xa7,0x07,0xf2,0x6e,0x17,0x8b,0x73,0x53,
  5883. 0x13,0x40,0x34,0xf4,0x63,0xbb,0xcc,0x7a,
  5884. 0x58,0xe4,0x73,0xda,0x13
  5885. };
  5886. int i, j;
  5887. for(i = 0x1c, j = 0; i <= 0x30; i++, j++) {
  5888. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,specialtv[j]);
  5889. }
  5890. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x43,0x72);
  5891. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750)) {
  5892. if(SiS_Pr->SiS_TVMode & TVSetPALM) {
  5893. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x14);
  5894. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x1b);
  5895. } else {
  5896. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x14); /* 15 */
  5897. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x1a); /* 1b */
  5898. }
  5899. }
  5900. }
  5901. } else {
  5902. if((ModeNo == 0x38) || (ModeNo == 0x4a) || (ModeNo == 0x64) ||
  5903. (ModeNo == 0x52) || (ModeNo == 0x58) || (ModeNo == 0x5c)) {
  5904. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x1b); /* 21 */
  5905. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x54); /* 5a */
  5906. } else {
  5907. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x1a); /* 21 */
  5908. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x53); /* 5a */
  5909. }
  5910. }
  5911. }
  5912. static void
  5913. SiS_SetGroup2_Tail(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
  5914. {
  5915. unsigned short temp;
  5916. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
  5917. if(SiS_Pr->SiS_VGAVDE == 525) {
  5918. temp = 0xc3;
  5919. if(SiS_Pr->SiS_ModeType <= ModeVGA) {
  5920. temp++;
  5921. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) temp += 2;
  5922. }
  5923. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2f,temp);
  5924. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x30,0xb3);
  5925. } else if(SiS_Pr->SiS_VGAVDE == 420) {
  5926. temp = 0x4d;
  5927. if(SiS_Pr->SiS_ModeType <= ModeVGA) {
  5928. temp++;
  5929. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) temp++;
  5930. }
  5931. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2f,temp);
  5932. }
  5933. }
  5934. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  5935. if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) {
  5936. if(SiS_Pr->SiS_VBType & VB_SIS30xB) {
  5937. SiS_SetRegOR(SiS_Pr->SiS_Part2Port,0x1a,0x03);
  5938. /* Not always for LV, see SetGrp2 */
  5939. }
  5940. temp = 1;
  5941. if(ModeNo <= 0x13) temp = 3;
  5942. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x0b,temp);
  5943. }
  5944. #if 0
  5945. /* 651+301C, for 1280x768 - do I really need that? */
  5946. if((SiS_Pr->SiS_PanelXRes == 1280) && (SiS_Pr->SiS_PanelYRes == 768)) {
  5947. if(SiS_Pr->SiS_VBInfo & SetSimuScanMode) {
  5948. if(((SiS_Pr->SiS_HDE == 640) && (SiS_Pr->SiS_VDE == 480)) ||
  5949. ((SiS_Pr->SiS_HDE == 320) && (SiS_Pr->SiS_VDE == 240))) {
  5950. SiS_SetReg(SiS_Part2Port,0x01,0x2b);
  5951. SiS_SetReg(SiS_Part2Port,0x02,0x13);
  5952. SiS_SetReg(SiS_Part2Port,0x04,0xe5);
  5953. SiS_SetReg(SiS_Part2Port,0x05,0x08);
  5954. SiS_SetReg(SiS_Part2Port,0x06,0xe2);
  5955. SiS_SetReg(SiS_Part2Port,0x1c,0x21);
  5956. SiS_SetReg(SiS_Part2Port,0x1d,0x45);
  5957. SiS_SetReg(SiS_Part2Port,0x1f,0x0b);
  5958. SiS_SetReg(SiS_Part2Port,0x20,0x00);
  5959. SiS_SetReg(SiS_Part2Port,0x21,0xa9);
  5960. SiS_SetReg(SiS_Part2Port,0x23,0x0b);
  5961. SiS_SetReg(SiS_Part2Port,0x25,0x04);
  5962. }
  5963. }
  5964. }
  5965. #endif
  5966. }
  5967. }
  5968. static void
  5969. SiS_SetGroup2(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  5970. unsigned short RefreshRateTableIndex)
  5971. {
  5972. unsigned short i, j, tempax, tempbx, tempcx, tempch, tempcl, temp;
  5973. unsigned short push2, modeflag, crt2crtc, bridgeoffset;
  5974. unsigned int longtemp, PhaseIndex;
  5975. bool newtvphase;
  5976. const unsigned char *TimingPoint;
  5977. #ifdef CONFIG_FB_SIS_315
  5978. unsigned short resindex, CRT2Index;
  5979. const struct SiS_Part2PortTbl *CRT2Part2Ptr = NULL;
  5980. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) return;
  5981. #endif
  5982. if(ModeNo <= 0x13) {
  5983. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  5984. crt2crtc = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  5985. } else if(SiS_Pr->UseCustomMode) {
  5986. modeflag = SiS_Pr->CModeFlag;
  5987. crt2crtc = 0;
  5988. } else {
  5989. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  5990. crt2crtc = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  5991. }
  5992. temp = 0;
  5993. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToAVIDEO)) temp |= 0x08;
  5994. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToSVIDEO)) temp |= 0x04;
  5995. if(SiS_Pr->SiS_VBInfo & SetCRT2ToSCART) temp |= 0x02;
  5996. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) temp |= 0x01;
  5997. if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) temp |= 0x10;
  5998. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x00,temp);
  5999. PhaseIndex = 0x01; /* SiS_PALPhase */
  6000. TimingPoint = SiS_Pr->SiS_PALTiming;
  6001. newtvphase = false;
  6002. if( (SiS_Pr->SiS_VBType & VB_SIS30xBLV) &&
  6003. ( (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) ||
  6004. (SiS_Pr->SiS_TVMode & TVSetTVSimuMode) ) ) {
  6005. newtvphase = true;
  6006. }
  6007. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  6008. TimingPoint = SiS_Pr->SiS_HiTVExtTiming;
  6009. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  6010. TimingPoint = SiS_Pr->SiS_HiTVSt2Timing;
  6011. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) {
  6012. TimingPoint = SiS_Pr->SiS_HiTVSt1Timing;
  6013. }
  6014. }
  6015. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  6016. i = 0;
  6017. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) i = 2;
  6018. else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) i = 1;
  6019. TimingPoint = &SiS_YPbPrTable[i][0];
  6020. PhaseIndex = 0x00; /* SiS_NTSCPhase */
  6021. } else if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  6022. if(newtvphase) PhaseIndex = 0x09; /* SiS_PALPhase2 */
  6023. } else {
  6024. TimingPoint = SiS_Pr->SiS_NTSCTiming;
  6025. PhaseIndex = (SiS_Pr->SiS_TVMode & TVSetNTSCJ) ? 0x01 : 0x00; /* SiS_PALPhase : SiS_NTSCPhase */
  6026. if(newtvphase) PhaseIndex += 8; /* SiS_PALPhase2 : SiS_NTSCPhase2 */
  6027. }
  6028. if(SiS_Pr->SiS_TVMode & (TVSetPALM | TVSetPALN)) {
  6029. PhaseIndex = (SiS_Pr->SiS_TVMode & TVSetPALM) ? 0x02 : 0x03; /* SiS_PALMPhase : SiS_PALNPhase */
  6030. if(newtvphase) PhaseIndex += 8; /* SiS_PALMPhase2 : SiS_PALNPhase2 */
  6031. }
  6032. if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) {
  6033. if(SiS_Pr->SiS_TVMode & TVSetPALM) {
  6034. PhaseIndex = 0x05; /* SiS_SpecialPhaseM */
  6035. } else if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) {
  6036. PhaseIndex = 0x11; /* SiS_SpecialPhaseJ */
  6037. } else {
  6038. PhaseIndex = 0x10; /* SiS_SpecialPhase */
  6039. }
  6040. }
  6041. for(i = 0x31, j = 0; i <= 0x34; i++, j++) {
  6042. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS_TVPhase[(PhaseIndex * 4) + j]);
  6043. }
  6044. for(i = 0x01, j = 0; i <= 0x2D; i++, j++) {
  6045. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,TimingPoint[j]);
  6046. }
  6047. for(i = 0x39; i <= 0x45; i++, j++) {
  6048. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,TimingPoint[j]);
  6049. }
  6050. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  6051. if(SiS_Pr->SiS_ModeType != ModeText) {
  6052. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x3A,0x1F);
  6053. }
  6054. }
  6055. SiS_SetRegOR(SiS_Pr->SiS_Part2Port,0x0A,SiS_Pr->SiS_NewFlickerMode);
  6056. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x35,SiS_Pr->SiS_RY1COE);
  6057. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x36,SiS_Pr->SiS_RY2COE);
  6058. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x37,SiS_Pr->SiS_RY3COE);
  6059. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x38,SiS_Pr->SiS_RY4COE);
  6060. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) tempax = 950;
  6061. else if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) tempax = 680;
  6062. else if(SiS_Pr->SiS_TVMode & TVSetPAL) tempax = 520;
  6063. else tempax = 440; /* NTSC, YPbPr 525 */
  6064. if( ((SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) && (SiS_Pr->SiS_VDE <= tempax)) ||
  6065. ( (SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoHiVision) &&
  6066. ((SiS_Pr->SiS_VGAHDE == 1024) || (SiS_Pr->SiS_VDE <= tempax)) ) ) {
  6067. tempax -= SiS_Pr->SiS_VDE;
  6068. tempax >>= 1;
  6069. if(!(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p))) {
  6070. tempax >>= 1;
  6071. }
  6072. tempax &= 0x00ff;
  6073. temp = tempax + (unsigned short)TimingPoint[0];
  6074. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,temp);
  6075. temp = tempax + (unsigned short)TimingPoint[1];
  6076. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,temp);
  6077. if((SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoYPbPrHiVision) && (SiS_Pr->SiS_VGAHDE >= 1024)) {
  6078. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  6079. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x1b);
  6080. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x54);
  6081. } else {
  6082. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x17);
  6083. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x1d);
  6084. }
  6085. }
  6086. }
  6087. tempcx = SiS_Pr->SiS_HT;
  6088. if(SiS_IsDualLink(SiS_Pr)) tempcx >>= 1;
  6089. tempcx--;
  6090. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) tempcx--;
  6091. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x1B,tempcx);
  6092. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1D,0xF0,((tempcx >> 8) & 0x0f));
  6093. tempcx = SiS_Pr->SiS_HT >> 1;
  6094. if(SiS_IsDualLink(SiS_Pr)) tempcx >>= 1;
  6095. tempcx += 7;
  6096. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) tempcx -= 4;
  6097. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x22,0x0F,((tempcx << 4) & 0xf0));
  6098. tempbx = TimingPoint[j] | (TimingPoint[j+1] << 8);
  6099. tempbx += tempcx;
  6100. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x24,tempbx);
  6101. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x25,0x0F,((tempbx >> 4) & 0xf0));
  6102. tempbx += 8;
  6103. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  6104. tempbx -= 4;
  6105. tempcx = tempbx;
  6106. }
  6107. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x29,0x0F,((tempbx << 4) & 0xf0));
  6108. j += 2;
  6109. tempcx += (TimingPoint[j] | (TimingPoint[j+1] << 8));
  6110. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x27,tempcx);
  6111. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x28,0x0F,((tempcx >> 4) & 0xf0));
  6112. tempcx += 8;
  6113. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) tempcx -= 4;
  6114. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2A,0x0F,((tempcx << 4) & 0xf0));
  6115. tempcx = SiS_Pr->SiS_HT >> 1;
  6116. if(SiS_IsDualLink(SiS_Pr)) tempcx >>= 1;
  6117. j += 2;
  6118. tempcx -= (TimingPoint[j] | ((TimingPoint[j+1]) << 8));
  6119. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2D,0x0F,((tempcx << 4) & 0xf0));
  6120. tempcx -= 11;
  6121. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
  6122. tempcx = SiS_GetVGAHT2(SiS_Pr) - 1;
  6123. }
  6124. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2E,tempcx);
  6125. tempbx = SiS_Pr->SiS_VDE;
  6126. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  6127. if(SiS_Pr->SiS_VGAVDE == 360) tempbx = 746;
  6128. if(SiS_Pr->SiS_VGAVDE == 375) tempbx = 746;
  6129. if(SiS_Pr->SiS_VGAVDE == 405) tempbx = 853;
  6130. } else if( (SiS_Pr->SiS_VBInfo & SetCRT2ToTV) &&
  6131. (!(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p|TVSetYPbPr750p))) ) {
  6132. tempbx >>= 1;
  6133. if(SiS_Pr->ChipType >= SIS_315H) {
  6134. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) {
  6135. if((ModeNo <= 0x13) && (crt2crtc == 1)) tempbx++;
  6136. } else if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  6137. if(SiS_Pr->SiS_ModeType <= ModeVGA) {
  6138. if(crt2crtc == 4) tempbx++;
  6139. }
  6140. }
  6141. }
  6142. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  6143. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  6144. if((ModeNo == 0x2f) || (ModeNo == 0x5d) || (ModeNo == 0x5e)) tempbx++;
  6145. }
  6146. if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) {
  6147. if(ModeNo == 0x03) tempbx++; /* From 1.10.7w - doesn't make sense */
  6148. }
  6149. }
  6150. }
  6151. tempbx -= 2;
  6152. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2F,tempbx);
  6153. temp = (tempcx >> 8) & 0x0F;
  6154. temp |= ((tempbx >> 2) & 0xC0);
  6155. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToSVIDEO | SetCRT2ToAVIDEO)) {
  6156. temp |= 0x10;
  6157. if(SiS_Pr->SiS_VBInfo & SetCRT2ToAVIDEO) temp |= 0x20;
  6158. }
  6159. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x30,temp);
  6160. if(SiS_Pr->SiS_VBType & VB_SISPART4OVERFLOW) {
  6161. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x10,0xdf,((tempbx & 0x0400) >> 5));
  6162. }
  6163. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  6164. tempbx = SiS_Pr->SiS_VDE;
  6165. if( (SiS_Pr->SiS_VBInfo & SetCRT2ToTV) &&
  6166. (!(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p))) ) {
  6167. tempbx >>= 1;
  6168. }
  6169. tempbx -= 3;
  6170. temp = ((tempbx >> 3) & 0x60) | 0x18;
  6171. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x46,temp);
  6172. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x47,tempbx);
  6173. if(SiS_Pr->SiS_VBType & VB_SISPART4OVERFLOW) {
  6174. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x10,0xbf,((tempbx & 0x0400) >> 4));
  6175. }
  6176. }
  6177. tempbx = 0;
  6178. if(!(modeflag & HalfDCLK)) {
  6179. if(SiS_Pr->SiS_VGAHDE >= SiS_Pr->SiS_HDE) {
  6180. tempax = 0;
  6181. tempbx |= 0x20;
  6182. }
  6183. }
  6184. tempch = tempcl = 0x01;
  6185. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  6186. if(SiS_Pr->SiS_VGAHDE >= 960) {
  6187. if((!(modeflag & HalfDCLK)) || (SiS_Pr->ChipType < SIS_315H)) {
  6188. tempcl = 0x20;
  6189. if(SiS_Pr->SiS_VGAHDE >= 1280) {
  6190. tempch = 20;
  6191. tempbx &= ~0x20;
  6192. } else {
  6193. tempch = 25; /* OK */
  6194. }
  6195. }
  6196. }
  6197. }
  6198. if(!(tempbx & 0x20)) {
  6199. if(modeflag & HalfDCLK) tempcl <<= 1;
  6200. longtemp = ((SiS_Pr->SiS_VGAHDE * tempch) / tempcl) << 13;
  6201. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) longtemp <<= 3;
  6202. tempax = longtemp / SiS_Pr->SiS_HDE;
  6203. if(longtemp % SiS_Pr->SiS_HDE) tempax++;
  6204. tempbx |= ((tempax >> 8) & 0x1F);
  6205. tempcx = tempax >> 13;
  6206. }
  6207. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x44,tempax);
  6208. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x45,0xC0,tempbx);
  6209. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  6210. tempcx &= 0x07;
  6211. if(tempbx & 0x20) tempcx = 0;
  6212. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x46,0xF8,tempcx);
  6213. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  6214. tempbx = 0x0382;
  6215. tempcx = 0x007e;
  6216. } else {
  6217. tempbx = 0x0369;
  6218. tempcx = 0x0061;
  6219. }
  6220. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x4B,tempbx);
  6221. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x4C,tempcx);
  6222. temp = (tempcx & 0x0300) >> 6;
  6223. temp |= ((tempbx >> 8) & 0x03);
  6224. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  6225. temp |= 0x10;
  6226. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) temp |= 0x20;
  6227. else if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) temp |= 0x40;
  6228. }
  6229. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x4D,temp);
  6230. temp = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x43);
  6231. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x43,(temp - 3));
  6232. SiS_SetTVSpecial(SiS_Pr, ModeNo);
  6233. if(SiS_Pr->SiS_VBType & VB_SIS30xCLV) {
  6234. temp = 0;
  6235. if(SiS_Pr->SiS_TVMode & TVSetPALM) temp = 8;
  6236. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x4e,0xf7,temp);
  6237. }
  6238. }
  6239. if(SiS_Pr->SiS_TVMode & TVSetPALM) {
  6240. if(!(SiS_Pr->SiS_TVMode & TVSetNTSC1024)) {
  6241. temp = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x01);
  6242. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,(temp - 1));
  6243. }
  6244. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xEF);
  6245. }
  6246. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  6247. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  6248. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x0B,0x00);
  6249. }
  6250. }
  6251. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) return;
  6252. /* From here: Part2 LCD setup */
  6253. tempbx = SiS_Pr->SiS_HDE;
  6254. if(SiS_IsDualLink(SiS_Pr)) tempbx >>= 1;
  6255. tempbx--; /* RHACTE = HDE - 1 */
  6256. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2C,tempbx);
  6257. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2B,0x0F,((tempbx >> 4) & 0xf0));
  6258. temp = 0x01;
  6259. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) {
  6260. if(SiS_Pr->SiS_ModeType == ModeEGA) {
  6261. if(SiS_Pr->SiS_VGAHDE >= 1024) {
  6262. temp = 0x02;
  6263. if(SiS_Pr->SiS_SetFlag & LCDVESATiming) {
  6264. temp = 0x01;
  6265. }
  6266. }
  6267. }
  6268. }
  6269. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x0B,temp);
  6270. tempbx = SiS_Pr->SiS_VDE - 1;
  6271. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x03,tempbx);
  6272. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x0C,0xF8,((tempbx >> 8) & 0x07));
  6273. tempcx = SiS_Pr->SiS_VT - 1;
  6274. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x19,tempcx);
  6275. temp = (tempcx >> 3) & 0xE0;
  6276. if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) {
  6277. /* Enable dithering; only do this for 32bpp mode */
  6278. if(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x01) {
  6279. temp |= 0x10;
  6280. }
  6281. }
  6282. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1A,0x0f,temp);
  6283. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x09,0xF0);
  6284. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x0A,0xF0);
  6285. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x17,0xFB);
  6286. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x18,0xDF);
  6287. #ifdef CONFIG_FB_SIS_315
  6288. if(SiS_GetCRT2Part2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex,
  6289. &CRT2Index, &resindex)) {
  6290. switch(CRT2Index) {
  6291. case 206: CRT2Part2Ptr = SiS310_CRT2Part2_Asus1024x768_3; break;
  6292. default:
  6293. case 200: CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1024x768_1; break;
  6294. }
  6295. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x01,0x80,(CRT2Part2Ptr+resindex)->CR[0]);
  6296. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x02,0x80,(CRT2Part2Ptr+resindex)->CR[1]);
  6297. for(i = 2, j = 0x04; j <= 0x06; i++, j++ ) {
  6298. SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]);
  6299. }
  6300. for(j = 0x1c; j <= 0x1d; i++, j++ ) {
  6301. SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]);
  6302. }
  6303. for(j = 0x1f; j <= 0x21; i++, j++ ) {
  6304. SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]);
  6305. }
  6306. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x23,(CRT2Part2Ptr+resindex)->CR[10]);
  6307. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x25,0x0f,(CRT2Part2Ptr+resindex)->CR[11]);
  6308. SiS_SetGroup2_Tail(SiS_Pr, ModeNo);
  6309. } else {
  6310. #endif
  6311. /* Checked for 1024x768, 1280x1024, 1400x1050, 1600x1200 */
  6312. /* Clevo dual-link 1024x768 */
  6313. /* Compaq 1280x1024 has HT 1696 sometimes (calculation OK, if given HT is correct) */
  6314. /* Acer: OK, but uses different setting for VESA timing at 640/800/1024 and 640x400 */
  6315. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  6316. if((SiS_Pr->SiS_LCDInfo & LCDPass11) || (SiS_Pr->PanelYRes == SiS_Pr->SiS_VDE)) {
  6317. tempbx = SiS_Pr->SiS_VDE - 1;
  6318. tempcx = SiS_Pr->SiS_VT - 1;
  6319. } else {
  6320. tempbx = SiS_Pr->SiS_VDE + ((SiS_Pr->PanelYRes - SiS_Pr->SiS_VDE) / 2);
  6321. tempcx = SiS_Pr->SiS_VT - ((SiS_Pr->PanelYRes - SiS_Pr->SiS_VDE) / 2);
  6322. }
  6323. } else {
  6324. tempbx = SiS_Pr->PanelYRes;
  6325. tempcx = SiS_Pr->SiS_VT;
  6326. tempax = 1;
  6327. if(SiS_Pr->PanelYRes != SiS_Pr->SiS_VDE) {
  6328. tempax = SiS_Pr->PanelYRes;
  6329. /* if(SiS_Pr->SiS_VGAVDE == 525) tempax += 0x3c; */ /* 651+301C */
  6330. if(SiS_Pr->PanelYRes < SiS_Pr->SiS_VDE) {
  6331. tempax = tempcx = 0;
  6332. } else {
  6333. tempax -= SiS_Pr->SiS_VDE;
  6334. }
  6335. tempax >>= 1;
  6336. }
  6337. tempcx -= tempax; /* lcdvdes */
  6338. tempbx -= tempax; /* lcdvdee */
  6339. }
  6340. /* Non-expanding: lcdvdes = tempcx = VT-1; lcdvdee = tempbx = VDE-1 */
  6341. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x05,tempcx); /* lcdvdes */
  6342. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x06,tempbx); /* lcdvdee */
  6343. temp = (tempbx >> 5) & 0x38;
  6344. temp |= ((tempcx >> 8) & 0x07);
  6345. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,temp);
  6346. tempax = SiS_Pr->SiS_VDE;
  6347. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
  6348. tempax = SiS_Pr->PanelYRes;
  6349. }
  6350. tempcx = (SiS_Pr->SiS_VT - tempax) >> 4;
  6351. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
  6352. if(SiS_Pr->PanelYRes != SiS_Pr->SiS_VDE) {
  6353. tempcx = (SiS_Pr->SiS_VT - tempax) / 10;
  6354. }
  6355. }
  6356. tempbx = ((SiS_Pr->SiS_VT + SiS_Pr->SiS_VDE) >> 1) - 1;
  6357. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  6358. if(SiS_Pr->PanelYRes != SiS_Pr->SiS_VDE) {
  6359. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) { /* ? */
  6360. tempax = SiS_Pr->SiS_VT - SiS_Pr->PanelYRes;
  6361. if(tempax % 4) { tempax >>= 2; tempax++; }
  6362. else { tempax >>= 2; }
  6363. tempbx -= (tempax - 1);
  6364. } else {
  6365. tempbx -= 10;
  6366. if(tempbx <= SiS_Pr->SiS_VDE) tempbx = SiS_Pr->SiS_VDE + 1;
  6367. }
  6368. }
  6369. }
  6370. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  6371. tempbx++;
  6372. if((!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) || (crt2crtc == 6)) {
  6373. if(SiS_Pr->SiS_SetFlag & LCDVESATiming) {
  6374. tempbx = 770;
  6375. tempcx = 3;
  6376. }
  6377. }
  6378. }
  6379. /* non-expanding: lcdvrs = ((VT + VDE) / 2) - 10 */
  6380. if(SiS_Pr->UseCustomMode) {
  6381. tempbx = SiS_Pr->CVSyncStart;
  6382. }
  6383. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,tempbx); /* lcdvrs */
  6384. temp = (tempbx >> 4) & 0xF0;
  6385. tempbx += (tempcx + 1);
  6386. temp |= (tempbx & 0x0F);
  6387. if(SiS_Pr->UseCustomMode) {
  6388. temp &= 0xf0;
  6389. temp |= (SiS_Pr->CVSyncEnd & 0x0f);
  6390. }
  6391. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,temp);
  6392. #ifdef CONFIG_FB_SIS_300
  6393. SiS_Group2LCDSpecial(SiS_Pr, ModeNo, crt2crtc);
  6394. #endif
  6395. bridgeoffset = 7;
  6396. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) bridgeoffset += 2;
  6397. if(SiS_Pr->SiS_VBType & VB_SIS30xCLV) bridgeoffset += 2; /* OK for Averatec 1280x800 (301C) */
  6398. if(SiS_IsDualLink(SiS_Pr)) bridgeoffset++;
  6399. else if(SiS_Pr->SiS_VBType & VB_SIS302LV) bridgeoffset++; /* OK for Asus A4L 1280x800 */
  6400. /* Higher bridgeoffset shifts to the LEFT */
  6401. temp = 0;
  6402. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
  6403. if(SiS_Pr->PanelXRes != SiS_Pr->SiS_HDE) {
  6404. temp = SiS_Pr->SiS_HT - ((SiS_Pr->PanelXRes - SiS_Pr->SiS_HDE) / 2);
  6405. if(SiS_IsDualLink(SiS_Pr)) temp >>= 1;
  6406. }
  6407. }
  6408. temp += bridgeoffset;
  6409. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x1F,temp); /* lcdhdes */
  6410. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x20,0x0F,((temp >> 4) & 0xf0));
  6411. tempcx = SiS_Pr->SiS_HT;
  6412. tempax = tempbx = SiS_Pr->SiS_HDE;
  6413. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
  6414. if(SiS_Pr->PanelXRes != SiS_Pr->SiS_HDE) {
  6415. tempax = SiS_Pr->PanelXRes;
  6416. tempbx = SiS_Pr->PanelXRes - ((SiS_Pr->PanelXRes - SiS_Pr->SiS_HDE) / 2);
  6417. }
  6418. }
  6419. if(SiS_IsDualLink(SiS_Pr)) {
  6420. tempcx >>= 1;
  6421. tempbx >>= 1;
  6422. tempax >>= 1;
  6423. }
  6424. tempbx += bridgeoffset;
  6425. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x23,tempbx); /* lcdhdee */
  6426. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x25,0xF0,((tempbx >> 8) & 0x0f));
  6427. tempcx = (tempcx - tempax) >> 2;
  6428. tempbx += tempcx;
  6429. push2 = tempbx;
  6430. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) {
  6431. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  6432. if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
  6433. if(SiS_Pr->SiS_HDE == 1280) tempbx = (tempbx & 0xff00) | 0x47;
  6434. }
  6435. }
  6436. }
  6437. if(SiS_Pr->UseCustomMode) {
  6438. tempbx = SiS_Pr->CHSyncStart;
  6439. if(modeflag & HalfDCLK) tempbx <<= 1;
  6440. if(SiS_IsDualLink(SiS_Pr)) tempbx >>= 1;
  6441. tempbx += bridgeoffset;
  6442. }
  6443. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x1C,tempbx); /* lcdhrs */
  6444. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1D,0x0F,((tempbx >> 4) & 0xf0));
  6445. tempbx = push2;
  6446. tempcx <<= 1;
  6447. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
  6448. if(SiS_Pr->PanelXRes != SiS_Pr->SiS_HDE) tempcx >>= 2;
  6449. }
  6450. tempbx += tempcx;
  6451. if(SiS_Pr->UseCustomMode) {
  6452. tempbx = SiS_Pr->CHSyncEnd;
  6453. if(modeflag & HalfDCLK) tempbx <<= 1;
  6454. if(SiS_IsDualLink(SiS_Pr)) tempbx >>= 1;
  6455. tempbx += bridgeoffset;
  6456. }
  6457. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x21,tempbx); /* lcdhre */
  6458. SiS_SetGroup2_Tail(SiS_Pr, ModeNo);
  6459. #ifdef CONFIG_FB_SIS_300
  6460. SiS_Set300Part2Regs(SiS_Pr, ModeIdIndex, RefreshRateTableIndex, ModeNo);
  6461. #endif
  6462. #ifdef CONFIG_FB_SIS_315
  6463. } /* CRT2-LCD from table */
  6464. #endif
  6465. }
  6466. /*********************************************/
  6467. /* SET PART 3 REGISTER GROUP */
  6468. /*********************************************/
  6469. static void
  6470. SiS_SetGroup3(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  6471. {
  6472. unsigned short i;
  6473. const unsigned char *tempdi;
  6474. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) return;
  6475. #ifndef SIS_CP
  6476. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x00,0x00);
  6477. #else
  6478. SIS_CP_INIT301_CP
  6479. #endif
  6480. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  6481. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x13,0xFA);
  6482. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x14,0xC8);
  6483. } else {
  6484. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x13,0xF5);
  6485. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x14,0xB7);
  6486. }
  6487. if(SiS_Pr->SiS_TVMode & TVSetPALM) {
  6488. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x13,0xFA);
  6489. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x14,0xC8);
  6490. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x3D,0xA8);
  6491. }
  6492. tempdi = NULL;
  6493. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  6494. tempdi = SiS_Pr->SiS_HiTVGroup3Data;
  6495. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) {
  6496. tempdi = SiS_Pr->SiS_HiTVGroup3Simu;
  6497. }
  6498. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  6499. if(!(SiS_Pr->SiS_TVMode & TVSetYPbPr525i)) {
  6500. tempdi = SiS_HiTVGroup3_1;
  6501. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) tempdi = SiS_HiTVGroup3_2;
  6502. }
  6503. }
  6504. if(tempdi) {
  6505. for(i=0; i<=0x3E; i++) {
  6506. SiS_SetReg(SiS_Pr->SiS_Part3Port,i,tempdi[i]);
  6507. }
  6508. if(SiS_Pr->SiS_VBType & VB_SIS30xCLV) {
  6509. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) {
  6510. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x28,0x3f);
  6511. }
  6512. }
  6513. }
  6514. #ifdef SIS_CP
  6515. SIS_CP_INIT301_CP2
  6516. #endif
  6517. }
  6518. /*********************************************/
  6519. /* SET PART 4 REGISTER GROUP */
  6520. /*********************************************/
  6521. #ifdef CONFIG_FB_SIS_315
  6522. #if 0
  6523. static void
  6524. SiS_ShiftXPos(struct SiS_Private *SiS_Pr, int shift)
  6525. {
  6526. unsigned short temp, temp1, temp2;
  6527. temp1 = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x1f);
  6528. temp2 = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x20);
  6529. temp = (unsigned short)((int)((temp1 | ((temp2 & 0xf0) << 4))) + shift);
  6530. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x1f,temp);
  6531. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x20,0x0f,((temp >> 4) & 0xf0));
  6532. temp = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x2b) & 0x0f;
  6533. temp = (unsigned short)((int)(temp) + shift);
  6534. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2b,0xf0,(temp & 0x0f));
  6535. temp1 = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x43);
  6536. temp2 = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x42);
  6537. temp = (unsigned short)((int)((temp1 | ((temp2 & 0xf0) << 4))) + shift);
  6538. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x43,temp);
  6539. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x42,0x0f,((temp >> 4) & 0xf0));
  6540. }
  6541. #endif
  6542. static void
  6543. SiS_SetGroup4_C_ELV(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  6544. {
  6545. unsigned short temp, temp1;
  6546. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  6547. if(!(SiS_Pr->SiS_VBType & VB_SIS30xCLV)) return;
  6548. if(!(SiS_Pr->SiS_VBInfo & (SetCRT2ToHiVision | SetCRT2ToYPbPr525750))) return;
  6549. if(SiS_Pr->ChipType >= XGI_20) return;
  6550. if((SiS_Pr->ChipType >= SIS_661) && (SiS_Pr->SiS_ROMNew)) {
  6551. if(!(ROMAddr[0x61] & 0x04)) return;
  6552. }
  6553. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x3a,0x08);
  6554. temp = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x3a);
  6555. if(!(temp & 0x01)) {
  6556. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x3a,0xdf);
  6557. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x25,0xfc);
  6558. if((SiS_Pr->ChipType < SIS_661) && (!(SiS_Pr->SiS_ROMNew))) {
  6559. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x25,0xf8);
  6560. }
  6561. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x0f,0xfb);
  6562. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) temp = 0x0000;
  6563. else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) temp = 0x0002;
  6564. else if(SiS_Pr->SiS_TVMode & TVSetHiVision) temp = 0x0400;
  6565. else temp = 0x0402;
  6566. if((SiS_Pr->ChipType >= SIS_661) || (SiS_Pr->SiS_ROMNew)) {
  6567. temp1 = 0;
  6568. if(SiS_Pr->SiS_TVMode & TVAspect43) temp1 = 4;
  6569. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x0f,0xfb,temp1);
  6570. if(SiS_Pr->SiS_TVMode & TVAspect43LB) temp |= 0x01;
  6571. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x26,0x7c,(temp & 0xff));
  6572. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x3a,0xfb,(temp >> 8));
  6573. if(ModeNo > 0x13) {
  6574. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x39,0xfd);
  6575. }
  6576. } else {
  6577. temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x3b) & 0x03;
  6578. if(temp1 == 0x01) temp |= 0x01;
  6579. if(temp1 == 0x03) temp |= 0x04; /* ? why not 0x10? */
  6580. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x26,0xf8,(temp & 0xff));
  6581. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x3a,0xfb,(temp >> 8));
  6582. if(ModeNo > 0x13) {
  6583. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x3b,0xfd);
  6584. }
  6585. }
  6586. #if 0
  6587. if(SiS_Pr->ChipType >= SIS_661) { /* ? */
  6588. if(SiS_Pr->SiS_TVMode & TVAspect43) {
  6589. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) {
  6590. if(resinfo == SIS_RI_1024x768) {
  6591. SiS_ShiftXPos(SiS_Pr, 97);
  6592. } else {
  6593. SiS_ShiftXPos(SiS_Pr, 111);
  6594. }
  6595. } else if(SiS_Pr->SiS_TVMode & TVSetHiVision) {
  6596. SiS_ShiftXPos(SiS_Pr, 136);
  6597. }
  6598. }
  6599. }
  6600. #endif
  6601. }
  6602. }
  6603. #endif
  6604. static void
  6605. SiS_SetCRT2VCLK(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  6606. unsigned short RefreshRateTableIndex)
  6607. {
  6608. unsigned short vclkindex, temp, reg1, reg2;
  6609. if(SiS_Pr->UseCustomMode) {
  6610. reg1 = SiS_Pr->CSR2B;
  6611. reg2 = SiS_Pr->CSR2C;
  6612. } else {
  6613. vclkindex = SiS_GetVCLK2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  6614. reg1 = SiS_Pr->SiS_VBVCLKData[vclkindex].Part4_A;
  6615. reg2 = SiS_Pr->SiS_VBVCLKData[vclkindex].Part4_B;
  6616. }
  6617. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  6618. if(SiS_Pr->SiS_TVMode & (TVSetNTSC1024 | TVSet525p1024)) {
  6619. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0a,0x57);
  6620. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0b,0x46);
  6621. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1f,0xf6);
  6622. } else {
  6623. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0a,reg1);
  6624. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0b,reg2);
  6625. }
  6626. } else {
  6627. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0a,0x01);
  6628. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0b,reg2);
  6629. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0a,reg1);
  6630. }
  6631. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x12,0x00);
  6632. temp = 0x08;
  6633. if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) temp |= 0x20;
  6634. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x12,temp);
  6635. }
  6636. static void
  6637. SiS_SetDualLinkEtc(struct SiS_Private *SiS_Pr)
  6638. {
  6639. if(SiS_Pr->ChipType >= SIS_315H) {
  6640. if(SiS_Pr->SiS_VBType & VB_SISDUALLINK) {
  6641. if((SiS_CRT2IsLCD(SiS_Pr)) ||
  6642. (SiS_IsVAMode(SiS_Pr))) {
  6643. if(SiS_Pr->SiS_LCDInfo & LCDDualLink) {
  6644. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x27,0x2c);
  6645. } else {
  6646. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x27,~0x20);
  6647. }
  6648. }
  6649. }
  6650. }
  6651. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  6652. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2a,0x00);
  6653. #ifdef SET_EMI
  6654. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
  6655. #endif
  6656. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x34,0x10);
  6657. }
  6658. }
  6659. static void
  6660. SiS_SetGroup4(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  6661. unsigned short RefreshRateTableIndex)
  6662. {
  6663. unsigned short tempax, tempcx, tempbx, modeflag, temp, resinfo;
  6664. unsigned int tempebx, tempeax, templong;
  6665. if(ModeNo <= 0x13) {
  6666. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  6667. resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
  6668. } else if(SiS_Pr->UseCustomMode) {
  6669. modeflag = SiS_Pr->CModeFlag;
  6670. resinfo = 0;
  6671. } else {
  6672. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  6673. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  6674. }
  6675. if(SiS_Pr->ChipType >= SIS_315H) {
  6676. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  6677. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  6678. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x24,0x0e);
  6679. }
  6680. }
  6681. }
  6682. if(SiS_Pr->SiS_VBType & (VB_SIS30xCLV | VB_SIS302LV)) {
  6683. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  6684. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x10,0x9f);
  6685. }
  6686. }
  6687. if(SiS_Pr->ChipType >= SIS_315H) {
  6688. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  6689. SiS_SetDualLinkEtc(SiS_Pr);
  6690. return;
  6691. }
  6692. }
  6693. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x13,SiS_Pr->SiS_RVBHCFACT);
  6694. tempbx = SiS_Pr->SiS_RVBHCMAX;
  6695. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x14,tempbx);
  6696. temp = (tempbx >> 1) & 0x80;
  6697. tempcx = SiS_Pr->SiS_VGAHT - 1;
  6698. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x16,tempcx);
  6699. temp |= ((tempcx >> 5) & 0x78);
  6700. tempcx = SiS_Pr->SiS_VGAVT - 1;
  6701. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) tempcx -= 5;
  6702. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x17,tempcx);
  6703. temp |= ((tempcx >> 8) & 0x07);
  6704. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x15,temp);
  6705. tempbx = SiS_Pr->SiS_VGAHDE;
  6706. if(modeflag & HalfDCLK) tempbx >>= 1;
  6707. if(SiS_IsDualLink(SiS_Pr)) tempbx >>= 1;
  6708. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  6709. temp = 0;
  6710. if(tempbx > 800) temp = 0x60;
  6711. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  6712. temp = 0;
  6713. if(tempbx > 1024) temp = 0xC0;
  6714. else if(tempbx >= 960) temp = 0xA0;
  6715. } else if(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p)) {
  6716. temp = 0;
  6717. if(tempbx >= 1280) temp = 0x40;
  6718. else if(tempbx >= 1024) temp = 0x20;
  6719. } else {
  6720. temp = 0x80;
  6721. if(tempbx >= 1024) temp = 0xA0;
  6722. }
  6723. temp |= SiS_Pr->Init_P4_0E;
  6724. if(SiS_Pr->SiS_VBType & VB_SIS301) {
  6725. if(SiS_Pr->SiS_LCDResInfo != Panel_1280x1024) {
  6726. temp &= 0xf0;
  6727. temp |= 0x0A;
  6728. }
  6729. }
  6730. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x0E,0x10,temp);
  6731. tempeax = SiS_Pr->SiS_VGAVDE;
  6732. tempebx = SiS_Pr->SiS_VDE;
  6733. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  6734. if(!(temp & 0xE0)) tempebx >>=1;
  6735. }
  6736. tempcx = SiS_Pr->SiS_RVBHRS;
  6737. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x18,tempcx);
  6738. tempcx >>= 8;
  6739. tempcx |= 0x40;
  6740. if(tempeax <= tempebx) {
  6741. tempcx ^= 0x40;
  6742. } else {
  6743. tempeax -= tempebx;
  6744. }
  6745. tempeax *= (256 * 1024);
  6746. templong = tempeax % tempebx;
  6747. tempeax /= tempebx;
  6748. if(templong) tempeax++;
  6749. temp = (unsigned short)(tempeax & 0x000000FF);
  6750. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1B,temp);
  6751. temp = (unsigned short)((tempeax & 0x0000FF00) >> 8);
  6752. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1A,temp);
  6753. temp = (unsigned short)((tempeax >> 12) & 0x70); /* sic! */
  6754. temp |= (tempcx & 0x4F);
  6755. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x19,temp);
  6756. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  6757. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1C,0x28);
  6758. /* Calc Linebuffer max address and set/clear decimode */
  6759. tempbx = 0;
  6760. if(SiS_Pr->SiS_TVMode & (TVSetHiVision | TVSetYPbPr750p)) tempbx = 0x08;
  6761. tempax = SiS_Pr->SiS_VGAHDE;
  6762. if(modeflag & HalfDCLK) tempax >>= 1;
  6763. if(SiS_IsDualLink(SiS_Pr)) tempax >>= 1;
  6764. if(tempax > 800) {
  6765. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  6766. tempax -= 800;
  6767. } else {
  6768. tempbx = 0x08;
  6769. if(tempax == 960) tempax *= 25; /* Correct */
  6770. else if(tempax == 1024) tempax *= 25;
  6771. else tempax *= 20;
  6772. temp = tempax % 32;
  6773. tempax /= 32;
  6774. if(temp) tempax++;
  6775. tempax++;
  6776. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  6777. if(resinfo == SIS_RI_1024x768 ||
  6778. resinfo == SIS_RI_1024x576 ||
  6779. resinfo == SIS_RI_1280x1024 ||
  6780. resinfo == SIS_RI_1280x720) {
  6781. /* Otherwise white line or garbage at right edge */
  6782. tempax = (tempax & 0xff00) | 0x20;
  6783. }
  6784. }
  6785. }
  6786. }
  6787. tempax--;
  6788. temp = ((tempax >> 4) & 0x30) | tempbx;
  6789. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1D,tempax);
  6790. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1E,temp);
  6791. temp = 0x0036; tempbx = 0xD0;
  6792. if((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->SiS_VBType & VB_SISLVDS)) {
  6793. temp = 0x0026; tempbx = 0xC0; /* See En/DisableBridge() */
  6794. }
  6795. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  6796. if(!(SiS_Pr->SiS_TVMode & (TVSetNTSC1024 | TVSetHiVision | TVSetYPbPr750p | TVSetYPbPr525p))) {
  6797. temp |= 0x01;
  6798. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  6799. if(!(SiS_Pr->SiS_TVMode & TVSetTVSimuMode)) {
  6800. temp &= ~0x01;
  6801. }
  6802. }
  6803. }
  6804. }
  6805. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x1F,tempbx,temp);
  6806. tempbx = SiS_Pr->SiS_HT >> 1;
  6807. if(SiS_IsDualLink(SiS_Pr)) tempbx >>= 1;
  6808. tempbx -= 2;
  6809. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x22,tempbx);
  6810. temp = (tempbx >> 5) & 0x38;
  6811. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x21,0xC0,temp);
  6812. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  6813. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  6814. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x24,0x0e);
  6815. /* LCD-too-dark-error-source, see FinalizeLCD() */
  6816. }
  6817. }
  6818. SiS_SetDualLinkEtc(SiS_Pr);
  6819. } /* 301B */
  6820. SiS_SetCRT2VCLK(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  6821. }
  6822. /*********************************************/
  6823. /* SET PART 5 REGISTER GROUP */
  6824. /*********************************************/
  6825. static void
  6826. SiS_SetGroup5(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  6827. {
  6828. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) return;
  6829. if(SiS_Pr->SiS_ModeType == ModeVGA) {
  6830. if(!(SiS_Pr->SiS_VBInfo & (SetInSlaveMode | LoadDACFlag))) {
  6831. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);
  6832. SiS_LoadDAC(SiS_Pr, ModeNo, ModeIdIndex);
  6833. }
  6834. }
  6835. }
  6836. /*********************************************/
  6837. /* MODIFY CRT1 GROUP FOR SLAVE MODE */
  6838. /*********************************************/
  6839. static bool
  6840. SiS_GetLVDSCRT1Ptr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  6841. unsigned short RefreshRateTableIndex, unsigned short *ResIndex,
  6842. unsigned short *DisplayType)
  6843. {
  6844. unsigned short modeflag = 0;
  6845. bool checkhd = true;
  6846. /* Pass 1:1 not supported here */
  6847. if(ModeNo <= 0x13) {
  6848. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  6849. (*ResIndex) = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  6850. } else {
  6851. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  6852. (*ResIndex) = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  6853. }
  6854. (*ResIndex) &= 0x3F;
  6855. if((SiS_Pr->SiS_IF_DEF_CH70xx) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
  6856. (*DisplayType) = 80;
  6857. if((SiS_Pr->SiS_TVMode & TVSetPAL) && (!(SiS_Pr->SiS_TVMode & TVSetPALM))) {
  6858. (*DisplayType) = 82;
  6859. if(SiS_Pr->SiS_ModeType > ModeVGA) {
  6860. if(SiS_Pr->SiS_CHSOverScan) (*DisplayType) = 84;
  6861. }
  6862. }
  6863. if((*DisplayType) != 84) {
  6864. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) (*DisplayType)++;
  6865. }
  6866. } else {
  6867. (*DisplayType = 0);
  6868. switch(SiS_Pr->SiS_LCDResInfo) {
  6869. case Panel_320x240_1: (*DisplayType) = 50;
  6870. checkhd = false;
  6871. break;
  6872. case Panel_320x240_2: (*DisplayType) = 14;
  6873. break;
  6874. case Panel_320x240_3: (*DisplayType) = 18;
  6875. break;
  6876. case Panel_640x480: (*DisplayType) = 10;
  6877. break;
  6878. case Panel_1024x600: (*DisplayType) = 26;
  6879. break;
  6880. default: return true;
  6881. }
  6882. if(checkhd) {
  6883. if(modeflag & HalfDCLK) (*DisplayType)++;
  6884. }
  6885. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x600) {
  6886. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) (*DisplayType) += 2;
  6887. }
  6888. }
  6889. return true;
  6890. }
  6891. static void
  6892. SiS_ModCRT1CRTC(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  6893. unsigned short RefreshRateTableIndex)
  6894. {
  6895. unsigned short tempah, i, modeflag, j, ResIndex, DisplayType;
  6896. const struct SiS_LVDSCRT1Data *LVDSCRT1Ptr=NULL;
  6897. static const unsigned short CRIdx[] = {
  6898. 0x00, 0x02, 0x03, 0x04, 0x05, 0x06,
  6899. 0x07, 0x10, 0x11, 0x15, 0x16
  6900. };
  6901. if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) ||
  6902. (SiS_Pr->SiS_CustomT == CUT_BARCO1024) ||
  6903. (SiS_Pr->SiS_CustomT == CUT_PANEL848) ||
  6904. (SiS_Pr->SiS_CustomT == CUT_PANEL856) )
  6905. return;
  6906. if(SiS_Pr->SiS_IF_DEF_LVDS) {
  6907. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  6908. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) return;
  6909. }
  6910. } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
  6911. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) return;
  6912. } else return;
  6913. if(SiS_Pr->SiS_LCDInfo & LCDPass11) return;
  6914. if(SiS_Pr->ChipType < SIS_315H) {
  6915. if(SiS_Pr->SiS_SetFlag & SetDOSMode) return;
  6916. }
  6917. if(!(SiS_GetLVDSCRT1Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex,
  6918. &ResIndex, &DisplayType))) {
  6919. return;
  6920. }
  6921. switch(DisplayType) {
  6922. case 50: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1320x240_1; break; /* xSTN */
  6923. case 14: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1320x240_2; break; /* xSTN */
  6924. case 15: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1320x240_2_H; break; /* xSTN */
  6925. case 18: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1320x240_3; break; /* xSTN */
  6926. case 19: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1320x240_3_H; break; /* xSTN */
  6927. case 10: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1640x480_1; break;
  6928. case 11: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1640x480_1_H; break;
  6929. #if 0 /* Works better with calculated numbers */
  6930. case 26: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x600_1; break;
  6931. case 27: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x600_1_H; break;
  6932. case 28: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x600_2; break;
  6933. case 29: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x600_2_H; break;
  6934. #endif
  6935. case 80: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1UNTSC; break;
  6936. case 81: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1ONTSC; break;
  6937. case 82: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1UPAL; break;
  6938. case 83: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1OPAL; break;
  6939. case 84: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1SOPAL; break;
  6940. }
  6941. if(LVDSCRT1Ptr) {
  6942. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x11,0x7f);
  6943. for(i = 0; i <= 10; i++) {
  6944. tempah = (LVDSCRT1Ptr + ResIndex)->CR[i];
  6945. SiS_SetReg(SiS_Pr->SiS_P3d4,CRIdx[i],tempah);
  6946. }
  6947. for(i = 0x0A, j = 11; i <= 0x0C; i++, j++) {
  6948. tempah = (LVDSCRT1Ptr + ResIndex)->CR[j];
  6949. SiS_SetReg(SiS_Pr->SiS_P3c4,i,tempah);
  6950. }
  6951. tempah = (LVDSCRT1Ptr + ResIndex)->CR[14] & 0xE0;
  6952. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0E,0x1f,tempah);
  6953. if(ModeNo <= 0x13) modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  6954. else modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  6955. tempah = ((LVDSCRT1Ptr + ResIndex)->CR[14] & 0x01) << 5;
  6956. if(modeflag & DoubleScanMode) tempah |= 0x80;
  6957. SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x09,~0x020,tempah);
  6958. } else {
  6959. SiS_CalcLCDACRT1Timing(SiS_Pr, ModeNo, ModeIdIndex);
  6960. }
  6961. }
  6962. /*********************************************/
  6963. /* SET CRT2 ECLK */
  6964. /*********************************************/
  6965. static void
  6966. SiS_SetCRT2ECLK(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  6967. unsigned short RefreshRateTableIndex)
  6968. {
  6969. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  6970. unsigned short clkbase, vclkindex = 0;
  6971. unsigned char sr2b, sr2c;
  6972. if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
  6973. SiS_Pr->SiS_SetFlag &= (~ProgrammingCRT2);
  6974. if(SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK == 2) {
  6975. RefreshRateTableIndex--;
  6976. }
  6977. vclkindex = SiS_GetVCLK2Ptr(SiS_Pr, ModeNo, ModeIdIndex,
  6978. RefreshRateTableIndex);
  6979. SiS_Pr->SiS_SetFlag |= ProgrammingCRT2;
  6980. } else {
  6981. vclkindex = SiS_GetVCLK2Ptr(SiS_Pr, ModeNo, ModeIdIndex,
  6982. RefreshRateTableIndex);
  6983. }
  6984. sr2b = SiS_Pr->SiS_VCLKData[vclkindex].SR2B;
  6985. sr2c = SiS_Pr->SiS_VCLKData[vclkindex].SR2C;
  6986. if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) || (SiS_Pr->SiS_CustomT == CUT_BARCO1024)) {
  6987. if(SiS_Pr->SiS_UseROM) {
  6988. if(ROMAddr[0x220] & 0x01) {
  6989. sr2b = ROMAddr[0x227];
  6990. sr2c = ROMAddr[0x228];
  6991. }
  6992. }
  6993. }
  6994. clkbase = 0x02B;
  6995. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  6996. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  6997. clkbase += 3;
  6998. }
  6999. }
  7000. SiS_SetReg(SiS_Pr->SiS_P3c4,0x31,0x20);
  7001. SiS_SetReg(SiS_Pr->SiS_P3c4,clkbase,sr2b);
  7002. SiS_SetReg(SiS_Pr->SiS_P3c4,clkbase+1,sr2c);
  7003. SiS_SetReg(SiS_Pr->SiS_P3c4,0x31,0x10);
  7004. SiS_SetReg(SiS_Pr->SiS_P3c4,clkbase,sr2b);
  7005. SiS_SetReg(SiS_Pr->SiS_P3c4,clkbase+1,sr2c);
  7006. SiS_SetReg(SiS_Pr->SiS_P3c4,0x31,0x00);
  7007. SiS_SetReg(SiS_Pr->SiS_P3c4,clkbase,sr2b);
  7008. SiS_SetReg(SiS_Pr->SiS_P3c4,clkbase+1,sr2c);
  7009. }
  7010. /*********************************************/
  7011. /* SET UP CHRONTEL CHIPS */
  7012. /*********************************************/
  7013. static void
  7014. SiS_SetCHTVReg(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  7015. unsigned short RefreshRateTableIndex)
  7016. {
  7017. unsigned short TVType, resindex;
  7018. const struct SiS_CHTVRegData *CHTVRegData = NULL;
  7019. if(ModeNo <= 0x13)
  7020. resindex = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  7021. else
  7022. resindex = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  7023. resindex &= 0x3F;
  7024. TVType = 0;
  7025. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) TVType += 1;
  7026. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  7027. TVType += 2;
  7028. if(SiS_Pr->SiS_ModeType > ModeVGA) {
  7029. if(SiS_Pr->SiS_CHSOverScan) TVType = 8;
  7030. }
  7031. if(SiS_Pr->SiS_TVMode & TVSetPALM) {
  7032. TVType = 4;
  7033. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) TVType += 1;
  7034. } else if(SiS_Pr->SiS_TVMode & TVSetPALN) {
  7035. TVType = 6;
  7036. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) TVType += 1;
  7037. }
  7038. }
  7039. switch(TVType) {
  7040. case 0: CHTVRegData = SiS_Pr->SiS_CHTVReg_UNTSC; break;
  7041. case 1: CHTVRegData = SiS_Pr->SiS_CHTVReg_ONTSC; break;
  7042. case 2: CHTVRegData = SiS_Pr->SiS_CHTVReg_UPAL; break;
  7043. case 3: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPAL; break;
  7044. case 4: CHTVRegData = SiS_Pr->SiS_CHTVReg_UPALM; break;
  7045. case 5: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPALM; break;
  7046. case 6: CHTVRegData = SiS_Pr->SiS_CHTVReg_UPALN; break;
  7047. case 7: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPALN; break;
  7048. case 8: CHTVRegData = SiS_Pr->SiS_CHTVReg_SOPAL; break;
  7049. default: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPAL; break;
  7050. }
  7051. if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) {
  7052. #ifdef CONFIG_FB_SIS_300
  7053. /* Chrontel 7005 - I assume that it does not come with a 315 series chip */
  7054. /* We don't support modes >800x600 */
  7055. if (resindex > 5) return;
  7056. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  7057. SiS_SetCH700x(SiS_Pr,0x04,0x43); /* 0x40=76uA (PAL); 0x03=15bit non-multi RGB*/
  7058. SiS_SetCH700x(SiS_Pr,0x09,0x69); /* Black level for PAL (105)*/
  7059. } else {
  7060. SiS_SetCH700x(SiS_Pr,0x04,0x03); /* upper nibble=71uA (NTSC), 0x03=15bit non-multi RGB*/
  7061. SiS_SetCH700x(SiS_Pr,0x09,0x71); /* Black level for NTSC (113)*/
  7062. }
  7063. SiS_SetCH700x(SiS_Pr,0x00,CHTVRegData[resindex].Reg[0]); /* Mode register */
  7064. SiS_SetCH700x(SiS_Pr,0x07,CHTVRegData[resindex].Reg[1]); /* Start active video register */
  7065. SiS_SetCH700x(SiS_Pr,0x08,CHTVRegData[resindex].Reg[2]); /* Position overflow register */
  7066. SiS_SetCH700x(SiS_Pr,0x0a,CHTVRegData[resindex].Reg[3]); /* Horiz Position register */
  7067. SiS_SetCH700x(SiS_Pr,0x0b,CHTVRegData[resindex].Reg[4]); /* Vertical Position register */
  7068. /* Set minimum flicker filter for Luma channel (SR1-0=00),
  7069. minimum text enhancement (S3-2=10),
  7070. maximum flicker filter for Chroma channel (S5-4=10)
  7071. =00101000=0x28 (When reading, S1-0->S3-2, and S3-2->S1-0!)
  7072. */
  7073. SiS_SetCH700x(SiS_Pr,0x01,0x28);
  7074. /* Set video bandwidth
  7075. High bandwidth Luma composite video filter(S0=1)
  7076. low bandwidth Luma S-video filter (S2-1=00)
  7077. disable peak filter in S-video channel (S3=0)
  7078. high bandwidth Chroma Filter (S5-4=11)
  7079. =00110001=0x31
  7080. */
  7081. SiS_SetCH700x(SiS_Pr,0x03,0xb1); /* old: 3103 */
  7082. /* Register 0x3D does not exist in non-macrovision register map
  7083. (Maybe this is a macrovision register?)
  7084. */
  7085. #ifndef SIS_CP
  7086. SiS_SetCH70xx(SiS_Pr,0x3d,0x00);
  7087. #endif
  7088. /* Register 0x10 only contains 1 writable bit (S0) for sensing,
  7089. all other bits a read-only. Macrovision?
  7090. */
  7091. SiS_SetCH70xxANDOR(SiS_Pr,0x10,0x00,0x1F);
  7092. /* Register 0x11 only contains 3 writable bits (S0-S2) for
  7093. contrast enhancement (set to 010 -> gain 1 Yout = 17/16*(Yin-30) )
  7094. */
  7095. SiS_SetCH70xxANDOR(SiS_Pr,0x11,0x02,0xF8);
  7096. /* Clear DSEN
  7097. */
  7098. SiS_SetCH70xxANDOR(SiS_Pr,0x1c,0x00,0xEF);
  7099. if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) { /* ---- NTSC ---- */
  7100. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) {
  7101. if(resindex == 0x04) { /* 640x480 overscan: Mode 16 */
  7102. SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x00,0xEF); /* loop filter off */
  7103. SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x01,0xFE); /* ACIV on, no need to set FSCI */
  7104. } else if(resindex == 0x05) { /* 800x600 overscan: Mode 23 */
  7105. SiS_SetCH70xxANDOR(SiS_Pr,0x18,0x01,0xF0); /* 0x18-0x1f: FSCI 469,762,048 */
  7106. SiS_SetCH70xxANDOR(SiS_Pr,0x19,0x0C,0xF0);
  7107. SiS_SetCH70xxANDOR(SiS_Pr,0x1a,0x00,0xF0);
  7108. SiS_SetCH70xxANDOR(SiS_Pr,0x1b,0x00,0xF0);
  7109. SiS_SetCH70xxANDOR(SiS_Pr,0x1c,0x00,0xF0);
  7110. SiS_SetCH70xxANDOR(SiS_Pr,0x1d,0x00,0xF0);
  7111. SiS_SetCH70xxANDOR(SiS_Pr,0x1e,0x00,0xF0);
  7112. SiS_SetCH70xxANDOR(SiS_Pr,0x1f,0x00,0xF0);
  7113. SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x01,0xEF); /* Loop filter on for mode 23 */
  7114. SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x00,0xFE); /* ACIV off, need to set FSCI */
  7115. }
  7116. } else {
  7117. if(resindex == 0x04) { /* ----- 640x480 underscan; Mode 17 */
  7118. SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x00,0xEF); /* loop filter off */
  7119. SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x01,0xFE);
  7120. } else if(resindex == 0x05) { /* ----- 800x600 underscan: Mode 24 */
  7121. #if 0
  7122. SiS_SetCH70xxANDOR(SiS_Pr,0x18,0x01,0xF0); /* (FSCI was 0x1f1c71c7 - this is for mode 22) */
  7123. SiS_SetCH70xxANDOR(SiS_Pr,0x19,0x09,0xF0); /* FSCI for mode 24 is 428,554,851 */
  7124. SiS_SetCH70xxANDOR(SiS_Pr,0x1a,0x08,0xF0); /* 198b3a63 */
  7125. SiS_SetCH70xxANDOR(SiS_Pr,0x1b,0x0b,0xF0);
  7126. SiS_SetCH70xxANDOR(SiS_Pr,0x1c,0x04,0xF0);
  7127. SiS_SetCH70xxANDOR(SiS_Pr,0x1d,0x01,0xF0);
  7128. SiS_SetCH70xxANDOR(SiS_Pr,0x1e,0x06,0xF0);
  7129. SiS_SetCH70xxANDOR(SiS_Pr,0x1f,0x05,0xF0);
  7130. SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x00,0xEF); /* loop filter off for mode 24 */
  7131. SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x00,0xFE); * ACIV off, need to set FSCI */
  7132. #endif /* All alternatives wrong (datasheet wrong?), don't use FSCI */
  7133. SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x00,0xEF); /* loop filter off */
  7134. SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x01,0xFE);
  7135. }
  7136. }
  7137. } else { /* ---- PAL ---- */
  7138. /* We don't play around with FSCI in PAL mode */
  7139. SiS_SetCH70xxANDOR(SiS_Pr, 0x20, 0x00, 0xEF); /* loop filter off */
  7140. SiS_SetCH70xxANDOR(SiS_Pr, 0x21, 0x01, 0xFE); /* ACIV on */
  7141. }
  7142. #endif /* 300 */
  7143. } else {
  7144. /* Chrontel 7019 - assumed that it does not come with a 300 series chip */
  7145. #ifdef CONFIG_FB_SIS_315
  7146. unsigned short temp;
  7147. /* We don't support modes >1024x768 */
  7148. if (resindex > 6) return;
  7149. temp = CHTVRegData[resindex].Reg[0];
  7150. if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) temp |= 0x10;
  7151. SiS_SetCH701x(SiS_Pr,0x00,temp);
  7152. SiS_SetCH701x(SiS_Pr,0x01,CHTVRegData[resindex].Reg[1]);
  7153. SiS_SetCH701x(SiS_Pr,0x02,CHTVRegData[resindex].Reg[2]);
  7154. SiS_SetCH701x(SiS_Pr,0x04,CHTVRegData[resindex].Reg[3]);
  7155. SiS_SetCH701x(SiS_Pr,0x03,CHTVRegData[resindex].Reg[4]);
  7156. SiS_SetCH701x(SiS_Pr,0x05,CHTVRegData[resindex].Reg[5]);
  7157. SiS_SetCH701x(SiS_Pr,0x06,CHTVRegData[resindex].Reg[6]);
  7158. temp = CHTVRegData[resindex].Reg[7];
  7159. if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) temp = 0x66;
  7160. SiS_SetCH701x(SiS_Pr,0x07,temp);
  7161. SiS_SetCH701x(SiS_Pr,0x08,CHTVRegData[resindex].Reg[8]);
  7162. SiS_SetCH701x(SiS_Pr,0x15,CHTVRegData[resindex].Reg[9]);
  7163. SiS_SetCH701x(SiS_Pr,0x1f,CHTVRegData[resindex].Reg[10]);
  7164. SiS_SetCH701x(SiS_Pr,0x0c,CHTVRegData[resindex].Reg[11]);
  7165. SiS_SetCH701x(SiS_Pr,0x0d,CHTVRegData[resindex].Reg[12]);
  7166. SiS_SetCH701x(SiS_Pr,0x0e,CHTVRegData[resindex].Reg[13]);
  7167. SiS_SetCH701x(SiS_Pr,0x0f,CHTVRegData[resindex].Reg[14]);
  7168. SiS_SetCH701x(SiS_Pr,0x10,CHTVRegData[resindex].Reg[15]);
  7169. temp = SiS_GetCH701x(SiS_Pr,0x21) & ~0x02;
  7170. /* D1 should be set for PAL, PAL-N and NTSC-J,
  7171. but I won't do that for PAL unless somebody
  7172. tells me to do so. Since the BIOS uses
  7173. non-default CIV values and blacklevels,
  7174. this might be compensated anyway.
  7175. */
  7176. if(SiS_Pr->SiS_TVMode & (TVSetPALN | TVSetNTSCJ)) temp |= 0x02;
  7177. SiS_SetCH701x(SiS_Pr,0x21,temp);
  7178. #endif /* 315 */
  7179. }
  7180. #ifdef SIS_CP
  7181. SIS_CP_INIT301_CP3
  7182. #endif
  7183. }
  7184. #ifdef CONFIG_FB_SIS_315 /* ----------- 315 series only ---------- */
  7185. void
  7186. SiS_Chrontel701xBLOn(struct SiS_Private *SiS_Pr)
  7187. {
  7188. unsigned short temp;
  7189. /* Enable Chrontel 7019 LCD panel backlight */
  7190. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  7191. if(SiS_Pr->ChipType == SIS_740) {
  7192. SiS_SetCH701x(SiS_Pr,0x66,0x65);
  7193. } else {
  7194. temp = SiS_GetCH701x(SiS_Pr,0x66);
  7195. temp |= 0x20;
  7196. SiS_SetCH701x(SiS_Pr,0x66,temp);
  7197. }
  7198. }
  7199. }
  7200. void
  7201. SiS_Chrontel701xBLOff(struct SiS_Private *SiS_Pr)
  7202. {
  7203. unsigned short temp;
  7204. /* Disable Chrontel 7019 LCD panel backlight */
  7205. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  7206. temp = SiS_GetCH701x(SiS_Pr,0x66);
  7207. temp &= 0xDF;
  7208. SiS_SetCH701x(SiS_Pr,0x66,temp);
  7209. }
  7210. }
  7211. static void
  7212. SiS_ChrontelPowerSequencing(struct SiS_Private *SiS_Pr)
  7213. {
  7214. static const unsigned char regtable[] = { 0x67, 0x68, 0x69, 0x6a, 0x6b };
  7215. static const unsigned char table1024_740[] = { 0x01, 0x02, 0x01, 0x01, 0x01 };
  7216. static const unsigned char table1400_740[] = { 0x01, 0x6e, 0x01, 0x01, 0x01 };
  7217. static const unsigned char asus1024_740[] = { 0x19, 0x6e, 0x01, 0x19, 0x09 };
  7218. static const unsigned char asus1400_740[] = { 0x19, 0x6e, 0x01, 0x19, 0x09 };
  7219. static const unsigned char table1024_650[] = { 0x01, 0x02, 0x01, 0x01, 0x02 };
  7220. static const unsigned char table1400_650[] = { 0x01, 0x02, 0x01, 0x01, 0x02 };
  7221. const unsigned char *tableptr = NULL;
  7222. int i;
  7223. /* Set up Power up/down timing */
  7224. if(SiS_Pr->ChipType == SIS_740) {
  7225. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  7226. if(SiS_Pr->SiS_CustomT == CUT_ASUSL3000D) tableptr = asus1024_740;
  7227. else tableptr = table1024_740;
  7228. } else if((SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) ||
  7229. (SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) ||
  7230. (SiS_Pr->SiS_LCDResInfo == Panel_1600x1200)) {
  7231. if(SiS_Pr->SiS_CustomT == CUT_ASUSL3000D) tableptr = asus1400_740;
  7232. else tableptr = table1400_740;
  7233. } else return;
  7234. } else {
  7235. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  7236. tableptr = table1024_650;
  7237. } else if((SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) ||
  7238. (SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) ||
  7239. (SiS_Pr->SiS_LCDResInfo == Panel_1600x1200)) {
  7240. tableptr = table1400_650;
  7241. } else return;
  7242. }
  7243. for(i=0; i<5; i++) {
  7244. SiS_SetCH701x(SiS_Pr, regtable[i], tableptr[i]);
  7245. }
  7246. }
  7247. static void
  7248. SiS_SetCH701xForLCD(struct SiS_Private *SiS_Pr)
  7249. {
  7250. const unsigned char *tableptr = NULL;
  7251. unsigned short tempbh;
  7252. int i;
  7253. static const unsigned char regtable[] = {
  7254. 0x1c, 0x5f, 0x64, 0x6f, 0x70, 0x71,
  7255. 0x72, 0x73, 0x74, 0x76, 0x78, 0x7d, 0x66
  7256. };
  7257. static const unsigned char table1024_740[] = {
  7258. 0x60, 0x02, 0x00, 0x07, 0x40, 0xed,
  7259. 0xa3, 0xc8, 0xc7, 0xac, 0xe0, 0x02, 0x44
  7260. };
  7261. static const unsigned char table1280_740[] = {
  7262. 0x60, 0x03, 0x11, 0x00, 0x40, 0xe3,
  7263. 0xad, 0xdb, 0xf6, 0xac, 0xe0, 0x02, 0x44
  7264. };
  7265. static const unsigned char table1400_740[] = {
  7266. 0x60, 0x03, 0x11, 0x00, 0x40, 0xe3,
  7267. 0xad, 0xdb, 0xf6, 0xac, 0xe0, 0x02, 0x44
  7268. };
  7269. static const unsigned char table1600_740[] = {
  7270. 0x60, 0x04, 0x11, 0x00, 0x40, 0xe3,
  7271. 0xad, 0xde, 0xf6, 0xac, 0x60, 0x1a, 0x44
  7272. };
  7273. static const unsigned char table1024_650[] = {
  7274. 0x60, 0x02, 0x00, 0x07, 0x40, 0xed,
  7275. 0xa3, 0xc8, 0xc7, 0xac, 0x60, 0x02
  7276. };
  7277. static const unsigned char table1280_650[] = {
  7278. 0x60, 0x03, 0x11, 0x00, 0x40, 0xe3,
  7279. 0xad, 0xdb, 0xf6, 0xac, 0xe0, 0x02
  7280. };
  7281. static const unsigned char table1400_650[] = {
  7282. 0x60, 0x03, 0x11, 0x00, 0x40, 0xef,
  7283. 0xad, 0xdb, 0xf6, 0xac, 0x60, 0x02
  7284. };
  7285. static const unsigned char table1600_650[] = {
  7286. 0x60, 0x04, 0x11, 0x00, 0x40, 0xe3,
  7287. 0xad, 0xde, 0xf6, 0xac, 0x60, 0x1a
  7288. };
  7289. if(SiS_Pr->ChipType == SIS_740) {
  7290. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) tableptr = table1024_740;
  7291. else if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) tableptr = table1280_740;
  7292. else if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) tableptr = table1400_740;
  7293. else if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) tableptr = table1600_740;
  7294. else return;
  7295. } else {
  7296. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) tableptr = table1024_650;
  7297. else if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) tableptr = table1280_650;
  7298. else if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) tableptr = table1400_650;
  7299. else if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) tableptr = table1600_650;
  7300. else return;
  7301. }
  7302. tempbh = SiS_GetCH701x(SiS_Pr,0x74);
  7303. if((tempbh == 0xf6) || (tempbh == 0xc7)) {
  7304. tempbh = SiS_GetCH701x(SiS_Pr,0x73);
  7305. if(tempbh == 0xc8) {
  7306. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) return;
  7307. } else if(tempbh == 0xdb) {
  7308. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) return;
  7309. if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) return;
  7310. } else if(tempbh == 0xde) {
  7311. if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) return;
  7312. }
  7313. }
  7314. if(SiS_Pr->ChipType == SIS_740) tempbh = 0x0d;
  7315. else tempbh = 0x0c;
  7316. for(i = 0; i < tempbh; i++) {
  7317. SiS_SetCH701x(SiS_Pr, regtable[i], tableptr[i]);
  7318. }
  7319. SiS_ChrontelPowerSequencing(SiS_Pr);
  7320. tempbh = SiS_GetCH701x(SiS_Pr,0x1e);
  7321. tempbh |= 0xc0;
  7322. SiS_SetCH701x(SiS_Pr,0x1e,tempbh);
  7323. if(SiS_Pr->ChipType == SIS_740) {
  7324. tempbh = SiS_GetCH701x(SiS_Pr,0x1c);
  7325. tempbh &= 0xfb;
  7326. SiS_SetCH701x(SiS_Pr,0x1c,tempbh);
  7327. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2d,0x03);
  7328. tempbh = SiS_GetCH701x(SiS_Pr,0x64);
  7329. tempbh |= 0x40;
  7330. SiS_SetCH701x(SiS_Pr,0x64,tempbh);
  7331. tempbh = SiS_GetCH701x(SiS_Pr,0x03);
  7332. tempbh &= 0x3f;
  7333. SiS_SetCH701x(SiS_Pr,0x03,tempbh);
  7334. }
  7335. }
  7336. static void
  7337. SiS_ChrontelResetVSync(struct SiS_Private *SiS_Pr)
  7338. {
  7339. unsigned char temp, temp1;
  7340. temp1 = SiS_GetCH701x(SiS_Pr,0x49);
  7341. SiS_SetCH701x(SiS_Pr,0x49,0x3e);
  7342. temp = SiS_GetCH701x(SiS_Pr,0x47);
  7343. temp &= 0x7f; /* Use external VSYNC */
  7344. SiS_SetCH701x(SiS_Pr,0x47,temp);
  7345. SiS_LongDelay(SiS_Pr, 3);
  7346. temp = SiS_GetCH701x(SiS_Pr,0x47);
  7347. temp |= 0x80; /* Use internal VSYNC */
  7348. SiS_SetCH701x(SiS_Pr,0x47,temp);
  7349. SiS_SetCH701x(SiS_Pr,0x49,temp1);
  7350. }
  7351. static void
  7352. SiS_Chrontel701xOn(struct SiS_Private *SiS_Pr)
  7353. {
  7354. unsigned short temp;
  7355. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  7356. if(SiS_Pr->ChipType == SIS_740) {
  7357. temp = SiS_GetCH701x(SiS_Pr,0x1c);
  7358. temp |= 0x04; /* Invert XCLK phase */
  7359. SiS_SetCH701x(SiS_Pr,0x1c,temp);
  7360. }
  7361. if(SiS_IsYPbPr(SiS_Pr)) {
  7362. temp = SiS_GetCH701x(SiS_Pr,0x01);
  7363. temp &= 0x3f;
  7364. temp |= 0x80; /* Enable YPrPb (HDTV) */
  7365. SiS_SetCH701x(SiS_Pr,0x01,temp);
  7366. }
  7367. if(SiS_IsChScart(SiS_Pr)) {
  7368. temp = SiS_GetCH701x(SiS_Pr,0x01);
  7369. temp &= 0x3f;
  7370. temp |= 0xc0; /* Enable SCART + CVBS */
  7371. SiS_SetCH701x(SiS_Pr,0x01,temp);
  7372. }
  7373. if(SiS_Pr->ChipType == SIS_740) {
  7374. SiS_ChrontelResetVSync(SiS_Pr);
  7375. SiS_SetCH701x(SiS_Pr,0x49,0x20); /* Enable TV path */
  7376. } else {
  7377. SiS_SetCH701x(SiS_Pr,0x49,0x20); /* Enable TV path */
  7378. temp = SiS_GetCH701x(SiS_Pr,0x49);
  7379. if(SiS_IsYPbPr(SiS_Pr)) {
  7380. temp = SiS_GetCH701x(SiS_Pr,0x73);
  7381. temp |= 0x60;
  7382. SiS_SetCH701x(SiS_Pr,0x73,temp);
  7383. }
  7384. temp = SiS_GetCH701x(SiS_Pr,0x47);
  7385. temp &= 0x7f;
  7386. SiS_SetCH701x(SiS_Pr,0x47,temp);
  7387. SiS_LongDelay(SiS_Pr, 2);
  7388. temp = SiS_GetCH701x(SiS_Pr,0x47);
  7389. temp |= 0x80;
  7390. SiS_SetCH701x(SiS_Pr,0x47,temp);
  7391. }
  7392. }
  7393. }
  7394. static void
  7395. SiS_Chrontel701xOff(struct SiS_Private *SiS_Pr)
  7396. {
  7397. unsigned short temp;
  7398. /* Complete power down of LVDS */
  7399. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  7400. if(SiS_Pr->ChipType == SIS_740) {
  7401. SiS_LongDelay(SiS_Pr, 1);
  7402. SiS_GenericDelay(SiS_Pr, 5887);
  7403. SiS_SetCH701x(SiS_Pr,0x76,0xac);
  7404. SiS_SetCH701x(SiS_Pr,0x66,0x00);
  7405. } else {
  7406. SiS_LongDelay(SiS_Pr, 2);
  7407. temp = SiS_GetCH701x(SiS_Pr,0x76);
  7408. temp &= 0xfc;
  7409. SiS_SetCH701x(SiS_Pr,0x76,temp);
  7410. SiS_SetCH701x(SiS_Pr,0x66,0x00);
  7411. }
  7412. }
  7413. }
  7414. static void
  7415. SiS_ChrontelResetDB(struct SiS_Private *SiS_Pr)
  7416. {
  7417. unsigned short temp;
  7418. if(SiS_Pr->ChipType == SIS_740) {
  7419. temp = SiS_GetCH701x(SiS_Pr,0x4a); /* Version ID */
  7420. temp &= 0x01;
  7421. if(!temp) {
  7422. if(SiS_WeHaveBacklightCtrl(SiS_Pr)) {
  7423. temp = SiS_GetCH701x(SiS_Pr,0x49);
  7424. SiS_SetCH701x(SiS_Pr,0x49,0x3e);
  7425. }
  7426. /* Reset Chrontel 7019 datapath */
  7427. SiS_SetCH701x(SiS_Pr,0x48,0x10);
  7428. SiS_LongDelay(SiS_Pr, 1);
  7429. SiS_SetCH701x(SiS_Pr,0x48,0x18);
  7430. if(SiS_WeHaveBacklightCtrl(SiS_Pr)) {
  7431. SiS_ChrontelResetVSync(SiS_Pr);
  7432. SiS_SetCH701x(SiS_Pr,0x49,temp);
  7433. }
  7434. } else {
  7435. /* Clear/set/clear GPIO */
  7436. temp = SiS_GetCH701x(SiS_Pr,0x5c);
  7437. temp &= 0xef;
  7438. SiS_SetCH701x(SiS_Pr,0x5c,temp);
  7439. temp = SiS_GetCH701x(SiS_Pr,0x5c);
  7440. temp |= 0x10;
  7441. SiS_SetCH701x(SiS_Pr,0x5c,temp);
  7442. temp = SiS_GetCH701x(SiS_Pr,0x5c);
  7443. temp &= 0xef;
  7444. SiS_SetCH701x(SiS_Pr,0x5c,temp);
  7445. temp = SiS_GetCH701x(SiS_Pr,0x61);
  7446. if(!temp) {
  7447. SiS_SetCH701xForLCD(SiS_Pr);
  7448. }
  7449. }
  7450. } else { /* 650 */
  7451. /* Reset Chrontel 7019 datapath */
  7452. SiS_SetCH701x(SiS_Pr,0x48,0x10);
  7453. SiS_LongDelay(SiS_Pr, 1);
  7454. SiS_SetCH701x(SiS_Pr,0x48,0x18);
  7455. }
  7456. }
  7457. static void
  7458. SiS_ChrontelInitTVVSync(struct SiS_Private *SiS_Pr)
  7459. {
  7460. unsigned short temp;
  7461. if(SiS_Pr->ChipType == SIS_740) {
  7462. if(SiS_WeHaveBacklightCtrl(SiS_Pr)) {
  7463. SiS_ChrontelResetVSync(SiS_Pr);
  7464. }
  7465. } else {
  7466. SiS_SetCH701x(SiS_Pr,0x76,0xaf); /* Power up LVDS block */
  7467. temp = SiS_GetCH701x(SiS_Pr,0x49);
  7468. temp &= 1;
  7469. if(temp != 1) { /* TV block powered? (0 = yes, 1 = no) */
  7470. temp = SiS_GetCH701x(SiS_Pr,0x47);
  7471. temp &= 0x70;
  7472. SiS_SetCH701x(SiS_Pr,0x47,temp); /* enable VSYNC */
  7473. SiS_LongDelay(SiS_Pr, 3);
  7474. temp = SiS_GetCH701x(SiS_Pr,0x47);
  7475. temp |= 0x80;
  7476. SiS_SetCH701x(SiS_Pr,0x47,temp); /* disable VSYNC */
  7477. }
  7478. }
  7479. }
  7480. static void
  7481. SiS_ChrontelDoSomething3(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
  7482. {
  7483. unsigned short temp,temp1;
  7484. if(SiS_Pr->ChipType == SIS_740) {
  7485. temp = SiS_GetCH701x(SiS_Pr,0x61);
  7486. if(temp < 1) {
  7487. temp++;
  7488. SiS_SetCH701x(SiS_Pr,0x61,temp);
  7489. }
  7490. SiS_SetCH701x(SiS_Pr,0x66,0x45); /* Panel power on */
  7491. SiS_SetCH701x(SiS_Pr,0x76,0xaf); /* All power on */
  7492. SiS_LongDelay(SiS_Pr, 1);
  7493. SiS_GenericDelay(SiS_Pr, 5887);
  7494. } else { /* 650 */
  7495. temp1 = 0;
  7496. temp = SiS_GetCH701x(SiS_Pr,0x61);
  7497. if(temp < 2) {
  7498. temp++;
  7499. SiS_SetCH701x(SiS_Pr,0x61,temp);
  7500. temp1 = 1;
  7501. }
  7502. SiS_SetCH701x(SiS_Pr,0x76,0xac);
  7503. temp = SiS_GetCH701x(SiS_Pr,0x66);
  7504. temp |= 0x5f;
  7505. SiS_SetCH701x(SiS_Pr,0x66,temp);
  7506. if(ModeNo > 0x13) {
  7507. if(SiS_WeHaveBacklightCtrl(SiS_Pr)) {
  7508. SiS_GenericDelay(SiS_Pr, 1023);
  7509. } else {
  7510. SiS_GenericDelay(SiS_Pr, 767);
  7511. }
  7512. } else {
  7513. if(!temp1)
  7514. SiS_GenericDelay(SiS_Pr, 767);
  7515. }
  7516. temp = SiS_GetCH701x(SiS_Pr,0x76);
  7517. temp |= 0x03;
  7518. SiS_SetCH701x(SiS_Pr,0x76,temp);
  7519. temp = SiS_GetCH701x(SiS_Pr,0x66);
  7520. temp &= 0x7f;
  7521. SiS_SetCH701x(SiS_Pr,0x66,temp);
  7522. SiS_LongDelay(SiS_Pr, 1);
  7523. }
  7524. }
  7525. static void
  7526. SiS_ChrontelDoSomething2(struct SiS_Private *SiS_Pr)
  7527. {
  7528. unsigned short temp;
  7529. SiS_LongDelay(SiS_Pr, 1);
  7530. do {
  7531. temp = SiS_GetCH701x(SiS_Pr,0x66);
  7532. temp &= 0x04; /* PLL stable? -> bail out */
  7533. if(temp == 0x04) break;
  7534. if(SiS_Pr->ChipType == SIS_740) {
  7535. /* Power down LVDS output, PLL normal operation */
  7536. SiS_SetCH701x(SiS_Pr,0x76,0xac);
  7537. }
  7538. SiS_SetCH701xForLCD(SiS_Pr);
  7539. temp = SiS_GetCH701x(SiS_Pr,0x76);
  7540. temp &= 0xfb; /* Reset PLL */
  7541. SiS_SetCH701x(SiS_Pr,0x76,temp);
  7542. SiS_LongDelay(SiS_Pr, 2);
  7543. temp = SiS_GetCH701x(SiS_Pr,0x76);
  7544. temp |= 0x04; /* PLL normal operation */
  7545. SiS_SetCH701x(SiS_Pr,0x76,temp);
  7546. if(SiS_Pr->ChipType == SIS_740) {
  7547. SiS_SetCH701x(SiS_Pr,0x78,0xe0); /* PLL loop filter */
  7548. } else {
  7549. SiS_SetCH701x(SiS_Pr,0x78,0x60);
  7550. }
  7551. SiS_LongDelay(SiS_Pr, 2);
  7552. } while(0);
  7553. SiS_SetCH701x(SiS_Pr,0x77,0x00); /* MV? */
  7554. }
  7555. static void
  7556. SiS_ChrontelDoSomething1(struct SiS_Private *SiS_Pr)
  7557. {
  7558. unsigned short temp;
  7559. temp = SiS_GetCH701x(SiS_Pr,0x03);
  7560. temp |= 0x80; /* Set datapath 1 to TV */
  7561. temp &= 0xbf; /* Set datapath 2 to LVDS */
  7562. SiS_SetCH701x(SiS_Pr,0x03,temp);
  7563. if(SiS_Pr->ChipType == SIS_740) {
  7564. temp = SiS_GetCH701x(SiS_Pr,0x1c);
  7565. temp &= 0xfb; /* Normal XCLK phase */
  7566. SiS_SetCH701x(SiS_Pr,0x1c,temp);
  7567. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2d,0x03);
  7568. temp = SiS_GetCH701x(SiS_Pr,0x64);
  7569. temp |= 0x40; /* ? Bit not defined */
  7570. SiS_SetCH701x(SiS_Pr,0x64,temp);
  7571. temp = SiS_GetCH701x(SiS_Pr,0x03);
  7572. temp &= 0x3f; /* D1 input to both LVDS and TV */
  7573. SiS_SetCH701x(SiS_Pr,0x03,temp);
  7574. if(SiS_Pr->SiS_CustomT == CUT_ASUSL3000D) {
  7575. SiS_SetCH701x(SiS_Pr,0x63,0x40); /* LVDS off */
  7576. SiS_LongDelay(SiS_Pr, 1);
  7577. SiS_SetCH701x(SiS_Pr,0x63,0x00); /* LVDS on */
  7578. SiS_ChrontelResetDB(SiS_Pr);
  7579. SiS_ChrontelDoSomething2(SiS_Pr);
  7580. SiS_ChrontelDoSomething3(SiS_Pr, 0);
  7581. } else {
  7582. temp = SiS_GetCH701x(SiS_Pr,0x66);
  7583. if(temp != 0x45) {
  7584. SiS_ChrontelResetDB(SiS_Pr);
  7585. SiS_ChrontelDoSomething2(SiS_Pr);
  7586. SiS_ChrontelDoSomething3(SiS_Pr, 0);
  7587. }
  7588. }
  7589. } else { /* 650 */
  7590. SiS_ChrontelResetDB(SiS_Pr);
  7591. SiS_ChrontelDoSomething2(SiS_Pr);
  7592. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x34);
  7593. SiS_ChrontelDoSomething3(SiS_Pr,temp);
  7594. SiS_SetCH701x(SiS_Pr,0x76,0xaf); /* All power on, LVDS normal operation */
  7595. }
  7596. }
  7597. #endif /* 315 series */
  7598. /*********************************************/
  7599. /* MAIN: SET CRT2 REGISTER GROUP */
  7600. /*********************************************/
  7601. bool
  7602. SiS_SetCRT2Group(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
  7603. {
  7604. #ifdef CONFIG_FB_SIS_300
  7605. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  7606. #endif
  7607. unsigned short ModeIdIndex, RefreshRateTableIndex;
  7608. SiS_Pr->SiS_SetFlag |= ProgrammingCRT2;
  7609. if(!SiS_Pr->UseCustomMode) {
  7610. SiS_SearchModeID(SiS_Pr, &ModeNo, &ModeIdIndex);
  7611. } else {
  7612. ModeIdIndex = 0;
  7613. }
  7614. /* Used for shifting CR33 */
  7615. SiS_Pr->SiS_SelectCRT2Rate = 4;
  7616. SiS_UnLockCRT2(SiS_Pr);
  7617. RefreshRateTableIndex = SiS_GetRatePtr(SiS_Pr, ModeNo, ModeIdIndex);
  7618. SiS_SaveCRT2Info(SiS_Pr,ModeNo);
  7619. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7620. SiS_DisableBridge(SiS_Pr);
  7621. if((SiS_Pr->SiS_IF_DEF_LVDS == 1) && (SiS_Pr->ChipType == SIS_730)) {
  7622. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,0x80);
  7623. }
  7624. SiS_SetCRT2ModeRegs(SiS_Pr, ModeNo, ModeIdIndex);
  7625. }
  7626. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) {
  7627. SiS_LockCRT2(SiS_Pr);
  7628. SiS_DisplayOn(SiS_Pr);
  7629. return true;
  7630. }
  7631. SiS_GetCRT2Data(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7632. /* Set up Panel Link for LVDS and LCDA */
  7633. SiS_Pr->SiS_LCDHDES = SiS_Pr->SiS_LCDVDES = 0;
  7634. if( (SiS_Pr->SiS_IF_DEF_LVDS == 1) ||
  7635. ((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) ||
  7636. ((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->SiS_VBType & VB_SIS30xBLV)) ) {
  7637. SiS_GetLVDSDesData(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7638. }
  7639. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7640. SiS_SetGroup1(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7641. }
  7642. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  7643. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7644. SiS_SetGroup2(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7645. #ifdef CONFIG_FB_SIS_315
  7646. SiS_SetGroup2_C_ELV(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7647. #endif
  7648. SiS_SetGroup3(SiS_Pr, ModeNo, ModeIdIndex);
  7649. SiS_SetGroup4(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7650. #ifdef CONFIG_FB_SIS_315
  7651. SiS_SetGroup4_C_ELV(SiS_Pr, ModeNo, ModeIdIndex);
  7652. #endif
  7653. SiS_SetGroup5(SiS_Pr, ModeNo, ModeIdIndex);
  7654. SiS_SetCRT2Sync(SiS_Pr, ModeNo, RefreshRateTableIndex);
  7655. /* For 301BDH (Panel link initialization): */
  7656. if((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) {
  7657. if(!((SiS_Pr->SiS_SetFlag & SetDOSMode) && ((ModeNo == 0x03) || (ModeNo == 0x10)))) {
  7658. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  7659. SiS_ModCRT1CRTC(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7660. }
  7661. }
  7662. SiS_SetCRT2ECLK(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7663. }
  7664. }
  7665. } else {
  7666. SiS_SetCRT2Sync(SiS_Pr, ModeNo, RefreshRateTableIndex);
  7667. SiS_ModCRT1CRTC(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex);
  7668. SiS_SetCRT2ECLK(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex);
  7669. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7670. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  7671. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  7672. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  7673. #ifdef CONFIG_FB_SIS_315
  7674. SiS_SetCH701xForLCD(SiS_Pr);
  7675. #endif
  7676. }
  7677. }
  7678. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  7679. SiS_SetCHTVReg(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex);
  7680. }
  7681. }
  7682. }
  7683. }
  7684. #ifdef CONFIG_FB_SIS_300
  7685. if(SiS_Pr->ChipType < SIS_315H) {
  7686. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7687. if(SiS_Pr->SiS_UseOEM) {
  7688. if((SiS_Pr->SiS_UseROM) && (SiS_Pr->SiS_UseOEM == -1)) {
  7689. if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) {
  7690. SiS_OEM300Setting(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7691. }
  7692. } else {
  7693. SiS_OEM300Setting(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7694. }
  7695. }
  7696. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  7697. if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) ||
  7698. (SiS_Pr->SiS_CustomT == CUT_BARCO1024)) {
  7699. SetOEMLCDData2(SiS_Pr, ModeNo, ModeIdIndex,RefreshRateTableIndex);
  7700. }
  7701. SiS_DisplayOn(SiS_Pr);
  7702. }
  7703. }
  7704. }
  7705. #endif
  7706. #ifdef CONFIG_FB_SIS_315
  7707. if(SiS_Pr->ChipType >= SIS_315H) {
  7708. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7709. if(SiS_Pr->ChipType < SIS_661) {
  7710. SiS_FinalizeLCD(SiS_Pr, ModeNo, ModeIdIndex);
  7711. SiS_OEM310Setting(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7712. } else {
  7713. SiS_OEM661Setting(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7714. }
  7715. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x01,0x40);
  7716. }
  7717. }
  7718. #endif
  7719. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7720. SiS_EnableBridge(SiS_Pr);
  7721. }
  7722. SiS_DisplayOn(SiS_Pr);
  7723. if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) {
  7724. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  7725. /* Disable LCD panel when using TV */
  7726. SiS_SetRegSR11ANDOR(SiS_Pr,0xFF,0x0C);
  7727. } else {
  7728. /* Disable TV when using LCD */
  7729. SiS_SetCH70xxANDOR(SiS_Pr,0x0e,0x01,0xf8);
  7730. }
  7731. }
  7732. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7733. SiS_LockCRT2(SiS_Pr);
  7734. }
  7735. return true;
  7736. }
  7737. /*********************************************/
  7738. /* ENABLE/DISABLE LCD BACKLIGHT (SIS) */
  7739. /*********************************************/
  7740. void
  7741. SiS_SiS30xBLOn(struct SiS_Private *SiS_Pr)
  7742. {
  7743. /* Switch on LCD backlight on SiS30xLV */
  7744. SiS_DDC2Delay(SiS_Pr,0xff00);
  7745. if(!(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x26) & 0x02)) {
  7746. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x02);
  7747. SiS_WaitVBRetrace(SiS_Pr);
  7748. }
  7749. if(!(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x26) & 0x01)) {
  7750. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x01);
  7751. }
  7752. }
  7753. void
  7754. SiS_SiS30xBLOff(struct SiS_Private *SiS_Pr)
  7755. {
  7756. /* Switch off LCD backlight on SiS30xLV */
  7757. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFE);
  7758. SiS_DDC2Delay(SiS_Pr,0xff00);
  7759. }
  7760. /*********************************************/
  7761. /* DDC RELATED FUNCTIONS */
  7762. /*********************************************/
  7763. static void
  7764. SiS_SetupDDCN(struct SiS_Private *SiS_Pr)
  7765. {
  7766. SiS_Pr->SiS_DDC_NData = ~SiS_Pr->SiS_DDC_Data;
  7767. SiS_Pr->SiS_DDC_NClk = ~SiS_Pr->SiS_DDC_Clk;
  7768. if((SiS_Pr->SiS_DDC_Index == 0x11) && (SiS_Pr->SiS_SensibleSR11)) {
  7769. SiS_Pr->SiS_DDC_NData &= 0x0f;
  7770. SiS_Pr->SiS_DDC_NClk &= 0x0f;
  7771. }
  7772. }
  7773. #ifdef CONFIG_FB_SIS_300
  7774. static unsigned char *
  7775. SiS_SetTrumpBlockLoop(struct SiS_Private *SiS_Pr, unsigned char *dataptr)
  7776. {
  7777. int i, j, num;
  7778. unsigned short tempah,temp;
  7779. unsigned char *mydataptr;
  7780. for(i=0; i<20; i++) { /* Do 20 attempts to write */
  7781. mydataptr = dataptr;
  7782. num = *mydataptr++;
  7783. if(!num) return mydataptr;
  7784. if(i) {
  7785. SiS_SetStop(SiS_Pr);
  7786. SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT * 2);
  7787. }
  7788. if(SiS_SetStart(SiS_Pr)) continue; /* Set start condition */
  7789. tempah = SiS_Pr->SiS_DDC_DeviceAddr;
  7790. temp = SiS_WriteDDC2Data(SiS_Pr,tempah); /* Write DAB (S0=0=write) */
  7791. if(temp) continue; /* (ERROR: no ack) */
  7792. tempah = *mydataptr++;
  7793. temp = SiS_WriteDDC2Data(SiS_Pr,tempah); /* Write register number */
  7794. if(temp) continue; /* (ERROR: no ack) */
  7795. for(j=0; j<num; j++) {
  7796. tempah = *mydataptr++;
  7797. temp = SiS_WriteDDC2Data(SiS_Pr,tempah);/* Write DAB (S0=0=write) */
  7798. if(temp) break;
  7799. }
  7800. if(temp) continue;
  7801. if(SiS_SetStop(SiS_Pr)) continue;
  7802. return mydataptr;
  7803. }
  7804. return NULL;
  7805. }
  7806. static bool
  7807. SiS_SetTrumpionBlock(struct SiS_Private *SiS_Pr, unsigned char *dataptr)
  7808. {
  7809. SiS_Pr->SiS_DDC_DeviceAddr = 0xF0; /* DAB (Device Address Byte) */
  7810. SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */
  7811. SiS_Pr->SiS_DDC_Data = 0x02; /* Bitmask in IndexReg for Data */
  7812. SiS_Pr->SiS_DDC_Clk = 0x01; /* Bitmask in IndexReg for Clk */
  7813. SiS_SetupDDCN(SiS_Pr);
  7814. SiS_SetSwitchDDC2(SiS_Pr);
  7815. while(*dataptr) {
  7816. dataptr = SiS_SetTrumpBlockLoop(SiS_Pr, dataptr);
  7817. if(!dataptr) return false;
  7818. }
  7819. return true;
  7820. }
  7821. #endif
  7822. /* The Chrontel 700x is connected to the 630/730 via
  7823. * the 630/730's DDC/I2C port.
  7824. *
  7825. * On 630(S)T chipset, the index changed from 0x11 to
  7826. * 0x0a, possibly for working around the DDC problems
  7827. */
  7828. static bool
  7829. SiS_SetChReg(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val, unsigned short myor)
  7830. {
  7831. unsigned short temp, i;
  7832. for(i=0; i<20; i++) { /* Do 20 attempts to write */
  7833. if(i) {
  7834. SiS_SetStop(SiS_Pr);
  7835. SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT * 4);
  7836. }
  7837. if(SiS_SetStart(SiS_Pr)) continue; /* Set start condition */
  7838. temp = SiS_WriteDDC2Data(SiS_Pr, SiS_Pr->SiS_DDC_DeviceAddr); /* Write DAB (S0=0=write) */
  7839. if(temp) continue; /* (ERROR: no ack) */
  7840. temp = SiS_WriteDDC2Data(SiS_Pr, (reg | myor)); /* Write RAB (700x: set bit 7, see datasheet) */
  7841. if(temp) continue; /* (ERROR: no ack) */
  7842. temp = SiS_WriteDDC2Data(SiS_Pr, val); /* Write data */
  7843. if(temp) continue; /* (ERROR: no ack) */
  7844. if(SiS_SetStop(SiS_Pr)) continue; /* Set stop condition */
  7845. SiS_Pr->SiS_ChrontelInit = 1;
  7846. return true;
  7847. }
  7848. return false;
  7849. }
  7850. /* Write to Chrontel 700x */
  7851. void
  7852. SiS_SetCH700x(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val)
  7853. {
  7854. SiS_Pr->SiS_DDC_DeviceAddr = 0xEA; /* DAB (Device Address Byte) */
  7855. SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT);
  7856. if(!(SiS_Pr->SiS_ChrontelInit)) {
  7857. SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */
  7858. SiS_Pr->SiS_DDC_Data = 0x02; /* Bitmask in IndexReg for Data */
  7859. SiS_Pr->SiS_DDC_Clk = 0x01; /* Bitmask in IndexReg for Clk */
  7860. SiS_SetupDDCN(SiS_Pr);
  7861. }
  7862. if( (!(SiS_SetChReg(SiS_Pr, reg, val, 0x80))) &&
  7863. (!(SiS_Pr->SiS_ChrontelInit)) ) {
  7864. SiS_Pr->SiS_DDC_Index = 0x0a;
  7865. SiS_Pr->SiS_DDC_Data = 0x80;
  7866. SiS_Pr->SiS_DDC_Clk = 0x40;
  7867. SiS_SetupDDCN(SiS_Pr);
  7868. SiS_SetChReg(SiS_Pr, reg, val, 0x80);
  7869. }
  7870. }
  7871. /* Write to Chrontel 701x */
  7872. /* Parameter is [Data (S15-S8) | Register no (S7-S0)] */
  7873. void
  7874. SiS_SetCH701x(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val)
  7875. {
  7876. SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */
  7877. SiS_Pr->SiS_DDC_Data = 0x08; /* Bitmask in IndexReg for Data */
  7878. SiS_Pr->SiS_DDC_Clk = 0x04; /* Bitmask in IndexReg for Clk */
  7879. SiS_SetupDDCN(SiS_Pr);
  7880. SiS_Pr->SiS_DDC_DeviceAddr = 0xEA; /* DAB (Device Address Byte) */
  7881. SiS_SetChReg(SiS_Pr, reg, val, 0);
  7882. }
  7883. static
  7884. void
  7885. SiS_SetCH70xx(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val)
  7886. {
  7887. if(SiS_Pr->SiS_IF_DEF_CH70xx == 1)
  7888. SiS_SetCH700x(SiS_Pr, reg, val);
  7889. else
  7890. SiS_SetCH701x(SiS_Pr, reg, val);
  7891. }
  7892. static unsigned short
  7893. SiS_GetChReg(struct SiS_Private *SiS_Pr, unsigned short myor)
  7894. {
  7895. unsigned short tempah, temp, i;
  7896. for(i=0; i<20; i++) { /* Do 20 attempts to read */
  7897. if(i) {
  7898. SiS_SetStop(SiS_Pr);
  7899. SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT * 4);
  7900. }
  7901. if(SiS_SetStart(SiS_Pr)) continue; /* Set start condition */
  7902. temp = SiS_WriteDDC2Data(SiS_Pr,SiS_Pr->SiS_DDC_DeviceAddr); /* Write DAB (S0=0=write) */
  7903. if(temp) continue; /* (ERROR: no ack) */
  7904. temp = SiS_WriteDDC2Data(SiS_Pr,SiS_Pr->SiS_DDC_ReadAddr | myor); /* Write RAB (700x: | 0x80) */
  7905. if(temp) continue; /* (ERROR: no ack) */
  7906. if (SiS_SetStart(SiS_Pr)) continue; /* Re-start */
  7907. temp = SiS_WriteDDC2Data(SiS_Pr,SiS_Pr->SiS_DDC_DeviceAddr | 0x01);/* DAB (S0=1=read) */
  7908. if(temp) continue; /* (ERROR: no ack) */
  7909. tempah = SiS_ReadDDC2Data(SiS_Pr); /* Read byte */
  7910. if(SiS_SetStop(SiS_Pr)) continue; /* Stop condition */
  7911. SiS_Pr->SiS_ChrontelInit = 1;
  7912. return tempah;
  7913. }
  7914. return 0xFFFF;
  7915. }
  7916. /* Read from Chrontel 700x */
  7917. /* Parameter is [Register no (S7-S0)] */
  7918. unsigned short
  7919. SiS_GetCH700x(struct SiS_Private *SiS_Pr, unsigned short tempbx)
  7920. {
  7921. unsigned short result;
  7922. SiS_Pr->SiS_DDC_DeviceAddr = 0xEA; /* DAB */
  7923. SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT);
  7924. if(!(SiS_Pr->SiS_ChrontelInit)) {
  7925. SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */
  7926. SiS_Pr->SiS_DDC_Data = 0x02; /* Bitmask in IndexReg for Data */
  7927. SiS_Pr->SiS_DDC_Clk = 0x01; /* Bitmask in IndexReg for Clk */
  7928. SiS_SetupDDCN(SiS_Pr);
  7929. }
  7930. SiS_Pr->SiS_DDC_ReadAddr = tempbx;
  7931. if( ((result = SiS_GetChReg(SiS_Pr,0x80)) == 0xFFFF) &&
  7932. (!SiS_Pr->SiS_ChrontelInit) ) {
  7933. SiS_Pr->SiS_DDC_Index = 0x0a;
  7934. SiS_Pr->SiS_DDC_Data = 0x80;
  7935. SiS_Pr->SiS_DDC_Clk = 0x40;
  7936. SiS_SetupDDCN(SiS_Pr);
  7937. result = SiS_GetChReg(SiS_Pr,0x80);
  7938. }
  7939. return result;
  7940. }
  7941. /* Read from Chrontel 701x */
  7942. /* Parameter is [Register no (S7-S0)] */
  7943. unsigned short
  7944. SiS_GetCH701x(struct SiS_Private *SiS_Pr, unsigned short tempbx)
  7945. {
  7946. SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */
  7947. SiS_Pr->SiS_DDC_Data = 0x08; /* Bitmask in IndexReg for Data */
  7948. SiS_Pr->SiS_DDC_Clk = 0x04; /* Bitmask in IndexReg for Clk */
  7949. SiS_SetupDDCN(SiS_Pr);
  7950. SiS_Pr->SiS_DDC_DeviceAddr = 0xEA; /* DAB */
  7951. SiS_Pr->SiS_DDC_ReadAddr = tempbx;
  7952. return SiS_GetChReg(SiS_Pr,0);
  7953. }
  7954. /* Read from Chrontel 70xx */
  7955. /* Parameter is [Register no (S7-S0)] */
  7956. static
  7957. unsigned short
  7958. SiS_GetCH70xx(struct SiS_Private *SiS_Pr, unsigned short tempbx)
  7959. {
  7960. if(SiS_Pr->SiS_IF_DEF_CH70xx == 1)
  7961. return SiS_GetCH700x(SiS_Pr, tempbx);
  7962. else
  7963. return SiS_GetCH701x(SiS_Pr, tempbx);
  7964. }
  7965. void
  7966. SiS_SetCH70xxANDOR(struct SiS_Private *SiS_Pr, unsigned short reg,
  7967. unsigned char myor, unsigned short myand)
  7968. {
  7969. unsigned short tempbl;
  7970. tempbl = (SiS_GetCH70xx(SiS_Pr, (reg & 0xFF)) & myand) | myor;
  7971. SiS_SetCH70xx(SiS_Pr, reg, tempbl);
  7972. }
  7973. /* Our own DDC functions */
  7974. static
  7975. unsigned short
  7976. SiS_InitDDCRegs(struct SiS_Private *SiS_Pr, unsigned int VBFlags, int VGAEngine,
  7977. unsigned short adaptnum, unsigned short DDCdatatype, bool checkcr32,
  7978. unsigned int VBFlags2)
  7979. {
  7980. unsigned char ddcdtype[] = { 0xa0, 0xa0, 0xa0, 0xa2, 0xa6 };
  7981. unsigned char flag, cr32;
  7982. unsigned short temp = 0, myadaptnum = adaptnum;
  7983. if(adaptnum != 0) {
  7984. if(!(VBFlags2 & VB2_SISTMDSBRIDGE)) return 0xFFFF;
  7985. if((VBFlags2 & VB2_30xBDH) && (adaptnum == 1)) return 0xFFFF;
  7986. }
  7987. /* adapternum for SiS bridges: 0 = CRT1, 1 = LCD, 2 = VGA2 */
  7988. SiS_Pr->SiS_ChrontelInit = 0; /* force re-detection! */
  7989. SiS_Pr->SiS_DDC_SecAddr = 0;
  7990. SiS_Pr->SiS_DDC_DeviceAddr = ddcdtype[DDCdatatype];
  7991. SiS_Pr->SiS_DDC_Port = SiS_Pr->SiS_P3c4;
  7992. SiS_Pr->SiS_DDC_Index = 0x11;
  7993. flag = 0xff;
  7994. cr32 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x32);
  7995. #if 0
  7996. if(VBFlags2 & VB2_SISBRIDGE) {
  7997. if(myadaptnum == 0) {
  7998. if(!(cr32 & 0x20)) {
  7999. myadaptnum = 2;
  8000. if(!(cr32 & 0x10)) {
  8001. myadaptnum = 1;
  8002. if(!(cr32 & 0x08)) {
  8003. myadaptnum = 0;
  8004. }
  8005. }
  8006. }
  8007. }
  8008. }
  8009. #endif
  8010. if(VGAEngine == SIS_300_VGA) { /* 300 series */
  8011. if(myadaptnum != 0) {
  8012. flag = 0;
  8013. if(VBFlags2 & VB2_SISBRIDGE) {
  8014. SiS_Pr->SiS_DDC_Port = SiS_Pr->SiS_Part4Port;
  8015. SiS_Pr->SiS_DDC_Index = 0x0f;
  8016. }
  8017. }
  8018. if(!(VBFlags2 & VB2_301)) {
  8019. if((cr32 & 0x80) && (checkcr32)) {
  8020. if(myadaptnum >= 1) {
  8021. if(!(cr32 & 0x08)) {
  8022. myadaptnum = 1;
  8023. if(!(cr32 & 0x10)) return 0xFFFF;
  8024. }
  8025. }
  8026. }
  8027. }
  8028. temp = 4 - (myadaptnum * 2);
  8029. if(flag) temp = 0;
  8030. } else { /* 315/330 series */
  8031. /* here we simplify: 0 = CRT1, 1 = CRT2 (VGA, LCD) */
  8032. if(VBFlags2 & VB2_SISBRIDGE) {
  8033. if(myadaptnum == 2) {
  8034. myadaptnum = 1;
  8035. }
  8036. }
  8037. if(myadaptnum == 1) {
  8038. flag = 0;
  8039. if(VBFlags2 & VB2_SISBRIDGE) {
  8040. SiS_Pr->SiS_DDC_Port = SiS_Pr->SiS_Part4Port;
  8041. SiS_Pr->SiS_DDC_Index = 0x0f;
  8042. }
  8043. }
  8044. if((cr32 & 0x80) && (checkcr32)) {
  8045. if(myadaptnum >= 1) {
  8046. if(!(cr32 & 0x08)) {
  8047. myadaptnum = 1;
  8048. if(!(cr32 & 0x10)) return 0xFFFF;
  8049. }
  8050. }
  8051. }
  8052. temp = myadaptnum;
  8053. if(myadaptnum == 1) {
  8054. temp = 0;
  8055. if(VBFlags2 & VB2_LVDS) flag = 0xff;
  8056. }
  8057. if(flag) temp = 0;
  8058. }
  8059. SiS_Pr->SiS_DDC_Data = 0x02 << temp;
  8060. SiS_Pr->SiS_DDC_Clk = 0x01 << temp;
  8061. SiS_SetupDDCN(SiS_Pr);
  8062. return 0;
  8063. }
  8064. static unsigned short
  8065. SiS_WriteDABDDC(struct SiS_Private *SiS_Pr)
  8066. {
  8067. if(SiS_SetStart(SiS_Pr)) return 0xFFFF;
  8068. if(SiS_WriteDDC2Data(SiS_Pr, SiS_Pr->SiS_DDC_DeviceAddr)) {
  8069. return 0xFFFF;
  8070. }
  8071. if(SiS_WriteDDC2Data(SiS_Pr, SiS_Pr->SiS_DDC_SecAddr)) {
  8072. return 0xFFFF;
  8073. }
  8074. return 0;
  8075. }
  8076. static unsigned short
  8077. SiS_PrepareReadDDC(struct SiS_Private *SiS_Pr)
  8078. {
  8079. if(SiS_SetStart(SiS_Pr)) return 0xFFFF;
  8080. if(SiS_WriteDDC2Data(SiS_Pr, (SiS_Pr->SiS_DDC_DeviceAddr | 0x01))) {
  8081. return 0xFFFF;
  8082. }
  8083. return 0;
  8084. }
  8085. static unsigned short
  8086. SiS_PrepareDDC(struct SiS_Private *SiS_Pr)
  8087. {
  8088. if(SiS_WriteDABDDC(SiS_Pr)) SiS_WriteDABDDC(SiS_Pr);
  8089. if(SiS_PrepareReadDDC(SiS_Pr)) return (SiS_PrepareReadDDC(SiS_Pr));
  8090. return 0;
  8091. }
  8092. static void
  8093. SiS_SendACK(struct SiS_Private *SiS_Pr, unsigned short yesno)
  8094. {
  8095. SiS_SetSCLKLow(SiS_Pr);
  8096. if(yesno) {
  8097. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8098. SiS_Pr->SiS_DDC_Index,
  8099. SiS_Pr->SiS_DDC_NData,
  8100. SiS_Pr->SiS_DDC_Data);
  8101. } else {
  8102. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8103. SiS_Pr->SiS_DDC_Index,
  8104. SiS_Pr->SiS_DDC_NData,
  8105. 0);
  8106. }
  8107. SiS_SetSCLKHigh(SiS_Pr);
  8108. }
  8109. static unsigned short
  8110. SiS_DoProbeDDC(struct SiS_Private *SiS_Pr)
  8111. {
  8112. unsigned char mask, value;
  8113. unsigned short temp, ret=0;
  8114. bool failed = false;
  8115. SiS_SetSwitchDDC2(SiS_Pr);
  8116. if(SiS_PrepareDDC(SiS_Pr)) {
  8117. SiS_SetStop(SiS_Pr);
  8118. return 0xFFFF;
  8119. }
  8120. mask = 0xf0;
  8121. value = 0x20;
  8122. if(SiS_Pr->SiS_DDC_DeviceAddr == 0xa0) {
  8123. temp = (unsigned char)SiS_ReadDDC2Data(SiS_Pr);
  8124. SiS_SendACK(SiS_Pr, 0);
  8125. if(temp == 0) {
  8126. mask = 0xff;
  8127. value = 0xff;
  8128. } else {
  8129. failed = true;
  8130. ret = 0xFFFF;
  8131. }
  8132. }
  8133. if(!failed) {
  8134. temp = (unsigned char)SiS_ReadDDC2Data(SiS_Pr);
  8135. SiS_SendACK(SiS_Pr, 1);
  8136. temp &= mask;
  8137. if(temp == value) ret = 0;
  8138. else {
  8139. ret = 0xFFFF;
  8140. if(SiS_Pr->SiS_DDC_DeviceAddr == 0xa0) {
  8141. if(temp == 0x30) ret = 0;
  8142. }
  8143. }
  8144. }
  8145. SiS_SetStop(SiS_Pr);
  8146. return ret;
  8147. }
  8148. static
  8149. unsigned short
  8150. SiS_ProbeDDC(struct SiS_Private *SiS_Pr)
  8151. {
  8152. unsigned short flag;
  8153. flag = 0x180;
  8154. SiS_Pr->SiS_DDC_DeviceAddr = 0xa0;
  8155. if(!(SiS_DoProbeDDC(SiS_Pr))) flag |= 0x02;
  8156. SiS_Pr->SiS_DDC_DeviceAddr = 0xa2;
  8157. if(!(SiS_DoProbeDDC(SiS_Pr))) flag |= 0x08;
  8158. SiS_Pr->SiS_DDC_DeviceAddr = 0xa6;
  8159. if(!(SiS_DoProbeDDC(SiS_Pr))) flag |= 0x10;
  8160. if(!(flag & 0x1a)) flag = 0;
  8161. return flag;
  8162. }
  8163. static
  8164. unsigned short
  8165. SiS_ReadDDC(struct SiS_Private *SiS_Pr, unsigned short DDCdatatype, unsigned char *buffer)
  8166. {
  8167. unsigned short flag, length, i;
  8168. unsigned char chksum,gotcha;
  8169. if(DDCdatatype > 4) return 0xFFFF;
  8170. flag = 0;
  8171. SiS_SetSwitchDDC2(SiS_Pr);
  8172. if(!(SiS_PrepareDDC(SiS_Pr))) {
  8173. length = 127;
  8174. if(DDCdatatype != 1) length = 255;
  8175. chksum = 0;
  8176. gotcha = 0;
  8177. for(i=0; i<length; i++) {
  8178. buffer[i] = (unsigned char)SiS_ReadDDC2Data(SiS_Pr);
  8179. chksum += buffer[i];
  8180. gotcha |= buffer[i];
  8181. SiS_SendACK(SiS_Pr, 0);
  8182. }
  8183. buffer[i] = (unsigned char)SiS_ReadDDC2Data(SiS_Pr);
  8184. chksum += buffer[i];
  8185. SiS_SendACK(SiS_Pr, 1);
  8186. if(gotcha) flag = (unsigned short)chksum;
  8187. else flag = 0xFFFF;
  8188. } else {
  8189. flag = 0xFFFF;
  8190. }
  8191. SiS_SetStop(SiS_Pr);
  8192. return flag;
  8193. }
  8194. /* Our private DDC functions
  8195. It complies somewhat with the corresponding VESA function
  8196. in arguments and return values.
  8197. Since this is probably called before the mode is changed,
  8198. we use our pre-detected pSiS-values instead of SiS_Pr as
  8199. regards chipset and video bridge type.
  8200. Arguments:
  8201. adaptnum: 0=CRT1(analog), 1=CRT2/LCD(digital), 2=CRT2/VGA2(analog)
  8202. CRT2 DDC is only supported on SiS301, 301B, 301C, 302B.
  8203. LCDA is CRT1, but DDC is read from CRT2 port.
  8204. DDCdatatype: 0=Probe, 1=EDID, 2=EDID+VDIF, 3=EDID V2 (P&D), 4=EDID V2 (FPDI-2)
  8205. buffer: ptr to 256 data bytes which will be filled with read data.
  8206. Returns 0xFFFF if error, otherwise
  8207. if DDCdatatype > 0: Returns 0 if reading OK (included a correct checksum)
  8208. if DDCdatatype = 0: Returns supported DDC modes
  8209. */
  8210. unsigned short
  8211. SiS_HandleDDC(struct SiS_Private *SiS_Pr, unsigned int VBFlags, int VGAEngine,
  8212. unsigned short adaptnum, unsigned short DDCdatatype, unsigned char *buffer,
  8213. unsigned int VBFlags2)
  8214. {
  8215. unsigned char sr1f, cr17=1;
  8216. unsigned short result;
  8217. if(adaptnum > 2)
  8218. return 0xFFFF;
  8219. if(DDCdatatype > 4)
  8220. return 0xFFFF;
  8221. if((!(VBFlags2 & VB2_VIDEOBRIDGE)) && (adaptnum > 0))
  8222. return 0xFFFF;
  8223. if(SiS_InitDDCRegs(SiS_Pr, VBFlags, VGAEngine, adaptnum, DDCdatatype, false, VBFlags2) == 0xFFFF)
  8224. return 0xFFFF;
  8225. sr1f = SiS_GetReg(SiS_Pr->SiS_P3c4,0x1f);
  8226. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x1f,0x3f,0x04);
  8227. if(VGAEngine == SIS_300_VGA) {
  8228. cr17 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x17) & 0x80;
  8229. if(!cr17) {
  8230. SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x17,0x80);
  8231. SiS_SetReg(SiS_Pr->SiS_P3c4,0x00,0x01);
  8232. SiS_SetReg(SiS_Pr->SiS_P3c4,0x00,0x03);
  8233. }
  8234. }
  8235. if((sr1f) || (!cr17)) {
  8236. SiS_WaitRetrace1(SiS_Pr);
  8237. SiS_WaitRetrace1(SiS_Pr);
  8238. SiS_WaitRetrace1(SiS_Pr);
  8239. SiS_WaitRetrace1(SiS_Pr);
  8240. }
  8241. if(DDCdatatype == 0) {
  8242. result = SiS_ProbeDDC(SiS_Pr);
  8243. } else {
  8244. result = SiS_ReadDDC(SiS_Pr, DDCdatatype, buffer);
  8245. if((!result) && (DDCdatatype == 1)) {
  8246. if((buffer[0] == 0x00) && (buffer[1] == 0xff) &&
  8247. (buffer[2] == 0xff) && (buffer[3] == 0xff) &&
  8248. (buffer[4] == 0xff) && (buffer[5] == 0xff) &&
  8249. (buffer[6] == 0xff) && (buffer[7] == 0x00) &&
  8250. (buffer[0x12] == 1)) {
  8251. if(!SiS_Pr->DDCPortMixup) {
  8252. if(adaptnum == 1) {
  8253. if(!(buffer[0x14] & 0x80)) result = 0xFFFE;
  8254. } else {
  8255. if(buffer[0x14] & 0x80) result = 0xFFFE;
  8256. }
  8257. }
  8258. }
  8259. }
  8260. }
  8261. SiS_SetReg(SiS_Pr->SiS_P3c4,0x1f,sr1f);
  8262. if(VGAEngine == SIS_300_VGA) {
  8263. SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x17,0x7f,cr17);
  8264. }
  8265. return result;
  8266. }
  8267. /* Generic I2C functions for Chrontel & DDC --------- */
  8268. static void
  8269. SiS_SetSwitchDDC2(struct SiS_Private *SiS_Pr)
  8270. {
  8271. SiS_SetSCLKHigh(SiS_Pr);
  8272. SiS_WaitRetrace1(SiS_Pr);
  8273. SiS_SetSCLKLow(SiS_Pr);
  8274. SiS_WaitRetrace1(SiS_Pr);
  8275. }
  8276. unsigned short
  8277. SiS_ReadDDC1Bit(struct SiS_Private *SiS_Pr)
  8278. {
  8279. SiS_WaitRetrace1(SiS_Pr);
  8280. return ((SiS_GetReg(SiS_Pr->SiS_P3c4,0x11) & 0x02) >> 1);
  8281. }
  8282. /* Set I2C start condition */
  8283. /* This is done by a SD high-to-low transition while SC is high */
  8284. static unsigned short
  8285. SiS_SetStart(struct SiS_Private *SiS_Pr)
  8286. {
  8287. if(SiS_SetSCLKLow(SiS_Pr)) return 0xFFFF; /* (SC->low) */
  8288. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8289. SiS_Pr->SiS_DDC_Index,
  8290. SiS_Pr->SiS_DDC_NData,
  8291. SiS_Pr->SiS_DDC_Data); /* SD->high */
  8292. if(SiS_SetSCLKHigh(SiS_Pr)) return 0xFFFF; /* SC->high */
  8293. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8294. SiS_Pr->SiS_DDC_Index,
  8295. SiS_Pr->SiS_DDC_NData,
  8296. 0x00); /* SD->low = start condition */
  8297. if(SiS_SetSCLKHigh(SiS_Pr)) return 0xFFFF; /* (SC->low) */
  8298. return 0;
  8299. }
  8300. /* Set I2C stop condition */
  8301. /* This is done by a SD low-to-high transition while SC is high */
  8302. static unsigned short
  8303. SiS_SetStop(struct SiS_Private *SiS_Pr)
  8304. {
  8305. if(SiS_SetSCLKLow(SiS_Pr)) return 0xFFFF; /* (SC->low) */
  8306. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8307. SiS_Pr->SiS_DDC_Index,
  8308. SiS_Pr->SiS_DDC_NData,
  8309. 0x00); /* SD->low */
  8310. if(SiS_SetSCLKHigh(SiS_Pr)) return 0xFFFF; /* SC->high */
  8311. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8312. SiS_Pr->SiS_DDC_Index,
  8313. SiS_Pr->SiS_DDC_NData,
  8314. SiS_Pr->SiS_DDC_Data); /* SD->high = stop condition */
  8315. if(SiS_SetSCLKHigh(SiS_Pr)) return 0xFFFF; /* (SC->high) */
  8316. return 0;
  8317. }
  8318. /* Write 8 bits of data */
  8319. static unsigned short
  8320. SiS_WriteDDC2Data(struct SiS_Private *SiS_Pr, unsigned short tempax)
  8321. {
  8322. unsigned short i,flag,temp;
  8323. flag = 0x80;
  8324. for(i = 0; i < 8; i++) {
  8325. SiS_SetSCLKLow(SiS_Pr); /* SC->low */
  8326. if(tempax & flag) {
  8327. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8328. SiS_Pr->SiS_DDC_Index,
  8329. SiS_Pr->SiS_DDC_NData,
  8330. SiS_Pr->SiS_DDC_Data); /* Write bit (1) to SD */
  8331. } else {
  8332. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8333. SiS_Pr->SiS_DDC_Index,
  8334. SiS_Pr->SiS_DDC_NData,
  8335. 0x00); /* Write bit (0) to SD */
  8336. }
  8337. SiS_SetSCLKHigh(SiS_Pr); /* SC->high */
  8338. flag >>= 1;
  8339. }
  8340. temp = SiS_CheckACK(SiS_Pr); /* Check acknowledge */
  8341. return temp;
  8342. }
  8343. static unsigned short
  8344. SiS_ReadDDC2Data(struct SiS_Private *SiS_Pr)
  8345. {
  8346. unsigned short i, temp, getdata;
  8347. getdata = 0;
  8348. for(i = 0; i < 8; i++) {
  8349. getdata <<= 1;
  8350. SiS_SetSCLKLow(SiS_Pr);
  8351. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8352. SiS_Pr->SiS_DDC_Index,
  8353. SiS_Pr->SiS_DDC_NData,
  8354. SiS_Pr->SiS_DDC_Data);
  8355. SiS_SetSCLKHigh(SiS_Pr);
  8356. temp = SiS_GetReg(SiS_Pr->SiS_DDC_Port,SiS_Pr->SiS_DDC_Index);
  8357. if(temp & SiS_Pr->SiS_DDC_Data) getdata |= 0x01;
  8358. }
  8359. return getdata;
  8360. }
  8361. static unsigned short
  8362. SiS_SetSCLKLow(struct SiS_Private *SiS_Pr)
  8363. {
  8364. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8365. SiS_Pr->SiS_DDC_Index,
  8366. SiS_Pr->SiS_DDC_NClk,
  8367. 0x00); /* SetSCLKLow() */
  8368. SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT);
  8369. return 0;
  8370. }
  8371. static unsigned short
  8372. SiS_SetSCLKHigh(struct SiS_Private *SiS_Pr)
  8373. {
  8374. unsigned short temp, watchdog=1000;
  8375. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8376. SiS_Pr->SiS_DDC_Index,
  8377. SiS_Pr->SiS_DDC_NClk,
  8378. SiS_Pr->SiS_DDC_Clk); /* SetSCLKHigh() */
  8379. do {
  8380. temp = SiS_GetReg(SiS_Pr->SiS_DDC_Port,SiS_Pr->SiS_DDC_Index);
  8381. } while((!(temp & SiS_Pr->SiS_DDC_Clk)) && --watchdog);
  8382. if (!watchdog) {
  8383. return 0xFFFF;
  8384. }
  8385. SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT);
  8386. return 0;
  8387. }
  8388. /* Check I2C acknowledge */
  8389. /* Returns 0 if ack ok, non-0 if ack not ok */
  8390. static unsigned short
  8391. SiS_CheckACK(struct SiS_Private *SiS_Pr)
  8392. {
  8393. unsigned short tempah;
  8394. SiS_SetSCLKLow(SiS_Pr); /* (SC->low) */
  8395. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8396. SiS_Pr->SiS_DDC_Index,
  8397. SiS_Pr->SiS_DDC_NData,
  8398. SiS_Pr->SiS_DDC_Data); /* (SD->high) */
  8399. SiS_SetSCLKHigh(SiS_Pr); /* SC->high = clock impulse for ack */
  8400. tempah = SiS_GetReg(SiS_Pr->SiS_DDC_Port,SiS_Pr->SiS_DDC_Index); /* Read SD */
  8401. SiS_SetSCLKLow(SiS_Pr); /* SC->low = end of clock impulse */
  8402. if(tempah & SiS_Pr->SiS_DDC_Data) return 1; /* Ack OK if bit = 0 */
  8403. return 0;
  8404. }
  8405. /* End of I2C functions ----------------------- */
  8406. /* =============== SiS 315/330 O.E.M. ================= */
  8407. #ifdef CONFIG_FB_SIS_315
  8408. static unsigned short
  8409. GetRAMDACromptr(struct SiS_Private *SiS_Pr)
  8410. {
  8411. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  8412. unsigned short romptr;
  8413. if(SiS_Pr->ChipType < SIS_330) {
  8414. romptr = SISGETROMW(0x128);
  8415. if(SiS_Pr->SiS_VBType & VB_SIS30xB)
  8416. romptr = SISGETROMW(0x12a);
  8417. } else {
  8418. romptr = SISGETROMW(0x1a8);
  8419. if(SiS_Pr->SiS_VBType & VB_SIS30xB)
  8420. romptr = SISGETROMW(0x1aa);
  8421. }
  8422. return romptr;
  8423. }
  8424. static unsigned short
  8425. GetLCDromptr(struct SiS_Private *SiS_Pr)
  8426. {
  8427. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  8428. unsigned short romptr;
  8429. if(SiS_Pr->ChipType < SIS_330) {
  8430. romptr = SISGETROMW(0x120);
  8431. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV)
  8432. romptr = SISGETROMW(0x122);
  8433. } else {
  8434. romptr = SISGETROMW(0x1a0);
  8435. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV)
  8436. romptr = SISGETROMW(0x1a2);
  8437. }
  8438. return romptr;
  8439. }
  8440. static unsigned short
  8441. GetTVromptr(struct SiS_Private *SiS_Pr)
  8442. {
  8443. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  8444. unsigned short romptr;
  8445. if(SiS_Pr->ChipType < SIS_330) {
  8446. romptr = SISGETROMW(0x114);
  8447. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV)
  8448. romptr = SISGETROMW(0x11a);
  8449. } else {
  8450. romptr = SISGETROMW(0x194);
  8451. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV)
  8452. romptr = SISGETROMW(0x19a);
  8453. }
  8454. return romptr;
  8455. }
  8456. static unsigned short
  8457. GetLCDPtrIndexBIOS(struct SiS_Private *SiS_Pr)
  8458. {
  8459. unsigned short index;
  8460. if((IS_SIS650) && (SiS_Pr->SiS_VBType & VB_SISLVDS)) {
  8461. if(!(SiS_IsNotM650orLater(SiS_Pr))) {
  8462. if((index = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) & 0xf0)) {
  8463. index >>= 4;
  8464. index *= 3;
  8465. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) index += 2;
  8466. else if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) index++;
  8467. return index;
  8468. }
  8469. }
  8470. }
  8471. index = SiS_GetBIOSLCDResInfo(SiS_Pr) & 0x0F;
  8472. if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) index -= 5;
  8473. if(SiS_Pr->SiS_VBType & VB_SIS301C) { /* 1.15.20 and later (not VB specific) */
  8474. if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) index -= 5;
  8475. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x768) index -= 5;
  8476. } else {
  8477. if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) index -= 6;
  8478. }
  8479. index--;
  8480. index *= 3;
  8481. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) index += 2;
  8482. else if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) index++;
  8483. return index;
  8484. }
  8485. static unsigned short
  8486. GetLCDPtrIndex(struct SiS_Private *SiS_Pr)
  8487. {
  8488. unsigned short index;
  8489. index = ((SiS_GetBIOSLCDResInfo(SiS_Pr) & 0x0F) - 1) * 3;
  8490. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) index += 2;
  8491. else if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) index++;
  8492. return index;
  8493. }
  8494. static unsigned short
  8495. GetTVPtrIndex(struct SiS_Private *SiS_Pr)
  8496. {
  8497. unsigned short index;
  8498. index = 0;
  8499. if(SiS_Pr->SiS_TVMode & TVSetPAL) index = 1;
  8500. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) index = 2;
  8501. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) index = 0;
  8502. index <<= 1;
  8503. if((SiS_Pr->SiS_VBInfo & SetInSlaveMode) &&
  8504. (SiS_Pr->SiS_TVMode & TVSetTVSimuMode)) {
  8505. index++;
  8506. }
  8507. return index;
  8508. }
  8509. static unsigned int
  8510. GetOEMTVPtr661_2_GEN(struct SiS_Private *SiS_Pr, int addme)
  8511. {
  8512. unsigned short index = 0, temp = 0;
  8513. if(SiS_Pr->SiS_TVMode & TVSetPAL) index = 1;
  8514. if(SiS_Pr->SiS_TVMode & TVSetPALM) index = 2;
  8515. if(SiS_Pr->SiS_TVMode & TVSetPALN) index = 3;
  8516. if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) index = 6;
  8517. if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) {
  8518. index = 4;
  8519. if(SiS_Pr->SiS_TVMode & TVSetPALM) index++;
  8520. if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) index = 7;
  8521. }
  8522. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  8523. if((!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) ||
  8524. (SiS_Pr->SiS_TVMode & TVSetTVSimuMode)) {
  8525. index += addme;
  8526. temp++;
  8527. }
  8528. temp += 0x0100;
  8529. }
  8530. return (unsigned int)(index | (temp << 16));
  8531. }
  8532. static unsigned int
  8533. GetOEMTVPtr661_2_OLD(struct SiS_Private *SiS_Pr)
  8534. {
  8535. return (GetOEMTVPtr661_2_GEN(SiS_Pr, 8));
  8536. }
  8537. #if 0
  8538. static unsigned int
  8539. GetOEMTVPtr661_2_NEW(struct SiS_Private *SiS_Pr)
  8540. {
  8541. return (GetOEMTVPtr661_2_GEN(SiS_Pr, 6));
  8542. }
  8543. #endif
  8544. static int
  8545. GetOEMTVPtr661(struct SiS_Private *SiS_Pr)
  8546. {
  8547. int index = 0;
  8548. if(SiS_Pr->SiS_TVMode & TVSetPAL) index = 2;
  8549. if(SiS_Pr->SiS_ROMNew) {
  8550. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525i) index = 4;
  8551. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) index = 6;
  8552. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) index = 8;
  8553. if(SiS_Pr->SiS_TVMode & TVSetHiVision) index = 10;
  8554. } else {
  8555. if(SiS_Pr->SiS_TVMode & TVSetHiVision) index = 4;
  8556. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525i) index = 6;
  8557. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) index = 8;
  8558. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) index = 10;
  8559. }
  8560. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) index++;
  8561. return index;
  8562. }
  8563. static void
  8564. SetDelayComp(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
  8565. {
  8566. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  8567. unsigned short delay=0,index,myindex,temp,romptr=0;
  8568. bool dochiptest = true;
  8569. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  8570. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x20,0xbf);
  8571. } else {
  8572. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x35,0x7f);
  8573. }
  8574. /* Find delay (from ROM, internal tables, PCI subsystem) */
  8575. if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) { /* ------------ VGA */
  8576. if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
  8577. romptr = GetRAMDACromptr(SiS_Pr);
  8578. }
  8579. if(romptr) delay = ROMAddr[romptr];
  8580. else {
  8581. delay = 0x04;
  8582. if(SiS_Pr->SiS_VBType & VB_SIS30xB) {
  8583. if(IS_SIS650) {
  8584. delay = 0x0a;
  8585. } else if(IS_SIS740) {
  8586. delay = 0x00;
  8587. } else {
  8588. delay = 0x0c;
  8589. }
  8590. } else if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  8591. delay = 0x00;
  8592. }
  8593. }
  8594. } else if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD|SetCRT2ToLCDA)) { /* ---------- LCD/LCDA */
  8595. bool gotitfrompci = false;
  8596. /* Could we detect a PDC for LCD or did we get a user-defined? If yes, use it */
  8597. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  8598. if(SiS_Pr->PDC != -1) {
  8599. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0xf0,((SiS_Pr->PDC >> 1) & 0x0f));
  8600. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x35,0x7f,((SiS_Pr->PDC & 0x01) << 7));
  8601. return;
  8602. }
  8603. } else {
  8604. if(SiS_Pr->PDCA != -1) {
  8605. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0x0f,((SiS_Pr->PDCA << 3) & 0xf0));
  8606. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x20,0xbf,((SiS_Pr->PDCA & 0x01) << 6));
  8607. return;
  8608. }
  8609. }
  8610. /* Custom Panel? */
  8611. if(SiS_Pr->SiS_LCDResInfo == Panel_Custom) {
  8612. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  8613. delay = 0x00;
  8614. if((SiS_Pr->PanelXRes <= 1280) && (SiS_Pr->PanelYRes <= 1024)) {
  8615. delay = 0x20;
  8616. }
  8617. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0x0f,delay);
  8618. } else {
  8619. delay = 0x0c;
  8620. if(SiS_Pr->SiS_VBType & VB_SIS301C) {
  8621. delay = 0x03;
  8622. if((SiS_Pr->PanelXRes > 1280) && (SiS_Pr->PanelYRes > 1024)) {
  8623. delay = 0x00;
  8624. }
  8625. } else if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  8626. if(IS_SIS740) delay = 0x01;
  8627. else delay = 0x03;
  8628. }
  8629. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0xf0,delay);
  8630. }
  8631. return;
  8632. }
  8633. /* This is a piece of typical SiS crap: They code the OEM LCD
  8634. * delay into the code, at no defined place in the BIOS.
  8635. * We now have to start doing a PCI subsystem check here.
  8636. */
  8637. switch(SiS_Pr->SiS_CustomT) {
  8638. case CUT_COMPAQ1280:
  8639. case CUT_COMPAQ12802:
  8640. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) {
  8641. gotitfrompci = true;
  8642. dochiptest = false;
  8643. delay = 0x03;
  8644. }
  8645. break;
  8646. case CUT_CLEVO1400:
  8647. case CUT_CLEVO14002:
  8648. gotitfrompci = true;
  8649. dochiptest = false;
  8650. delay = 0x02;
  8651. break;
  8652. case CUT_CLEVO1024:
  8653. case CUT_CLEVO10242:
  8654. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  8655. gotitfrompci = true;
  8656. dochiptest = false;
  8657. delay = 0x33;
  8658. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2D,delay);
  8659. delay &= 0x0f;
  8660. }
  8661. break;
  8662. }
  8663. /* Could we find it through the PCI ID? If no, use ROM or table */
  8664. if(!gotitfrompci) {
  8665. index = GetLCDPtrIndexBIOS(SiS_Pr);
  8666. myindex = GetLCDPtrIndex(SiS_Pr);
  8667. if(IS_SIS650 && (SiS_Pr->SiS_VBType & VB_SISLVDS)) {
  8668. if(SiS_IsNotM650orLater(SiS_Pr)) {
  8669. if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
  8670. /* Always use the second pointer on 650; some BIOSes */
  8671. /* still carry old 301 data at the first location */
  8672. /* romptr = SISGETROMW(0x120); */
  8673. /* if(SiS_Pr->SiS_VBType & VB_SIS302LV) */
  8674. romptr = SISGETROMW(0x122);
  8675. if(!romptr) return;
  8676. delay = ROMAddr[(romptr + index)];
  8677. } else {
  8678. delay = SiS310_LCDDelayCompensation_650301LV[myindex];
  8679. }
  8680. } else {
  8681. delay = SiS310_LCDDelayCompensation_651301LV[myindex];
  8682. if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV))
  8683. delay = SiS310_LCDDelayCompensation_651302LV[myindex];
  8684. }
  8685. } else if(SiS_Pr->SiS_UseROM &&
  8686. (!(SiS_Pr->SiS_ROMNew)) &&
  8687. (SiS_Pr->SiS_LCDResInfo != Panel_1280x1024) &&
  8688. (SiS_Pr->SiS_LCDResInfo != Panel_1280x768) &&
  8689. (SiS_Pr->SiS_LCDResInfo != Panel_1280x960) &&
  8690. (SiS_Pr->SiS_LCDResInfo != Panel_1600x1200) &&
  8691. ((romptr = GetLCDromptr(SiS_Pr)))) {
  8692. /* Data for 1280x1024 wrong in 301B BIOS */
  8693. /* Data for 1600x1200 wrong in 301C BIOS */
  8694. delay = ROMAddr[(romptr + index)];
  8695. } else if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  8696. if(IS_SIS740) delay = 0x03;
  8697. else delay = 0x00;
  8698. } else {
  8699. delay = SiS310_LCDDelayCompensation_301[myindex];
  8700. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  8701. if(IS_SIS740) delay = 0x01;
  8702. else if(SiS_Pr->ChipType <= SIS_315PRO) delay = SiS310_LCDDelayCompensation_3xx301LV[myindex];
  8703. else delay = SiS310_LCDDelayCompensation_650301LV[myindex];
  8704. } else if(SiS_Pr->SiS_VBType & VB_SIS301C) {
  8705. if(IS_SIS740) delay = 0x01; /* ? */
  8706. else delay = 0x03;
  8707. if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) delay = 0x00; /* experience */
  8708. } else if(SiS_Pr->SiS_VBType & VB_SIS30xB) {
  8709. if(IS_SIS740) delay = 0x01;
  8710. else delay = SiS310_LCDDelayCompensation_3xx301B[myindex];
  8711. }
  8712. }
  8713. } /* got it from PCI */
  8714. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  8715. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,0x0F,((delay << 4) & 0xf0));
  8716. dochiptest = false;
  8717. }
  8718. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { /* ------------ TV */
  8719. index = GetTVPtrIndex(SiS_Pr);
  8720. if(IS_SIS650 && (SiS_Pr->SiS_VBType & VB_SISLVDS)) {
  8721. if(SiS_IsNotM650orLater(SiS_Pr)) {
  8722. if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
  8723. /* Always use the second pointer on 650; some BIOSes */
  8724. /* still carry old 301 data at the first location */
  8725. /* romptr = SISGETROMW(0x114); */
  8726. /* if(SiS_Pr->SiS_VBType & VB_SIS302LV) */
  8727. romptr = SISGETROMW(0x11a);
  8728. if(!romptr) return;
  8729. delay = ROMAddr[romptr + index];
  8730. } else {
  8731. delay = SiS310_TVDelayCompensation_301B[index];
  8732. }
  8733. } else {
  8734. switch(SiS_Pr->SiS_CustomT) {
  8735. case CUT_COMPAQ1280:
  8736. case CUT_COMPAQ12802:
  8737. case CUT_CLEVO1400:
  8738. case CUT_CLEVO14002:
  8739. delay = 0x02;
  8740. dochiptest = false;
  8741. break;
  8742. case CUT_CLEVO1024:
  8743. case CUT_CLEVO10242:
  8744. delay = 0x03;
  8745. dochiptest = false;
  8746. break;
  8747. default:
  8748. delay = SiS310_TVDelayCompensation_651301LV[index];
  8749. if(SiS_Pr->SiS_VBType & VB_SIS302LV) {
  8750. delay = SiS310_TVDelayCompensation_651302LV[index];
  8751. }
  8752. }
  8753. }
  8754. } else if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
  8755. romptr = GetTVromptr(SiS_Pr);
  8756. if(!romptr) return;
  8757. delay = ROMAddr[romptr + index];
  8758. } else if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  8759. delay = SiS310_TVDelayCompensation_LVDS[index];
  8760. } else {
  8761. delay = SiS310_TVDelayCompensation_301[index];
  8762. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  8763. if(IS_SIS740) {
  8764. delay = SiS310_TVDelayCompensation_740301B[index];
  8765. /* LV: use 301 data? BIOS bug? */
  8766. } else {
  8767. delay = SiS310_TVDelayCompensation_301B[index];
  8768. if(SiS_Pr->SiS_VBType & VB_SIS301C) delay = 0x02;
  8769. }
  8770. }
  8771. }
  8772. if(SiS_LCDAEnabled(SiS_Pr)) {
  8773. delay &= 0x0f;
  8774. dochiptest = false;
  8775. }
  8776. } else return;
  8777. /* Write delay */
  8778. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  8779. if(IS_SIS650 && (SiS_Pr->SiS_VBType & VB_SISLVDS) && dochiptest) {
  8780. temp = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) & 0xf0) >> 4;
  8781. if(temp == 8) { /* 1400x1050 BIOS (COMPAL) */
  8782. delay &= 0x0f;
  8783. delay |= 0xb0;
  8784. } else if(temp == 6) {
  8785. delay &= 0x0f;
  8786. delay |= 0xc0;
  8787. } else if(temp > 7) { /* 1280x1024 BIOS (which one?) */
  8788. delay = 0x35;
  8789. }
  8790. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2D,delay);
  8791. } else {
  8792. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,0xF0,delay);
  8793. }
  8794. } else { /* LVDS */
  8795. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  8796. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,0xF0,delay);
  8797. } else {
  8798. if(IS_SIS650 && (SiS_Pr->SiS_IF_DEF_CH70xx != 0)) {
  8799. delay <<= 4;
  8800. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,0x0F,delay);
  8801. } else {
  8802. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,0xF0,delay);
  8803. }
  8804. }
  8805. }
  8806. }
  8807. static void
  8808. SetAntiFlicker(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  8809. {
  8810. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  8811. unsigned short index,temp,temp1,romptr=0;
  8812. if(SiS_Pr->SiS_TVMode & (TVSetYPbPr750p|TVSetYPbPr525p)) return;
  8813. if(ModeNo<=0x13)
  8814. index = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].VB_StTVFlickerIndex;
  8815. else
  8816. index = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].VB_ExtTVFlickerIndex;
  8817. temp = GetTVPtrIndex(SiS_Pr);
  8818. temp >>= 1; /* 0: NTSC/YPbPr, 1: PAL, 2: HiTV */
  8819. temp1 = temp;
  8820. if(SiS_Pr->SiS_UseROM && (!(SiS_Pr->SiS_ROMNew))) {
  8821. if(SiS_Pr->ChipType >= SIS_661) {
  8822. temp1 = GetOEMTVPtr661(SiS_Pr);
  8823. temp1 >>= 1;
  8824. romptr = SISGETROMW(0x260);
  8825. if(SiS_Pr->ChipType >= SIS_760) {
  8826. romptr = SISGETROMW(0x360);
  8827. }
  8828. } else if(SiS_Pr->ChipType >= SIS_330) {
  8829. romptr = SISGETROMW(0x192);
  8830. } else {
  8831. romptr = SISGETROMW(0x112);
  8832. }
  8833. }
  8834. if(romptr) {
  8835. temp1 <<= 1;
  8836. temp = ROMAddr[romptr + temp1 + index];
  8837. } else {
  8838. temp = SiS310_TVAntiFlick1[temp][index];
  8839. }
  8840. temp <<= 4;
  8841. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x0A,0x8f,temp); /* index 0A D[6:4] */
  8842. }
  8843. static void
  8844. SetEdgeEnhance(struct SiS_Private *SiS_Pr, unsigned short ModeNo,unsigned short ModeIdIndex)
  8845. {
  8846. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  8847. unsigned short index,temp,temp1,romptr=0;
  8848. temp = temp1 = GetTVPtrIndex(SiS_Pr) >> 1; /* 0: NTSC/YPbPr, 1: PAL, 2: HiTV */
  8849. if(ModeNo <= 0x13)
  8850. index = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].VB_StTVEdgeIndex;
  8851. else
  8852. index = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].VB_ExtTVEdgeIndex;
  8853. if(SiS_Pr->SiS_UseROM && (!(SiS_Pr->SiS_ROMNew))) {
  8854. if(SiS_Pr->ChipType >= SIS_661) {
  8855. romptr = SISGETROMW(0x26c);
  8856. if(SiS_Pr->ChipType >= SIS_760) {
  8857. romptr = SISGETROMW(0x36c);
  8858. }
  8859. temp1 = GetOEMTVPtr661(SiS_Pr);
  8860. temp1 >>= 1;
  8861. } else if(SiS_Pr->ChipType >= SIS_330) {
  8862. romptr = SISGETROMW(0x1a4);
  8863. } else {
  8864. romptr = SISGETROMW(0x124);
  8865. }
  8866. }
  8867. if(romptr) {
  8868. temp1 <<= 1;
  8869. temp = ROMAddr[romptr + temp1 + index];
  8870. } else {
  8871. temp = SiS310_TVEdge1[temp][index];
  8872. }
  8873. temp <<= 5;
  8874. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x3A,0x1F,temp); /* index 0A D[7:5] */
  8875. }
  8876. static void
  8877. SetYFilter(struct SiS_Private *SiS_Pr, unsigned short ModeNo,unsigned short ModeIdIndex)
  8878. {
  8879. unsigned short index, temp, i, j;
  8880. if(ModeNo <= 0x13) {
  8881. index = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].VB_StTVYFilterIndex;
  8882. } else {
  8883. index = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].VB_ExtTVYFilterIndex;
  8884. }
  8885. temp = GetTVPtrIndex(SiS_Pr) >> 1; /* 0: NTSC/YPbPr, 1: PAL, 2: HiTV */
  8886. if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) temp = 1; /* NTSC-J uses PAL */
  8887. else if(SiS_Pr->SiS_TVMode & TVSetPALM) temp = 3; /* PAL-M */
  8888. else if(SiS_Pr->SiS_TVMode & TVSetPALN) temp = 4; /* PAL-N */
  8889. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) temp = 1; /* HiVision uses PAL */
  8890. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  8891. for(i=0x35, j=0; i<=0x38; i++, j++) {
  8892. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVYFilter2[temp][index][j]);
  8893. }
  8894. for(i=0x48; i<=0x4A; i++, j++) {
  8895. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVYFilter2[temp][index][j]);
  8896. }
  8897. } else {
  8898. for(i=0x35, j=0; i<=0x38; i++, j++) {
  8899. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVYFilter1[temp][index][j]);
  8900. }
  8901. }
  8902. }
  8903. static void
  8904. SetPhaseIncr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  8905. {
  8906. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  8907. unsigned short index,temp,i,j,resinfo,romptr=0;
  8908. unsigned int lindex;
  8909. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) return;
  8910. /* NTSC-J data not in BIOS, and already set in SetGroup2 */
  8911. if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) return;
  8912. if((SiS_Pr->ChipType >= SIS_661) || SiS_Pr->SiS_ROMNew) {
  8913. lindex = GetOEMTVPtr661_2_OLD(SiS_Pr) & 0xffff;
  8914. lindex <<= 2;
  8915. for(j=0, i=0x31; i<=0x34; i++, j++) {
  8916. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS_TVPhase[lindex + j]);
  8917. }
  8918. return;
  8919. }
  8920. /* PAL-M, PAL-N not in BIOS, and already set in SetGroup2 */
  8921. if(SiS_Pr->SiS_TVMode & (TVSetPALM | TVSetPALN)) return;
  8922. if(ModeNo<=0x13) {
  8923. resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
  8924. } else {
  8925. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  8926. }
  8927. temp = GetTVPtrIndex(SiS_Pr);
  8928. /* 0: NTSC Graphics, 1: NTSC Text, 2: PAL Graphics,
  8929. * 3: PAL Text, 4: HiTV Graphics 5: HiTV Text
  8930. */
  8931. if(SiS_Pr->SiS_UseROM) {
  8932. romptr = SISGETROMW(0x116);
  8933. if(SiS_Pr->ChipType >= SIS_330) {
  8934. romptr = SISGETROMW(0x196);
  8935. }
  8936. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  8937. romptr = SISGETROMW(0x11c);
  8938. if(SiS_Pr->ChipType >= SIS_330) {
  8939. romptr = SISGETROMW(0x19c);
  8940. }
  8941. if((SiS_Pr->SiS_VBInfo & SetInSlaveMode) && (!(SiS_Pr->SiS_TVMode & TVSetTVSimuMode))) {
  8942. romptr = SISGETROMW(0x116);
  8943. if(SiS_Pr->ChipType >= SIS_330) {
  8944. romptr = SISGETROMW(0x196);
  8945. }
  8946. }
  8947. }
  8948. }
  8949. if(romptr) {
  8950. romptr += (temp << 2);
  8951. for(j=0, i=0x31; i<=0x34; i++, j++) {
  8952. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,ROMAddr[romptr + j]);
  8953. }
  8954. } else {
  8955. index = temp % 2;
  8956. temp >>= 1; /* 0:NTSC, 1:PAL, 2:HiTV */
  8957. for(j=0, i=0x31; i<=0x34; i++, j++) {
  8958. if(!(SiS_Pr->SiS_VBType & VB_SIS30xBLV))
  8959. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVPhaseIncr1[temp][index][j]);
  8960. else if((!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) || (SiS_Pr->SiS_TVMode & TVSetTVSimuMode))
  8961. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVPhaseIncr2[temp][index][j]);
  8962. else
  8963. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVPhaseIncr1[temp][index][j]);
  8964. }
  8965. }
  8966. if((SiS_Pr->SiS_VBType & VB_SIS30xBLV) && (!(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision))) {
  8967. if((!(SiS_Pr->SiS_TVMode & (TVSetPAL | TVSetYPbPr525p | TVSetYPbPr750p))) && (ModeNo > 0x13)) {
  8968. if((resinfo == SIS_RI_640x480) ||
  8969. (resinfo == SIS_RI_800x600)) {
  8970. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x31,0x21);
  8971. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x32,0xf0);
  8972. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x33,0xf5);
  8973. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x34,0x7f);
  8974. } else if(resinfo == SIS_RI_1024x768) {
  8975. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x31,0x1e);
  8976. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x32,0x8b);
  8977. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x33,0xfb);
  8978. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x34,0x7b);
  8979. }
  8980. }
  8981. }
  8982. }
  8983. static void
  8984. SetDelayComp661(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
  8985. unsigned short ModeIdIndex, unsigned short RTI)
  8986. {
  8987. unsigned short delay = 0, romptr = 0, index, lcdpdcindex;
  8988. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  8989. if(!(SiS_Pr->SiS_VBInfo & (SetCRT2ToTV | SetCRT2ToLCD | SetCRT2ToLCDA | SetCRT2ToRAMDAC)))
  8990. return;
  8991. /* 1. New ROM: VGA2 and LCD/LCDA-Pass1:1 */
  8992. /* (If a custom mode is used, Pass1:1 is always set; hence we do this:) */
  8993. if(SiS_Pr->SiS_ROMNew) {
  8994. if((SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) ||
  8995. ((SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) &&
  8996. (SiS_Pr->SiS_LCDInfo & LCDPass11))) {
  8997. index = 25;
  8998. if(SiS_Pr->UseCustomMode) {
  8999. index = SiS_Pr->CSRClock;
  9000. } else if(ModeNo > 0x13) {
  9001. index = SiS_GetVCLK2Ptr(SiS_Pr,ModeNo,ModeIdIndex,RTI);
  9002. index = SiS_Pr->SiS_VCLKData[index].CLOCK;
  9003. }
  9004. if(index < 25) index = 25;
  9005. index = ((index / 25) - 1) << 1;
  9006. if((ROMAddr[0x5b] & 0x80) || (SiS_Pr->SiS_VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD))) {
  9007. index++;
  9008. }
  9009. romptr = SISGETROMW(0x104);
  9010. delay = ROMAddr[romptr + index];
  9011. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD)) {
  9012. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0xf0,((delay >> 1) & 0x0f));
  9013. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x35,0x7f,((delay & 0x01) << 7));
  9014. } else {
  9015. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0x0f,((delay << 3) & 0xf0));
  9016. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x20,0xbf,((delay & 0x01) << 6));
  9017. }
  9018. return;
  9019. }
  9020. }
  9021. /* 2. Old ROM: VGA2 and LCD/LCDA-Pass 1:1 */
  9022. if(SiS_Pr->UseCustomMode) delay = 0x04;
  9023. else if(ModeNo <= 0x13) delay = 0x04;
  9024. else delay = (SiS_Pr->SiS_RefIndex[RTI].Ext_PDC >> 4);
  9025. delay |= (delay << 8);
  9026. if(SiS_Pr->ChipType >= XGI_20) {
  9027. delay = 0x0606;
  9028. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  9029. delay = 0x0404;
  9030. if(SiS_Pr->SiS_XGIROM) {
  9031. index = GetTVPtrIndex(SiS_Pr);
  9032. if((romptr = SISGETROMW(0x35e))) {
  9033. delay = (ROMAddr[romptr + index] & 0x0f) << 1;
  9034. delay |= (delay << 8);
  9035. }
  9036. }
  9037. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  9038. if(SiS_Pr->ChipType == XGI_40 && SiS_Pr->ChipRevision == 0x02) {
  9039. delay -= 0x0404;
  9040. }
  9041. }
  9042. }
  9043. } else if(SiS_Pr->ChipType >= SIS_340) {
  9044. delay = 0x0606;
  9045. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  9046. delay = 0x0404;
  9047. }
  9048. /* TODO (eventually) */
  9049. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  9050. /* 3. TV */
  9051. index = GetOEMTVPtr661(SiS_Pr);
  9052. if(SiS_Pr->SiS_ROMNew) {
  9053. romptr = SISGETROMW(0x106);
  9054. if(SiS_Pr->SiS_VBType & VB_UMC) romptr += 12;
  9055. delay = ROMAddr[romptr + index];
  9056. } else {
  9057. delay = 0x04;
  9058. if(index > 3) delay = 0;
  9059. }
  9060. } else if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  9061. /* 4. LCD, LCDA (for new ROM only LV and non-Pass 1:1) */
  9062. if( (SiS_Pr->SiS_LCDResInfo != Panel_Custom) &&
  9063. ((romptr = GetLCDStructPtr661_2(SiS_Pr))) ) {
  9064. lcdpdcindex = (SiS_Pr->SiS_VBType & VB_UMC) ? 14 : 12;
  9065. /* For LVDS (and sometimes TMDS), the BIOS must know about the correct value */
  9066. delay = ROMAddr[romptr + lcdpdcindex + 1]; /* LCD */
  9067. delay |= (ROMAddr[romptr + lcdpdcindex] << 8); /* LCDA */
  9068. } else {
  9069. /* TMDS: Set our own, since BIOS has no idea */
  9070. /* (This is done on >=661 only, since <661 is calling this only for LVDS) */
  9071. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  9072. switch(SiS_Pr->SiS_LCDResInfo) {
  9073. case Panel_1024x768: delay = 0x0008; break;
  9074. case Panel_1280x720: delay = 0x0004; break;
  9075. case Panel_1280x768:
  9076. case Panel_1280x768_2:delay = 0x0004; break;
  9077. case Panel_1280x800:
  9078. case Panel_1280x800_2:delay = 0x0004; break; /* Verified for 1280x800 */
  9079. case Panel_1280x854: delay = 0x0004; break; /* FIXME */
  9080. case Panel_1280x1024: delay = 0x1e04; break;
  9081. case Panel_1400x1050: delay = 0x0004; break;
  9082. case Panel_1600x1200: delay = 0x0400; break;
  9083. case Panel_1680x1050: delay = 0x0e04; break;
  9084. default:
  9085. if((SiS_Pr->PanelXRes <= 1024) && (SiS_Pr->PanelYRes <= 768)) {
  9086. delay = 0x0008;
  9087. } else if((SiS_Pr->PanelXRes == 1280) && (SiS_Pr->PanelYRes == 1024)) {
  9088. delay = 0x1e04;
  9089. } else if((SiS_Pr->PanelXRes <= 1400) && (SiS_Pr->PanelYRes <= 1050)) {
  9090. delay = 0x0004;
  9091. } else if((SiS_Pr->PanelXRes <= 1600) && (SiS_Pr->PanelYRes <= 1200)) {
  9092. delay = 0x0400;
  9093. } else
  9094. delay = 0x0e04;
  9095. break;
  9096. }
  9097. }
  9098. /* Override by detected or user-set values */
  9099. /* (but only if, for some reason, we can't read value from BIOS) */
  9100. if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && (SiS_Pr->PDC != -1)) {
  9101. delay = SiS_Pr->PDC & 0x1f;
  9102. }
  9103. if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) && (SiS_Pr->PDCA != -1)) {
  9104. delay = (SiS_Pr->PDCA & 0x1f) << 8;
  9105. }
  9106. }
  9107. }
  9108. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  9109. delay >>= 8;
  9110. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0x0f,((delay << 3) & 0xf0));
  9111. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x20,0xbf,((delay & 0x01) << 6));
  9112. } else {
  9113. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0xf0,((delay >> 1) & 0x0f));
  9114. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x35,0x7f,((delay & 0x01) << 7));
  9115. }
  9116. }
  9117. static void
  9118. SetCRT2SyncDither661(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short RTI)
  9119. {
  9120. unsigned short infoflag;
  9121. unsigned char temp;
  9122. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  9123. if(ModeNo <= 0x13) {
  9124. infoflag = SiS_GetRegByte(SiS_Pr->SiS_P3ca+2);
  9125. } else if(SiS_Pr->UseCustomMode) {
  9126. infoflag = SiS_Pr->CInfoFlag;
  9127. } else {
  9128. infoflag = SiS_Pr->SiS_RefIndex[RTI].Ext_InfoFlag;
  9129. }
  9130. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  9131. infoflag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x37); /* No longer check D5 */
  9132. }
  9133. infoflag &= 0xc0;
  9134. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  9135. temp = (infoflag >> 6) | 0x0c;
  9136. if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) {
  9137. temp ^= 0x04;
  9138. if(SiS_Pr->SiS_ModeType >= Mode24Bpp) temp |= 0x10;
  9139. }
  9140. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1a,0xe0,temp);
  9141. } else {
  9142. temp = 0x30;
  9143. if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) temp = 0x20;
  9144. temp |= infoflag;
  9145. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0f,temp);
  9146. temp = 0;
  9147. if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) {
  9148. if(SiS_Pr->SiS_ModeType >= Mode24Bpp) temp |= 0x80;
  9149. }
  9150. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x1a,0x7f,temp);
  9151. }
  9152. }
  9153. }
  9154. static void
  9155. SetPanelParms661(struct SiS_Private *SiS_Pr)
  9156. {
  9157. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  9158. unsigned short romptr, temp1, temp2;
  9159. if(SiS_Pr->SiS_VBType & (VB_SISLVDS | VB_SIS30xC)) {
  9160. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x24,0x0f);
  9161. }
  9162. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  9163. if(SiS_Pr->LVDSHL != -1) {
  9164. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,0xfc,SiS_Pr->LVDSHL);
  9165. }
  9166. }
  9167. if(SiS_Pr->SiS_ROMNew) {
  9168. if((romptr = GetLCDStructPtr661_2(SiS_Pr))) {
  9169. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  9170. temp1 = (ROMAddr[romptr] & 0x03) | 0x0c;
  9171. temp2 = 0xfc;
  9172. if(SiS_Pr->LVDSHL != -1) {
  9173. temp1 &= 0xfc;
  9174. temp2 = 0xf3;
  9175. }
  9176. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,temp2,temp1);
  9177. }
  9178. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  9179. temp1 = (ROMAddr[romptr + 1] & 0x80) >> 1;
  9180. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x0d,0xbf,temp1);
  9181. }
  9182. }
  9183. }
  9184. }
  9185. static void
  9186. SiS_OEM310Setting(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex, unsigned short RRTI)
  9187. {
  9188. if((SiS_Pr->SiS_ROMNew) && (SiS_Pr->SiS_VBType & VB_SISLVDS)) {
  9189. SetDelayComp661(SiS_Pr, ModeNo, ModeIdIndex, RRTI);
  9190. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  9191. SetCRT2SyncDither661(SiS_Pr, ModeNo, RRTI);
  9192. SetPanelParms661(SiS_Pr);
  9193. }
  9194. } else {
  9195. SetDelayComp(SiS_Pr,ModeNo);
  9196. }
  9197. if((SiS_Pr->SiS_VBType & VB_SISVB) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
  9198. SetAntiFlicker(SiS_Pr,ModeNo,ModeIdIndex);
  9199. SetPhaseIncr(SiS_Pr,ModeNo,ModeIdIndex);
  9200. SetYFilter(SiS_Pr,ModeNo,ModeIdIndex);
  9201. if(SiS_Pr->SiS_VBType & VB_SIS301) {
  9202. SetEdgeEnhance(SiS_Pr,ModeNo,ModeIdIndex);
  9203. }
  9204. }
  9205. }
  9206. static void
  9207. SiS_OEM661Setting(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
  9208. unsigned short ModeIdIndex, unsigned short RRTI)
  9209. {
  9210. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  9211. SetDelayComp661(SiS_Pr, ModeNo, ModeIdIndex, RRTI);
  9212. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  9213. SetCRT2SyncDither661(SiS_Pr, ModeNo, RRTI);
  9214. SetPanelParms661(SiS_Pr);
  9215. }
  9216. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  9217. SetPhaseIncr(SiS_Pr, ModeNo, ModeIdIndex);
  9218. SetYFilter(SiS_Pr, ModeNo, ModeIdIndex);
  9219. SetAntiFlicker(SiS_Pr, ModeNo, ModeIdIndex);
  9220. if(SiS_Pr->SiS_VBType & VB_SIS301) {
  9221. SetEdgeEnhance(SiS_Pr, ModeNo, ModeIdIndex);
  9222. }
  9223. }
  9224. }
  9225. }
  9226. /* FinalizeLCD
  9227. * This finalizes some CRT2 registers for the very panel used.
  9228. * If we have a backup if these registers, we use it; otherwise
  9229. * we set the register according to most BIOSes. However, this
  9230. * function looks quite different in every BIOS, so you better
  9231. * pray that we have a backup...
  9232. */
  9233. static void
  9234. SiS_FinalizeLCD(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  9235. {
  9236. unsigned short tempcl,tempch,tempbl,tempbh,tempbx,tempax,temp;
  9237. unsigned short resinfo,modeflag;
  9238. if(!(SiS_Pr->SiS_VBType & VB_SISLVDS)) return;
  9239. if(SiS_Pr->SiS_ROMNew) return;
  9240. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  9241. if(SiS_Pr->LVDSHL != -1) {
  9242. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,0xfc,SiS_Pr->LVDSHL);
  9243. }
  9244. }
  9245. if(SiS_Pr->SiS_LCDResInfo == Panel_Custom) return;
  9246. if(SiS_Pr->UseCustomMode) return;
  9247. switch(SiS_Pr->SiS_CustomT) {
  9248. case CUT_COMPAQ1280:
  9249. case CUT_COMPAQ12802:
  9250. case CUT_CLEVO1400:
  9251. case CUT_CLEVO14002:
  9252. return;
  9253. }
  9254. if(ModeNo <= 0x13) {
  9255. resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
  9256. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  9257. } else {
  9258. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  9259. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  9260. }
  9261. if(IS_SIS650) {
  9262. if(!(SiS_GetReg(SiS_Pr->SiS_P3d4, 0x5f) & 0xf0)) {
  9263. if(SiS_Pr->SiS_CustomT == CUT_CLEVO1024) {
  9264. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1e,0x02);
  9265. } else {
  9266. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1e,0x03);
  9267. }
  9268. }
  9269. }
  9270. if(SiS_Pr->SiS_CustomT == CUT_CLEVO1024) {
  9271. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  9272. /* Maybe all panels? */
  9273. if(SiS_Pr->LVDSHL == -1) {
  9274. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,0xfc,0x01);
  9275. }
  9276. return;
  9277. }
  9278. }
  9279. if(SiS_Pr->SiS_CustomT == CUT_CLEVO10242) {
  9280. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  9281. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  9282. if(SiS_Pr->LVDSHL == -1) {
  9283. /* Maybe all panels? */
  9284. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,0xfc,0x01);
  9285. }
  9286. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  9287. tempch = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4;
  9288. if(tempch == 3) {
  9289. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x02);
  9290. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,0x25);
  9291. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1c,0x00);
  9292. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1d,0x1b);
  9293. }
  9294. }
  9295. return;
  9296. }
  9297. }
  9298. }
  9299. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  9300. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  9301. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  9302. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2a,0x00);
  9303. #ifdef SET_EMI
  9304. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
  9305. #endif
  9306. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x34,0x10);
  9307. }
  9308. } else if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) {
  9309. if(SiS_Pr->LVDSHL == -1) {
  9310. /* Maybe ACER only? */
  9311. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,0xfc,0x01);
  9312. }
  9313. }
  9314. tempch = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4;
  9315. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  9316. if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) {
  9317. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1f,0x76);
  9318. } else if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  9319. if(tempch == 0x03) {
  9320. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x02);
  9321. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,0x25);
  9322. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1c,0x00);
  9323. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1d,0x1b);
  9324. }
  9325. if(SiS_Pr->Backup && (SiS_Pr->Backup_Mode == ModeNo)) {
  9326. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x14,SiS_Pr->Backup_14);
  9327. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x15,SiS_Pr->Backup_15);
  9328. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x16,SiS_Pr->Backup_16);
  9329. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x17,SiS_Pr->Backup_17);
  9330. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,SiS_Pr->Backup_18);
  9331. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x19,SiS_Pr->Backup_19);
  9332. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1a,SiS_Pr->Backup_1a);
  9333. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,SiS_Pr->Backup_1b);
  9334. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1c,SiS_Pr->Backup_1c);
  9335. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1d,SiS_Pr->Backup_1d);
  9336. } else if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) { /* 1.10.8w */
  9337. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x14,0x90);
  9338. if(ModeNo <= 0x13) {
  9339. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x11);
  9340. if((resinfo == 0) || (resinfo == 2)) return;
  9341. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x18);
  9342. if((resinfo == 1) || (resinfo == 3)) return;
  9343. }
  9344. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x02);
  9345. if((ModeNo > 0x13) && (resinfo == SIS_RI_1024x768)) {
  9346. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x02); /* 1.10.7u */
  9347. #if 0
  9348. tempbx = 806; /* 0x326 */ /* other older BIOSes */
  9349. tempbx--;
  9350. temp = tempbx & 0xff;
  9351. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,temp);
  9352. temp = (tempbx >> 8) & 0x03;
  9353. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x1d,0xf8,temp);
  9354. #endif
  9355. }
  9356. } else if(ModeNo <= 0x13) {
  9357. if(ModeNo <= 1) {
  9358. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x70);
  9359. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x19,0xff);
  9360. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,0x48);
  9361. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1d,0x12);
  9362. }
  9363. if(!(modeflag & HalfDCLK)) {
  9364. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x14,0x20);
  9365. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x15,0x1a);
  9366. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x16,0x28);
  9367. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x17,0x00);
  9368. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x4c);
  9369. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x19,0xdc);
  9370. if(ModeNo == 0x12) {
  9371. switch(tempch) {
  9372. case 0:
  9373. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x95);
  9374. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x19,0xdc);
  9375. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1a,0x10);
  9376. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,0x95);
  9377. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1c,0x48);
  9378. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1d,0x12);
  9379. break;
  9380. case 2:
  9381. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x95);
  9382. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,0x48);
  9383. break;
  9384. case 3:
  9385. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,0x95);
  9386. break;
  9387. }
  9388. }
  9389. }
  9390. }
  9391. }
  9392. } else {
  9393. tempcl = tempbh = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x01);
  9394. tempcl &= 0x0f;
  9395. tempbh &= 0x70;
  9396. tempbh >>= 4;
  9397. tempbl = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x04);
  9398. tempbx = (tempbh << 8) | tempbl;
  9399. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  9400. if((resinfo == SIS_RI_1024x768) || (!(SiS_Pr->SiS_LCDInfo & DontExpandLCD))) {
  9401. if(SiS_Pr->SiS_SetFlag & LCDVESATiming) {
  9402. tempbx = 770;
  9403. } else {
  9404. if(tempbx > 770) tempbx = 770;
  9405. if(SiS_Pr->SiS_VGAVDE < 600) {
  9406. tempax = 768 - SiS_Pr->SiS_VGAVDE;
  9407. tempax >>= 4; /* 1.10.7w; 1.10.6s: 3; */
  9408. if(SiS_Pr->SiS_VGAVDE <= 480) tempax >>= 4; /* 1.10.7w; 1.10.6s: < 480; >>=1; */
  9409. tempbx -= tempax;
  9410. }
  9411. }
  9412. } else return;
  9413. }
  9414. temp = tempbx & 0xff;
  9415. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,temp);
  9416. temp = ((tempbx & 0xff00) >> 4) | tempcl;
  9417. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x01,0x80,temp);
  9418. }
  9419. }
  9420. }
  9421. #endif
  9422. /* ================= SiS 300 O.E.M. ================== */
  9423. #ifdef CONFIG_FB_SIS_300
  9424. static void
  9425. SetOEMLCDData2(struct SiS_Private *SiS_Pr, unsigned short ModeNo,unsigned short ModeIdIndex,
  9426. unsigned short RefTabIndex)
  9427. {
  9428. unsigned short crt2crtc=0, modeflag, myindex=0;
  9429. unsigned char temp;
  9430. int i;
  9431. if(ModeNo <= 0x13) {
  9432. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  9433. crt2crtc = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  9434. } else {
  9435. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  9436. crt2crtc = SiS_Pr->SiS_RefIndex[RefTabIndex].Ext_CRT2CRTC;
  9437. }
  9438. crt2crtc &= 0x3f;
  9439. if(SiS_Pr->SiS_CustomT == CUT_BARCO1024) {
  9440. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xdf);
  9441. }
  9442. if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) {
  9443. if(modeflag & HalfDCLK) myindex = 1;
  9444. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  9445. for(i=0; i<7; i++) {
  9446. if(barco_p1[myindex][crt2crtc][i][0]) {
  9447. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,
  9448. barco_p1[myindex][crt2crtc][i][0],
  9449. barco_p1[myindex][crt2crtc][i][2],
  9450. barco_p1[myindex][crt2crtc][i][1]);
  9451. }
  9452. }
  9453. }
  9454. temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00);
  9455. if(temp & 0x80) {
  9456. temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x18);
  9457. temp++;
  9458. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,temp);
  9459. }
  9460. }
  9461. }
  9462. static unsigned short
  9463. GetOEMLCDPtr(struct SiS_Private *SiS_Pr, int Flag)
  9464. {
  9465. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  9466. unsigned short tempbx=0,romptr=0;
  9467. static const unsigned char customtable300[] = {
  9468. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  9469. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
  9470. };
  9471. static const unsigned char customtable630[] = {
  9472. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  9473. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
  9474. };
  9475. if(SiS_Pr->ChipType == SIS_300) {
  9476. tempbx = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) & 0x0f;
  9477. if(SiS_Pr->SiS_VBType & VB_SIS301) tempbx &= 0x07;
  9478. tempbx -= 2;
  9479. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) tempbx += 4;
  9480. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  9481. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx += 3;
  9482. }
  9483. if(SiS_Pr->SiS_UseROM) {
  9484. if(ROMAddr[0x235] & 0x80) {
  9485. tempbx = SiS_Pr->SiS_LCDTypeInfo;
  9486. if(Flag) {
  9487. romptr = SISGETROMW(0x255);
  9488. if(romptr) tempbx = ROMAddr[romptr + SiS_Pr->SiS_LCDTypeInfo];
  9489. else tempbx = customtable300[SiS_Pr->SiS_LCDTypeInfo];
  9490. if(tempbx == 0xFF) return 0xFFFF;
  9491. }
  9492. tempbx <<= 1;
  9493. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) tempbx++;
  9494. }
  9495. }
  9496. } else {
  9497. if(Flag) {
  9498. if(SiS_Pr->SiS_UseROM) {
  9499. romptr = SISGETROMW(0x255);
  9500. if(romptr) tempbx = ROMAddr[romptr + SiS_Pr->SiS_LCDTypeInfo];
  9501. else tempbx = 0xff;
  9502. } else {
  9503. tempbx = customtable630[SiS_Pr->SiS_LCDTypeInfo];
  9504. }
  9505. if(tempbx == 0xFF) return 0xFFFF;
  9506. tempbx <<= 2;
  9507. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) tempbx += 2;
  9508. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++;
  9509. return tempbx;
  9510. }
  9511. tempbx = SiS_Pr->SiS_LCDTypeInfo << 2;
  9512. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) tempbx += 2;
  9513. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++;
  9514. }
  9515. return tempbx;
  9516. }
  9517. static void
  9518. SetOEMLCDDelay(struct SiS_Private *SiS_Pr, unsigned short ModeNo,unsigned short ModeIdIndex)
  9519. {
  9520. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  9521. unsigned short index,temp,romptr=0;
  9522. if(SiS_Pr->SiS_LCDResInfo == Panel_Custom) return;
  9523. if(SiS_Pr->SiS_UseROM) {
  9524. if(!(ROMAddr[0x237] & 0x01)) return;
  9525. if(!(ROMAddr[0x237] & 0x02)) return;
  9526. romptr = SISGETROMW(0x24b);
  9527. }
  9528. /* The Panel Compensation Delay should be set according to tables
  9529. * here. Unfortunately, various BIOS versions don't care about
  9530. * a uniform way using eg. ROM byte 0x220, but use different
  9531. * hard coded delays (0x04, 0x20, 0x18) in SetGroup1().
  9532. * Thus we don't set this if the user selected a custom pdc or if
  9533. * we otherwise detected a valid pdc.
  9534. */
  9535. if(SiS_Pr->PDC != -1) return;
  9536. temp = GetOEMLCDPtr(SiS_Pr, 0);
  9537. if(SiS_Pr->UseCustomMode)
  9538. index = 0;
  9539. else
  9540. index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].VB_LCDDelayIndex;
  9541. if(SiS_Pr->ChipType != SIS_300) {
  9542. if(romptr) {
  9543. romptr += (temp * 2);
  9544. romptr = SISGETROMW(romptr);
  9545. romptr += index;
  9546. temp = ROMAddr[romptr];
  9547. } else {
  9548. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  9549. temp = SiS300_OEMLCDDelay2[temp][index];
  9550. } else {
  9551. temp = SiS300_OEMLCDDelay3[temp][index];
  9552. }
  9553. }
  9554. } else {
  9555. if(SiS_Pr->SiS_UseROM && (ROMAddr[0x235] & 0x80)) {
  9556. if(romptr) {
  9557. romptr += (temp * 2);
  9558. romptr = SISGETROMW(romptr);
  9559. romptr += index;
  9560. temp = ROMAddr[romptr];
  9561. } else {
  9562. temp = SiS300_OEMLCDDelay5[temp][index];
  9563. }
  9564. } else {
  9565. if(SiS_Pr->SiS_UseROM) {
  9566. romptr = ROMAddr[0x249] | (ROMAddr[0x24a] << 8);
  9567. if(romptr) {
  9568. romptr += (temp * 2);
  9569. romptr = SISGETROMW(romptr);
  9570. romptr += index;
  9571. temp = ROMAddr[romptr];
  9572. } else {
  9573. temp = SiS300_OEMLCDDelay4[temp][index];
  9574. }
  9575. } else {
  9576. temp = SiS300_OEMLCDDelay4[temp][index];
  9577. }
  9578. }
  9579. }
  9580. temp &= 0x3c;
  9581. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,~0x3C,temp); /* index 0A D[6:4] */
  9582. }
  9583. static void
  9584. SetOEMLCDData(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  9585. {
  9586. #if 0 /* Unfinished; Data table missing */
  9587. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  9588. unsigned short index,temp;
  9589. if((SiS_Pr->SiS_UseROM) {
  9590. if(!(ROMAddr[0x237] & 0x01)) return;
  9591. if(!(ROMAddr[0x237] & 0x04)) return;
  9592. /* No rom pointer in BIOS header! */
  9593. }
  9594. temp = GetOEMLCDPtr(SiS_Pr, 1);
  9595. if(temp == 0xFFFF) return;
  9596. index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex]._VB_LCDHIndex;
  9597. for(i=0x14, j=0; i<=0x17; i++, j++) {
  9598. SiS_SetReg(SiS_Pr->SiS_Part1Port,i,SiS300_LCDHData[temp][index][j]);
  9599. }
  9600. SiS_SetRegANDOR(SiS_SiS_Part1Port,0x1a, 0xf8, (SiS300_LCDHData[temp][index][j] & 0x07));
  9601. index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex]._VB_LCDVIndex;
  9602. SiS_SetReg(SiS_SiS_Part1Port,0x18, SiS300_LCDVData[temp][index][0]);
  9603. SiS_SetRegANDOR(SiS_SiS_Part1Port,0x19, 0xF0, SiS300_LCDVData[temp][index][1]);
  9604. SiS_SetRegANDOR(SiS_SiS_Part1Port,0x1A, 0xC7, (SiS300_LCDVData[temp][index][2] & 0x38));
  9605. for(i=0x1b, j=3; i<=0x1d; i++, j++) {
  9606. SiS_SetReg(SiS_Pr->SiS_Part1Port,i,SiS300_LCDVData[temp][index][j]);
  9607. }
  9608. #endif
  9609. }
  9610. static unsigned short
  9611. GetOEMTVPtr(struct SiS_Private *SiS_Pr)
  9612. {
  9613. unsigned short index;
  9614. index = 0;
  9615. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) index += 4;
  9616. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  9617. if(SiS_Pr->SiS_VBInfo & SetCRT2ToSCART) index += 2;
  9618. else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) index += 3;
  9619. else if(SiS_Pr->SiS_TVMode & TVSetPAL) index += 1;
  9620. } else {
  9621. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) index += 2;
  9622. if(SiS_Pr->SiS_TVMode & TVSetPAL) index += 1;
  9623. }
  9624. return index;
  9625. }
  9626. static void
  9627. SetOEMTVDelay(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  9628. {
  9629. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  9630. unsigned short index,temp,romptr=0;
  9631. if(SiS_Pr->SiS_UseROM) {
  9632. if(!(ROMAddr[0x238] & 0x01)) return;
  9633. if(!(ROMAddr[0x238] & 0x02)) return;
  9634. romptr = SISGETROMW(0x241);
  9635. }
  9636. temp = GetOEMTVPtr(SiS_Pr);
  9637. index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].VB_TVDelayIndex;
  9638. if(romptr) {
  9639. romptr += (temp * 2);
  9640. romptr = SISGETROMW(romptr);
  9641. romptr += index;
  9642. temp = ROMAddr[romptr];
  9643. } else {
  9644. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  9645. temp = SiS300_OEMTVDelay301[temp][index];
  9646. } else {
  9647. temp = SiS300_OEMTVDelayLVDS[temp][index];
  9648. }
  9649. }
  9650. temp &= 0x3c;
  9651. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,~0x3C,temp);
  9652. }
  9653. static void
  9654. SetOEMAntiFlicker(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  9655. {
  9656. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  9657. unsigned short index,temp,romptr=0;
  9658. if(SiS_Pr->SiS_UseROM) {
  9659. if(!(ROMAddr[0x238] & 0x01)) return;
  9660. if(!(ROMAddr[0x238] & 0x04)) return;
  9661. romptr = SISGETROMW(0x243);
  9662. }
  9663. temp = GetOEMTVPtr(SiS_Pr);
  9664. index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].VB_TVFlickerIndex;
  9665. if(romptr) {
  9666. romptr += (temp * 2);
  9667. romptr = SISGETROMW(romptr);
  9668. romptr += index;
  9669. temp = ROMAddr[romptr];
  9670. } else {
  9671. temp = SiS300_OEMTVFlicker[temp][index];
  9672. }
  9673. temp &= 0x70;
  9674. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x0A,0x8F,temp);
  9675. }
  9676. static void
  9677. SetOEMPhaseIncr(struct SiS_Private *SiS_Pr, unsigned short ModeNo,unsigned short ModeIdIndex)
  9678. {
  9679. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  9680. unsigned short index,i,j,temp,romptr=0;
  9681. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) return;
  9682. if(SiS_Pr->SiS_TVMode & (TVSetNTSC1024 | TVSetNTSCJ | TVSetPALM | TVSetPALN)) return;
  9683. if(SiS_Pr->SiS_UseROM) {
  9684. if(!(ROMAddr[0x238] & 0x01)) return;
  9685. if(!(ROMAddr[0x238] & 0x08)) return;
  9686. romptr = SISGETROMW(0x245);
  9687. }
  9688. temp = GetOEMTVPtr(SiS_Pr);
  9689. index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].VB_TVPhaseIndex;
  9690. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  9691. for(i=0x31, j=0; i<=0x34; i++, j++) {
  9692. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS300_Phase2[temp][index][j]);
  9693. }
  9694. } else {
  9695. if(romptr) {
  9696. romptr += (temp * 2);
  9697. romptr = SISGETROMW(romptr);
  9698. romptr += (index * 4);
  9699. for(i=0x31, j=0; i<=0x34; i++, j++) {
  9700. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,ROMAddr[romptr + j]);
  9701. }
  9702. } else {
  9703. for(i=0x31, j=0; i<=0x34; i++, j++) {
  9704. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS300_Phase1[temp][index][j]);
  9705. }
  9706. }
  9707. }
  9708. }
  9709. static void
  9710. SetOEMYFilter(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  9711. {
  9712. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  9713. unsigned short index,temp,i,j,romptr=0;
  9714. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToSCART | SetCRT2ToHiVision | SetCRT2ToYPbPr525750)) return;
  9715. if(SiS_Pr->SiS_UseROM) {
  9716. if(!(ROMAddr[0x238] & 0x01)) return;
  9717. if(!(ROMAddr[0x238] & 0x10)) return;
  9718. romptr = SISGETROMW(0x247);
  9719. }
  9720. temp = GetOEMTVPtr(SiS_Pr);
  9721. if(SiS_Pr->SiS_TVMode & TVSetPALM) temp = 8;
  9722. else if(SiS_Pr->SiS_TVMode & TVSetPALN) temp = 9;
  9723. /* NTSCJ uses NTSC filters */
  9724. index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].VB_TVYFilterIndex;
  9725. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  9726. for(i=0x35, j=0; i<=0x38; i++, j++) {
  9727. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS300_Filter2[temp][index][j]);
  9728. }
  9729. for(i=0x48; i<=0x4A; i++, j++) {
  9730. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS300_Filter2[temp][index][j]);
  9731. }
  9732. } else {
  9733. if((romptr) && (!(SiS_Pr->SiS_TVMode & (TVSetPALM|TVSetPALN)))) {
  9734. romptr += (temp * 2);
  9735. romptr = SISGETROMW(romptr);
  9736. romptr += (index * 4);
  9737. for(i=0x35, j=0; i<=0x38; i++, j++) {
  9738. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,ROMAddr[romptr + j]);
  9739. }
  9740. } else {
  9741. for(i=0x35, j=0; i<=0x38; i++, j++) {
  9742. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS300_Filter1[temp][index][j]);
  9743. }
  9744. }
  9745. }
  9746. }
  9747. static unsigned short
  9748. SiS_SearchVBModeID(struct SiS_Private *SiS_Pr, unsigned short *ModeNo)
  9749. {
  9750. unsigned short ModeIdIndex;
  9751. unsigned char VGAINFO = SiS_Pr->SiS_VGAINFO;
  9752. if(*ModeNo <= 5) *ModeNo |= 1;
  9753. for(ModeIdIndex=0; ; ModeIdIndex++) {
  9754. if(SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].ModeID == *ModeNo) break;
  9755. if(SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].ModeID == 0xFF) return 0;
  9756. }
  9757. if(*ModeNo != 0x07) {
  9758. if(*ModeNo > 0x03) return ModeIdIndex;
  9759. if(VGAINFO & 0x80) return ModeIdIndex;
  9760. ModeIdIndex++;
  9761. }
  9762. if(VGAINFO & 0x10) ModeIdIndex++; /* 400 lines */
  9763. /* else 350 lines */
  9764. return ModeIdIndex;
  9765. }
  9766. static void
  9767. SiS_OEM300Setting(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  9768. unsigned short RefTableIndex)
  9769. {
  9770. unsigned short OEMModeIdIndex = 0;
  9771. if(!SiS_Pr->UseCustomMode) {
  9772. OEMModeIdIndex = SiS_SearchVBModeID(SiS_Pr,&ModeNo);
  9773. if(!(OEMModeIdIndex)) return;
  9774. }
  9775. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  9776. SetOEMLCDDelay(SiS_Pr, ModeNo, OEMModeIdIndex);
  9777. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  9778. SetOEMLCDData(SiS_Pr, ModeNo, OEMModeIdIndex);
  9779. }
  9780. }
  9781. if(SiS_Pr->UseCustomMode) return;
  9782. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  9783. SetOEMTVDelay(SiS_Pr, ModeNo,OEMModeIdIndex);
  9784. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  9785. SetOEMAntiFlicker(SiS_Pr, ModeNo, OEMModeIdIndex);
  9786. SetOEMPhaseIncr(SiS_Pr, ModeNo, OEMModeIdIndex);
  9787. SetOEMYFilter(SiS_Pr, ModeNo, OEMModeIdIndex);
  9788. }
  9789. }
  9790. }
  9791. #endif