init301.c 334 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065
  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 unsigned short SiS_GetBIOSLCDResInfo(struct SiS_Private *SiS_Pr);
  78. static void SiS_SetCH70xx(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val);
  79. /*********************************************/
  80. /* HELPER: Lock/Unlock CRT2 */
  81. /*********************************************/
  82. void
  83. SiS_UnLockCRT2(struct SiS_Private *SiS_Pr)
  84. {
  85. if(SiS_Pr->ChipType == XGI_20)
  86. return;
  87. else if(SiS_Pr->ChipType >= SIS_315H)
  88. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2f,0x01);
  89. else
  90. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x24,0x01);
  91. }
  92. static
  93. void
  94. SiS_LockCRT2(struct SiS_Private *SiS_Pr)
  95. {
  96. if(SiS_Pr->ChipType == XGI_20)
  97. return;
  98. else if(SiS_Pr->ChipType >= SIS_315H)
  99. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2F,0xFE);
  100. else
  101. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x24,0xFE);
  102. }
  103. /*********************************************/
  104. /* HELPER: Write SR11 */
  105. /*********************************************/
  106. static void
  107. SiS_SetRegSR11ANDOR(struct SiS_Private *SiS_Pr, unsigned short DataAND, unsigned short DataOR)
  108. {
  109. if(SiS_Pr->ChipType >= SIS_661) {
  110. DataAND &= 0x0f;
  111. DataOR &= 0x0f;
  112. }
  113. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x11,DataAND,DataOR);
  114. }
  115. /*********************************************/
  116. /* HELPER: Get Pointer to LCD structure */
  117. /*********************************************/
  118. #ifdef CONFIG_FB_SIS_315
  119. static unsigned char *
  120. GetLCDStructPtr661(struct SiS_Private *SiS_Pr)
  121. {
  122. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  123. unsigned char *myptr = NULL;
  124. unsigned short romindex = 0, reg = 0, idx = 0;
  125. /* Use the BIOS tables only for LVDS panels; TMDS is unreliable
  126. * due to the variaty of panels the BIOS doesn't know about.
  127. * Exception: If the BIOS has better knowledge (such as in case
  128. * of machines with a 301C and a panel that does not support DDC)
  129. * use the BIOS data as well.
  130. */
  131. if((SiS_Pr->SiS_ROMNew) &&
  132. ((SiS_Pr->SiS_VBType & VB_SISLVDS) || (!SiS_Pr->PanelSelfDetected))) {
  133. if(SiS_Pr->ChipType < SIS_661) reg = 0x3c;
  134. else reg = 0x7d;
  135. idx = (SiS_GetReg(SiS_Pr->SiS_P3d4,reg) & 0x1f) * 26;
  136. if(idx < (8*26)) {
  137. myptr = (unsigned char *)&SiS_LCDStruct661[idx];
  138. }
  139. romindex = SISGETROMW(0x100);
  140. if(romindex) {
  141. romindex += idx;
  142. myptr = &ROMAddr[romindex];
  143. }
  144. }
  145. return myptr;
  146. }
  147. static unsigned short
  148. GetLCDStructPtr661_2(struct SiS_Private *SiS_Pr)
  149. {
  150. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  151. unsigned short romptr = 0;
  152. /* Use the BIOS tables only for LVDS panels; TMDS is unreliable
  153. * due to the variaty of panels the BIOS doesn't know about.
  154. * Exception: If the BIOS has better knowledge (such as in case
  155. * of machines with a 301C and a panel that does not support DDC)
  156. * use the BIOS data as well.
  157. */
  158. if((SiS_Pr->SiS_ROMNew) &&
  159. ((SiS_Pr->SiS_VBType & VB_SISLVDS) || (!SiS_Pr->PanelSelfDetected))) {
  160. romptr = SISGETROMW(0x102);
  161. romptr += ((SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4) * SiS_Pr->SiS661LCD2TableSize);
  162. }
  163. return romptr;
  164. }
  165. #endif
  166. /*********************************************/
  167. /* Adjust Rate for CRT2 */
  168. /*********************************************/
  169. static bool
  170. SiS_AdjustCRT2Rate(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  171. unsigned short RRTI, unsigned short *i)
  172. {
  173. unsigned short checkmask=0, modeid, infoflag;
  174. modeid = SiS_Pr->SiS_RefIndex[RRTI + (*i)].ModeID;
  175. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  176. if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) {
  177. checkmask |= SupportRAMDAC2;
  178. if(SiS_Pr->ChipType >= SIS_315H) {
  179. checkmask |= SupportRAMDAC2_135;
  180. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  181. checkmask |= SupportRAMDAC2_162;
  182. if(SiS_Pr->SiS_VBType & VB_SISRAMDAC202) {
  183. checkmask |= SupportRAMDAC2_202;
  184. }
  185. }
  186. }
  187. } else if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  188. checkmask |= SupportLCD;
  189. if(SiS_Pr->ChipType >= SIS_315H) {
  190. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  191. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  192. if(modeid == 0x2e) checkmask |= Support64048060Hz;
  193. }
  194. }
  195. }
  196. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  197. checkmask |= SupportHiVision;
  198. } else if(SiS_Pr->SiS_VBInfo & (SetCRT2ToYPbPr525750|SetCRT2ToAVIDEO|SetCRT2ToSVIDEO|SetCRT2ToSCART)) {
  199. checkmask |= SupportTV;
  200. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  201. checkmask |= SupportTV1024;
  202. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  203. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) {
  204. checkmask |= SupportYPbPr750p;
  205. }
  206. }
  207. }
  208. }
  209. } else { /* LVDS */
  210. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  211. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  212. checkmask |= SupportCHTV;
  213. }
  214. }
  215. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  216. checkmask |= SupportLCD;
  217. }
  218. }
  219. /* Look backwards in table for matching CRT2 mode */
  220. for(; SiS_Pr->SiS_RefIndex[RRTI + (*i)].ModeID == modeid; (*i)--) {
  221. infoflag = SiS_Pr->SiS_RefIndex[RRTI + (*i)].Ext_InfoFlag;
  222. if(infoflag & checkmask) return true;
  223. if((*i) == 0) break;
  224. }
  225. /* Look through the whole mode-section of the table from the beginning
  226. * for a matching CRT2 mode if no mode was found yet.
  227. */
  228. for((*i) = 0; ; (*i)++) {
  229. if(SiS_Pr->SiS_RefIndex[RRTI + (*i)].ModeID != modeid) break;
  230. infoflag = SiS_Pr->SiS_RefIndex[RRTI + (*i)].Ext_InfoFlag;
  231. if(infoflag & checkmask) return true;
  232. }
  233. return false;
  234. }
  235. /*********************************************/
  236. /* Get rate index */
  237. /*********************************************/
  238. unsigned short
  239. SiS_GetRatePtr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  240. {
  241. unsigned short RRTI,i,backup_i;
  242. unsigned short modeflag,index,temp,backupindex;
  243. static const unsigned short LCDRefreshIndex[] = {
  244. 0x00, 0x00, 0x01, 0x01,
  245. 0x01, 0x01, 0x01, 0x01,
  246. 0x01, 0x01, 0x01, 0x01,
  247. 0x01, 0x01, 0x01, 0x01,
  248. 0x00, 0x00, 0x00, 0x00
  249. };
  250. /* Do NOT check for UseCustomMode here, will skrew up FIFO */
  251. if(ModeNo == 0xfe) return 0;
  252. if(ModeNo <= 0x13) {
  253. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  254. } else {
  255. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  256. }
  257. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  258. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  259. if(modeflag & HalfDCLK) return 0;
  260. }
  261. }
  262. if(ModeNo < 0x14) return 0xFFFF;
  263. index = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x33) >> SiS_Pr->SiS_SelectCRT2Rate) & 0x0F;
  264. backupindex = index;
  265. if(index > 0) index--;
  266. if(SiS_Pr->SiS_SetFlag & ProgrammingCRT2) {
  267. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  268. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  269. if(SiS_Pr->SiS_VBType & VB_NoLCD) index = 0;
  270. else if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) index = backupindex = 0;
  271. }
  272. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  273. if(!(SiS_Pr->SiS_VBType & VB_NoLCD)) {
  274. temp = LCDRefreshIndex[SiS_GetBIOSLCDResInfo(SiS_Pr)];
  275. if(index > temp) index = temp;
  276. }
  277. }
  278. } else {
  279. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) index = 0;
  280. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  281. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) index = 0;
  282. }
  283. }
  284. }
  285. RRTI = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].REFindex;
  286. ModeNo = SiS_Pr->SiS_RefIndex[RRTI].ModeID;
  287. if(SiS_Pr->ChipType >= SIS_315H) {
  288. if(!(SiS_Pr->SiS_VBInfo & DriverMode)) {
  289. if( (SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_VESAID == 0x105) ||
  290. (SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_VESAID == 0x107) ) {
  291. if(backupindex <= 1) RRTI++;
  292. }
  293. }
  294. }
  295. i = 0;
  296. do {
  297. if(SiS_Pr->SiS_RefIndex[RRTI + i].ModeID != ModeNo) break;
  298. temp = SiS_Pr->SiS_RefIndex[RRTI + i].Ext_InfoFlag;
  299. temp &= ModeTypeMask;
  300. if(temp < SiS_Pr->SiS_ModeType) break;
  301. i++;
  302. index--;
  303. } while(index != 0xFFFF);
  304. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) {
  305. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  306. temp = SiS_Pr->SiS_RefIndex[RRTI + i - 1].Ext_InfoFlag;
  307. if(temp & InterlaceMode) i++;
  308. }
  309. }
  310. i--;
  311. if((SiS_Pr->SiS_SetFlag & ProgrammingCRT2) && (!(SiS_Pr->SiS_VBInfo & DisableCRT2Display))) {
  312. backup_i = i;
  313. if(!(SiS_AdjustCRT2Rate(SiS_Pr, ModeNo, ModeIdIndex, RRTI, &i))) {
  314. i = backup_i;
  315. }
  316. }
  317. return (RRTI + i);
  318. }
  319. /*********************************************/
  320. /* STORE CRT2 INFO in CR34 */
  321. /*********************************************/
  322. static void
  323. SiS_SaveCRT2Info(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
  324. {
  325. unsigned short temp1, temp2;
  326. /* Store CRT1 ModeNo in CR34 */
  327. SiS_SetReg(SiS_Pr->SiS_P3d4,0x34,ModeNo);
  328. temp1 = (SiS_Pr->SiS_VBInfo & SetInSlaveMode) >> 8;
  329. temp2 = ~(SetInSlaveMode >> 8);
  330. SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x31,temp2,temp1);
  331. }
  332. /*********************************************/
  333. /* HELPER: GET SOME DATA FROM BIOS ROM */
  334. /*********************************************/
  335. #ifdef CONFIG_FB_SIS_300
  336. static bool
  337. SiS_CR36BIOSWord23b(struct SiS_Private *SiS_Pr)
  338. {
  339. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  340. unsigned short temp,temp1;
  341. if(SiS_Pr->SiS_UseROM) {
  342. if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) {
  343. temp = 1 << ((SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4) & 0x0f);
  344. temp1 = SISGETROMW(0x23b);
  345. if(temp1 & temp) return true;
  346. }
  347. }
  348. return false;
  349. }
  350. static bool
  351. SiS_CR36BIOSWord23d(struct SiS_Private *SiS_Pr)
  352. {
  353. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  354. unsigned short temp,temp1;
  355. if(SiS_Pr->SiS_UseROM) {
  356. if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) {
  357. temp = 1 << ((SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4) & 0x0f);
  358. temp1 = SISGETROMW(0x23d);
  359. if(temp1 & temp) return true;
  360. }
  361. }
  362. return false;
  363. }
  364. #endif
  365. /*********************************************/
  366. /* HELPER: DELAY FUNCTIONS */
  367. /*********************************************/
  368. void
  369. SiS_DDC2Delay(struct SiS_Private *SiS_Pr, unsigned int delaytime)
  370. {
  371. while (delaytime-- > 0)
  372. SiS_GetReg(SiS_Pr->SiS_P3c4, 0x05);
  373. }
  374. #if defined(CONFIG_FB_SIS_300) || defined(CONFIG_FB_SIS_315)
  375. static void
  376. SiS_GenericDelay(struct SiS_Private *SiS_Pr, unsigned short delay)
  377. {
  378. SiS_DDC2Delay(SiS_Pr, delay * 36);
  379. }
  380. #endif
  381. #ifdef CONFIG_FB_SIS_315
  382. static void
  383. SiS_LongDelay(struct SiS_Private *SiS_Pr, unsigned short delay)
  384. {
  385. while(delay--) {
  386. SiS_GenericDelay(SiS_Pr, 6623);
  387. }
  388. }
  389. #endif
  390. #if defined(CONFIG_FB_SIS_300) || defined(CONFIG_FB_SIS_315)
  391. static void
  392. SiS_ShortDelay(struct SiS_Private *SiS_Pr, unsigned short delay)
  393. {
  394. while(delay--) {
  395. SiS_GenericDelay(SiS_Pr, 66);
  396. }
  397. }
  398. #endif
  399. static void
  400. SiS_PanelDelay(struct SiS_Private *SiS_Pr, unsigned short DelayTime)
  401. {
  402. #if defined(CONFIG_FB_SIS_300) || defined(CONFIG_FB_SIS_315)
  403. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  404. unsigned short PanelID, DelayIndex, Delay=0;
  405. #endif
  406. if(SiS_Pr->ChipType < SIS_315H) {
  407. #ifdef CONFIG_FB_SIS_300
  408. PanelID = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36);
  409. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  410. if(SiS_Pr->SiS_VBType & VB_SIS301) PanelID &= 0xf7;
  411. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x18) & 0x10)) PanelID = 0x12;
  412. }
  413. DelayIndex = PanelID >> 4;
  414. if((DelayTime >= 2) && ((PanelID & 0x0f) == 1)) {
  415. Delay = 3;
  416. } else {
  417. if(DelayTime >= 2) DelayTime -= 2;
  418. if(!(DelayTime & 0x01)) {
  419. Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[0];
  420. } else {
  421. Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[1];
  422. }
  423. if(SiS_Pr->SiS_UseROM) {
  424. if(ROMAddr[0x220] & 0x40) {
  425. if(!(DelayTime & 0x01)) Delay = (unsigned short)ROMAddr[0x225];
  426. else Delay = (unsigned short)ROMAddr[0x226];
  427. }
  428. }
  429. }
  430. SiS_ShortDelay(SiS_Pr, Delay);
  431. #endif /* CONFIG_FB_SIS_300 */
  432. } else {
  433. #ifdef CONFIG_FB_SIS_315
  434. if((SiS_Pr->ChipType >= SIS_661) ||
  435. (SiS_Pr->ChipType <= SIS_315PRO) ||
  436. (SiS_Pr->ChipType == SIS_330) ||
  437. (SiS_Pr->SiS_ROMNew)) {
  438. if(!(DelayTime & 0x01)) {
  439. SiS_DDC2Delay(SiS_Pr, 0x1000);
  440. } else {
  441. SiS_DDC2Delay(SiS_Pr, 0x4000);
  442. }
  443. } else if((SiS_Pr->SiS_IF_DEF_LVDS == 1) /* ||
  444. (SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) ||
  445. (SiS_Pr->SiS_CustomT == CUT_CLEVO1400) */ ) { /* 315 series, LVDS; Special */
  446. if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
  447. PanelID = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36);
  448. if(SiS_Pr->SiS_CustomT == CUT_CLEVO1400) {
  449. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x1b) & 0x10)) PanelID = 0x12;
  450. }
  451. if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) {
  452. DelayIndex = PanelID & 0x0f;
  453. } else {
  454. DelayIndex = PanelID >> 4;
  455. }
  456. if((DelayTime >= 2) && ((PanelID & 0x0f) == 1)) {
  457. Delay = 3;
  458. } else {
  459. if(DelayTime >= 2) DelayTime -= 2;
  460. if(!(DelayTime & 0x01)) {
  461. Delay = SiS_Pr->SiS_PanelDelayTblLVDS[DelayIndex].timer[0];
  462. } else {
  463. Delay = SiS_Pr->SiS_PanelDelayTblLVDS[DelayIndex].timer[1];
  464. }
  465. if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
  466. if(ROMAddr[0x13c] & 0x40) {
  467. if(!(DelayTime & 0x01)) {
  468. Delay = (unsigned short)ROMAddr[0x17e];
  469. } else {
  470. Delay = (unsigned short)ROMAddr[0x17f];
  471. }
  472. }
  473. }
  474. }
  475. SiS_ShortDelay(SiS_Pr, Delay);
  476. }
  477. } else if(SiS_Pr->SiS_VBType & VB_SISVB) { /* 315 series, all bridges */
  478. DelayIndex = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4;
  479. if(!(DelayTime & 0x01)) {
  480. Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[0];
  481. } else {
  482. Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[1];
  483. }
  484. Delay <<= 8;
  485. SiS_DDC2Delay(SiS_Pr, Delay);
  486. }
  487. #endif /* CONFIG_FB_SIS_315 */
  488. }
  489. }
  490. #ifdef CONFIG_FB_SIS_315
  491. static void
  492. SiS_PanelDelayLoop(struct SiS_Private *SiS_Pr, unsigned short DelayTime, unsigned short DelayLoop)
  493. {
  494. int i;
  495. for(i = 0; i < DelayLoop; i++) {
  496. SiS_PanelDelay(SiS_Pr, DelayTime);
  497. }
  498. }
  499. #endif
  500. /*********************************************/
  501. /* HELPER: WAIT-FOR-RETRACE FUNCTIONS */
  502. /*********************************************/
  503. void
  504. SiS_WaitRetrace1(struct SiS_Private *SiS_Pr)
  505. {
  506. unsigned short watchdog;
  507. if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x1f) & 0xc0) return;
  508. if(!(SiS_GetReg(SiS_Pr->SiS_P3d4,0x17) & 0x80)) return;
  509. watchdog = 65535;
  510. while((SiS_GetRegByte(SiS_Pr->SiS_P3da) & 0x08) && --watchdog);
  511. watchdog = 65535;
  512. while((!(SiS_GetRegByte(SiS_Pr->SiS_P3da) & 0x08)) && --watchdog);
  513. }
  514. #if defined(CONFIG_FB_SIS_300) || defined(CONFIG_FB_SIS_315)
  515. static void
  516. SiS_WaitRetrace2(struct SiS_Private *SiS_Pr, unsigned short reg)
  517. {
  518. unsigned short watchdog;
  519. watchdog = 65535;
  520. while((SiS_GetReg(SiS_Pr->SiS_Part1Port,reg) & 0x02) && --watchdog);
  521. watchdog = 65535;
  522. while((!(SiS_GetReg(SiS_Pr->SiS_Part1Port,reg) & 0x02)) && --watchdog);
  523. }
  524. #endif
  525. static void
  526. SiS_WaitVBRetrace(struct SiS_Private *SiS_Pr)
  527. {
  528. if(SiS_Pr->ChipType < SIS_315H) {
  529. #ifdef CONFIG_FB_SIS_300
  530. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  531. if(!(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x20)) return;
  532. }
  533. if(!(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x80)) {
  534. SiS_WaitRetrace1(SiS_Pr);
  535. } else {
  536. SiS_WaitRetrace2(SiS_Pr, 0x25);
  537. }
  538. #endif
  539. } else {
  540. #ifdef CONFIG_FB_SIS_315
  541. if(!(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x40)) {
  542. SiS_WaitRetrace1(SiS_Pr);
  543. } else {
  544. SiS_WaitRetrace2(SiS_Pr, 0x30);
  545. }
  546. #endif
  547. }
  548. }
  549. static void
  550. SiS_VBWait(struct SiS_Private *SiS_Pr)
  551. {
  552. unsigned short tempal,temp,i,j;
  553. temp = 0;
  554. for(i = 0; i < 3; i++) {
  555. for(j = 0; j < 100; j++) {
  556. tempal = SiS_GetRegByte(SiS_Pr->SiS_P3da);
  557. if(temp & 0x01) {
  558. if((tempal & 0x08)) continue;
  559. else break;
  560. } else {
  561. if(!(tempal & 0x08)) continue;
  562. else break;
  563. }
  564. }
  565. temp ^= 0x01;
  566. }
  567. }
  568. static void
  569. SiS_VBLongWait(struct SiS_Private *SiS_Pr)
  570. {
  571. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  572. SiS_VBWait(SiS_Pr);
  573. } else {
  574. SiS_WaitRetrace1(SiS_Pr);
  575. }
  576. }
  577. /*********************************************/
  578. /* HELPER: MISC */
  579. /*********************************************/
  580. #ifdef CONFIG_FB_SIS_300
  581. static bool
  582. SiS_Is301B(struct SiS_Private *SiS_Pr)
  583. {
  584. if(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x01) >= 0xb0) return true;
  585. return false;
  586. }
  587. #endif
  588. static bool
  589. SiS_CRT2IsLCD(struct SiS_Private *SiS_Pr)
  590. {
  591. if(SiS_Pr->ChipType == SIS_730) {
  592. if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x20) return true;
  593. }
  594. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x30) & 0x20) return true;
  595. return false;
  596. }
  597. bool
  598. SiS_IsDualEdge(struct SiS_Private *SiS_Pr)
  599. {
  600. #ifdef CONFIG_FB_SIS_315
  601. if(SiS_Pr->ChipType >= SIS_315H) {
  602. if((SiS_Pr->ChipType != SIS_650) || (SiS_GetReg(SiS_Pr->SiS_P3d4,0x5f) & 0xf0)) {
  603. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x38) & EnableDualEdge) return true;
  604. }
  605. }
  606. #endif
  607. return false;
  608. }
  609. bool
  610. SiS_IsVAMode(struct SiS_Private *SiS_Pr)
  611. {
  612. #ifdef CONFIG_FB_SIS_315
  613. unsigned short flag;
  614. if(SiS_Pr->ChipType >= SIS_315H) {
  615. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  616. if((flag & EnableDualEdge) && (flag & SetToLCDA)) return true;
  617. }
  618. #endif
  619. return false;
  620. }
  621. #ifdef CONFIG_FB_SIS_315
  622. static bool
  623. SiS_IsVAorLCD(struct SiS_Private *SiS_Pr)
  624. {
  625. if(SiS_IsVAMode(SiS_Pr)) return true;
  626. if(SiS_CRT2IsLCD(SiS_Pr)) return true;
  627. return false;
  628. }
  629. #endif
  630. static bool
  631. SiS_IsDualLink(struct SiS_Private *SiS_Pr)
  632. {
  633. #ifdef CONFIG_FB_SIS_315
  634. if(SiS_Pr->ChipType >= SIS_315H) {
  635. if((SiS_CRT2IsLCD(SiS_Pr)) ||
  636. (SiS_IsVAMode(SiS_Pr))) {
  637. if(SiS_Pr->SiS_LCDInfo & LCDDualLink) return true;
  638. }
  639. }
  640. #endif
  641. return false;
  642. }
  643. #ifdef CONFIG_FB_SIS_315
  644. static bool
  645. SiS_TVEnabled(struct SiS_Private *SiS_Pr)
  646. {
  647. if((SiS_GetReg(SiS_Pr->SiS_Part2Port,0x00) & 0x0f) != 0x0c) return true;
  648. if(SiS_Pr->SiS_VBType & VB_SISYPBPR) {
  649. if(SiS_GetReg(SiS_Pr->SiS_Part2Port,0x4d) & 0x10) return true;
  650. }
  651. return false;
  652. }
  653. #endif
  654. #ifdef CONFIG_FB_SIS_315
  655. static bool
  656. SiS_LCDAEnabled(struct SiS_Private *SiS_Pr)
  657. {
  658. if(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x13) & 0x04) return true;
  659. return false;
  660. }
  661. #endif
  662. #ifdef CONFIG_FB_SIS_315
  663. static bool
  664. SiS_WeHaveBacklightCtrl(struct SiS_Private *SiS_Pr)
  665. {
  666. if((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->ChipType < SIS_661)) {
  667. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x79) & 0x10) return true;
  668. }
  669. return false;
  670. }
  671. #endif
  672. #ifdef CONFIG_FB_SIS_315
  673. static bool
  674. SiS_IsNotM650orLater(struct SiS_Private *SiS_Pr)
  675. {
  676. unsigned short flag;
  677. if(SiS_Pr->ChipType == SIS_650) {
  678. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x5f) & 0xf0;
  679. /* Check for revision != A0 only */
  680. if((flag == 0xe0) || (flag == 0xc0) ||
  681. (flag == 0xb0) || (flag == 0x90)) return false;
  682. } else if(SiS_Pr->ChipType >= SIS_661) return false;
  683. return true;
  684. }
  685. #endif
  686. #ifdef CONFIG_FB_SIS_315
  687. static bool
  688. SiS_IsYPbPr(struct SiS_Private *SiS_Pr)
  689. {
  690. if(SiS_Pr->ChipType >= SIS_315H) {
  691. /* YPrPb = 0x08 */
  692. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x38) & EnableCHYPbPr) return true;
  693. }
  694. return false;
  695. }
  696. #endif
  697. #ifdef CONFIG_FB_SIS_315
  698. static bool
  699. SiS_IsChScart(struct SiS_Private *SiS_Pr)
  700. {
  701. if(SiS_Pr->ChipType >= SIS_315H) {
  702. /* Scart = 0x04 */
  703. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x38) & EnableCHScart) return true;
  704. }
  705. return false;
  706. }
  707. #endif
  708. #ifdef CONFIG_FB_SIS_315
  709. static bool
  710. SiS_IsTVOrYPbPrOrScart(struct SiS_Private *SiS_Pr)
  711. {
  712. unsigned short flag;
  713. if(SiS_Pr->ChipType >= SIS_315H) {
  714. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  715. if(flag & SetCRT2ToTV) return true;
  716. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  717. if(flag & EnableCHYPbPr) return true; /* = YPrPb = 0x08 */
  718. if(flag & EnableCHScart) return true; /* = Scart = 0x04 - TW */
  719. } else {
  720. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  721. if(flag & SetCRT2ToTV) return true;
  722. }
  723. return false;
  724. }
  725. #endif
  726. #ifdef CONFIG_FB_SIS_315
  727. static bool
  728. SiS_IsLCDOrLCDA(struct SiS_Private *SiS_Pr)
  729. {
  730. unsigned short flag;
  731. if(SiS_Pr->ChipType >= SIS_315H) {
  732. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  733. if(flag & SetCRT2ToLCD) return true;
  734. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  735. if(flag & SetToLCDA) return true;
  736. } else {
  737. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  738. if(flag & SetCRT2ToLCD) return true;
  739. }
  740. return false;
  741. }
  742. #endif
  743. static bool
  744. SiS_HaveBridge(struct SiS_Private *SiS_Pr)
  745. {
  746. unsigned short flag;
  747. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  748. return true;
  749. } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
  750. flag = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x00);
  751. if((flag == 1) || (flag == 2)) return true;
  752. }
  753. return false;
  754. }
  755. static bool
  756. SiS_BridgeIsEnabled(struct SiS_Private *SiS_Pr)
  757. {
  758. unsigned short flag;
  759. if(SiS_HaveBridge(SiS_Pr)) {
  760. flag = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00);
  761. if(SiS_Pr->ChipType < SIS_315H) {
  762. flag &= 0xa0;
  763. if((flag == 0x80) || (flag == 0x20)) return true;
  764. } else {
  765. flag &= 0x50;
  766. if((flag == 0x40) || (flag == 0x10)) return true;
  767. }
  768. }
  769. return false;
  770. }
  771. static bool
  772. SiS_BridgeInSlavemode(struct SiS_Private *SiS_Pr)
  773. {
  774. unsigned short flag1;
  775. flag1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x31);
  776. if(flag1 & (SetInSlaveMode >> 8)) return true;
  777. return false;
  778. }
  779. /*********************************************/
  780. /* GET VIDEO BRIDGE CONFIG INFO */
  781. /*********************************************/
  782. /* Setup general purpose IO for Chrontel communication */
  783. #ifdef CONFIG_FB_SIS_300
  784. void
  785. SiS_SetChrontelGPIO(struct SiS_Private *SiS_Pr, unsigned short myvbinfo)
  786. {
  787. unsigned int acpibase;
  788. unsigned short temp;
  789. if(!(SiS_Pr->SiS_ChSW)) return;
  790. acpibase = sisfb_read_lpc_pci_dword(SiS_Pr, 0x74);
  791. acpibase &= 0xFFFF;
  792. if(!acpibase) return;
  793. temp = SiS_GetRegShort((acpibase + 0x3c)); /* ACPI register 0x3c: GP Event 1 I/O mode select */
  794. temp &= 0xFEFF;
  795. SiS_SetRegShort((acpibase + 0x3c), temp);
  796. temp = SiS_GetRegShort((acpibase + 0x3c));
  797. temp = SiS_GetRegShort((acpibase + 0x3a)); /* ACPI register 0x3a: GP Pin Level (low/high) */
  798. temp &= 0xFEFF;
  799. if(!(myvbinfo & SetCRT2ToTV)) temp |= 0x0100;
  800. SiS_SetRegShort((acpibase + 0x3a), temp);
  801. temp = SiS_GetRegShort((acpibase + 0x3a));
  802. }
  803. #endif
  804. void
  805. SiS_GetVBInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
  806. unsigned short ModeIdIndex, int checkcrt2mode)
  807. {
  808. unsigned short tempax, tempbx, temp;
  809. unsigned short modeflag, resinfo = 0;
  810. SiS_Pr->SiS_SetFlag = 0;
  811. modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
  812. SiS_Pr->SiS_ModeType = modeflag & ModeTypeMask;
  813. if((ModeNo > 0x13) && (!SiS_Pr->UseCustomMode)) {
  814. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  815. }
  816. tempbx = 0;
  817. if(SiS_HaveBridge(SiS_Pr)) {
  818. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  819. tempbx |= temp;
  820. tempax = SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) << 8;
  821. tempax &= (DriverMode | LoadDACFlag | SetNotSimuMode | SetPALTV);
  822. tempbx |= tempax;
  823. #ifdef CONFIG_FB_SIS_315
  824. if(SiS_Pr->ChipType >= SIS_315H) {
  825. if(SiS_Pr->SiS_VBType & VB_SISLCDA) {
  826. if(ModeNo == 0x03) {
  827. /* Mode 0x03 is never in driver mode */
  828. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x31,0xbf);
  829. }
  830. if(!(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & (DriverMode >> 8))) {
  831. /* Reset LCDA setting if not driver mode */
  832. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x38,0xfc);
  833. }
  834. if(IS_SIS650) {
  835. if(SiS_Pr->SiS_UseLCDA) {
  836. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x5f) & 0xF0) {
  837. if((ModeNo <= 0x13) || (!(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & (DriverMode >> 8)))) {
  838. SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x38,(EnableDualEdge | SetToLCDA));
  839. }
  840. }
  841. }
  842. }
  843. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  844. if((temp & (EnableDualEdge | SetToLCDA)) == (EnableDualEdge | SetToLCDA)) {
  845. tempbx |= SetCRT2ToLCDA;
  846. }
  847. }
  848. if(SiS_Pr->ChipType >= SIS_661) { /* New CR layout */
  849. tempbx &= ~(SetCRT2ToYPbPr525750 | SetCRT2ToHiVision);
  850. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x38) & 0x04) {
  851. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35) & 0xe0;
  852. if(temp == 0x60) tempbx |= SetCRT2ToHiVision;
  853. else if(SiS_Pr->SiS_VBType & VB_SISYPBPR) {
  854. tempbx |= SetCRT2ToYPbPr525750;
  855. }
  856. }
  857. }
  858. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  859. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  860. if(temp & SetToLCDA) {
  861. tempbx |= SetCRT2ToLCDA;
  862. }
  863. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  864. if(temp & EnableCHYPbPr) {
  865. tempbx |= SetCRT2ToCHYPbPr;
  866. }
  867. }
  868. }
  869. }
  870. #endif /* CONFIG_FB_SIS_315 */
  871. if(!(SiS_Pr->SiS_VBType & VB_SISVGA2)) {
  872. tempbx &= ~(SetCRT2ToRAMDAC);
  873. }
  874. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  875. temp = SetCRT2ToSVIDEO |
  876. SetCRT2ToAVIDEO |
  877. SetCRT2ToSCART |
  878. SetCRT2ToLCDA |
  879. SetCRT2ToLCD |
  880. SetCRT2ToRAMDAC |
  881. SetCRT2ToHiVision |
  882. SetCRT2ToYPbPr525750;
  883. } else {
  884. if(SiS_Pr->ChipType >= SIS_315H) {
  885. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  886. temp = SetCRT2ToAVIDEO |
  887. SetCRT2ToSVIDEO |
  888. SetCRT2ToSCART |
  889. SetCRT2ToLCDA |
  890. SetCRT2ToLCD |
  891. SetCRT2ToCHYPbPr;
  892. } else {
  893. temp = SetCRT2ToLCDA |
  894. SetCRT2ToLCD;
  895. }
  896. } else {
  897. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  898. temp = SetCRT2ToTV | SetCRT2ToLCD;
  899. } else {
  900. temp = SetCRT2ToLCD;
  901. }
  902. }
  903. }
  904. if(!(tempbx & temp)) {
  905. tempax = DisableCRT2Display;
  906. tempbx = 0;
  907. }
  908. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  909. unsigned short clearmask = ( DriverMode |
  910. DisableCRT2Display |
  911. LoadDACFlag |
  912. SetNotSimuMode |
  913. SetInSlaveMode |
  914. SetPALTV |
  915. SwitchCRT2 |
  916. SetSimuScanMode );
  917. if(tempbx & SetCRT2ToLCDA) tempbx &= (clearmask | SetCRT2ToLCDA);
  918. if(tempbx & SetCRT2ToRAMDAC) tempbx &= (clearmask | SetCRT2ToRAMDAC);
  919. if(tempbx & SetCRT2ToLCD) tempbx &= (clearmask | SetCRT2ToLCD);
  920. if(tempbx & SetCRT2ToSCART) tempbx &= (clearmask | SetCRT2ToSCART);
  921. if(tempbx & SetCRT2ToHiVision) tempbx &= (clearmask | SetCRT2ToHiVision);
  922. if(tempbx & SetCRT2ToYPbPr525750) tempbx &= (clearmask | SetCRT2ToYPbPr525750);
  923. } else {
  924. if(SiS_Pr->ChipType >= SIS_315H) {
  925. if(tempbx & SetCRT2ToLCDA) {
  926. tempbx &= (0xFF00|SwitchCRT2|SetSimuScanMode);
  927. }
  928. }
  929. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  930. if(tempbx & SetCRT2ToTV) {
  931. tempbx &= (0xFF00|SetCRT2ToTV|SwitchCRT2|SetSimuScanMode);
  932. }
  933. }
  934. if(tempbx & SetCRT2ToLCD) {
  935. tempbx &= (0xFF00|SetCRT2ToLCD|SwitchCRT2|SetSimuScanMode);
  936. }
  937. if(SiS_Pr->ChipType >= SIS_315H) {
  938. if(tempbx & SetCRT2ToLCDA) {
  939. tempbx |= SetCRT2ToLCD;
  940. }
  941. }
  942. }
  943. if(tempax & DisableCRT2Display) {
  944. if(!(tempbx & (SwitchCRT2 | SetSimuScanMode))) {
  945. tempbx = SetSimuScanMode | DisableCRT2Display;
  946. }
  947. }
  948. if(!(tempbx & DriverMode)) tempbx |= SetSimuScanMode;
  949. /* LVDS/CHRONTEL (LCD/TV) and 301BDH (LCD) can only be slave in 8bpp modes */
  950. if(SiS_Pr->SiS_ModeType <= ModeVGA) {
  951. if( (SiS_Pr->SiS_IF_DEF_LVDS == 1) ||
  952. ((SiS_Pr->SiS_VBType & VB_NoLCD) && (tempbx & SetCRT2ToLCD)) ) {
  953. modeflag &= (~CRT2Mode);
  954. }
  955. }
  956. if(!(tempbx & SetSimuScanMode)) {
  957. if(tempbx & SwitchCRT2) {
  958. if((!(modeflag & CRT2Mode)) && (checkcrt2mode)) {
  959. if(resinfo != SIS_RI_1600x1200) {
  960. tempbx |= SetSimuScanMode;
  961. }
  962. }
  963. } else {
  964. if(SiS_BridgeIsEnabled(SiS_Pr)) {
  965. if(!(tempbx & DriverMode)) {
  966. if(SiS_BridgeInSlavemode(SiS_Pr)) {
  967. tempbx |= SetSimuScanMode;
  968. }
  969. }
  970. }
  971. }
  972. }
  973. if(!(tempbx & DisableCRT2Display)) {
  974. if(tempbx & DriverMode) {
  975. if(tempbx & SetSimuScanMode) {
  976. if((!(modeflag & CRT2Mode)) && (checkcrt2mode)) {
  977. if(resinfo != SIS_RI_1600x1200) {
  978. tempbx |= SetInSlaveMode;
  979. }
  980. }
  981. }
  982. } else {
  983. tempbx |= SetInSlaveMode;
  984. }
  985. }
  986. }
  987. SiS_Pr->SiS_VBInfo = tempbx;
  988. #ifdef CONFIG_FB_SIS_300
  989. if(SiS_Pr->ChipType == SIS_630) {
  990. SiS_SetChrontelGPIO(SiS_Pr, SiS_Pr->SiS_VBInfo);
  991. }
  992. #endif
  993. #if 0
  994. printk(KERN_DEBUG "sisfb: (init301: VBInfo= 0x%04x, SetFlag=0x%04x)\n",
  995. SiS_Pr->SiS_VBInfo, SiS_Pr->SiS_SetFlag);
  996. #endif
  997. }
  998. /*********************************************/
  999. /* DETERMINE YPbPr MODE */
  1000. /*********************************************/
  1001. void
  1002. SiS_SetYPbPr(struct SiS_Private *SiS_Pr)
  1003. {
  1004. unsigned char temp;
  1005. /* Note: This variable is only used on 30xLV systems.
  1006. * CR38 has a different meaning on LVDS/CH7019 systems.
  1007. * On 661 and later, these bits moved to CR35.
  1008. *
  1009. * On 301, 301B, only HiVision 1080i is supported.
  1010. * On 30xLV, 301C, only YPbPr 1080i is supported.
  1011. */
  1012. SiS_Pr->SiS_YPbPr = 0;
  1013. if(SiS_Pr->ChipType >= SIS_661) return;
  1014. if(SiS_Pr->SiS_VBType) {
  1015. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  1016. SiS_Pr->SiS_YPbPr = YPbPrHiVision;
  1017. }
  1018. }
  1019. if(SiS_Pr->ChipType >= SIS_315H) {
  1020. if(SiS_Pr->SiS_VBType & VB_SISYPBPR) {
  1021. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  1022. if(temp & 0x08) {
  1023. switch((temp >> 4)) {
  1024. case 0x00: SiS_Pr->SiS_YPbPr = YPbPr525i; break;
  1025. case 0x01: SiS_Pr->SiS_YPbPr = YPbPr525p; break;
  1026. case 0x02: SiS_Pr->SiS_YPbPr = YPbPr750p; break;
  1027. case 0x03: SiS_Pr->SiS_YPbPr = YPbPrHiVision; break;
  1028. }
  1029. }
  1030. }
  1031. }
  1032. }
  1033. /*********************************************/
  1034. /* DETERMINE TVMode flag */
  1035. /*********************************************/
  1036. void
  1037. SiS_SetTVMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  1038. {
  1039. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  1040. unsigned short temp, temp1, resinfo = 0, romindex = 0;
  1041. unsigned char OutputSelect = *SiS_Pr->pSiS_OutputSelect;
  1042. SiS_Pr->SiS_TVMode = 0;
  1043. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) return;
  1044. if(SiS_Pr->UseCustomMode) return;
  1045. if(ModeNo > 0x13) {
  1046. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  1047. }
  1048. if(SiS_Pr->ChipType < SIS_661) {
  1049. if(SiS_Pr->SiS_VBInfo & SetPALTV) SiS_Pr->SiS_TVMode |= TVSetPAL;
  1050. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  1051. temp = 0;
  1052. if((SiS_Pr->ChipType == SIS_630) ||
  1053. (SiS_Pr->ChipType == SIS_730)) {
  1054. temp = 0x35;
  1055. romindex = 0xfe;
  1056. } else if(SiS_Pr->ChipType >= SIS_315H) {
  1057. temp = 0x38;
  1058. if(SiS_Pr->ChipType < XGI_20) {
  1059. romindex = 0xf3;
  1060. if(SiS_Pr->ChipType >= SIS_330) romindex = 0x11b;
  1061. }
  1062. }
  1063. if(temp) {
  1064. if(romindex && SiS_Pr->SiS_UseROM && (!(SiS_Pr->SiS_ROMNew))) {
  1065. OutputSelect = ROMAddr[romindex];
  1066. if(!(OutputSelect & EnablePALMN)) {
  1067. SiS_SetRegAND(SiS_Pr->SiS_P3d4,temp,0x3F);
  1068. }
  1069. }
  1070. temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,temp);
  1071. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  1072. if(temp1 & EnablePALM) { /* 0x40 */
  1073. SiS_Pr->SiS_TVMode |= TVSetPALM;
  1074. SiS_Pr->SiS_TVMode &= ~TVSetPAL;
  1075. } else if(temp1 & EnablePALN) { /* 0x80 */
  1076. SiS_Pr->SiS_TVMode |= TVSetPALN;
  1077. }
  1078. } else {
  1079. if(temp1 & EnableNTSCJ) { /* 0x40 */
  1080. SiS_Pr->SiS_TVMode |= TVSetNTSCJ;
  1081. }
  1082. }
  1083. }
  1084. /* Translate HiVision/YPbPr to our new flags */
  1085. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  1086. if(SiS_Pr->SiS_YPbPr == YPbPr750p) SiS_Pr->SiS_TVMode |= TVSetYPbPr750p;
  1087. else if(SiS_Pr->SiS_YPbPr == YPbPr525p) SiS_Pr->SiS_TVMode |= TVSetYPbPr525p;
  1088. else if(SiS_Pr->SiS_YPbPr == YPbPrHiVision) SiS_Pr->SiS_TVMode |= TVSetHiVision;
  1089. else SiS_Pr->SiS_TVMode |= TVSetYPbPr525i;
  1090. if(SiS_Pr->SiS_TVMode & (TVSetYPbPr750p | TVSetYPbPr525p | TVSetYPbPr525i)) {
  1091. SiS_Pr->SiS_VBInfo &= ~SetCRT2ToHiVision;
  1092. SiS_Pr->SiS_VBInfo |= SetCRT2ToYPbPr525750;
  1093. } else if(SiS_Pr->SiS_TVMode & TVSetHiVision) {
  1094. SiS_Pr->SiS_TVMode |= TVSetPAL;
  1095. }
  1096. }
  1097. } else if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  1098. if(SiS_Pr->SiS_CHOverScan) {
  1099. if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) {
  1100. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35);
  1101. if((temp & TVOverScan) || (SiS_Pr->SiS_CHOverScan == 1)) {
  1102. SiS_Pr->SiS_TVMode |= TVSetCHOverScan;
  1103. }
  1104. } else if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  1105. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x79);
  1106. if((temp & 0x80) || (SiS_Pr->SiS_CHOverScan == 1)) {
  1107. SiS_Pr->SiS_TVMode |= TVSetCHOverScan;
  1108. }
  1109. }
  1110. if(SiS_Pr->SiS_CHSOverScan) {
  1111. SiS_Pr->SiS_TVMode |= TVSetCHOverScan;
  1112. }
  1113. }
  1114. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  1115. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  1116. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  1117. if(temp & EnablePALM) SiS_Pr->SiS_TVMode |= TVSetPALM;
  1118. else if(temp & EnablePALN) SiS_Pr->SiS_TVMode |= TVSetPALN;
  1119. } else {
  1120. if(temp & EnableNTSCJ) {
  1121. SiS_Pr->SiS_TVMode |= TVSetNTSCJ;
  1122. }
  1123. }
  1124. }
  1125. }
  1126. } else { /* 661 and later */
  1127. temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35);
  1128. if(temp1 & 0x01) {
  1129. SiS_Pr->SiS_TVMode |= TVSetPAL;
  1130. if(temp1 & 0x08) {
  1131. SiS_Pr->SiS_TVMode |= TVSetPALN;
  1132. } else if(temp1 & 0x04) {
  1133. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  1134. SiS_Pr->SiS_TVMode &= ~TVSetPAL;
  1135. }
  1136. SiS_Pr->SiS_TVMode |= TVSetPALM;
  1137. }
  1138. } else {
  1139. if(temp1 & 0x02) {
  1140. SiS_Pr->SiS_TVMode |= TVSetNTSCJ;
  1141. }
  1142. }
  1143. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  1144. if(SiS_Pr->SiS_CHOverScan) {
  1145. if((temp1 & 0x10) || (SiS_Pr->SiS_CHOverScan == 1)) {
  1146. SiS_Pr->SiS_TVMode |= TVSetCHOverScan;
  1147. }
  1148. }
  1149. }
  1150. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  1151. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  1152. temp1 &= 0xe0;
  1153. if(temp1 == 0x00) SiS_Pr->SiS_TVMode |= TVSetYPbPr525i;
  1154. else if(temp1 == 0x20) SiS_Pr->SiS_TVMode |= TVSetYPbPr525p;
  1155. else if(temp1 == 0x40) SiS_Pr->SiS_TVMode |= TVSetYPbPr750p;
  1156. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  1157. SiS_Pr->SiS_TVMode |= (TVSetHiVision | TVSetPAL);
  1158. }
  1159. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToYPbPr525750 | SetCRT2ToHiVision)) {
  1160. if(resinfo == SIS_RI_800x480 || resinfo == SIS_RI_1024x576 || resinfo == SIS_RI_1280x720) {
  1161. SiS_Pr->SiS_TVMode |= TVAspect169;
  1162. } else {
  1163. temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x39);
  1164. if(temp1 & 0x02) {
  1165. if(SiS_Pr->SiS_TVMode & (TVSetYPbPr750p | TVSetHiVision)) {
  1166. SiS_Pr->SiS_TVMode |= TVAspect169;
  1167. } else {
  1168. SiS_Pr->SiS_TVMode |= TVAspect43LB;
  1169. }
  1170. } else {
  1171. SiS_Pr->SiS_TVMode |= TVAspect43;
  1172. }
  1173. }
  1174. }
  1175. }
  1176. }
  1177. if(SiS_Pr->SiS_VBInfo & SetCRT2ToSCART) SiS_Pr->SiS_TVMode |= TVSetPAL;
  1178. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  1179. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  1180. SiS_Pr->SiS_TVMode |= TVSetPAL;
  1181. SiS_Pr->SiS_TVMode &= ~(TVSetPALM | TVSetPALN | TVSetNTSCJ);
  1182. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  1183. if(SiS_Pr->SiS_TVMode & (TVSetYPbPr525i | TVSetYPbPr525p | TVSetYPbPr750p)) {
  1184. SiS_Pr->SiS_TVMode &= ~(TVSetPAL | TVSetNTSCJ | TVSetPALM | TVSetPALN);
  1185. }
  1186. }
  1187. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  1188. if(!(SiS_Pr->SiS_VBInfo & SetNotSimuMode)) {
  1189. SiS_Pr->SiS_TVMode |= TVSetTVSimuMode;
  1190. }
  1191. }
  1192. if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) {
  1193. if(resinfo == SIS_RI_1024x768) {
  1194. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) {
  1195. SiS_Pr->SiS_TVMode |= TVSet525p1024;
  1196. } else if(!(SiS_Pr->SiS_TVMode & (TVSetHiVision | TVSetYPbPr750p))) {
  1197. SiS_Pr->SiS_TVMode |= TVSetNTSC1024;
  1198. }
  1199. }
  1200. }
  1201. SiS_Pr->SiS_TVMode |= TVRPLLDIV2XO;
  1202. if((SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) &&
  1203. (SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  1204. SiS_Pr->SiS_TVMode &= ~TVRPLLDIV2XO;
  1205. } else if(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p)) {
  1206. SiS_Pr->SiS_TVMode &= ~TVRPLLDIV2XO;
  1207. } else if(!(SiS_Pr->SiS_VBType & VB_SIS30xBLV)) {
  1208. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) {
  1209. SiS_Pr->SiS_TVMode &= ~TVRPLLDIV2XO;
  1210. }
  1211. }
  1212. }
  1213. SiS_Pr->SiS_VBInfo &= ~SetPALTV;
  1214. }
  1215. /*********************************************/
  1216. /* GET LCD INFO */
  1217. /*********************************************/
  1218. static unsigned short
  1219. SiS_GetBIOSLCDResInfo(struct SiS_Private *SiS_Pr)
  1220. {
  1221. unsigned short temp = SiS_Pr->SiS_LCDResInfo;
  1222. /* Translate my LCDResInfo to BIOS value */
  1223. switch(temp) {
  1224. case Panel_1280x768_2: temp = Panel_1280x768; break;
  1225. case Panel_1280x800_2: temp = Panel_1280x800; break;
  1226. case Panel_1280x854: temp = Panel661_1280x854; break;
  1227. }
  1228. return temp;
  1229. }
  1230. static void
  1231. SiS_GetLCDInfoBIOS(struct SiS_Private *SiS_Pr)
  1232. {
  1233. #ifdef CONFIG_FB_SIS_315
  1234. unsigned char *ROMAddr;
  1235. unsigned short temp;
  1236. if((ROMAddr = GetLCDStructPtr661(SiS_Pr))) {
  1237. if((temp = SISGETROMW(6)) != SiS_Pr->PanelHT) {
  1238. SiS_Pr->SiS_NeedRomModeData = true;
  1239. SiS_Pr->PanelHT = temp;
  1240. }
  1241. if((temp = SISGETROMW(8)) != SiS_Pr->PanelVT) {
  1242. SiS_Pr->SiS_NeedRomModeData = true;
  1243. SiS_Pr->PanelVT = temp;
  1244. }
  1245. SiS_Pr->PanelHRS = SISGETROMW(10);
  1246. SiS_Pr->PanelHRE = SISGETROMW(12);
  1247. SiS_Pr->PanelVRS = SISGETROMW(14);
  1248. SiS_Pr->PanelVRE = SISGETROMW(16);
  1249. SiS_Pr->PanelVCLKIdx315 = VCLK_CUSTOM_315;
  1250. SiS_Pr->SiS_VCLKData[VCLK_CUSTOM_315].CLOCK =
  1251. SiS_Pr->SiS_VBVCLKData[VCLK_CUSTOM_315].CLOCK = (unsigned short)((unsigned char)ROMAddr[18]);
  1252. SiS_Pr->SiS_VCLKData[VCLK_CUSTOM_315].SR2B =
  1253. SiS_Pr->SiS_VBVCLKData[VCLK_CUSTOM_315].Part4_A = ROMAddr[19];
  1254. SiS_Pr->SiS_VCLKData[VCLK_CUSTOM_315].SR2C =
  1255. SiS_Pr->SiS_VBVCLKData[VCLK_CUSTOM_315].Part4_B = ROMAddr[20];
  1256. }
  1257. #endif
  1258. }
  1259. static void
  1260. SiS_CheckScaling(struct SiS_Private *SiS_Pr, unsigned short resinfo,
  1261. const unsigned char *nonscalingmodes)
  1262. {
  1263. int i = 0;
  1264. while(nonscalingmodes[i] != 0xff) {
  1265. if(nonscalingmodes[i++] == resinfo) {
  1266. if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) ||
  1267. (SiS_Pr->UsePanelScaler == -1)) {
  1268. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1269. }
  1270. break;
  1271. }
  1272. }
  1273. }
  1274. void
  1275. SiS_GetLCDResInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  1276. {
  1277. unsigned short temp,modeflag,resinfo=0,modexres=0,modeyres=0;
  1278. bool panelcanscale = false;
  1279. #ifdef CONFIG_FB_SIS_300
  1280. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  1281. static const unsigned char SiS300SeriesLCDRes[] =
  1282. { 0, 1, 2, 3, 7, 4, 5, 8,
  1283. 0, 0, 10, 0, 0, 0, 0, 15 };
  1284. #endif
  1285. #ifdef CONFIG_FB_SIS_315
  1286. unsigned char *myptr = NULL;
  1287. #endif
  1288. SiS_Pr->SiS_LCDResInfo = 0;
  1289. SiS_Pr->SiS_LCDTypeInfo = 0;
  1290. SiS_Pr->SiS_LCDInfo = 0;
  1291. SiS_Pr->PanelHRS = 999; /* HSync start */
  1292. SiS_Pr->PanelHRE = 999; /* HSync end */
  1293. SiS_Pr->PanelVRS = 999; /* VSync start */
  1294. SiS_Pr->PanelVRE = 999; /* VSync end */
  1295. SiS_Pr->SiS_NeedRomModeData = false;
  1296. /* Alternative 1600x1200@60 timing for 1600x1200 LCDA */
  1297. SiS_Pr->Alternate1600x1200 = false;
  1298. if(!(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA))) return;
  1299. modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
  1300. if((ModeNo > 0x13) && (!SiS_Pr->UseCustomMode)) {
  1301. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  1302. modexres = SiS_Pr->SiS_ModeResInfo[resinfo].HTotal;
  1303. modeyres = SiS_Pr->SiS_ModeResInfo[resinfo].VTotal;
  1304. }
  1305. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36);
  1306. /* For broken BIOSes: Assume 1024x768 */
  1307. if(temp == 0) temp = 0x02;
  1308. if((SiS_Pr->ChipType >= SIS_661) || (SiS_Pr->SiS_ROMNew)) {
  1309. SiS_Pr->SiS_LCDTypeInfo = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x39) & 0x7c) >> 2;
  1310. } else if((SiS_Pr->ChipType < SIS_315H) || (SiS_Pr->ChipType >= SIS_661)) {
  1311. SiS_Pr->SiS_LCDTypeInfo = temp >> 4;
  1312. } else {
  1313. SiS_Pr->SiS_LCDTypeInfo = (temp & 0x0F) - 1;
  1314. }
  1315. temp &= 0x0f;
  1316. #ifdef CONFIG_FB_SIS_300
  1317. if(SiS_Pr->ChipType < SIS_315H) {
  1318. /* Very old BIOSes only know 7 sizes (NetVista 2179, 1.01g) */
  1319. if(SiS_Pr->SiS_VBType & VB_SIS301) {
  1320. if(temp < 0x0f) temp &= 0x07;
  1321. }
  1322. /* Translate 300 series LCDRes to 315 series for unified usage */
  1323. temp = SiS300SeriesLCDRes[temp];
  1324. }
  1325. #endif
  1326. /* Translate to our internal types */
  1327. #ifdef CONFIG_FB_SIS_315
  1328. if(SiS_Pr->ChipType == SIS_550) {
  1329. if (temp == Panel310_1152x768) temp = Panel_320x240_2; /* Verified working */
  1330. else if(temp == Panel310_320x240_2) temp = Panel_320x240_2;
  1331. else if(temp == Panel310_320x240_3) temp = Panel_320x240_3;
  1332. } else if(SiS_Pr->ChipType >= SIS_661) {
  1333. if(temp == Panel661_1280x854) temp = Panel_1280x854;
  1334. }
  1335. #endif
  1336. if(SiS_Pr->SiS_VBType & VB_SISLVDS) { /* SiS LVDS */
  1337. if(temp == Panel310_1280x768) {
  1338. temp = Panel_1280x768_2;
  1339. }
  1340. if(SiS_Pr->SiS_ROMNew) {
  1341. if(temp == Panel661_1280x800) {
  1342. temp = Panel_1280x800_2;
  1343. }
  1344. }
  1345. }
  1346. SiS_Pr->SiS_LCDResInfo = temp;
  1347. #ifdef CONFIG_FB_SIS_300
  1348. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  1349. if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) {
  1350. SiS_Pr->SiS_LCDResInfo = Panel_Barco1366;
  1351. } else if(SiS_Pr->SiS_CustomT == CUT_PANEL848) {
  1352. SiS_Pr->SiS_LCDResInfo = Panel_848x480;
  1353. } else if(SiS_Pr->SiS_CustomT == CUT_PANEL856) {
  1354. SiS_Pr->SiS_LCDResInfo = Panel_856x480;
  1355. }
  1356. }
  1357. #endif
  1358. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  1359. if(SiS_Pr->SiS_LCDResInfo < SiS_Pr->SiS_PanelMin301)
  1360. SiS_Pr->SiS_LCDResInfo = SiS_Pr->SiS_PanelMin301;
  1361. } else {
  1362. if(SiS_Pr->SiS_LCDResInfo < SiS_Pr->SiS_PanelMinLVDS)
  1363. SiS_Pr->SiS_LCDResInfo = SiS_Pr->SiS_PanelMinLVDS;
  1364. }
  1365. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x37);
  1366. SiS_Pr->SiS_LCDInfo = temp & ~0x000e;
  1367. /* Need temp below! */
  1368. /* These must/can't scale no matter what */
  1369. switch(SiS_Pr->SiS_LCDResInfo) {
  1370. case Panel_320x240_1:
  1371. case Panel_320x240_2:
  1372. case Panel_320x240_3:
  1373. case Panel_1280x960:
  1374. SiS_Pr->SiS_LCDInfo &= ~DontExpandLCD;
  1375. break;
  1376. case Panel_640x480:
  1377. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1378. }
  1379. panelcanscale = (bool)(SiS_Pr->SiS_LCDInfo & DontExpandLCD);
  1380. if(!SiS_Pr->UsePanelScaler) SiS_Pr->SiS_LCDInfo &= ~DontExpandLCD;
  1381. else if(SiS_Pr->UsePanelScaler == 1) SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1382. /* Dual link, Pass 1:1 BIOS default, etc. */
  1383. #ifdef CONFIG_FB_SIS_315
  1384. if(SiS_Pr->ChipType >= SIS_661) {
  1385. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  1386. if(temp & 0x08) SiS_Pr->SiS_LCDInfo |= LCDPass11;
  1387. }
  1388. if(SiS_Pr->SiS_VBType & VB_SISDUALLINK) {
  1389. if(SiS_Pr->SiS_ROMNew) {
  1390. if(temp & 0x02) SiS_Pr->SiS_LCDInfo |= LCDDualLink;
  1391. } else if((myptr = GetLCDStructPtr661(SiS_Pr))) {
  1392. if(myptr[2] & 0x01) SiS_Pr->SiS_LCDInfo |= LCDDualLink;
  1393. }
  1394. }
  1395. } else if(SiS_Pr->ChipType >= SIS_315H) {
  1396. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  1397. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x39) & 0x01) SiS_Pr->SiS_LCDInfo |= LCDPass11;
  1398. }
  1399. if((SiS_Pr->SiS_ROMNew) && (!(SiS_Pr->PanelSelfDetected))) {
  1400. SiS_Pr->SiS_LCDInfo &= ~(LCDRGB18Bit);
  1401. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35);
  1402. if(temp & 0x01) SiS_Pr->SiS_LCDInfo |= LCDRGB18Bit;
  1403. if(SiS_Pr->SiS_VBType & VB_SISDUALLINK) {
  1404. if(temp & 0x02) SiS_Pr->SiS_LCDInfo |= LCDDualLink;
  1405. }
  1406. } else if(!(SiS_Pr->SiS_ROMNew)) {
  1407. if(SiS_Pr->SiS_VBType & VB_SISDUALLINK) {
  1408. if((SiS_Pr->SiS_CustomT == CUT_CLEVO1024) &&
  1409. (SiS_Pr->SiS_LCDResInfo == Panel_1024x768)) {
  1410. SiS_Pr->SiS_LCDInfo |= LCDDualLink;
  1411. }
  1412. if((SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) ||
  1413. (SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) ||
  1414. (SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) ||
  1415. (SiS_Pr->SiS_LCDResInfo == Panel_1680x1050)) {
  1416. SiS_Pr->SiS_LCDInfo |= LCDDualLink;
  1417. }
  1418. }
  1419. }
  1420. }
  1421. #endif
  1422. /* Pass 1:1 */
  1423. if((SiS_Pr->SiS_IF_DEF_LVDS == 1) || (SiS_Pr->SiS_VBType & VB_NoLCD)) {
  1424. /* Always center screen on LVDS (if scaling is disabled) */
  1425. SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  1426. } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
  1427. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  1428. /* Always center screen on SiS LVDS (if scaling is disabled) */
  1429. SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  1430. } else {
  1431. /* By default, pass 1:1 on SiS TMDS (if scaling is supported) */
  1432. if(panelcanscale) SiS_Pr->SiS_LCDInfo |= LCDPass11;
  1433. if(SiS_Pr->CenterScreen == 1) SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  1434. }
  1435. }
  1436. SiS_Pr->PanelVCLKIdx300 = VCLK65_300;
  1437. SiS_Pr->PanelVCLKIdx315 = VCLK108_2_315;
  1438. switch(SiS_Pr->SiS_LCDResInfo) {
  1439. case Panel_320x240_1:
  1440. case Panel_320x240_2:
  1441. case Panel_320x240_3: SiS_Pr->PanelXRes = 640; SiS_Pr->PanelYRes = 480;
  1442. SiS_Pr->PanelVRS = 24; SiS_Pr->PanelVRE = 3;
  1443. SiS_Pr->PanelVCLKIdx300 = VCLK28;
  1444. SiS_Pr->PanelVCLKIdx315 = VCLK28;
  1445. break;
  1446. case Panel_640x480: SiS_Pr->PanelXRes = 640; SiS_Pr->PanelYRes = 480;
  1447. SiS_Pr->PanelVRE = 3;
  1448. SiS_Pr->PanelVCLKIdx300 = VCLK28;
  1449. SiS_Pr->PanelVCLKIdx315 = VCLK28;
  1450. break;
  1451. case Panel_800x600: SiS_Pr->PanelXRes = 800; SiS_Pr->PanelYRes = 600;
  1452. SiS_Pr->PanelHT = 1056; SiS_Pr->PanelVT = 628;
  1453. SiS_Pr->PanelHRS = 40; SiS_Pr->PanelHRE = 128;
  1454. SiS_Pr->PanelVRS = 1; SiS_Pr->PanelVRE = 4;
  1455. SiS_Pr->PanelVCLKIdx300 = VCLK40;
  1456. SiS_Pr->PanelVCLKIdx315 = VCLK40;
  1457. break;
  1458. case Panel_1024x600: SiS_Pr->PanelXRes = 1024; SiS_Pr->PanelYRes = 600;
  1459. SiS_Pr->PanelHT = 1344; SiS_Pr->PanelVT = 800;
  1460. SiS_Pr->PanelHRS = 24; SiS_Pr->PanelHRE = 136;
  1461. SiS_Pr->PanelVRS = 2 /* 88 */ ; SiS_Pr->PanelVRE = 6;
  1462. SiS_Pr->PanelVCLKIdx300 = VCLK65_300;
  1463. SiS_Pr->PanelVCLKIdx315 = VCLK65_315;
  1464. break;
  1465. case Panel_1024x768: SiS_Pr->PanelXRes = 1024; SiS_Pr->PanelYRes = 768;
  1466. SiS_Pr->PanelHT = 1344; SiS_Pr->PanelVT = 806;
  1467. SiS_Pr->PanelHRS = 24; SiS_Pr->PanelHRE = 136;
  1468. SiS_Pr->PanelVRS = 3; SiS_Pr->PanelVRE = 6;
  1469. if(SiS_Pr->ChipType < SIS_315H) {
  1470. SiS_Pr->PanelHRS = 23;
  1471. SiS_Pr->PanelVRE = 5;
  1472. }
  1473. SiS_Pr->PanelVCLKIdx300 = VCLK65_300;
  1474. SiS_Pr->PanelVCLKIdx315 = VCLK65_315;
  1475. SiS_GetLCDInfoBIOS(SiS_Pr);
  1476. break;
  1477. case Panel_1152x768: SiS_Pr->PanelXRes = 1152; SiS_Pr->PanelYRes = 768;
  1478. SiS_Pr->PanelHT = 1344; SiS_Pr->PanelVT = 806;
  1479. SiS_Pr->PanelHRS = 24; SiS_Pr->PanelHRE = 136;
  1480. SiS_Pr->PanelVRS = 3; SiS_Pr->PanelVRE = 6;
  1481. if(SiS_Pr->ChipType < SIS_315H) {
  1482. SiS_Pr->PanelHRS = 23;
  1483. SiS_Pr->PanelVRE = 5;
  1484. }
  1485. SiS_Pr->PanelVCLKIdx300 = VCLK65_300;
  1486. SiS_Pr->PanelVCLKIdx315 = VCLK65_315;
  1487. break;
  1488. case Panel_1152x864: SiS_Pr->PanelXRes = 1152; SiS_Pr->PanelYRes = 864;
  1489. break;
  1490. case Panel_1280x720: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 720;
  1491. SiS_Pr->PanelHT = 1650; SiS_Pr->PanelVT = 750;
  1492. SiS_Pr->PanelHRS = 110; SiS_Pr->PanelHRE = 40;
  1493. SiS_Pr->PanelVRS = 5; SiS_Pr->PanelVRE = 5;
  1494. SiS_Pr->PanelVCLKIdx315 = VCLK_1280x720;
  1495. /* Data above for TMDS (projector); get from BIOS for LVDS */
  1496. SiS_GetLCDInfoBIOS(SiS_Pr);
  1497. break;
  1498. case Panel_1280x768: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 768;
  1499. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  1500. SiS_Pr->PanelHT = 1408; SiS_Pr->PanelVT = 806;
  1501. SiS_Pr->PanelVCLKIdx300 = VCLK81_300; /* ? */
  1502. SiS_Pr->PanelVCLKIdx315 = VCLK81_315; /* ? */
  1503. } else {
  1504. SiS_Pr->PanelHT = 1688; SiS_Pr->PanelVT = 802;
  1505. SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 112;
  1506. SiS_Pr->PanelVRS = 3; SiS_Pr->PanelVRE = 6;
  1507. SiS_Pr->PanelVCLKIdx300 = VCLK81_300;
  1508. SiS_Pr->PanelVCLKIdx315 = VCLK81_315;
  1509. }
  1510. break;
  1511. case Panel_1280x768_2: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 768;
  1512. SiS_Pr->PanelHT = 1660; SiS_Pr->PanelVT = 806;
  1513. SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 112;
  1514. SiS_Pr->PanelVRS = 3; SiS_Pr->PanelVRE = 6;
  1515. SiS_Pr->PanelVCLKIdx315 = VCLK_1280x768_2;
  1516. SiS_GetLCDInfoBIOS(SiS_Pr);
  1517. break;
  1518. case Panel_1280x800: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 800;
  1519. SiS_Pr->PanelHT = 1408; SiS_Pr->PanelVT = 816;
  1520. SiS_Pr->PanelHRS = 21; SiS_Pr->PanelHRE = 24;
  1521. SiS_Pr->PanelVRS = 4; SiS_Pr->PanelVRE = 3;
  1522. SiS_Pr->PanelVCLKIdx315 = VCLK_1280x800_315;
  1523. SiS_GetLCDInfoBIOS(SiS_Pr);
  1524. break;
  1525. case Panel_1280x800_2: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 800;
  1526. SiS_Pr->PanelHT = 1552; SiS_Pr->PanelVT = 812;
  1527. SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 112;
  1528. SiS_Pr->PanelVRS = 4; SiS_Pr->PanelVRE = 3;
  1529. SiS_Pr->PanelVCLKIdx315 = VCLK_1280x800_315_2;
  1530. SiS_GetLCDInfoBIOS(SiS_Pr);
  1531. break;
  1532. case Panel_1280x854: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 854;
  1533. SiS_Pr->PanelHT = 1664; SiS_Pr->PanelVT = 861;
  1534. SiS_Pr->PanelHRS = 16; SiS_Pr->PanelHRE = 112;
  1535. SiS_Pr->PanelVRS = 1; SiS_Pr->PanelVRE = 3;
  1536. SiS_Pr->PanelVCLKIdx315 = VCLK_1280x854;
  1537. SiS_GetLCDInfoBIOS(SiS_Pr);
  1538. break;
  1539. case Panel_1280x960: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 960;
  1540. SiS_Pr->PanelHT = 1800; SiS_Pr->PanelVT = 1000;
  1541. SiS_Pr->PanelVCLKIdx300 = VCLK108_3_300;
  1542. SiS_Pr->PanelVCLKIdx315 = VCLK108_3_315;
  1543. if(resinfo == SIS_RI_1280x1024) {
  1544. SiS_Pr->PanelVCLKIdx300 = VCLK100_300;
  1545. SiS_Pr->PanelVCLKIdx315 = VCLK100_315;
  1546. }
  1547. break;
  1548. case Panel_1280x1024: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 1024;
  1549. SiS_Pr->PanelHT = 1688; SiS_Pr->PanelVT = 1066;
  1550. SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 112;
  1551. SiS_Pr->PanelVRS = 1; SiS_Pr->PanelVRE = 3;
  1552. SiS_Pr->PanelVCLKIdx300 = VCLK108_3_300;
  1553. SiS_Pr->PanelVCLKIdx315 = VCLK108_2_315;
  1554. SiS_GetLCDInfoBIOS(SiS_Pr);
  1555. break;
  1556. case Panel_1400x1050: SiS_Pr->PanelXRes = 1400; SiS_Pr->PanelYRes = 1050;
  1557. SiS_Pr->PanelHT = 1688; SiS_Pr->PanelVT = 1066;
  1558. SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 112;
  1559. SiS_Pr->PanelVRS = 1; SiS_Pr->PanelVRE = 3;
  1560. SiS_Pr->PanelVCLKIdx315 = VCLK108_2_315;
  1561. SiS_GetLCDInfoBIOS(SiS_Pr);
  1562. break;
  1563. case Panel_1600x1200: SiS_Pr->PanelXRes = 1600; SiS_Pr->PanelYRes = 1200;
  1564. SiS_Pr->PanelHT = 2160; SiS_Pr->PanelVT = 1250;
  1565. SiS_Pr->PanelHRS = 64; SiS_Pr->PanelHRE = 192;
  1566. SiS_Pr->PanelVRS = 1; SiS_Pr->PanelVRE = 3;
  1567. SiS_Pr->PanelVCLKIdx315 = VCLK162_315;
  1568. if(SiS_Pr->SiS_VBType & VB_SISTMDSLCDA) {
  1569. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  1570. SiS_Pr->PanelHT = 1760; SiS_Pr->PanelVT = 1235;
  1571. SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 32;
  1572. SiS_Pr->PanelVRS = 2; SiS_Pr->PanelVRE = 4;
  1573. SiS_Pr->PanelVCLKIdx315 = VCLK130_315;
  1574. SiS_Pr->Alternate1600x1200 = true;
  1575. }
  1576. } else if(SiS_Pr->SiS_IF_DEF_LVDS) {
  1577. SiS_Pr->PanelHT = 2048; SiS_Pr->PanelVT = 1320;
  1578. SiS_Pr->PanelHRS = SiS_Pr->PanelHRE = 999;
  1579. SiS_Pr->PanelVRS = SiS_Pr->PanelVRE = 999;
  1580. }
  1581. SiS_GetLCDInfoBIOS(SiS_Pr);
  1582. break;
  1583. case Panel_1680x1050: SiS_Pr->PanelXRes = 1680; SiS_Pr->PanelYRes = 1050;
  1584. SiS_Pr->PanelHT = 1900; SiS_Pr->PanelVT = 1066;
  1585. SiS_Pr->PanelHRS = 26; SiS_Pr->PanelHRE = 76;
  1586. SiS_Pr->PanelVRS = 3; SiS_Pr->PanelVRE = 6;
  1587. SiS_Pr->PanelVCLKIdx315 = VCLK121_315;
  1588. SiS_GetLCDInfoBIOS(SiS_Pr);
  1589. break;
  1590. case Panel_Barco1366: SiS_Pr->PanelXRes = 1360; SiS_Pr->PanelYRes = 1024;
  1591. SiS_Pr->PanelHT = 1688; SiS_Pr->PanelVT = 1066;
  1592. break;
  1593. case Panel_848x480: SiS_Pr->PanelXRes = 848; SiS_Pr->PanelYRes = 480;
  1594. SiS_Pr->PanelHT = 1088; SiS_Pr->PanelVT = 525;
  1595. break;
  1596. case Panel_856x480: SiS_Pr->PanelXRes = 856; SiS_Pr->PanelYRes = 480;
  1597. SiS_Pr->PanelHT = 1088; SiS_Pr->PanelVT = 525;
  1598. break;
  1599. case Panel_Custom: SiS_Pr->PanelXRes = SiS_Pr->CP_MaxX;
  1600. SiS_Pr->PanelYRes = SiS_Pr->CP_MaxY;
  1601. SiS_Pr->PanelHT = SiS_Pr->CHTotal;
  1602. SiS_Pr->PanelVT = SiS_Pr->CVTotal;
  1603. if(SiS_Pr->CP_PreferredIndex != -1) {
  1604. SiS_Pr->PanelXRes = SiS_Pr->CP_HDisplay[SiS_Pr->CP_PreferredIndex];
  1605. SiS_Pr->PanelYRes = SiS_Pr->CP_VDisplay[SiS_Pr->CP_PreferredIndex];
  1606. SiS_Pr->PanelHT = SiS_Pr->CP_HTotal[SiS_Pr->CP_PreferredIndex];
  1607. SiS_Pr->PanelVT = SiS_Pr->CP_VTotal[SiS_Pr->CP_PreferredIndex];
  1608. SiS_Pr->PanelHRS = SiS_Pr->CP_HSyncStart[SiS_Pr->CP_PreferredIndex];
  1609. SiS_Pr->PanelHRE = SiS_Pr->CP_HSyncEnd[SiS_Pr->CP_PreferredIndex];
  1610. SiS_Pr->PanelVRS = SiS_Pr->CP_VSyncStart[SiS_Pr->CP_PreferredIndex];
  1611. SiS_Pr->PanelVRE = SiS_Pr->CP_VSyncEnd[SiS_Pr->CP_PreferredIndex];
  1612. SiS_Pr->PanelHRS -= SiS_Pr->PanelXRes;
  1613. SiS_Pr->PanelHRE -= SiS_Pr->PanelHRS;
  1614. SiS_Pr->PanelVRS -= SiS_Pr->PanelYRes;
  1615. SiS_Pr->PanelVRE -= SiS_Pr->PanelVRS;
  1616. if(SiS_Pr->CP_PrefClock) {
  1617. int idx;
  1618. SiS_Pr->PanelVCLKIdx315 = VCLK_CUSTOM_315;
  1619. SiS_Pr->PanelVCLKIdx300 = VCLK_CUSTOM_300;
  1620. if(SiS_Pr->ChipType < SIS_315H) idx = VCLK_CUSTOM_300;
  1621. else idx = VCLK_CUSTOM_315;
  1622. SiS_Pr->SiS_VCLKData[idx].CLOCK =
  1623. SiS_Pr->SiS_VBVCLKData[idx].CLOCK = SiS_Pr->CP_PrefClock;
  1624. SiS_Pr->SiS_VCLKData[idx].SR2B =
  1625. SiS_Pr->SiS_VBVCLKData[idx].Part4_A = SiS_Pr->CP_PrefSR2B;
  1626. SiS_Pr->SiS_VCLKData[idx].SR2C =
  1627. SiS_Pr->SiS_VBVCLKData[idx].Part4_B = SiS_Pr->CP_PrefSR2C;
  1628. }
  1629. }
  1630. break;
  1631. default: SiS_Pr->PanelXRes = 1024; SiS_Pr->PanelYRes = 768;
  1632. SiS_Pr->PanelHT = 1344; SiS_Pr->PanelVT = 806;
  1633. break;
  1634. }
  1635. /* Special cases */
  1636. if( (SiS_Pr->SiS_IF_DEF_FSTN) ||
  1637. (SiS_Pr->SiS_IF_DEF_DSTN) ||
  1638. (SiS_Pr->SiS_CustomT == CUT_BARCO1366) ||
  1639. (SiS_Pr->SiS_CustomT == CUT_BARCO1024) ||
  1640. (SiS_Pr->SiS_CustomT == CUT_PANEL848) ||
  1641. (SiS_Pr->SiS_CustomT == CUT_PANEL856) ) {
  1642. SiS_Pr->PanelHRS = 999;
  1643. SiS_Pr->PanelHRE = 999;
  1644. }
  1645. if( (SiS_Pr->SiS_CustomT == CUT_BARCO1366) ||
  1646. (SiS_Pr->SiS_CustomT == CUT_BARCO1024) ||
  1647. (SiS_Pr->SiS_CustomT == CUT_PANEL848) ||
  1648. (SiS_Pr->SiS_CustomT == CUT_PANEL856) ) {
  1649. SiS_Pr->PanelVRS = 999;
  1650. SiS_Pr->PanelVRE = 999;
  1651. }
  1652. /* DontExpand overrule */
  1653. if((SiS_Pr->SiS_VBType & VB_SISVB) && (!(SiS_Pr->SiS_VBType & VB_NoLCD))) {
  1654. if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && (modeflag & NoSupportLCDScale)) {
  1655. /* No scaling for this mode on any panel (LCD=CRT2)*/
  1656. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1657. }
  1658. switch(SiS_Pr->SiS_LCDResInfo) {
  1659. case Panel_Custom:
  1660. case Panel_1152x864:
  1661. case Panel_1280x768: /* TMDS only */
  1662. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1663. break;
  1664. case Panel_800x600: {
  1665. static const unsigned char nonscalingmodes[] = {
  1666. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, 0xff
  1667. };
  1668. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1669. break;
  1670. }
  1671. case Panel_1024x768: {
  1672. static const unsigned char nonscalingmodes[] = {
  1673. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1674. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1675. 0xff
  1676. };
  1677. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1678. break;
  1679. }
  1680. case Panel_1280x720: {
  1681. static const unsigned char nonscalingmodes[] = {
  1682. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1683. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1684. 0xff
  1685. };
  1686. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1687. if(SiS_Pr->PanelHT == 1650) {
  1688. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1689. }
  1690. break;
  1691. }
  1692. case Panel_1280x768_2: { /* LVDS only */
  1693. static const unsigned char nonscalingmodes[] = {
  1694. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1695. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1696. SIS_RI_1152x768,0xff
  1697. };
  1698. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1699. switch(resinfo) {
  1700. case SIS_RI_1280x720: if(SiS_Pr->UsePanelScaler == -1) {
  1701. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1702. }
  1703. break;
  1704. }
  1705. break;
  1706. }
  1707. case Panel_1280x800: { /* SiS TMDS special (Averatec 6200 series) */
  1708. static const unsigned char nonscalingmodes[] = {
  1709. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1710. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1711. SIS_RI_1152x768,SIS_RI_1280x720,SIS_RI_1280x768,0xff
  1712. };
  1713. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1714. break;
  1715. }
  1716. case Panel_1280x800_2: { /* SiS LVDS */
  1717. static const unsigned char nonscalingmodes[] = {
  1718. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1719. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1720. SIS_RI_1152x768,0xff
  1721. };
  1722. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1723. switch(resinfo) {
  1724. case SIS_RI_1280x720:
  1725. case SIS_RI_1280x768: if(SiS_Pr->UsePanelScaler == -1) {
  1726. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1727. }
  1728. break;
  1729. }
  1730. break;
  1731. }
  1732. case Panel_1280x854: { /* SiS LVDS */
  1733. static const unsigned char nonscalingmodes[] = {
  1734. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1735. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1736. SIS_RI_1152x768,0xff
  1737. };
  1738. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1739. switch(resinfo) {
  1740. case SIS_RI_1280x720:
  1741. case SIS_RI_1280x768:
  1742. case SIS_RI_1280x800: if(SiS_Pr->UsePanelScaler == -1) {
  1743. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1744. }
  1745. break;
  1746. }
  1747. break;
  1748. }
  1749. case Panel_1280x960: {
  1750. static const unsigned char nonscalingmodes[] = {
  1751. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1752. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1753. SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x720,SIS_RI_1280x768,SIS_RI_1280x800,
  1754. SIS_RI_1280x854,0xff
  1755. };
  1756. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1757. break;
  1758. }
  1759. case Panel_1280x1024: {
  1760. static const unsigned char nonscalingmodes[] = {
  1761. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1762. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1763. SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x720,SIS_RI_1280x768,SIS_RI_1280x800,
  1764. SIS_RI_1280x854,SIS_RI_1280x960,0xff
  1765. };
  1766. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1767. break;
  1768. }
  1769. case Panel_1400x1050: {
  1770. static const unsigned char nonscalingmodes[] = {
  1771. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1772. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1773. SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x768,SIS_RI_1280x800,SIS_RI_1280x854,
  1774. SIS_RI_1280x960,0xff
  1775. };
  1776. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1777. switch(resinfo) {
  1778. case SIS_RI_1280x720: if(SiS_Pr->UsePanelScaler == -1) {
  1779. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1780. }
  1781. break;
  1782. case SIS_RI_1280x1024: SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1783. break;
  1784. }
  1785. break;
  1786. }
  1787. case Panel_1600x1200: {
  1788. static const unsigned char nonscalingmodes[] = {
  1789. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1790. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1791. SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x720,SIS_RI_1280x768,SIS_RI_1280x800,
  1792. SIS_RI_1280x854,SIS_RI_1280x960,SIS_RI_1360x768,SIS_RI_1360x1024,0xff
  1793. };
  1794. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1795. break;
  1796. }
  1797. case Panel_1680x1050: {
  1798. static const unsigned char nonscalingmodes[] = {
  1799. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1800. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1801. SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x854,SIS_RI_1280x960,SIS_RI_1360x768,
  1802. SIS_RI_1360x1024,0xff
  1803. };
  1804. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1805. break;
  1806. }
  1807. }
  1808. }
  1809. #ifdef CONFIG_FB_SIS_300
  1810. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  1811. if(SiS_Pr->SiS_CustomT == CUT_PANEL848 || SiS_Pr->SiS_CustomT == CUT_PANEL856) {
  1812. SiS_Pr->SiS_LCDInfo = 0x80 | 0x40 | 0x20; /* neg h/v sync, RGB24(D0 = 0) */
  1813. }
  1814. }
  1815. if(SiS_Pr->ChipType < SIS_315H) {
  1816. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  1817. if(SiS_Pr->SiS_UseROM) {
  1818. if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) {
  1819. if(!(ROMAddr[0x235] & 0x02)) {
  1820. SiS_Pr->SiS_LCDInfo &= (~DontExpandLCD);
  1821. }
  1822. }
  1823. }
  1824. } else if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  1825. if((SiS_Pr->SiS_SetFlag & SetDOSMode) && ((ModeNo == 0x03) || (ModeNo == 0x10))) {
  1826. SiS_Pr->SiS_LCDInfo &= (~DontExpandLCD);
  1827. }
  1828. }
  1829. }
  1830. #endif
  1831. /* Special cases */
  1832. if(modexres == SiS_Pr->PanelXRes && modeyres == SiS_Pr->PanelYRes) {
  1833. SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  1834. }
  1835. if(SiS_Pr->SiS_IF_DEF_TRUMPION) {
  1836. SiS_Pr->SiS_LCDInfo |= (DontExpandLCD | LCDPass11);
  1837. }
  1838. switch(SiS_Pr->SiS_LCDResInfo) {
  1839. case Panel_640x480:
  1840. SiS_Pr->SiS_LCDInfo |= (DontExpandLCD | LCDPass11);
  1841. break;
  1842. case Panel_1280x800:
  1843. /* Don't pass 1:1 by default (TMDS special) */
  1844. if(SiS_Pr->CenterScreen == -1) SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  1845. break;
  1846. case Panel_1280x960:
  1847. SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  1848. break;
  1849. case Panel_Custom:
  1850. if((!SiS_Pr->CP_PrefClock) ||
  1851. (modexres > SiS_Pr->PanelXRes) || (modeyres > SiS_Pr->PanelYRes)) {
  1852. SiS_Pr->SiS_LCDInfo |= LCDPass11;
  1853. }
  1854. break;
  1855. }
  1856. if((SiS_Pr->UseCustomMode) || (SiS_Pr->SiS_CustomT == CUT_UNKNOWNLCD)) {
  1857. SiS_Pr->SiS_LCDInfo |= (DontExpandLCD | LCDPass11);
  1858. }
  1859. /* (In)validate LCDPass11 flag */
  1860. if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
  1861. SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  1862. }
  1863. /* LVDS DDA */
  1864. if(!((SiS_Pr->ChipType < SIS_315H) && (SiS_Pr->SiS_SetFlag & SetDOSMode))) {
  1865. if((SiS_Pr->SiS_IF_DEF_LVDS == 1) || (SiS_Pr->SiS_VBType & VB_NoLCD)) {
  1866. if(SiS_Pr->SiS_IF_DEF_TRUMPION == 0) {
  1867. if(ModeNo == 0x12) {
  1868. if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
  1869. SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
  1870. }
  1871. } else if(ModeNo > 0x13) {
  1872. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x600) {
  1873. if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
  1874. if((resinfo == SIS_RI_800x600) || (resinfo == SIS_RI_400x300)) {
  1875. SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
  1876. }
  1877. }
  1878. }
  1879. }
  1880. }
  1881. }
  1882. if(modeflag & HalfDCLK) {
  1883. if(SiS_Pr->SiS_IF_DEF_TRUMPION == 1) {
  1884. SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
  1885. } else if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  1886. SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
  1887. } else if(SiS_Pr->SiS_LCDResInfo == Panel_640x480) {
  1888. SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
  1889. } else if(ModeNo > 0x13) {
  1890. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  1891. if(resinfo == SIS_RI_512x384) SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
  1892. } else if(SiS_Pr->SiS_LCDResInfo == Panel_800x600) {
  1893. if(resinfo == SIS_RI_400x300) SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
  1894. }
  1895. }
  1896. }
  1897. }
  1898. /* VESA timing */
  1899. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  1900. if(SiS_Pr->SiS_VBInfo & SetNotSimuMode) {
  1901. SiS_Pr->SiS_SetFlag |= LCDVESATiming;
  1902. }
  1903. } else {
  1904. SiS_Pr->SiS_SetFlag |= LCDVESATiming;
  1905. }
  1906. #if 0
  1907. printk(KERN_DEBUG "sisfb: (LCDInfo=0x%04x LCDResInfo=0x%02x LCDTypeInfo=0x%02x)\n",
  1908. SiS_Pr->SiS_LCDInfo, SiS_Pr->SiS_LCDResInfo, SiS_Pr->SiS_LCDTypeInfo);
  1909. #endif
  1910. }
  1911. /*********************************************/
  1912. /* GET VCLK */
  1913. /*********************************************/
  1914. unsigned short
  1915. SiS_GetVCLK2Ptr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  1916. unsigned short RefreshRateTableIndex)
  1917. {
  1918. unsigned short CRT2Index, VCLKIndex = 0, VCLKIndexGEN = 0, VCLKIndexGENCRT = 0;
  1919. unsigned short resinfo, tempbx;
  1920. const unsigned char *CHTVVCLKPtr = NULL;
  1921. if(ModeNo <= 0x13) {
  1922. resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
  1923. CRT2Index = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  1924. VCLKIndexGEN = (SiS_GetRegByte((SiS_Pr->SiS_P3ca+0x02)) >> 2) & 0x03;
  1925. VCLKIndexGENCRT = VCLKIndexGEN;
  1926. } else {
  1927. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  1928. CRT2Index = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  1929. VCLKIndexGEN = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
  1930. VCLKIndexGENCRT = SiS_GetRefCRTVCLK(SiS_Pr, RefreshRateTableIndex,
  1931. (SiS_Pr->SiS_SetFlag & ProgrammingCRT2) ? SiS_Pr->SiS_UseWideCRT2 : SiS_Pr->SiS_UseWide);
  1932. }
  1933. if(SiS_Pr->SiS_VBType & VB_SISVB) { /* 30x/B/LV */
  1934. if(SiS_Pr->SiS_SetFlag & ProgrammingCRT2) {
  1935. CRT2Index >>= 6;
  1936. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { /* LCD */
  1937. if(SiS_Pr->ChipType < SIS_315H) {
  1938. VCLKIndex = SiS_Pr->PanelVCLKIdx300;
  1939. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  1940. VCLKIndex = VCLKIndexGEN;
  1941. }
  1942. } else {
  1943. VCLKIndex = SiS_Pr->PanelVCLKIdx315;
  1944. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  1945. switch(resinfo) {
  1946. /* Correct those whose IndexGEN doesn't match VBVCLK array */
  1947. case SIS_RI_720x480: VCLKIndex = VCLK_720x480; break;
  1948. case SIS_RI_720x576: VCLKIndex = VCLK_720x576; break;
  1949. case SIS_RI_768x576: VCLKIndex = VCLK_768x576; break;
  1950. case SIS_RI_848x480: VCLKIndex = VCLK_848x480; break;
  1951. case SIS_RI_856x480: VCLKIndex = VCLK_856x480; break;
  1952. case SIS_RI_800x480: VCLKIndex = VCLK_800x480; break;
  1953. case SIS_RI_1024x576: VCLKIndex = VCLK_1024x576; break;
  1954. case SIS_RI_1152x864: VCLKIndex = VCLK_1152x864; break;
  1955. case SIS_RI_1280x720: VCLKIndex = VCLK_1280x720; break;
  1956. case SIS_RI_1360x768: VCLKIndex = VCLK_1360x768; break;
  1957. default: VCLKIndex = VCLKIndexGEN;
  1958. }
  1959. if(ModeNo <= 0x13) {
  1960. if(SiS_Pr->ChipType <= SIS_315PRO) {
  1961. if(SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC == 1) VCLKIndex = 0x42;
  1962. } else {
  1963. if(SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC == 1) VCLKIndex = 0x00;
  1964. }
  1965. }
  1966. if(SiS_Pr->ChipType <= SIS_315PRO) {
  1967. if(VCLKIndex == 0) VCLKIndex = 0x41;
  1968. if(VCLKIndex == 1) VCLKIndex = 0x43;
  1969. if(VCLKIndex == 4) VCLKIndex = 0x44;
  1970. }
  1971. }
  1972. }
  1973. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { /* TV */
  1974. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  1975. if(SiS_Pr->SiS_TVMode & TVRPLLDIV2XO) VCLKIndex = HiTVVCLKDIV2;
  1976. else VCLKIndex = HiTVVCLK;
  1977. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) VCLKIndex = HiTVSimuVCLK;
  1978. } else if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) VCLKIndex = YPbPr750pVCLK;
  1979. else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) VCLKIndex = TVVCLKDIV2;
  1980. else if(SiS_Pr->SiS_TVMode & TVRPLLDIV2XO) VCLKIndex = TVVCLKDIV2;
  1981. else VCLKIndex = TVVCLK;
  1982. if(SiS_Pr->ChipType < SIS_315H) VCLKIndex += TVCLKBASE_300;
  1983. else VCLKIndex += TVCLKBASE_315;
  1984. } else { /* VGA2 */
  1985. VCLKIndex = VCLKIndexGENCRT;
  1986. if(SiS_Pr->ChipType < SIS_315H) {
  1987. if(ModeNo > 0x13) {
  1988. if( (SiS_Pr->ChipType == SIS_630) &&
  1989. (SiS_Pr->ChipRevision >= 0x30)) {
  1990. if(VCLKIndex == 0x14) VCLKIndex = 0x34;
  1991. }
  1992. /* Better VGA2 clock for 1280x1024@75 */
  1993. if(VCLKIndex == 0x17) VCLKIndex = 0x45;
  1994. }
  1995. }
  1996. }
  1997. } else { /* If not programming CRT2 */
  1998. VCLKIndex = VCLKIndexGENCRT;
  1999. if(SiS_Pr->ChipType < SIS_315H) {
  2000. if(ModeNo > 0x13) {
  2001. if( (SiS_Pr->ChipType != SIS_630) &&
  2002. (SiS_Pr->ChipType != SIS_300) ) {
  2003. if(VCLKIndex == 0x1b) VCLKIndex = 0x48;
  2004. }
  2005. }
  2006. }
  2007. }
  2008. } else { /* LVDS */
  2009. VCLKIndex = CRT2Index;
  2010. if(SiS_Pr->SiS_SetFlag & ProgrammingCRT2) {
  2011. if( (SiS_Pr->SiS_IF_DEF_CH70xx != 0) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV) ) {
  2012. VCLKIndex &= 0x1f;
  2013. tempbx = 0;
  2014. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx += 1;
  2015. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  2016. tempbx += 2;
  2017. if(SiS_Pr->SiS_ModeType > ModeVGA) {
  2018. if(SiS_Pr->SiS_CHSOverScan) tempbx = 8;
  2019. }
  2020. if(SiS_Pr->SiS_TVMode & TVSetPALM) {
  2021. tempbx = 4;
  2022. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx += 1;
  2023. } else if(SiS_Pr->SiS_TVMode & TVSetPALN) {
  2024. tempbx = 6;
  2025. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx += 1;
  2026. }
  2027. }
  2028. switch(tempbx) {
  2029. case 0: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKUNTSC; break;
  2030. case 1: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKONTSC; break;
  2031. case 2: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKUPAL; break;
  2032. case 3: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKOPAL; break;
  2033. case 4: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKUPALM; break;
  2034. case 5: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKOPALM; break;
  2035. case 6: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKUPALN; break;
  2036. case 7: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKOPALN; break;
  2037. case 8: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKSOPAL; break;
  2038. default: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKOPAL; break;
  2039. }
  2040. VCLKIndex = CHTVVCLKPtr[VCLKIndex];
  2041. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  2042. if(SiS_Pr->ChipType < SIS_315H) {
  2043. VCLKIndex = SiS_Pr->PanelVCLKIdx300;
  2044. } else {
  2045. VCLKIndex = SiS_Pr->PanelVCLKIdx315;
  2046. }
  2047. #ifdef CONFIG_FB_SIS_300
  2048. /* Special Timing: Barco iQ Pro R series */
  2049. if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) VCLKIndex = 0x44;
  2050. /* Special Timing: 848x480 and 856x480 parallel lvds panels */
  2051. if(SiS_Pr->SiS_CustomT == CUT_PANEL848 || SiS_Pr->SiS_CustomT == CUT_PANEL856) {
  2052. if(SiS_Pr->ChipType < SIS_315H) {
  2053. VCLKIndex = VCLK34_300;
  2054. /* if(resinfo == SIS_RI_1360x768) VCLKIndex = ?; */
  2055. } else {
  2056. VCLKIndex = VCLK34_315;
  2057. /* if(resinfo == SIS_RI_1360x768) VCLKIndex = ?; */
  2058. }
  2059. }
  2060. #endif
  2061. } else {
  2062. VCLKIndex = VCLKIndexGENCRT;
  2063. if(SiS_Pr->ChipType < SIS_315H) {
  2064. if(ModeNo > 0x13) {
  2065. if( (SiS_Pr->ChipType == SIS_630) &&
  2066. (SiS_Pr->ChipRevision >= 0x30) ) {
  2067. if(VCLKIndex == 0x14) VCLKIndex = 0x2e;
  2068. }
  2069. }
  2070. }
  2071. }
  2072. } else { /* if not programming CRT2 */
  2073. VCLKIndex = VCLKIndexGENCRT;
  2074. if(SiS_Pr->ChipType < SIS_315H) {
  2075. if(ModeNo > 0x13) {
  2076. if( (SiS_Pr->ChipType != SIS_630) &&
  2077. (SiS_Pr->ChipType != SIS_300) ) {
  2078. if(VCLKIndex == 0x1b) VCLKIndex = 0x48;
  2079. }
  2080. #if 0
  2081. if(SiS_Pr->ChipType == SIS_730) {
  2082. if(VCLKIndex == 0x0b) VCLKIndex = 0x40; /* 1024x768-70 */
  2083. if(VCLKIndex == 0x0d) VCLKIndex = 0x41; /* 1024x768-75 */
  2084. }
  2085. #endif
  2086. }
  2087. }
  2088. }
  2089. }
  2090. return VCLKIndex;
  2091. }
  2092. /*********************************************/
  2093. /* SET CRT2 MODE TYPE REGISTERS */
  2094. /*********************************************/
  2095. static void
  2096. SiS_SetCRT2ModeRegs(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  2097. {
  2098. unsigned short i, j, modeflag, tempah=0;
  2099. short tempcl;
  2100. #if defined(CONFIG_FB_SIS_300) || defined(CONFIG_FB_SIS_315)
  2101. unsigned short tempbl;
  2102. #endif
  2103. #ifdef CONFIG_FB_SIS_315
  2104. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  2105. unsigned short tempah2, tempbl2;
  2106. #endif
  2107. modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
  2108. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  2109. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x00,0xAF,0x40);
  2110. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2E,0xF7);
  2111. } else {
  2112. for(i=0,j=4; i<3; i++,j++) SiS_SetReg(SiS_Pr->SiS_Part1Port,j,0);
  2113. if(SiS_Pr->ChipType >= SIS_315H) {
  2114. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x02,0x7F);
  2115. }
  2116. tempcl = SiS_Pr->SiS_ModeType;
  2117. if(SiS_Pr->ChipType < SIS_315H) {
  2118. #ifdef CONFIG_FB_SIS_300 /* ---- 300 series ---- */
  2119. /* For 301BDH: (with LCD via LVDS) */
  2120. if(SiS_Pr->SiS_VBType & VB_NoLCD) {
  2121. tempbl = SiS_GetReg(SiS_Pr->SiS_P3c4,0x32);
  2122. tempbl &= 0xef;
  2123. tempbl |= 0x02;
  2124. if((SiS_Pr->SiS_VBInfo & SetCRT2ToTV) || (SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) {
  2125. tempbl |= 0x10;
  2126. tempbl &= 0xfd;
  2127. }
  2128. SiS_SetReg(SiS_Pr->SiS_P3c4,0x32,tempbl);
  2129. }
  2130. if(ModeNo > 0x13) {
  2131. tempcl -= ModeVGA;
  2132. if(tempcl >= 0) {
  2133. tempah = ((0x10 >> tempcl) | 0x80);
  2134. }
  2135. } else tempah = 0x80;
  2136. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) tempah ^= 0xA0;
  2137. #endif /* CONFIG_FB_SIS_300 */
  2138. } else {
  2139. #ifdef CONFIG_FB_SIS_315 /* ------- 315/330 series ------ */
  2140. if(ModeNo > 0x13) {
  2141. tempcl -= ModeVGA;
  2142. if(tempcl >= 0) {
  2143. tempah = (0x08 >> tempcl);
  2144. if (tempah == 0) tempah = 1;
  2145. tempah |= 0x40;
  2146. }
  2147. } else tempah = 0x40;
  2148. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) tempah ^= 0x50;
  2149. #endif /* CONFIG_FB_SIS_315 */
  2150. }
  2151. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 0;
  2152. if(SiS_Pr->ChipType < SIS_315H) {
  2153. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,tempah);
  2154. } else {
  2155. #ifdef CONFIG_FB_SIS_315
  2156. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  2157. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x00,0xa0,tempah);
  2158. } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
  2159. if(IS_SIS740) {
  2160. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,tempah);
  2161. } else {
  2162. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x00,0xa0,tempah);
  2163. }
  2164. }
  2165. #endif
  2166. }
  2167. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  2168. tempah = 0x01;
  2169. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  2170. tempah |= 0x02;
  2171. }
  2172. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) {
  2173. tempah ^= 0x05;
  2174. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) {
  2175. tempah ^= 0x01;
  2176. }
  2177. }
  2178. if(SiS_Pr->ChipType < SIS_315H) {
  2179. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 0;
  2180. tempah = (tempah << 5) & 0xFF;
  2181. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x01,tempah);
  2182. tempah = (tempah >> 5) & 0xFF;
  2183. } else {
  2184. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 0x08;
  2185. else if(!(SiS_IsDualEdge(SiS_Pr))) tempah |= 0x08;
  2186. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2E,0xF0,tempah);
  2187. tempah &= ~0x08;
  2188. }
  2189. if((SiS_Pr->SiS_ModeType == ModeVGA) && (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode))) {
  2190. tempah |= 0x10;
  2191. }
  2192. tempah |= 0x80;
  2193. if(SiS_Pr->SiS_VBType & VB_SIS301) {
  2194. if(SiS_Pr->PanelXRes < 1280 && SiS_Pr->PanelYRes < 960) tempah &= ~0x80;
  2195. }
  2196. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  2197. if(!(SiS_Pr->SiS_TVMode & (TVSetYPbPr750p | TVSetYPbPr525p))) {
  2198. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  2199. tempah |= 0x20;
  2200. }
  2201. }
  2202. }
  2203. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x0D,0x40,tempah);
  2204. tempah = 0x80;
  2205. if(SiS_Pr->SiS_VBType & VB_SIS301) {
  2206. if(SiS_Pr->PanelXRes < 1280 && SiS_Pr->PanelYRes < 960) tempah = 0;
  2207. }
  2208. if(SiS_IsDualLink(SiS_Pr)) tempah |= 0x40;
  2209. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  2210. if(SiS_Pr->SiS_TVMode & TVRPLLDIV2XO) {
  2211. tempah |= 0x40;
  2212. }
  2213. }
  2214. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0C,tempah);
  2215. } else { /* LVDS */
  2216. if(SiS_Pr->ChipType >= SIS_315H) {
  2217. #ifdef CONFIG_FB_SIS_315
  2218. /* LVDS can only be slave in 8bpp modes */
  2219. tempah = 0x80;
  2220. if((modeflag & CRT2Mode) && (SiS_Pr->SiS_ModeType > ModeVGA)) {
  2221. if(SiS_Pr->SiS_VBInfo & DriverMode) {
  2222. tempah |= 0x02;
  2223. }
  2224. }
  2225. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) tempah |= 0x02;
  2226. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) tempah ^= 0x01;
  2227. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 1;
  2228. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2e,0xF0,tempah);
  2229. #endif
  2230. } else {
  2231. #ifdef CONFIG_FB_SIS_300
  2232. tempah = 0;
  2233. if( (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) && (SiS_Pr->SiS_ModeType > ModeVGA) ) {
  2234. tempah |= 0x02;
  2235. }
  2236. tempah <<= 5;
  2237. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 0;
  2238. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x01,tempah);
  2239. #endif
  2240. }
  2241. }
  2242. } /* LCDA */
  2243. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  2244. if(SiS_Pr->ChipType >= SIS_315H) {
  2245. #ifdef CONFIG_FB_SIS_315
  2246. /* unsigned char bridgerev = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x01); */
  2247. /* The following is nearly unpreditable and varies from machine
  2248. * to machine. Especially the 301DH seems to be a real trouble
  2249. * maker. Some BIOSes simply set the registers (like in the
  2250. * NoLCD-if-statements here), some set them according to the
  2251. * LCDA stuff. It is very likely that some machines are not
  2252. * treated correctly in the following, very case-orientated
  2253. * code. What do I do then...?
  2254. */
  2255. /* 740 variants match for 30xB, 301B-DH, 30xLV */
  2256. if(!(IS_SIS740)) {
  2257. tempah = 0x04; /* For all bridges */
  2258. tempbl = 0xfb;
  2259. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  2260. tempah = 0x00;
  2261. if(SiS_IsDualEdge(SiS_Pr)) {
  2262. tempbl = 0xff;
  2263. }
  2264. }
  2265. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,tempbl,tempah);
  2266. }
  2267. /* The following two are responsible for eventually wrong colors
  2268. * in TV output. The DH (VB_NoLCD) conditions are unknown; the
  2269. * b0 was found in some 651 machine (Pim; P4_23=0xe5); the b1 version
  2270. * in a 650 box (Jake). What is the criteria?
  2271. * Addendum: Another combination 651+301B-DH(b1) (Rapo) needs same
  2272. * treatment like the 651+301B-DH(b0) case. Seems more to be the
  2273. * chipset than the bridge revision.
  2274. */
  2275. if((IS_SIS740) || (SiS_Pr->ChipType >= SIS_661) || (SiS_Pr->SiS_ROMNew)) {
  2276. tempah = 0x30;
  2277. tempbl = 0xc0;
  2278. if((SiS_Pr->SiS_VBInfo & DisableCRT2Display) ||
  2279. ((SiS_Pr->SiS_ROMNew) && (!(ROMAddr[0x5b] & 0x04)))) {
  2280. tempah = 0x00;
  2281. tempbl = 0x00;
  2282. }
  2283. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2c,0xcf,tempah);
  2284. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x21,0x3f,tempbl);
  2285. } else if(SiS_Pr->SiS_VBType & VB_SIS301) {
  2286. /* Fixes "TV-blue-bug" on 315+301 */
  2287. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2c,0xcf); /* For 301 */
  2288. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x21,0x3f);
  2289. } else if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  2290. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2c,0x30); /* For 30xLV */
  2291. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x21,0xc0);
  2292. } else if(SiS_Pr->SiS_VBType & VB_NoLCD) { /* For 301B-DH */
  2293. tempah = 0x30; tempah2 = 0xc0;
  2294. tempbl = 0xcf; tempbl2 = 0x3f;
  2295. if(SiS_Pr->SiS_TVBlue == 0) {
  2296. tempah = tempah2 = 0x00;
  2297. } else if(SiS_Pr->SiS_TVBlue == -1) {
  2298. /* Set on 651/M650, clear on 315/650 */
  2299. if(!(IS_SIS65x)) /* (bridgerev != 0xb0) */ {
  2300. tempah = tempah2 = 0x00;
  2301. }
  2302. }
  2303. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2c,tempbl,tempah);
  2304. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x21,tempbl2,tempah2);
  2305. } else {
  2306. tempah = 0x30; tempah2 = 0xc0; /* For 30xB, 301C */
  2307. tempbl = 0xcf; tempbl2 = 0x3f;
  2308. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  2309. tempah = tempah2 = 0x00;
  2310. if(SiS_IsDualEdge(SiS_Pr)) {
  2311. tempbl = tempbl2 = 0xff;
  2312. }
  2313. }
  2314. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2c,tempbl,tempah);
  2315. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x21,tempbl2,tempah2);
  2316. }
  2317. if(IS_SIS740) {
  2318. tempah = 0x80;
  2319. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 0x00;
  2320. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x23,0x7f,tempah);
  2321. } else {
  2322. tempah = 0x00;
  2323. tempbl = 0x7f;
  2324. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  2325. tempbl = 0xff;
  2326. if(!(SiS_IsDualEdge(SiS_Pr))) tempah = 0x80;
  2327. }
  2328. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x23,tempbl,tempah);
  2329. }
  2330. #endif /* CONFIG_FB_SIS_315 */
  2331. } else if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  2332. #ifdef CONFIG_FB_SIS_300
  2333. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x21,0x3f);
  2334. if((SiS_Pr->SiS_VBInfo & DisableCRT2Display) ||
  2335. ((SiS_Pr->SiS_VBType & VB_NoLCD) &&
  2336. (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD))) {
  2337. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x23,0x7F);
  2338. } else {
  2339. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x23,0x80);
  2340. }
  2341. #endif
  2342. }
  2343. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  2344. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x0D,0x80);
  2345. if(SiS_Pr->SiS_VBType & VB_SIS30xCLV) {
  2346. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x3A,0xC0);
  2347. }
  2348. }
  2349. } else { /* LVDS */
  2350. #ifdef CONFIG_FB_SIS_315
  2351. if(SiS_Pr->ChipType >= SIS_315H) {
  2352. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  2353. tempah = 0x04;
  2354. tempbl = 0xfb;
  2355. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  2356. tempah = 0x00;
  2357. if(SiS_IsDualEdge(SiS_Pr)) tempbl = 0xff;
  2358. }
  2359. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,tempbl,tempah);
  2360. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) {
  2361. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xfb);
  2362. }
  2363. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2c,0x30);
  2364. } else if(SiS_Pr->ChipType == SIS_550) {
  2365. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xfb);
  2366. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2c,0x30);
  2367. }
  2368. }
  2369. #endif
  2370. }
  2371. }
  2372. /*********************************************/
  2373. /* GET RESOLUTION DATA */
  2374. /*********************************************/
  2375. unsigned short
  2376. SiS_GetResInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  2377. {
  2378. if(ModeNo <= 0x13)
  2379. return ((unsigned short)SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo);
  2380. else
  2381. return ((unsigned short)SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO);
  2382. }
  2383. static void
  2384. SiS_GetCRT2ResInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  2385. {
  2386. unsigned short xres, yres, modeflag=0, resindex;
  2387. if(SiS_Pr->UseCustomMode) {
  2388. xres = SiS_Pr->CHDisplay;
  2389. if(SiS_Pr->CModeFlag & HalfDCLK) xres <<= 1;
  2390. SiS_Pr->SiS_VGAHDE = SiS_Pr->SiS_HDE = xres;
  2391. /* DoubleScanMode-check done in CheckCalcCustomMode()! */
  2392. SiS_Pr->SiS_VGAVDE = SiS_Pr->SiS_VDE = SiS_Pr->CVDisplay;
  2393. return;
  2394. }
  2395. resindex = SiS_GetResInfo(SiS_Pr,ModeNo,ModeIdIndex);
  2396. if(ModeNo <= 0x13) {
  2397. xres = SiS_Pr->SiS_StResInfo[resindex].HTotal;
  2398. yres = SiS_Pr->SiS_StResInfo[resindex].VTotal;
  2399. } else {
  2400. xres = SiS_Pr->SiS_ModeResInfo[resindex].HTotal;
  2401. yres = SiS_Pr->SiS_ModeResInfo[resindex].VTotal;
  2402. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  2403. }
  2404. if(!SiS_Pr->SiS_IF_DEF_DSTN && !SiS_Pr->SiS_IF_DEF_FSTN) {
  2405. if((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->SiS_IF_DEF_LVDS == 1)) {
  2406. if((ModeNo != 0x03) && (SiS_Pr->SiS_SetFlag & SetDOSMode)) {
  2407. if(yres == 350) yres = 400;
  2408. }
  2409. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x3a) & 0x01) {
  2410. if(ModeNo == 0x12) yres = 400;
  2411. }
  2412. }
  2413. if(modeflag & HalfDCLK) xres <<= 1;
  2414. if(modeflag & DoubleScanMode) yres <<= 1;
  2415. }
  2416. if((SiS_Pr->SiS_VBType & VB_SISVB) && (!(SiS_Pr->SiS_VBType & VB_NoLCD))) {
  2417. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  2418. switch(SiS_Pr->SiS_LCDResInfo) {
  2419. case Panel_1024x768:
  2420. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
  2421. if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
  2422. if(yres == 350) yres = 357;
  2423. if(yres == 400) yres = 420;
  2424. if(yres == 480) yres = 525;
  2425. }
  2426. }
  2427. break;
  2428. case Panel_1280x1024:
  2429. if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
  2430. /* BIOS bug - does this regardless of scaling */
  2431. if(yres == 400) yres = 405;
  2432. }
  2433. if(yres == 350) yres = 360;
  2434. if(SiS_Pr->SiS_SetFlag & LCDVESATiming) {
  2435. if(yres == 360) yres = 375;
  2436. }
  2437. break;
  2438. case Panel_1600x1200:
  2439. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
  2440. if(yres == 1024) yres = 1056;
  2441. }
  2442. break;
  2443. }
  2444. }
  2445. } else {
  2446. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  2447. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToHiVision)) {
  2448. if(xres == 720) xres = 640;
  2449. }
  2450. } else if(xres == 720) xres = 640;
  2451. if(SiS_Pr->SiS_SetFlag & SetDOSMode) {
  2452. yres = 400;
  2453. if(SiS_Pr->ChipType >= SIS_315H) {
  2454. if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x17) & 0x80) yres = 480;
  2455. } else {
  2456. if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x80) yres = 480;
  2457. }
  2458. if(SiS_Pr->SiS_IF_DEF_DSTN || SiS_Pr->SiS_IF_DEF_FSTN) yres = 480;
  2459. }
  2460. }
  2461. SiS_Pr->SiS_VGAHDE = SiS_Pr->SiS_HDE = xres;
  2462. SiS_Pr->SiS_VGAVDE = SiS_Pr->SiS_VDE = yres;
  2463. }
  2464. /*********************************************/
  2465. /* GET CRT2 TIMING DATA */
  2466. /*********************************************/
  2467. static void
  2468. SiS_GetCRT2Ptr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  2469. unsigned short RefreshRateTableIndex, unsigned short *CRT2Index,
  2470. unsigned short *ResIndex)
  2471. {
  2472. unsigned short tempbx=0, tempal=0, resinfo=0;
  2473. if(ModeNo <= 0x13) {
  2474. tempal = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  2475. } else {
  2476. tempal = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  2477. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  2478. }
  2479. if((SiS_Pr->SiS_VBType & VB_SISVB) && (SiS_Pr->SiS_IF_DEF_LVDS == 0)) {
  2480. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { /* LCD */
  2481. tempbx = SiS_Pr->SiS_LCDResInfo;
  2482. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) tempbx += 32;
  2483. /* patch index */
  2484. if(SiS_Pr->SiS_LCDResInfo == Panel_1680x1050) {
  2485. if (resinfo == SIS_RI_1280x800) tempal = 9;
  2486. else if(resinfo == SIS_RI_1400x1050) tempal = 11;
  2487. } else if((SiS_Pr->SiS_LCDResInfo == Panel_1280x800) ||
  2488. (SiS_Pr->SiS_LCDResInfo == Panel_1280x800_2) ||
  2489. (SiS_Pr->SiS_LCDResInfo == Panel_1280x854)) {
  2490. if (resinfo == SIS_RI_1280x768) tempal = 9;
  2491. }
  2492. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  2493. /* Pass 1:1 only (center-screen handled outside) */
  2494. /* This is never called for the panel's native resolution */
  2495. /* since Pass1:1 will not be set in this case */
  2496. tempbx = 100;
  2497. if(ModeNo >= 0x13) {
  2498. tempal = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC_NS;
  2499. }
  2500. }
  2501. #ifdef CONFIG_FB_SIS_315
  2502. if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) {
  2503. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) {
  2504. if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
  2505. tempbx = 200;
  2506. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) tempbx++;
  2507. }
  2508. }
  2509. }
  2510. #endif
  2511. } else { /* TV */
  2512. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  2513. /* if(SiS_Pr->SiS_VGAVDE > 480) SiS_Pr->SiS_TVMode &= (~TVSetTVSimuMode); */
  2514. tempbx = 2;
  2515. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  2516. tempbx = 13;
  2517. if(!(SiS_Pr->SiS_TVMode & TVSetTVSimuMode)) tempbx = 14;
  2518. }
  2519. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  2520. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) tempbx = 7;
  2521. else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) tempbx = 6;
  2522. else tempbx = 5;
  2523. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) tempbx += 5;
  2524. } else {
  2525. if(SiS_Pr->SiS_TVMode & TVSetPAL) tempbx = 3;
  2526. else tempbx = 4;
  2527. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) tempbx += 5;
  2528. }
  2529. }
  2530. tempal &= 0x3F;
  2531. if(ModeNo > 0x13) {
  2532. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoHiVision) {
  2533. switch(resinfo) {
  2534. case SIS_RI_720x480:
  2535. tempal = 6;
  2536. if(SiS_Pr->SiS_TVMode & (TVSetPAL | TVSetPALN)) tempal = 9;
  2537. break;
  2538. case SIS_RI_720x576:
  2539. case SIS_RI_768x576:
  2540. case SIS_RI_1024x576: /* Not in NTSC or YPBPR mode (except 1080i)! */
  2541. tempal = 6;
  2542. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  2543. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) tempal = 8;
  2544. }
  2545. break;
  2546. case SIS_RI_800x480:
  2547. tempal = 4;
  2548. break;
  2549. case SIS_RI_512x384:
  2550. case SIS_RI_1024x768:
  2551. tempal = 7;
  2552. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  2553. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) tempal = 8;
  2554. }
  2555. break;
  2556. case SIS_RI_1280x720:
  2557. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  2558. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) tempal = 9;
  2559. }
  2560. break;
  2561. }
  2562. }
  2563. }
  2564. *CRT2Index = tempbx;
  2565. *ResIndex = tempal;
  2566. } else { /* LVDS, 301B-DH (if running on LCD) */
  2567. tempbx = 0;
  2568. if((SiS_Pr->SiS_IF_DEF_CH70xx) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
  2569. tempbx = 90;
  2570. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  2571. tempbx = 92;
  2572. if(SiS_Pr->SiS_ModeType > ModeVGA) {
  2573. if(SiS_Pr->SiS_CHSOverScan) tempbx = 99;
  2574. }
  2575. if(SiS_Pr->SiS_TVMode & TVSetPALM) tempbx = 94;
  2576. else if(SiS_Pr->SiS_TVMode & TVSetPALN) tempbx = 96;
  2577. }
  2578. if(tempbx != 99) {
  2579. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx++;
  2580. }
  2581. } else {
  2582. switch(SiS_Pr->SiS_LCDResInfo) {
  2583. case Panel_640x480: tempbx = 12; break;
  2584. case Panel_320x240_1: tempbx = 10; break;
  2585. case Panel_320x240_2:
  2586. case Panel_320x240_3: tempbx = 14; break;
  2587. case Panel_800x600: tempbx = 16; break;
  2588. case Panel_1024x600: tempbx = 18; break;
  2589. case Panel_1152x768:
  2590. case Panel_1024x768: tempbx = 20; break;
  2591. case Panel_1280x768: tempbx = 22; break;
  2592. case Panel_1280x1024: tempbx = 24; break;
  2593. case Panel_1400x1050: tempbx = 26; break;
  2594. case Panel_1600x1200: tempbx = 28; break;
  2595. #ifdef CONFIG_FB_SIS_300
  2596. case Panel_Barco1366: tempbx = 80; break;
  2597. #endif
  2598. }
  2599. switch(SiS_Pr->SiS_LCDResInfo) {
  2600. case Panel_320x240_1:
  2601. case Panel_320x240_2:
  2602. case Panel_320x240_3:
  2603. case Panel_640x480:
  2604. break;
  2605. default:
  2606. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++;
  2607. }
  2608. if(SiS_Pr->SiS_LCDInfo & LCDPass11) tempbx = 30;
  2609. #ifdef CONFIG_FB_SIS_300
  2610. if(SiS_Pr->SiS_CustomT == CUT_BARCO1024) {
  2611. tempbx = 82;
  2612. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++;
  2613. } else if(SiS_Pr->SiS_CustomT == CUT_PANEL848 || SiS_Pr->SiS_CustomT == CUT_PANEL856) {
  2614. tempbx = 84;
  2615. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++;
  2616. }
  2617. #endif
  2618. }
  2619. (*CRT2Index) = tempbx;
  2620. (*ResIndex) = tempal & 0x1F;
  2621. }
  2622. }
  2623. static void
  2624. SiS_GetRAMDAC2DATA(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  2625. unsigned short RefreshRateTableIndex)
  2626. {
  2627. unsigned short tempax=0, tempbx=0, index, dotclock;
  2628. unsigned short temp1=0, modeflag=0, tempcx=0;
  2629. SiS_Pr->SiS_RVBHCMAX = 1;
  2630. SiS_Pr->SiS_RVBHCFACT = 1;
  2631. if(ModeNo <= 0x13) {
  2632. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  2633. index = SiS_GetModePtr(SiS_Pr,ModeNo,ModeIdIndex);
  2634. tempax = SiS_Pr->SiS_StandTable[index].CRTC[0];
  2635. tempbx = SiS_Pr->SiS_StandTable[index].CRTC[6];
  2636. temp1 = SiS_Pr->SiS_StandTable[index].CRTC[7];
  2637. dotclock = (modeflag & Charx8Dot) ? 8 : 9;
  2638. } else {
  2639. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  2640. index = SiS_GetRefCRT1CRTC(SiS_Pr, RefreshRateTableIndex, SiS_Pr->SiS_UseWideCRT2);
  2641. tempax = SiS_Pr->SiS_CRT1Table[index].CR[0];
  2642. tempax |= (SiS_Pr->SiS_CRT1Table[index].CR[14] << 8);
  2643. tempax &= 0x03FF;
  2644. tempbx = SiS_Pr->SiS_CRT1Table[index].CR[6];
  2645. tempcx = SiS_Pr->SiS_CRT1Table[index].CR[13] << 8;
  2646. tempcx &= 0x0100;
  2647. tempcx <<= 2;
  2648. tempbx |= tempcx;
  2649. temp1 = SiS_Pr->SiS_CRT1Table[index].CR[7];
  2650. dotclock = 8;
  2651. }
  2652. if(temp1 & 0x01) tempbx |= 0x0100;
  2653. if(temp1 & 0x20) tempbx |= 0x0200;
  2654. tempax += 5;
  2655. tempax *= dotclock;
  2656. if(modeflag & HalfDCLK) tempax <<= 1;
  2657. tempbx++;
  2658. SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_HT = tempax;
  2659. SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_VT = tempbx;
  2660. }
  2661. static void
  2662. SiS_CalcPanelLinkTiming(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
  2663. unsigned short ModeIdIndex, unsigned short RefreshRateTableIndex)
  2664. {
  2665. unsigned short ResIndex;
  2666. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  2667. if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
  2668. if(SiS_Pr->UseCustomMode) {
  2669. ResIndex = SiS_Pr->CHTotal;
  2670. if(SiS_Pr->CModeFlag & HalfDCLK) ResIndex <<= 1;
  2671. SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_HT = ResIndex;
  2672. SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_VT = SiS_Pr->CVTotal;
  2673. } else {
  2674. if(ModeNo < 0x13) {
  2675. ResIndex = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  2676. } else {
  2677. ResIndex = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC_NS;
  2678. }
  2679. if(ResIndex == 0x09) {
  2680. if(SiS_Pr->Alternate1600x1200) ResIndex = 0x20; /* 1600x1200 LCDA */
  2681. else if(SiS_Pr->SiS_IF_DEF_LVDS == 1) ResIndex = 0x21; /* 1600x1200 LVDS */
  2682. }
  2683. SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_NoScaleData[ResIndex].VGAHT;
  2684. SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_NoScaleData[ResIndex].VGAVT;
  2685. SiS_Pr->SiS_HT = SiS_Pr->SiS_NoScaleData[ResIndex].LCDHT;
  2686. SiS_Pr->SiS_VT = SiS_Pr->SiS_NoScaleData[ResIndex].LCDVT;
  2687. }
  2688. } else {
  2689. SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_HT = SiS_Pr->PanelHT;
  2690. SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_VT = SiS_Pr->PanelVT;
  2691. }
  2692. } else {
  2693. /* This handles custom modes and custom panels */
  2694. SiS_Pr->SiS_HDE = SiS_Pr->PanelXRes;
  2695. SiS_Pr->SiS_VDE = SiS_Pr->PanelYRes;
  2696. SiS_Pr->SiS_HT = SiS_Pr->PanelHT;
  2697. SiS_Pr->SiS_VT = SiS_Pr->PanelVT;
  2698. SiS_Pr->SiS_VGAHT = SiS_Pr->PanelHT - (SiS_Pr->PanelXRes - SiS_Pr->SiS_VGAHDE);
  2699. SiS_Pr->SiS_VGAVT = SiS_Pr->PanelVT - (SiS_Pr->PanelYRes - SiS_Pr->SiS_VGAVDE);
  2700. }
  2701. }
  2702. static void
  2703. SiS_GetCRT2DataLVDS(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  2704. unsigned short RefreshRateTableIndex)
  2705. {
  2706. unsigned short CRT2Index, ResIndex, backup;
  2707. const struct SiS_LVDSData *LVDSData = NULL;
  2708. SiS_GetCRT2ResInfo(SiS_Pr, ModeNo, ModeIdIndex);
  2709. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  2710. SiS_Pr->SiS_RVBHCMAX = 1;
  2711. SiS_Pr->SiS_RVBHCFACT = 1;
  2712. SiS_Pr->SiS_NewFlickerMode = 0;
  2713. SiS_Pr->SiS_RVBHRS = 50;
  2714. SiS_Pr->SiS_RY1COE = 0;
  2715. SiS_Pr->SiS_RY2COE = 0;
  2716. SiS_Pr->SiS_RY3COE = 0;
  2717. SiS_Pr->SiS_RY4COE = 0;
  2718. SiS_Pr->SiS_RVBHRS2 = 0;
  2719. }
  2720. if((SiS_Pr->SiS_VBType & VB_SISVB) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  2721. #ifdef CONFIG_FB_SIS_315
  2722. SiS_CalcPanelLinkTiming(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  2723. SiS_CalcLCDACRT1Timing(SiS_Pr, ModeNo, ModeIdIndex);
  2724. #endif
  2725. } else {
  2726. /* 301BDH needs LVDS Data */
  2727. backup = SiS_Pr->SiS_IF_DEF_LVDS;
  2728. if((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) {
  2729. SiS_Pr->SiS_IF_DEF_LVDS = 1;
  2730. }
  2731. SiS_GetCRT2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex,
  2732. &CRT2Index, &ResIndex);
  2733. SiS_Pr->SiS_IF_DEF_LVDS = backup;
  2734. switch(CRT2Index) {
  2735. case 10: LVDSData = SiS_Pr->SiS_LVDS320x240Data_1; break;
  2736. case 14: LVDSData = SiS_Pr->SiS_LVDS320x240Data_2; break;
  2737. case 12: LVDSData = SiS_Pr->SiS_LVDS640x480Data_1; break;
  2738. case 16: LVDSData = SiS_Pr->SiS_LVDS800x600Data_1; break;
  2739. case 18: LVDSData = SiS_Pr->SiS_LVDS1024x600Data_1; break;
  2740. case 20: LVDSData = SiS_Pr->SiS_LVDS1024x768Data_1; break;
  2741. #ifdef CONFIG_FB_SIS_300
  2742. case 80: LVDSData = SiS_Pr->SiS_LVDSBARCO1366Data_1; break;
  2743. case 81: LVDSData = SiS_Pr->SiS_LVDSBARCO1366Data_2; break;
  2744. case 82: LVDSData = SiS_Pr->SiS_LVDSBARCO1024Data_1; break;
  2745. case 84: LVDSData = SiS_Pr->SiS_LVDS848x480Data_1; break;
  2746. case 85: LVDSData = SiS_Pr->SiS_LVDS848x480Data_2; break;
  2747. #endif
  2748. case 90: LVDSData = SiS_Pr->SiS_CHTVUNTSCData; break;
  2749. case 91: LVDSData = SiS_Pr->SiS_CHTVONTSCData; break;
  2750. case 92: LVDSData = SiS_Pr->SiS_CHTVUPALData; break;
  2751. case 93: LVDSData = SiS_Pr->SiS_CHTVOPALData; break;
  2752. case 94: LVDSData = SiS_Pr->SiS_CHTVUPALMData; break;
  2753. case 95: LVDSData = SiS_Pr->SiS_CHTVOPALMData; break;
  2754. case 96: LVDSData = SiS_Pr->SiS_CHTVUPALNData; break;
  2755. case 97: LVDSData = SiS_Pr->SiS_CHTVOPALNData; break;
  2756. case 99: LVDSData = SiS_Pr->SiS_CHTVSOPALData; break;
  2757. }
  2758. if(LVDSData) {
  2759. SiS_Pr->SiS_VGAHT = (LVDSData+ResIndex)->VGAHT;
  2760. SiS_Pr->SiS_VGAVT = (LVDSData+ResIndex)->VGAVT;
  2761. SiS_Pr->SiS_HT = (LVDSData+ResIndex)->LCDHT;
  2762. SiS_Pr->SiS_VT = (LVDSData+ResIndex)->LCDVT;
  2763. } else {
  2764. SiS_CalcPanelLinkTiming(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  2765. }
  2766. if( (!(SiS_Pr->SiS_VBType & VB_SISVB)) &&
  2767. (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) &&
  2768. (!(SiS_Pr->SiS_LCDInfo & LCDPass11)) ) {
  2769. if( (!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) ||
  2770. (SiS_Pr->SiS_SetFlag & SetDOSMode) ) {
  2771. SiS_Pr->SiS_HDE = SiS_Pr->PanelXRes;
  2772. SiS_Pr->SiS_VDE = SiS_Pr->PanelYRes;
  2773. #ifdef CONFIG_FB_SIS_300
  2774. if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) {
  2775. if(ResIndex < 0x08) {
  2776. SiS_Pr->SiS_HDE = 1280;
  2777. SiS_Pr->SiS_VDE = 1024;
  2778. }
  2779. }
  2780. #endif
  2781. }
  2782. }
  2783. }
  2784. }
  2785. static void
  2786. SiS_GetCRT2Data301(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  2787. unsigned short RefreshRateTableIndex)
  2788. {
  2789. unsigned char *ROMAddr = NULL;
  2790. unsigned short tempax, tempbx, modeflag, romptr=0;
  2791. unsigned short resinfo, CRT2Index, ResIndex;
  2792. const struct SiS_LCDData *LCDPtr = NULL;
  2793. const struct SiS_TVData *TVPtr = NULL;
  2794. #ifdef CONFIG_FB_SIS_315
  2795. short resinfo661;
  2796. #endif
  2797. if(ModeNo <= 0x13) {
  2798. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  2799. resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
  2800. } else if(SiS_Pr->UseCustomMode) {
  2801. modeflag = SiS_Pr->CModeFlag;
  2802. resinfo = 0;
  2803. } else {
  2804. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  2805. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  2806. #ifdef CONFIG_FB_SIS_315
  2807. resinfo661 = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].ROMMODEIDX661;
  2808. if( (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) &&
  2809. (SiS_Pr->SiS_SetFlag & LCDVESATiming) &&
  2810. (resinfo661 >= 0) &&
  2811. (SiS_Pr->SiS_NeedRomModeData) ) {
  2812. if((ROMAddr = GetLCDStructPtr661(SiS_Pr))) {
  2813. if((romptr = (SISGETROMW(21)))) {
  2814. romptr += (resinfo661 * 10);
  2815. ROMAddr = SiS_Pr->VirtualRomBase;
  2816. }
  2817. }
  2818. }
  2819. #endif
  2820. }
  2821. SiS_Pr->SiS_NewFlickerMode = 0;
  2822. SiS_Pr->SiS_RVBHRS = 50;
  2823. SiS_Pr->SiS_RY1COE = 0;
  2824. SiS_Pr->SiS_RY2COE = 0;
  2825. SiS_Pr->SiS_RY3COE = 0;
  2826. SiS_Pr->SiS_RY4COE = 0;
  2827. SiS_Pr->SiS_RVBHRS2 = 0;
  2828. SiS_GetCRT2ResInfo(SiS_Pr,ModeNo,ModeIdIndex);
  2829. if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) {
  2830. if(SiS_Pr->UseCustomMode) {
  2831. SiS_Pr->SiS_RVBHCMAX = 1;
  2832. SiS_Pr->SiS_RVBHCFACT = 1;
  2833. SiS_Pr->SiS_HDE = SiS_Pr->SiS_VGAHDE;
  2834. SiS_Pr->SiS_VDE = SiS_Pr->SiS_VGAVDE;
  2835. tempax = SiS_Pr->CHTotal;
  2836. if(modeflag & HalfDCLK) tempax <<= 1;
  2837. SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_HT = tempax;
  2838. SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_VT = SiS_Pr->CVTotal;
  2839. } else {
  2840. SiS_GetRAMDAC2DATA(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  2841. }
  2842. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  2843. SiS_GetCRT2Ptr(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex,
  2844. &CRT2Index,&ResIndex);
  2845. switch(CRT2Index) {
  2846. case 2: TVPtr = SiS_Pr->SiS_ExtHiTVData; break;
  2847. case 3: TVPtr = SiS_Pr->SiS_ExtPALData; break;
  2848. case 4: TVPtr = SiS_Pr->SiS_ExtNTSCData; break;
  2849. case 5: TVPtr = SiS_Pr->SiS_Ext525iData; break;
  2850. case 6: TVPtr = SiS_Pr->SiS_Ext525pData; break;
  2851. case 7: TVPtr = SiS_Pr->SiS_Ext750pData; break;
  2852. case 8: TVPtr = SiS_Pr->SiS_StPALData; break;
  2853. case 9: TVPtr = SiS_Pr->SiS_StNTSCData; break;
  2854. case 10: TVPtr = SiS_Pr->SiS_St525iData; break;
  2855. case 11: TVPtr = SiS_Pr->SiS_St525pData; break;
  2856. case 12: TVPtr = SiS_Pr->SiS_St750pData; break;
  2857. case 13: TVPtr = SiS_Pr->SiS_St1HiTVData; break;
  2858. case 14: TVPtr = SiS_Pr->SiS_St2HiTVData; break;
  2859. default: TVPtr = SiS_Pr->SiS_StPALData; break;
  2860. }
  2861. SiS_Pr->SiS_RVBHCMAX = (TVPtr+ResIndex)->RVBHCMAX;
  2862. SiS_Pr->SiS_RVBHCFACT = (TVPtr+ResIndex)->RVBHCFACT;
  2863. SiS_Pr->SiS_VGAHT = (TVPtr+ResIndex)->VGAHT;
  2864. SiS_Pr->SiS_VGAVT = (TVPtr+ResIndex)->VGAVT;
  2865. SiS_Pr->SiS_HDE = (TVPtr+ResIndex)->TVHDE;
  2866. SiS_Pr->SiS_VDE = (TVPtr+ResIndex)->TVVDE;
  2867. SiS_Pr->SiS_RVBHRS2 = (TVPtr+ResIndex)->RVBHRS2 & 0x0fff;
  2868. if(modeflag & HalfDCLK) {
  2869. SiS_Pr->SiS_RVBHRS = (TVPtr+ResIndex)->HALFRVBHRS;
  2870. if(SiS_Pr->SiS_RVBHRS2) {
  2871. SiS_Pr->SiS_RVBHRS2 = ((SiS_Pr->SiS_RVBHRS2 + 3) >> 1) - 3;
  2872. tempax = ((TVPtr+ResIndex)->RVBHRS2 >> 12) & 0x07;
  2873. if((TVPtr+ResIndex)->RVBHRS2 & 0x8000) SiS_Pr->SiS_RVBHRS2 -= tempax;
  2874. else SiS_Pr->SiS_RVBHRS2 += tempax;
  2875. }
  2876. } else {
  2877. SiS_Pr->SiS_RVBHRS = (TVPtr+ResIndex)->RVBHRS;
  2878. }
  2879. SiS_Pr->SiS_NewFlickerMode = ((TVPtr+ResIndex)->FlickerMode) << 7;
  2880. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  2881. if((resinfo == SIS_RI_960x600) ||
  2882. (resinfo == SIS_RI_1024x768) ||
  2883. (resinfo == SIS_RI_1280x1024) ||
  2884. (resinfo == SIS_RI_1280x720)) {
  2885. SiS_Pr->SiS_NewFlickerMode = 0x40;
  2886. }
  2887. if(SiS_Pr->SiS_VGAVDE == 350) SiS_Pr->SiS_TVMode |= TVSetTVSimuMode;
  2888. SiS_Pr->SiS_HT = ExtHiTVHT;
  2889. SiS_Pr->SiS_VT = ExtHiTVVT;
  2890. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  2891. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) {
  2892. SiS_Pr->SiS_HT = StHiTVHT;
  2893. SiS_Pr->SiS_VT = StHiTVVT;
  2894. }
  2895. }
  2896. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  2897. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) {
  2898. SiS_Pr->SiS_HT = 1650;
  2899. SiS_Pr->SiS_VT = 750;
  2900. } else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) {
  2901. SiS_Pr->SiS_HT = NTSCHT;
  2902. if(SiS_Pr->SiS_TVMode & TVSet525p1024) SiS_Pr->SiS_HT = NTSC2HT;
  2903. SiS_Pr->SiS_VT = NTSCVT;
  2904. } else {
  2905. SiS_Pr->SiS_HT = NTSCHT;
  2906. if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) SiS_Pr->SiS_HT = NTSC2HT;
  2907. SiS_Pr->SiS_VT = NTSCVT;
  2908. }
  2909. } else {
  2910. SiS_Pr->SiS_RY1COE = (TVPtr+ResIndex)->RY1COE;
  2911. SiS_Pr->SiS_RY2COE = (TVPtr+ResIndex)->RY2COE;
  2912. SiS_Pr->SiS_RY3COE = (TVPtr+ResIndex)->RY3COE;
  2913. SiS_Pr->SiS_RY4COE = (TVPtr+ResIndex)->RY4COE;
  2914. if(modeflag & HalfDCLK) {
  2915. SiS_Pr->SiS_RY1COE = 0x00;
  2916. SiS_Pr->SiS_RY2COE = 0xf4;
  2917. SiS_Pr->SiS_RY3COE = 0x10;
  2918. SiS_Pr->SiS_RY4COE = 0x38;
  2919. }
  2920. if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) {
  2921. SiS_Pr->SiS_HT = NTSCHT;
  2922. if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) SiS_Pr->SiS_HT = NTSC2HT;
  2923. SiS_Pr->SiS_VT = NTSCVT;
  2924. } else {
  2925. SiS_Pr->SiS_HT = PALHT;
  2926. SiS_Pr->SiS_VT = PALVT;
  2927. }
  2928. }
  2929. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  2930. SiS_Pr->SiS_RVBHCMAX = 1;
  2931. SiS_Pr->SiS_RVBHCFACT = 1;
  2932. if(SiS_Pr->UseCustomMode) {
  2933. SiS_Pr->SiS_HDE = SiS_Pr->SiS_VGAHDE;
  2934. SiS_Pr->SiS_VDE = SiS_Pr->SiS_VGAVDE;
  2935. tempax = SiS_Pr->CHTotal;
  2936. if(modeflag & HalfDCLK) tempax <<= 1;
  2937. SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_HT = tempax;
  2938. SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_VT = SiS_Pr->CVTotal;
  2939. } else {
  2940. bool gotit = false;
  2941. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
  2942. SiS_Pr->SiS_VGAHT = SiS_Pr->PanelHT;
  2943. SiS_Pr->SiS_VGAVT = SiS_Pr->PanelVT;
  2944. SiS_Pr->SiS_HT = SiS_Pr->PanelHT;
  2945. SiS_Pr->SiS_VT = SiS_Pr->PanelVT;
  2946. gotit = true;
  2947. } else if( (!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) && (romptr) && (ROMAddr) ) {
  2948. #ifdef CONFIG_FB_SIS_315
  2949. SiS_Pr->SiS_RVBHCMAX = ROMAddr[romptr];
  2950. SiS_Pr->SiS_RVBHCFACT = ROMAddr[romptr+1];
  2951. SiS_Pr->SiS_VGAHT = ROMAddr[romptr+2] | ((ROMAddr[romptr+3] & 0x0f) << 8);
  2952. SiS_Pr->SiS_VGAVT = (ROMAddr[romptr+4] << 4) | ((ROMAddr[romptr+3] & 0xf0) >> 4);
  2953. SiS_Pr->SiS_HT = ROMAddr[romptr+5] | ((ROMAddr[romptr+6] & 0x0f) << 8);
  2954. SiS_Pr->SiS_VT = (ROMAddr[romptr+7] << 4) | ((ROMAddr[romptr+6] & 0xf0) >> 4);
  2955. SiS_Pr->SiS_RVBHRS2 = ROMAddr[romptr+8] | ((ROMAddr[romptr+9] & 0x0f) << 8);
  2956. if((SiS_Pr->SiS_RVBHRS2) && (modeflag & HalfDCLK)) {
  2957. SiS_Pr->SiS_RVBHRS2 = ((SiS_Pr->SiS_RVBHRS2 + 3) >> 1) - 3;
  2958. tempax = (ROMAddr[romptr+9] >> 4) & 0x07;
  2959. if(ROMAddr[romptr+9] & 0x80) SiS_Pr->SiS_RVBHRS2 -= tempax;
  2960. else SiS_Pr->SiS_RVBHRS2 += tempax;
  2961. }
  2962. if(SiS_Pr->SiS_VGAHT) gotit = true;
  2963. else {
  2964. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  2965. SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  2966. SiS_Pr->SiS_RVBHCMAX = 1;
  2967. SiS_Pr->SiS_RVBHCFACT = 1;
  2968. SiS_Pr->SiS_VGAHT = SiS_Pr->PanelHT;
  2969. SiS_Pr->SiS_VGAVT = SiS_Pr->PanelVT;
  2970. SiS_Pr->SiS_HT = SiS_Pr->PanelHT;
  2971. SiS_Pr->SiS_VT = SiS_Pr->PanelVT;
  2972. SiS_Pr->SiS_RVBHRS2 = 0;
  2973. gotit = true;
  2974. }
  2975. #endif
  2976. }
  2977. if(!gotit) {
  2978. SiS_GetCRT2Ptr(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex,
  2979. &CRT2Index,&ResIndex);
  2980. switch(CRT2Index) {
  2981. case Panel_1024x768 : LCDPtr = SiS_Pr->SiS_ExtLCD1024x768Data; break;
  2982. case Panel_1024x768 + 32: LCDPtr = SiS_Pr->SiS_St2LCD1024x768Data; break;
  2983. case Panel_1280x720 :
  2984. case Panel_1280x720 + 32: LCDPtr = SiS_Pr->SiS_LCD1280x720Data; break;
  2985. case Panel_1280x768_2 : LCDPtr = SiS_Pr->SiS_ExtLCD1280x768_2Data; break;
  2986. case Panel_1280x768_2+ 32: LCDPtr = SiS_Pr->SiS_StLCD1280x768_2Data; break;
  2987. case Panel_1280x800 :
  2988. case Panel_1280x800 + 32: LCDPtr = SiS_Pr->SiS_LCD1280x800Data; break;
  2989. case Panel_1280x800_2 :
  2990. case Panel_1280x800_2+ 32: LCDPtr = SiS_Pr->SiS_LCD1280x800_2Data; break;
  2991. case Panel_1280x854 :
  2992. case Panel_1280x854 + 32: LCDPtr = SiS_Pr->SiS_LCD1280x854Data; break;
  2993. case Panel_1280x960 :
  2994. case Panel_1280x960 + 32: LCDPtr = SiS_Pr->SiS_LCD1280x960Data; break;
  2995. case Panel_1280x1024 : LCDPtr = SiS_Pr->SiS_ExtLCD1280x1024Data; break;
  2996. case Panel_1280x1024 + 32: LCDPtr = SiS_Pr->SiS_St2LCD1280x1024Data; break;
  2997. case Panel_1400x1050 : LCDPtr = SiS_Pr->SiS_ExtLCD1400x1050Data; break;
  2998. case Panel_1400x1050 + 32: LCDPtr = SiS_Pr->SiS_StLCD1400x1050Data; break;
  2999. case Panel_1600x1200 : LCDPtr = SiS_Pr->SiS_ExtLCD1600x1200Data; break;
  3000. case Panel_1600x1200 + 32: LCDPtr = SiS_Pr->SiS_StLCD1600x1200Data; break;
  3001. case Panel_1680x1050 :
  3002. case Panel_1680x1050 + 32: LCDPtr = SiS_Pr->SiS_LCD1680x1050Data; break;
  3003. case 100 : LCDPtr = SiS_Pr->SiS_NoScaleData; break;
  3004. #ifdef CONFIG_FB_SIS_315
  3005. case 200 : LCDPtr = SiS310_ExtCompaq1280x1024Data; break;
  3006. case 201 : LCDPtr = SiS_Pr->SiS_St2LCD1280x1024Data; break;
  3007. #endif
  3008. default : LCDPtr = SiS_Pr->SiS_ExtLCD1024x768Data; break;
  3009. }
  3010. SiS_Pr->SiS_RVBHCMAX = (LCDPtr+ResIndex)->RVBHCMAX;
  3011. SiS_Pr->SiS_RVBHCFACT = (LCDPtr+ResIndex)->RVBHCFACT;
  3012. SiS_Pr->SiS_VGAHT = (LCDPtr+ResIndex)->VGAHT;
  3013. SiS_Pr->SiS_VGAVT = (LCDPtr+ResIndex)->VGAVT;
  3014. SiS_Pr->SiS_HT = (LCDPtr+ResIndex)->LCDHT;
  3015. SiS_Pr->SiS_VT = (LCDPtr+ResIndex)->LCDVT;
  3016. }
  3017. tempax = SiS_Pr->PanelXRes;
  3018. tempbx = SiS_Pr->PanelYRes;
  3019. switch(SiS_Pr->SiS_LCDResInfo) {
  3020. case Panel_1024x768:
  3021. if(SiS_Pr->SiS_SetFlag & LCDVESATiming) {
  3022. if(SiS_Pr->ChipType < SIS_315H) {
  3023. if (SiS_Pr->SiS_VGAVDE == 350) tempbx = 560;
  3024. else if(SiS_Pr->SiS_VGAVDE == 400) tempbx = 640;
  3025. }
  3026. } else {
  3027. if (SiS_Pr->SiS_VGAVDE == 357) tempbx = 527;
  3028. else if(SiS_Pr->SiS_VGAVDE == 420) tempbx = 620;
  3029. else if(SiS_Pr->SiS_VGAVDE == 525) tempbx = 775;
  3030. else if(SiS_Pr->SiS_VGAVDE == 600) tempbx = 775;
  3031. else if(SiS_Pr->SiS_VGAVDE == 350) tempbx = 560;
  3032. else if(SiS_Pr->SiS_VGAVDE == 400) tempbx = 640;
  3033. }
  3034. break;
  3035. case Panel_1280x960:
  3036. if (SiS_Pr->SiS_VGAVDE == 350) tempbx = 700;
  3037. else if(SiS_Pr->SiS_VGAVDE == 400) tempbx = 800;
  3038. else if(SiS_Pr->SiS_VGAVDE == 1024) tempbx = 960;
  3039. break;
  3040. case Panel_1280x1024:
  3041. if (SiS_Pr->SiS_VGAVDE == 360) tempbx = 768;
  3042. else if(SiS_Pr->SiS_VGAVDE == 375) tempbx = 800;
  3043. else if(SiS_Pr->SiS_VGAVDE == 405) tempbx = 864;
  3044. break;
  3045. case Panel_1600x1200:
  3046. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
  3047. if (SiS_Pr->SiS_VGAVDE == 350) tempbx = 875;
  3048. else if(SiS_Pr->SiS_VGAVDE == 400) tempbx = 1000;
  3049. }
  3050. break;
  3051. }
  3052. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  3053. tempax = SiS_Pr->SiS_VGAHDE;
  3054. tempbx = SiS_Pr->SiS_VGAVDE;
  3055. }
  3056. SiS_Pr->SiS_HDE = tempax;
  3057. SiS_Pr->SiS_VDE = tempbx;
  3058. }
  3059. }
  3060. }
  3061. static void
  3062. SiS_GetCRT2Data(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  3063. unsigned short RefreshRateTableIndex)
  3064. {
  3065. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  3066. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  3067. SiS_GetCRT2DataLVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  3068. } else {
  3069. if((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) {
  3070. /* Need LVDS Data for LCD on 301B-DH */
  3071. SiS_GetCRT2DataLVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  3072. } else {
  3073. SiS_GetCRT2Data301(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  3074. }
  3075. }
  3076. } else {
  3077. SiS_GetCRT2DataLVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  3078. }
  3079. }
  3080. /*********************************************/
  3081. /* GET LVDS DES (SKEW) DATA */
  3082. /*********************************************/
  3083. static const struct SiS_LVDSDes *
  3084. SiS_GetLVDSDesPtr(struct SiS_Private *SiS_Pr)
  3085. {
  3086. const struct SiS_LVDSDes *PanelDesPtr = NULL;
  3087. #ifdef CONFIG_FB_SIS_300
  3088. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  3089. if(SiS_Pr->ChipType < SIS_315H) {
  3090. if(SiS_Pr->SiS_LCDTypeInfo == 4) {
  3091. if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) {
  3092. PanelDesPtr = SiS_Pr->SiS_PanelType04_1a;
  3093. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  3094. PanelDesPtr = SiS_Pr->SiS_PanelType04_2a;
  3095. }
  3096. } else if(SiS_Pr->SiS_CustomT == CUT_BARCO1024) {
  3097. PanelDesPtr = SiS_Pr->SiS_PanelType04_1b;
  3098. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  3099. PanelDesPtr = SiS_Pr->SiS_PanelType04_2b;
  3100. }
  3101. }
  3102. }
  3103. }
  3104. }
  3105. #endif
  3106. return PanelDesPtr;
  3107. }
  3108. static void
  3109. SiS_GetLVDSDesData(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  3110. unsigned short RefreshRateTableIndex)
  3111. {
  3112. unsigned short modeflag, ResIndex;
  3113. const struct SiS_LVDSDes *PanelDesPtr = NULL;
  3114. SiS_Pr->SiS_LCDHDES = 0;
  3115. SiS_Pr->SiS_LCDVDES = 0;
  3116. /* Some special cases */
  3117. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  3118. /* Trumpion */
  3119. if(SiS_Pr->SiS_IF_DEF_TRUMPION) {
  3120. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  3121. if(SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) {
  3122. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3123. }
  3124. }
  3125. return;
  3126. }
  3127. /* 640x480 on LVDS */
  3128. if(SiS_Pr->ChipType < SIS_315H) {
  3129. if(SiS_Pr->SiS_LCDResInfo == Panel_640x480 && SiS_Pr->SiS_LCDTypeInfo == 3) {
  3130. SiS_Pr->SiS_LCDHDES = 8;
  3131. if (SiS_Pr->SiS_VGAVDE >= 480) SiS_Pr->SiS_LCDVDES = 512;
  3132. else if(SiS_Pr->SiS_VGAVDE >= 400) SiS_Pr->SiS_LCDVDES = 436;
  3133. else if(SiS_Pr->SiS_VGAVDE >= 350) SiS_Pr->SiS_LCDVDES = 440;
  3134. return;
  3135. }
  3136. }
  3137. } /* LCD */
  3138. if( (SiS_Pr->UseCustomMode) ||
  3139. (SiS_Pr->SiS_LCDResInfo == Panel_Custom) ||
  3140. (SiS_Pr->SiS_CustomT == CUT_PANEL848) ||
  3141. (SiS_Pr->SiS_CustomT == CUT_PANEL856) ||
  3142. (SiS_Pr->SiS_LCDInfo & LCDPass11) ) {
  3143. return;
  3144. }
  3145. if(ModeNo <= 0x13) ResIndex = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  3146. else ResIndex = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  3147. if((SiS_Pr->SiS_VBType & VB_SIS30xBLV) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  3148. #ifdef CONFIG_FB_SIS_315
  3149. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  3150. /* non-pass 1:1 only, see above */
  3151. if(SiS_Pr->SiS_VGAHDE != SiS_Pr->PanelXRes) {
  3152. SiS_Pr->SiS_LCDHDES = SiS_Pr->SiS_HT - ((SiS_Pr->PanelXRes - SiS_Pr->SiS_VGAHDE) / 2);
  3153. }
  3154. if(SiS_Pr->SiS_VGAVDE != SiS_Pr->PanelYRes) {
  3155. SiS_Pr->SiS_LCDVDES = SiS_Pr->SiS_VT - ((SiS_Pr->PanelYRes - SiS_Pr->SiS_VGAVDE) / 2);
  3156. }
  3157. }
  3158. if(SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) {
  3159. switch(SiS_Pr->SiS_CustomT) {
  3160. case CUT_UNIWILL1024:
  3161. case CUT_UNIWILL10242:
  3162. case CUT_CLEVO1400:
  3163. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  3164. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3165. }
  3166. break;
  3167. }
  3168. switch(SiS_Pr->SiS_LCDResInfo) {
  3169. case Panel_1280x1024:
  3170. if(SiS_Pr->SiS_CustomT != CUT_COMPAQ1280) {
  3171. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3172. }
  3173. break;
  3174. case Panel_1280x800: /* Verified for Averatec 6240 */
  3175. case Panel_1280x800_2: /* Verified for Asus A4L */
  3176. case Panel_1280x854: /* Not verified yet FIXME */
  3177. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3178. break;
  3179. }
  3180. }
  3181. #endif
  3182. } else {
  3183. if((SiS_Pr->SiS_IF_DEF_CH70xx != 0) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
  3184. if((SiS_Pr->SiS_TVMode & TVSetPAL) && (!(SiS_Pr->SiS_TVMode & TVSetPALM))) {
  3185. if(ResIndex <= 3) SiS_Pr->SiS_LCDHDES = 256;
  3186. }
  3187. } else if((PanelDesPtr = SiS_GetLVDSDesPtr(SiS_Pr))) {
  3188. SiS_Pr->SiS_LCDHDES = (PanelDesPtr+ResIndex)->LCDHDES;
  3189. SiS_Pr->SiS_LCDVDES = (PanelDesPtr+ResIndex)->LCDVDES;
  3190. } else if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  3191. if(SiS_Pr->SiS_VGAHDE != SiS_Pr->PanelXRes) {
  3192. SiS_Pr->SiS_LCDHDES = SiS_Pr->SiS_HT - ((SiS_Pr->PanelXRes - SiS_Pr->SiS_VGAHDE) / 2);
  3193. }
  3194. if(SiS_Pr->SiS_VGAVDE != SiS_Pr->PanelYRes) {
  3195. SiS_Pr->SiS_LCDVDES = SiS_Pr->SiS_VT - ((SiS_Pr->PanelYRes - SiS_Pr->SiS_VGAVDE) / 2);
  3196. } else {
  3197. if(SiS_Pr->ChipType < SIS_315H) {
  3198. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3199. } else {
  3200. switch(SiS_Pr->SiS_LCDResInfo) {
  3201. case Panel_800x600:
  3202. case Panel_1024x768:
  3203. case Panel_1280x1024:
  3204. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT;
  3205. break;
  3206. case Panel_1400x1050:
  3207. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3208. break;
  3209. }
  3210. }
  3211. }
  3212. } else {
  3213. if(SiS_Pr->ChipType < SIS_315H) {
  3214. #ifdef CONFIG_FB_SIS_300
  3215. switch(SiS_Pr->SiS_LCDResInfo) {
  3216. case Panel_800x600:
  3217. if(SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) {
  3218. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3219. } else {
  3220. SiS_Pr->SiS_LCDHDES = SiS_Pr->PanelHT + 3;
  3221. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT;
  3222. if(SiS_Pr->SiS_VGAVDE == 400) SiS_Pr->SiS_LCDVDES -= 2;
  3223. else SiS_Pr->SiS_LCDVDES -= 4;
  3224. }
  3225. break;
  3226. case Panel_1024x768:
  3227. if(SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) {
  3228. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3229. } else {
  3230. SiS_Pr->SiS_LCDHDES = SiS_Pr->PanelHT - 1;
  3231. if(SiS_Pr->SiS_VGAVDE <= 400) SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 8;
  3232. if(SiS_Pr->SiS_VGAVDE <= 350) SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 12;
  3233. }
  3234. break;
  3235. case Panel_1024x600:
  3236. default:
  3237. if( (SiS_Pr->SiS_VGAHDE == SiS_Pr->PanelXRes) &&
  3238. (SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) ) {
  3239. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3240. } else {
  3241. SiS_Pr->SiS_LCDHDES = SiS_Pr->PanelHT - 1;
  3242. }
  3243. break;
  3244. }
  3245. switch(SiS_Pr->SiS_LCDTypeInfo) {
  3246. case 1:
  3247. SiS_Pr->SiS_LCDHDES = SiS_Pr->SiS_LCDVDES = 0;
  3248. break;
  3249. case 3: /* 640x480 only? */
  3250. SiS_Pr->SiS_LCDHDES = 8;
  3251. if (SiS_Pr->SiS_VGAVDE >= 480) SiS_Pr->SiS_LCDVDES = 512;
  3252. else if(SiS_Pr->SiS_VGAVDE >= 400) SiS_Pr->SiS_LCDVDES = 436;
  3253. else if(SiS_Pr->SiS_VGAVDE >= 350) SiS_Pr->SiS_LCDVDES = 440;
  3254. break;
  3255. }
  3256. #endif
  3257. } else {
  3258. #ifdef CONFIG_FB_SIS_315
  3259. switch(SiS_Pr->SiS_LCDResInfo) {
  3260. case Panel_1024x768:
  3261. case Panel_1280x1024:
  3262. if(SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) {
  3263. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3264. }
  3265. break;
  3266. case Panel_320x240_1:
  3267. case Panel_320x240_2:
  3268. case Panel_320x240_3:
  3269. SiS_Pr->SiS_LCDVDES = 524;
  3270. break;
  3271. }
  3272. #endif
  3273. }
  3274. }
  3275. if((ModeNo <= 0x13) && (SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
  3276. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  3277. if((SiS_Pr->SiS_VBType & VB_SIS30xBLV) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  3278. if(!(modeflag & HalfDCLK)) SiS_Pr->SiS_LCDHDES = 632;
  3279. } else if(!(SiS_Pr->SiS_SetFlag & SetDOSMode)) {
  3280. if(SiS_Pr->SiS_LCDResInfo != Panel_1280x1024) {
  3281. if(SiS_Pr->SiS_LCDResInfo >= Panel_1024x768) {
  3282. if(SiS_Pr->ChipType < SIS_315H) {
  3283. if(!(modeflag & HalfDCLK)) SiS_Pr->SiS_LCDHDES = 320;
  3284. } else {
  3285. #ifdef CONFIG_FB_SIS_315
  3286. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) SiS_Pr->SiS_LCDHDES = 480;
  3287. if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) SiS_Pr->SiS_LCDHDES = 804;
  3288. if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) SiS_Pr->SiS_LCDHDES = 704;
  3289. if(!(modeflag & HalfDCLK)) {
  3290. SiS_Pr->SiS_LCDHDES = 320;
  3291. if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) SiS_Pr->SiS_LCDHDES = 632;
  3292. if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) SiS_Pr->SiS_LCDHDES = 542;
  3293. }
  3294. #endif
  3295. }
  3296. }
  3297. }
  3298. }
  3299. }
  3300. }
  3301. }
  3302. /*********************************************/
  3303. /* DISABLE VIDEO BRIDGE */
  3304. /*********************************************/
  3305. #ifdef CONFIG_FB_SIS_315
  3306. static int
  3307. SiS_HandlePWD(struct SiS_Private *SiS_Pr)
  3308. {
  3309. int ret = 0;
  3310. #ifdef SET_PWD
  3311. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  3312. unsigned short romptr = GetLCDStructPtr661_2(SiS_Pr);
  3313. unsigned char drivermode = SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & 0x40;
  3314. unsigned short temp;
  3315. if( (SiS_Pr->SiS_VBType & VB_SISPWD) &&
  3316. (romptr) &&
  3317. (SiS_Pr->SiS_PWDOffset) ) {
  3318. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2b,ROMAddr[romptr + SiS_Pr->SiS_PWDOffset + 0]);
  3319. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2c,ROMAddr[romptr + SiS_Pr->SiS_PWDOffset + 1]);
  3320. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2d,ROMAddr[romptr + SiS_Pr->SiS_PWDOffset + 2]);
  3321. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2e,ROMAddr[romptr + SiS_Pr->SiS_PWDOffset + 3]);
  3322. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2f,ROMAddr[romptr + SiS_Pr->SiS_PWDOffset + 4]);
  3323. temp = 0x00;
  3324. if((ROMAddr[romptr + 2] & (0x06 << 1)) && !drivermode) {
  3325. temp = 0x80;
  3326. ret = 1;
  3327. }
  3328. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x27,0x7f,temp);
  3329. }
  3330. #endif
  3331. return ret;
  3332. }
  3333. #endif
  3334. /* NEVER use any variables (VBInfo), this will be called
  3335. * from outside the context of modeswitch!
  3336. * MUST call getVBType before calling this
  3337. */
  3338. void
  3339. SiS_DisableBridge(struct SiS_Private *SiS_Pr)
  3340. {
  3341. #ifdef CONFIG_FB_SIS_315
  3342. unsigned short tempah, pushax=0, modenum;
  3343. #endif
  3344. unsigned short temp=0;
  3345. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  3346. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) { /* ===== For 30xB/C/LV ===== */
  3347. if(SiS_Pr->ChipType < SIS_315H) {
  3348. #ifdef CONFIG_FB_SIS_300 /* 300 series */
  3349. if(!(SiS_CR36BIOSWord23b(SiS_Pr))) {
  3350. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3351. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFE);
  3352. } else {
  3353. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x08);
  3354. }
  3355. SiS_PanelDelay(SiS_Pr, 3);
  3356. }
  3357. if(SiS_Is301B(SiS_Pr)) {
  3358. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1f,0x3f);
  3359. SiS_ShortDelay(SiS_Pr,1);
  3360. }
  3361. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xDF);
  3362. SiS_DisplayOff(SiS_Pr);
  3363. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF);
  3364. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF);
  3365. SiS_UnLockCRT2(SiS_Pr);
  3366. if(!(SiS_Pr->SiS_VBType & VB_SISLVDS)) {
  3367. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x01,0x80);
  3368. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x02,0x40);
  3369. }
  3370. if( (!(SiS_CRT2IsLCD(SiS_Pr))) ||
  3371. (!(SiS_CR36BIOSWord23d(SiS_Pr))) ) {
  3372. SiS_PanelDelay(SiS_Pr, 2);
  3373. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3374. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFD);
  3375. } else {
  3376. SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x04);
  3377. }
  3378. }
  3379. #endif /* CONFIG_FB_SIS_300 */
  3380. } else {
  3381. #ifdef CONFIG_FB_SIS_315 /* 315 series */
  3382. int didpwd = 0;
  3383. bool custom1 = (SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) ||
  3384. (SiS_Pr->SiS_CustomT == CUT_CLEVO1400);
  3385. modenum = SiS_GetReg(SiS_Pr->SiS_P3d4,0x34) & 0x7f;
  3386. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3387. #ifdef SET_EMI
  3388. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  3389. if(SiS_Pr->SiS_CustomT != CUT_CLEVO1400) {
  3390. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
  3391. }
  3392. }
  3393. #endif
  3394. didpwd = SiS_HandlePWD(SiS_Pr);
  3395. if( (modenum <= 0x13) ||
  3396. (SiS_IsVAMode(SiS_Pr)) ||
  3397. (!(SiS_IsDualEdge(SiS_Pr))) ) {
  3398. if(!didpwd) {
  3399. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xfe);
  3400. if(custom1) SiS_PanelDelay(SiS_Pr, 3);
  3401. } else {
  3402. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xfc);
  3403. }
  3404. }
  3405. if(!custom1) {
  3406. SiS_DDC2Delay(SiS_Pr,0xff00);
  3407. SiS_DDC2Delay(SiS_Pr,0xe000);
  3408. SiS_SetRegByte(SiS_Pr->SiS_P3c6,0x00);
  3409. pushax = SiS_GetReg(SiS_Pr->SiS_P3c4,0x06);
  3410. if(IS_SIS740) {
  3411. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x06,0xE3);
  3412. }
  3413. SiS_PanelDelay(SiS_Pr, 3);
  3414. }
  3415. }
  3416. if(!(SiS_IsNotM650orLater(SiS_Pr))) {
  3417. /* if(SiS_Pr->ChipType < SIS_340) {*/
  3418. tempah = 0xef;
  3419. if(SiS_IsVAMode(SiS_Pr)) tempah = 0xf7;
  3420. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x4c,tempah);
  3421. /*}*/
  3422. }
  3423. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3424. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1F,~0x10);
  3425. }
  3426. tempah = 0x3f;
  3427. if(SiS_IsDualEdge(SiS_Pr)) {
  3428. tempah = 0x7f;
  3429. if(!(SiS_IsVAMode(SiS_Pr))) tempah = 0xbf;
  3430. }
  3431. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1F,tempah);
  3432. if((SiS_IsVAMode(SiS_Pr)) ||
  3433. ((SiS_Pr->SiS_VBType & VB_SISLVDS) && (modenum <= 0x13))) {
  3434. SiS_DisplayOff(SiS_Pr);
  3435. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3436. SiS_PanelDelay(SiS_Pr, 2);
  3437. }
  3438. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF);
  3439. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1E,0xDF);
  3440. }
  3441. if((!(SiS_IsVAMode(SiS_Pr))) ||
  3442. ((SiS_Pr->SiS_VBType & VB_SISLVDS) && (modenum <= 0x13))) {
  3443. if(!(SiS_IsDualEdge(SiS_Pr))) {
  3444. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xdf);
  3445. SiS_DisplayOff(SiS_Pr);
  3446. }
  3447. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x80);
  3448. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3449. SiS_PanelDelay(SiS_Pr, 2);
  3450. }
  3451. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF);
  3452. temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00);
  3453. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x10);
  3454. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF);
  3455. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,temp);
  3456. }
  3457. if(SiS_IsNotM650orLater(SiS_Pr)) {
  3458. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0x7f);
  3459. }
  3460. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3461. if( (!(SiS_IsVAMode(SiS_Pr))) &&
  3462. (!(SiS_CRT2IsLCD(SiS_Pr))) &&
  3463. (!(SiS_IsDualEdge(SiS_Pr))) ) {
  3464. if(custom1) SiS_PanelDelay(SiS_Pr, 2);
  3465. if(!didpwd) {
  3466. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFD);
  3467. }
  3468. if(custom1) SiS_PanelDelay(SiS_Pr, 4);
  3469. }
  3470. if(!custom1) {
  3471. SiS_SetReg(SiS_Pr->SiS_P3c4,0x06,pushax);
  3472. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  3473. if(SiS_IsVAorLCD(SiS_Pr)) {
  3474. SiS_PanelDelayLoop(SiS_Pr, 3, 20);
  3475. }
  3476. }
  3477. }
  3478. }
  3479. #endif /* CONFIG_FB_SIS_315 */
  3480. }
  3481. } else { /* ============ For 301 ================ */
  3482. if(SiS_Pr->ChipType < SIS_315H) {
  3483. #ifdef CONFIG_FB_SIS_300
  3484. if(!(SiS_CR36BIOSWord23b(SiS_Pr))) {
  3485. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x08);
  3486. SiS_PanelDelay(SiS_Pr, 3);
  3487. }
  3488. #endif
  3489. }
  3490. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xDF); /* disable VB */
  3491. SiS_DisplayOff(SiS_Pr);
  3492. if(SiS_Pr->ChipType >= SIS_315H) {
  3493. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x80);
  3494. }
  3495. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF); /* disable lock mode */
  3496. if(SiS_Pr->ChipType >= SIS_315H) {
  3497. temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00);
  3498. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x10);
  3499. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);
  3500. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,temp);
  3501. } else {
  3502. #ifdef CONFIG_FB_SIS_300
  3503. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF); /* disable CRT2 */
  3504. if( (!(SiS_CRT2IsLCD(SiS_Pr))) ||
  3505. (!(SiS_CR36BIOSWord23d(SiS_Pr))) ) {
  3506. SiS_PanelDelay(SiS_Pr, 2);
  3507. SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x04);
  3508. }
  3509. #endif
  3510. }
  3511. }
  3512. } else { /* ============ For LVDS =============*/
  3513. if(SiS_Pr->ChipType < SIS_315H) {
  3514. #ifdef CONFIG_FB_SIS_300 /* 300 series */
  3515. if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) {
  3516. SiS_SetCH700x(SiS_Pr,0x0E,0x09);
  3517. }
  3518. if(SiS_Pr->ChipType == SIS_730) {
  3519. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x11) & 0x08)) {
  3520. SiS_WaitVBRetrace(SiS_Pr);
  3521. }
  3522. if(!(SiS_CR36BIOSWord23b(SiS_Pr))) {
  3523. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x08);
  3524. SiS_PanelDelay(SiS_Pr, 3);
  3525. }
  3526. } else {
  3527. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x11) & 0x08)) {
  3528. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x40)) {
  3529. if(!(SiS_CR36BIOSWord23b(SiS_Pr))) {
  3530. SiS_WaitVBRetrace(SiS_Pr);
  3531. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x06) & 0x1c)) {
  3532. SiS_DisplayOff(SiS_Pr);
  3533. }
  3534. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x08);
  3535. SiS_PanelDelay(SiS_Pr, 3);
  3536. }
  3537. }
  3538. }
  3539. }
  3540. SiS_DisplayOff(SiS_Pr);
  3541. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF);
  3542. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF);
  3543. SiS_UnLockCRT2(SiS_Pr);
  3544. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x01,0x80);
  3545. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x02,0x40);
  3546. if( (!(SiS_CRT2IsLCD(SiS_Pr))) ||
  3547. (!(SiS_CR36BIOSWord23d(SiS_Pr))) ) {
  3548. SiS_PanelDelay(SiS_Pr, 2);
  3549. SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x04);
  3550. }
  3551. #endif /* CONFIG_FB_SIS_300 */
  3552. } else {
  3553. #ifdef CONFIG_FB_SIS_315 /* 315 series */
  3554. if(!(SiS_IsNotM650orLater(SiS_Pr))) {
  3555. /*if(SiS_Pr->ChipType < SIS_340) { */ /* XGI needs this */
  3556. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x4c,~0x18);
  3557. /* } */
  3558. }
  3559. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  3560. if(SiS_Pr->ChipType == SIS_740) {
  3561. temp = SiS_GetCH701x(SiS_Pr,0x61);
  3562. if(temp < 1) {
  3563. SiS_SetCH701x(SiS_Pr,0x76,0xac);
  3564. SiS_SetCH701x(SiS_Pr,0x66,0x00);
  3565. }
  3566. if( (!(SiS_IsDualEdge(SiS_Pr))) ||
  3567. (SiS_IsTVOrYPbPrOrScart(SiS_Pr)) ) {
  3568. SiS_SetCH701x(SiS_Pr,0x49,0x3e);
  3569. }
  3570. }
  3571. if( (!(SiS_IsDualEdge(SiS_Pr))) ||
  3572. (SiS_IsVAMode(SiS_Pr)) ) {
  3573. SiS_Chrontel701xBLOff(SiS_Pr);
  3574. SiS_Chrontel701xOff(SiS_Pr);
  3575. }
  3576. if(SiS_Pr->ChipType != SIS_740) {
  3577. if( (!(SiS_IsDualEdge(SiS_Pr))) ||
  3578. (SiS_IsTVOrYPbPrOrScart(SiS_Pr)) ) {
  3579. SiS_SetCH701x(SiS_Pr,0x49,0x01);
  3580. }
  3581. }
  3582. }
  3583. if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
  3584. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x08);
  3585. SiS_PanelDelay(SiS_Pr, 3);
  3586. }
  3587. if( (SiS_Pr->SiS_IF_DEF_CH70xx == 0) ||
  3588. (!(SiS_IsDualEdge(SiS_Pr))) ||
  3589. (!(SiS_IsTVOrYPbPrOrScart(SiS_Pr))) ) {
  3590. SiS_DisplayOff(SiS_Pr);
  3591. }
  3592. if( (SiS_Pr->SiS_IF_DEF_CH70xx == 0) ||
  3593. (!(SiS_IsDualEdge(SiS_Pr))) ||
  3594. (!(SiS_IsVAMode(SiS_Pr))) ) {
  3595. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x80);
  3596. }
  3597. if(SiS_Pr->ChipType == SIS_740) {
  3598. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0x7f);
  3599. }
  3600. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF);
  3601. if( (SiS_Pr->SiS_IF_DEF_CH70xx == 0) ||
  3602. (!(SiS_IsDualEdge(SiS_Pr))) ||
  3603. (!(SiS_IsVAMode(SiS_Pr))) ) {
  3604. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF);
  3605. }
  3606. if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
  3607. if(SiS_CRT2IsLCD(SiS_Pr)) {
  3608. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xdf);
  3609. if(SiS_Pr->ChipType == SIS_550) {
  3610. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xbf);
  3611. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xef);
  3612. }
  3613. }
  3614. } else {
  3615. if(SiS_Pr->ChipType == SIS_740) {
  3616. if(SiS_IsLCDOrLCDA(SiS_Pr)) {
  3617. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xdf);
  3618. }
  3619. } else if(SiS_IsVAMode(SiS_Pr)) {
  3620. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xdf);
  3621. }
  3622. }
  3623. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  3624. if(SiS_IsDualEdge(SiS_Pr)) {
  3625. /* SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xff); */
  3626. } else {
  3627. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xfb);
  3628. }
  3629. }
  3630. SiS_UnLockCRT2(SiS_Pr);
  3631. if(SiS_Pr->ChipType == SIS_550) {
  3632. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x01,0x80); /* DirectDVD PAL?*/
  3633. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x02,0x40); /* VB clock / 4 ? */
  3634. } else if( (SiS_Pr->SiS_IF_DEF_CH70xx == 0) ||
  3635. (!(SiS_IsDualEdge(SiS_Pr))) ||
  3636. (!(SiS_IsVAMode(SiS_Pr))) ) {
  3637. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0xf7);
  3638. }
  3639. if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
  3640. if(SiS_CRT2IsLCD(SiS_Pr)) {
  3641. if(!(SiS_WeHaveBacklightCtrl(SiS_Pr))) {
  3642. SiS_PanelDelay(SiS_Pr, 2);
  3643. SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x04);
  3644. }
  3645. }
  3646. }
  3647. #endif /* CONFIG_FB_SIS_315 */
  3648. } /* 315 series */
  3649. } /* LVDS */
  3650. }
  3651. /*********************************************/
  3652. /* ENABLE VIDEO BRIDGE */
  3653. /*********************************************/
  3654. /* NEVER use any variables (VBInfo), this will be called
  3655. * from outside the context of a mode switch!
  3656. * MUST call getVBType before calling this
  3657. */
  3658. static
  3659. void
  3660. SiS_EnableBridge(struct SiS_Private *SiS_Pr)
  3661. {
  3662. unsigned short temp=0, tempah;
  3663. #ifdef CONFIG_FB_SIS_315
  3664. unsigned short temp1, pushax=0;
  3665. bool delaylong = false;
  3666. #endif
  3667. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  3668. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) { /* ====== For 301B et al ====== */
  3669. if(SiS_Pr->ChipType < SIS_315H) {
  3670. #ifdef CONFIG_FB_SIS_300 /* 300 series */
  3671. if(SiS_CRT2IsLCD(SiS_Pr)) {
  3672. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3673. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x02);
  3674. } else if(SiS_Pr->SiS_VBType & VB_NoLCD) {
  3675. SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x00);
  3676. }
  3677. if(SiS_Pr->SiS_VBType & (VB_SISLVDS | VB_NoLCD)) {
  3678. if(!(SiS_CR36BIOSWord23d(SiS_Pr))) {
  3679. SiS_PanelDelay(SiS_Pr, 0);
  3680. }
  3681. }
  3682. }
  3683. if((SiS_Pr->SiS_VBType & VB_NoLCD) &&
  3684. (SiS_CRT2IsLCD(SiS_Pr))) {
  3685. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20); /* Enable CRT2 */
  3686. SiS_DisplayOn(SiS_Pr);
  3687. SiS_UnLockCRT2(SiS_Pr);
  3688. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x02,0xBF);
  3689. if(SiS_BridgeInSlavemode(SiS_Pr)) {
  3690. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x01,0x1F);
  3691. } else {
  3692. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x01,0x1F,0x40);
  3693. }
  3694. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x40)) {
  3695. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x16) & 0x10)) {
  3696. if(!(SiS_CR36BIOSWord23b(SiS_Pr))) {
  3697. SiS_PanelDelay(SiS_Pr, 1);
  3698. }
  3699. SiS_WaitVBRetrace(SiS_Pr);
  3700. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x00);
  3701. }
  3702. }
  3703. } else {
  3704. temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x32) & 0xDF; /* lock mode */
  3705. if(SiS_BridgeInSlavemode(SiS_Pr)) {
  3706. tempah = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  3707. if(!(tempah & SetCRT2ToRAMDAC)) temp |= 0x20;
  3708. }
  3709. SiS_SetReg(SiS_Pr->SiS_P3c4,0x32,temp);
  3710. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);
  3711. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x00,0x1F,0x20); /* enable VB processor */
  3712. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x1F,0xC0);
  3713. SiS_DisplayOn(SiS_Pr);
  3714. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3715. if(SiS_CRT2IsLCD(SiS_Pr)) {
  3716. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x16) & 0x10)) {
  3717. if(!(SiS_CR36BIOSWord23b(SiS_Pr))) {
  3718. SiS_PanelDelay(SiS_Pr, 1);
  3719. }
  3720. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x01);
  3721. }
  3722. }
  3723. }
  3724. }
  3725. #endif /* CONFIG_FB_SIS_300 */
  3726. } else {
  3727. #ifdef CONFIG_FB_SIS_315 /* 315 series */
  3728. #ifdef SET_EMI
  3729. unsigned char r30=0, r31=0, r32=0, r33=0, cr36=0;
  3730. int didpwd = 0;
  3731. /* unsigned short emidelay=0; */
  3732. #endif
  3733. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3734. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1f,0xef);
  3735. #ifdef SET_EMI
  3736. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  3737. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
  3738. }
  3739. #endif
  3740. }
  3741. if(!(SiS_IsNotM650orLater(SiS_Pr))) {
  3742. /*if(SiS_Pr->ChipType < SIS_340) { */
  3743. tempah = 0x10;
  3744. if(SiS_LCDAEnabled(SiS_Pr)) {
  3745. if(SiS_TVEnabled(SiS_Pr)) tempah = 0x18;
  3746. else tempah = 0x08;
  3747. }
  3748. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x4c,tempah);
  3749. /*}*/
  3750. }
  3751. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3752. SiS_SetRegByte(SiS_Pr->SiS_P3c6,0x00);
  3753. SiS_DisplayOff(SiS_Pr);
  3754. pushax = SiS_GetReg(SiS_Pr->SiS_P3c4,0x06);
  3755. if(IS_SIS740) {
  3756. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x06,0xE3);
  3757. }
  3758. didpwd = SiS_HandlePWD(SiS_Pr);
  3759. if(SiS_IsVAorLCD(SiS_Pr)) {
  3760. if(!didpwd) {
  3761. if(!(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x26) & 0x02)) {
  3762. SiS_PanelDelayLoop(SiS_Pr, 3, 2);
  3763. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x02);
  3764. SiS_PanelDelayLoop(SiS_Pr, 3, 2);
  3765. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  3766. SiS_GenericDelay(SiS_Pr, 17664);
  3767. }
  3768. }
  3769. } else {
  3770. SiS_PanelDelayLoop(SiS_Pr, 3, 2);
  3771. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  3772. SiS_GenericDelay(SiS_Pr, 17664);
  3773. }
  3774. }
  3775. }
  3776. if(!(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & 0x40)) {
  3777. SiS_PanelDelayLoop(SiS_Pr, 3, 10);
  3778. delaylong = true;
  3779. }
  3780. }
  3781. if(!(SiS_IsVAMode(SiS_Pr))) {
  3782. temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x32) & 0xDF;
  3783. if(SiS_BridgeInSlavemode(SiS_Pr)) {
  3784. tempah = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  3785. if(!(tempah & SetCRT2ToRAMDAC)) {
  3786. if(!(SiS_LCDAEnabled(SiS_Pr))) temp |= 0x20;
  3787. }
  3788. }
  3789. SiS_SetReg(SiS_Pr->SiS_P3c4,0x32,temp);
  3790. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20); /* enable CRT2 */
  3791. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0x7f);
  3792. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2e,0x80);
  3793. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3794. SiS_PanelDelay(SiS_Pr, 2);
  3795. }
  3796. } else {
  3797. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1e,0x20);
  3798. }
  3799. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x00,0x1f,0x20);
  3800. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2e,0x80);
  3801. if(SiS_Pr->SiS_VBType & VB_SISPOWER) {
  3802. if( (SiS_LCDAEnabled(SiS_Pr)) ||
  3803. (SiS_CRT2IsLCD(SiS_Pr)) ) {
  3804. /* Enable "LVDS PLL power on" (even on 301C) */
  3805. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x2a,0x7f);
  3806. /* Enable "LVDS Driver Power on" (even on 301C) */
  3807. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x7f);
  3808. }
  3809. }
  3810. tempah = 0xc0;
  3811. if(SiS_IsDualEdge(SiS_Pr)) {
  3812. tempah = 0x80;
  3813. if(!(SiS_IsVAMode(SiS_Pr))) tempah = 0x40;
  3814. }
  3815. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x1F,tempah);
  3816. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3817. SiS_PanelDelay(SiS_Pr, 2);
  3818. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x1f,0x10);
  3819. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2e,0x80);
  3820. if(SiS_Pr->SiS_CustomT != CUT_CLEVO1400) {
  3821. #ifdef SET_EMI
  3822. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  3823. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
  3824. SiS_GenericDelay(SiS_Pr, 2048);
  3825. }
  3826. #endif
  3827. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x27,0x0c);
  3828. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  3829. #ifdef SET_EMI
  3830. cr36 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36);
  3831. if(SiS_Pr->SiS_ROMNew) {
  3832. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  3833. unsigned short romptr = GetLCDStructPtr661_2(SiS_Pr);
  3834. if(romptr) {
  3835. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x30,0x20); /* Reset */
  3836. SiS_Pr->EMI_30 = 0;
  3837. SiS_Pr->EMI_31 = ROMAddr[romptr + SiS_Pr->SiS_EMIOffset + 0];
  3838. SiS_Pr->EMI_32 = ROMAddr[romptr + SiS_Pr->SiS_EMIOffset + 1];
  3839. SiS_Pr->EMI_33 = ROMAddr[romptr + SiS_Pr->SiS_EMIOffset + 2];
  3840. if(ROMAddr[romptr + 1] & 0x10) SiS_Pr->EMI_30 = 0x40;
  3841. /* emidelay = SISGETROMW((romptr + 0x22)); */
  3842. SiS_Pr->HaveEMI = SiS_Pr->HaveEMILCD = SiS_Pr->OverruleEMI = true;
  3843. }
  3844. }
  3845. /* (P4_30|0x40) */
  3846. /* Compal 1400x1050: 0x05, 0x60, 0x00 YES (1.10.7w; CR36=69) */
  3847. /* Compal 1400x1050: 0x0d, 0x70, 0x40 YES (1.10.7x; CR36=69) */
  3848. /* Acer 1280x1024: 0x12, 0xd0, 0x6b NO (1.10.9k; CR36=73) */
  3849. /* Compaq 1280x1024: 0x0d, 0x70, 0x6b YES (1.12.04b; CR36=03) */
  3850. /* Clevo 1024x768: 0x05, 0x60, 0x33 NO (1.10.8e; CR36=12, DL!) */
  3851. /* Clevo 1024x768: 0x0d, 0x70, 0x40 (if type == 3) YES (1.10.8y; CR36=?2) */
  3852. /* Clevo 1024x768: 0x05, 0x60, 0x33 (if type != 3) YES (1.10.8y; CR36=?2) */
  3853. /* Asus 1024x768: ? ? (1.10.8o; CR36=?2) */
  3854. /* Asus 1024x768: 0x08, 0x10, 0x3c (problematic) YES (1.10.8q; CR36=22) */
  3855. if(SiS_Pr->HaveEMI) {
  3856. r30 = SiS_Pr->EMI_30; r31 = SiS_Pr->EMI_31;
  3857. r32 = SiS_Pr->EMI_32; r33 = SiS_Pr->EMI_33;
  3858. } else {
  3859. r30 = 0;
  3860. }
  3861. /* EMI_30 is read at driver start; however, the BIOS sets this
  3862. * (if it is used) only if the LCD is in use. In case we caught
  3863. * the machine while on TV output, this bit is not set and we
  3864. * don't know if it should be set - hence our detection is wrong.
  3865. * Work-around this here:
  3866. */
  3867. if((!SiS_Pr->HaveEMI) || (!SiS_Pr->HaveEMILCD)) {
  3868. switch((cr36 & 0x0f)) {
  3869. case 2:
  3870. r30 |= 0x40;
  3871. if(SiS_Pr->SiS_CustomT == CUT_CLEVO1024) r30 &= ~0x40;
  3872. if(!SiS_Pr->HaveEMI) {
  3873. r31 = 0x05; r32 = 0x60; r33 = 0x33;
  3874. if((cr36 & 0xf0) == 0x30) {
  3875. r31 = 0x0d; r32 = 0x70; r33 = 0x40;
  3876. }
  3877. }
  3878. break;
  3879. case 3: /* 1280x1024 */
  3880. if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) r30 |= 0x40;
  3881. if(!SiS_Pr->HaveEMI) {
  3882. r31 = 0x12; r32 = 0xd0; r33 = 0x6b;
  3883. if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) {
  3884. r31 = 0x0d; r32 = 0x70; r33 = 0x6b;
  3885. }
  3886. }
  3887. break;
  3888. case 9: /* 1400x1050 */
  3889. r30 |= 0x40;
  3890. if(!SiS_Pr->HaveEMI) {
  3891. r31 = 0x05; r32 = 0x60; r33 = 0x00;
  3892. if(SiS_Pr->SiS_CustomT == CUT_COMPAL1400_2) {
  3893. r31 = 0x0d; r32 = 0x70; r33 = 0x40; /* BIOS values */
  3894. }
  3895. }
  3896. break;
  3897. case 11: /* 1600x1200 - unknown */
  3898. r30 |= 0x40;
  3899. if(!SiS_Pr->HaveEMI) {
  3900. r31 = 0x05; r32 = 0x60; r33 = 0x00;
  3901. }
  3902. }
  3903. }
  3904. /* BIOS values don't work so well sometimes */
  3905. if(!SiS_Pr->OverruleEMI) {
  3906. #ifdef COMPAL_HACK
  3907. if(SiS_Pr->SiS_CustomT == CUT_COMPAL1400_2) {
  3908. if((cr36 & 0x0f) == 0x09) {
  3909. r30 = 0x60; r31 = 0x05; r32 = 0x60; r33 = 0x00;
  3910. }
  3911. }
  3912. #endif
  3913. #ifdef COMPAQ_HACK
  3914. if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) {
  3915. if((cr36 & 0x0f) == 0x03) {
  3916. r30 = 0x20; r31 = 0x12; r32 = 0xd0; r33 = 0x6b;
  3917. }
  3918. }
  3919. #endif
  3920. #ifdef ASUS_HACK
  3921. if(SiS_Pr->SiS_CustomT == CUT_ASUSA2H_2) {
  3922. if((cr36 & 0x0f) == 0x02) {
  3923. /* r30 = 0x60; r31 = 0x05; r32 = 0x60; r33 = 0x33; */ /* rev 2 */
  3924. /* r30 = 0x20; r31 = 0x05; r32 = 0x60; r33 = 0x33; */ /* rev 3 */
  3925. /* r30 = 0x60; r31 = 0x0d; r32 = 0x70; r33 = 0x40; */ /* rev 4 */
  3926. /* r30 = 0x20; r31 = 0x0d; r32 = 0x70; r33 = 0x40; */ /* rev 5 */
  3927. }
  3928. }
  3929. #endif
  3930. }
  3931. if(!(SiS_Pr->OverruleEMI && (!r30) && (!r31) && (!r32) && (!r33))) {
  3932. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x30,0x20); /* Reset */
  3933. SiS_GenericDelay(SiS_Pr, 2048);
  3934. }
  3935. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x31,r31);
  3936. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x32,r32);
  3937. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x33,r33);
  3938. #endif /* SET_EMI */
  3939. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x34,0x10);
  3940. #ifdef SET_EMI
  3941. if( (SiS_LCDAEnabled(SiS_Pr)) ||
  3942. (SiS_CRT2IsLCD(SiS_Pr)) ) {
  3943. if(r30 & 0x40) {
  3944. /*SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x2a,0x80);*/
  3945. SiS_PanelDelayLoop(SiS_Pr, 3, 5);
  3946. if(delaylong) {
  3947. SiS_PanelDelayLoop(SiS_Pr, 3, 5);
  3948. delaylong = false;
  3949. }
  3950. SiS_WaitVBRetrace(SiS_Pr);
  3951. SiS_WaitVBRetrace(SiS_Pr);
  3952. if(SiS_Pr->SiS_CustomT == CUT_ASUSA2H_2) {
  3953. SiS_GenericDelay(SiS_Pr, 1280);
  3954. }
  3955. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x30,0x40); /* Enable */
  3956. /*SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x2a,0x7f);*/
  3957. }
  3958. }
  3959. #endif
  3960. }
  3961. }
  3962. if(!(SiS_WeHaveBacklightCtrl(SiS_Pr))) {
  3963. if(SiS_IsVAorLCD(SiS_Pr)) {
  3964. SiS_PanelDelayLoop(SiS_Pr, 3, 10);
  3965. if(delaylong) {
  3966. SiS_PanelDelayLoop(SiS_Pr, 3, 10);
  3967. }
  3968. SiS_WaitVBRetrace(SiS_Pr);
  3969. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  3970. SiS_GenericDelay(SiS_Pr, 2048);
  3971. SiS_WaitVBRetrace(SiS_Pr);
  3972. }
  3973. if(!didpwd) {
  3974. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x01);
  3975. } else {
  3976. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x03);
  3977. }
  3978. }
  3979. }
  3980. SiS_SetReg(SiS_Pr->SiS_P3c4,0x06,pushax);
  3981. SiS_DisplayOn(SiS_Pr);
  3982. SiS_SetRegByte(SiS_Pr->SiS_P3c6,0xff);
  3983. }
  3984. if(!(SiS_WeHaveBacklightCtrl(SiS_Pr))) {
  3985. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x00,0x7f);
  3986. }
  3987. #endif /* CONFIG_FB_SIS_315 */
  3988. }
  3989. } else { /* ============ For 301 ================ */
  3990. if(SiS_Pr->ChipType < SIS_315H) {
  3991. if(SiS_CRT2IsLCD(SiS_Pr)) {
  3992. SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x00);
  3993. SiS_PanelDelay(SiS_Pr, 0);
  3994. }
  3995. }
  3996. temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x32) & 0xDF; /* lock mode */
  3997. if(SiS_BridgeInSlavemode(SiS_Pr)) {
  3998. tempah = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  3999. if(!(tempah & SetCRT2ToRAMDAC)) temp |= 0x20;
  4000. }
  4001. SiS_SetReg(SiS_Pr->SiS_P3c4,0x32,temp);
  4002. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20); /* enable CRT2 */
  4003. if(SiS_Pr->ChipType >= SIS_315H) {
  4004. temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x2E);
  4005. if(!(temp & 0x80)) {
  4006. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2E,0x80); /* BVBDOENABLE=1 */
  4007. }
  4008. }
  4009. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x00,0x1F,0x20); /* enable VB processor */
  4010. SiS_VBLongWait(SiS_Pr);
  4011. SiS_DisplayOn(SiS_Pr);
  4012. if(SiS_Pr->ChipType >= SIS_315H) {
  4013. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x00,0x7f);
  4014. }
  4015. SiS_VBLongWait(SiS_Pr);
  4016. if(SiS_Pr->ChipType < SIS_315H) {
  4017. if(SiS_CRT2IsLCD(SiS_Pr)) {
  4018. SiS_PanelDelay(SiS_Pr, 1);
  4019. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x00);
  4020. }
  4021. }
  4022. }
  4023. } else { /* =================== For LVDS ================== */
  4024. if(SiS_Pr->ChipType < SIS_315H) {
  4025. #ifdef CONFIG_FB_SIS_300 /* 300 series */
  4026. if(SiS_CRT2IsLCD(SiS_Pr)) {
  4027. if(SiS_Pr->ChipType == SIS_730) {
  4028. SiS_PanelDelay(SiS_Pr, 1);
  4029. SiS_PanelDelay(SiS_Pr, 1);
  4030. SiS_PanelDelay(SiS_Pr, 1);
  4031. }
  4032. SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x00);
  4033. if(!(SiS_CR36BIOSWord23d(SiS_Pr))) {
  4034. SiS_PanelDelay(SiS_Pr, 0);
  4035. }
  4036. }
  4037. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);
  4038. SiS_DisplayOn(SiS_Pr);
  4039. SiS_UnLockCRT2(SiS_Pr);
  4040. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x02,0xBF);
  4041. if(SiS_BridgeInSlavemode(SiS_Pr)) {
  4042. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x01,0x1F);
  4043. } else {
  4044. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x01,0x1F,0x40);
  4045. }
  4046. if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) {
  4047. if(!(SiS_CRT2IsLCD(SiS_Pr))) {
  4048. SiS_WaitVBRetrace(SiS_Pr);
  4049. SiS_SetCH700x(SiS_Pr,0x0E,0x0B);
  4050. }
  4051. }
  4052. if(SiS_CRT2IsLCD(SiS_Pr)) {
  4053. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x40)) {
  4054. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x16) & 0x10)) {
  4055. if(!(SiS_CR36BIOSWord23b(SiS_Pr))) {
  4056. SiS_PanelDelay(SiS_Pr, 1);
  4057. SiS_PanelDelay(SiS_Pr, 1);
  4058. }
  4059. SiS_WaitVBRetrace(SiS_Pr);
  4060. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x00);
  4061. }
  4062. }
  4063. }
  4064. #endif /* CONFIG_FB_SIS_300 */
  4065. } else {
  4066. #ifdef CONFIG_FB_SIS_315 /* 315 series */
  4067. if(!(SiS_IsNotM650orLater(SiS_Pr))) {
  4068. /*if(SiS_Pr->ChipType < SIS_340) {*/ /* XGI needs this */
  4069. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x4c,0x18);
  4070. /*}*/
  4071. }
  4072. if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
  4073. if(SiS_CRT2IsLCD(SiS_Pr)) {
  4074. SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x00);
  4075. SiS_PanelDelay(SiS_Pr, 0);
  4076. }
  4077. }
  4078. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);
  4079. SiS_UnLockCRT2(SiS_Pr);
  4080. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0xf7);
  4081. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  4082. temp = SiS_GetCH701x(SiS_Pr,0x66);
  4083. temp &= 0x20;
  4084. SiS_Chrontel701xBLOff(SiS_Pr);
  4085. }
  4086. if(SiS_Pr->ChipType != SIS_550) {
  4087. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0x7f);
  4088. }
  4089. if(SiS_Pr->ChipType == SIS_740) {
  4090. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  4091. if(SiS_IsLCDOrLCDA(SiS_Pr)) {
  4092. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x20);
  4093. }
  4094. }
  4095. }
  4096. temp1 = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x2E);
  4097. if(!(temp1 & 0x80)) {
  4098. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2E,0x80);
  4099. }
  4100. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  4101. if(temp) {
  4102. SiS_Chrontel701xBLOn(SiS_Pr);
  4103. }
  4104. }
  4105. if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
  4106. if(SiS_CRT2IsLCD(SiS_Pr)) {
  4107. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x20);
  4108. if(SiS_Pr->ChipType == SIS_550) {
  4109. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x40);
  4110. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x10);
  4111. }
  4112. }
  4113. } else if(SiS_IsVAMode(SiS_Pr)) {
  4114. if(SiS_Pr->ChipType != SIS_740) {
  4115. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x20);
  4116. }
  4117. }
  4118. if(!(SiS_WeHaveBacklightCtrl(SiS_Pr))) {
  4119. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x00,0x7f);
  4120. }
  4121. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  4122. if(SiS_IsTVOrYPbPrOrScart(SiS_Pr)) {
  4123. SiS_Chrontel701xOn(SiS_Pr);
  4124. }
  4125. if( (SiS_IsVAMode(SiS_Pr)) ||
  4126. (SiS_IsLCDOrLCDA(SiS_Pr)) ) {
  4127. SiS_ChrontelDoSomething1(SiS_Pr);
  4128. }
  4129. }
  4130. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  4131. if(!(SiS_WeHaveBacklightCtrl(SiS_Pr))) {
  4132. if( (SiS_IsVAMode(SiS_Pr)) ||
  4133. (SiS_IsLCDOrLCDA(SiS_Pr)) ) {
  4134. SiS_Chrontel701xBLOn(SiS_Pr);
  4135. SiS_ChrontelInitTVVSync(SiS_Pr);
  4136. }
  4137. }
  4138. } else if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
  4139. if(!(SiS_WeHaveBacklightCtrl(SiS_Pr))) {
  4140. if(SiS_CRT2IsLCD(SiS_Pr)) {
  4141. SiS_PanelDelay(SiS_Pr, 1);
  4142. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x00);
  4143. }
  4144. }
  4145. }
  4146. #endif /* CONFIG_FB_SIS_315 */
  4147. } /* 310 series */
  4148. } /* LVDS */
  4149. }
  4150. /*********************************************/
  4151. /* SET PART 1 REGISTER GROUP */
  4152. /*********************************************/
  4153. /* Set CRT2 OFFSET / PITCH */
  4154. static void
  4155. SiS_SetCRT2Offset(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  4156. unsigned short RRTI)
  4157. {
  4158. unsigned short offset;
  4159. unsigned char temp;
  4160. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) return;
  4161. offset = SiS_GetOffset(SiS_Pr,ModeNo,ModeIdIndex,RRTI);
  4162. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x07,(offset & 0xFF));
  4163. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x09,(offset >> 8));
  4164. temp = (unsigned char)(((offset >> 3) & 0xFF) + 1);
  4165. if(offset & 0x07) temp++;
  4166. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x03,temp);
  4167. }
  4168. /* Set CRT2 sync and PanelLink mode */
  4169. static void
  4170. SiS_SetCRT2Sync(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short RefreshRateTableIndex)
  4171. {
  4172. unsigned short tempah=0, tempbl, infoflag;
  4173. tempbl = 0xC0;
  4174. if(SiS_Pr->UseCustomMode) {
  4175. infoflag = SiS_Pr->CInfoFlag;
  4176. } else {
  4177. infoflag = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
  4178. }
  4179. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { /* LVDS */
  4180. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  4181. tempah = 0;
  4182. } else if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && (SiS_Pr->SiS_LCDInfo & LCDSync)) {
  4183. tempah = SiS_Pr->SiS_LCDInfo;
  4184. } else tempah = infoflag >> 8;
  4185. tempah &= 0xC0;
  4186. tempah |= 0x20;
  4187. if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10;
  4188. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  4189. if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) ||
  4190. (SiS_Pr->SiS_CustomT == CUT_BARCO1024)) {
  4191. tempah |= 0xf0;
  4192. }
  4193. if( (SiS_Pr->SiS_IF_DEF_FSTN) ||
  4194. (SiS_Pr->SiS_IF_DEF_DSTN) ||
  4195. (SiS_Pr->SiS_IF_DEF_TRUMPION) ||
  4196. (SiS_Pr->SiS_CustomT == CUT_PANEL848) ||
  4197. (SiS_Pr->SiS_CustomT == CUT_PANEL856) ) {
  4198. tempah |= 0x30;
  4199. }
  4200. if( (SiS_Pr->SiS_IF_DEF_FSTN) ||
  4201. (SiS_Pr->SiS_IF_DEF_DSTN) ) {
  4202. tempah &= ~0xc0;
  4203. }
  4204. }
  4205. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  4206. if(SiS_Pr->ChipType >= SIS_315H) {
  4207. tempah >>= 3;
  4208. tempah &= 0x18;
  4209. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,0xE7,tempah);
  4210. /* Don't care about 12/18/24 bit mode - TV is via VGA, not PL */
  4211. } else {
  4212. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,0xe0);
  4213. }
  4214. } else {
  4215. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah);
  4216. }
  4217. } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
  4218. if(SiS_Pr->ChipType < SIS_315H) {
  4219. #ifdef CONFIG_FB_SIS_300 /* ---- 300 series --- */
  4220. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) { /* 630 - 301B(-DH) */
  4221. tempah = infoflag >> 8;
  4222. tempbl = 0;
  4223. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  4224. if(SiS_Pr->SiS_LCDInfo & LCDSync) {
  4225. tempah = SiS_Pr->SiS_LCDInfo;
  4226. tempbl = (tempah >> 6) & 0x03;
  4227. }
  4228. }
  4229. tempah &= 0xC0;
  4230. tempah |= 0x20;
  4231. if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10;
  4232. tempah |= 0xc0;
  4233. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah);
  4234. if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && (!(SiS_Pr->SiS_VBType & VB_NoLCD))) {
  4235. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1a,0xf0,tempbl);
  4236. }
  4237. } else { /* 630 - 301 */
  4238. tempah = ((infoflag >> 8) & 0xc0) | 0x20;
  4239. if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10;
  4240. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah);
  4241. }
  4242. #endif /* CONFIG_FB_SIS_300 */
  4243. } else {
  4244. #ifdef CONFIG_FB_SIS_315 /* ------- 315 series ------ */
  4245. if(SiS_Pr->SiS_VBType & VB_SISLVDS) { /* 315 - LVDS */
  4246. tempbl = 0;
  4247. if((SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) &&
  4248. (SiS_Pr->SiS_LCDResInfo == Panel_1280x1024)) {
  4249. tempah = infoflag >> 8;
  4250. if(SiS_Pr->SiS_LCDInfo & LCDSync) {
  4251. tempbl = ((SiS_Pr->SiS_LCDInfo & 0xc0) >> 6);
  4252. }
  4253. } else if((SiS_Pr->SiS_CustomT == CUT_CLEVO1400) &&
  4254. (SiS_Pr->SiS_LCDResInfo == Panel_1400x1050)) {
  4255. tempah = infoflag >> 8;
  4256. tempbl = 0x03;
  4257. } else {
  4258. tempah = SiS_GetReg(SiS_Pr->SiS_P3d4,0x37);
  4259. tempbl = (tempah >> 6) & 0x03;
  4260. tempbl |= 0x08;
  4261. if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempbl |= 0x04;
  4262. }
  4263. tempah &= 0xC0;
  4264. tempah |= 0x20;
  4265. if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10;
  4266. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) tempah |= 0xc0;
  4267. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah);
  4268. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  4269. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  4270. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1a,0xf0,tempbl);
  4271. }
  4272. }
  4273. } else { /* 315 - TMDS */
  4274. tempah = tempbl = infoflag >> 8;
  4275. if(!SiS_Pr->UseCustomMode) {
  4276. tempbl = 0;
  4277. if((SiS_Pr->SiS_VBType & VB_SIS30xC) && (SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) {
  4278. if(ModeNo <= 0x13) {
  4279. tempah = SiS_GetRegByte((SiS_Pr->SiS_P3ca+0x02));
  4280. }
  4281. }
  4282. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4283. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  4284. if(SiS_Pr->SiS_LCDInfo & LCDSync) {
  4285. tempah = SiS_Pr->SiS_LCDInfo;
  4286. tempbl = (tempah >> 6) & 0x03;
  4287. }
  4288. }
  4289. }
  4290. }
  4291. tempah &= 0xC0;
  4292. tempah |= 0x20;
  4293. if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10;
  4294. if(SiS_Pr->SiS_VBType & VB_NoLCD) {
  4295. /* Imitate BIOS bug */
  4296. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) tempah |= 0xc0;
  4297. }
  4298. if((SiS_Pr->SiS_VBType & VB_SIS30xC) && (SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) {
  4299. tempah >>= 3;
  4300. tempah &= 0x18;
  4301. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,0xe7,tempah);
  4302. } else {
  4303. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah);
  4304. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  4305. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  4306. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1a,0xf0,tempbl);
  4307. }
  4308. }
  4309. }
  4310. }
  4311. #endif /* CONFIG_FB_SIS_315 */
  4312. }
  4313. }
  4314. }
  4315. /* Set CRT2 FIFO on 300/540/630/730 */
  4316. #ifdef CONFIG_FB_SIS_300
  4317. static void
  4318. SiS_SetCRT2FIFO_300(struct SiS_Private *SiS_Pr,unsigned short ModeNo)
  4319. {
  4320. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  4321. unsigned short temp, index, modeidindex, refreshratetableindex;
  4322. unsigned short VCLK = 0, MCLK, colorth = 0, data2 = 0;
  4323. unsigned short tempbx, tempcl, CRT1ModeNo, CRT2ModeNo, SelectRate_backup;
  4324. unsigned int data, pci50, pciA0;
  4325. static const unsigned char colortharray[] = {
  4326. 1, 1, 2, 2, 3, 4
  4327. };
  4328. SelectRate_backup = SiS_Pr->SiS_SelectCRT2Rate;
  4329. if(!SiS_Pr->CRT1UsesCustomMode) {
  4330. CRT1ModeNo = SiS_Pr->SiS_CRT1Mode; /* get CRT1 ModeNo */
  4331. SiS_SearchModeID(SiS_Pr, &CRT1ModeNo, &modeidindex);
  4332. SiS_Pr->SiS_SetFlag &= (~ProgrammingCRT2);
  4333. SiS_Pr->SiS_SelectCRT2Rate = 0;
  4334. refreshratetableindex = SiS_GetRatePtr(SiS_Pr, CRT1ModeNo, modeidindex);
  4335. if(CRT1ModeNo >= 0x13) {
  4336. /* Get VCLK */
  4337. index = SiS_GetRefCRTVCLK(SiS_Pr, refreshratetableindex, SiS_Pr->SiS_UseWide);
  4338. VCLK = SiS_Pr->SiS_VCLKData[index].CLOCK;
  4339. /* Get colordepth */
  4340. colorth = SiS_GetColorDepth(SiS_Pr,CRT1ModeNo,modeidindex) >> 1;
  4341. if(!colorth) colorth++;
  4342. }
  4343. } else {
  4344. CRT1ModeNo = 0xfe;
  4345. /* Get VCLK */
  4346. VCLK = SiS_Pr->CSRClock_CRT1;
  4347. /* Get color depth */
  4348. colorth = colortharray[((SiS_Pr->CModeFlag_CRT1 & ModeTypeMask) - 2)];
  4349. }
  4350. if(CRT1ModeNo >= 0x13) {
  4351. /* Get MCLK */
  4352. if(SiS_Pr->ChipType == SIS_300) {
  4353. index = SiS_GetReg(SiS_Pr->SiS_P3c4,0x3A);
  4354. } else {
  4355. index = SiS_GetReg(SiS_Pr->SiS_P3c4,0x1A);
  4356. }
  4357. index &= 0x07;
  4358. MCLK = SiS_Pr->SiS_MCLKData_0[index].CLOCK;
  4359. temp = ((SiS_GetReg(SiS_Pr->SiS_P3c4,0x14) >> 6) & 0x03) << 1;
  4360. if(!temp) temp++;
  4361. temp <<= 2;
  4362. data2 = temp - ((colorth * VCLK) / MCLK);
  4363. temp = (28 * 16) % data2;
  4364. data2 = (28 * 16) / data2;
  4365. if(temp) data2++;
  4366. if(SiS_Pr->ChipType == SIS_300) {
  4367. SiS_GetFIFOThresholdIndex300(SiS_Pr, &tempbx, &tempcl);
  4368. data = SiS_GetFIFOThresholdB300(tempbx, tempcl);
  4369. } else {
  4370. pci50 = sisfb_read_nbridge_pci_dword(SiS_Pr, 0x50);
  4371. pciA0 = sisfb_read_nbridge_pci_dword(SiS_Pr, 0xa0);
  4372. if(SiS_Pr->ChipType == SIS_730) {
  4373. index = (unsigned short)(((pciA0 >> 28) & 0x0f) * 3);
  4374. index += (unsigned short)(((pci50 >> 9)) & 0x03);
  4375. /* BIOS BUG (2.04.5d, 2.04.6a use ah here, which is unset!) */
  4376. index = 0; /* -- do it like the BIOS anyway... */
  4377. } else {
  4378. pci50 >>= 24;
  4379. pciA0 >>= 24;
  4380. index = (pci50 >> 1) & 0x07;
  4381. if(pci50 & 0x01) index += 6;
  4382. if(!(pciA0 & 0x01)) index += 24;
  4383. if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x14) & 0x80) index += 12;
  4384. }
  4385. data = SiS_GetLatencyFactor630(SiS_Pr, index) + 15;
  4386. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x14) & 0x80)) data += 5;
  4387. }
  4388. data += data2; /* CRT1 Request Period */
  4389. SiS_Pr->SiS_SetFlag |= ProgrammingCRT2;
  4390. SiS_Pr->SiS_SelectCRT2Rate = SelectRate_backup;
  4391. if(!SiS_Pr->UseCustomMode) {
  4392. CRT2ModeNo = ModeNo;
  4393. SiS_SearchModeID(SiS_Pr, &CRT2ModeNo, &modeidindex);
  4394. refreshratetableindex = SiS_GetRatePtr(SiS_Pr, CRT2ModeNo, modeidindex);
  4395. /* Get VCLK */
  4396. index = SiS_GetVCLK2Ptr(SiS_Pr, CRT2ModeNo, modeidindex, refreshratetableindex);
  4397. VCLK = SiS_Pr->SiS_VCLKData[index].CLOCK;
  4398. if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) || (SiS_Pr->SiS_CustomT == CUT_BARCO1024)) {
  4399. if(SiS_Pr->SiS_UseROM) {
  4400. if(ROMAddr[0x220] & 0x01) {
  4401. VCLK = ROMAddr[0x229] | (ROMAddr[0x22a] << 8);
  4402. }
  4403. }
  4404. }
  4405. } else {
  4406. /* Get VCLK */
  4407. CRT2ModeNo = 0xfe;
  4408. VCLK = SiS_Pr->CSRClock;
  4409. }
  4410. /* Get colordepth */
  4411. colorth = SiS_GetColorDepth(SiS_Pr,CRT2ModeNo,modeidindex) >> 1;
  4412. if(!colorth) colorth++;
  4413. data = data * VCLK * colorth;
  4414. temp = data % (MCLK << 4);
  4415. data = data / (MCLK << 4);
  4416. if(temp) data++;
  4417. if(data < 6) data = 6;
  4418. else if(data > 0x14) data = 0x14;
  4419. if(SiS_Pr->ChipType == SIS_300) {
  4420. temp = 0x16;
  4421. if((data <= 0x0f) || (SiS_Pr->SiS_LCDResInfo == Panel_1280x1024))
  4422. temp = 0x13;
  4423. } else {
  4424. temp = 0x16;
  4425. if(( (SiS_Pr->ChipType == SIS_630) ||
  4426. (SiS_Pr->ChipType == SIS_730) ) &&
  4427. (SiS_Pr->ChipRevision >= 0x30))
  4428. temp = 0x1b;
  4429. }
  4430. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x01,0xe0,temp);
  4431. if((SiS_Pr->ChipType == SIS_630) &&
  4432. (SiS_Pr->ChipRevision >= 0x30)) {
  4433. if(data > 0x13) data = 0x13;
  4434. }
  4435. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x02,0xe0,data);
  4436. } else { /* If mode <= 0x13, we just restore everything */
  4437. SiS_Pr->SiS_SetFlag |= ProgrammingCRT2;
  4438. SiS_Pr->SiS_SelectCRT2Rate = SelectRate_backup;
  4439. }
  4440. }
  4441. #endif
  4442. /* Set CRT2 FIFO on 315/330 series */
  4443. #ifdef CONFIG_FB_SIS_315
  4444. static void
  4445. SiS_SetCRT2FIFO_310(struct SiS_Private *SiS_Pr)
  4446. {
  4447. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x01,0x3B);
  4448. if( (SiS_Pr->ChipType == SIS_760) &&
  4449. (SiS_Pr->SiS_SysFlags & SF_760LFB) &&
  4450. (SiS_Pr->SiS_ModeType == Mode32Bpp) &&
  4451. (SiS_Pr->SiS_VGAHDE >= 1280) &&
  4452. (SiS_Pr->SiS_VGAVDE >= 1024) ) {
  4453. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2f,0x03);
  4454. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x01,0x3b);
  4455. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x4d,0xc0);
  4456. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2f,0x01);
  4457. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x4d,0xc0);
  4458. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x02,0x6e);
  4459. } else {
  4460. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x02,~0x3f,0x04);
  4461. }
  4462. }
  4463. #endif
  4464. static unsigned short
  4465. SiS_GetVGAHT2(struct SiS_Private *SiS_Pr)
  4466. {
  4467. unsigned int tempax,tempbx;
  4468. tempbx = (SiS_Pr->SiS_VGAVT - SiS_Pr->SiS_VGAVDE) * SiS_Pr->SiS_RVBHCMAX;
  4469. tempax = (SiS_Pr->SiS_VT - SiS_Pr->SiS_VDE) * SiS_Pr->SiS_RVBHCFACT;
  4470. tempax = (tempax * SiS_Pr->SiS_HT) / tempbx;
  4471. return (unsigned short)tempax;
  4472. }
  4473. /* Set Part 1 / SiS bridge slave mode */
  4474. static void
  4475. SiS_SetGroup1_301(struct SiS_Private *SiS_Pr, unsigned short ModeNo,unsigned short ModeIdIndex,
  4476. unsigned short RefreshRateTableIndex)
  4477. {
  4478. unsigned short temp, modeflag, i, j, xres=0, VGAVDE;
  4479. static const unsigned short CRTranslation[] = {
  4480. /* CR0 CR1 CR2 CR3 CR4 CR5 CR6 CR7 */
  4481. 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a,
  4482. /* CR8 CR9 SR0A SR0B SR0C SR0D SR0E CR0F */
  4483. 0x00, 0x0b, 0x17, 0x18, 0x19, 0x00, 0x1a, 0x00,
  4484. /* CR10 CR11 CR12 CR13 CR14 CR15 CR16 CR17 */
  4485. 0x0c, 0x0d, 0x0e, 0x00, 0x0f, 0x10, 0x11, 0x00
  4486. };
  4487. if(ModeNo <= 0x13) {
  4488. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  4489. } else if(SiS_Pr->UseCustomMode) {
  4490. modeflag = SiS_Pr->CModeFlag;
  4491. xres = SiS_Pr->CHDisplay;
  4492. } else {
  4493. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  4494. xres = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].XRes;
  4495. }
  4496. /* The following is only done if bridge is in slave mode: */
  4497. if(SiS_Pr->ChipType >= SIS_315H) {
  4498. if(xres >= 1600) { /* BIOS: == 1600 */
  4499. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x31,0x04);
  4500. }
  4501. }
  4502. SiS_Pr->CHTotal = 8224; /* Max HT, 0x2020, results in 0x3ff in registers */
  4503. SiS_Pr->CHDisplay = SiS_Pr->SiS_VGAHDE;
  4504. if(modeflag & HalfDCLK) SiS_Pr->CHDisplay >>= 1;
  4505. SiS_Pr->CHBlankStart = SiS_Pr->CHDisplay;
  4506. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  4507. SiS_Pr->CHBlankStart += 16;
  4508. }
  4509. SiS_Pr->CHBlankEnd = 32;
  4510. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  4511. if(xres == 1600) SiS_Pr->CHBlankEnd += 80;
  4512. }
  4513. temp = SiS_Pr->SiS_VGAHT - 96;
  4514. if(!(modeflag & HalfDCLK)) temp -= 32;
  4515. if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
  4516. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x04);
  4517. temp |= ((SiS_GetReg(SiS_Pr->SiS_P3c4,0x0b) & 0xc0) << 2);
  4518. temp -= 3;
  4519. temp <<= 3;
  4520. } else {
  4521. if(SiS_Pr->SiS_RVBHRS2) temp = SiS_Pr->SiS_RVBHRS2;
  4522. }
  4523. SiS_Pr->CHSyncStart = temp;
  4524. SiS_Pr->CHSyncEnd = 0xffe8; /* results in 0x2000 in registers */
  4525. SiS_Pr->CVTotal = 2049; /* Max VT, 0x0801, results in 0x7ff in registers */
  4526. VGAVDE = SiS_Pr->SiS_VGAVDE;
  4527. if (VGAVDE == 357) VGAVDE = 350;
  4528. else if(VGAVDE == 360) VGAVDE = 350;
  4529. else if(VGAVDE == 375) VGAVDE = 350;
  4530. else if(VGAVDE == 405) VGAVDE = 400;
  4531. else if(VGAVDE == 420) VGAVDE = 400;
  4532. else if(VGAVDE == 525) VGAVDE = 480;
  4533. else if(VGAVDE == 1056) VGAVDE = 1024;
  4534. SiS_Pr->CVDisplay = VGAVDE;
  4535. SiS_Pr->CVBlankStart = SiS_Pr->CVDisplay;
  4536. SiS_Pr->CVBlankEnd = 1;
  4537. if(ModeNo == 0x3c) SiS_Pr->CVBlankEnd = 226;
  4538. temp = (SiS_Pr->SiS_VGAVT - VGAVDE) >> 1;
  4539. SiS_Pr->CVSyncStart = VGAVDE + temp;
  4540. temp >>= 3;
  4541. SiS_Pr->CVSyncEnd = SiS_Pr->CVSyncStart + temp;
  4542. SiS_CalcCRRegisters(SiS_Pr, 0);
  4543. SiS_Pr->CCRT1CRTC[16] &= ~0xE0;
  4544. for(i = 0; i <= 7; i++) {
  4545. SiS_SetReg(SiS_Pr->SiS_Part1Port,CRTranslation[i],SiS_Pr->CCRT1CRTC[i]);
  4546. }
  4547. for(i = 0x10, j = 8; i <= 0x12; i++, j++) {
  4548. SiS_SetReg(SiS_Pr->SiS_Part1Port,CRTranslation[i],SiS_Pr->CCRT1CRTC[j]);
  4549. }
  4550. for(i = 0x15, j = 11; i <= 0x16; i++, j++) {
  4551. SiS_SetReg(SiS_Pr->SiS_Part1Port,CRTranslation[i],SiS_Pr->CCRT1CRTC[j]);
  4552. }
  4553. for(i = 0x0a, j = 13; i <= 0x0c; i++, j++) {
  4554. SiS_SetReg(SiS_Pr->SiS_Part1Port,CRTranslation[i],SiS_Pr->CCRT1CRTC[j]);
  4555. }
  4556. temp = SiS_Pr->CCRT1CRTC[16] & 0xE0;
  4557. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,CRTranslation[0x0E],0x1F,temp);
  4558. temp = (SiS_Pr->CCRT1CRTC[16] & 0x01) << 5;
  4559. if(modeflag & DoubleScanMode) temp |= 0x80;
  4560. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,CRTranslation[0x09],0x5F,temp);
  4561. temp = 0;
  4562. temp |= (SiS_GetReg(SiS_Pr->SiS_P3c4,0x01) & 0x01);
  4563. if(modeflag & HalfDCLK) temp |= 0x08;
  4564. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x16,temp); /* SR01: HalfDCLK[3], 8/9 div dotclock[0] */
  4565. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0F,0x00); /* CR14: (text mode: underline location) */
  4566. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x12,0x00); /* CR17: n/a */
  4567. temp = 0;
  4568. if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) {
  4569. temp = (SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x01) << 7;
  4570. }
  4571. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1A,temp); /* SR0E, dither[7] */
  4572. temp = SiS_GetRegByte((SiS_Pr->SiS_P3ca+0x02));
  4573. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,temp); /* ? */
  4574. }
  4575. /* Setup panel link
  4576. * This is used for LVDS, LCDA and Chrontel TV output
  4577. * 300/LVDS+TV, 300/301B-DH, 315/LVDS+TV, 315/LCDA
  4578. */
  4579. static void
  4580. SiS_SetGroup1_LVDS(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  4581. unsigned short RefreshRateTableIndex)
  4582. {
  4583. unsigned short modeflag, resinfo = 0;
  4584. unsigned short push2, tempax, tempbx, tempcx, temp;
  4585. unsigned int tempeax = 0, tempebx, tempecx, tempvcfact = 0;
  4586. bool islvds = false, issis = false, chkdclkfirst = false;
  4587. #ifdef CONFIG_FB_SIS_300
  4588. unsigned short crt2crtc = 0;
  4589. #endif
  4590. #ifdef CONFIG_FB_SIS_315
  4591. unsigned short pushcx;
  4592. #endif
  4593. if(ModeNo <= 0x13) {
  4594. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  4595. resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
  4596. #ifdef CONFIG_FB_SIS_300
  4597. crt2crtc = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  4598. #endif
  4599. } else if(SiS_Pr->UseCustomMode) {
  4600. modeflag = SiS_Pr->CModeFlag;
  4601. } else {
  4602. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  4603. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  4604. #ifdef CONFIG_FB_SIS_300
  4605. crt2crtc = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  4606. #endif
  4607. }
  4608. /* is lvds if really LVDS, or 301B-DH with external LVDS transmitter */
  4609. if((SiS_Pr->SiS_IF_DEF_LVDS == 1) || (SiS_Pr->SiS_VBType & VB_NoLCD)) {
  4610. islvds = true;
  4611. }
  4612. /* is really sis if sis bridge, but not 301B-DH */
  4613. if((SiS_Pr->SiS_VBType & VB_SISVB) && (!(SiS_Pr->SiS_VBType & VB_NoLCD))) {
  4614. issis = true;
  4615. }
  4616. if((SiS_Pr->ChipType >= SIS_315H) && (islvds) && (!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA))) {
  4617. if((!SiS_Pr->SiS_IF_DEF_FSTN) && (!SiS_Pr->SiS_IF_DEF_DSTN)) {
  4618. chkdclkfirst = true;
  4619. }
  4620. }
  4621. #ifdef CONFIG_FB_SIS_315
  4622. if((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  4623. if(IS_SIS330) {
  4624. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x10);
  4625. } else if(IS_SIS740) {
  4626. if(islvds) {
  4627. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,0xfb,0x04);
  4628. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x03);
  4629. } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
  4630. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x10);
  4631. }
  4632. } else {
  4633. if(islvds) {
  4634. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,0xfb,0x04);
  4635. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x00);
  4636. } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
  4637. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2D,0x0f);
  4638. if(SiS_Pr->SiS_VBType & VB_SIS30xC) {
  4639. if((SiS_Pr->SiS_LCDResInfo == Panel_1024x768) ||
  4640. (SiS_Pr->SiS_LCDResInfo == Panel_1280x1024)) {
  4641. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x20);
  4642. }
  4643. }
  4644. }
  4645. }
  4646. }
  4647. #endif
  4648. /* Horizontal */
  4649. tempax = SiS_Pr->SiS_LCDHDES;
  4650. if(islvds) {
  4651. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4652. if(!SiS_Pr->SiS_IF_DEF_FSTN && !SiS_Pr->SiS_IF_DEF_DSTN) {
  4653. if((SiS_Pr->SiS_LCDResInfo == Panel_640x480) &&
  4654. (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode))) {
  4655. tempax -= 8;
  4656. }
  4657. }
  4658. }
  4659. }
  4660. temp = (tempax & 0x0007);
  4661. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1A,temp); /* BPLHDESKEW[2:0] */
  4662. temp = (tempax >> 3) & 0x00FF;
  4663. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x16,temp); /* BPLHDESKEW[10:3] */
  4664. tempbx = SiS_Pr->SiS_HDE;
  4665. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4666. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  4667. tempbx = SiS_Pr->PanelXRes;
  4668. }
  4669. if((SiS_Pr->SiS_LCDResInfo == Panel_320x240_1) ||
  4670. (SiS_Pr->SiS_LCDResInfo == Panel_320x240_2) ||
  4671. (SiS_Pr->SiS_LCDResInfo == Panel_320x240_3)) {
  4672. tempbx >>= 1;
  4673. }
  4674. }
  4675. tempax += tempbx;
  4676. if(tempax >= SiS_Pr->SiS_HT) tempax -= SiS_Pr->SiS_HT;
  4677. temp = tempax;
  4678. if(temp & 0x07) temp += 8;
  4679. temp >>= 3;
  4680. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x17,temp); /* BPLHDEE */
  4681. tempcx = (SiS_Pr->SiS_HT - tempbx) >> 2;
  4682. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4683. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  4684. if(SiS_Pr->PanelHRS != 999) tempcx = SiS_Pr->PanelHRS;
  4685. }
  4686. }
  4687. tempcx += tempax;
  4688. if(tempcx >= SiS_Pr->SiS_HT) tempcx -= SiS_Pr->SiS_HT;
  4689. temp = (tempcx >> 3) & 0x00FF;
  4690. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4691. if(SiS_Pr->SiS_IF_DEF_TRUMPION) {
  4692. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  4693. switch(ModeNo) {
  4694. case 0x04:
  4695. case 0x05:
  4696. case 0x0d: temp = 0x56; break;
  4697. case 0x10: temp = 0x60; break;
  4698. case 0x13: temp = 0x5f; break;
  4699. case 0x40:
  4700. case 0x41:
  4701. case 0x4f:
  4702. case 0x43:
  4703. case 0x44:
  4704. case 0x62:
  4705. case 0x56:
  4706. case 0x53:
  4707. case 0x5d:
  4708. case 0x5e: temp = 0x54; break;
  4709. }
  4710. }
  4711. }
  4712. }
  4713. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x14,temp); /* BPLHRS */
  4714. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4715. temp += 2;
  4716. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  4717. temp += 8;
  4718. if(SiS_Pr->PanelHRE != 999) {
  4719. temp = tempcx + SiS_Pr->PanelHRE;
  4720. if(temp >= SiS_Pr->SiS_HT) temp -= SiS_Pr->SiS_HT;
  4721. temp >>= 3;
  4722. }
  4723. }
  4724. } else {
  4725. temp += 10;
  4726. }
  4727. temp &= 0x1F;
  4728. temp |= ((tempcx & 0x07) << 5);
  4729. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x15,temp); /* BPLHRE */
  4730. /* Vertical */
  4731. tempax = SiS_Pr->SiS_VGAVDE;
  4732. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4733. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  4734. tempax = SiS_Pr->PanelYRes;
  4735. }
  4736. }
  4737. tempbx = SiS_Pr->SiS_LCDVDES + tempax;
  4738. if(tempbx >= SiS_Pr->SiS_VT) tempbx -= SiS_Pr->SiS_VT;
  4739. push2 = tempbx;
  4740. tempcx = SiS_Pr->SiS_VGAVT - SiS_Pr->SiS_VGAVDE;
  4741. if(SiS_Pr->ChipType < SIS_315H) {
  4742. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4743. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  4744. tempcx = SiS_Pr->SiS_VGAVT - SiS_Pr->PanelYRes;
  4745. }
  4746. }
  4747. }
  4748. if(islvds) tempcx >>= 1;
  4749. else tempcx >>= 2;
  4750. if( (SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) &&
  4751. (!(SiS_Pr->SiS_LCDInfo & LCDPass11)) &&
  4752. (SiS_Pr->PanelVRS != 999) ) {
  4753. tempcx = SiS_Pr->PanelVRS;
  4754. tempbx += tempcx;
  4755. if(issis) tempbx++;
  4756. } else {
  4757. tempbx += tempcx;
  4758. if(SiS_Pr->ChipType < SIS_315H) tempbx++;
  4759. else if(issis) tempbx++;
  4760. }
  4761. if(tempbx >= SiS_Pr->SiS_VT) tempbx -= SiS_Pr->SiS_VT;
  4762. temp = tempbx & 0x00FF;
  4763. if(SiS_Pr->SiS_IF_DEF_TRUMPION) {
  4764. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  4765. if(ModeNo == 0x10) temp = 0xa9;
  4766. }
  4767. }
  4768. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,temp); /* BPLVRS */
  4769. tempcx >>= 3;
  4770. tempcx++;
  4771. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4772. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  4773. if(SiS_Pr->PanelVRE != 999) tempcx = SiS_Pr->PanelVRE;
  4774. }
  4775. }
  4776. tempcx += tempbx;
  4777. temp = tempcx & 0x000F;
  4778. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0xF0,temp); /* BPLVRE */
  4779. temp = ((tempbx >> 8) & 0x07) << 3;
  4780. if(SiS_Pr->SiS_IF_DEF_FSTN || SiS_Pr->SiS_IF_DEF_DSTN) {
  4781. if(SiS_Pr->SiS_HDE != 640) {
  4782. if(SiS_Pr->SiS_VGAVDE != SiS_Pr->SiS_VDE) temp |= 0x40;
  4783. }
  4784. } else if(SiS_Pr->SiS_VGAVDE != SiS_Pr->SiS_VDE) temp |= 0x40;
  4785. if(SiS_Pr->SiS_SetFlag & EnableLVDSDDA) temp |= 0x40;
  4786. tempbx = 0x87;
  4787. if((SiS_Pr->ChipType >= SIS_315H) ||
  4788. (SiS_Pr->ChipRevision >= 0x30)) {
  4789. tempbx = 0x07;
  4790. if((SiS_Pr->SiS_IF_DEF_CH70xx == 1) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
  4791. if(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x03) temp |= 0x80;
  4792. }
  4793. /* Chrontel 701x operates in 24bit mode (8-8-8, 2x12bit multiplexed) via VGA2 */
  4794. if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) {
  4795. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  4796. if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x06) & 0x10) temp |= 0x80;
  4797. } else {
  4798. if(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x01) temp |= 0x80;
  4799. }
  4800. }
  4801. }
  4802. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x1A,tempbx,temp);
  4803. tempbx = push2; /* BPLVDEE */
  4804. tempcx = SiS_Pr->SiS_LCDVDES; /* BPLVDES */
  4805. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4806. switch(SiS_Pr->SiS_LCDResInfo) {
  4807. case Panel_640x480:
  4808. tempbx = SiS_Pr->SiS_VGAVDE - 1;
  4809. tempcx = SiS_Pr->SiS_VGAVDE;
  4810. break;
  4811. case Panel_800x600:
  4812. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  4813. if(resinfo == SIS_RI_800x600) tempcx++;
  4814. }
  4815. break;
  4816. case Panel_1024x600:
  4817. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  4818. if(resinfo == SIS_RI_1024x600) tempcx++;
  4819. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  4820. if(resinfo == SIS_RI_800x600) tempcx++;
  4821. }
  4822. }
  4823. break;
  4824. case Panel_1024x768:
  4825. if(SiS_Pr->ChipType < SIS_315H) {
  4826. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  4827. if(resinfo == SIS_RI_1024x768) tempcx++;
  4828. }
  4829. }
  4830. break;
  4831. }
  4832. }
  4833. temp = ((tempbx >> 8) & 0x07) << 3;
  4834. temp |= ((tempcx >> 8) & 0x07);
  4835. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1D,temp);
  4836. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1C,tempbx);
  4837. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1B,tempcx);
  4838. /* Vertical scaling */
  4839. if(SiS_Pr->ChipType < SIS_315H) {
  4840. #ifdef CONFIG_FB_SIS_300 /* 300 series */
  4841. tempeax = SiS_Pr->SiS_VGAVDE << 6;
  4842. temp = (tempeax % (unsigned int)SiS_Pr->SiS_VDE);
  4843. tempeax = tempeax / (unsigned int)SiS_Pr->SiS_VDE;
  4844. if(temp) tempeax++;
  4845. if(SiS_Pr->SiS_SetFlag & EnableLVDSDDA) tempeax = 0x3F;
  4846. temp = (unsigned short)(tempeax & 0x00FF);
  4847. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1E,temp); /* BPLVCFACT */
  4848. tempvcfact = temp;
  4849. #endif /* CONFIG_FB_SIS_300 */
  4850. } else {
  4851. #ifdef CONFIG_FB_SIS_315 /* 315 series */
  4852. tempeax = SiS_Pr->SiS_VGAVDE << 18;
  4853. tempebx = SiS_Pr->SiS_VDE;
  4854. temp = (tempeax % tempebx);
  4855. tempeax = tempeax / tempebx;
  4856. if(temp) tempeax++;
  4857. tempvcfact = tempeax;
  4858. temp = (unsigned short)(tempeax & 0x00FF);
  4859. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x37,temp);
  4860. temp = (unsigned short)((tempeax & 0x00FF00) >> 8);
  4861. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x36,temp);
  4862. temp = (unsigned short)((tempeax & 0x00030000) >> 16);
  4863. if(SiS_Pr->SiS_VDE == SiS_Pr->SiS_VGAVDE) temp |= 0x04;
  4864. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x35,temp);
  4865. if(SiS_Pr->SiS_VBType & VB_SISPART4SCALER) {
  4866. temp = (unsigned short)(tempeax & 0x00FF);
  4867. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x3c,temp);
  4868. temp = (unsigned short)((tempeax & 0x00FF00) >> 8);
  4869. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x3b,temp);
  4870. temp = (unsigned short)(((tempeax & 0x00030000) >> 16) << 6);
  4871. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x3a,0x3f,temp);
  4872. temp = 0;
  4873. if(SiS_Pr->SiS_VDE != SiS_Pr->SiS_VGAVDE) temp |= 0x08;
  4874. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x30,0xf3,temp);
  4875. }
  4876. #endif
  4877. }
  4878. /* Horizontal scaling */
  4879. tempeax = SiS_Pr->SiS_VGAHDE; /* 1f = ( (VGAHDE * 65536) / ( (VGAHDE * 65536) / HDE ) ) - 1*/
  4880. if(chkdclkfirst) {
  4881. if(modeflag & HalfDCLK) tempeax >>= 1;
  4882. }
  4883. tempebx = tempeax << 16;
  4884. if(SiS_Pr->SiS_HDE == tempeax) {
  4885. tempecx = 0xFFFF;
  4886. } else {
  4887. tempecx = tempebx / SiS_Pr->SiS_HDE;
  4888. if(SiS_Pr->ChipType >= SIS_315H) {
  4889. if(tempebx % SiS_Pr->SiS_HDE) tempecx++;
  4890. }
  4891. }
  4892. if(SiS_Pr->ChipType >= SIS_315H) {
  4893. tempeax = (tempebx / tempecx) - 1;
  4894. } else {
  4895. tempeax = ((SiS_Pr->SiS_VGAHT << 16) / tempecx) - 1;
  4896. }
  4897. tempecx = (tempecx << 16) | (tempeax & 0xFFFF);
  4898. temp = (unsigned short)(tempecx & 0x00FF);
  4899. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1F,temp);
  4900. if(SiS_Pr->ChipType >= SIS_315H) {
  4901. tempeax = (SiS_Pr->SiS_VGAVDE << 18) / tempvcfact;
  4902. tempbx = (unsigned short)(tempeax & 0xFFFF);
  4903. } else {
  4904. tempeax = SiS_Pr->SiS_VGAVDE << 6;
  4905. tempbx = tempvcfact & 0x3f;
  4906. if(tempbx == 0) tempbx = 64;
  4907. tempeax /= tempbx;
  4908. tempbx = (unsigned short)(tempeax & 0xFFFF);
  4909. }
  4910. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) tempbx--;
  4911. if(SiS_Pr->SiS_SetFlag & EnableLVDSDDA) {
  4912. if((!SiS_Pr->SiS_IF_DEF_FSTN) && (!SiS_Pr->SiS_IF_DEF_DSTN)) tempbx = 1;
  4913. else if(SiS_Pr->SiS_LCDResInfo != Panel_640x480) tempbx = 1;
  4914. }
  4915. temp = ((tempbx >> 8) & 0x07) << 3;
  4916. temp = temp | ((tempecx >> 8) & 0x07);
  4917. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x20,temp);
  4918. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x21,tempbx);
  4919. tempecx >>= 16; /* BPLHCFACT */
  4920. if(!chkdclkfirst) {
  4921. if(modeflag & HalfDCLK) tempecx >>= 1;
  4922. }
  4923. temp = (unsigned short)((tempecx & 0xFF00) >> 8);
  4924. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x22,temp);
  4925. temp = (unsigned short)(tempecx & 0x00FF);
  4926. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x23,temp);
  4927. #ifdef CONFIG_FB_SIS_315
  4928. if(SiS_Pr->ChipType >= SIS_315H) {
  4929. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  4930. if((islvds) || (SiS_Pr->SiS_VBInfo & VB_SISLVDS)) {
  4931. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1e,0x20);
  4932. }
  4933. } else {
  4934. if(islvds) {
  4935. if(SiS_Pr->ChipType == SIS_740) {
  4936. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1e,0x03);
  4937. } else {
  4938. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1e,0x23);
  4939. }
  4940. }
  4941. }
  4942. }
  4943. #endif
  4944. #ifdef CONFIG_FB_SIS_300
  4945. if(SiS_Pr->SiS_IF_DEF_TRUMPION) {
  4946. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  4947. unsigned char *trumpdata;
  4948. int i, j = crt2crtc;
  4949. unsigned char TrumpMode13[4] = { 0x01, 0x10, 0x2c, 0x00 };
  4950. unsigned char TrumpMode10_1[4] = { 0x01, 0x10, 0x27, 0x00 };
  4951. unsigned char TrumpMode10_2[4] = { 0x01, 0x16, 0x10, 0x00 };
  4952. if(SiS_Pr->SiS_UseROM) {
  4953. trumpdata = &ROMAddr[0x8001 + (j * 80)];
  4954. } else {
  4955. if(SiS_Pr->SiS_LCDTypeInfo == 0x0e) j += 7;
  4956. trumpdata = &SiS300_TrumpionData[j][0];
  4957. }
  4958. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x02,0xbf);
  4959. for(i=0; i<5; i++) {
  4960. SiS_SetTrumpionBlock(SiS_Pr, trumpdata);
  4961. }
  4962. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  4963. if(ModeNo == 0x13) {
  4964. for(i=0; i<4; i++) {
  4965. SiS_SetTrumpionBlock(SiS_Pr, &TrumpMode13[0]);
  4966. }
  4967. } else if(ModeNo == 0x10) {
  4968. for(i=0; i<4; i++) {
  4969. SiS_SetTrumpionBlock(SiS_Pr, &TrumpMode10_1[0]);
  4970. SiS_SetTrumpionBlock(SiS_Pr, &TrumpMode10_2[0]);
  4971. }
  4972. }
  4973. }
  4974. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x02,0x40);
  4975. }
  4976. #endif
  4977. #ifdef CONFIG_FB_SIS_315
  4978. if(SiS_Pr->SiS_IF_DEF_FSTN || SiS_Pr->SiS_IF_DEF_DSTN) {
  4979. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x25,0x00);
  4980. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x26,0x00);
  4981. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x27,0x00);
  4982. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x28,0x87);
  4983. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x29,0x5A);
  4984. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2A,0x4B);
  4985. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x44,~0x07,0x03);
  4986. tempax = SiS_Pr->SiS_HDE; /* Blps = lcdhdee(lcdhdes+HDE) + 64 */
  4987. if(SiS_Pr->SiS_LCDResInfo == Panel_320x240_1 ||
  4988. SiS_Pr->SiS_LCDResInfo == Panel_320x240_2 ||
  4989. SiS_Pr->SiS_LCDResInfo == Panel_320x240_3) tempax >>= 1;
  4990. tempax += 64;
  4991. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x38,tempax & 0xff);
  4992. temp = (tempax >> 8) << 3;
  4993. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x35,~0x078,temp);
  4994. tempax += 32; /* Blpe = lBlps+32 */
  4995. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x39,tempax & 0xff);
  4996. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3A,0x00); /* Bflml = 0 */
  4997. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x3C,~0x007);
  4998. tempax = SiS_Pr->SiS_VDE;
  4999. if(SiS_Pr->SiS_LCDResInfo == Panel_320x240_1 ||
  5000. SiS_Pr->SiS_LCDResInfo == Panel_320x240_2 ||
  5001. SiS_Pr->SiS_LCDResInfo == Panel_320x240_3) tempax >>= 1;
  5002. tempax >>= 1;
  5003. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3B,tempax & 0xff);
  5004. temp = (tempax >> 8) << 3;
  5005. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x3C,~0x038,temp);
  5006. tempeax = SiS_Pr->SiS_HDE;
  5007. if(SiS_Pr->SiS_LCDResInfo == Panel_320x240_1 ||
  5008. SiS_Pr->SiS_LCDResInfo == Panel_320x240_2 ||
  5009. SiS_Pr->SiS_LCDResInfo == Panel_320x240_3) tempeax >>= 1;
  5010. tempeax <<= 2; /* BDxFIFOSTOP = (HDE*4)/128 */
  5011. temp = tempeax & 0x7f;
  5012. tempeax >>= 7;
  5013. if(temp) tempeax++;
  5014. temp = tempeax & 0x3f;
  5015. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x45,temp);
  5016. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3F,0x00); /* BDxWadrst0 */
  5017. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3E,0x00);
  5018. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3D,0x10);
  5019. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x3C,~0x040);
  5020. tempax = SiS_Pr->SiS_HDE;
  5021. if(SiS_Pr->SiS_LCDResInfo == Panel_320x240_1 ||
  5022. SiS_Pr->SiS_LCDResInfo == Panel_320x240_2 ||
  5023. SiS_Pr->SiS_LCDResInfo == Panel_320x240_3) tempax >>= 1;
  5024. tempax >>= 4; /* BDxWadroff = HDE*4/8/8 */
  5025. pushcx = tempax;
  5026. temp = tempax & 0x00FF;
  5027. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x43,temp);
  5028. temp = ((tempax & 0xFF00) >> 8) << 3;
  5029. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port, 0x44, 0x07, temp);
  5030. tempax = SiS_Pr->SiS_VDE; /* BDxWadrst1 = BDxWadrst0 + BDxWadroff * VDE */
  5031. if(SiS_Pr->SiS_LCDResInfo == Panel_320x240_1 ||
  5032. SiS_Pr->SiS_LCDResInfo == Panel_320x240_2 ||
  5033. SiS_Pr->SiS_LCDResInfo == Panel_320x240_3) tempax >>= 1;
  5034. tempeax = tempax * pushcx;
  5035. temp = tempeax & 0xFF;
  5036. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x42,temp);
  5037. temp = (tempeax & 0xFF00) >> 8;
  5038. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x41,temp);
  5039. temp = ((tempeax & 0xFF0000) >> 16) | 0x10;
  5040. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x40,temp);
  5041. temp = ((tempeax & 0x01000000) >> 24) << 7;
  5042. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port, 0x3C, 0x7F, temp);
  5043. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2F,0x03);
  5044. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x03,0x50);
  5045. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x04,0x00);
  5046. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2F,0x01);
  5047. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x19,0x38);
  5048. if(SiS_Pr->SiS_IF_DEF_FSTN) {
  5049. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2b,0x02);
  5050. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2c,0x00);
  5051. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2d,0x00);
  5052. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x35,0x0c);
  5053. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x36,0x00);
  5054. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x37,0x00);
  5055. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x38,0x80);
  5056. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x39,0xA0);
  5057. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3a,0x00);
  5058. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3b,0xf0);
  5059. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3c,0x00);
  5060. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3d,0x10);
  5061. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3e,0x00);
  5062. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3f,0x00);
  5063. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x40,0x10);
  5064. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x41,0x25);
  5065. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x42,0x80);
  5066. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x43,0x14);
  5067. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x44,0x03);
  5068. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x45,0x0a);
  5069. }
  5070. }
  5071. #endif /* CONFIG_FB_SIS_315 */
  5072. }
  5073. /* Set Part 1 */
  5074. static void
  5075. SiS_SetGroup1(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  5076. unsigned short RefreshRateTableIndex)
  5077. {
  5078. #if defined(CONFIG_FB_SIS_300) || defined(CONFIG_FB_SIS_315)
  5079. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  5080. #endif
  5081. unsigned short temp=0, tempax=0, tempbx=0, tempcx=0, bridgeadd=0;
  5082. unsigned short pushbx=0, CRT1Index=0, modeflag, resinfo=0;
  5083. #ifdef CONFIG_FB_SIS_315
  5084. unsigned short tempbl=0;
  5085. #endif
  5086. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  5087. SiS_SetGroup1_LVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  5088. return;
  5089. }
  5090. if(ModeNo <= 0x13) {
  5091. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  5092. } else if(SiS_Pr->UseCustomMode) {
  5093. modeflag = SiS_Pr->CModeFlag;
  5094. } else {
  5095. CRT1Index = SiS_GetRefCRT1CRTC(SiS_Pr, RefreshRateTableIndex, SiS_Pr->SiS_UseWideCRT2);
  5096. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  5097. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  5098. }
  5099. SiS_SetCRT2Offset(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  5100. if( ! ((SiS_Pr->ChipType >= SIS_315H) &&
  5101. (SiS_Pr->SiS_IF_DEF_LVDS == 1) &&
  5102. (SiS_Pr->SiS_VBInfo & SetInSlaveMode)) ) {
  5103. if(SiS_Pr->ChipType < SIS_315H ) {
  5104. #ifdef CONFIG_FB_SIS_300
  5105. SiS_SetCRT2FIFO_300(SiS_Pr, ModeNo);
  5106. #endif
  5107. } else {
  5108. #ifdef CONFIG_FB_SIS_315
  5109. SiS_SetCRT2FIFO_310(SiS_Pr);
  5110. #endif
  5111. }
  5112. /* 1. Horizontal setup */
  5113. if(SiS_Pr->ChipType < SIS_315H ) {
  5114. #ifdef CONFIG_FB_SIS_300 /* ------------- 300 series --------------*/
  5115. temp = (SiS_Pr->SiS_VGAHT - 1) & 0x0FF; /* BTVGA2HT 0x08,0x09 */
  5116. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x08,temp); /* CRT2 Horizontal Total */
  5117. temp = (((SiS_Pr->SiS_VGAHT - 1) & 0xFF00) >> 8) << 4;
  5118. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x09,0x0f,temp); /* CRT2 Horizontal Total Overflow [7:4] */
  5119. temp = (SiS_Pr->SiS_VGAHDE + 12) & 0x0FF; /* BTVGA2HDEE 0x0A,0x0C */
  5120. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0A,temp); /* CRT2 Horizontal Display Enable End */
  5121. pushbx = SiS_Pr->SiS_VGAHDE + 12; /* bx BTVGA2HRS 0x0B,0x0C */
  5122. tempcx = (SiS_Pr->SiS_VGAHT - SiS_Pr->SiS_VGAHDE) >> 2;
  5123. tempbx = pushbx + tempcx;
  5124. tempcx <<= 1;
  5125. tempcx += tempbx;
  5126. bridgeadd = 12;
  5127. #endif /* CONFIG_FB_SIS_300 */
  5128. } else {
  5129. #ifdef CONFIG_FB_SIS_315 /* ------------------- 315/330 series --------------- */
  5130. tempcx = SiS_Pr->SiS_VGAHT; /* BTVGA2HT 0x08,0x09 */
  5131. if(modeflag & HalfDCLK) {
  5132. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  5133. tempcx >>= 1;
  5134. } else {
  5135. tempax = SiS_Pr->SiS_VGAHDE >> 1;
  5136. tempcx = SiS_Pr->SiS_HT - SiS_Pr->SiS_HDE + tempax;
  5137. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  5138. tempcx = SiS_Pr->SiS_HT - tempax;
  5139. }
  5140. }
  5141. }
  5142. tempcx--;
  5143. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x08,tempcx); /* CRT2 Horizontal Total */
  5144. temp = (tempcx >> 4) & 0xF0;
  5145. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x09,0x0F,temp); /* CRT2 Horizontal Total Overflow [7:4] */
  5146. tempcx = SiS_Pr->SiS_VGAHT; /* BTVGA2HDEE 0x0A,0x0C */
  5147. tempbx = SiS_Pr->SiS_VGAHDE;
  5148. tempcx -= tempbx;
  5149. tempcx >>= 2;
  5150. if(modeflag & HalfDCLK) {
  5151. tempbx >>= 1;
  5152. tempcx >>= 1;
  5153. }
  5154. tempbx += 16;
  5155. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0A,tempbx); /* CRT2 Horizontal Display Enable End */
  5156. pushbx = tempbx;
  5157. tempcx >>= 1;
  5158. tempbx += tempcx;
  5159. tempcx += tempbx;
  5160. bridgeadd = 16;
  5161. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  5162. if(SiS_Pr->ChipType >= SIS_661) {
  5163. if((SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) ||
  5164. (SiS_Pr->SiS_LCDResInfo == Panel_1280x1024)) {
  5165. if(resinfo == SIS_RI_1280x1024) {
  5166. tempcx = (tempcx & 0xff00) | 0x30;
  5167. } else if(resinfo == SIS_RI_1600x1200) {
  5168. tempcx = (tempcx & 0xff00) | 0xff;
  5169. }
  5170. }
  5171. }
  5172. }
  5173. #endif /* CONFIG_FB_SIS_315 */
  5174. } /* 315/330 series */
  5175. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  5176. if(SiS_Pr->UseCustomMode) {
  5177. tempbx = SiS_Pr->CHSyncStart + bridgeadd;
  5178. tempcx = SiS_Pr->CHSyncEnd + bridgeadd;
  5179. tempax = SiS_Pr->SiS_VGAHT;
  5180. if(modeflag & HalfDCLK) tempax >>= 1;
  5181. tempax--;
  5182. if(tempcx > tempax) tempcx = tempax;
  5183. }
  5184. if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) {
  5185. unsigned char cr4, cr14, cr5, cr15;
  5186. if(SiS_Pr->UseCustomMode) {
  5187. cr4 = SiS_Pr->CCRT1CRTC[4];
  5188. cr14 = SiS_Pr->CCRT1CRTC[14];
  5189. cr5 = SiS_Pr->CCRT1CRTC[5];
  5190. cr15 = SiS_Pr->CCRT1CRTC[15];
  5191. } else {
  5192. cr4 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[4];
  5193. cr14 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[14];
  5194. cr5 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[5];
  5195. cr15 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[15];
  5196. }
  5197. tempbx = ((cr4 | ((cr14 & 0xC0) << 2)) - 3) << 3; /* (VGAHRS-3)*8 */
  5198. tempcx = (((cr5 & 0x1f) | ((cr15 & 0x04) << (5-2))) - 3) << 3; /* (VGAHRE-3)*8 */
  5199. tempcx &= 0x00FF;
  5200. tempcx |= (tempbx & 0xFF00);
  5201. tempbx += bridgeadd;
  5202. tempcx += bridgeadd;
  5203. tempax = SiS_Pr->SiS_VGAHT;
  5204. if(modeflag & HalfDCLK) tempax >>= 1;
  5205. tempax--;
  5206. if(tempcx > tempax) tempcx = tempax;
  5207. }
  5208. if(SiS_Pr->SiS_TVMode & (TVSetNTSC1024 | TVSet525p1024)) {
  5209. tempbx = 1040;
  5210. tempcx = 1044; /* HWCursor bug! */
  5211. }
  5212. }
  5213. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0B,tempbx); /* CRT2 Horizontal Retrace Start */
  5214. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0D,tempcx); /* CRT2 Horizontal Retrace End */
  5215. temp = ((tempbx >> 8) & 0x0F) | ((pushbx >> 4) & 0xF0);
  5216. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0C,temp); /* Overflow */
  5217. /* 2. Vertical setup */
  5218. tempcx = SiS_Pr->SiS_VGAVT - 1;
  5219. temp = tempcx & 0x00FF;
  5220. if(SiS_Pr->ChipType < SIS_661) {
  5221. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  5222. if(SiS_Pr->ChipType < SIS_315H) {
  5223. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  5224. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToSVIDEO | SetCRT2ToAVIDEO)) {
  5225. temp--;
  5226. }
  5227. }
  5228. } else {
  5229. temp--;
  5230. }
  5231. } else if(SiS_Pr->ChipType >= SIS_315H) {
  5232. temp--;
  5233. }
  5234. }
  5235. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0E,temp); /* CRT2 Vertical Total */
  5236. tempbx = SiS_Pr->SiS_VGAVDE - 1;
  5237. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0F,tempbx); /* CRT2 Vertical Display Enable End */
  5238. temp = ((tempbx >> 5) & 0x38) | ((tempcx >> 8) & 0x07);
  5239. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x12,temp); /* Overflow */
  5240. if((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->ChipType < SIS_661)) {
  5241. tempbx++;
  5242. tempax = tempbx;
  5243. tempcx++;
  5244. tempcx -= tempax;
  5245. tempcx >>= 2;
  5246. tempbx += tempcx;
  5247. if(tempcx < 4) tempcx = 4;
  5248. tempcx >>= 2;
  5249. tempcx += tempbx;
  5250. tempcx++;
  5251. } else {
  5252. tempbx = (SiS_Pr->SiS_VGAVT + SiS_Pr->SiS_VGAVDE) >> 1; /* BTVGA2VRS 0x10,0x11 */
  5253. tempcx = ((SiS_Pr->SiS_VGAVT - SiS_Pr->SiS_VGAVDE) >> 4) + tempbx + 1; /* BTVGA2VRE 0x11 */
  5254. }
  5255. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  5256. if(SiS_Pr->UseCustomMode) {
  5257. tempbx = SiS_Pr->CVSyncStart;
  5258. tempcx = SiS_Pr->CVSyncEnd;
  5259. }
  5260. if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) {
  5261. unsigned char cr8, cr7, cr13;
  5262. if(SiS_Pr->UseCustomMode) {
  5263. cr8 = SiS_Pr->CCRT1CRTC[8];
  5264. cr7 = SiS_Pr->CCRT1CRTC[7];
  5265. cr13 = SiS_Pr->CCRT1CRTC[13];
  5266. tempcx = SiS_Pr->CCRT1CRTC[9];
  5267. } else {
  5268. cr8 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[8];
  5269. cr7 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[7];
  5270. cr13 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[13];
  5271. tempcx = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[9];
  5272. }
  5273. tempbx = cr8;
  5274. if(cr7 & 0x04) tempbx |= 0x0100;
  5275. if(cr7 & 0x80) tempbx |= 0x0200;
  5276. if(cr13 & 0x08) tempbx |= 0x0400;
  5277. }
  5278. }
  5279. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x10,tempbx); /* CRT2 Vertical Retrace Start */
  5280. temp = ((tempbx >> 4) & 0x70) | (tempcx & 0x0F);
  5281. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x11,temp); /* CRT2 Vert. Retrace End; Overflow */
  5282. /* 3. Panel delay compensation */
  5283. if(SiS_Pr->ChipType < SIS_315H) {
  5284. #ifdef CONFIG_FB_SIS_300 /* ---------- 300 series -------------- */
  5285. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  5286. temp = 0x20;
  5287. if(SiS_Pr->ChipType == SIS_300) {
  5288. temp = 0x10;
  5289. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) temp = 0x2c;
  5290. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) temp = 0x20;
  5291. }
  5292. if(SiS_Pr->SiS_VBType & VB_SIS301) {
  5293. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) temp = 0x20;
  5294. }
  5295. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x960) temp = 0x24;
  5296. if(SiS_Pr->SiS_LCDResInfo == Panel_Custom) temp = 0x2c;
  5297. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) temp = 0x08;
  5298. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  5299. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) temp = 0x2c;
  5300. else temp = 0x20;
  5301. }
  5302. if(SiS_Pr->SiS_UseROM) {
  5303. if(ROMAddr[0x220] & 0x80) {
  5304. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoYPbPrHiVision)
  5305. temp = ROMAddr[0x221];
  5306. else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision)
  5307. temp = ROMAddr[0x222];
  5308. else if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024)
  5309. temp = ROMAddr[0x223];
  5310. else
  5311. temp = ROMAddr[0x224];
  5312. }
  5313. }
  5314. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  5315. if(SiS_Pr->PDC != -1) temp = SiS_Pr->PDC;
  5316. }
  5317. } else {
  5318. temp = 0x20;
  5319. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
  5320. if(SiS_Pr->SiS_LCDResInfo == Panel_640x480) temp = 0x04;
  5321. }
  5322. if(SiS_Pr->SiS_UseROM) {
  5323. if(ROMAddr[0x220] & 0x80) {
  5324. temp = ROMAddr[0x220];
  5325. }
  5326. }
  5327. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  5328. if(SiS_Pr->PDC != -1) temp = SiS_Pr->PDC;
  5329. }
  5330. }
  5331. temp &= 0x3c;
  5332. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,~0x3C,temp); /* Panel Link Delay Compensation; (Software Command Reset; Power Saving) */
  5333. #endif /* CONFIG_FB_SIS_300 */
  5334. } else {
  5335. #ifdef CONFIG_FB_SIS_315 /* --------------- 315/330 series ---------------*/
  5336. if(SiS_Pr->ChipType < SIS_661) {
  5337. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  5338. if(SiS_Pr->ChipType == SIS_740) temp = 0x03;
  5339. else temp = 0x00;
  5340. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) temp = 0x0a;
  5341. tempbl = 0xF0;
  5342. if(SiS_Pr->ChipType == SIS_650) {
  5343. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  5344. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) tempbl = 0x0F;
  5345. }
  5346. }
  5347. if(SiS_Pr->SiS_IF_DEF_DSTN || SiS_Pr->SiS_IF_DEF_FSTN) {
  5348. temp = 0x08;
  5349. tempbl = 0;
  5350. if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
  5351. if(ROMAddr[0x13c] & 0x80) tempbl = 0xf0;
  5352. }
  5353. }
  5354. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,tempbl,temp); /* Panel Link Delay Compensation */
  5355. }
  5356. } /* < 661 */
  5357. tempax = 0;
  5358. if(modeflag & DoubleScanMode) tempax |= 0x80;
  5359. if(modeflag & HalfDCLK) tempax |= 0x40;
  5360. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2C,0x3f,tempax);
  5361. #endif /* CONFIG_FB_SIS_315 */
  5362. }
  5363. } /* Slavemode */
  5364. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  5365. if((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) {
  5366. /* For 301BDH with LCD, we set up the Panel Link */
  5367. SiS_SetGroup1_LVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  5368. } else if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  5369. SiS_SetGroup1_301(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  5370. }
  5371. } else {
  5372. if(SiS_Pr->ChipType < SIS_315H) {
  5373. SiS_SetGroup1_LVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  5374. } else {
  5375. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  5376. if((!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) || (SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  5377. SiS_SetGroup1_LVDS(SiS_Pr, ModeNo,ModeIdIndex,RefreshRateTableIndex);
  5378. }
  5379. } else {
  5380. SiS_SetGroup1_LVDS(SiS_Pr, ModeNo,ModeIdIndex,RefreshRateTableIndex);
  5381. }
  5382. }
  5383. }
  5384. }
  5385. /*********************************************/
  5386. /* SET PART 2 REGISTER GROUP */
  5387. /*********************************************/
  5388. #ifdef CONFIG_FB_SIS_315
  5389. static unsigned char *
  5390. SiS_GetGroup2CLVXPtr(struct SiS_Private *SiS_Pr, int tabletype)
  5391. {
  5392. const unsigned char *tableptr = NULL;
  5393. unsigned short a, b, p = 0;
  5394. a = SiS_Pr->SiS_VGAHDE;
  5395. b = SiS_Pr->SiS_HDE;
  5396. if(tabletype) {
  5397. a = SiS_Pr->SiS_VGAVDE;
  5398. b = SiS_Pr->SiS_VDE;
  5399. }
  5400. if(a < b) {
  5401. tableptr = SiS_Part2CLVX_1;
  5402. } else if(a == b) {
  5403. tableptr = SiS_Part2CLVX_2;
  5404. } else {
  5405. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  5406. tableptr = SiS_Part2CLVX_4;
  5407. } else {
  5408. tableptr = SiS_Part2CLVX_3;
  5409. }
  5410. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  5411. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525i) tableptr = SiS_Part2CLVX_3;
  5412. else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) tableptr = SiS_Part2CLVX_3;
  5413. else tableptr = SiS_Part2CLVX_5;
  5414. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  5415. tableptr = SiS_Part2CLVX_6;
  5416. }
  5417. do {
  5418. if((tableptr[p] | tableptr[p+1] << 8) == a) break;
  5419. p += 0x42;
  5420. } while((tableptr[p] | tableptr[p+1] << 8) != 0xffff);
  5421. if((tableptr[p] | tableptr[p+1] << 8) == 0xffff) p -= 0x42;
  5422. }
  5423. p += 2;
  5424. return ((unsigned char *)&tableptr[p]);
  5425. }
  5426. static void
  5427. SiS_SetGroup2_C_ELV(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  5428. unsigned short RefreshRateTableIndex)
  5429. {
  5430. unsigned char *tableptr;
  5431. unsigned char temp;
  5432. int i, j;
  5433. if(!(SiS_Pr->SiS_VBType & VB_SISTAP4SCALER)) return;
  5434. tableptr = SiS_GetGroup2CLVXPtr(SiS_Pr, 0);
  5435. for(i = 0x80, j = 0; i <= 0xbf; i++, j++) {
  5436. SiS_SetReg(SiS_Pr->SiS_Part2Port, i, tableptr[j]);
  5437. }
  5438. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  5439. tableptr = SiS_GetGroup2CLVXPtr(SiS_Pr, 1);
  5440. for(i = 0xc0, j = 0; i <= 0xff; i++, j++) {
  5441. SiS_SetReg(SiS_Pr->SiS_Part2Port, i, tableptr[j]);
  5442. }
  5443. }
  5444. temp = 0x10;
  5445. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) temp |= 0x04;
  5446. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x4e,0xeb,temp);
  5447. }
  5448. static bool
  5449. SiS_GetCRT2Part2Ptr(struct SiS_Private *SiS_Pr,unsigned short ModeNo,unsigned short ModeIdIndex,
  5450. unsigned short RefreshRateTableIndex,unsigned short *CRT2Index,
  5451. unsigned short *ResIndex)
  5452. {
  5453. if(SiS_Pr->ChipType < SIS_315H) return false;
  5454. if(ModeNo <= 0x13)
  5455. (*ResIndex) = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  5456. else
  5457. (*ResIndex) = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  5458. (*ResIndex) &= 0x3f;
  5459. (*CRT2Index) = 0;
  5460. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  5461. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
  5462. (*CRT2Index) = 200;
  5463. }
  5464. }
  5465. if(SiS_Pr->SiS_CustomT == CUT_ASUSA2H_2) {
  5466. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  5467. if(SiS_Pr->SiS_SetFlag & LCDVESATiming) (*CRT2Index) = 206;
  5468. }
  5469. }
  5470. return (((*CRT2Index) != 0));
  5471. }
  5472. #endif
  5473. #ifdef CONFIG_FB_SIS_300
  5474. static void
  5475. SiS_Group2LCDSpecial(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short crt2crtc)
  5476. {
  5477. unsigned short tempcx;
  5478. static const unsigned char atable[] = {
  5479. 0xc3,0x9e,0xc3,0x9e,0x02,0x02,0x02,
  5480. 0xab,0x87,0xab,0x9e,0xe7,0x02,0x02
  5481. };
  5482. if(!SiS_Pr->UseCustomMode) {
  5483. if( ( ( (SiS_Pr->ChipType == SIS_630) ||
  5484. (SiS_Pr->ChipType == SIS_730) ) &&
  5485. (SiS_Pr->ChipRevision > 2) ) &&
  5486. (SiS_Pr->SiS_LCDResInfo == Panel_1024x768) &&
  5487. (!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) &&
  5488. (!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) ) {
  5489. if(ModeNo == 0x13) {
  5490. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,0xB9);
  5491. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x05,0xCC);
  5492. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x06,0xA6);
  5493. } else if((crt2crtc & 0x3F) == 4) {
  5494. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x2B);
  5495. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x13);
  5496. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,0xE5);
  5497. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x05,0x08);
  5498. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x06,0xE2);
  5499. }
  5500. }
  5501. if(SiS_Pr->ChipType < SIS_315H) {
  5502. if(SiS_Pr->SiS_LCDTypeInfo == 0x0c) {
  5503. crt2crtc &= 0x1f;
  5504. tempcx = 0;
  5505. if(!(SiS_Pr->SiS_VBInfo & SetNotSimuMode)) {
  5506. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  5507. tempcx += 7;
  5508. }
  5509. }
  5510. tempcx += crt2crtc;
  5511. if(crt2crtc >= 4) {
  5512. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x06,0xff);
  5513. }
  5514. if(!(SiS_Pr->SiS_VBInfo & SetNotSimuMode)) {
  5515. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  5516. if(crt2crtc == 4) {
  5517. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x28);
  5518. }
  5519. }
  5520. }
  5521. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x18);
  5522. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,atable[tempcx]);
  5523. }
  5524. }
  5525. }
  5526. }
  5527. /* For ECS A907. Highly preliminary. */
  5528. static void
  5529. SiS_Set300Part2Regs(struct SiS_Private *SiS_Pr, unsigned short ModeIdIndex, unsigned short RefreshRateTableIndex,
  5530. unsigned short ModeNo)
  5531. {
  5532. const struct SiS_Part2PortTbl *CRT2Part2Ptr = NULL;
  5533. unsigned short crt2crtc, resindex;
  5534. int i, j;
  5535. if(SiS_Pr->ChipType != SIS_300) return;
  5536. if(!(SiS_Pr->SiS_VBType & VB_SIS30xBLV)) return;
  5537. if(SiS_Pr->UseCustomMode) return;
  5538. if(ModeNo <= 0x13) {
  5539. crt2crtc = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  5540. } else {
  5541. crt2crtc = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  5542. }
  5543. resindex = crt2crtc & 0x3F;
  5544. if(SiS_Pr->SiS_SetFlag & LCDVESATiming) CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1024x768_1;
  5545. else CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1024x768_2;
  5546. /* The BIOS code (1.16.51,56) is obviously a fragment! */
  5547. if(ModeNo > 0x13) {
  5548. CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1024x768_1;
  5549. resindex = 4;
  5550. }
  5551. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x01,0x80,(CRT2Part2Ptr+resindex)->CR[0]);
  5552. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x02,0x80,(CRT2Part2Ptr+resindex)->CR[1]);
  5553. for(i = 2, j = 0x04; j <= 0x06; i++, j++ ) {
  5554. SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]);
  5555. }
  5556. for(j = 0x1c; j <= 0x1d; i++, j++ ) {
  5557. SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]);
  5558. }
  5559. for(j = 0x1f; j <= 0x21; i++, j++ ) {
  5560. SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]);
  5561. }
  5562. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x23,(CRT2Part2Ptr+resindex)->CR[10]);
  5563. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x25,0x0f,(CRT2Part2Ptr+resindex)->CR[11]);
  5564. }
  5565. #endif
  5566. static void
  5567. SiS_SetTVSpecial(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
  5568. {
  5569. if(!(SiS_Pr->SiS_VBType & VB_SIS30xBLV)) return;
  5570. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoHiVision)) return;
  5571. if(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p)) return;
  5572. if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) {
  5573. if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) {
  5574. const unsigned char specialtv[] = {
  5575. 0xa7,0x07,0xf2,0x6e,0x17,0x8b,0x73,0x53,
  5576. 0x13,0x40,0x34,0xf4,0x63,0xbb,0xcc,0x7a,
  5577. 0x58,0xe4,0x73,0xda,0x13
  5578. };
  5579. int i, j;
  5580. for(i = 0x1c, j = 0; i <= 0x30; i++, j++) {
  5581. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,specialtv[j]);
  5582. }
  5583. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x43,0x72);
  5584. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750)) {
  5585. if(SiS_Pr->SiS_TVMode & TVSetPALM) {
  5586. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x14);
  5587. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x1b);
  5588. } else {
  5589. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x14); /* 15 */
  5590. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x1a); /* 1b */
  5591. }
  5592. }
  5593. }
  5594. } else {
  5595. if((ModeNo == 0x38) || (ModeNo == 0x4a) || (ModeNo == 0x64) ||
  5596. (ModeNo == 0x52) || (ModeNo == 0x58) || (ModeNo == 0x5c)) {
  5597. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x1b); /* 21 */
  5598. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x54); /* 5a */
  5599. } else {
  5600. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x1a); /* 21 */
  5601. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x53); /* 5a */
  5602. }
  5603. }
  5604. }
  5605. static void
  5606. SiS_SetGroup2_Tail(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
  5607. {
  5608. unsigned short temp;
  5609. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
  5610. if(SiS_Pr->SiS_VGAVDE == 525) {
  5611. temp = 0xc3;
  5612. if(SiS_Pr->SiS_ModeType <= ModeVGA) {
  5613. temp++;
  5614. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) temp += 2;
  5615. }
  5616. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2f,temp);
  5617. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x30,0xb3);
  5618. } else if(SiS_Pr->SiS_VGAVDE == 420) {
  5619. temp = 0x4d;
  5620. if(SiS_Pr->SiS_ModeType <= ModeVGA) {
  5621. temp++;
  5622. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) temp++;
  5623. }
  5624. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2f,temp);
  5625. }
  5626. }
  5627. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  5628. if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) {
  5629. if(SiS_Pr->SiS_VBType & VB_SIS30xB) {
  5630. SiS_SetRegOR(SiS_Pr->SiS_Part2Port,0x1a,0x03);
  5631. /* Not always for LV, see SetGrp2 */
  5632. }
  5633. temp = 1;
  5634. if(ModeNo <= 0x13) temp = 3;
  5635. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x0b,temp);
  5636. }
  5637. #if 0
  5638. /* 651+301C, for 1280x768 - do I really need that? */
  5639. if((SiS_Pr->SiS_PanelXRes == 1280) && (SiS_Pr->SiS_PanelYRes == 768)) {
  5640. if(SiS_Pr->SiS_VBInfo & SetSimuScanMode) {
  5641. if(((SiS_Pr->SiS_HDE == 640) && (SiS_Pr->SiS_VDE == 480)) ||
  5642. ((SiS_Pr->SiS_HDE == 320) && (SiS_Pr->SiS_VDE == 240))) {
  5643. SiS_SetReg(SiS_Part2Port,0x01,0x2b);
  5644. SiS_SetReg(SiS_Part2Port,0x02,0x13);
  5645. SiS_SetReg(SiS_Part2Port,0x04,0xe5);
  5646. SiS_SetReg(SiS_Part2Port,0x05,0x08);
  5647. SiS_SetReg(SiS_Part2Port,0x06,0xe2);
  5648. SiS_SetReg(SiS_Part2Port,0x1c,0x21);
  5649. SiS_SetReg(SiS_Part2Port,0x1d,0x45);
  5650. SiS_SetReg(SiS_Part2Port,0x1f,0x0b);
  5651. SiS_SetReg(SiS_Part2Port,0x20,0x00);
  5652. SiS_SetReg(SiS_Part2Port,0x21,0xa9);
  5653. SiS_SetReg(SiS_Part2Port,0x23,0x0b);
  5654. SiS_SetReg(SiS_Part2Port,0x25,0x04);
  5655. }
  5656. }
  5657. }
  5658. #endif
  5659. }
  5660. }
  5661. static void
  5662. SiS_SetGroup2(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  5663. unsigned short RefreshRateTableIndex)
  5664. {
  5665. unsigned short i, j, tempax, tempbx, tempcx, tempch, tempcl, temp;
  5666. unsigned short push2, modeflag, crt2crtc, bridgeoffset;
  5667. unsigned int longtemp, PhaseIndex;
  5668. bool newtvphase;
  5669. const unsigned char *TimingPoint;
  5670. #ifdef CONFIG_FB_SIS_315
  5671. unsigned short resindex, CRT2Index;
  5672. const struct SiS_Part2PortTbl *CRT2Part2Ptr = NULL;
  5673. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) return;
  5674. #endif
  5675. if(ModeNo <= 0x13) {
  5676. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  5677. crt2crtc = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  5678. } else if(SiS_Pr->UseCustomMode) {
  5679. modeflag = SiS_Pr->CModeFlag;
  5680. crt2crtc = 0;
  5681. } else {
  5682. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  5683. crt2crtc = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  5684. }
  5685. temp = 0;
  5686. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToAVIDEO)) temp |= 0x08;
  5687. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToSVIDEO)) temp |= 0x04;
  5688. if(SiS_Pr->SiS_VBInfo & SetCRT2ToSCART) temp |= 0x02;
  5689. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) temp |= 0x01;
  5690. if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) temp |= 0x10;
  5691. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x00,temp);
  5692. PhaseIndex = 0x01; /* SiS_PALPhase */
  5693. TimingPoint = SiS_Pr->SiS_PALTiming;
  5694. newtvphase = false;
  5695. if( (SiS_Pr->SiS_VBType & VB_SIS30xBLV) &&
  5696. ( (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) ||
  5697. (SiS_Pr->SiS_TVMode & TVSetTVSimuMode) ) ) {
  5698. newtvphase = true;
  5699. }
  5700. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  5701. TimingPoint = SiS_Pr->SiS_HiTVExtTiming;
  5702. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  5703. TimingPoint = SiS_Pr->SiS_HiTVSt2Timing;
  5704. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) {
  5705. TimingPoint = SiS_Pr->SiS_HiTVSt1Timing;
  5706. }
  5707. }
  5708. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  5709. i = 0;
  5710. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) i = 2;
  5711. else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) i = 1;
  5712. TimingPoint = &SiS_YPbPrTable[i][0];
  5713. PhaseIndex = 0x00; /* SiS_NTSCPhase */
  5714. } else if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  5715. if(newtvphase) PhaseIndex = 0x09; /* SiS_PALPhase2 */
  5716. } else {
  5717. TimingPoint = SiS_Pr->SiS_NTSCTiming;
  5718. PhaseIndex = (SiS_Pr->SiS_TVMode & TVSetNTSCJ) ? 0x01 : 0x00; /* SiS_PALPhase : SiS_NTSCPhase */
  5719. if(newtvphase) PhaseIndex += 8; /* SiS_PALPhase2 : SiS_NTSCPhase2 */
  5720. }
  5721. if(SiS_Pr->SiS_TVMode & (TVSetPALM | TVSetPALN)) {
  5722. PhaseIndex = (SiS_Pr->SiS_TVMode & TVSetPALM) ? 0x02 : 0x03; /* SiS_PALMPhase : SiS_PALNPhase */
  5723. if(newtvphase) PhaseIndex += 8; /* SiS_PALMPhase2 : SiS_PALNPhase2 */
  5724. }
  5725. if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) {
  5726. if(SiS_Pr->SiS_TVMode & TVSetPALM) {
  5727. PhaseIndex = 0x05; /* SiS_SpecialPhaseM */
  5728. } else if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) {
  5729. PhaseIndex = 0x11; /* SiS_SpecialPhaseJ */
  5730. } else {
  5731. PhaseIndex = 0x10; /* SiS_SpecialPhase */
  5732. }
  5733. }
  5734. for(i = 0x31, j = 0; i <= 0x34; i++, j++) {
  5735. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS_TVPhase[(PhaseIndex * 4) + j]);
  5736. }
  5737. for(i = 0x01, j = 0; i <= 0x2D; i++, j++) {
  5738. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,TimingPoint[j]);
  5739. }
  5740. for(i = 0x39; i <= 0x45; i++, j++) {
  5741. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,TimingPoint[j]);
  5742. }
  5743. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  5744. if(SiS_Pr->SiS_ModeType != ModeText) {
  5745. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x3A,0x1F);
  5746. }
  5747. }
  5748. SiS_SetRegOR(SiS_Pr->SiS_Part2Port,0x0A,SiS_Pr->SiS_NewFlickerMode);
  5749. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x35,SiS_Pr->SiS_RY1COE);
  5750. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x36,SiS_Pr->SiS_RY2COE);
  5751. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x37,SiS_Pr->SiS_RY3COE);
  5752. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x38,SiS_Pr->SiS_RY4COE);
  5753. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) tempax = 950;
  5754. else if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) tempax = 680;
  5755. else if(SiS_Pr->SiS_TVMode & TVSetPAL) tempax = 520;
  5756. else tempax = 440; /* NTSC, YPbPr 525 */
  5757. if( ((SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) && (SiS_Pr->SiS_VDE <= tempax)) ||
  5758. ( (SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoHiVision) &&
  5759. ((SiS_Pr->SiS_VGAHDE == 1024) || (SiS_Pr->SiS_VDE <= tempax)) ) ) {
  5760. tempax -= SiS_Pr->SiS_VDE;
  5761. tempax >>= 1;
  5762. if(!(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p))) {
  5763. tempax >>= 1;
  5764. }
  5765. tempax &= 0x00ff;
  5766. temp = tempax + (unsigned short)TimingPoint[0];
  5767. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,temp);
  5768. temp = tempax + (unsigned short)TimingPoint[1];
  5769. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,temp);
  5770. if((SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoYPbPrHiVision) && (SiS_Pr->SiS_VGAHDE >= 1024)) {
  5771. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  5772. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x1b);
  5773. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x54);
  5774. } else {
  5775. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x17);
  5776. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x1d);
  5777. }
  5778. }
  5779. }
  5780. tempcx = SiS_Pr->SiS_HT;
  5781. if(SiS_IsDualLink(SiS_Pr)) tempcx >>= 1;
  5782. tempcx--;
  5783. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) tempcx--;
  5784. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x1B,tempcx);
  5785. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1D,0xF0,((tempcx >> 8) & 0x0f));
  5786. tempcx = SiS_Pr->SiS_HT >> 1;
  5787. if(SiS_IsDualLink(SiS_Pr)) tempcx >>= 1;
  5788. tempcx += 7;
  5789. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) tempcx -= 4;
  5790. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x22,0x0F,((tempcx << 4) & 0xf0));
  5791. tempbx = TimingPoint[j] | (TimingPoint[j+1] << 8);
  5792. tempbx += tempcx;
  5793. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x24,tempbx);
  5794. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x25,0x0F,((tempbx >> 4) & 0xf0));
  5795. tempbx += 8;
  5796. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  5797. tempbx -= 4;
  5798. tempcx = tempbx;
  5799. }
  5800. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x29,0x0F,((tempbx << 4) & 0xf0));
  5801. j += 2;
  5802. tempcx += (TimingPoint[j] | (TimingPoint[j+1] << 8));
  5803. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x27,tempcx);
  5804. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x28,0x0F,((tempcx >> 4) & 0xf0));
  5805. tempcx += 8;
  5806. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) tempcx -= 4;
  5807. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2A,0x0F,((tempcx << 4) & 0xf0));
  5808. tempcx = SiS_Pr->SiS_HT >> 1;
  5809. if(SiS_IsDualLink(SiS_Pr)) tempcx >>= 1;
  5810. j += 2;
  5811. tempcx -= (TimingPoint[j] | ((TimingPoint[j+1]) << 8));
  5812. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2D,0x0F,((tempcx << 4) & 0xf0));
  5813. tempcx -= 11;
  5814. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
  5815. tempcx = SiS_GetVGAHT2(SiS_Pr) - 1;
  5816. }
  5817. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2E,tempcx);
  5818. tempbx = SiS_Pr->SiS_VDE;
  5819. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  5820. if(SiS_Pr->SiS_VGAVDE == 360) tempbx = 746;
  5821. if(SiS_Pr->SiS_VGAVDE == 375) tempbx = 746;
  5822. if(SiS_Pr->SiS_VGAVDE == 405) tempbx = 853;
  5823. } else if( (SiS_Pr->SiS_VBInfo & SetCRT2ToTV) &&
  5824. (!(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p|TVSetYPbPr750p))) ) {
  5825. tempbx >>= 1;
  5826. if(SiS_Pr->ChipType >= SIS_315H) {
  5827. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) {
  5828. if((ModeNo <= 0x13) && (crt2crtc == 1)) tempbx++;
  5829. } else if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  5830. if(SiS_Pr->SiS_ModeType <= ModeVGA) {
  5831. if(crt2crtc == 4) tempbx++;
  5832. }
  5833. }
  5834. }
  5835. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  5836. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  5837. if((ModeNo == 0x2f) || (ModeNo == 0x5d) || (ModeNo == 0x5e)) tempbx++;
  5838. }
  5839. if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) {
  5840. if(ModeNo == 0x03) tempbx++; /* From 1.10.7w - doesn't make sense */
  5841. }
  5842. }
  5843. }
  5844. tempbx -= 2;
  5845. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2F,tempbx);
  5846. temp = (tempcx >> 8) & 0x0F;
  5847. temp |= ((tempbx >> 2) & 0xC0);
  5848. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToSVIDEO | SetCRT2ToAVIDEO)) {
  5849. temp |= 0x10;
  5850. if(SiS_Pr->SiS_VBInfo & SetCRT2ToAVIDEO) temp |= 0x20;
  5851. }
  5852. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x30,temp);
  5853. if(SiS_Pr->SiS_VBType & VB_SISPART4OVERFLOW) {
  5854. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x10,0xdf,((tempbx & 0x0400) >> 5));
  5855. }
  5856. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  5857. tempbx = SiS_Pr->SiS_VDE;
  5858. if( (SiS_Pr->SiS_VBInfo & SetCRT2ToTV) &&
  5859. (!(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p))) ) {
  5860. tempbx >>= 1;
  5861. }
  5862. tempbx -= 3;
  5863. temp = ((tempbx >> 3) & 0x60) | 0x18;
  5864. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x46,temp);
  5865. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x47,tempbx);
  5866. if(SiS_Pr->SiS_VBType & VB_SISPART4OVERFLOW) {
  5867. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x10,0xbf,((tempbx & 0x0400) >> 4));
  5868. }
  5869. }
  5870. tempbx = 0;
  5871. if(!(modeflag & HalfDCLK)) {
  5872. if(SiS_Pr->SiS_VGAHDE >= SiS_Pr->SiS_HDE) {
  5873. tempax = 0;
  5874. tempbx |= 0x20;
  5875. }
  5876. }
  5877. tempch = tempcl = 0x01;
  5878. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  5879. if(SiS_Pr->SiS_VGAHDE >= 960) {
  5880. if((!(modeflag & HalfDCLK)) || (SiS_Pr->ChipType < SIS_315H)) {
  5881. tempcl = 0x20;
  5882. if(SiS_Pr->SiS_VGAHDE >= 1280) {
  5883. tempch = 20;
  5884. tempbx &= ~0x20;
  5885. } else if(SiS_Pr->SiS_VGAHDE >= 1024) {
  5886. tempch = 25;
  5887. } else {
  5888. tempch = 25; /* OK */
  5889. }
  5890. }
  5891. }
  5892. }
  5893. if(!(tempbx & 0x20)) {
  5894. if(modeflag & HalfDCLK) tempcl <<= 1;
  5895. longtemp = ((SiS_Pr->SiS_VGAHDE * tempch) / tempcl) << 13;
  5896. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) longtemp <<= 3;
  5897. tempax = longtemp / SiS_Pr->SiS_HDE;
  5898. if(longtemp % SiS_Pr->SiS_HDE) tempax++;
  5899. tempbx |= ((tempax >> 8) & 0x1F);
  5900. tempcx = tempax >> 13;
  5901. }
  5902. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x44,tempax);
  5903. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x45,0xC0,tempbx);
  5904. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  5905. tempcx &= 0x07;
  5906. if(tempbx & 0x20) tempcx = 0;
  5907. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x46,0xF8,tempcx);
  5908. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  5909. tempbx = 0x0382;
  5910. tempcx = 0x007e;
  5911. } else {
  5912. tempbx = 0x0369;
  5913. tempcx = 0x0061;
  5914. }
  5915. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x4B,tempbx);
  5916. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x4C,tempcx);
  5917. temp = (tempcx & 0x0300) >> 6;
  5918. temp |= ((tempbx >> 8) & 0x03);
  5919. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  5920. temp |= 0x10;
  5921. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) temp |= 0x20;
  5922. else if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) temp |= 0x40;
  5923. }
  5924. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x4D,temp);
  5925. temp = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x43);
  5926. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x43,(temp - 3));
  5927. SiS_SetTVSpecial(SiS_Pr, ModeNo);
  5928. if(SiS_Pr->SiS_VBType & VB_SIS30xCLV) {
  5929. temp = 0;
  5930. if(SiS_Pr->SiS_TVMode & TVSetPALM) temp = 8;
  5931. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x4e,0xf7,temp);
  5932. }
  5933. }
  5934. if(SiS_Pr->SiS_TVMode & TVSetPALM) {
  5935. if(!(SiS_Pr->SiS_TVMode & TVSetNTSC1024)) {
  5936. temp = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x01);
  5937. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,(temp - 1));
  5938. }
  5939. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xEF);
  5940. }
  5941. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  5942. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  5943. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x0B,0x00);
  5944. }
  5945. }
  5946. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) return;
  5947. /* From here: Part2 LCD setup */
  5948. tempbx = SiS_Pr->SiS_HDE;
  5949. if(SiS_IsDualLink(SiS_Pr)) tempbx >>= 1;
  5950. tempbx--; /* RHACTE = HDE - 1 */
  5951. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2C,tempbx);
  5952. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2B,0x0F,((tempbx >> 4) & 0xf0));
  5953. temp = 0x01;
  5954. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) {
  5955. if(SiS_Pr->SiS_ModeType == ModeEGA) {
  5956. if(SiS_Pr->SiS_VGAHDE >= 1024) {
  5957. temp = 0x02;
  5958. if(SiS_Pr->SiS_SetFlag & LCDVESATiming) {
  5959. temp = 0x01;
  5960. }
  5961. }
  5962. }
  5963. }
  5964. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x0B,temp);
  5965. tempbx = SiS_Pr->SiS_VDE - 1;
  5966. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x03,tempbx);
  5967. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x0C,0xF8,((tempbx >> 8) & 0x07));
  5968. tempcx = SiS_Pr->SiS_VT - 1;
  5969. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x19,tempcx);
  5970. temp = (tempcx >> 3) & 0xE0;
  5971. if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) {
  5972. /* Enable dithering; only do this for 32bpp mode */
  5973. if(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x01) {
  5974. temp |= 0x10;
  5975. }
  5976. }
  5977. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1A,0x0f,temp);
  5978. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x09,0xF0);
  5979. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x0A,0xF0);
  5980. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x17,0xFB);
  5981. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x18,0xDF);
  5982. #ifdef CONFIG_FB_SIS_315
  5983. if(SiS_GetCRT2Part2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex,
  5984. &CRT2Index, &resindex)) {
  5985. switch(CRT2Index) {
  5986. case 206: CRT2Part2Ptr = SiS310_CRT2Part2_Asus1024x768_3; break;
  5987. default:
  5988. case 200: CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1024x768_1; break;
  5989. }
  5990. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x01,0x80,(CRT2Part2Ptr+resindex)->CR[0]);
  5991. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x02,0x80,(CRT2Part2Ptr+resindex)->CR[1]);
  5992. for(i = 2, j = 0x04; j <= 0x06; i++, j++ ) {
  5993. SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]);
  5994. }
  5995. for(j = 0x1c; j <= 0x1d; i++, j++ ) {
  5996. SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]);
  5997. }
  5998. for(j = 0x1f; j <= 0x21; i++, j++ ) {
  5999. SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]);
  6000. }
  6001. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x23,(CRT2Part2Ptr+resindex)->CR[10]);
  6002. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x25,0x0f,(CRT2Part2Ptr+resindex)->CR[11]);
  6003. SiS_SetGroup2_Tail(SiS_Pr, ModeNo);
  6004. } else {
  6005. #endif
  6006. /* Checked for 1024x768, 1280x1024, 1400x1050, 1600x1200 */
  6007. /* Clevo dual-link 1024x768 */
  6008. /* Compaq 1280x1024 has HT 1696 sometimes (calculation OK, if given HT is correct) */
  6009. /* Acer: OK, but uses different setting for VESA timing at 640/800/1024 and 640x400 */
  6010. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  6011. if((SiS_Pr->SiS_LCDInfo & LCDPass11) || (SiS_Pr->PanelYRes == SiS_Pr->SiS_VDE)) {
  6012. tempbx = SiS_Pr->SiS_VDE - 1;
  6013. tempcx = SiS_Pr->SiS_VT - 1;
  6014. } else {
  6015. tempbx = SiS_Pr->SiS_VDE + ((SiS_Pr->PanelYRes - SiS_Pr->SiS_VDE) / 2);
  6016. tempcx = SiS_Pr->SiS_VT - ((SiS_Pr->PanelYRes - SiS_Pr->SiS_VDE) / 2);
  6017. }
  6018. } else {
  6019. tempbx = SiS_Pr->PanelYRes;
  6020. tempcx = SiS_Pr->SiS_VT;
  6021. tempax = 1;
  6022. if(SiS_Pr->PanelYRes != SiS_Pr->SiS_VDE) {
  6023. tempax = SiS_Pr->PanelYRes;
  6024. /* if(SiS_Pr->SiS_VGAVDE == 525) tempax += 0x3c; */ /* 651+301C */
  6025. if(SiS_Pr->PanelYRes < SiS_Pr->SiS_VDE) {
  6026. tempax = tempcx = 0;
  6027. } else {
  6028. tempax -= SiS_Pr->SiS_VDE;
  6029. }
  6030. tempax >>= 1;
  6031. }
  6032. tempcx -= tempax; /* lcdvdes */
  6033. tempbx -= tempax; /* lcdvdee */
  6034. }
  6035. /* Non-expanding: lcdvdes = tempcx = VT-1; lcdvdee = tempbx = VDE-1 */
  6036. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x05,tempcx); /* lcdvdes */
  6037. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x06,tempbx); /* lcdvdee */
  6038. temp = (tempbx >> 5) & 0x38;
  6039. temp |= ((tempcx >> 8) & 0x07);
  6040. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,temp);
  6041. tempax = SiS_Pr->SiS_VDE;
  6042. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
  6043. tempax = SiS_Pr->PanelYRes;
  6044. }
  6045. tempcx = (SiS_Pr->SiS_VT - tempax) >> 4;
  6046. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
  6047. if(SiS_Pr->PanelYRes != SiS_Pr->SiS_VDE) {
  6048. tempcx = (SiS_Pr->SiS_VT - tempax) / 10;
  6049. }
  6050. }
  6051. tempbx = ((SiS_Pr->SiS_VT + SiS_Pr->SiS_VDE) >> 1) - 1;
  6052. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  6053. if(SiS_Pr->PanelYRes != SiS_Pr->SiS_VDE) {
  6054. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) { /* ? */
  6055. tempax = SiS_Pr->SiS_VT - SiS_Pr->PanelYRes;
  6056. if(tempax % 4) { tempax >>= 2; tempax++; }
  6057. else { tempax >>= 2; }
  6058. tempbx -= (tempax - 1);
  6059. } else {
  6060. tempbx -= 10;
  6061. if(tempbx <= SiS_Pr->SiS_VDE) tempbx = SiS_Pr->SiS_VDE + 1;
  6062. }
  6063. }
  6064. }
  6065. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  6066. tempbx++;
  6067. if((!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) || (crt2crtc == 6)) {
  6068. if(SiS_Pr->SiS_SetFlag & LCDVESATiming) {
  6069. tempbx = 770;
  6070. tempcx = 3;
  6071. }
  6072. }
  6073. }
  6074. /* non-expanding: lcdvrs = ((VT + VDE) / 2) - 10 */
  6075. if(SiS_Pr->UseCustomMode) {
  6076. tempbx = SiS_Pr->CVSyncStart;
  6077. }
  6078. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,tempbx); /* lcdvrs */
  6079. temp = (tempbx >> 4) & 0xF0;
  6080. tempbx += (tempcx + 1);
  6081. temp |= (tempbx & 0x0F);
  6082. if(SiS_Pr->UseCustomMode) {
  6083. temp &= 0xf0;
  6084. temp |= (SiS_Pr->CVSyncEnd & 0x0f);
  6085. }
  6086. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,temp);
  6087. #ifdef CONFIG_FB_SIS_300
  6088. SiS_Group2LCDSpecial(SiS_Pr, ModeNo, crt2crtc);
  6089. #endif
  6090. bridgeoffset = 7;
  6091. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) bridgeoffset += 2;
  6092. if(SiS_Pr->SiS_VBType & VB_SIS30xCLV) bridgeoffset += 2; /* OK for Averatec 1280x800 (301C) */
  6093. if(SiS_IsDualLink(SiS_Pr)) bridgeoffset++;
  6094. else if(SiS_Pr->SiS_VBType & VB_SIS302LV) bridgeoffset++; /* OK for Asus A4L 1280x800 */
  6095. /* Higher bridgeoffset shifts to the LEFT */
  6096. temp = 0;
  6097. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
  6098. if(SiS_Pr->PanelXRes != SiS_Pr->SiS_HDE) {
  6099. temp = SiS_Pr->SiS_HT - ((SiS_Pr->PanelXRes - SiS_Pr->SiS_HDE) / 2);
  6100. if(SiS_IsDualLink(SiS_Pr)) temp >>= 1;
  6101. }
  6102. }
  6103. temp += bridgeoffset;
  6104. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x1F,temp); /* lcdhdes */
  6105. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x20,0x0F,((temp >> 4) & 0xf0));
  6106. tempcx = SiS_Pr->SiS_HT;
  6107. tempax = tempbx = SiS_Pr->SiS_HDE;
  6108. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
  6109. if(SiS_Pr->PanelXRes != SiS_Pr->SiS_HDE) {
  6110. tempax = SiS_Pr->PanelXRes;
  6111. tempbx = SiS_Pr->PanelXRes - ((SiS_Pr->PanelXRes - SiS_Pr->SiS_HDE) / 2);
  6112. }
  6113. }
  6114. if(SiS_IsDualLink(SiS_Pr)) {
  6115. tempcx >>= 1;
  6116. tempbx >>= 1;
  6117. tempax >>= 1;
  6118. }
  6119. tempbx += bridgeoffset;
  6120. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x23,tempbx); /* lcdhdee */
  6121. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x25,0xF0,((tempbx >> 8) & 0x0f));
  6122. tempcx = (tempcx - tempax) >> 2;
  6123. tempbx += tempcx;
  6124. push2 = tempbx;
  6125. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) {
  6126. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  6127. if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
  6128. if(SiS_Pr->SiS_HDE == 1280) tempbx = (tempbx & 0xff00) | 0x47;
  6129. }
  6130. }
  6131. }
  6132. if(SiS_Pr->UseCustomMode) {
  6133. tempbx = SiS_Pr->CHSyncStart;
  6134. if(modeflag & HalfDCLK) tempbx <<= 1;
  6135. if(SiS_IsDualLink(SiS_Pr)) tempbx >>= 1;
  6136. tempbx += bridgeoffset;
  6137. }
  6138. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x1C,tempbx); /* lcdhrs */
  6139. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1D,0x0F,((tempbx >> 4) & 0xf0));
  6140. tempbx = push2;
  6141. tempcx <<= 1;
  6142. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
  6143. if(SiS_Pr->PanelXRes != SiS_Pr->SiS_HDE) tempcx >>= 2;
  6144. }
  6145. tempbx += tempcx;
  6146. if(SiS_Pr->UseCustomMode) {
  6147. tempbx = SiS_Pr->CHSyncEnd;
  6148. if(modeflag & HalfDCLK) tempbx <<= 1;
  6149. if(SiS_IsDualLink(SiS_Pr)) tempbx >>= 1;
  6150. tempbx += bridgeoffset;
  6151. }
  6152. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x21,tempbx); /* lcdhre */
  6153. SiS_SetGroup2_Tail(SiS_Pr, ModeNo);
  6154. #ifdef CONFIG_FB_SIS_300
  6155. SiS_Set300Part2Regs(SiS_Pr, ModeIdIndex, RefreshRateTableIndex, ModeNo);
  6156. #endif
  6157. #ifdef CONFIG_FB_SIS_315
  6158. } /* CRT2-LCD from table */
  6159. #endif
  6160. }
  6161. /*********************************************/
  6162. /* SET PART 3 REGISTER GROUP */
  6163. /*********************************************/
  6164. static void
  6165. SiS_SetGroup3(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  6166. {
  6167. unsigned short i;
  6168. const unsigned char *tempdi;
  6169. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) return;
  6170. #ifndef SIS_CP
  6171. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x00,0x00);
  6172. #else
  6173. SIS_CP_INIT301_CP
  6174. #endif
  6175. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  6176. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x13,0xFA);
  6177. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x14,0xC8);
  6178. } else {
  6179. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x13,0xF5);
  6180. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x14,0xB7);
  6181. }
  6182. if(SiS_Pr->SiS_TVMode & TVSetPALM) {
  6183. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x13,0xFA);
  6184. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x14,0xC8);
  6185. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x3D,0xA8);
  6186. }
  6187. tempdi = NULL;
  6188. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  6189. tempdi = SiS_Pr->SiS_HiTVGroup3Data;
  6190. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) {
  6191. tempdi = SiS_Pr->SiS_HiTVGroup3Simu;
  6192. }
  6193. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  6194. if(!(SiS_Pr->SiS_TVMode & TVSetYPbPr525i)) {
  6195. tempdi = SiS_HiTVGroup3_1;
  6196. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) tempdi = SiS_HiTVGroup3_2;
  6197. }
  6198. }
  6199. if(tempdi) {
  6200. for(i=0; i<=0x3E; i++) {
  6201. SiS_SetReg(SiS_Pr->SiS_Part3Port,i,tempdi[i]);
  6202. }
  6203. if(SiS_Pr->SiS_VBType & VB_SIS30xCLV) {
  6204. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) {
  6205. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x28,0x3f);
  6206. }
  6207. }
  6208. }
  6209. #ifdef SIS_CP
  6210. SIS_CP_INIT301_CP2
  6211. #endif
  6212. }
  6213. /*********************************************/
  6214. /* SET PART 4 REGISTER GROUP */
  6215. /*********************************************/
  6216. #ifdef CONFIG_FB_SIS_315
  6217. #if 0
  6218. static void
  6219. SiS_ShiftXPos(struct SiS_Private *SiS_Pr, int shift)
  6220. {
  6221. unsigned short temp, temp1, temp2;
  6222. temp1 = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x1f);
  6223. temp2 = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x20);
  6224. temp = (unsigned short)((int)((temp1 | ((temp2 & 0xf0) << 4))) + shift);
  6225. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x1f,temp);
  6226. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x20,0x0f,((temp >> 4) & 0xf0));
  6227. temp = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x2b) & 0x0f;
  6228. temp = (unsigned short)((int)(temp) + shift);
  6229. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2b,0xf0,(temp & 0x0f));
  6230. temp1 = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x43);
  6231. temp2 = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x42);
  6232. temp = (unsigned short)((int)((temp1 | ((temp2 & 0xf0) << 4))) + shift);
  6233. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x43,temp);
  6234. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x42,0x0f,((temp >> 4) & 0xf0));
  6235. }
  6236. #endif
  6237. static void
  6238. SiS_SetGroup4_C_ELV(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  6239. {
  6240. unsigned short temp, temp1;
  6241. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  6242. if(!(SiS_Pr->SiS_VBType & VB_SIS30xCLV)) return;
  6243. if(!(SiS_Pr->SiS_VBInfo & (SetCRT2ToHiVision | SetCRT2ToYPbPr525750))) return;
  6244. if(SiS_Pr->ChipType >= XGI_20) return;
  6245. if((SiS_Pr->ChipType >= SIS_661) && (SiS_Pr->SiS_ROMNew)) {
  6246. if(!(ROMAddr[0x61] & 0x04)) return;
  6247. }
  6248. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x3a,0x08);
  6249. temp = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x3a);
  6250. if(!(temp & 0x01)) {
  6251. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x3a,0xdf);
  6252. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x25,0xfc);
  6253. if((SiS_Pr->ChipType < SIS_661) && (!(SiS_Pr->SiS_ROMNew))) {
  6254. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x25,0xf8);
  6255. }
  6256. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x0f,0xfb);
  6257. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) temp = 0x0000;
  6258. else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) temp = 0x0002;
  6259. else if(SiS_Pr->SiS_TVMode & TVSetHiVision) temp = 0x0400;
  6260. else temp = 0x0402;
  6261. if((SiS_Pr->ChipType >= SIS_661) || (SiS_Pr->SiS_ROMNew)) {
  6262. temp1 = 0;
  6263. if(SiS_Pr->SiS_TVMode & TVAspect43) temp1 = 4;
  6264. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x0f,0xfb,temp1);
  6265. if(SiS_Pr->SiS_TVMode & TVAspect43LB) temp |= 0x01;
  6266. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x26,0x7c,(temp & 0xff));
  6267. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x3a,0xfb,(temp >> 8));
  6268. if(ModeNo > 0x13) {
  6269. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x39,0xfd);
  6270. }
  6271. } else {
  6272. temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x3b) & 0x03;
  6273. if(temp1 == 0x01) temp |= 0x01;
  6274. if(temp1 == 0x03) temp |= 0x04; /* ? why not 0x10? */
  6275. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x26,0xf8,(temp & 0xff));
  6276. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x3a,0xfb,(temp >> 8));
  6277. if(ModeNo > 0x13) {
  6278. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x3b,0xfd);
  6279. }
  6280. }
  6281. #if 0
  6282. if(SiS_Pr->ChipType >= SIS_661) { /* ? */
  6283. if(SiS_Pr->SiS_TVMode & TVAspect43) {
  6284. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) {
  6285. if(resinfo == SIS_RI_1024x768) {
  6286. SiS_ShiftXPos(SiS_Pr, 97);
  6287. } else {
  6288. SiS_ShiftXPos(SiS_Pr, 111);
  6289. }
  6290. } else if(SiS_Pr->SiS_TVMode & TVSetHiVision) {
  6291. SiS_ShiftXPos(SiS_Pr, 136);
  6292. }
  6293. }
  6294. }
  6295. #endif
  6296. }
  6297. }
  6298. #endif
  6299. static void
  6300. SiS_SetCRT2VCLK(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  6301. unsigned short RefreshRateTableIndex)
  6302. {
  6303. unsigned short vclkindex, temp, reg1, reg2;
  6304. if(SiS_Pr->UseCustomMode) {
  6305. reg1 = SiS_Pr->CSR2B;
  6306. reg2 = SiS_Pr->CSR2C;
  6307. } else {
  6308. vclkindex = SiS_GetVCLK2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  6309. reg1 = SiS_Pr->SiS_VBVCLKData[vclkindex].Part4_A;
  6310. reg2 = SiS_Pr->SiS_VBVCLKData[vclkindex].Part4_B;
  6311. }
  6312. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  6313. if(SiS_Pr->SiS_TVMode & (TVSetNTSC1024 | TVSet525p1024)) {
  6314. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0a,0x57);
  6315. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0b,0x46);
  6316. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1f,0xf6);
  6317. } else {
  6318. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0a,reg1);
  6319. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0b,reg2);
  6320. }
  6321. } else {
  6322. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0a,0x01);
  6323. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0b,reg2);
  6324. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0a,reg1);
  6325. }
  6326. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x12,0x00);
  6327. temp = 0x08;
  6328. if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) temp |= 0x20;
  6329. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x12,temp);
  6330. }
  6331. static void
  6332. SiS_SetDualLinkEtc(struct SiS_Private *SiS_Pr)
  6333. {
  6334. if(SiS_Pr->ChipType >= SIS_315H) {
  6335. if(SiS_Pr->SiS_VBType & VB_SISDUALLINK) {
  6336. if((SiS_CRT2IsLCD(SiS_Pr)) ||
  6337. (SiS_IsVAMode(SiS_Pr))) {
  6338. if(SiS_Pr->SiS_LCDInfo & LCDDualLink) {
  6339. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x27,0x2c);
  6340. } else {
  6341. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x27,~0x20);
  6342. }
  6343. }
  6344. }
  6345. }
  6346. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  6347. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2a,0x00);
  6348. #ifdef SET_EMI
  6349. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
  6350. #endif
  6351. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x34,0x10);
  6352. }
  6353. }
  6354. static void
  6355. SiS_SetGroup4(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  6356. unsigned short RefreshRateTableIndex)
  6357. {
  6358. unsigned short tempax, tempcx, tempbx, modeflag, temp, resinfo;
  6359. unsigned int tempebx, tempeax, templong;
  6360. if(ModeNo <= 0x13) {
  6361. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  6362. resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
  6363. } else if(SiS_Pr->UseCustomMode) {
  6364. modeflag = SiS_Pr->CModeFlag;
  6365. resinfo = 0;
  6366. } else {
  6367. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  6368. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  6369. }
  6370. if(SiS_Pr->ChipType >= SIS_315H) {
  6371. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  6372. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  6373. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x24,0x0e);
  6374. }
  6375. }
  6376. }
  6377. if(SiS_Pr->SiS_VBType & (VB_SIS30xCLV | VB_SIS302LV)) {
  6378. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  6379. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x10,0x9f);
  6380. }
  6381. }
  6382. if(SiS_Pr->ChipType >= SIS_315H) {
  6383. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  6384. SiS_SetDualLinkEtc(SiS_Pr);
  6385. return;
  6386. }
  6387. }
  6388. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x13,SiS_Pr->SiS_RVBHCFACT);
  6389. tempbx = SiS_Pr->SiS_RVBHCMAX;
  6390. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x14,tempbx);
  6391. temp = (tempbx >> 1) & 0x80;
  6392. tempcx = SiS_Pr->SiS_VGAHT - 1;
  6393. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x16,tempcx);
  6394. temp |= ((tempcx >> 5) & 0x78);
  6395. tempcx = SiS_Pr->SiS_VGAVT - 1;
  6396. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) tempcx -= 5;
  6397. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x17,tempcx);
  6398. temp |= ((tempcx >> 8) & 0x07);
  6399. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x15,temp);
  6400. tempbx = SiS_Pr->SiS_VGAHDE;
  6401. if(modeflag & HalfDCLK) tempbx >>= 1;
  6402. if(SiS_IsDualLink(SiS_Pr)) tempbx >>= 1;
  6403. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  6404. temp = 0;
  6405. if(tempbx > 800) temp = 0x60;
  6406. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  6407. temp = 0;
  6408. if(tempbx > 1024) temp = 0xC0;
  6409. else if(tempbx >= 960) temp = 0xA0;
  6410. } else if(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p)) {
  6411. temp = 0;
  6412. if(tempbx >= 1280) temp = 0x40;
  6413. else if(tempbx >= 1024) temp = 0x20;
  6414. } else {
  6415. temp = 0x80;
  6416. if(tempbx >= 1024) temp = 0xA0;
  6417. }
  6418. temp |= SiS_Pr->Init_P4_0E;
  6419. if(SiS_Pr->SiS_VBType & VB_SIS301) {
  6420. if(SiS_Pr->SiS_LCDResInfo != Panel_1280x1024) {
  6421. temp &= 0xf0;
  6422. temp |= 0x0A;
  6423. }
  6424. }
  6425. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x0E,0x10,temp);
  6426. tempeax = SiS_Pr->SiS_VGAVDE;
  6427. tempebx = SiS_Pr->SiS_VDE;
  6428. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  6429. if(!(temp & 0xE0)) tempebx >>=1;
  6430. }
  6431. tempcx = SiS_Pr->SiS_RVBHRS;
  6432. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x18,tempcx);
  6433. tempcx >>= 8;
  6434. tempcx |= 0x40;
  6435. if(tempeax <= tempebx) {
  6436. tempcx ^= 0x40;
  6437. } else {
  6438. tempeax -= tempebx;
  6439. }
  6440. tempeax *= (256 * 1024);
  6441. templong = tempeax % tempebx;
  6442. tempeax /= tempebx;
  6443. if(templong) tempeax++;
  6444. temp = (unsigned short)(tempeax & 0x000000FF);
  6445. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1B,temp);
  6446. temp = (unsigned short)((tempeax & 0x0000FF00) >> 8);
  6447. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1A,temp);
  6448. temp = (unsigned short)((tempeax >> 12) & 0x70); /* sic! */
  6449. temp |= (tempcx & 0x4F);
  6450. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x19,temp);
  6451. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  6452. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1C,0x28);
  6453. /* Calc Linebuffer max address and set/clear decimode */
  6454. tempbx = 0;
  6455. if(SiS_Pr->SiS_TVMode & (TVSetHiVision | TVSetYPbPr750p)) tempbx = 0x08;
  6456. tempax = SiS_Pr->SiS_VGAHDE;
  6457. if(modeflag & HalfDCLK) tempax >>= 1;
  6458. if(SiS_IsDualLink(SiS_Pr)) tempax >>= 1;
  6459. if(tempax > 800) {
  6460. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  6461. tempax -= 800;
  6462. } else {
  6463. tempbx = 0x08;
  6464. if(tempax == 960) tempax *= 25; /* Correct */
  6465. else if(tempax == 1024) tempax *= 25;
  6466. else tempax *= 20;
  6467. temp = tempax % 32;
  6468. tempax /= 32;
  6469. if(temp) tempax++;
  6470. tempax++;
  6471. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  6472. if(resinfo == SIS_RI_1024x768 ||
  6473. resinfo == SIS_RI_1024x576 ||
  6474. resinfo == SIS_RI_1280x1024 ||
  6475. resinfo == SIS_RI_1280x720) {
  6476. /* Otherwise white line or garbage at right edge */
  6477. tempax = (tempax & 0xff00) | 0x20;
  6478. }
  6479. }
  6480. }
  6481. }
  6482. tempax--;
  6483. temp = ((tempax >> 4) & 0x30) | tempbx;
  6484. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1D,tempax);
  6485. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1E,temp);
  6486. temp = 0x0036; tempbx = 0xD0;
  6487. if((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->SiS_VBType & VB_SISLVDS)) {
  6488. temp = 0x0026; tempbx = 0xC0; /* See En/DisableBridge() */
  6489. }
  6490. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  6491. if(!(SiS_Pr->SiS_TVMode & (TVSetNTSC1024 | TVSetHiVision | TVSetYPbPr750p | TVSetYPbPr525p))) {
  6492. temp |= 0x01;
  6493. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  6494. if(!(SiS_Pr->SiS_TVMode & TVSetTVSimuMode)) {
  6495. temp &= ~0x01;
  6496. }
  6497. }
  6498. }
  6499. }
  6500. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x1F,tempbx,temp);
  6501. tempbx = SiS_Pr->SiS_HT >> 1;
  6502. if(SiS_IsDualLink(SiS_Pr)) tempbx >>= 1;
  6503. tempbx -= 2;
  6504. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x22,tempbx);
  6505. temp = (tempbx >> 5) & 0x38;
  6506. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x21,0xC0,temp);
  6507. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  6508. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  6509. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x24,0x0e);
  6510. /* LCD-too-dark-error-source, see FinalizeLCD() */
  6511. }
  6512. }
  6513. SiS_SetDualLinkEtc(SiS_Pr);
  6514. } /* 301B */
  6515. SiS_SetCRT2VCLK(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  6516. }
  6517. /*********************************************/
  6518. /* SET PART 5 REGISTER GROUP */
  6519. /*********************************************/
  6520. static void
  6521. SiS_SetGroup5(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  6522. {
  6523. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) return;
  6524. if(SiS_Pr->SiS_ModeType == ModeVGA) {
  6525. if(!(SiS_Pr->SiS_VBInfo & (SetInSlaveMode | LoadDACFlag))) {
  6526. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);
  6527. SiS_LoadDAC(SiS_Pr, ModeNo, ModeIdIndex);
  6528. }
  6529. }
  6530. }
  6531. /*********************************************/
  6532. /* MODIFY CRT1 GROUP FOR SLAVE MODE */
  6533. /*********************************************/
  6534. static bool
  6535. SiS_GetLVDSCRT1Ptr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  6536. unsigned short RefreshRateTableIndex, unsigned short *ResIndex,
  6537. unsigned short *DisplayType)
  6538. {
  6539. unsigned short modeflag = 0;
  6540. bool checkhd = true;
  6541. /* Pass 1:1 not supported here */
  6542. if(ModeNo <= 0x13) {
  6543. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  6544. (*ResIndex) = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  6545. } else {
  6546. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  6547. (*ResIndex) = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  6548. }
  6549. (*ResIndex) &= 0x3F;
  6550. if((SiS_Pr->SiS_IF_DEF_CH70xx) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
  6551. (*DisplayType) = 80;
  6552. if((SiS_Pr->SiS_TVMode & TVSetPAL) && (!(SiS_Pr->SiS_TVMode & TVSetPALM))) {
  6553. (*DisplayType) = 82;
  6554. if(SiS_Pr->SiS_ModeType > ModeVGA) {
  6555. if(SiS_Pr->SiS_CHSOverScan) (*DisplayType) = 84;
  6556. }
  6557. }
  6558. if((*DisplayType) != 84) {
  6559. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) (*DisplayType)++;
  6560. }
  6561. } else {
  6562. (*DisplayType = 0);
  6563. switch(SiS_Pr->SiS_LCDResInfo) {
  6564. case Panel_320x240_1: (*DisplayType) = 50;
  6565. checkhd = false;
  6566. break;
  6567. case Panel_320x240_2: (*DisplayType) = 14;
  6568. break;
  6569. case Panel_320x240_3: (*DisplayType) = 18;
  6570. break;
  6571. case Panel_640x480: (*DisplayType) = 10;
  6572. break;
  6573. case Panel_1024x600: (*DisplayType) = 26;
  6574. break;
  6575. default: return true;
  6576. }
  6577. if(checkhd) {
  6578. if(modeflag & HalfDCLK) (*DisplayType)++;
  6579. }
  6580. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x600) {
  6581. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) (*DisplayType) += 2;
  6582. }
  6583. }
  6584. return true;
  6585. }
  6586. static void
  6587. SiS_ModCRT1CRTC(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  6588. unsigned short RefreshRateTableIndex)
  6589. {
  6590. unsigned short tempah, i, modeflag, j, ResIndex, DisplayType;
  6591. const struct SiS_LVDSCRT1Data *LVDSCRT1Ptr=NULL;
  6592. static const unsigned short CRIdx[] = {
  6593. 0x00, 0x02, 0x03, 0x04, 0x05, 0x06,
  6594. 0x07, 0x10, 0x11, 0x15, 0x16
  6595. };
  6596. if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) ||
  6597. (SiS_Pr->SiS_CustomT == CUT_BARCO1024) ||
  6598. (SiS_Pr->SiS_CustomT == CUT_PANEL848) ||
  6599. (SiS_Pr->SiS_CustomT == CUT_PANEL856) )
  6600. return;
  6601. if(SiS_Pr->SiS_IF_DEF_LVDS) {
  6602. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  6603. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) return;
  6604. }
  6605. } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
  6606. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) return;
  6607. } else return;
  6608. if(SiS_Pr->SiS_LCDInfo & LCDPass11) return;
  6609. if(SiS_Pr->ChipType < SIS_315H) {
  6610. if(SiS_Pr->SiS_SetFlag & SetDOSMode) return;
  6611. }
  6612. if(!(SiS_GetLVDSCRT1Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex,
  6613. &ResIndex, &DisplayType))) {
  6614. return;
  6615. }
  6616. switch(DisplayType) {
  6617. case 50: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1320x240_1; break; /* xSTN */
  6618. case 14: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1320x240_2; break; /* xSTN */
  6619. case 15: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1320x240_2_H; break; /* xSTN */
  6620. case 18: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1320x240_3; break; /* xSTN */
  6621. case 19: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1320x240_3_H; break; /* xSTN */
  6622. case 10: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1640x480_1; break;
  6623. case 11: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1640x480_1_H; break;
  6624. #if 0 /* Works better with calculated numbers */
  6625. case 26: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x600_1; break;
  6626. case 27: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x600_1_H; break;
  6627. case 28: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x600_2; break;
  6628. case 29: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x600_2_H; break;
  6629. #endif
  6630. case 80: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1UNTSC; break;
  6631. case 81: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1ONTSC; break;
  6632. case 82: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1UPAL; break;
  6633. case 83: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1OPAL; break;
  6634. case 84: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1SOPAL; break;
  6635. }
  6636. if(LVDSCRT1Ptr) {
  6637. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x11,0x7f);
  6638. for(i = 0; i <= 10; i++) {
  6639. tempah = (LVDSCRT1Ptr + ResIndex)->CR[i];
  6640. SiS_SetReg(SiS_Pr->SiS_P3d4,CRIdx[i],tempah);
  6641. }
  6642. for(i = 0x0A, j = 11; i <= 0x0C; i++, j++) {
  6643. tempah = (LVDSCRT1Ptr + ResIndex)->CR[j];
  6644. SiS_SetReg(SiS_Pr->SiS_P3c4,i,tempah);
  6645. }
  6646. tempah = (LVDSCRT1Ptr + ResIndex)->CR[14] & 0xE0;
  6647. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0E,0x1f,tempah);
  6648. if(ModeNo <= 0x13) modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  6649. else modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  6650. tempah = ((LVDSCRT1Ptr + ResIndex)->CR[14] & 0x01) << 5;
  6651. if(modeflag & DoubleScanMode) tempah |= 0x80;
  6652. SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x09,~0x020,tempah);
  6653. } else {
  6654. SiS_CalcLCDACRT1Timing(SiS_Pr, ModeNo, ModeIdIndex);
  6655. }
  6656. }
  6657. /*********************************************/
  6658. /* SET CRT2 ECLK */
  6659. /*********************************************/
  6660. static void
  6661. SiS_SetCRT2ECLK(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  6662. unsigned short RefreshRateTableIndex)
  6663. {
  6664. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  6665. unsigned short clkbase, vclkindex = 0;
  6666. unsigned char sr2b, sr2c;
  6667. if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
  6668. SiS_Pr->SiS_SetFlag &= (~ProgrammingCRT2);
  6669. if(SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK == 2) {
  6670. RefreshRateTableIndex--;
  6671. }
  6672. vclkindex = SiS_GetVCLK2Ptr(SiS_Pr, ModeNo, ModeIdIndex,
  6673. RefreshRateTableIndex);
  6674. SiS_Pr->SiS_SetFlag |= ProgrammingCRT2;
  6675. } else {
  6676. vclkindex = SiS_GetVCLK2Ptr(SiS_Pr, ModeNo, ModeIdIndex,
  6677. RefreshRateTableIndex);
  6678. }
  6679. sr2b = SiS_Pr->SiS_VCLKData[vclkindex].SR2B;
  6680. sr2c = SiS_Pr->SiS_VCLKData[vclkindex].SR2C;
  6681. if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) || (SiS_Pr->SiS_CustomT == CUT_BARCO1024)) {
  6682. if(SiS_Pr->SiS_UseROM) {
  6683. if(ROMAddr[0x220] & 0x01) {
  6684. sr2b = ROMAddr[0x227];
  6685. sr2c = ROMAddr[0x228];
  6686. }
  6687. }
  6688. }
  6689. clkbase = 0x02B;
  6690. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  6691. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  6692. clkbase += 3;
  6693. }
  6694. }
  6695. SiS_SetReg(SiS_Pr->SiS_P3c4,0x31,0x20);
  6696. SiS_SetReg(SiS_Pr->SiS_P3c4,clkbase,sr2b);
  6697. SiS_SetReg(SiS_Pr->SiS_P3c4,clkbase+1,sr2c);
  6698. SiS_SetReg(SiS_Pr->SiS_P3c4,0x31,0x10);
  6699. SiS_SetReg(SiS_Pr->SiS_P3c4,clkbase,sr2b);
  6700. SiS_SetReg(SiS_Pr->SiS_P3c4,clkbase+1,sr2c);
  6701. SiS_SetReg(SiS_Pr->SiS_P3c4,0x31,0x00);
  6702. SiS_SetReg(SiS_Pr->SiS_P3c4,clkbase,sr2b);
  6703. SiS_SetReg(SiS_Pr->SiS_P3c4,clkbase+1,sr2c);
  6704. }
  6705. /*********************************************/
  6706. /* SET UP CHRONTEL CHIPS */
  6707. /*********************************************/
  6708. static void
  6709. SiS_SetCHTVReg(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  6710. unsigned short RefreshRateTableIndex)
  6711. {
  6712. unsigned short TVType, resindex;
  6713. const struct SiS_CHTVRegData *CHTVRegData = NULL;
  6714. if(ModeNo <= 0x13)
  6715. resindex = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  6716. else
  6717. resindex = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  6718. resindex &= 0x3F;
  6719. TVType = 0;
  6720. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) TVType += 1;
  6721. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  6722. TVType += 2;
  6723. if(SiS_Pr->SiS_ModeType > ModeVGA) {
  6724. if(SiS_Pr->SiS_CHSOverScan) TVType = 8;
  6725. }
  6726. if(SiS_Pr->SiS_TVMode & TVSetPALM) {
  6727. TVType = 4;
  6728. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) TVType += 1;
  6729. } else if(SiS_Pr->SiS_TVMode & TVSetPALN) {
  6730. TVType = 6;
  6731. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) TVType += 1;
  6732. }
  6733. }
  6734. switch(TVType) {
  6735. case 0: CHTVRegData = SiS_Pr->SiS_CHTVReg_UNTSC; break;
  6736. case 1: CHTVRegData = SiS_Pr->SiS_CHTVReg_ONTSC; break;
  6737. case 2: CHTVRegData = SiS_Pr->SiS_CHTVReg_UPAL; break;
  6738. case 3: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPAL; break;
  6739. case 4: CHTVRegData = SiS_Pr->SiS_CHTVReg_UPALM; break;
  6740. case 5: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPALM; break;
  6741. case 6: CHTVRegData = SiS_Pr->SiS_CHTVReg_UPALN; break;
  6742. case 7: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPALN; break;
  6743. case 8: CHTVRegData = SiS_Pr->SiS_CHTVReg_SOPAL; break;
  6744. default: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPAL; break;
  6745. }
  6746. if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) {
  6747. #ifdef CONFIG_FB_SIS_300
  6748. /* Chrontel 7005 - I assume that it does not come with a 315 series chip */
  6749. /* We don't support modes >800x600 */
  6750. if (resindex > 5) return;
  6751. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  6752. SiS_SetCH700x(SiS_Pr,0x04,0x43); /* 0x40=76uA (PAL); 0x03=15bit non-multi RGB*/
  6753. SiS_SetCH700x(SiS_Pr,0x09,0x69); /* Black level for PAL (105)*/
  6754. } else {
  6755. SiS_SetCH700x(SiS_Pr,0x04,0x03); /* upper nibble=71uA (NTSC), 0x03=15bit non-multi RGB*/
  6756. SiS_SetCH700x(SiS_Pr,0x09,0x71); /* Black level for NTSC (113)*/
  6757. }
  6758. SiS_SetCH700x(SiS_Pr,0x00,CHTVRegData[resindex].Reg[0]); /* Mode register */
  6759. SiS_SetCH700x(SiS_Pr,0x07,CHTVRegData[resindex].Reg[1]); /* Start active video register */
  6760. SiS_SetCH700x(SiS_Pr,0x08,CHTVRegData[resindex].Reg[2]); /* Position overflow register */
  6761. SiS_SetCH700x(SiS_Pr,0x0a,CHTVRegData[resindex].Reg[3]); /* Horiz Position register */
  6762. SiS_SetCH700x(SiS_Pr,0x0b,CHTVRegData[resindex].Reg[4]); /* Vertical Position register */
  6763. /* Set minimum flicker filter for Luma channel (SR1-0=00),
  6764. minimum text enhancement (S3-2=10),
  6765. maximum flicker filter for Chroma channel (S5-4=10)
  6766. =00101000=0x28 (When reading, S1-0->S3-2, and S3-2->S1-0!)
  6767. */
  6768. SiS_SetCH700x(SiS_Pr,0x01,0x28);
  6769. /* Set video bandwidth
  6770. High bandwidth Luma composite video filter(S0=1)
  6771. low bandwidth Luma S-video filter (S2-1=00)
  6772. disable peak filter in S-video channel (S3=0)
  6773. high bandwidth Chroma Filter (S5-4=11)
  6774. =00110001=0x31
  6775. */
  6776. SiS_SetCH700x(SiS_Pr,0x03,0xb1); /* old: 3103 */
  6777. /* Register 0x3D does not exist in non-macrovision register map
  6778. (Maybe this is a macrovision register?)
  6779. */
  6780. #ifndef SIS_CP
  6781. SiS_SetCH70xx(SiS_Pr,0x3d,0x00);
  6782. #endif
  6783. /* Register 0x10 only contains 1 writable bit (S0) for sensing,
  6784. all other bits a read-only. Macrovision?
  6785. */
  6786. SiS_SetCH70xxANDOR(SiS_Pr,0x10,0x00,0x1F);
  6787. /* Register 0x11 only contains 3 writable bits (S0-S2) for
  6788. contrast enhancement (set to 010 -> gain 1 Yout = 17/16*(Yin-30) )
  6789. */
  6790. SiS_SetCH70xxANDOR(SiS_Pr,0x11,0x02,0xF8);
  6791. /* Clear DSEN
  6792. */
  6793. SiS_SetCH70xxANDOR(SiS_Pr,0x1c,0x00,0xEF);
  6794. if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) { /* ---- NTSC ---- */
  6795. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) {
  6796. if(resindex == 0x04) { /* 640x480 overscan: Mode 16 */
  6797. SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x00,0xEF); /* loop filter off */
  6798. SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x01,0xFE); /* ACIV on, no need to set FSCI */
  6799. } else if(resindex == 0x05) { /* 800x600 overscan: Mode 23 */
  6800. SiS_SetCH70xxANDOR(SiS_Pr,0x18,0x01,0xF0); /* 0x18-0x1f: FSCI 469,762,048 */
  6801. SiS_SetCH70xxANDOR(SiS_Pr,0x19,0x0C,0xF0);
  6802. SiS_SetCH70xxANDOR(SiS_Pr,0x1a,0x00,0xF0);
  6803. SiS_SetCH70xxANDOR(SiS_Pr,0x1b,0x00,0xF0);
  6804. SiS_SetCH70xxANDOR(SiS_Pr,0x1c,0x00,0xF0);
  6805. SiS_SetCH70xxANDOR(SiS_Pr,0x1d,0x00,0xF0);
  6806. SiS_SetCH70xxANDOR(SiS_Pr,0x1e,0x00,0xF0);
  6807. SiS_SetCH70xxANDOR(SiS_Pr,0x1f,0x00,0xF0);
  6808. SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x01,0xEF); /* Loop filter on for mode 23 */
  6809. SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x00,0xFE); /* ACIV off, need to set FSCI */
  6810. }
  6811. } else {
  6812. if(resindex == 0x04) { /* ----- 640x480 underscan; Mode 17 */
  6813. SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x00,0xEF); /* loop filter off */
  6814. SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x01,0xFE);
  6815. } else if(resindex == 0x05) { /* ----- 800x600 underscan: Mode 24 */
  6816. #if 0
  6817. SiS_SetCH70xxANDOR(SiS_Pr,0x18,0x01,0xF0); /* (FSCI was 0x1f1c71c7 - this is for mode 22) */
  6818. SiS_SetCH70xxANDOR(SiS_Pr,0x19,0x09,0xF0); /* FSCI for mode 24 is 428,554,851 */
  6819. SiS_SetCH70xxANDOR(SiS_Pr,0x1a,0x08,0xF0); /* 198b3a63 */
  6820. SiS_SetCH70xxANDOR(SiS_Pr,0x1b,0x0b,0xF0);
  6821. SiS_SetCH70xxANDOR(SiS_Pr,0x1c,0x04,0xF0);
  6822. SiS_SetCH70xxANDOR(SiS_Pr,0x1d,0x01,0xF0);
  6823. SiS_SetCH70xxANDOR(SiS_Pr,0x1e,0x06,0xF0);
  6824. SiS_SetCH70xxANDOR(SiS_Pr,0x1f,0x05,0xF0);
  6825. SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x00,0xEF); /* loop filter off for mode 24 */
  6826. SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x00,0xFE); * ACIV off, need to set FSCI */
  6827. #endif /* All alternatives wrong (datasheet wrong?), don't use FSCI */
  6828. SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x00,0xEF); /* loop filter off */
  6829. SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x01,0xFE);
  6830. }
  6831. }
  6832. } else { /* ---- PAL ---- */
  6833. /* We don't play around with FSCI in PAL mode */
  6834. if(resindex == 0x04) {
  6835. SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x00,0xEF); /* loop filter off */
  6836. SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x01,0xFE); /* ACIV on */
  6837. } else {
  6838. SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x00,0xEF); /* loop filter off */
  6839. SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x01,0xFE); /* ACIV on */
  6840. }
  6841. }
  6842. #endif /* 300 */
  6843. } else {
  6844. /* Chrontel 7019 - assumed that it does not come with a 300 series chip */
  6845. #ifdef CONFIG_FB_SIS_315
  6846. unsigned short temp;
  6847. /* We don't support modes >1024x768 */
  6848. if (resindex > 6) return;
  6849. temp = CHTVRegData[resindex].Reg[0];
  6850. if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) temp |= 0x10;
  6851. SiS_SetCH701x(SiS_Pr,0x00,temp);
  6852. SiS_SetCH701x(SiS_Pr,0x01,CHTVRegData[resindex].Reg[1]);
  6853. SiS_SetCH701x(SiS_Pr,0x02,CHTVRegData[resindex].Reg[2]);
  6854. SiS_SetCH701x(SiS_Pr,0x04,CHTVRegData[resindex].Reg[3]);
  6855. SiS_SetCH701x(SiS_Pr,0x03,CHTVRegData[resindex].Reg[4]);
  6856. SiS_SetCH701x(SiS_Pr,0x05,CHTVRegData[resindex].Reg[5]);
  6857. SiS_SetCH701x(SiS_Pr,0x06,CHTVRegData[resindex].Reg[6]);
  6858. temp = CHTVRegData[resindex].Reg[7];
  6859. if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) temp = 0x66;
  6860. SiS_SetCH701x(SiS_Pr,0x07,temp);
  6861. SiS_SetCH701x(SiS_Pr,0x08,CHTVRegData[resindex].Reg[8]);
  6862. SiS_SetCH701x(SiS_Pr,0x15,CHTVRegData[resindex].Reg[9]);
  6863. SiS_SetCH701x(SiS_Pr,0x1f,CHTVRegData[resindex].Reg[10]);
  6864. SiS_SetCH701x(SiS_Pr,0x0c,CHTVRegData[resindex].Reg[11]);
  6865. SiS_SetCH701x(SiS_Pr,0x0d,CHTVRegData[resindex].Reg[12]);
  6866. SiS_SetCH701x(SiS_Pr,0x0e,CHTVRegData[resindex].Reg[13]);
  6867. SiS_SetCH701x(SiS_Pr,0x0f,CHTVRegData[resindex].Reg[14]);
  6868. SiS_SetCH701x(SiS_Pr,0x10,CHTVRegData[resindex].Reg[15]);
  6869. temp = SiS_GetCH701x(SiS_Pr,0x21) & ~0x02;
  6870. /* D1 should be set for PAL, PAL-N and NTSC-J,
  6871. but I won't do that for PAL unless somebody
  6872. tells me to do so. Since the BIOS uses
  6873. non-default CIV values and blacklevels,
  6874. this might be compensated anyway.
  6875. */
  6876. if(SiS_Pr->SiS_TVMode & (TVSetPALN | TVSetNTSCJ)) temp |= 0x02;
  6877. SiS_SetCH701x(SiS_Pr,0x21,temp);
  6878. #endif /* 315 */
  6879. }
  6880. #ifdef SIS_CP
  6881. SIS_CP_INIT301_CP3
  6882. #endif
  6883. }
  6884. #ifdef CONFIG_FB_SIS_315 /* ----------- 315 series only ---------- */
  6885. void
  6886. SiS_Chrontel701xBLOn(struct SiS_Private *SiS_Pr)
  6887. {
  6888. unsigned short temp;
  6889. /* Enable Chrontel 7019 LCD panel backlight */
  6890. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  6891. if(SiS_Pr->ChipType == SIS_740) {
  6892. SiS_SetCH701x(SiS_Pr,0x66,0x65);
  6893. } else {
  6894. temp = SiS_GetCH701x(SiS_Pr,0x66);
  6895. temp |= 0x20;
  6896. SiS_SetCH701x(SiS_Pr,0x66,temp);
  6897. }
  6898. }
  6899. }
  6900. void
  6901. SiS_Chrontel701xBLOff(struct SiS_Private *SiS_Pr)
  6902. {
  6903. unsigned short temp;
  6904. /* Disable Chrontel 7019 LCD panel backlight */
  6905. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  6906. temp = SiS_GetCH701x(SiS_Pr,0x66);
  6907. temp &= 0xDF;
  6908. SiS_SetCH701x(SiS_Pr,0x66,temp);
  6909. }
  6910. }
  6911. static void
  6912. SiS_ChrontelPowerSequencing(struct SiS_Private *SiS_Pr)
  6913. {
  6914. static const unsigned char regtable[] = { 0x67, 0x68, 0x69, 0x6a, 0x6b };
  6915. static const unsigned char table1024_740[] = { 0x01, 0x02, 0x01, 0x01, 0x01 };
  6916. static const unsigned char table1400_740[] = { 0x01, 0x6e, 0x01, 0x01, 0x01 };
  6917. static const unsigned char asus1024_740[] = { 0x19, 0x6e, 0x01, 0x19, 0x09 };
  6918. static const unsigned char asus1400_740[] = { 0x19, 0x6e, 0x01, 0x19, 0x09 };
  6919. static const unsigned char table1024_650[] = { 0x01, 0x02, 0x01, 0x01, 0x02 };
  6920. static const unsigned char table1400_650[] = { 0x01, 0x02, 0x01, 0x01, 0x02 };
  6921. const unsigned char *tableptr = NULL;
  6922. int i;
  6923. /* Set up Power up/down timing */
  6924. if(SiS_Pr->ChipType == SIS_740) {
  6925. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  6926. if(SiS_Pr->SiS_CustomT == CUT_ASUSL3000D) tableptr = asus1024_740;
  6927. else tableptr = table1024_740;
  6928. } else if((SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) ||
  6929. (SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) ||
  6930. (SiS_Pr->SiS_LCDResInfo == Panel_1600x1200)) {
  6931. if(SiS_Pr->SiS_CustomT == CUT_ASUSL3000D) tableptr = asus1400_740;
  6932. else tableptr = table1400_740;
  6933. } else return;
  6934. } else {
  6935. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  6936. tableptr = table1024_650;
  6937. } else if((SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) ||
  6938. (SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) ||
  6939. (SiS_Pr->SiS_LCDResInfo == Panel_1600x1200)) {
  6940. tableptr = table1400_650;
  6941. } else return;
  6942. }
  6943. for(i=0; i<5; i++) {
  6944. SiS_SetCH701x(SiS_Pr, regtable[i], tableptr[i]);
  6945. }
  6946. }
  6947. static void
  6948. SiS_SetCH701xForLCD(struct SiS_Private *SiS_Pr)
  6949. {
  6950. const unsigned char *tableptr = NULL;
  6951. unsigned short tempbh;
  6952. int i;
  6953. static const unsigned char regtable[] = {
  6954. 0x1c, 0x5f, 0x64, 0x6f, 0x70, 0x71,
  6955. 0x72, 0x73, 0x74, 0x76, 0x78, 0x7d, 0x66
  6956. };
  6957. static const unsigned char table1024_740[] = {
  6958. 0x60, 0x02, 0x00, 0x07, 0x40, 0xed,
  6959. 0xa3, 0xc8, 0xc7, 0xac, 0xe0, 0x02, 0x44
  6960. };
  6961. static const unsigned char table1280_740[] = {
  6962. 0x60, 0x03, 0x11, 0x00, 0x40, 0xe3,
  6963. 0xad, 0xdb, 0xf6, 0xac, 0xe0, 0x02, 0x44
  6964. };
  6965. static const unsigned char table1400_740[] = {
  6966. 0x60, 0x03, 0x11, 0x00, 0x40, 0xe3,
  6967. 0xad, 0xdb, 0xf6, 0xac, 0xe0, 0x02, 0x44
  6968. };
  6969. static const unsigned char table1600_740[] = {
  6970. 0x60, 0x04, 0x11, 0x00, 0x40, 0xe3,
  6971. 0xad, 0xde, 0xf6, 0xac, 0x60, 0x1a, 0x44
  6972. };
  6973. static const unsigned char table1024_650[] = {
  6974. 0x60, 0x02, 0x00, 0x07, 0x40, 0xed,
  6975. 0xa3, 0xc8, 0xc7, 0xac, 0x60, 0x02
  6976. };
  6977. static const unsigned char table1280_650[] = {
  6978. 0x60, 0x03, 0x11, 0x00, 0x40, 0xe3,
  6979. 0xad, 0xdb, 0xf6, 0xac, 0xe0, 0x02
  6980. };
  6981. static const unsigned char table1400_650[] = {
  6982. 0x60, 0x03, 0x11, 0x00, 0x40, 0xef,
  6983. 0xad, 0xdb, 0xf6, 0xac, 0x60, 0x02
  6984. };
  6985. static const unsigned char table1600_650[] = {
  6986. 0x60, 0x04, 0x11, 0x00, 0x40, 0xe3,
  6987. 0xad, 0xde, 0xf6, 0xac, 0x60, 0x1a
  6988. };
  6989. if(SiS_Pr->ChipType == SIS_740) {
  6990. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) tableptr = table1024_740;
  6991. else if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) tableptr = table1280_740;
  6992. else if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) tableptr = table1400_740;
  6993. else if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) tableptr = table1600_740;
  6994. else return;
  6995. } else {
  6996. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) tableptr = table1024_650;
  6997. else if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) tableptr = table1280_650;
  6998. else if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) tableptr = table1400_650;
  6999. else if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) tableptr = table1600_650;
  7000. else return;
  7001. }
  7002. tempbh = SiS_GetCH701x(SiS_Pr,0x74);
  7003. if((tempbh == 0xf6) || (tempbh == 0xc7)) {
  7004. tempbh = SiS_GetCH701x(SiS_Pr,0x73);
  7005. if(tempbh == 0xc8) {
  7006. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) return;
  7007. } else if(tempbh == 0xdb) {
  7008. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) return;
  7009. if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) return;
  7010. } else if(tempbh == 0xde) {
  7011. if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) return;
  7012. }
  7013. }
  7014. if(SiS_Pr->ChipType == SIS_740) tempbh = 0x0d;
  7015. else tempbh = 0x0c;
  7016. for(i = 0; i < tempbh; i++) {
  7017. SiS_SetCH701x(SiS_Pr, regtable[i], tableptr[i]);
  7018. }
  7019. SiS_ChrontelPowerSequencing(SiS_Pr);
  7020. tempbh = SiS_GetCH701x(SiS_Pr,0x1e);
  7021. tempbh |= 0xc0;
  7022. SiS_SetCH701x(SiS_Pr,0x1e,tempbh);
  7023. if(SiS_Pr->ChipType == SIS_740) {
  7024. tempbh = SiS_GetCH701x(SiS_Pr,0x1c);
  7025. tempbh &= 0xfb;
  7026. SiS_SetCH701x(SiS_Pr,0x1c,tempbh);
  7027. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2d,0x03);
  7028. tempbh = SiS_GetCH701x(SiS_Pr,0x64);
  7029. tempbh |= 0x40;
  7030. SiS_SetCH701x(SiS_Pr,0x64,tempbh);
  7031. tempbh = SiS_GetCH701x(SiS_Pr,0x03);
  7032. tempbh &= 0x3f;
  7033. SiS_SetCH701x(SiS_Pr,0x03,tempbh);
  7034. }
  7035. }
  7036. static void
  7037. SiS_ChrontelResetVSync(struct SiS_Private *SiS_Pr)
  7038. {
  7039. unsigned char temp, temp1;
  7040. temp1 = SiS_GetCH701x(SiS_Pr,0x49);
  7041. SiS_SetCH701x(SiS_Pr,0x49,0x3e);
  7042. temp = SiS_GetCH701x(SiS_Pr,0x47);
  7043. temp &= 0x7f; /* Use external VSYNC */
  7044. SiS_SetCH701x(SiS_Pr,0x47,temp);
  7045. SiS_LongDelay(SiS_Pr, 3);
  7046. temp = SiS_GetCH701x(SiS_Pr,0x47);
  7047. temp |= 0x80; /* Use internal VSYNC */
  7048. SiS_SetCH701x(SiS_Pr,0x47,temp);
  7049. SiS_SetCH701x(SiS_Pr,0x49,temp1);
  7050. }
  7051. static void
  7052. SiS_Chrontel701xOn(struct SiS_Private *SiS_Pr)
  7053. {
  7054. unsigned short temp;
  7055. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  7056. if(SiS_Pr->ChipType == SIS_740) {
  7057. temp = SiS_GetCH701x(SiS_Pr,0x1c);
  7058. temp |= 0x04; /* Invert XCLK phase */
  7059. SiS_SetCH701x(SiS_Pr,0x1c,temp);
  7060. }
  7061. if(SiS_IsYPbPr(SiS_Pr)) {
  7062. temp = SiS_GetCH701x(SiS_Pr,0x01);
  7063. temp &= 0x3f;
  7064. temp |= 0x80; /* Enable YPrPb (HDTV) */
  7065. SiS_SetCH701x(SiS_Pr,0x01,temp);
  7066. }
  7067. if(SiS_IsChScart(SiS_Pr)) {
  7068. temp = SiS_GetCH701x(SiS_Pr,0x01);
  7069. temp &= 0x3f;
  7070. temp |= 0xc0; /* Enable SCART + CVBS */
  7071. SiS_SetCH701x(SiS_Pr,0x01,temp);
  7072. }
  7073. if(SiS_Pr->ChipType == SIS_740) {
  7074. SiS_ChrontelResetVSync(SiS_Pr);
  7075. SiS_SetCH701x(SiS_Pr,0x49,0x20); /* Enable TV path */
  7076. } else {
  7077. SiS_SetCH701x(SiS_Pr,0x49,0x20); /* Enable TV path */
  7078. temp = SiS_GetCH701x(SiS_Pr,0x49);
  7079. if(SiS_IsYPbPr(SiS_Pr)) {
  7080. temp = SiS_GetCH701x(SiS_Pr,0x73);
  7081. temp |= 0x60;
  7082. SiS_SetCH701x(SiS_Pr,0x73,temp);
  7083. }
  7084. temp = SiS_GetCH701x(SiS_Pr,0x47);
  7085. temp &= 0x7f;
  7086. SiS_SetCH701x(SiS_Pr,0x47,temp);
  7087. SiS_LongDelay(SiS_Pr, 2);
  7088. temp = SiS_GetCH701x(SiS_Pr,0x47);
  7089. temp |= 0x80;
  7090. SiS_SetCH701x(SiS_Pr,0x47,temp);
  7091. }
  7092. }
  7093. }
  7094. static void
  7095. SiS_Chrontel701xOff(struct SiS_Private *SiS_Pr)
  7096. {
  7097. unsigned short temp;
  7098. /* Complete power down of LVDS */
  7099. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  7100. if(SiS_Pr->ChipType == SIS_740) {
  7101. SiS_LongDelay(SiS_Pr, 1);
  7102. SiS_GenericDelay(SiS_Pr, 5887);
  7103. SiS_SetCH701x(SiS_Pr,0x76,0xac);
  7104. SiS_SetCH701x(SiS_Pr,0x66,0x00);
  7105. } else {
  7106. SiS_LongDelay(SiS_Pr, 2);
  7107. temp = SiS_GetCH701x(SiS_Pr,0x76);
  7108. temp &= 0xfc;
  7109. SiS_SetCH701x(SiS_Pr,0x76,temp);
  7110. SiS_SetCH701x(SiS_Pr,0x66,0x00);
  7111. }
  7112. }
  7113. }
  7114. static void
  7115. SiS_ChrontelResetDB(struct SiS_Private *SiS_Pr)
  7116. {
  7117. unsigned short temp;
  7118. if(SiS_Pr->ChipType == SIS_740) {
  7119. temp = SiS_GetCH701x(SiS_Pr,0x4a); /* Version ID */
  7120. temp &= 0x01;
  7121. if(!temp) {
  7122. if(SiS_WeHaveBacklightCtrl(SiS_Pr)) {
  7123. temp = SiS_GetCH701x(SiS_Pr,0x49);
  7124. SiS_SetCH701x(SiS_Pr,0x49,0x3e);
  7125. }
  7126. /* Reset Chrontel 7019 datapath */
  7127. SiS_SetCH701x(SiS_Pr,0x48,0x10);
  7128. SiS_LongDelay(SiS_Pr, 1);
  7129. SiS_SetCH701x(SiS_Pr,0x48,0x18);
  7130. if(SiS_WeHaveBacklightCtrl(SiS_Pr)) {
  7131. SiS_ChrontelResetVSync(SiS_Pr);
  7132. SiS_SetCH701x(SiS_Pr,0x49,temp);
  7133. }
  7134. } else {
  7135. /* Clear/set/clear GPIO */
  7136. temp = SiS_GetCH701x(SiS_Pr,0x5c);
  7137. temp &= 0xef;
  7138. SiS_SetCH701x(SiS_Pr,0x5c,temp);
  7139. temp = SiS_GetCH701x(SiS_Pr,0x5c);
  7140. temp |= 0x10;
  7141. SiS_SetCH701x(SiS_Pr,0x5c,temp);
  7142. temp = SiS_GetCH701x(SiS_Pr,0x5c);
  7143. temp &= 0xef;
  7144. SiS_SetCH701x(SiS_Pr,0x5c,temp);
  7145. temp = SiS_GetCH701x(SiS_Pr,0x61);
  7146. if(!temp) {
  7147. SiS_SetCH701xForLCD(SiS_Pr);
  7148. }
  7149. }
  7150. } else { /* 650 */
  7151. /* Reset Chrontel 7019 datapath */
  7152. SiS_SetCH701x(SiS_Pr,0x48,0x10);
  7153. SiS_LongDelay(SiS_Pr, 1);
  7154. SiS_SetCH701x(SiS_Pr,0x48,0x18);
  7155. }
  7156. }
  7157. static void
  7158. SiS_ChrontelInitTVVSync(struct SiS_Private *SiS_Pr)
  7159. {
  7160. unsigned short temp;
  7161. if(SiS_Pr->ChipType == SIS_740) {
  7162. if(SiS_WeHaveBacklightCtrl(SiS_Pr)) {
  7163. SiS_ChrontelResetVSync(SiS_Pr);
  7164. }
  7165. } else {
  7166. SiS_SetCH701x(SiS_Pr,0x76,0xaf); /* Power up LVDS block */
  7167. temp = SiS_GetCH701x(SiS_Pr,0x49);
  7168. temp &= 1;
  7169. if(temp != 1) { /* TV block powered? (0 = yes, 1 = no) */
  7170. temp = SiS_GetCH701x(SiS_Pr,0x47);
  7171. temp &= 0x70;
  7172. SiS_SetCH701x(SiS_Pr,0x47,temp); /* enable VSYNC */
  7173. SiS_LongDelay(SiS_Pr, 3);
  7174. temp = SiS_GetCH701x(SiS_Pr,0x47);
  7175. temp |= 0x80;
  7176. SiS_SetCH701x(SiS_Pr,0x47,temp); /* disable VSYNC */
  7177. }
  7178. }
  7179. }
  7180. static void
  7181. SiS_ChrontelDoSomething3(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
  7182. {
  7183. unsigned short temp,temp1;
  7184. if(SiS_Pr->ChipType == SIS_740) {
  7185. temp = SiS_GetCH701x(SiS_Pr,0x61);
  7186. if(temp < 1) {
  7187. temp++;
  7188. SiS_SetCH701x(SiS_Pr,0x61,temp);
  7189. }
  7190. SiS_SetCH701x(SiS_Pr,0x66,0x45); /* Panel power on */
  7191. SiS_SetCH701x(SiS_Pr,0x76,0xaf); /* All power on */
  7192. SiS_LongDelay(SiS_Pr, 1);
  7193. SiS_GenericDelay(SiS_Pr, 5887);
  7194. } else { /* 650 */
  7195. temp1 = 0;
  7196. temp = SiS_GetCH701x(SiS_Pr,0x61);
  7197. if(temp < 2) {
  7198. temp++;
  7199. SiS_SetCH701x(SiS_Pr,0x61,temp);
  7200. temp1 = 1;
  7201. }
  7202. SiS_SetCH701x(SiS_Pr,0x76,0xac);
  7203. temp = SiS_GetCH701x(SiS_Pr,0x66);
  7204. temp |= 0x5f;
  7205. SiS_SetCH701x(SiS_Pr,0x66,temp);
  7206. if(ModeNo > 0x13) {
  7207. if(SiS_WeHaveBacklightCtrl(SiS_Pr)) {
  7208. SiS_GenericDelay(SiS_Pr, 1023);
  7209. } else {
  7210. SiS_GenericDelay(SiS_Pr, 767);
  7211. }
  7212. } else {
  7213. if(!temp1)
  7214. SiS_GenericDelay(SiS_Pr, 767);
  7215. }
  7216. temp = SiS_GetCH701x(SiS_Pr,0x76);
  7217. temp |= 0x03;
  7218. SiS_SetCH701x(SiS_Pr,0x76,temp);
  7219. temp = SiS_GetCH701x(SiS_Pr,0x66);
  7220. temp &= 0x7f;
  7221. SiS_SetCH701x(SiS_Pr,0x66,temp);
  7222. SiS_LongDelay(SiS_Pr, 1);
  7223. }
  7224. }
  7225. static void
  7226. SiS_ChrontelDoSomething2(struct SiS_Private *SiS_Pr)
  7227. {
  7228. unsigned short temp;
  7229. SiS_LongDelay(SiS_Pr, 1);
  7230. do {
  7231. temp = SiS_GetCH701x(SiS_Pr,0x66);
  7232. temp &= 0x04; /* PLL stable? -> bail out */
  7233. if(temp == 0x04) break;
  7234. if(SiS_Pr->ChipType == SIS_740) {
  7235. /* Power down LVDS output, PLL normal operation */
  7236. SiS_SetCH701x(SiS_Pr,0x76,0xac);
  7237. }
  7238. SiS_SetCH701xForLCD(SiS_Pr);
  7239. temp = SiS_GetCH701x(SiS_Pr,0x76);
  7240. temp &= 0xfb; /* Reset PLL */
  7241. SiS_SetCH701x(SiS_Pr,0x76,temp);
  7242. SiS_LongDelay(SiS_Pr, 2);
  7243. temp = SiS_GetCH701x(SiS_Pr,0x76);
  7244. temp |= 0x04; /* PLL normal operation */
  7245. SiS_SetCH701x(SiS_Pr,0x76,temp);
  7246. if(SiS_Pr->ChipType == SIS_740) {
  7247. SiS_SetCH701x(SiS_Pr,0x78,0xe0); /* PLL loop filter */
  7248. } else {
  7249. SiS_SetCH701x(SiS_Pr,0x78,0x60);
  7250. }
  7251. SiS_LongDelay(SiS_Pr, 2);
  7252. } while(0);
  7253. SiS_SetCH701x(SiS_Pr,0x77,0x00); /* MV? */
  7254. }
  7255. static void
  7256. SiS_ChrontelDoSomething1(struct SiS_Private *SiS_Pr)
  7257. {
  7258. unsigned short temp;
  7259. temp = SiS_GetCH701x(SiS_Pr,0x03);
  7260. temp |= 0x80; /* Set datapath 1 to TV */
  7261. temp &= 0xbf; /* Set datapath 2 to LVDS */
  7262. SiS_SetCH701x(SiS_Pr,0x03,temp);
  7263. if(SiS_Pr->ChipType == SIS_740) {
  7264. temp = SiS_GetCH701x(SiS_Pr,0x1c);
  7265. temp &= 0xfb; /* Normal XCLK phase */
  7266. SiS_SetCH701x(SiS_Pr,0x1c,temp);
  7267. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2d,0x03);
  7268. temp = SiS_GetCH701x(SiS_Pr,0x64);
  7269. temp |= 0x40; /* ? Bit not defined */
  7270. SiS_SetCH701x(SiS_Pr,0x64,temp);
  7271. temp = SiS_GetCH701x(SiS_Pr,0x03);
  7272. temp &= 0x3f; /* D1 input to both LVDS and TV */
  7273. SiS_SetCH701x(SiS_Pr,0x03,temp);
  7274. if(SiS_Pr->SiS_CustomT == CUT_ASUSL3000D) {
  7275. SiS_SetCH701x(SiS_Pr,0x63,0x40); /* LVDS off */
  7276. SiS_LongDelay(SiS_Pr, 1);
  7277. SiS_SetCH701x(SiS_Pr,0x63,0x00); /* LVDS on */
  7278. SiS_ChrontelResetDB(SiS_Pr);
  7279. SiS_ChrontelDoSomething2(SiS_Pr);
  7280. SiS_ChrontelDoSomething3(SiS_Pr, 0);
  7281. } else {
  7282. temp = SiS_GetCH701x(SiS_Pr,0x66);
  7283. if(temp != 0x45) {
  7284. SiS_ChrontelResetDB(SiS_Pr);
  7285. SiS_ChrontelDoSomething2(SiS_Pr);
  7286. SiS_ChrontelDoSomething3(SiS_Pr, 0);
  7287. }
  7288. }
  7289. } else { /* 650 */
  7290. SiS_ChrontelResetDB(SiS_Pr);
  7291. SiS_ChrontelDoSomething2(SiS_Pr);
  7292. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x34);
  7293. SiS_ChrontelDoSomething3(SiS_Pr,temp);
  7294. SiS_SetCH701x(SiS_Pr,0x76,0xaf); /* All power on, LVDS normal operation */
  7295. }
  7296. }
  7297. #endif /* 315 series */
  7298. /*********************************************/
  7299. /* MAIN: SET CRT2 REGISTER GROUP */
  7300. /*********************************************/
  7301. bool
  7302. SiS_SetCRT2Group(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
  7303. {
  7304. #ifdef CONFIG_FB_SIS_300
  7305. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  7306. #endif
  7307. unsigned short ModeIdIndex, RefreshRateTableIndex;
  7308. SiS_Pr->SiS_SetFlag |= ProgrammingCRT2;
  7309. if(!SiS_Pr->UseCustomMode) {
  7310. SiS_SearchModeID(SiS_Pr, &ModeNo, &ModeIdIndex);
  7311. } else {
  7312. ModeIdIndex = 0;
  7313. }
  7314. /* Used for shifting CR33 */
  7315. SiS_Pr->SiS_SelectCRT2Rate = 4;
  7316. SiS_UnLockCRT2(SiS_Pr);
  7317. RefreshRateTableIndex = SiS_GetRatePtr(SiS_Pr, ModeNo, ModeIdIndex);
  7318. SiS_SaveCRT2Info(SiS_Pr,ModeNo);
  7319. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7320. SiS_DisableBridge(SiS_Pr);
  7321. if((SiS_Pr->SiS_IF_DEF_LVDS == 1) && (SiS_Pr->ChipType == SIS_730)) {
  7322. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,0x80);
  7323. }
  7324. SiS_SetCRT2ModeRegs(SiS_Pr, ModeNo, ModeIdIndex);
  7325. }
  7326. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) {
  7327. SiS_LockCRT2(SiS_Pr);
  7328. SiS_DisplayOn(SiS_Pr);
  7329. return true;
  7330. }
  7331. SiS_GetCRT2Data(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7332. /* Set up Panel Link for LVDS and LCDA */
  7333. SiS_Pr->SiS_LCDHDES = SiS_Pr->SiS_LCDVDES = 0;
  7334. if( (SiS_Pr->SiS_IF_DEF_LVDS == 1) ||
  7335. ((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) ||
  7336. ((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->SiS_VBType & VB_SIS30xBLV)) ) {
  7337. SiS_GetLVDSDesData(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7338. }
  7339. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7340. SiS_SetGroup1(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7341. }
  7342. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  7343. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7344. SiS_SetGroup2(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7345. #ifdef CONFIG_FB_SIS_315
  7346. SiS_SetGroup2_C_ELV(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7347. #endif
  7348. SiS_SetGroup3(SiS_Pr, ModeNo, ModeIdIndex);
  7349. SiS_SetGroup4(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7350. #ifdef CONFIG_FB_SIS_315
  7351. SiS_SetGroup4_C_ELV(SiS_Pr, ModeNo, ModeIdIndex);
  7352. #endif
  7353. SiS_SetGroup5(SiS_Pr, ModeNo, ModeIdIndex);
  7354. SiS_SetCRT2Sync(SiS_Pr, ModeNo, RefreshRateTableIndex);
  7355. /* For 301BDH (Panel link initialization): */
  7356. if((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) {
  7357. if(!((SiS_Pr->SiS_SetFlag & SetDOSMode) && ((ModeNo == 0x03) || (ModeNo == 0x10)))) {
  7358. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  7359. SiS_ModCRT1CRTC(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7360. }
  7361. }
  7362. SiS_SetCRT2ECLK(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7363. }
  7364. }
  7365. } else {
  7366. SiS_SetCRT2Sync(SiS_Pr, ModeNo, RefreshRateTableIndex);
  7367. SiS_ModCRT1CRTC(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex);
  7368. SiS_SetCRT2ECLK(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex);
  7369. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7370. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  7371. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  7372. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  7373. #ifdef CONFIG_FB_SIS_315
  7374. SiS_SetCH701xForLCD(SiS_Pr);
  7375. #endif
  7376. }
  7377. }
  7378. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  7379. SiS_SetCHTVReg(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex);
  7380. }
  7381. }
  7382. }
  7383. }
  7384. #ifdef CONFIG_FB_SIS_300
  7385. if(SiS_Pr->ChipType < SIS_315H) {
  7386. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7387. if(SiS_Pr->SiS_UseOEM) {
  7388. if((SiS_Pr->SiS_UseROM) && (SiS_Pr->SiS_UseOEM == -1)) {
  7389. if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) {
  7390. SiS_OEM300Setting(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7391. }
  7392. } else {
  7393. SiS_OEM300Setting(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7394. }
  7395. }
  7396. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  7397. if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) ||
  7398. (SiS_Pr->SiS_CustomT == CUT_BARCO1024)) {
  7399. SetOEMLCDData2(SiS_Pr, ModeNo, ModeIdIndex,RefreshRateTableIndex);
  7400. }
  7401. SiS_DisplayOn(SiS_Pr);
  7402. }
  7403. }
  7404. }
  7405. #endif
  7406. #ifdef CONFIG_FB_SIS_315
  7407. if(SiS_Pr->ChipType >= SIS_315H) {
  7408. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7409. if(SiS_Pr->ChipType < SIS_661) {
  7410. SiS_FinalizeLCD(SiS_Pr, ModeNo, ModeIdIndex);
  7411. SiS_OEM310Setting(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7412. } else {
  7413. SiS_OEM661Setting(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7414. }
  7415. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x01,0x40);
  7416. }
  7417. }
  7418. #endif
  7419. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7420. SiS_EnableBridge(SiS_Pr);
  7421. }
  7422. SiS_DisplayOn(SiS_Pr);
  7423. if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) {
  7424. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  7425. /* Disable LCD panel when using TV */
  7426. SiS_SetRegSR11ANDOR(SiS_Pr,0xFF,0x0C);
  7427. } else {
  7428. /* Disable TV when using LCD */
  7429. SiS_SetCH70xxANDOR(SiS_Pr,0x0e,0x01,0xf8);
  7430. }
  7431. }
  7432. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7433. SiS_LockCRT2(SiS_Pr);
  7434. }
  7435. return true;
  7436. }
  7437. /*********************************************/
  7438. /* ENABLE/DISABLE LCD BACKLIGHT (SIS) */
  7439. /*********************************************/
  7440. void
  7441. SiS_SiS30xBLOn(struct SiS_Private *SiS_Pr)
  7442. {
  7443. /* Switch on LCD backlight on SiS30xLV */
  7444. SiS_DDC2Delay(SiS_Pr,0xff00);
  7445. if(!(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x26) & 0x02)) {
  7446. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x02);
  7447. SiS_WaitVBRetrace(SiS_Pr);
  7448. }
  7449. if(!(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x26) & 0x01)) {
  7450. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x01);
  7451. }
  7452. }
  7453. void
  7454. SiS_SiS30xBLOff(struct SiS_Private *SiS_Pr)
  7455. {
  7456. /* Switch off LCD backlight on SiS30xLV */
  7457. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFE);
  7458. SiS_DDC2Delay(SiS_Pr,0xff00);
  7459. }
  7460. /*********************************************/
  7461. /* DDC RELATED FUNCTIONS */
  7462. /*********************************************/
  7463. static void
  7464. SiS_SetupDDCN(struct SiS_Private *SiS_Pr)
  7465. {
  7466. SiS_Pr->SiS_DDC_NData = ~SiS_Pr->SiS_DDC_Data;
  7467. SiS_Pr->SiS_DDC_NClk = ~SiS_Pr->SiS_DDC_Clk;
  7468. if((SiS_Pr->SiS_DDC_Index == 0x11) && (SiS_Pr->SiS_SensibleSR11)) {
  7469. SiS_Pr->SiS_DDC_NData &= 0x0f;
  7470. SiS_Pr->SiS_DDC_NClk &= 0x0f;
  7471. }
  7472. }
  7473. #ifdef CONFIG_FB_SIS_300
  7474. static unsigned char *
  7475. SiS_SetTrumpBlockLoop(struct SiS_Private *SiS_Pr, unsigned char *dataptr)
  7476. {
  7477. int i, j, num;
  7478. unsigned short tempah,temp;
  7479. unsigned char *mydataptr;
  7480. for(i=0; i<20; i++) { /* Do 20 attempts to write */
  7481. mydataptr = dataptr;
  7482. num = *mydataptr++;
  7483. if(!num) return mydataptr;
  7484. if(i) {
  7485. SiS_SetStop(SiS_Pr);
  7486. SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT * 2);
  7487. }
  7488. if(SiS_SetStart(SiS_Pr)) continue; /* Set start condition */
  7489. tempah = SiS_Pr->SiS_DDC_DeviceAddr;
  7490. temp = SiS_WriteDDC2Data(SiS_Pr,tempah); /* Write DAB (S0=0=write) */
  7491. if(temp) continue; /* (ERROR: no ack) */
  7492. tempah = *mydataptr++;
  7493. temp = SiS_WriteDDC2Data(SiS_Pr,tempah); /* Write register number */
  7494. if(temp) continue; /* (ERROR: no ack) */
  7495. for(j=0; j<num; j++) {
  7496. tempah = *mydataptr++;
  7497. temp = SiS_WriteDDC2Data(SiS_Pr,tempah);/* Write DAB (S0=0=write) */
  7498. if(temp) break;
  7499. }
  7500. if(temp) continue;
  7501. if(SiS_SetStop(SiS_Pr)) continue;
  7502. return mydataptr;
  7503. }
  7504. return NULL;
  7505. }
  7506. static bool
  7507. SiS_SetTrumpionBlock(struct SiS_Private *SiS_Pr, unsigned char *dataptr)
  7508. {
  7509. SiS_Pr->SiS_DDC_DeviceAddr = 0xF0; /* DAB (Device Address Byte) */
  7510. SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */
  7511. SiS_Pr->SiS_DDC_Data = 0x02; /* Bitmask in IndexReg for Data */
  7512. SiS_Pr->SiS_DDC_Clk = 0x01; /* Bitmask in IndexReg for Clk */
  7513. SiS_SetupDDCN(SiS_Pr);
  7514. SiS_SetSwitchDDC2(SiS_Pr);
  7515. while(*dataptr) {
  7516. dataptr = SiS_SetTrumpBlockLoop(SiS_Pr, dataptr);
  7517. if(!dataptr) return false;
  7518. }
  7519. return true;
  7520. }
  7521. #endif
  7522. /* The Chrontel 700x is connected to the 630/730 via
  7523. * the 630/730's DDC/I2C port.
  7524. *
  7525. * On 630(S)T chipset, the index changed from 0x11 to
  7526. * 0x0a, possibly for working around the DDC problems
  7527. */
  7528. static bool
  7529. SiS_SetChReg(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val, unsigned short myor)
  7530. {
  7531. unsigned short temp, i;
  7532. for(i=0; i<20; i++) { /* Do 20 attempts to write */
  7533. if(i) {
  7534. SiS_SetStop(SiS_Pr);
  7535. SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT * 4);
  7536. }
  7537. if(SiS_SetStart(SiS_Pr)) continue; /* Set start condition */
  7538. temp = SiS_WriteDDC2Data(SiS_Pr, SiS_Pr->SiS_DDC_DeviceAddr); /* Write DAB (S0=0=write) */
  7539. if(temp) continue; /* (ERROR: no ack) */
  7540. temp = SiS_WriteDDC2Data(SiS_Pr, (reg | myor)); /* Write RAB (700x: set bit 7, see datasheet) */
  7541. if(temp) continue; /* (ERROR: no ack) */
  7542. temp = SiS_WriteDDC2Data(SiS_Pr, val); /* Write data */
  7543. if(temp) continue; /* (ERROR: no ack) */
  7544. if(SiS_SetStop(SiS_Pr)) continue; /* Set stop condition */
  7545. SiS_Pr->SiS_ChrontelInit = 1;
  7546. return true;
  7547. }
  7548. return false;
  7549. }
  7550. /* Write to Chrontel 700x */
  7551. void
  7552. SiS_SetCH700x(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val)
  7553. {
  7554. SiS_Pr->SiS_DDC_DeviceAddr = 0xEA; /* DAB (Device Address Byte) */
  7555. SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT);
  7556. if(!(SiS_Pr->SiS_ChrontelInit)) {
  7557. SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */
  7558. SiS_Pr->SiS_DDC_Data = 0x02; /* Bitmask in IndexReg for Data */
  7559. SiS_Pr->SiS_DDC_Clk = 0x01; /* Bitmask in IndexReg for Clk */
  7560. SiS_SetupDDCN(SiS_Pr);
  7561. }
  7562. if( (!(SiS_SetChReg(SiS_Pr, reg, val, 0x80))) &&
  7563. (!(SiS_Pr->SiS_ChrontelInit)) ) {
  7564. SiS_Pr->SiS_DDC_Index = 0x0a;
  7565. SiS_Pr->SiS_DDC_Data = 0x80;
  7566. SiS_Pr->SiS_DDC_Clk = 0x40;
  7567. SiS_SetupDDCN(SiS_Pr);
  7568. SiS_SetChReg(SiS_Pr, reg, val, 0x80);
  7569. }
  7570. }
  7571. /* Write to Chrontel 701x */
  7572. /* Parameter is [Data (S15-S8) | Register no (S7-S0)] */
  7573. void
  7574. SiS_SetCH701x(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val)
  7575. {
  7576. SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */
  7577. SiS_Pr->SiS_DDC_Data = 0x08; /* Bitmask in IndexReg for Data */
  7578. SiS_Pr->SiS_DDC_Clk = 0x04; /* Bitmask in IndexReg for Clk */
  7579. SiS_SetupDDCN(SiS_Pr);
  7580. SiS_Pr->SiS_DDC_DeviceAddr = 0xEA; /* DAB (Device Address Byte) */
  7581. SiS_SetChReg(SiS_Pr, reg, val, 0);
  7582. }
  7583. static
  7584. void
  7585. SiS_SetCH70xx(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val)
  7586. {
  7587. if(SiS_Pr->SiS_IF_DEF_CH70xx == 1)
  7588. SiS_SetCH700x(SiS_Pr, reg, val);
  7589. else
  7590. SiS_SetCH701x(SiS_Pr, reg, val);
  7591. }
  7592. static unsigned short
  7593. SiS_GetChReg(struct SiS_Private *SiS_Pr, unsigned short myor)
  7594. {
  7595. unsigned short tempah, temp, i;
  7596. for(i=0; i<20; i++) { /* Do 20 attempts to read */
  7597. if(i) {
  7598. SiS_SetStop(SiS_Pr);
  7599. SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT * 4);
  7600. }
  7601. if(SiS_SetStart(SiS_Pr)) continue; /* Set start condition */
  7602. temp = SiS_WriteDDC2Data(SiS_Pr,SiS_Pr->SiS_DDC_DeviceAddr); /* Write DAB (S0=0=write) */
  7603. if(temp) continue; /* (ERROR: no ack) */
  7604. temp = SiS_WriteDDC2Data(SiS_Pr,SiS_Pr->SiS_DDC_ReadAddr | myor); /* Write RAB (700x: | 0x80) */
  7605. if(temp) continue; /* (ERROR: no ack) */
  7606. if (SiS_SetStart(SiS_Pr)) continue; /* Re-start */
  7607. temp = SiS_WriteDDC2Data(SiS_Pr,SiS_Pr->SiS_DDC_DeviceAddr | 0x01);/* DAB (S0=1=read) */
  7608. if(temp) continue; /* (ERROR: no ack) */
  7609. tempah = SiS_ReadDDC2Data(SiS_Pr); /* Read byte */
  7610. if(SiS_SetStop(SiS_Pr)) continue; /* Stop condition */
  7611. SiS_Pr->SiS_ChrontelInit = 1;
  7612. return tempah;
  7613. }
  7614. return 0xFFFF;
  7615. }
  7616. /* Read from Chrontel 700x */
  7617. /* Parameter is [Register no (S7-S0)] */
  7618. unsigned short
  7619. SiS_GetCH700x(struct SiS_Private *SiS_Pr, unsigned short tempbx)
  7620. {
  7621. unsigned short result;
  7622. SiS_Pr->SiS_DDC_DeviceAddr = 0xEA; /* DAB */
  7623. SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT);
  7624. if(!(SiS_Pr->SiS_ChrontelInit)) {
  7625. SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */
  7626. SiS_Pr->SiS_DDC_Data = 0x02; /* Bitmask in IndexReg for Data */
  7627. SiS_Pr->SiS_DDC_Clk = 0x01; /* Bitmask in IndexReg for Clk */
  7628. SiS_SetupDDCN(SiS_Pr);
  7629. }
  7630. SiS_Pr->SiS_DDC_ReadAddr = tempbx;
  7631. if( ((result = SiS_GetChReg(SiS_Pr,0x80)) == 0xFFFF) &&
  7632. (!SiS_Pr->SiS_ChrontelInit) ) {
  7633. SiS_Pr->SiS_DDC_Index = 0x0a;
  7634. SiS_Pr->SiS_DDC_Data = 0x80;
  7635. SiS_Pr->SiS_DDC_Clk = 0x40;
  7636. SiS_SetupDDCN(SiS_Pr);
  7637. result = SiS_GetChReg(SiS_Pr,0x80);
  7638. }
  7639. return result;
  7640. }
  7641. /* Read from Chrontel 701x */
  7642. /* Parameter is [Register no (S7-S0)] */
  7643. unsigned short
  7644. SiS_GetCH701x(struct SiS_Private *SiS_Pr, unsigned short tempbx)
  7645. {
  7646. SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */
  7647. SiS_Pr->SiS_DDC_Data = 0x08; /* Bitmask in IndexReg for Data */
  7648. SiS_Pr->SiS_DDC_Clk = 0x04; /* Bitmask in IndexReg for Clk */
  7649. SiS_SetupDDCN(SiS_Pr);
  7650. SiS_Pr->SiS_DDC_DeviceAddr = 0xEA; /* DAB */
  7651. SiS_Pr->SiS_DDC_ReadAddr = tempbx;
  7652. return SiS_GetChReg(SiS_Pr,0);
  7653. }
  7654. /* Read from Chrontel 70xx */
  7655. /* Parameter is [Register no (S7-S0)] */
  7656. static
  7657. unsigned short
  7658. SiS_GetCH70xx(struct SiS_Private *SiS_Pr, unsigned short tempbx)
  7659. {
  7660. if(SiS_Pr->SiS_IF_DEF_CH70xx == 1)
  7661. return SiS_GetCH700x(SiS_Pr, tempbx);
  7662. else
  7663. return SiS_GetCH701x(SiS_Pr, tempbx);
  7664. }
  7665. void
  7666. SiS_SetCH70xxANDOR(struct SiS_Private *SiS_Pr, unsigned short reg,
  7667. unsigned char myor, unsigned short myand)
  7668. {
  7669. unsigned short tempbl;
  7670. tempbl = (SiS_GetCH70xx(SiS_Pr, (reg & 0xFF)) & myand) | myor;
  7671. SiS_SetCH70xx(SiS_Pr, reg, tempbl);
  7672. }
  7673. /* Our own DDC functions */
  7674. static
  7675. unsigned short
  7676. SiS_InitDDCRegs(struct SiS_Private *SiS_Pr, unsigned int VBFlags, int VGAEngine,
  7677. unsigned short adaptnum, unsigned short DDCdatatype, bool checkcr32,
  7678. unsigned int VBFlags2)
  7679. {
  7680. unsigned char ddcdtype[] = { 0xa0, 0xa0, 0xa0, 0xa2, 0xa6 };
  7681. unsigned char flag, cr32;
  7682. unsigned short temp = 0, myadaptnum = adaptnum;
  7683. if(adaptnum != 0) {
  7684. if(!(VBFlags2 & VB2_SISTMDSBRIDGE)) return 0xFFFF;
  7685. if((VBFlags2 & VB2_30xBDH) && (adaptnum == 1)) return 0xFFFF;
  7686. }
  7687. /* adapternum for SiS bridges: 0 = CRT1, 1 = LCD, 2 = VGA2 */
  7688. SiS_Pr->SiS_ChrontelInit = 0; /* force re-detection! */
  7689. SiS_Pr->SiS_DDC_SecAddr = 0;
  7690. SiS_Pr->SiS_DDC_DeviceAddr = ddcdtype[DDCdatatype];
  7691. SiS_Pr->SiS_DDC_Port = SiS_Pr->SiS_P3c4;
  7692. SiS_Pr->SiS_DDC_Index = 0x11;
  7693. flag = 0xff;
  7694. cr32 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x32);
  7695. #if 0
  7696. if(VBFlags2 & VB2_SISBRIDGE) {
  7697. if(myadaptnum == 0) {
  7698. if(!(cr32 & 0x20)) {
  7699. myadaptnum = 2;
  7700. if(!(cr32 & 0x10)) {
  7701. myadaptnum = 1;
  7702. if(!(cr32 & 0x08)) {
  7703. myadaptnum = 0;
  7704. }
  7705. }
  7706. }
  7707. }
  7708. }
  7709. #endif
  7710. if(VGAEngine == SIS_300_VGA) { /* 300 series */
  7711. if(myadaptnum != 0) {
  7712. flag = 0;
  7713. if(VBFlags2 & VB2_SISBRIDGE) {
  7714. SiS_Pr->SiS_DDC_Port = SiS_Pr->SiS_Part4Port;
  7715. SiS_Pr->SiS_DDC_Index = 0x0f;
  7716. }
  7717. }
  7718. if(!(VBFlags2 & VB2_301)) {
  7719. if((cr32 & 0x80) && (checkcr32)) {
  7720. if(myadaptnum >= 1) {
  7721. if(!(cr32 & 0x08)) {
  7722. myadaptnum = 1;
  7723. if(!(cr32 & 0x10)) return 0xFFFF;
  7724. }
  7725. }
  7726. }
  7727. }
  7728. temp = 4 - (myadaptnum * 2);
  7729. if(flag) temp = 0;
  7730. } else { /* 315/330 series */
  7731. /* here we simplify: 0 = CRT1, 1 = CRT2 (VGA, LCD) */
  7732. if(VBFlags2 & VB2_SISBRIDGE) {
  7733. if(myadaptnum == 2) {
  7734. myadaptnum = 1;
  7735. }
  7736. }
  7737. if(myadaptnum == 1) {
  7738. flag = 0;
  7739. if(VBFlags2 & VB2_SISBRIDGE) {
  7740. SiS_Pr->SiS_DDC_Port = SiS_Pr->SiS_Part4Port;
  7741. SiS_Pr->SiS_DDC_Index = 0x0f;
  7742. }
  7743. }
  7744. if((cr32 & 0x80) && (checkcr32)) {
  7745. if(myadaptnum >= 1) {
  7746. if(!(cr32 & 0x08)) {
  7747. myadaptnum = 1;
  7748. if(!(cr32 & 0x10)) return 0xFFFF;
  7749. }
  7750. }
  7751. }
  7752. temp = myadaptnum;
  7753. if(myadaptnum == 1) {
  7754. temp = 0;
  7755. if(VBFlags2 & VB2_LVDS) flag = 0xff;
  7756. }
  7757. if(flag) temp = 0;
  7758. }
  7759. SiS_Pr->SiS_DDC_Data = 0x02 << temp;
  7760. SiS_Pr->SiS_DDC_Clk = 0x01 << temp;
  7761. SiS_SetupDDCN(SiS_Pr);
  7762. return 0;
  7763. }
  7764. static unsigned short
  7765. SiS_WriteDABDDC(struct SiS_Private *SiS_Pr)
  7766. {
  7767. if(SiS_SetStart(SiS_Pr)) return 0xFFFF;
  7768. if(SiS_WriteDDC2Data(SiS_Pr, SiS_Pr->SiS_DDC_DeviceAddr)) {
  7769. return 0xFFFF;
  7770. }
  7771. if(SiS_WriteDDC2Data(SiS_Pr, SiS_Pr->SiS_DDC_SecAddr)) {
  7772. return 0xFFFF;
  7773. }
  7774. return 0;
  7775. }
  7776. static unsigned short
  7777. SiS_PrepareReadDDC(struct SiS_Private *SiS_Pr)
  7778. {
  7779. if(SiS_SetStart(SiS_Pr)) return 0xFFFF;
  7780. if(SiS_WriteDDC2Data(SiS_Pr, (SiS_Pr->SiS_DDC_DeviceAddr | 0x01))) {
  7781. return 0xFFFF;
  7782. }
  7783. return 0;
  7784. }
  7785. static unsigned short
  7786. SiS_PrepareDDC(struct SiS_Private *SiS_Pr)
  7787. {
  7788. if(SiS_WriteDABDDC(SiS_Pr)) SiS_WriteDABDDC(SiS_Pr);
  7789. if(SiS_PrepareReadDDC(SiS_Pr)) return (SiS_PrepareReadDDC(SiS_Pr));
  7790. return 0;
  7791. }
  7792. static void
  7793. SiS_SendACK(struct SiS_Private *SiS_Pr, unsigned short yesno)
  7794. {
  7795. SiS_SetSCLKLow(SiS_Pr);
  7796. if(yesno) {
  7797. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  7798. SiS_Pr->SiS_DDC_Index,
  7799. SiS_Pr->SiS_DDC_NData,
  7800. SiS_Pr->SiS_DDC_Data);
  7801. } else {
  7802. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  7803. SiS_Pr->SiS_DDC_Index,
  7804. SiS_Pr->SiS_DDC_NData,
  7805. 0);
  7806. }
  7807. SiS_SetSCLKHigh(SiS_Pr);
  7808. }
  7809. static unsigned short
  7810. SiS_DoProbeDDC(struct SiS_Private *SiS_Pr)
  7811. {
  7812. unsigned char mask, value;
  7813. unsigned short temp, ret=0;
  7814. bool failed = false;
  7815. SiS_SetSwitchDDC2(SiS_Pr);
  7816. if(SiS_PrepareDDC(SiS_Pr)) {
  7817. SiS_SetStop(SiS_Pr);
  7818. return 0xFFFF;
  7819. }
  7820. mask = 0xf0;
  7821. value = 0x20;
  7822. if(SiS_Pr->SiS_DDC_DeviceAddr == 0xa0) {
  7823. temp = (unsigned char)SiS_ReadDDC2Data(SiS_Pr);
  7824. SiS_SendACK(SiS_Pr, 0);
  7825. if(temp == 0) {
  7826. mask = 0xff;
  7827. value = 0xff;
  7828. } else {
  7829. failed = true;
  7830. ret = 0xFFFF;
  7831. }
  7832. }
  7833. if(!failed) {
  7834. temp = (unsigned char)SiS_ReadDDC2Data(SiS_Pr);
  7835. SiS_SendACK(SiS_Pr, 1);
  7836. temp &= mask;
  7837. if(temp == value) ret = 0;
  7838. else {
  7839. ret = 0xFFFF;
  7840. if(SiS_Pr->SiS_DDC_DeviceAddr == 0xa0) {
  7841. if(temp == 0x30) ret = 0;
  7842. }
  7843. }
  7844. }
  7845. SiS_SetStop(SiS_Pr);
  7846. return ret;
  7847. }
  7848. static
  7849. unsigned short
  7850. SiS_ProbeDDC(struct SiS_Private *SiS_Pr)
  7851. {
  7852. unsigned short flag;
  7853. flag = 0x180;
  7854. SiS_Pr->SiS_DDC_DeviceAddr = 0xa0;
  7855. if(!(SiS_DoProbeDDC(SiS_Pr))) flag |= 0x02;
  7856. SiS_Pr->SiS_DDC_DeviceAddr = 0xa2;
  7857. if(!(SiS_DoProbeDDC(SiS_Pr))) flag |= 0x08;
  7858. SiS_Pr->SiS_DDC_DeviceAddr = 0xa6;
  7859. if(!(SiS_DoProbeDDC(SiS_Pr))) flag |= 0x10;
  7860. if(!(flag & 0x1a)) flag = 0;
  7861. return flag;
  7862. }
  7863. static
  7864. unsigned short
  7865. SiS_ReadDDC(struct SiS_Private *SiS_Pr, unsigned short DDCdatatype, unsigned char *buffer)
  7866. {
  7867. unsigned short flag, length, i;
  7868. unsigned char chksum,gotcha;
  7869. if(DDCdatatype > 4) return 0xFFFF;
  7870. flag = 0;
  7871. SiS_SetSwitchDDC2(SiS_Pr);
  7872. if(!(SiS_PrepareDDC(SiS_Pr))) {
  7873. length = 127;
  7874. if(DDCdatatype != 1) length = 255;
  7875. chksum = 0;
  7876. gotcha = 0;
  7877. for(i=0; i<length; i++) {
  7878. buffer[i] = (unsigned char)SiS_ReadDDC2Data(SiS_Pr);
  7879. chksum += buffer[i];
  7880. gotcha |= buffer[i];
  7881. SiS_SendACK(SiS_Pr, 0);
  7882. }
  7883. buffer[i] = (unsigned char)SiS_ReadDDC2Data(SiS_Pr);
  7884. chksum += buffer[i];
  7885. SiS_SendACK(SiS_Pr, 1);
  7886. if(gotcha) flag = (unsigned short)chksum;
  7887. else flag = 0xFFFF;
  7888. } else {
  7889. flag = 0xFFFF;
  7890. }
  7891. SiS_SetStop(SiS_Pr);
  7892. return flag;
  7893. }
  7894. /* Our private DDC functions
  7895. It complies somewhat with the corresponding VESA function
  7896. in arguments and return values.
  7897. Since this is probably called before the mode is changed,
  7898. we use our pre-detected pSiS-values instead of SiS_Pr as
  7899. regards chipset and video bridge type.
  7900. Arguments:
  7901. adaptnum: 0=CRT1(analog), 1=CRT2/LCD(digital), 2=CRT2/VGA2(analog)
  7902. CRT2 DDC is only supported on SiS301, 301B, 301C, 302B.
  7903. LCDA is CRT1, but DDC is read from CRT2 port.
  7904. DDCdatatype: 0=Probe, 1=EDID, 2=EDID+VDIF, 3=EDID V2 (P&D), 4=EDID V2 (FPDI-2)
  7905. buffer: ptr to 256 data bytes which will be filled with read data.
  7906. Returns 0xFFFF if error, otherwise
  7907. if DDCdatatype > 0: Returns 0 if reading OK (included a correct checksum)
  7908. if DDCdatatype = 0: Returns supported DDC modes
  7909. */
  7910. unsigned short
  7911. SiS_HandleDDC(struct SiS_Private *SiS_Pr, unsigned int VBFlags, int VGAEngine,
  7912. unsigned short adaptnum, unsigned short DDCdatatype, unsigned char *buffer,
  7913. unsigned int VBFlags2)
  7914. {
  7915. unsigned char sr1f, cr17=1;
  7916. unsigned short result;
  7917. if(adaptnum > 2)
  7918. return 0xFFFF;
  7919. if(DDCdatatype > 4)
  7920. return 0xFFFF;
  7921. if((!(VBFlags2 & VB2_VIDEOBRIDGE)) && (adaptnum > 0))
  7922. return 0xFFFF;
  7923. if(SiS_InitDDCRegs(SiS_Pr, VBFlags, VGAEngine, adaptnum, DDCdatatype, false, VBFlags2) == 0xFFFF)
  7924. return 0xFFFF;
  7925. sr1f = SiS_GetReg(SiS_Pr->SiS_P3c4,0x1f);
  7926. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x1f,0x3f,0x04);
  7927. if(VGAEngine == SIS_300_VGA) {
  7928. cr17 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x17) & 0x80;
  7929. if(!cr17) {
  7930. SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x17,0x80);
  7931. SiS_SetReg(SiS_Pr->SiS_P3c4,0x00,0x01);
  7932. SiS_SetReg(SiS_Pr->SiS_P3c4,0x00,0x03);
  7933. }
  7934. }
  7935. if((sr1f) || (!cr17)) {
  7936. SiS_WaitRetrace1(SiS_Pr);
  7937. SiS_WaitRetrace1(SiS_Pr);
  7938. SiS_WaitRetrace1(SiS_Pr);
  7939. SiS_WaitRetrace1(SiS_Pr);
  7940. }
  7941. if(DDCdatatype == 0) {
  7942. result = SiS_ProbeDDC(SiS_Pr);
  7943. } else {
  7944. result = SiS_ReadDDC(SiS_Pr, DDCdatatype, buffer);
  7945. if((!result) && (DDCdatatype == 1)) {
  7946. if((buffer[0] == 0x00) && (buffer[1] == 0xff) &&
  7947. (buffer[2] == 0xff) && (buffer[3] == 0xff) &&
  7948. (buffer[4] == 0xff) && (buffer[5] == 0xff) &&
  7949. (buffer[6] == 0xff) && (buffer[7] == 0x00) &&
  7950. (buffer[0x12] == 1)) {
  7951. if(!SiS_Pr->DDCPortMixup) {
  7952. if(adaptnum == 1) {
  7953. if(!(buffer[0x14] & 0x80)) result = 0xFFFE;
  7954. } else {
  7955. if(buffer[0x14] & 0x80) result = 0xFFFE;
  7956. }
  7957. }
  7958. }
  7959. }
  7960. }
  7961. SiS_SetReg(SiS_Pr->SiS_P3c4,0x1f,sr1f);
  7962. if(VGAEngine == SIS_300_VGA) {
  7963. SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x17,0x7f,cr17);
  7964. }
  7965. return result;
  7966. }
  7967. /* Generic I2C functions for Chrontel & DDC --------- */
  7968. static void
  7969. SiS_SetSwitchDDC2(struct SiS_Private *SiS_Pr)
  7970. {
  7971. SiS_SetSCLKHigh(SiS_Pr);
  7972. SiS_WaitRetrace1(SiS_Pr);
  7973. SiS_SetSCLKLow(SiS_Pr);
  7974. SiS_WaitRetrace1(SiS_Pr);
  7975. }
  7976. unsigned short
  7977. SiS_ReadDDC1Bit(struct SiS_Private *SiS_Pr)
  7978. {
  7979. SiS_WaitRetrace1(SiS_Pr);
  7980. return ((SiS_GetReg(SiS_Pr->SiS_P3c4,0x11) & 0x02) >> 1);
  7981. }
  7982. /* Set I2C start condition */
  7983. /* This is done by a SD high-to-low transition while SC is high */
  7984. static unsigned short
  7985. SiS_SetStart(struct SiS_Private *SiS_Pr)
  7986. {
  7987. if(SiS_SetSCLKLow(SiS_Pr)) return 0xFFFF; /* (SC->low) */
  7988. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  7989. SiS_Pr->SiS_DDC_Index,
  7990. SiS_Pr->SiS_DDC_NData,
  7991. SiS_Pr->SiS_DDC_Data); /* SD->high */
  7992. if(SiS_SetSCLKHigh(SiS_Pr)) return 0xFFFF; /* SC->high */
  7993. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  7994. SiS_Pr->SiS_DDC_Index,
  7995. SiS_Pr->SiS_DDC_NData,
  7996. 0x00); /* SD->low = start condition */
  7997. if(SiS_SetSCLKHigh(SiS_Pr)) return 0xFFFF; /* (SC->low) */
  7998. return 0;
  7999. }
  8000. /* Set I2C stop condition */
  8001. /* This is done by a SD low-to-high transition while SC is high */
  8002. static unsigned short
  8003. SiS_SetStop(struct SiS_Private *SiS_Pr)
  8004. {
  8005. if(SiS_SetSCLKLow(SiS_Pr)) return 0xFFFF; /* (SC->low) */
  8006. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8007. SiS_Pr->SiS_DDC_Index,
  8008. SiS_Pr->SiS_DDC_NData,
  8009. 0x00); /* SD->low */
  8010. if(SiS_SetSCLKHigh(SiS_Pr)) return 0xFFFF; /* SC->high */
  8011. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8012. SiS_Pr->SiS_DDC_Index,
  8013. SiS_Pr->SiS_DDC_NData,
  8014. SiS_Pr->SiS_DDC_Data); /* SD->high = stop condition */
  8015. if(SiS_SetSCLKHigh(SiS_Pr)) return 0xFFFF; /* (SC->high) */
  8016. return 0;
  8017. }
  8018. /* Write 8 bits of data */
  8019. static unsigned short
  8020. SiS_WriteDDC2Data(struct SiS_Private *SiS_Pr, unsigned short tempax)
  8021. {
  8022. unsigned short i,flag,temp;
  8023. flag = 0x80;
  8024. for(i = 0; i < 8; i++) {
  8025. SiS_SetSCLKLow(SiS_Pr); /* SC->low */
  8026. if(tempax & flag) {
  8027. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8028. SiS_Pr->SiS_DDC_Index,
  8029. SiS_Pr->SiS_DDC_NData,
  8030. SiS_Pr->SiS_DDC_Data); /* Write bit (1) to SD */
  8031. } else {
  8032. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8033. SiS_Pr->SiS_DDC_Index,
  8034. SiS_Pr->SiS_DDC_NData,
  8035. 0x00); /* Write bit (0) to SD */
  8036. }
  8037. SiS_SetSCLKHigh(SiS_Pr); /* SC->high */
  8038. flag >>= 1;
  8039. }
  8040. temp = SiS_CheckACK(SiS_Pr); /* Check acknowledge */
  8041. return temp;
  8042. }
  8043. static unsigned short
  8044. SiS_ReadDDC2Data(struct SiS_Private *SiS_Pr)
  8045. {
  8046. unsigned short i, temp, getdata;
  8047. getdata = 0;
  8048. for(i = 0; i < 8; i++) {
  8049. getdata <<= 1;
  8050. SiS_SetSCLKLow(SiS_Pr);
  8051. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8052. SiS_Pr->SiS_DDC_Index,
  8053. SiS_Pr->SiS_DDC_NData,
  8054. SiS_Pr->SiS_DDC_Data);
  8055. SiS_SetSCLKHigh(SiS_Pr);
  8056. temp = SiS_GetReg(SiS_Pr->SiS_DDC_Port,SiS_Pr->SiS_DDC_Index);
  8057. if(temp & SiS_Pr->SiS_DDC_Data) getdata |= 0x01;
  8058. }
  8059. return getdata;
  8060. }
  8061. static unsigned short
  8062. SiS_SetSCLKLow(struct SiS_Private *SiS_Pr)
  8063. {
  8064. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8065. SiS_Pr->SiS_DDC_Index,
  8066. SiS_Pr->SiS_DDC_NClk,
  8067. 0x00); /* SetSCLKLow() */
  8068. SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT);
  8069. return 0;
  8070. }
  8071. static unsigned short
  8072. SiS_SetSCLKHigh(struct SiS_Private *SiS_Pr)
  8073. {
  8074. unsigned short temp, watchdog=1000;
  8075. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8076. SiS_Pr->SiS_DDC_Index,
  8077. SiS_Pr->SiS_DDC_NClk,
  8078. SiS_Pr->SiS_DDC_Clk); /* SetSCLKHigh() */
  8079. do {
  8080. temp = SiS_GetReg(SiS_Pr->SiS_DDC_Port,SiS_Pr->SiS_DDC_Index);
  8081. } while((!(temp & SiS_Pr->SiS_DDC_Clk)) && --watchdog);
  8082. if (!watchdog) {
  8083. return 0xFFFF;
  8084. }
  8085. SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT);
  8086. return 0;
  8087. }
  8088. /* Check I2C acknowledge */
  8089. /* Returns 0 if ack ok, non-0 if ack not ok */
  8090. static unsigned short
  8091. SiS_CheckACK(struct SiS_Private *SiS_Pr)
  8092. {
  8093. unsigned short tempah;
  8094. SiS_SetSCLKLow(SiS_Pr); /* (SC->low) */
  8095. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8096. SiS_Pr->SiS_DDC_Index,
  8097. SiS_Pr->SiS_DDC_NData,
  8098. SiS_Pr->SiS_DDC_Data); /* (SD->high) */
  8099. SiS_SetSCLKHigh(SiS_Pr); /* SC->high = clock impulse for ack */
  8100. tempah = SiS_GetReg(SiS_Pr->SiS_DDC_Port,SiS_Pr->SiS_DDC_Index); /* Read SD */
  8101. SiS_SetSCLKLow(SiS_Pr); /* SC->low = end of clock impulse */
  8102. if(tempah & SiS_Pr->SiS_DDC_Data) return 1; /* Ack OK if bit = 0 */
  8103. return 0;
  8104. }
  8105. /* End of I2C functions ----------------------- */
  8106. /* =============== SiS 315/330 O.E.M. ================= */
  8107. #ifdef CONFIG_FB_SIS_315
  8108. static unsigned short
  8109. GetRAMDACromptr(struct SiS_Private *SiS_Pr)
  8110. {
  8111. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  8112. unsigned short romptr;
  8113. if(SiS_Pr->ChipType < SIS_330) {
  8114. romptr = SISGETROMW(0x128);
  8115. if(SiS_Pr->SiS_VBType & VB_SIS30xB)
  8116. romptr = SISGETROMW(0x12a);
  8117. } else {
  8118. romptr = SISGETROMW(0x1a8);
  8119. if(SiS_Pr->SiS_VBType & VB_SIS30xB)
  8120. romptr = SISGETROMW(0x1aa);
  8121. }
  8122. return romptr;
  8123. }
  8124. static unsigned short
  8125. GetLCDromptr(struct SiS_Private *SiS_Pr)
  8126. {
  8127. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  8128. unsigned short romptr;
  8129. if(SiS_Pr->ChipType < SIS_330) {
  8130. romptr = SISGETROMW(0x120);
  8131. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV)
  8132. romptr = SISGETROMW(0x122);
  8133. } else {
  8134. romptr = SISGETROMW(0x1a0);
  8135. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV)
  8136. romptr = SISGETROMW(0x1a2);
  8137. }
  8138. return romptr;
  8139. }
  8140. static unsigned short
  8141. GetTVromptr(struct SiS_Private *SiS_Pr)
  8142. {
  8143. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  8144. unsigned short romptr;
  8145. if(SiS_Pr->ChipType < SIS_330) {
  8146. romptr = SISGETROMW(0x114);
  8147. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV)
  8148. romptr = SISGETROMW(0x11a);
  8149. } else {
  8150. romptr = SISGETROMW(0x194);
  8151. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV)
  8152. romptr = SISGETROMW(0x19a);
  8153. }
  8154. return romptr;
  8155. }
  8156. static unsigned short
  8157. GetLCDPtrIndexBIOS(struct SiS_Private *SiS_Pr)
  8158. {
  8159. unsigned short index;
  8160. if((IS_SIS650) && (SiS_Pr->SiS_VBType & VB_SISLVDS)) {
  8161. if(!(SiS_IsNotM650orLater(SiS_Pr))) {
  8162. if((index = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) & 0xf0)) {
  8163. index >>= 4;
  8164. index *= 3;
  8165. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) index += 2;
  8166. else if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) index++;
  8167. return index;
  8168. }
  8169. }
  8170. }
  8171. index = SiS_GetBIOSLCDResInfo(SiS_Pr) & 0x0F;
  8172. if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) index -= 5;
  8173. if(SiS_Pr->SiS_VBType & VB_SIS301C) { /* 1.15.20 and later (not VB specific) */
  8174. if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) index -= 5;
  8175. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x768) index -= 5;
  8176. } else {
  8177. if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) index -= 6;
  8178. }
  8179. index--;
  8180. index *= 3;
  8181. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) index += 2;
  8182. else if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) index++;
  8183. return index;
  8184. }
  8185. static unsigned short
  8186. GetLCDPtrIndex(struct SiS_Private *SiS_Pr)
  8187. {
  8188. unsigned short index;
  8189. index = ((SiS_GetBIOSLCDResInfo(SiS_Pr) & 0x0F) - 1) * 3;
  8190. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) index += 2;
  8191. else if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) index++;
  8192. return index;
  8193. }
  8194. static unsigned short
  8195. GetTVPtrIndex(struct SiS_Private *SiS_Pr)
  8196. {
  8197. unsigned short index;
  8198. index = 0;
  8199. if(SiS_Pr->SiS_TVMode & TVSetPAL) index = 1;
  8200. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) index = 2;
  8201. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) index = 0;
  8202. index <<= 1;
  8203. if((SiS_Pr->SiS_VBInfo & SetInSlaveMode) &&
  8204. (SiS_Pr->SiS_TVMode & TVSetTVSimuMode)) {
  8205. index++;
  8206. }
  8207. return index;
  8208. }
  8209. static unsigned int
  8210. GetOEMTVPtr661_2_GEN(struct SiS_Private *SiS_Pr, int addme)
  8211. {
  8212. unsigned short index = 0, temp = 0;
  8213. if(SiS_Pr->SiS_TVMode & TVSetPAL) index = 1;
  8214. if(SiS_Pr->SiS_TVMode & TVSetPALM) index = 2;
  8215. if(SiS_Pr->SiS_TVMode & TVSetPALN) index = 3;
  8216. if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) index = 6;
  8217. if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) {
  8218. index = 4;
  8219. if(SiS_Pr->SiS_TVMode & TVSetPALM) index++;
  8220. if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) index = 7;
  8221. }
  8222. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  8223. if((!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) ||
  8224. (SiS_Pr->SiS_TVMode & TVSetTVSimuMode)) {
  8225. index += addme;
  8226. temp++;
  8227. }
  8228. temp += 0x0100;
  8229. }
  8230. return (unsigned int)(index | (temp << 16));
  8231. }
  8232. static unsigned int
  8233. GetOEMTVPtr661_2_OLD(struct SiS_Private *SiS_Pr)
  8234. {
  8235. return (GetOEMTVPtr661_2_GEN(SiS_Pr, 8));
  8236. }
  8237. #if 0
  8238. static unsigned int
  8239. GetOEMTVPtr661_2_NEW(struct SiS_Private *SiS_Pr)
  8240. {
  8241. return (GetOEMTVPtr661_2_GEN(SiS_Pr, 6));
  8242. }
  8243. #endif
  8244. static int
  8245. GetOEMTVPtr661(struct SiS_Private *SiS_Pr)
  8246. {
  8247. int index = 0;
  8248. if(SiS_Pr->SiS_TVMode & TVSetPAL) index = 2;
  8249. if(SiS_Pr->SiS_ROMNew) {
  8250. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525i) index = 4;
  8251. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) index = 6;
  8252. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) index = 8;
  8253. if(SiS_Pr->SiS_TVMode & TVSetHiVision) index = 10;
  8254. } else {
  8255. if(SiS_Pr->SiS_TVMode & TVSetHiVision) index = 4;
  8256. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525i) index = 6;
  8257. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) index = 8;
  8258. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) index = 10;
  8259. }
  8260. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) index++;
  8261. return index;
  8262. }
  8263. static void
  8264. SetDelayComp(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
  8265. {
  8266. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  8267. unsigned short delay=0,index,myindex,temp,romptr=0;
  8268. bool dochiptest = true;
  8269. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  8270. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x20,0xbf);
  8271. } else {
  8272. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x35,0x7f);
  8273. }
  8274. /* Find delay (from ROM, internal tables, PCI subsystem) */
  8275. if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) { /* ------------ VGA */
  8276. if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
  8277. romptr = GetRAMDACromptr(SiS_Pr);
  8278. }
  8279. if(romptr) delay = ROMAddr[romptr];
  8280. else {
  8281. delay = 0x04;
  8282. if(SiS_Pr->SiS_VBType & VB_SIS30xB) {
  8283. if(IS_SIS650) {
  8284. delay = 0x0a;
  8285. } else if(IS_SIS740) {
  8286. delay = 0x00;
  8287. } else if(SiS_Pr->ChipType < SIS_330) {
  8288. delay = 0x0c;
  8289. } else {
  8290. delay = 0x0c;
  8291. }
  8292. } else if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  8293. delay = 0x00;
  8294. }
  8295. }
  8296. } else if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD|SetCRT2ToLCDA)) { /* ---------- LCD/LCDA */
  8297. bool gotitfrompci = false;
  8298. /* Could we detect a PDC for LCD or did we get a user-defined? If yes, use it */
  8299. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  8300. if(SiS_Pr->PDC != -1) {
  8301. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0xf0,((SiS_Pr->PDC >> 1) & 0x0f));
  8302. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x35,0x7f,((SiS_Pr->PDC & 0x01) << 7));
  8303. return;
  8304. }
  8305. } else {
  8306. if(SiS_Pr->PDCA != -1) {
  8307. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0x0f,((SiS_Pr->PDCA << 3) & 0xf0));
  8308. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x20,0xbf,((SiS_Pr->PDCA & 0x01) << 6));
  8309. return;
  8310. }
  8311. }
  8312. /* Custom Panel? */
  8313. if(SiS_Pr->SiS_LCDResInfo == Panel_Custom) {
  8314. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  8315. delay = 0x00;
  8316. if((SiS_Pr->PanelXRes <= 1280) && (SiS_Pr->PanelYRes <= 1024)) {
  8317. delay = 0x20;
  8318. }
  8319. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0x0f,delay);
  8320. } else {
  8321. delay = 0x0c;
  8322. if(SiS_Pr->SiS_VBType & VB_SIS301C) {
  8323. delay = 0x03;
  8324. if((SiS_Pr->PanelXRes > 1280) && (SiS_Pr->PanelYRes > 1024)) {
  8325. delay = 0x00;
  8326. }
  8327. } else if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  8328. if(IS_SIS740) delay = 0x01;
  8329. else delay = 0x03;
  8330. }
  8331. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0xf0,delay);
  8332. }
  8333. return;
  8334. }
  8335. /* This is a piece of typical SiS crap: They code the OEM LCD
  8336. * delay into the code, at no defined place in the BIOS.
  8337. * We now have to start doing a PCI subsystem check here.
  8338. */
  8339. switch(SiS_Pr->SiS_CustomT) {
  8340. case CUT_COMPAQ1280:
  8341. case CUT_COMPAQ12802:
  8342. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) {
  8343. gotitfrompci = true;
  8344. dochiptest = false;
  8345. delay = 0x03;
  8346. }
  8347. break;
  8348. case CUT_CLEVO1400:
  8349. case CUT_CLEVO14002:
  8350. gotitfrompci = true;
  8351. dochiptest = false;
  8352. delay = 0x02;
  8353. break;
  8354. case CUT_CLEVO1024:
  8355. case CUT_CLEVO10242:
  8356. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  8357. gotitfrompci = true;
  8358. dochiptest = false;
  8359. delay = 0x33;
  8360. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2D,delay);
  8361. delay &= 0x0f;
  8362. }
  8363. break;
  8364. }
  8365. /* Could we find it through the PCI ID? If no, use ROM or table */
  8366. if(!gotitfrompci) {
  8367. index = GetLCDPtrIndexBIOS(SiS_Pr);
  8368. myindex = GetLCDPtrIndex(SiS_Pr);
  8369. if(IS_SIS650 && (SiS_Pr->SiS_VBType & VB_SISLVDS)) {
  8370. if(SiS_IsNotM650orLater(SiS_Pr)) {
  8371. if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
  8372. /* Always use the second pointer on 650; some BIOSes */
  8373. /* still carry old 301 data at the first location */
  8374. /* romptr = SISGETROMW(0x120); */
  8375. /* if(SiS_Pr->SiS_VBType & VB_SIS302LV) */
  8376. romptr = SISGETROMW(0x122);
  8377. if(!romptr) return;
  8378. delay = ROMAddr[(romptr + index)];
  8379. } else {
  8380. delay = SiS310_LCDDelayCompensation_650301LV[myindex];
  8381. }
  8382. } else {
  8383. delay = SiS310_LCDDelayCompensation_651301LV[myindex];
  8384. if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV))
  8385. delay = SiS310_LCDDelayCompensation_651302LV[myindex];
  8386. }
  8387. } else if(SiS_Pr->SiS_UseROM &&
  8388. (!(SiS_Pr->SiS_ROMNew)) &&
  8389. (SiS_Pr->SiS_LCDResInfo != Panel_1280x1024) &&
  8390. (SiS_Pr->SiS_LCDResInfo != Panel_1280x768) &&
  8391. (SiS_Pr->SiS_LCDResInfo != Panel_1280x960) &&
  8392. (SiS_Pr->SiS_LCDResInfo != Panel_1600x1200) &&
  8393. ((romptr = GetLCDromptr(SiS_Pr)))) {
  8394. /* Data for 1280x1024 wrong in 301B BIOS */
  8395. /* Data for 1600x1200 wrong in 301C BIOS */
  8396. delay = ROMAddr[(romptr + index)];
  8397. } else if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  8398. if(IS_SIS740) delay = 0x03;
  8399. else delay = 0x00;
  8400. } else {
  8401. delay = SiS310_LCDDelayCompensation_301[myindex];
  8402. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  8403. if(IS_SIS740) delay = 0x01;
  8404. else if(SiS_Pr->ChipType <= SIS_315PRO) delay = SiS310_LCDDelayCompensation_3xx301LV[myindex];
  8405. else delay = SiS310_LCDDelayCompensation_650301LV[myindex];
  8406. } else if(SiS_Pr->SiS_VBType & VB_SIS301C) {
  8407. if(IS_SIS740) delay = 0x01; /* ? */
  8408. else delay = 0x03;
  8409. if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) delay = 0x00; /* experience */
  8410. } else if(SiS_Pr->SiS_VBType & VB_SIS30xB) {
  8411. if(IS_SIS740) delay = 0x01;
  8412. else delay = SiS310_LCDDelayCompensation_3xx301B[myindex];
  8413. }
  8414. }
  8415. } /* got it from PCI */
  8416. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  8417. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,0x0F,((delay << 4) & 0xf0));
  8418. dochiptest = false;
  8419. }
  8420. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { /* ------------ TV */
  8421. index = GetTVPtrIndex(SiS_Pr);
  8422. if(IS_SIS650 && (SiS_Pr->SiS_VBType & VB_SISLVDS)) {
  8423. if(SiS_IsNotM650orLater(SiS_Pr)) {
  8424. if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
  8425. /* Always use the second pointer on 650; some BIOSes */
  8426. /* still carry old 301 data at the first location */
  8427. /* romptr = SISGETROMW(0x114); */
  8428. /* if(SiS_Pr->SiS_VBType & VB_SIS302LV) */
  8429. romptr = SISGETROMW(0x11a);
  8430. if(!romptr) return;
  8431. delay = ROMAddr[romptr + index];
  8432. } else {
  8433. delay = SiS310_TVDelayCompensation_301B[index];
  8434. }
  8435. } else {
  8436. switch(SiS_Pr->SiS_CustomT) {
  8437. case CUT_COMPAQ1280:
  8438. case CUT_COMPAQ12802:
  8439. case CUT_CLEVO1400:
  8440. case CUT_CLEVO14002:
  8441. delay = 0x02;
  8442. dochiptest = false;
  8443. break;
  8444. case CUT_CLEVO1024:
  8445. case CUT_CLEVO10242:
  8446. delay = 0x03;
  8447. dochiptest = false;
  8448. break;
  8449. default:
  8450. delay = SiS310_TVDelayCompensation_651301LV[index];
  8451. if(SiS_Pr->SiS_VBType & VB_SIS302LV) {
  8452. delay = SiS310_TVDelayCompensation_651302LV[index];
  8453. }
  8454. }
  8455. }
  8456. } else if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
  8457. romptr = GetTVromptr(SiS_Pr);
  8458. if(!romptr) return;
  8459. delay = ROMAddr[romptr + index];
  8460. } else if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  8461. delay = SiS310_TVDelayCompensation_LVDS[index];
  8462. } else {
  8463. delay = SiS310_TVDelayCompensation_301[index];
  8464. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  8465. if(IS_SIS740) {
  8466. delay = SiS310_TVDelayCompensation_740301B[index];
  8467. /* LV: use 301 data? BIOS bug? */
  8468. } else {
  8469. delay = SiS310_TVDelayCompensation_301B[index];
  8470. if(SiS_Pr->SiS_VBType & VB_SIS301C) delay = 0x02;
  8471. }
  8472. }
  8473. }
  8474. if(SiS_LCDAEnabled(SiS_Pr)) {
  8475. delay &= 0x0f;
  8476. dochiptest = false;
  8477. }
  8478. } else return;
  8479. /* Write delay */
  8480. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  8481. if(IS_SIS650 && (SiS_Pr->SiS_VBType & VB_SISLVDS) && dochiptest) {
  8482. temp = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) & 0xf0) >> 4;
  8483. if(temp == 8) { /* 1400x1050 BIOS (COMPAL) */
  8484. delay &= 0x0f;
  8485. delay |= 0xb0;
  8486. } else if(temp == 6) {
  8487. delay &= 0x0f;
  8488. delay |= 0xc0;
  8489. } else if(temp > 7) { /* 1280x1024 BIOS (which one?) */
  8490. delay = 0x35;
  8491. }
  8492. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2D,delay);
  8493. } else {
  8494. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,0xF0,delay);
  8495. }
  8496. } else { /* LVDS */
  8497. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  8498. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,0xF0,delay);
  8499. } else {
  8500. if(IS_SIS650 && (SiS_Pr->SiS_IF_DEF_CH70xx != 0)) {
  8501. delay <<= 4;
  8502. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,0x0F,delay);
  8503. } else {
  8504. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,0xF0,delay);
  8505. }
  8506. }
  8507. }
  8508. }
  8509. static void
  8510. SetAntiFlicker(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  8511. {
  8512. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  8513. unsigned short index,temp,temp1,romptr=0;
  8514. if(SiS_Pr->SiS_TVMode & (TVSetYPbPr750p|TVSetYPbPr525p)) return;
  8515. if(ModeNo<=0x13)
  8516. index = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].VB_StTVFlickerIndex;
  8517. else
  8518. index = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].VB_ExtTVFlickerIndex;
  8519. temp = GetTVPtrIndex(SiS_Pr);
  8520. temp >>= 1; /* 0: NTSC/YPbPr, 1: PAL, 2: HiTV */
  8521. temp1 = temp;
  8522. if(SiS_Pr->SiS_UseROM && (!(SiS_Pr->SiS_ROMNew))) {
  8523. if(SiS_Pr->ChipType >= SIS_661) {
  8524. temp1 = GetOEMTVPtr661(SiS_Pr);
  8525. temp1 >>= 1;
  8526. romptr = SISGETROMW(0x260);
  8527. if(SiS_Pr->ChipType >= SIS_760) {
  8528. romptr = SISGETROMW(0x360);
  8529. }
  8530. } else if(SiS_Pr->ChipType >= SIS_330) {
  8531. romptr = SISGETROMW(0x192);
  8532. } else {
  8533. romptr = SISGETROMW(0x112);
  8534. }
  8535. }
  8536. if(romptr) {
  8537. temp1 <<= 1;
  8538. temp = ROMAddr[romptr + temp1 + index];
  8539. } else {
  8540. temp = SiS310_TVAntiFlick1[temp][index];
  8541. }
  8542. temp <<= 4;
  8543. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x0A,0x8f,temp); /* index 0A D[6:4] */
  8544. }
  8545. static void
  8546. SetEdgeEnhance(struct SiS_Private *SiS_Pr, unsigned short ModeNo,unsigned short ModeIdIndex)
  8547. {
  8548. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  8549. unsigned short index,temp,temp1,romptr=0;
  8550. temp = temp1 = GetTVPtrIndex(SiS_Pr) >> 1; /* 0: NTSC/YPbPr, 1: PAL, 2: HiTV */
  8551. if(ModeNo <= 0x13)
  8552. index = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].VB_StTVEdgeIndex;
  8553. else
  8554. index = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].VB_ExtTVEdgeIndex;
  8555. if(SiS_Pr->SiS_UseROM && (!(SiS_Pr->SiS_ROMNew))) {
  8556. if(SiS_Pr->ChipType >= SIS_661) {
  8557. romptr = SISGETROMW(0x26c);
  8558. if(SiS_Pr->ChipType >= SIS_760) {
  8559. romptr = SISGETROMW(0x36c);
  8560. }
  8561. temp1 = GetOEMTVPtr661(SiS_Pr);
  8562. temp1 >>= 1;
  8563. } else if(SiS_Pr->ChipType >= SIS_330) {
  8564. romptr = SISGETROMW(0x1a4);
  8565. } else {
  8566. romptr = SISGETROMW(0x124);
  8567. }
  8568. }
  8569. if(romptr) {
  8570. temp1 <<= 1;
  8571. temp = ROMAddr[romptr + temp1 + index];
  8572. } else {
  8573. temp = SiS310_TVEdge1[temp][index];
  8574. }
  8575. temp <<= 5;
  8576. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x3A,0x1F,temp); /* index 0A D[7:5] */
  8577. }
  8578. static void
  8579. SetYFilter(struct SiS_Private *SiS_Pr, unsigned short ModeNo,unsigned short ModeIdIndex)
  8580. {
  8581. unsigned short index, temp, i, j;
  8582. if(ModeNo <= 0x13) {
  8583. index = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].VB_StTVYFilterIndex;
  8584. } else {
  8585. index = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].VB_ExtTVYFilterIndex;
  8586. }
  8587. temp = GetTVPtrIndex(SiS_Pr) >> 1; /* 0: NTSC/YPbPr, 1: PAL, 2: HiTV */
  8588. if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) temp = 1; /* NTSC-J uses PAL */
  8589. else if(SiS_Pr->SiS_TVMode & TVSetPALM) temp = 3; /* PAL-M */
  8590. else if(SiS_Pr->SiS_TVMode & TVSetPALN) temp = 4; /* PAL-N */
  8591. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) temp = 1; /* HiVision uses PAL */
  8592. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  8593. for(i=0x35, j=0; i<=0x38; i++, j++) {
  8594. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVYFilter2[temp][index][j]);
  8595. }
  8596. for(i=0x48; i<=0x4A; i++, j++) {
  8597. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVYFilter2[temp][index][j]);
  8598. }
  8599. } else {
  8600. for(i=0x35, j=0; i<=0x38; i++, j++) {
  8601. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVYFilter1[temp][index][j]);
  8602. }
  8603. }
  8604. }
  8605. static void
  8606. SetPhaseIncr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  8607. {
  8608. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  8609. unsigned short index,temp,i,j,resinfo,romptr=0;
  8610. unsigned int lindex;
  8611. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) return;
  8612. /* NTSC-J data not in BIOS, and already set in SetGroup2 */
  8613. if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) return;
  8614. if((SiS_Pr->ChipType >= SIS_661) || SiS_Pr->SiS_ROMNew) {
  8615. lindex = GetOEMTVPtr661_2_OLD(SiS_Pr) & 0xffff;
  8616. lindex <<= 2;
  8617. for(j=0, i=0x31; i<=0x34; i++, j++) {
  8618. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS_TVPhase[lindex + j]);
  8619. }
  8620. return;
  8621. }
  8622. /* PAL-M, PAL-N not in BIOS, and already set in SetGroup2 */
  8623. if(SiS_Pr->SiS_TVMode & (TVSetPALM | TVSetPALN)) return;
  8624. if(ModeNo<=0x13) {
  8625. resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
  8626. } else {
  8627. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  8628. }
  8629. temp = GetTVPtrIndex(SiS_Pr);
  8630. /* 0: NTSC Graphics, 1: NTSC Text, 2: PAL Graphics,
  8631. * 3: PAL Text, 4: HiTV Graphics 5: HiTV Text
  8632. */
  8633. if(SiS_Pr->SiS_UseROM) {
  8634. romptr = SISGETROMW(0x116);
  8635. if(SiS_Pr->ChipType >= SIS_330) {
  8636. romptr = SISGETROMW(0x196);
  8637. }
  8638. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  8639. romptr = SISGETROMW(0x11c);
  8640. if(SiS_Pr->ChipType >= SIS_330) {
  8641. romptr = SISGETROMW(0x19c);
  8642. }
  8643. if((SiS_Pr->SiS_VBInfo & SetInSlaveMode) && (!(SiS_Pr->SiS_TVMode & TVSetTVSimuMode))) {
  8644. romptr = SISGETROMW(0x116);
  8645. if(SiS_Pr->ChipType >= SIS_330) {
  8646. romptr = SISGETROMW(0x196);
  8647. }
  8648. }
  8649. }
  8650. }
  8651. if(romptr) {
  8652. romptr += (temp << 2);
  8653. for(j=0, i=0x31; i<=0x34; i++, j++) {
  8654. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,ROMAddr[romptr + j]);
  8655. }
  8656. } else {
  8657. index = temp % 2;
  8658. temp >>= 1; /* 0:NTSC, 1:PAL, 2:HiTV */
  8659. for(j=0, i=0x31; i<=0x34; i++, j++) {
  8660. if(!(SiS_Pr->SiS_VBType & VB_SIS30xBLV))
  8661. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVPhaseIncr1[temp][index][j]);
  8662. else if((!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) || (SiS_Pr->SiS_TVMode & TVSetTVSimuMode))
  8663. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVPhaseIncr2[temp][index][j]);
  8664. else
  8665. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVPhaseIncr1[temp][index][j]);
  8666. }
  8667. }
  8668. if((SiS_Pr->SiS_VBType & VB_SIS30xBLV) && (!(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision))) {
  8669. if((!(SiS_Pr->SiS_TVMode & (TVSetPAL | TVSetYPbPr525p | TVSetYPbPr750p))) && (ModeNo > 0x13)) {
  8670. if((resinfo == SIS_RI_640x480) ||
  8671. (resinfo == SIS_RI_800x600)) {
  8672. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x31,0x21);
  8673. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x32,0xf0);
  8674. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x33,0xf5);
  8675. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x34,0x7f);
  8676. } else if(resinfo == SIS_RI_1024x768) {
  8677. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x31,0x1e);
  8678. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x32,0x8b);
  8679. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x33,0xfb);
  8680. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x34,0x7b);
  8681. }
  8682. }
  8683. }
  8684. }
  8685. static void
  8686. SetDelayComp661(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
  8687. unsigned short ModeIdIndex, unsigned short RTI)
  8688. {
  8689. unsigned short delay = 0, romptr = 0, index, lcdpdcindex;
  8690. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  8691. if(!(SiS_Pr->SiS_VBInfo & (SetCRT2ToTV | SetCRT2ToLCD | SetCRT2ToLCDA | SetCRT2ToRAMDAC)))
  8692. return;
  8693. /* 1. New ROM: VGA2 and LCD/LCDA-Pass1:1 */
  8694. /* (If a custom mode is used, Pass1:1 is always set; hence we do this:) */
  8695. if(SiS_Pr->SiS_ROMNew) {
  8696. if((SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) ||
  8697. ((SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) &&
  8698. (SiS_Pr->SiS_LCDInfo & LCDPass11))) {
  8699. index = 25;
  8700. if(SiS_Pr->UseCustomMode) {
  8701. index = SiS_Pr->CSRClock;
  8702. } else if(ModeNo > 0x13) {
  8703. index = SiS_GetVCLK2Ptr(SiS_Pr,ModeNo,ModeIdIndex,RTI);
  8704. index = SiS_Pr->SiS_VCLKData[index].CLOCK;
  8705. }
  8706. if(index < 25) index = 25;
  8707. index = ((index / 25) - 1) << 1;
  8708. if((ROMAddr[0x5b] & 0x80) || (SiS_Pr->SiS_VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD))) {
  8709. index++;
  8710. }
  8711. romptr = SISGETROMW(0x104);
  8712. delay = ROMAddr[romptr + index];
  8713. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD)) {
  8714. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0xf0,((delay >> 1) & 0x0f));
  8715. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x35,0x7f,((delay & 0x01) << 7));
  8716. } else {
  8717. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0x0f,((delay << 3) & 0xf0));
  8718. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x20,0xbf,((delay & 0x01) << 6));
  8719. }
  8720. return;
  8721. }
  8722. }
  8723. /* 2. Old ROM: VGA2 and LCD/LCDA-Pass 1:1 */
  8724. if(SiS_Pr->UseCustomMode) delay = 0x04;
  8725. else if(ModeNo <= 0x13) delay = 0x04;
  8726. else delay = (SiS_Pr->SiS_RefIndex[RTI].Ext_PDC >> 4);
  8727. delay |= (delay << 8);
  8728. if(SiS_Pr->ChipType >= XGI_20) {
  8729. delay = 0x0606;
  8730. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  8731. delay = 0x0404;
  8732. if(SiS_Pr->SiS_XGIROM) {
  8733. index = GetTVPtrIndex(SiS_Pr);
  8734. if((romptr = SISGETROMW(0x35e))) {
  8735. delay = (ROMAddr[romptr + index] & 0x0f) << 1;
  8736. delay |= (delay << 8);
  8737. }
  8738. }
  8739. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  8740. if(SiS_Pr->ChipType == XGI_40 && SiS_Pr->ChipRevision == 0x02) {
  8741. delay -= 0x0404;
  8742. }
  8743. }
  8744. }
  8745. } else if(SiS_Pr->ChipType >= SIS_340) {
  8746. delay = 0x0606;
  8747. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  8748. delay = 0x0404;
  8749. }
  8750. /* TODO (eventually) */
  8751. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  8752. /* 3. TV */
  8753. index = GetOEMTVPtr661(SiS_Pr);
  8754. if(SiS_Pr->SiS_ROMNew) {
  8755. romptr = SISGETROMW(0x106);
  8756. if(SiS_Pr->SiS_VBType & VB_UMC) romptr += 12;
  8757. delay = ROMAddr[romptr + index];
  8758. } else {
  8759. delay = 0x04;
  8760. if(index > 3) delay = 0;
  8761. }
  8762. } else if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  8763. /* 4. LCD, LCDA (for new ROM only LV and non-Pass 1:1) */
  8764. if( (SiS_Pr->SiS_LCDResInfo != Panel_Custom) &&
  8765. ((romptr = GetLCDStructPtr661_2(SiS_Pr))) ) {
  8766. lcdpdcindex = (SiS_Pr->SiS_VBType & VB_UMC) ? 14 : 12;
  8767. /* For LVDS (and sometimes TMDS), the BIOS must know about the correct value */
  8768. delay = ROMAddr[romptr + lcdpdcindex + 1]; /* LCD */
  8769. delay |= (ROMAddr[romptr + lcdpdcindex] << 8); /* LCDA */
  8770. } else {
  8771. /* TMDS: Set our own, since BIOS has no idea */
  8772. /* (This is done on >=661 only, since <661 is calling this only for LVDS) */
  8773. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  8774. switch(SiS_Pr->SiS_LCDResInfo) {
  8775. case Panel_1024x768: delay = 0x0008; break;
  8776. case Panel_1280x720: delay = 0x0004; break;
  8777. case Panel_1280x768:
  8778. case Panel_1280x768_2:delay = 0x0004; break;
  8779. case Panel_1280x800:
  8780. case Panel_1280x800_2:delay = 0x0004; break; /* Verified for 1280x800 */
  8781. case Panel_1280x854: delay = 0x0004; break; /* FIXME */
  8782. case Panel_1280x1024: delay = 0x1e04; break;
  8783. case Panel_1400x1050: delay = 0x0004; break;
  8784. case Panel_1600x1200: delay = 0x0400; break;
  8785. case Panel_1680x1050: delay = 0x0e04; break;
  8786. default:
  8787. if((SiS_Pr->PanelXRes <= 1024) && (SiS_Pr->PanelYRes <= 768)) {
  8788. delay = 0x0008;
  8789. } else if((SiS_Pr->PanelXRes == 1280) && (SiS_Pr->PanelYRes == 1024)) {
  8790. delay = 0x1e04;
  8791. } else if((SiS_Pr->PanelXRes <= 1400) && (SiS_Pr->PanelYRes <= 1050)) {
  8792. delay = 0x0004;
  8793. } else if((SiS_Pr->PanelXRes <= 1600) && (SiS_Pr->PanelYRes <= 1200)) {
  8794. delay = 0x0400;
  8795. } else
  8796. delay = 0x0e04;
  8797. break;
  8798. }
  8799. }
  8800. /* Override by detected or user-set values */
  8801. /* (but only if, for some reason, we can't read value from BIOS) */
  8802. if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && (SiS_Pr->PDC != -1)) {
  8803. delay = SiS_Pr->PDC & 0x1f;
  8804. }
  8805. if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) && (SiS_Pr->PDCA != -1)) {
  8806. delay = (SiS_Pr->PDCA & 0x1f) << 8;
  8807. }
  8808. }
  8809. }
  8810. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  8811. delay >>= 8;
  8812. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0x0f,((delay << 3) & 0xf0));
  8813. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x20,0xbf,((delay & 0x01) << 6));
  8814. } else {
  8815. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0xf0,((delay >> 1) & 0x0f));
  8816. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x35,0x7f,((delay & 0x01) << 7));
  8817. }
  8818. }
  8819. static void
  8820. SetCRT2SyncDither661(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short RTI)
  8821. {
  8822. unsigned short infoflag;
  8823. unsigned char temp;
  8824. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  8825. if(ModeNo <= 0x13) {
  8826. infoflag = SiS_GetRegByte(SiS_Pr->SiS_P3ca+2);
  8827. } else if(SiS_Pr->UseCustomMode) {
  8828. infoflag = SiS_Pr->CInfoFlag;
  8829. } else {
  8830. infoflag = SiS_Pr->SiS_RefIndex[RTI].Ext_InfoFlag;
  8831. }
  8832. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  8833. infoflag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x37); /* No longer check D5 */
  8834. }
  8835. infoflag &= 0xc0;
  8836. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  8837. temp = (infoflag >> 6) | 0x0c;
  8838. if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) {
  8839. temp ^= 0x04;
  8840. if(SiS_Pr->SiS_ModeType >= Mode24Bpp) temp |= 0x10;
  8841. }
  8842. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1a,0xe0,temp);
  8843. } else {
  8844. temp = 0x30;
  8845. if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) temp = 0x20;
  8846. temp |= infoflag;
  8847. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0f,temp);
  8848. temp = 0;
  8849. if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) {
  8850. if(SiS_Pr->SiS_ModeType >= Mode24Bpp) temp |= 0x80;
  8851. }
  8852. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x1a,0x7f,temp);
  8853. }
  8854. }
  8855. }
  8856. static void
  8857. SetPanelParms661(struct SiS_Private *SiS_Pr)
  8858. {
  8859. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  8860. unsigned short romptr, temp1, temp2;
  8861. if(SiS_Pr->SiS_VBType & (VB_SISLVDS | VB_SIS30xC)) {
  8862. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x24,0x0f);
  8863. }
  8864. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  8865. if(SiS_Pr->LVDSHL != -1) {
  8866. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,0xfc,SiS_Pr->LVDSHL);
  8867. }
  8868. }
  8869. if(SiS_Pr->SiS_ROMNew) {
  8870. if((romptr = GetLCDStructPtr661_2(SiS_Pr))) {
  8871. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  8872. temp1 = (ROMAddr[romptr] & 0x03) | 0x0c;
  8873. temp2 = 0xfc;
  8874. if(SiS_Pr->LVDSHL != -1) {
  8875. temp1 &= 0xfc;
  8876. temp2 = 0xf3;
  8877. }
  8878. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,temp2,temp1);
  8879. }
  8880. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  8881. temp1 = (ROMAddr[romptr + 1] & 0x80) >> 1;
  8882. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x0d,0xbf,temp1);
  8883. }
  8884. }
  8885. }
  8886. }
  8887. static void
  8888. SiS_OEM310Setting(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex, unsigned short RRTI)
  8889. {
  8890. if((SiS_Pr->SiS_ROMNew) && (SiS_Pr->SiS_VBType & VB_SISLVDS)) {
  8891. SetDelayComp661(SiS_Pr, ModeNo, ModeIdIndex, RRTI);
  8892. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  8893. SetCRT2SyncDither661(SiS_Pr, ModeNo, RRTI);
  8894. SetPanelParms661(SiS_Pr);
  8895. }
  8896. } else {
  8897. SetDelayComp(SiS_Pr,ModeNo);
  8898. }
  8899. if((SiS_Pr->SiS_VBType & VB_SISVB) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
  8900. SetAntiFlicker(SiS_Pr,ModeNo,ModeIdIndex);
  8901. SetPhaseIncr(SiS_Pr,ModeNo,ModeIdIndex);
  8902. SetYFilter(SiS_Pr,ModeNo,ModeIdIndex);
  8903. if(SiS_Pr->SiS_VBType & VB_SIS301) {
  8904. SetEdgeEnhance(SiS_Pr,ModeNo,ModeIdIndex);
  8905. }
  8906. }
  8907. }
  8908. static void
  8909. SiS_OEM661Setting(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
  8910. unsigned short ModeIdIndex, unsigned short RRTI)
  8911. {
  8912. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  8913. SetDelayComp661(SiS_Pr, ModeNo, ModeIdIndex, RRTI);
  8914. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  8915. SetCRT2SyncDither661(SiS_Pr, ModeNo, RRTI);
  8916. SetPanelParms661(SiS_Pr);
  8917. }
  8918. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  8919. SetPhaseIncr(SiS_Pr, ModeNo, ModeIdIndex);
  8920. SetYFilter(SiS_Pr, ModeNo, ModeIdIndex);
  8921. SetAntiFlicker(SiS_Pr, ModeNo, ModeIdIndex);
  8922. if(SiS_Pr->SiS_VBType & VB_SIS301) {
  8923. SetEdgeEnhance(SiS_Pr, ModeNo, ModeIdIndex);
  8924. }
  8925. }
  8926. }
  8927. }
  8928. /* FinalizeLCD
  8929. * This finalizes some CRT2 registers for the very panel used.
  8930. * If we have a backup if these registers, we use it; otherwise
  8931. * we set the register according to most BIOSes. However, this
  8932. * function looks quite different in every BIOS, so you better
  8933. * pray that we have a backup...
  8934. */
  8935. static void
  8936. SiS_FinalizeLCD(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  8937. {
  8938. unsigned short tempcl,tempch,tempbl,tempbh,tempbx,tempax,temp;
  8939. unsigned short resinfo,modeflag;
  8940. if(!(SiS_Pr->SiS_VBType & VB_SISLVDS)) return;
  8941. if(SiS_Pr->SiS_ROMNew) return;
  8942. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  8943. if(SiS_Pr->LVDSHL != -1) {
  8944. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,0xfc,SiS_Pr->LVDSHL);
  8945. }
  8946. }
  8947. if(SiS_Pr->SiS_LCDResInfo == Panel_Custom) return;
  8948. if(SiS_Pr->UseCustomMode) return;
  8949. switch(SiS_Pr->SiS_CustomT) {
  8950. case CUT_COMPAQ1280:
  8951. case CUT_COMPAQ12802:
  8952. case CUT_CLEVO1400:
  8953. case CUT_CLEVO14002:
  8954. return;
  8955. }
  8956. if(ModeNo <= 0x13) {
  8957. resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
  8958. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  8959. } else {
  8960. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  8961. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  8962. }
  8963. if(IS_SIS650) {
  8964. if(!(SiS_GetReg(SiS_Pr->SiS_P3d4, 0x5f) & 0xf0)) {
  8965. if(SiS_Pr->SiS_CustomT == CUT_CLEVO1024) {
  8966. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1e,0x02);
  8967. } else {
  8968. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1e,0x03);
  8969. }
  8970. }
  8971. }
  8972. if(SiS_Pr->SiS_CustomT == CUT_CLEVO1024) {
  8973. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  8974. /* Maybe all panels? */
  8975. if(SiS_Pr->LVDSHL == -1) {
  8976. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,0xfc,0x01);
  8977. }
  8978. return;
  8979. }
  8980. }
  8981. if(SiS_Pr->SiS_CustomT == CUT_CLEVO10242) {
  8982. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  8983. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  8984. if(SiS_Pr->LVDSHL == -1) {
  8985. /* Maybe all panels? */
  8986. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,0xfc,0x01);
  8987. }
  8988. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  8989. tempch = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4;
  8990. if(tempch == 3) {
  8991. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x02);
  8992. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,0x25);
  8993. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1c,0x00);
  8994. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1d,0x1b);
  8995. }
  8996. }
  8997. return;
  8998. }
  8999. }
  9000. }
  9001. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  9002. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  9003. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  9004. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2a,0x00);
  9005. #ifdef SET_EMI
  9006. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
  9007. #endif
  9008. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x34,0x10);
  9009. }
  9010. } else if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) {
  9011. if(SiS_Pr->LVDSHL == -1) {
  9012. /* Maybe ACER only? */
  9013. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,0xfc,0x01);
  9014. }
  9015. }
  9016. tempch = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4;
  9017. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  9018. if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) {
  9019. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1f,0x76);
  9020. } else if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  9021. if(tempch == 0x03) {
  9022. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x02);
  9023. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,0x25);
  9024. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1c,0x00);
  9025. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1d,0x1b);
  9026. }
  9027. if(SiS_Pr->Backup && (SiS_Pr->Backup_Mode == ModeNo)) {
  9028. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x14,SiS_Pr->Backup_14);
  9029. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x15,SiS_Pr->Backup_15);
  9030. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x16,SiS_Pr->Backup_16);
  9031. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x17,SiS_Pr->Backup_17);
  9032. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,SiS_Pr->Backup_18);
  9033. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x19,SiS_Pr->Backup_19);
  9034. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1a,SiS_Pr->Backup_1a);
  9035. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,SiS_Pr->Backup_1b);
  9036. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1c,SiS_Pr->Backup_1c);
  9037. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1d,SiS_Pr->Backup_1d);
  9038. } else if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) { /* 1.10.8w */
  9039. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x14,0x90);
  9040. if(ModeNo <= 0x13) {
  9041. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x11);
  9042. if((resinfo == 0) || (resinfo == 2)) return;
  9043. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x18);
  9044. if((resinfo == 1) || (resinfo == 3)) return;
  9045. }
  9046. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x02);
  9047. if((ModeNo > 0x13) && (resinfo == SIS_RI_1024x768)) {
  9048. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x02); /* 1.10.7u */
  9049. #if 0
  9050. tempbx = 806; /* 0x326 */ /* other older BIOSes */
  9051. tempbx--;
  9052. temp = tempbx & 0xff;
  9053. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,temp);
  9054. temp = (tempbx >> 8) & 0x03;
  9055. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x1d,0xf8,temp);
  9056. #endif
  9057. }
  9058. } else if(ModeNo <= 0x13) {
  9059. if(ModeNo <= 1) {
  9060. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x70);
  9061. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x19,0xff);
  9062. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,0x48);
  9063. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1d,0x12);
  9064. }
  9065. if(!(modeflag & HalfDCLK)) {
  9066. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x14,0x20);
  9067. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x15,0x1a);
  9068. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x16,0x28);
  9069. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x17,0x00);
  9070. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x4c);
  9071. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x19,0xdc);
  9072. if(ModeNo == 0x12) {
  9073. switch(tempch) {
  9074. case 0:
  9075. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x95);
  9076. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x19,0xdc);
  9077. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1a,0x10);
  9078. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,0x95);
  9079. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1c,0x48);
  9080. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1d,0x12);
  9081. break;
  9082. case 2:
  9083. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x95);
  9084. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,0x48);
  9085. break;
  9086. case 3:
  9087. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,0x95);
  9088. break;
  9089. }
  9090. }
  9091. }
  9092. }
  9093. }
  9094. } else {
  9095. tempcl = tempbh = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x01);
  9096. tempcl &= 0x0f;
  9097. tempbh &= 0x70;
  9098. tempbh >>= 4;
  9099. tempbl = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x04);
  9100. tempbx = (tempbh << 8) | tempbl;
  9101. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  9102. if((resinfo == SIS_RI_1024x768) || (!(SiS_Pr->SiS_LCDInfo & DontExpandLCD))) {
  9103. if(SiS_Pr->SiS_SetFlag & LCDVESATiming) {
  9104. tempbx = 770;
  9105. } else {
  9106. if(tempbx > 770) tempbx = 770;
  9107. if(SiS_Pr->SiS_VGAVDE < 600) {
  9108. tempax = 768 - SiS_Pr->SiS_VGAVDE;
  9109. tempax >>= 4; /* 1.10.7w; 1.10.6s: 3; */
  9110. if(SiS_Pr->SiS_VGAVDE <= 480) tempax >>= 4; /* 1.10.7w; 1.10.6s: < 480; >>=1; */
  9111. tempbx -= tempax;
  9112. }
  9113. }
  9114. } else return;
  9115. }
  9116. temp = tempbx & 0xff;
  9117. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,temp);
  9118. temp = ((tempbx & 0xff00) >> 4) | tempcl;
  9119. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x01,0x80,temp);
  9120. }
  9121. }
  9122. }
  9123. #endif
  9124. /* ================= SiS 300 O.E.M. ================== */
  9125. #ifdef CONFIG_FB_SIS_300
  9126. static void
  9127. SetOEMLCDData2(struct SiS_Private *SiS_Pr, unsigned short ModeNo,unsigned short ModeIdIndex,
  9128. unsigned short RefTabIndex)
  9129. {
  9130. unsigned short crt2crtc=0, modeflag, myindex=0;
  9131. unsigned char temp;
  9132. int i;
  9133. if(ModeNo <= 0x13) {
  9134. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  9135. crt2crtc = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  9136. } else {
  9137. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  9138. crt2crtc = SiS_Pr->SiS_RefIndex[RefTabIndex].Ext_CRT2CRTC;
  9139. }
  9140. crt2crtc &= 0x3f;
  9141. if(SiS_Pr->SiS_CustomT == CUT_BARCO1024) {
  9142. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xdf);
  9143. }
  9144. if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) {
  9145. if(modeflag & HalfDCLK) myindex = 1;
  9146. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  9147. for(i=0; i<7; i++) {
  9148. if(barco_p1[myindex][crt2crtc][i][0]) {
  9149. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,
  9150. barco_p1[myindex][crt2crtc][i][0],
  9151. barco_p1[myindex][crt2crtc][i][2],
  9152. barco_p1[myindex][crt2crtc][i][1]);
  9153. }
  9154. }
  9155. }
  9156. temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00);
  9157. if(temp & 0x80) {
  9158. temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x18);
  9159. temp++;
  9160. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,temp);
  9161. }
  9162. }
  9163. }
  9164. static unsigned short
  9165. GetOEMLCDPtr(struct SiS_Private *SiS_Pr, int Flag)
  9166. {
  9167. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  9168. unsigned short tempbx=0,romptr=0;
  9169. static const unsigned char customtable300[] = {
  9170. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  9171. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
  9172. };
  9173. static const unsigned char customtable630[] = {
  9174. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  9175. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
  9176. };
  9177. if(SiS_Pr->ChipType == SIS_300) {
  9178. tempbx = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) & 0x0f;
  9179. if(SiS_Pr->SiS_VBType & VB_SIS301) tempbx &= 0x07;
  9180. tempbx -= 2;
  9181. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) tempbx += 4;
  9182. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  9183. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx += 3;
  9184. }
  9185. if(SiS_Pr->SiS_UseROM) {
  9186. if(ROMAddr[0x235] & 0x80) {
  9187. tempbx = SiS_Pr->SiS_LCDTypeInfo;
  9188. if(Flag) {
  9189. romptr = SISGETROMW(0x255);
  9190. if(romptr) tempbx = ROMAddr[romptr + SiS_Pr->SiS_LCDTypeInfo];
  9191. else tempbx = customtable300[SiS_Pr->SiS_LCDTypeInfo];
  9192. if(tempbx == 0xFF) return 0xFFFF;
  9193. }
  9194. tempbx <<= 1;
  9195. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) tempbx++;
  9196. }
  9197. }
  9198. } else {
  9199. if(Flag) {
  9200. if(SiS_Pr->SiS_UseROM) {
  9201. romptr = SISGETROMW(0x255);
  9202. if(romptr) tempbx = ROMAddr[romptr + SiS_Pr->SiS_LCDTypeInfo];
  9203. else tempbx = 0xff;
  9204. } else {
  9205. tempbx = customtable630[SiS_Pr->SiS_LCDTypeInfo];
  9206. }
  9207. if(tempbx == 0xFF) return 0xFFFF;
  9208. tempbx <<= 2;
  9209. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) tempbx += 2;
  9210. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++;
  9211. return tempbx;
  9212. }
  9213. tempbx = SiS_Pr->SiS_LCDTypeInfo << 2;
  9214. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) tempbx += 2;
  9215. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++;
  9216. }
  9217. return tempbx;
  9218. }
  9219. static void
  9220. SetOEMLCDDelay(struct SiS_Private *SiS_Pr, unsigned short ModeNo,unsigned short ModeIdIndex)
  9221. {
  9222. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  9223. unsigned short index,temp,romptr=0;
  9224. if(SiS_Pr->SiS_LCDResInfo == Panel_Custom) return;
  9225. if(SiS_Pr->SiS_UseROM) {
  9226. if(!(ROMAddr[0x237] & 0x01)) return;
  9227. if(!(ROMAddr[0x237] & 0x02)) return;
  9228. romptr = SISGETROMW(0x24b);
  9229. }
  9230. /* The Panel Compensation Delay should be set according to tables
  9231. * here. Unfortunately, various BIOS versions don't care about
  9232. * a uniform way using eg. ROM byte 0x220, but use different
  9233. * hard coded delays (0x04, 0x20, 0x18) in SetGroup1().
  9234. * Thus we don't set this if the user selected a custom pdc or if
  9235. * we otherwise detected a valid pdc.
  9236. */
  9237. if(SiS_Pr->PDC != -1) return;
  9238. temp = GetOEMLCDPtr(SiS_Pr, 0);
  9239. if(SiS_Pr->UseCustomMode)
  9240. index = 0;
  9241. else
  9242. index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].VB_LCDDelayIndex;
  9243. if(SiS_Pr->ChipType != SIS_300) {
  9244. if(romptr) {
  9245. romptr += (temp * 2);
  9246. romptr = SISGETROMW(romptr);
  9247. romptr += index;
  9248. temp = ROMAddr[romptr];
  9249. } else {
  9250. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  9251. temp = SiS300_OEMLCDDelay2[temp][index];
  9252. } else {
  9253. temp = SiS300_OEMLCDDelay3[temp][index];
  9254. }
  9255. }
  9256. } else {
  9257. if(SiS_Pr->SiS_UseROM && (ROMAddr[0x235] & 0x80)) {
  9258. if(romptr) {
  9259. romptr += (temp * 2);
  9260. romptr = SISGETROMW(romptr);
  9261. romptr += index;
  9262. temp = ROMAddr[romptr];
  9263. } else {
  9264. temp = SiS300_OEMLCDDelay5[temp][index];
  9265. }
  9266. } else {
  9267. if(SiS_Pr->SiS_UseROM) {
  9268. romptr = ROMAddr[0x249] | (ROMAddr[0x24a] << 8);
  9269. if(romptr) {
  9270. romptr += (temp * 2);
  9271. romptr = SISGETROMW(romptr);
  9272. romptr += index;
  9273. temp = ROMAddr[romptr];
  9274. } else {
  9275. temp = SiS300_OEMLCDDelay4[temp][index];
  9276. }
  9277. } else {
  9278. temp = SiS300_OEMLCDDelay4[temp][index];
  9279. }
  9280. }
  9281. }
  9282. temp &= 0x3c;
  9283. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,~0x3C,temp); /* index 0A D[6:4] */
  9284. }
  9285. static void
  9286. SetOEMLCDData(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  9287. {
  9288. #if 0 /* Unfinished; Data table missing */
  9289. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  9290. unsigned short index,temp;
  9291. if((SiS_Pr->SiS_UseROM) {
  9292. if(!(ROMAddr[0x237] & 0x01)) return;
  9293. if(!(ROMAddr[0x237] & 0x04)) return;
  9294. /* No rom pointer in BIOS header! */
  9295. }
  9296. temp = GetOEMLCDPtr(SiS_Pr, 1);
  9297. if(temp == 0xFFFF) return;
  9298. index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex]._VB_LCDHIndex;
  9299. for(i=0x14, j=0; i<=0x17; i++, j++) {
  9300. SiS_SetReg(SiS_Pr->SiS_Part1Port,i,SiS300_LCDHData[temp][index][j]);
  9301. }
  9302. SiS_SetRegANDOR(SiS_SiS_Part1Port,0x1a, 0xf8, (SiS300_LCDHData[temp][index][j] & 0x07));
  9303. index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex]._VB_LCDVIndex;
  9304. SiS_SetReg(SiS_SiS_Part1Port,0x18, SiS300_LCDVData[temp][index][0]);
  9305. SiS_SetRegANDOR(SiS_SiS_Part1Port,0x19, 0xF0, SiS300_LCDVData[temp][index][1]);
  9306. SiS_SetRegANDOR(SiS_SiS_Part1Port,0x1A, 0xC7, (SiS300_LCDVData[temp][index][2] & 0x38));
  9307. for(i=0x1b, j=3; i<=0x1d; i++, j++) {
  9308. SiS_SetReg(SiS_Pr->SiS_Part1Port,i,SiS300_LCDVData[temp][index][j]);
  9309. }
  9310. #endif
  9311. }
  9312. static unsigned short
  9313. GetOEMTVPtr(struct SiS_Private *SiS_Pr)
  9314. {
  9315. unsigned short index;
  9316. index = 0;
  9317. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) index += 4;
  9318. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  9319. if(SiS_Pr->SiS_VBInfo & SetCRT2ToSCART) index += 2;
  9320. else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) index += 3;
  9321. else if(SiS_Pr->SiS_TVMode & TVSetPAL) index += 1;
  9322. } else {
  9323. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) index += 2;
  9324. if(SiS_Pr->SiS_TVMode & TVSetPAL) index += 1;
  9325. }
  9326. return index;
  9327. }
  9328. static void
  9329. SetOEMTVDelay(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  9330. {
  9331. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  9332. unsigned short index,temp,romptr=0;
  9333. if(SiS_Pr->SiS_UseROM) {
  9334. if(!(ROMAddr[0x238] & 0x01)) return;
  9335. if(!(ROMAddr[0x238] & 0x02)) return;
  9336. romptr = SISGETROMW(0x241);
  9337. }
  9338. temp = GetOEMTVPtr(SiS_Pr);
  9339. index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].VB_TVDelayIndex;
  9340. if(romptr) {
  9341. romptr += (temp * 2);
  9342. romptr = SISGETROMW(romptr);
  9343. romptr += index;
  9344. temp = ROMAddr[romptr];
  9345. } else {
  9346. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  9347. temp = SiS300_OEMTVDelay301[temp][index];
  9348. } else {
  9349. temp = SiS300_OEMTVDelayLVDS[temp][index];
  9350. }
  9351. }
  9352. temp &= 0x3c;
  9353. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,~0x3C,temp);
  9354. }
  9355. static void
  9356. SetOEMAntiFlicker(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  9357. {
  9358. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  9359. unsigned short index,temp,romptr=0;
  9360. if(SiS_Pr->SiS_UseROM) {
  9361. if(!(ROMAddr[0x238] & 0x01)) return;
  9362. if(!(ROMAddr[0x238] & 0x04)) return;
  9363. romptr = SISGETROMW(0x243);
  9364. }
  9365. temp = GetOEMTVPtr(SiS_Pr);
  9366. index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].VB_TVFlickerIndex;
  9367. if(romptr) {
  9368. romptr += (temp * 2);
  9369. romptr = SISGETROMW(romptr);
  9370. romptr += index;
  9371. temp = ROMAddr[romptr];
  9372. } else {
  9373. temp = SiS300_OEMTVFlicker[temp][index];
  9374. }
  9375. temp &= 0x70;
  9376. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x0A,0x8F,temp);
  9377. }
  9378. static void
  9379. SetOEMPhaseIncr(struct SiS_Private *SiS_Pr, unsigned short ModeNo,unsigned short ModeIdIndex)
  9380. {
  9381. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  9382. unsigned short index,i,j,temp,romptr=0;
  9383. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) return;
  9384. if(SiS_Pr->SiS_TVMode & (TVSetNTSC1024 | TVSetNTSCJ | TVSetPALM | TVSetPALN)) return;
  9385. if(SiS_Pr->SiS_UseROM) {
  9386. if(!(ROMAddr[0x238] & 0x01)) return;
  9387. if(!(ROMAddr[0x238] & 0x08)) return;
  9388. romptr = SISGETROMW(0x245);
  9389. }
  9390. temp = GetOEMTVPtr(SiS_Pr);
  9391. index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].VB_TVPhaseIndex;
  9392. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  9393. for(i=0x31, j=0; i<=0x34; i++, j++) {
  9394. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS300_Phase2[temp][index][j]);
  9395. }
  9396. } else {
  9397. if(romptr) {
  9398. romptr += (temp * 2);
  9399. romptr = SISGETROMW(romptr);
  9400. romptr += (index * 4);
  9401. for(i=0x31, j=0; i<=0x34; i++, j++) {
  9402. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,ROMAddr[romptr + j]);
  9403. }
  9404. } else {
  9405. for(i=0x31, j=0; i<=0x34; i++, j++) {
  9406. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS300_Phase1[temp][index][j]);
  9407. }
  9408. }
  9409. }
  9410. }
  9411. static void
  9412. SetOEMYFilter(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  9413. {
  9414. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  9415. unsigned short index,temp,i,j,romptr=0;
  9416. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToSCART | SetCRT2ToHiVision | SetCRT2ToYPbPr525750)) return;
  9417. if(SiS_Pr->SiS_UseROM) {
  9418. if(!(ROMAddr[0x238] & 0x01)) return;
  9419. if(!(ROMAddr[0x238] & 0x10)) return;
  9420. romptr = SISGETROMW(0x247);
  9421. }
  9422. temp = GetOEMTVPtr(SiS_Pr);
  9423. if(SiS_Pr->SiS_TVMode & TVSetPALM) temp = 8;
  9424. else if(SiS_Pr->SiS_TVMode & TVSetPALN) temp = 9;
  9425. /* NTSCJ uses NTSC filters */
  9426. index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].VB_TVYFilterIndex;
  9427. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  9428. for(i=0x35, j=0; i<=0x38; i++, j++) {
  9429. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS300_Filter2[temp][index][j]);
  9430. }
  9431. for(i=0x48; i<=0x4A; i++, j++) {
  9432. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS300_Filter2[temp][index][j]);
  9433. }
  9434. } else {
  9435. if((romptr) && (!(SiS_Pr->SiS_TVMode & (TVSetPALM|TVSetPALN)))) {
  9436. romptr += (temp * 2);
  9437. romptr = SISGETROMW(romptr);
  9438. romptr += (index * 4);
  9439. for(i=0x35, j=0; i<=0x38; i++, j++) {
  9440. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,ROMAddr[romptr + j]);
  9441. }
  9442. } else {
  9443. for(i=0x35, j=0; i<=0x38; i++, j++) {
  9444. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS300_Filter1[temp][index][j]);
  9445. }
  9446. }
  9447. }
  9448. }
  9449. static unsigned short
  9450. SiS_SearchVBModeID(struct SiS_Private *SiS_Pr, unsigned short *ModeNo)
  9451. {
  9452. unsigned short ModeIdIndex;
  9453. unsigned char VGAINFO = SiS_Pr->SiS_VGAINFO;
  9454. if(*ModeNo <= 5) *ModeNo |= 1;
  9455. for(ModeIdIndex=0; ; ModeIdIndex++) {
  9456. if(SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].ModeID == *ModeNo) break;
  9457. if(SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].ModeID == 0xFF) return 0;
  9458. }
  9459. if(*ModeNo != 0x07) {
  9460. if(*ModeNo > 0x03) return ModeIdIndex;
  9461. if(VGAINFO & 0x80) return ModeIdIndex;
  9462. ModeIdIndex++;
  9463. }
  9464. if(VGAINFO & 0x10) ModeIdIndex++; /* 400 lines */
  9465. /* else 350 lines */
  9466. return ModeIdIndex;
  9467. }
  9468. static void
  9469. SiS_OEM300Setting(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  9470. unsigned short RefTableIndex)
  9471. {
  9472. unsigned short OEMModeIdIndex = 0;
  9473. if(!SiS_Pr->UseCustomMode) {
  9474. OEMModeIdIndex = SiS_SearchVBModeID(SiS_Pr,&ModeNo);
  9475. if(!(OEMModeIdIndex)) return;
  9476. }
  9477. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  9478. SetOEMLCDDelay(SiS_Pr, ModeNo, OEMModeIdIndex);
  9479. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  9480. SetOEMLCDData(SiS_Pr, ModeNo, OEMModeIdIndex);
  9481. }
  9482. }
  9483. if(SiS_Pr->UseCustomMode) return;
  9484. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  9485. SetOEMTVDelay(SiS_Pr, ModeNo,OEMModeIdIndex);
  9486. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  9487. SetOEMAntiFlicker(SiS_Pr, ModeNo, OEMModeIdIndex);
  9488. SetOEMPhaseIncr(SiS_Pr, ModeNo, OEMModeIdIndex);
  9489. SetOEMYFilter(SiS_Pr, ModeNo, OEMModeIdIndex);
  9490. }
  9491. }
  9492. }
  9493. #endif