sis_main.c 184 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894
  1. /*
  2. * SiS 300/540/630[S]/730[S],
  3. * SiS 315[E|PRO]/550/[M]65x/[M]66x[F|M|G]X/[M]74x[GX]/330/[M]76x[GX],
  4. * XGI V3XT/V5/V8, Z7
  5. * frame buffer driver for Linux kernels >= 2.4.14 and >=2.6.3
  6. *
  7. * Copyright (C) 2001-2005 Thomas Winischhofer, Vienna, Austria.
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the named License,
  12. * or any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
  22. *
  23. * Author: Thomas Winischhofer <thomas@winischhofer.net>
  24. *
  25. * Author of (practically wiped) code base:
  26. * SiS (www.sis.com)
  27. * Copyright (C) 1999 Silicon Integrated Systems, Inc.
  28. *
  29. * See http://www.winischhofer.net/ for more information and updates
  30. *
  31. * Originally based on the VBE 2.0 compliant graphic boards framebuffer driver,
  32. * which is (c) 1998 Gerd Knorr <kraxel@goldbach.in-berlin.de>
  33. *
  34. */
  35. #include <linux/module.h>
  36. #include <linux/moduleparam.h>
  37. #include <linux/kernel.h>
  38. #include <linux/spinlock.h>
  39. #include <linux/errno.h>
  40. #include <linux/string.h>
  41. #include <linux/mm.h>
  42. #include <linux/screen_info.h>
  43. #include <linux/slab.h>
  44. #include <linux/fb.h>
  45. #include <linux/selection.h>
  46. #include <linux/ioport.h>
  47. #include <linux/init.h>
  48. #include <linux/pci.h>
  49. #include <linux/vmalloc.h>
  50. #include <linux/capability.h>
  51. #include <linux/fs.h>
  52. #include <linux/types.h>
  53. #include <linux/uaccess.h>
  54. #include <asm/io.h>
  55. #ifdef CONFIG_MTRR
  56. #include <asm/mtrr.h>
  57. #endif
  58. #include "sis.h"
  59. #include "sis_main.h"
  60. #if !defined(CONFIG_FB_SIS_300) && !defined(CONFIG_FB_SIS_315)
  61. #warning Neither CONFIG_FB_SIS_300 nor CONFIG_FB_SIS_315 is set
  62. #warning sisfb will not work!
  63. #endif
  64. static void sisfb_handle_command(struct sis_video_info *ivideo,
  65. struct sisfb_cmd *sisfb_command);
  66. /* ------------------ Internal helper routines ----------------- */
  67. static void __init
  68. sisfb_setdefaultparms(void)
  69. {
  70. sisfb_off = 0;
  71. sisfb_parm_mem = 0;
  72. sisfb_accel = -1;
  73. sisfb_ypan = -1;
  74. sisfb_max = -1;
  75. sisfb_userom = -1;
  76. sisfb_useoem = -1;
  77. sisfb_mode_idx = -1;
  78. sisfb_parm_rate = -1;
  79. sisfb_crt1off = 0;
  80. sisfb_forcecrt1 = -1;
  81. sisfb_crt2type = -1;
  82. sisfb_crt2flags = 0;
  83. sisfb_pdc = 0xff;
  84. sisfb_pdca = 0xff;
  85. sisfb_scalelcd = -1;
  86. sisfb_specialtiming = CUT_NONE;
  87. sisfb_lvdshl = -1;
  88. sisfb_dstn = 0;
  89. sisfb_fstn = 0;
  90. sisfb_tvplug = -1;
  91. sisfb_tvstd = -1;
  92. sisfb_tvxposoffset = 0;
  93. sisfb_tvyposoffset = 0;
  94. sisfb_nocrt2rate = 0;
  95. #if !defined(__i386__) && !defined(__x86_64__)
  96. sisfb_resetcard = 0;
  97. sisfb_videoram = 0;
  98. #endif
  99. }
  100. /* ------------- Parameter parsing -------------- */
  101. static void __devinit
  102. sisfb_search_vesamode(unsigned int vesamode, bool quiet)
  103. {
  104. int i = 0, j = 0;
  105. /* We don't know the hardware specs yet and there is no ivideo */
  106. if(vesamode == 0) {
  107. if(!quiet)
  108. printk(KERN_ERR "sisfb: Invalid mode. Using default.\n");
  109. sisfb_mode_idx = DEFAULT_MODE;
  110. return;
  111. }
  112. vesamode &= 0x1dff; /* Clean VESA mode number from other flags */
  113. while(sisbios_mode[i++].mode_no[0] != 0) {
  114. if( (sisbios_mode[i-1].vesa_mode_no_1 == vesamode) ||
  115. (sisbios_mode[i-1].vesa_mode_no_2 == vesamode) ) {
  116. if(sisfb_fstn) {
  117. if(sisbios_mode[i-1].mode_no[1] == 0x50 ||
  118. sisbios_mode[i-1].mode_no[1] == 0x56 ||
  119. sisbios_mode[i-1].mode_no[1] == 0x53)
  120. continue;
  121. } else {
  122. if(sisbios_mode[i-1].mode_no[1] == 0x5a ||
  123. sisbios_mode[i-1].mode_no[1] == 0x5b)
  124. continue;
  125. }
  126. sisfb_mode_idx = i - 1;
  127. j = 1;
  128. break;
  129. }
  130. }
  131. if((!j) && !quiet)
  132. printk(KERN_ERR "sisfb: Invalid VESA mode 0x%x'\n", vesamode);
  133. }
  134. static void __devinit
  135. sisfb_search_mode(char *name, bool quiet)
  136. {
  137. unsigned int j = 0, xres = 0, yres = 0, depth = 0, rate = 0;
  138. int i = 0;
  139. char strbuf[16], strbuf1[20];
  140. char *nameptr = name;
  141. /* We don't know the hardware specs yet and there is no ivideo */
  142. if(name == NULL) {
  143. if(!quiet)
  144. printk(KERN_ERR "sisfb: Internal error, using default mode.\n");
  145. sisfb_mode_idx = DEFAULT_MODE;
  146. return;
  147. }
  148. if(!strnicmp(name, sisbios_mode[MODE_INDEX_NONE].name, strlen(name))) {
  149. if(!quiet)
  150. printk(KERN_ERR "sisfb: Mode 'none' not supported anymore. Using default.\n");
  151. sisfb_mode_idx = DEFAULT_MODE;
  152. return;
  153. }
  154. if(strlen(name) <= 19) {
  155. strcpy(strbuf1, name);
  156. for(i = 0; i < strlen(strbuf1); i++) {
  157. if(strbuf1[i] < '0' || strbuf1[i] > '9') strbuf1[i] = ' ';
  158. }
  159. /* This does some fuzzy mode naming detection */
  160. if(sscanf(strbuf1, "%u %u %u %u", &xres, &yres, &depth, &rate) == 4) {
  161. if((rate <= 32) || (depth > 32)) {
  162. j = rate; rate = depth; depth = j;
  163. }
  164. sprintf(strbuf, "%ux%ux%u", xres, yres, depth);
  165. nameptr = strbuf;
  166. sisfb_parm_rate = rate;
  167. } else if(sscanf(strbuf1, "%u %u %u", &xres, &yres, &depth) == 3) {
  168. sprintf(strbuf, "%ux%ux%u", xres, yres, depth);
  169. nameptr = strbuf;
  170. } else {
  171. xres = 0;
  172. if((sscanf(strbuf1, "%u %u", &xres, &yres) == 2) && (xres != 0)) {
  173. sprintf(strbuf, "%ux%ux8", xres, yres);
  174. nameptr = strbuf;
  175. } else {
  176. sisfb_search_vesamode(simple_strtoul(name, NULL, 0), quiet);
  177. return;
  178. }
  179. }
  180. }
  181. i = 0; j = 0;
  182. while(sisbios_mode[i].mode_no[0] != 0) {
  183. if(!strnicmp(nameptr, sisbios_mode[i++].name, strlen(nameptr))) {
  184. if(sisfb_fstn) {
  185. if(sisbios_mode[i-1].mode_no[1] == 0x50 ||
  186. sisbios_mode[i-1].mode_no[1] == 0x56 ||
  187. sisbios_mode[i-1].mode_no[1] == 0x53)
  188. continue;
  189. } else {
  190. if(sisbios_mode[i-1].mode_no[1] == 0x5a ||
  191. sisbios_mode[i-1].mode_no[1] == 0x5b)
  192. continue;
  193. }
  194. sisfb_mode_idx = i - 1;
  195. j = 1;
  196. break;
  197. }
  198. }
  199. if((!j) && !quiet)
  200. printk(KERN_ERR "sisfb: Invalid mode '%s'\n", nameptr);
  201. }
  202. #ifndef MODULE
  203. static void __devinit
  204. sisfb_get_vga_mode_from_kernel(void)
  205. {
  206. #ifdef CONFIG_X86
  207. char mymode[32];
  208. int mydepth = screen_info.lfb_depth;
  209. if(screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB) return;
  210. if( (screen_info.lfb_width >= 320) && (screen_info.lfb_width <= 2048) &&
  211. (screen_info.lfb_height >= 200) && (screen_info.lfb_height <= 1536) &&
  212. (mydepth >= 8) && (mydepth <= 32) ) {
  213. if(mydepth == 24) mydepth = 32;
  214. sprintf(mymode, "%ux%ux%u", screen_info.lfb_width,
  215. screen_info.lfb_height,
  216. mydepth);
  217. printk(KERN_DEBUG
  218. "sisfb: Using vga mode %s pre-set by kernel as default\n",
  219. mymode);
  220. sisfb_search_mode(mymode, true);
  221. }
  222. #endif
  223. return;
  224. }
  225. #endif
  226. static void __init
  227. sisfb_search_crt2type(const char *name)
  228. {
  229. int i = 0;
  230. /* We don't know the hardware specs yet and there is no ivideo */
  231. if(name == NULL) return;
  232. while(sis_crt2type[i].type_no != -1) {
  233. if(!strnicmp(name, sis_crt2type[i].name, strlen(sis_crt2type[i].name))) {
  234. sisfb_crt2type = sis_crt2type[i].type_no;
  235. sisfb_tvplug = sis_crt2type[i].tvplug_no;
  236. sisfb_crt2flags = sis_crt2type[i].flags;
  237. break;
  238. }
  239. i++;
  240. }
  241. sisfb_dstn = (sisfb_crt2flags & FL_550_DSTN) ? 1 : 0;
  242. sisfb_fstn = (sisfb_crt2flags & FL_550_FSTN) ? 1 : 0;
  243. if(sisfb_crt2type < 0)
  244. printk(KERN_ERR "sisfb: Invalid CRT2 type: %s\n", name);
  245. }
  246. static void __init
  247. sisfb_search_tvstd(const char *name)
  248. {
  249. int i = 0;
  250. /* We don't know the hardware specs yet and there is no ivideo */
  251. if(name == NULL)
  252. return;
  253. while(sis_tvtype[i].type_no != -1) {
  254. if(!strnicmp(name, sis_tvtype[i].name, strlen(sis_tvtype[i].name))) {
  255. sisfb_tvstd = sis_tvtype[i].type_no;
  256. break;
  257. }
  258. i++;
  259. }
  260. }
  261. static void __init
  262. sisfb_search_specialtiming(const char *name)
  263. {
  264. int i = 0;
  265. bool found = false;
  266. /* We don't know the hardware specs yet and there is no ivideo */
  267. if(name == NULL)
  268. return;
  269. if(!strnicmp(name, "none", 4)) {
  270. sisfb_specialtiming = CUT_FORCENONE;
  271. printk(KERN_DEBUG "sisfb: Special timing disabled\n");
  272. } else {
  273. while(mycustomttable[i].chipID != 0) {
  274. if(!strnicmp(name,mycustomttable[i].optionName,
  275. strlen(mycustomttable[i].optionName))) {
  276. sisfb_specialtiming = mycustomttable[i].SpecialID;
  277. found = true;
  278. printk(KERN_INFO "sisfb: Special timing for %s %s forced (\"%s\")\n",
  279. mycustomttable[i].vendorName,
  280. mycustomttable[i].cardName,
  281. mycustomttable[i].optionName);
  282. break;
  283. }
  284. i++;
  285. }
  286. if(!found) {
  287. printk(KERN_WARNING "sisfb: Invalid SpecialTiming parameter, valid are:");
  288. printk(KERN_WARNING "\t\"none\" (to disable special timings)\n");
  289. i = 0;
  290. while(mycustomttable[i].chipID != 0) {
  291. printk(KERN_WARNING "\t\"%s\" (for %s %s)\n",
  292. mycustomttable[i].optionName,
  293. mycustomttable[i].vendorName,
  294. mycustomttable[i].cardName);
  295. i++;
  296. }
  297. }
  298. }
  299. }
  300. /* ----------- Various detection routines ----------- */
  301. static void __devinit
  302. sisfb_detect_custom_timing(struct sis_video_info *ivideo)
  303. {
  304. unsigned char *biosver = NULL;
  305. unsigned char *biosdate = NULL;
  306. bool footprint;
  307. u32 chksum = 0;
  308. int i, j;
  309. if(ivideo->SiS_Pr.UseROM) {
  310. biosver = ivideo->SiS_Pr.VirtualRomBase + 0x06;
  311. biosdate = ivideo->SiS_Pr.VirtualRomBase + 0x2c;
  312. for(i = 0; i < 32768; i++)
  313. chksum += ivideo->SiS_Pr.VirtualRomBase[i];
  314. }
  315. i = 0;
  316. do {
  317. if( (mycustomttable[i].chipID == ivideo->chip) &&
  318. ((!strlen(mycustomttable[i].biosversion)) ||
  319. (ivideo->SiS_Pr.UseROM &&
  320. (!strncmp(mycustomttable[i].biosversion, biosver,
  321. strlen(mycustomttable[i].biosversion))))) &&
  322. ((!strlen(mycustomttable[i].biosdate)) ||
  323. (ivideo->SiS_Pr.UseROM &&
  324. (!strncmp(mycustomttable[i].biosdate, biosdate,
  325. strlen(mycustomttable[i].biosdate))))) &&
  326. ((!mycustomttable[i].bioschksum) ||
  327. (ivideo->SiS_Pr.UseROM &&
  328. (mycustomttable[i].bioschksum == chksum))) &&
  329. (mycustomttable[i].pcisubsysvendor == ivideo->subsysvendor) &&
  330. (mycustomttable[i].pcisubsyscard == ivideo->subsysdevice) ) {
  331. footprint = true;
  332. for(j = 0; j < 5; j++) {
  333. if(mycustomttable[i].biosFootprintAddr[j]) {
  334. if(ivideo->SiS_Pr.UseROM) {
  335. if(ivideo->SiS_Pr.VirtualRomBase[mycustomttable[i].biosFootprintAddr[j]] !=
  336. mycustomttable[i].biosFootprintData[j]) {
  337. footprint = false;
  338. }
  339. } else
  340. footprint = false;
  341. }
  342. }
  343. if(footprint) {
  344. ivideo->SiS_Pr.SiS_CustomT = mycustomttable[i].SpecialID;
  345. printk(KERN_DEBUG "sisfb: Identified [%s %s], special timing applies\n",
  346. mycustomttable[i].vendorName,
  347. mycustomttable[i].cardName);
  348. printk(KERN_DEBUG "sisfb: [specialtiming parameter name: %s]\n",
  349. mycustomttable[i].optionName);
  350. break;
  351. }
  352. }
  353. i++;
  354. } while(mycustomttable[i].chipID);
  355. }
  356. static bool __devinit
  357. sisfb_interpret_edid(struct sisfb_monitor *monitor, u8 *buffer)
  358. {
  359. int i, j, xres, yres, refresh, index;
  360. u32 emodes;
  361. if(buffer[0] != 0x00 || buffer[1] != 0xff ||
  362. buffer[2] != 0xff || buffer[3] != 0xff ||
  363. buffer[4] != 0xff || buffer[5] != 0xff ||
  364. buffer[6] != 0xff || buffer[7] != 0x00) {
  365. printk(KERN_DEBUG "sisfb: Bad EDID header\n");
  366. return false;
  367. }
  368. if(buffer[0x12] != 0x01) {
  369. printk(KERN_INFO "sisfb: EDID version %d not supported\n",
  370. buffer[0x12]);
  371. return false;
  372. }
  373. monitor->feature = buffer[0x18];
  374. if(!(buffer[0x14] & 0x80)) {
  375. if(!(buffer[0x14] & 0x08)) {
  376. printk(KERN_INFO
  377. "sisfb: WARNING: Monitor does not support separate syncs\n");
  378. }
  379. }
  380. if(buffer[0x13] >= 0x01) {
  381. /* EDID V1 rev 1 and 2: Search for monitor descriptor
  382. * to extract ranges
  383. */
  384. j = 0x36;
  385. for(i=0; i<4; i++) {
  386. if(buffer[j] == 0x00 && buffer[j + 1] == 0x00 &&
  387. buffer[j + 2] == 0x00 && buffer[j + 3] == 0xfd &&
  388. buffer[j + 4] == 0x00) {
  389. monitor->hmin = buffer[j + 7];
  390. monitor->hmax = buffer[j + 8];
  391. monitor->vmin = buffer[j + 5];
  392. monitor->vmax = buffer[j + 6];
  393. monitor->dclockmax = buffer[j + 9] * 10 * 1000;
  394. monitor->datavalid = true;
  395. break;
  396. }
  397. j += 18;
  398. }
  399. }
  400. if(!monitor->datavalid) {
  401. /* Otherwise: Get a range from the list of supported
  402. * Estabished Timings. This is not entirely accurate,
  403. * because fixed frequency monitors are not supported
  404. * that way.
  405. */
  406. monitor->hmin = 65535; monitor->hmax = 0;
  407. monitor->vmin = 65535; monitor->vmax = 0;
  408. monitor->dclockmax = 0;
  409. emodes = buffer[0x23] | (buffer[0x24] << 8) | (buffer[0x25] << 16);
  410. for(i = 0; i < 13; i++) {
  411. if(emodes & sisfb_ddcsmodes[i].mask) {
  412. if(monitor->hmin > sisfb_ddcsmodes[i].h) monitor->hmin = sisfb_ddcsmodes[i].h;
  413. if(monitor->hmax < sisfb_ddcsmodes[i].h) monitor->hmax = sisfb_ddcsmodes[i].h + 1;
  414. if(monitor->vmin > sisfb_ddcsmodes[i].v) monitor->vmin = sisfb_ddcsmodes[i].v;
  415. if(monitor->vmax < sisfb_ddcsmodes[i].v) monitor->vmax = sisfb_ddcsmodes[i].v;
  416. if(monitor->dclockmax < sisfb_ddcsmodes[i].d) monitor->dclockmax = sisfb_ddcsmodes[i].d;
  417. }
  418. }
  419. index = 0x26;
  420. for(i = 0; i < 8; i++) {
  421. xres = (buffer[index] + 31) * 8;
  422. switch(buffer[index + 1] & 0xc0) {
  423. case 0xc0: yres = (xres * 9) / 16; break;
  424. case 0x80: yres = (xres * 4) / 5; break;
  425. case 0x40: yres = (xres * 3) / 4; break;
  426. default: yres = xres; break;
  427. }
  428. refresh = (buffer[index + 1] & 0x3f) + 60;
  429. if((xres >= 640) && (yres >= 480)) {
  430. for(j = 0; j < 8; j++) {
  431. if((xres == sisfb_ddcfmodes[j].x) &&
  432. (yres == sisfb_ddcfmodes[j].y) &&
  433. (refresh == sisfb_ddcfmodes[j].v)) {
  434. if(monitor->hmin > sisfb_ddcfmodes[j].h) monitor->hmin = sisfb_ddcfmodes[j].h;
  435. if(monitor->hmax < sisfb_ddcfmodes[j].h) monitor->hmax = sisfb_ddcfmodes[j].h + 1;
  436. if(monitor->vmin > sisfb_ddcsmodes[j].v) monitor->vmin = sisfb_ddcsmodes[j].v;
  437. if(monitor->vmax < sisfb_ddcsmodes[j].v) monitor->vmax = sisfb_ddcsmodes[j].v;
  438. if(monitor->dclockmax < sisfb_ddcsmodes[j].d) monitor->dclockmax = sisfb_ddcsmodes[j].d;
  439. }
  440. }
  441. }
  442. index += 2;
  443. }
  444. if((monitor->hmin <= monitor->hmax) && (monitor->vmin <= monitor->vmax)) {
  445. monitor->datavalid = true;
  446. }
  447. }
  448. return monitor->datavalid;
  449. }
  450. static void __devinit
  451. sisfb_handle_ddc(struct sis_video_info *ivideo, struct sisfb_monitor *monitor, int crtno)
  452. {
  453. unsigned short temp, i, realcrtno = crtno;
  454. unsigned char buffer[256];
  455. monitor->datavalid = false;
  456. if(crtno) {
  457. if(ivideo->vbflags & CRT2_LCD) realcrtno = 1;
  458. else if(ivideo->vbflags & CRT2_VGA) realcrtno = 2;
  459. else return;
  460. }
  461. if((ivideo->sisfb_crt1off) && (!crtno))
  462. return;
  463. temp = SiS_HandleDDC(&ivideo->SiS_Pr, ivideo->vbflags, ivideo->sisvga_engine,
  464. realcrtno, 0, &buffer[0], ivideo->vbflags2);
  465. if((!temp) || (temp == 0xffff)) {
  466. printk(KERN_INFO "sisfb: CRT%d DDC probing failed\n", crtno + 1);
  467. return;
  468. } else {
  469. printk(KERN_INFO "sisfb: CRT%d DDC supported\n", crtno + 1);
  470. printk(KERN_INFO "sisfb: CRT%d DDC level: %s%s%s%s\n",
  471. crtno + 1,
  472. (temp & 0x1a) ? "" : "[none of the supported]",
  473. (temp & 0x02) ? "2 " : "",
  474. (temp & 0x08) ? "D&P" : "",
  475. (temp & 0x10) ? "FPDI-2" : "");
  476. if(temp & 0x02) {
  477. i = 3; /* Number of retrys */
  478. do {
  479. temp = SiS_HandleDDC(&ivideo->SiS_Pr, ivideo->vbflags, ivideo->sisvga_engine,
  480. realcrtno, 1, &buffer[0], ivideo->vbflags2);
  481. } while((temp) && i--);
  482. if(!temp) {
  483. if(sisfb_interpret_edid(monitor, &buffer[0])) {
  484. printk(KERN_INFO "sisfb: Monitor range H %d-%dKHz, V %d-%dHz, Max. dotclock %dMHz\n",
  485. monitor->hmin, monitor->hmax, monitor->vmin, monitor->vmax,
  486. monitor->dclockmax / 1000);
  487. } else {
  488. printk(KERN_INFO "sisfb: CRT%d DDC EDID corrupt\n", crtno + 1);
  489. }
  490. } else {
  491. printk(KERN_INFO "sisfb: CRT%d DDC reading failed\n", crtno + 1);
  492. }
  493. } else {
  494. printk(KERN_INFO "sisfb: VESA D&P and FPDI-2 not supported yet\n");
  495. }
  496. }
  497. }
  498. /* -------------- Mode validation --------------- */
  499. static bool
  500. sisfb_verify_rate(struct sis_video_info *ivideo, struct sisfb_monitor *monitor,
  501. int mode_idx, int rate_idx, int rate)
  502. {
  503. int htotal, vtotal;
  504. unsigned int dclock, hsync;
  505. if(!monitor->datavalid)
  506. return true;
  507. if(mode_idx < 0)
  508. return false;
  509. /* Skip for 320x200, 320x240, 640x400 */
  510. switch(sisbios_mode[mode_idx].mode_no[ivideo->mni]) {
  511. case 0x59:
  512. case 0x41:
  513. case 0x4f:
  514. case 0x50:
  515. case 0x56:
  516. case 0x53:
  517. case 0x2f:
  518. case 0x5d:
  519. case 0x5e:
  520. return true;
  521. #ifdef CONFIG_FB_SIS_315
  522. case 0x5a:
  523. case 0x5b:
  524. if(ivideo->sisvga_engine == SIS_315_VGA) return true;
  525. #endif
  526. }
  527. if(rate < (monitor->vmin - 1))
  528. return false;
  529. if(rate > (monitor->vmax + 1))
  530. return false;
  531. if(sisfb_gettotalfrommode(&ivideo->SiS_Pr,
  532. sisbios_mode[mode_idx].mode_no[ivideo->mni],
  533. &htotal, &vtotal, rate_idx)) {
  534. dclock = (htotal * vtotal * rate) / 1000;
  535. if(dclock > (monitor->dclockmax + 1000))
  536. return false;
  537. hsync = dclock / htotal;
  538. if(hsync < (monitor->hmin - 1))
  539. return false;
  540. if(hsync > (monitor->hmax + 1))
  541. return false;
  542. } else {
  543. return false;
  544. }
  545. return true;
  546. }
  547. static int
  548. sisfb_validate_mode(struct sis_video_info *ivideo, int myindex, u32 vbflags)
  549. {
  550. u16 xres=0, yres, myres;
  551. #ifdef CONFIG_FB_SIS_300
  552. if(ivideo->sisvga_engine == SIS_300_VGA) {
  553. if(!(sisbios_mode[myindex].chipset & MD_SIS300))
  554. return -1 ;
  555. }
  556. #endif
  557. #ifdef CONFIG_FB_SIS_315
  558. if(ivideo->sisvga_engine == SIS_315_VGA) {
  559. if(!(sisbios_mode[myindex].chipset & MD_SIS315))
  560. return -1;
  561. }
  562. #endif
  563. myres = sisbios_mode[myindex].yres;
  564. switch(vbflags & VB_DISPTYPE_DISP2) {
  565. case CRT2_LCD:
  566. xres = ivideo->lcdxres; yres = ivideo->lcdyres;
  567. if((ivideo->SiS_Pr.SiS_CustomT != CUT_PANEL848) &&
  568. (ivideo->SiS_Pr.SiS_CustomT != CUT_PANEL856)) {
  569. if(sisbios_mode[myindex].xres > xres)
  570. return -1;
  571. if(myres > yres)
  572. return -1;
  573. }
  574. if(ivideo->sisfb_fstn) {
  575. if(sisbios_mode[myindex].xres == 320) {
  576. if(myres == 240) {
  577. switch(sisbios_mode[myindex].mode_no[1]) {
  578. case 0x50: myindex = MODE_FSTN_8; break;
  579. case 0x56: myindex = MODE_FSTN_16; break;
  580. case 0x53: return -1;
  581. }
  582. }
  583. }
  584. }
  585. if(SiS_GetModeID_LCD(ivideo->sisvga_engine, vbflags, sisbios_mode[myindex].xres,
  586. sisbios_mode[myindex].yres, 0, ivideo->sisfb_fstn,
  587. ivideo->SiS_Pr.SiS_CustomT, xres, yres, ivideo->vbflags2) < 0x14) {
  588. return -1;
  589. }
  590. break;
  591. case CRT2_TV:
  592. if(SiS_GetModeID_TV(ivideo->sisvga_engine, vbflags, sisbios_mode[myindex].xres,
  593. sisbios_mode[myindex].yres, 0, ivideo->vbflags2) < 0x14) {
  594. return -1;
  595. }
  596. break;
  597. case CRT2_VGA:
  598. if(SiS_GetModeID_VGA2(ivideo->sisvga_engine, vbflags, sisbios_mode[myindex].xres,
  599. sisbios_mode[myindex].yres, 0, ivideo->vbflags2) < 0x14) {
  600. return -1;
  601. }
  602. break;
  603. }
  604. return myindex;
  605. }
  606. static u8
  607. sisfb_search_refresh_rate(struct sis_video_info *ivideo, unsigned int rate, int mode_idx)
  608. {
  609. int i = 0;
  610. u16 xres = sisbios_mode[mode_idx].xres;
  611. u16 yres = sisbios_mode[mode_idx].yres;
  612. ivideo->rate_idx = 0;
  613. while((sisfb_vrate[i].idx != 0) && (sisfb_vrate[i].xres <= xres)) {
  614. if((sisfb_vrate[i].xres == xres) && (sisfb_vrate[i].yres == yres)) {
  615. if(sisfb_vrate[i].refresh == rate) {
  616. ivideo->rate_idx = sisfb_vrate[i].idx;
  617. break;
  618. } else if(sisfb_vrate[i].refresh > rate) {
  619. if((sisfb_vrate[i].refresh - rate) <= 3) {
  620. DPRINTK("sisfb: Adjusting rate from %d up to %d\n",
  621. rate, sisfb_vrate[i].refresh);
  622. ivideo->rate_idx = sisfb_vrate[i].idx;
  623. ivideo->refresh_rate = sisfb_vrate[i].refresh;
  624. } else if((sisfb_vrate[i].idx != 1) &&
  625. ((rate - sisfb_vrate[i-1].refresh) <= 2)) {
  626. DPRINTK("sisfb: Adjusting rate from %d down to %d\n",
  627. rate, sisfb_vrate[i-1].refresh);
  628. ivideo->rate_idx = sisfb_vrate[i-1].idx;
  629. ivideo->refresh_rate = sisfb_vrate[i-1].refresh;
  630. }
  631. break;
  632. } else if((rate - sisfb_vrate[i].refresh) <= 2) {
  633. DPRINTK("sisfb: Adjusting rate from %d down to %d\n",
  634. rate, sisfb_vrate[i].refresh);
  635. ivideo->rate_idx = sisfb_vrate[i].idx;
  636. break;
  637. }
  638. }
  639. i++;
  640. }
  641. if(ivideo->rate_idx > 0) {
  642. return ivideo->rate_idx;
  643. } else {
  644. printk(KERN_INFO "sisfb: Unsupported rate %d for %dx%d\n",
  645. rate, xres, yres);
  646. return 0;
  647. }
  648. }
  649. static bool
  650. sisfb_bridgeisslave(struct sis_video_info *ivideo)
  651. {
  652. unsigned char P1_00;
  653. if(!(ivideo->vbflags2 & VB2_VIDEOBRIDGE))
  654. return false;
  655. P1_00 = SiS_GetReg(SISPART1, 0x00);
  656. if( ((ivideo->sisvga_engine == SIS_300_VGA) && (P1_00 & 0xa0) == 0x20) ||
  657. ((ivideo->sisvga_engine == SIS_315_VGA) && (P1_00 & 0x50) == 0x10) ) {
  658. return true;
  659. } else {
  660. return false;
  661. }
  662. }
  663. static bool
  664. sisfballowretracecrt1(struct sis_video_info *ivideo)
  665. {
  666. u8 temp;
  667. temp = SiS_GetReg(SISCR, 0x17);
  668. if(!(temp & 0x80))
  669. return false;
  670. temp = SiS_GetReg(SISSR, 0x1f);
  671. if(temp & 0xc0)
  672. return false;
  673. return true;
  674. }
  675. static bool
  676. sisfbcheckvretracecrt1(struct sis_video_info *ivideo)
  677. {
  678. if(!sisfballowretracecrt1(ivideo))
  679. return false;
  680. if (SiS_GetRegByte(SISINPSTAT) & 0x08)
  681. return true;
  682. else
  683. return false;
  684. }
  685. static void
  686. sisfbwaitretracecrt1(struct sis_video_info *ivideo)
  687. {
  688. int watchdog;
  689. if(!sisfballowretracecrt1(ivideo))
  690. return;
  691. watchdog = 65536;
  692. while ((!(SiS_GetRegByte(SISINPSTAT) & 0x08)) && --watchdog);
  693. watchdog = 65536;
  694. while ((SiS_GetRegByte(SISINPSTAT) & 0x08) && --watchdog);
  695. }
  696. static bool
  697. sisfbcheckvretracecrt2(struct sis_video_info *ivideo)
  698. {
  699. unsigned char temp, reg;
  700. switch(ivideo->sisvga_engine) {
  701. case SIS_300_VGA: reg = 0x25; break;
  702. case SIS_315_VGA: reg = 0x30; break;
  703. default: return false;
  704. }
  705. temp = SiS_GetReg(SISPART1, reg);
  706. if(temp & 0x02)
  707. return true;
  708. else
  709. return false;
  710. }
  711. static bool
  712. sisfb_CheckVBRetrace(struct sis_video_info *ivideo)
  713. {
  714. if(ivideo->currentvbflags & VB_DISPTYPE_DISP2) {
  715. if(!sisfb_bridgeisslave(ivideo)) {
  716. return sisfbcheckvretracecrt2(ivideo);
  717. }
  718. }
  719. return sisfbcheckvretracecrt1(ivideo);
  720. }
  721. static u32
  722. sisfb_setupvbblankflags(struct sis_video_info *ivideo, u32 *vcount, u32 *hcount)
  723. {
  724. u8 idx, reg1, reg2, reg3, reg4;
  725. u32 ret = 0;
  726. (*vcount) = (*hcount) = 0;
  727. if((ivideo->currentvbflags & VB_DISPTYPE_DISP2) && (!(sisfb_bridgeisslave(ivideo)))) {
  728. ret |= (FB_VBLANK_HAVE_VSYNC |
  729. FB_VBLANK_HAVE_HBLANK |
  730. FB_VBLANK_HAVE_VBLANK |
  731. FB_VBLANK_HAVE_VCOUNT |
  732. FB_VBLANK_HAVE_HCOUNT);
  733. switch(ivideo->sisvga_engine) {
  734. case SIS_300_VGA: idx = 0x25; break;
  735. default:
  736. case SIS_315_VGA: idx = 0x30; break;
  737. }
  738. reg1 = SiS_GetReg(SISPART1, (idx+0)); /* 30 */
  739. reg2 = SiS_GetReg(SISPART1, (idx+1)); /* 31 */
  740. reg3 = SiS_GetReg(SISPART1, (idx+2)); /* 32 */
  741. reg4 = SiS_GetReg(SISPART1, (idx+3)); /* 33 */
  742. if(reg1 & 0x01) ret |= FB_VBLANK_VBLANKING;
  743. if(reg1 & 0x02) ret |= FB_VBLANK_VSYNCING;
  744. if(reg4 & 0x80) ret |= FB_VBLANK_HBLANKING;
  745. (*vcount) = reg3 | ((reg4 & 0x70) << 4);
  746. (*hcount) = reg2 | ((reg4 & 0x0f) << 8);
  747. } else if(sisfballowretracecrt1(ivideo)) {
  748. ret |= (FB_VBLANK_HAVE_VSYNC |
  749. FB_VBLANK_HAVE_VBLANK |
  750. FB_VBLANK_HAVE_VCOUNT |
  751. FB_VBLANK_HAVE_HCOUNT);
  752. reg1 = SiS_GetRegByte(SISINPSTAT);
  753. if(reg1 & 0x08) ret |= FB_VBLANK_VSYNCING;
  754. if(reg1 & 0x01) ret |= FB_VBLANK_VBLANKING;
  755. reg1 = SiS_GetReg(SISCR, 0x20);
  756. reg1 = SiS_GetReg(SISCR, 0x1b);
  757. reg2 = SiS_GetReg(SISCR, 0x1c);
  758. reg3 = SiS_GetReg(SISCR, 0x1d);
  759. (*vcount) = reg2 | ((reg3 & 0x07) << 8);
  760. (*hcount) = (reg1 | ((reg3 & 0x10) << 4)) << 3;
  761. }
  762. return ret;
  763. }
  764. static int
  765. sisfb_myblank(struct sis_video_info *ivideo, int blank)
  766. {
  767. u8 sr01, sr11, sr1f, cr63=0, p2_0, p1_13;
  768. bool backlight = true;
  769. switch(blank) {
  770. case FB_BLANK_UNBLANK: /* on */
  771. sr01 = 0x00;
  772. sr11 = 0x00;
  773. sr1f = 0x00;
  774. cr63 = 0x00;
  775. p2_0 = 0x20;
  776. p1_13 = 0x00;
  777. backlight = true;
  778. break;
  779. case FB_BLANK_NORMAL: /* blank */
  780. sr01 = 0x20;
  781. sr11 = 0x00;
  782. sr1f = 0x00;
  783. cr63 = 0x00;
  784. p2_0 = 0x20;
  785. p1_13 = 0x00;
  786. backlight = true;
  787. break;
  788. case FB_BLANK_VSYNC_SUSPEND: /* no vsync */
  789. sr01 = 0x20;
  790. sr11 = 0x08;
  791. sr1f = 0x80;
  792. cr63 = 0x40;
  793. p2_0 = 0x40;
  794. p1_13 = 0x80;
  795. backlight = false;
  796. break;
  797. case FB_BLANK_HSYNC_SUSPEND: /* no hsync */
  798. sr01 = 0x20;
  799. sr11 = 0x08;
  800. sr1f = 0x40;
  801. cr63 = 0x40;
  802. p2_0 = 0x80;
  803. p1_13 = 0x40;
  804. backlight = false;
  805. break;
  806. case FB_BLANK_POWERDOWN: /* off */
  807. sr01 = 0x20;
  808. sr11 = 0x08;
  809. sr1f = 0xc0;
  810. cr63 = 0x40;
  811. p2_0 = 0xc0;
  812. p1_13 = 0xc0;
  813. backlight = false;
  814. break;
  815. default:
  816. return 1;
  817. }
  818. if(ivideo->currentvbflags & VB_DISPTYPE_CRT1) {
  819. if( (!ivideo->sisfb_thismonitor.datavalid) ||
  820. ((ivideo->sisfb_thismonitor.datavalid) &&
  821. (ivideo->sisfb_thismonitor.feature & 0xe0))) {
  822. if(ivideo->sisvga_engine == SIS_315_VGA) {
  823. SiS_SetRegANDOR(SISCR, ivideo->SiS_Pr.SiS_MyCR63, 0xbf, cr63);
  824. }
  825. if(!(sisfb_bridgeisslave(ivideo))) {
  826. SiS_SetRegANDOR(SISSR, 0x01, ~0x20, sr01);
  827. SiS_SetRegANDOR(SISSR, 0x1f, 0x3f, sr1f);
  828. }
  829. }
  830. }
  831. if(ivideo->currentvbflags & CRT2_LCD) {
  832. if(ivideo->vbflags2 & VB2_SISLVDSBRIDGE) {
  833. if(backlight) {
  834. SiS_SiS30xBLOn(&ivideo->SiS_Pr);
  835. } else {
  836. SiS_SiS30xBLOff(&ivideo->SiS_Pr);
  837. }
  838. } else if(ivideo->sisvga_engine == SIS_315_VGA) {
  839. #ifdef CONFIG_FB_SIS_315
  840. if(ivideo->vbflags2 & VB2_CHRONTEL) {
  841. if(backlight) {
  842. SiS_Chrontel701xBLOn(&ivideo->SiS_Pr);
  843. } else {
  844. SiS_Chrontel701xBLOff(&ivideo->SiS_Pr);
  845. }
  846. }
  847. #endif
  848. }
  849. if(((ivideo->sisvga_engine == SIS_300_VGA) &&
  850. (ivideo->vbflags2 & (VB2_301|VB2_30xBDH|VB2_LVDS))) ||
  851. ((ivideo->sisvga_engine == SIS_315_VGA) &&
  852. ((ivideo->vbflags2 & (VB2_LVDS | VB2_CHRONTEL)) == VB2_LVDS))) {
  853. SiS_SetRegANDOR(SISSR, 0x11, ~0x0c, sr11);
  854. }
  855. if(ivideo->sisvga_engine == SIS_300_VGA) {
  856. if((ivideo->vbflags2 & VB2_30xB) &&
  857. (!(ivideo->vbflags2 & VB2_30xBDH))) {
  858. SiS_SetRegANDOR(SISPART1, 0x13, 0x3f, p1_13);
  859. }
  860. } else if(ivideo->sisvga_engine == SIS_315_VGA) {
  861. if((ivideo->vbflags2 & VB2_30xB) &&
  862. (!(ivideo->vbflags2 & VB2_30xBDH))) {
  863. SiS_SetRegANDOR(SISPART2, 0x00, 0x1f, p2_0);
  864. }
  865. }
  866. } else if(ivideo->currentvbflags & CRT2_VGA) {
  867. if(ivideo->vbflags2 & VB2_30xB) {
  868. SiS_SetRegANDOR(SISPART2, 0x00, 0x1f, p2_0);
  869. }
  870. }
  871. return 0;
  872. }
  873. /* ------------- Callbacks from init.c/init301.c -------------- */
  874. #ifdef CONFIG_FB_SIS_300
  875. unsigned int
  876. sisfb_read_nbridge_pci_dword(struct SiS_Private *SiS_Pr, int reg)
  877. {
  878. struct sis_video_info *ivideo = (struct sis_video_info *)SiS_Pr->ivideo;
  879. u32 val = 0;
  880. pci_read_config_dword(ivideo->nbridge, reg, &val);
  881. return (unsigned int)val;
  882. }
  883. void
  884. sisfb_write_nbridge_pci_dword(struct SiS_Private *SiS_Pr, int reg, unsigned int val)
  885. {
  886. struct sis_video_info *ivideo = (struct sis_video_info *)SiS_Pr->ivideo;
  887. pci_write_config_dword(ivideo->nbridge, reg, (u32)val);
  888. }
  889. unsigned int
  890. sisfb_read_lpc_pci_dword(struct SiS_Private *SiS_Pr, int reg)
  891. {
  892. struct sis_video_info *ivideo = (struct sis_video_info *)SiS_Pr->ivideo;
  893. u32 val = 0;
  894. if(!ivideo->lpcdev) return 0;
  895. pci_read_config_dword(ivideo->lpcdev, reg, &val);
  896. return (unsigned int)val;
  897. }
  898. #endif
  899. #ifdef CONFIG_FB_SIS_315
  900. void
  901. sisfb_write_nbridge_pci_byte(struct SiS_Private *SiS_Pr, int reg, unsigned char val)
  902. {
  903. struct sis_video_info *ivideo = (struct sis_video_info *)SiS_Pr->ivideo;
  904. pci_write_config_byte(ivideo->nbridge, reg, (u8)val);
  905. }
  906. unsigned int
  907. sisfb_read_mio_pci_word(struct SiS_Private *SiS_Pr, int reg)
  908. {
  909. struct sis_video_info *ivideo = (struct sis_video_info *)SiS_Pr->ivideo;
  910. u16 val = 0;
  911. if(!ivideo->lpcdev) return 0;
  912. pci_read_config_word(ivideo->lpcdev, reg, &val);
  913. return (unsigned int)val;
  914. }
  915. #endif
  916. /* ----------- FBDev related routines for all series ----------- */
  917. static int
  918. sisfb_get_cmap_len(const struct fb_var_screeninfo *var)
  919. {
  920. return (var->bits_per_pixel == 8) ? 256 : 16;
  921. }
  922. static void
  923. sisfb_set_vparms(struct sis_video_info *ivideo)
  924. {
  925. switch(ivideo->video_bpp) {
  926. case 8:
  927. ivideo->DstColor = 0x0000;
  928. ivideo->SiS310_AccelDepth = 0x00000000;
  929. ivideo->video_cmap_len = 256;
  930. break;
  931. case 16:
  932. ivideo->DstColor = 0x8000;
  933. ivideo->SiS310_AccelDepth = 0x00010000;
  934. ivideo->video_cmap_len = 16;
  935. break;
  936. case 32:
  937. ivideo->DstColor = 0xC000;
  938. ivideo->SiS310_AccelDepth = 0x00020000;
  939. ivideo->video_cmap_len = 16;
  940. break;
  941. default:
  942. ivideo->video_cmap_len = 16;
  943. printk(KERN_ERR "sisfb: Unsupported depth %d", ivideo->video_bpp);
  944. ivideo->accel = 0;
  945. }
  946. }
  947. static int
  948. sisfb_calc_maxyres(struct sis_video_info *ivideo, struct fb_var_screeninfo *var)
  949. {
  950. int maxyres = ivideo->sisfb_mem / (var->xres_virtual * (var->bits_per_pixel >> 3));
  951. if(maxyres > 32767) maxyres = 32767;
  952. return maxyres;
  953. }
  954. static void
  955. sisfb_calc_pitch(struct sis_video_info *ivideo, struct fb_var_screeninfo *var)
  956. {
  957. ivideo->video_linelength = var->xres_virtual * (var->bits_per_pixel >> 3);
  958. ivideo->scrnpitchCRT1 = ivideo->video_linelength;
  959. if(!(ivideo->currentvbflags & CRT1_LCDA)) {
  960. if((var->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) {
  961. ivideo->scrnpitchCRT1 <<= 1;
  962. }
  963. }
  964. }
  965. static void
  966. sisfb_set_pitch(struct sis_video_info *ivideo)
  967. {
  968. bool isslavemode = false;
  969. unsigned short HDisplay1 = ivideo->scrnpitchCRT1 >> 3;
  970. unsigned short HDisplay2 = ivideo->video_linelength >> 3;
  971. if(sisfb_bridgeisslave(ivideo)) isslavemode = true;
  972. /* We need to set pitch for CRT1 if bridge is in slave mode, too */
  973. if((ivideo->currentvbflags & VB_DISPTYPE_DISP1) || (isslavemode)) {
  974. SiS_SetReg(SISCR, 0x13, (HDisplay1 & 0xFF));
  975. SiS_SetRegANDOR(SISSR, 0x0E, 0xF0, (HDisplay1 >> 8));
  976. }
  977. /* We must not set the pitch for CRT2 if bridge is in slave mode */
  978. if((ivideo->currentvbflags & VB_DISPTYPE_DISP2) && (!isslavemode)) {
  979. SiS_SetRegOR(SISPART1, ivideo->CRT2_write_enable, 0x01);
  980. SiS_SetReg(SISPART1, 0x07, (HDisplay2 & 0xFF));
  981. SiS_SetRegANDOR(SISPART1, 0x09, 0xF0, (HDisplay2 >> 8));
  982. }
  983. }
  984. static void
  985. sisfb_bpp_to_var(struct sis_video_info *ivideo, struct fb_var_screeninfo *var)
  986. {
  987. ivideo->video_cmap_len = sisfb_get_cmap_len(var);
  988. switch(var->bits_per_pixel) {
  989. case 8:
  990. var->red.offset = var->green.offset = var->blue.offset = 0;
  991. var->red.length = var->green.length = var->blue.length = 8;
  992. break;
  993. case 16:
  994. var->red.offset = 11;
  995. var->red.length = 5;
  996. var->green.offset = 5;
  997. var->green.length = 6;
  998. var->blue.offset = 0;
  999. var->blue.length = 5;
  1000. var->transp.offset = 0;
  1001. var->transp.length = 0;
  1002. break;
  1003. case 32:
  1004. var->red.offset = 16;
  1005. var->red.length = 8;
  1006. var->green.offset = 8;
  1007. var->green.length = 8;
  1008. var->blue.offset = 0;
  1009. var->blue.length = 8;
  1010. var->transp.offset = 24;
  1011. var->transp.length = 8;
  1012. break;
  1013. }
  1014. }
  1015. static int
  1016. sisfb_set_mode(struct sis_video_info *ivideo, int clrscrn)
  1017. {
  1018. unsigned short modeno = ivideo->mode_no;
  1019. /* >=2.6.12's fbcon clears the screen anyway */
  1020. modeno |= 0x80;
  1021. SiS_SetReg(SISSR, IND_SIS_PASSWORD, SIS_PASSWORD);
  1022. sisfb_pre_setmode(ivideo);
  1023. if(!SiSSetMode(&ivideo->SiS_Pr, modeno)) {
  1024. printk(KERN_ERR "sisfb: Setting mode[0x%x] failed\n", ivideo->mode_no);
  1025. return -EINVAL;
  1026. }
  1027. SiS_SetReg(SISSR, IND_SIS_PASSWORD, SIS_PASSWORD);
  1028. sisfb_post_setmode(ivideo);
  1029. return 0;
  1030. }
  1031. static int
  1032. sisfb_do_set_var(struct fb_var_screeninfo *var, int isactive, struct fb_info *info)
  1033. {
  1034. struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
  1035. unsigned int htotal = 0, vtotal = 0;
  1036. unsigned int drate = 0, hrate = 0;
  1037. int found_mode = 0, ret;
  1038. int old_mode;
  1039. u32 pixclock;
  1040. htotal = var->left_margin + var->xres + var->right_margin + var->hsync_len;
  1041. vtotal = var->upper_margin + var->lower_margin + var->vsync_len;
  1042. pixclock = var->pixclock;
  1043. if((var->vmode & FB_VMODE_MASK) == FB_VMODE_NONINTERLACED) {
  1044. vtotal += var->yres;
  1045. vtotal <<= 1;
  1046. } else if((var->vmode & FB_VMODE_MASK) == FB_VMODE_DOUBLE) {
  1047. vtotal += var->yres;
  1048. vtotal <<= 2;
  1049. } else if((var->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) {
  1050. vtotal += var->yres;
  1051. vtotal <<= 1;
  1052. } else vtotal += var->yres;
  1053. if(!(htotal) || !(vtotal)) {
  1054. DPRINTK("sisfb: Invalid 'var' information\n");
  1055. return -EINVAL;
  1056. }
  1057. if(pixclock && htotal && vtotal) {
  1058. drate = 1000000000 / pixclock;
  1059. hrate = (drate * 1000) / htotal;
  1060. ivideo->refresh_rate = (unsigned int) (hrate * 2 / vtotal);
  1061. } else {
  1062. ivideo->refresh_rate = 60;
  1063. }
  1064. old_mode = ivideo->sisfb_mode_idx;
  1065. ivideo->sisfb_mode_idx = 0;
  1066. while( (sisbios_mode[ivideo->sisfb_mode_idx].mode_no[0] != 0) &&
  1067. (sisbios_mode[ivideo->sisfb_mode_idx].xres <= var->xres) ) {
  1068. if( (sisbios_mode[ivideo->sisfb_mode_idx].xres == var->xres) &&
  1069. (sisbios_mode[ivideo->sisfb_mode_idx].yres == var->yres) &&
  1070. (sisbios_mode[ivideo->sisfb_mode_idx].bpp == var->bits_per_pixel)) {
  1071. ivideo->mode_no = sisbios_mode[ivideo->sisfb_mode_idx].mode_no[ivideo->mni];
  1072. found_mode = 1;
  1073. break;
  1074. }
  1075. ivideo->sisfb_mode_idx++;
  1076. }
  1077. if(found_mode) {
  1078. ivideo->sisfb_mode_idx = sisfb_validate_mode(ivideo,
  1079. ivideo->sisfb_mode_idx, ivideo->currentvbflags);
  1080. } else {
  1081. ivideo->sisfb_mode_idx = -1;
  1082. }
  1083. if(ivideo->sisfb_mode_idx < 0) {
  1084. printk(KERN_ERR "sisfb: Mode %dx%dx%d not supported\n", var->xres,
  1085. var->yres, var->bits_per_pixel);
  1086. ivideo->sisfb_mode_idx = old_mode;
  1087. return -EINVAL;
  1088. }
  1089. ivideo->mode_no = sisbios_mode[ivideo->sisfb_mode_idx].mode_no[ivideo->mni];
  1090. if(sisfb_search_refresh_rate(ivideo, ivideo->refresh_rate, ivideo->sisfb_mode_idx) == 0) {
  1091. ivideo->rate_idx = sisbios_mode[ivideo->sisfb_mode_idx].rate_idx;
  1092. ivideo->refresh_rate = 60;
  1093. }
  1094. if(isactive) {
  1095. /* If acceleration to be used? Need to know
  1096. * before pre/post_set_mode()
  1097. */
  1098. ivideo->accel = 0;
  1099. #if defined(FBINFO_HWACCEL_DISABLED) && defined(FBINFO_HWACCEL_XPAN)
  1100. #ifdef STUPID_ACCELF_TEXT_SHIT
  1101. if(var->accel_flags & FB_ACCELF_TEXT) {
  1102. info->flags &= ~FBINFO_HWACCEL_DISABLED;
  1103. } else {
  1104. info->flags |= FBINFO_HWACCEL_DISABLED;
  1105. }
  1106. #endif
  1107. if(!(info->flags & FBINFO_HWACCEL_DISABLED)) ivideo->accel = -1;
  1108. #else
  1109. if(var->accel_flags & FB_ACCELF_TEXT) ivideo->accel = -1;
  1110. #endif
  1111. if((ret = sisfb_set_mode(ivideo, 1))) {
  1112. return ret;
  1113. }
  1114. ivideo->video_bpp = sisbios_mode[ivideo->sisfb_mode_idx].bpp;
  1115. ivideo->video_width = sisbios_mode[ivideo->sisfb_mode_idx].xres;
  1116. ivideo->video_height = sisbios_mode[ivideo->sisfb_mode_idx].yres;
  1117. sisfb_calc_pitch(ivideo, var);
  1118. sisfb_set_pitch(ivideo);
  1119. sisfb_set_vparms(ivideo);
  1120. ivideo->current_width = ivideo->video_width;
  1121. ivideo->current_height = ivideo->video_height;
  1122. ivideo->current_bpp = ivideo->video_bpp;
  1123. ivideo->current_htotal = htotal;
  1124. ivideo->current_vtotal = vtotal;
  1125. ivideo->current_linelength = ivideo->video_linelength;
  1126. ivideo->current_pixclock = var->pixclock;
  1127. ivideo->current_refresh_rate = ivideo->refresh_rate;
  1128. ivideo->sisfb_lastrates[ivideo->mode_no] = ivideo->refresh_rate;
  1129. }
  1130. return 0;
  1131. }
  1132. static void
  1133. sisfb_set_base_CRT1(struct sis_video_info *ivideo, unsigned int base)
  1134. {
  1135. SiS_SetReg(SISSR, IND_SIS_PASSWORD, SIS_PASSWORD);
  1136. SiS_SetReg(SISCR, 0x0D, base & 0xFF);
  1137. SiS_SetReg(SISCR, 0x0C, (base >> 8) & 0xFF);
  1138. SiS_SetReg(SISSR, 0x0D, (base >> 16) & 0xFF);
  1139. if(ivideo->sisvga_engine == SIS_315_VGA) {
  1140. SiS_SetRegANDOR(SISSR, 0x37, 0xFE, (base >> 24) & 0x01);
  1141. }
  1142. }
  1143. static void
  1144. sisfb_set_base_CRT2(struct sis_video_info *ivideo, unsigned int base)
  1145. {
  1146. if(ivideo->currentvbflags & VB_DISPTYPE_DISP2) {
  1147. SiS_SetRegOR(SISPART1, ivideo->CRT2_write_enable, 0x01);
  1148. SiS_SetReg(SISPART1, 0x06, (base & 0xFF));
  1149. SiS_SetReg(SISPART1, 0x05, ((base >> 8) & 0xFF));
  1150. SiS_SetReg(SISPART1, 0x04, ((base >> 16) & 0xFF));
  1151. if(ivideo->sisvga_engine == SIS_315_VGA) {
  1152. SiS_SetRegANDOR(SISPART1, 0x02, 0x7F, ((base >> 24) & 0x01) << 7);
  1153. }
  1154. }
  1155. }
  1156. static int
  1157. sisfb_pan_var(struct sis_video_info *ivideo, struct fb_var_screeninfo *var)
  1158. {
  1159. if(var->xoffset > (var->xres_virtual - var->xres)) {
  1160. return -EINVAL;
  1161. }
  1162. if(var->yoffset > (var->yres_virtual - var->yres)) {
  1163. return -EINVAL;
  1164. }
  1165. ivideo->current_base = (var->yoffset * var->xres_virtual) + var->xoffset;
  1166. /* calculate base bpp dep. */
  1167. switch(var->bits_per_pixel) {
  1168. case 32:
  1169. break;
  1170. case 16:
  1171. ivideo->current_base >>= 1;
  1172. break;
  1173. case 8:
  1174. default:
  1175. ivideo->current_base >>= 2;
  1176. break;
  1177. }
  1178. ivideo->current_base += (ivideo->video_offset >> 2);
  1179. sisfb_set_base_CRT1(ivideo, ivideo->current_base);
  1180. sisfb_set_base_CRT2(ivideo, ivideo->current_base);
  1181. return 0;
  1182. }
  1183. static int
  1184. sisfb_open(struct fb_info *info, int user)
  1185. {
  1186. return 0;
  1187. }
  1188. static int
  1189. sisfb_release(struct fb_info *info, int user)
  1190. {
  1191. return 0;
  1192. }
  1193. static int
  1194. sisfb_setcolreg(unsigned regno, unsigned red, unsigned green, unsigned blue,
  1195. unsigned transp, struct fb_info *info)
  1196. {
  1197. struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
  1198. if(regno >= sisfb_get_cmap_len(&info->var))
  1199. return 1;
  1200. switch(info->var.bits_per_pixel) {
  1201. case 8:
  1202. SiS_SetRegByte(SISDACA, regno);
  1203. SiS_SetRegByte(SISDACD, (red >> 10));
  1204. SiS_SetRegByte(SISDACD, (green >> 10));
  1205. SiS_SetRegByte(SISDACD, (blue >> 10));
  1206. if(ivideo->currentvbflags & VB_DISPTYPE_DISP2) {
  1207. SiS_SetRegByte(SISDAC2A, regno);
  1208. SiS_SetRegByte(SISDAC2D, (red >> 8));
  1209. SiS_SetRegByte(SISDAC2D, (green >> 8));
  1210. SiS_SetRegByte(SISDAC2D, (blue >> 8));
  1211. }
  1212. break;
  1213. case 16:
  1214. if (regno >= 16)
  1215. break;
  1216. ((u32 *)(info->pseudo_palette))[regno] =
  1217. (red & 0xf800) |
  1218. ((green & 0xfc00) >> 5) |
  1219. ((blue & 0xf800) >> 11);
  1220. break;
  1221. case 32:
  1222. if (regno >= 16)
  1223. break;
  1224. red >>= 8;
  1225. green >>= 8;
  1226. blue >>= 8;
  1227. ((u32 *)(info->pseudo_palette))[regno] =
  1228. (red << 16) | (green << 8) | (blue);
  1229. break;
  1230. }
  1231. return 0;
  1232. }
  1233. static int
  1234. sisfb_set_par(struct fb_info *info)
  1235. {
  1236. int err;
  1237. if((err = sisfb_do_set_var(&info->var, 1, info)))
  1238. return err;
  1239. sisfb_get_fix(&info->fix, -1, info);
  1240. return 0;
  1241. }
  1242. static int
  1243. sisfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
  1244. {
  1245. struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
  1246. unsigned int htotal = 0, vtotal = 0, myrateindex = 0;
  1247. unsigned int drate = 0, hrate = 0, maxyres;
  1248. int found_mode = 0;
  1249. int refresh_rate, search_idx, tidx;
  1250. bool recalc_clock = false;
  1251. u32 pixclock;
  1252. htotal = var->left_margin + var->xres + var->right_margin + var->hsync_len;
  1253. vtotal = var->upper_margin + var->lower_margin + var->vsync_len;
  1254. pixclock = var->pixclock;
  1255. if((var->vmode & FB_VMODE_MASK) == FB_VMODE_NONINTERLACED) {
  1256. vtotal += var->yres;
  1257. vtotal <<= 1;
  1258. } else if((var->vmode & FB_VMODE_MASK) == FB_VMODE_DOUBLE) {
  1259. vtotal += var->yres;
  1260. vtotal <<= 2;
  1261. } else if((var->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) {
  1262. vtotal += var->yres;
  1263. vtotal <<= 1;
  1264. } else
  1265. vtotal += var->yres;
  1266. if(!(htotal) || !(vtotal)) {
  1267. SISFAIL("sisfb: no valid timing data");
  1268. }
  1269. search_idx = 0;
  1270. while( (sisbios_mode[search_idx].mode_no[0] != 0) &&
  1271. (sisbios_mode[search_idx].xres <= var->xres) ) {
  1272. if( (sisbios_mode[search_idx].xres == var->xres) &&
  1273. (sisbios_mode[search_idx].yres == var->yres) &&
  1274. (sisbios_mode[search_idx].bpp == var->bits_per_pixel)) {
  1275. if((tidx = sisfb_validate_mode(ivideo, search_idx,
  1276. ivideo->currentvbflags)) > 0) {
  1277. found_mode = 1;
  1278. search_idx = tidx;
  1279. break;
  1280. }
  1281. }
  1282. search_idx++;
  1283. }
  1284. if(!found_mode) {
  1285. search_idx = 0;
  1286. while(sisbios_mode[search_idx].mode_no[0] != 0) {
  1287. if( (var->xres <= sisbios_mode[search_idx].xres) &&
  1288. (var->yres <= sisbios_mode[search_idx].yres) &&
  1289. (var->bits_per_pixel == sisbios_mode[search_idx].bpp) ) {
  1290. if((tidx = sisfb_validate_mode(ivideo,search_idx,
  1291. ivideo->currentvbflags)) > 0) {
  1292. found_mode = 1;
  1293. search_idx = tidx;
  1294. break;
  1295. }
  1296. }
  1297. search_idx++;
  1298. }
  1299. if(found_mode) {
  1300. printk(KERN_DEBUG
  1301. "sisfb: Adapted from %dx%dx%d to %dx%dx%d\n",
  1302. var->xres, var->yres, var->bits_per_pixel,
  1303. sisbios_mode[search_idx].xres,
  1304. sisbios_mode[search_idx].yres,
  1305. var->bits_per_pixel);
  1306. var->xres = sisbios_mode[search_idx].xres;
  1307. var->yres = sisbios_mode[search_idx].yres;
  1308. } else {
  1309. printk(KERN_ERR
  1310. "sisfb: Failed to find supported mode near %dx%dx%d\n",
  1311. var->xres, var->yres, var->bits_per_pixel);
  1312. return -EINVAL;
  1313. }
  1314. }
  1315. if( ((ivideo->vbflags2 & VB2_LVDS) ||
  1316. ((ivideo->vbflags2 & VB2_30xBDH) && (ivideo->currentvbflags & CRT2_LCD))) &&
  1317. (var->bits_per_pixel == 8) ) {
  1318. /* Slave modes on LVDS and 301B-DH */
  1319. refresh_rate = 60;
  1320. recalc_clock = true;
  1321. } else if( (ivideo->current_htotal == htotal) &&
  1322. (ivideo->current_vtotal == vtotal) &&
  1323. (ivideo->current_pixclock == pixclock) ) {
  1324. /* x=x & y=y & c=c -> assume depth change */
  1325. drate = 1000000000 / pixclock;
  1326. hrate = (drate * 1000) / htotal;
  1327. refresh_rate = (unsigned int) (hrate * 2 / vtotal);
  1328. } else if( ( (ivideo->current_htotal != htotal) ||
  1329. (ivideo->current_vtotal != vtotal) ) &&
  1330. (ivideo->current_pixclock == var->pixclock) ) {
  1331. /* x!=x | y!=y & c=c -> invalid pixclock */
  1332. if(ivideo->sisfb_lastrates[sisbios_mode[search_idx].mode_no[ivideo->mni]]) {
  1333. refresh_rate =
  1334. ivideo->sisfb_lastrates[sisbios_mode[search_idx].mode_no[ivideo->mni]];
  1335. } else if(ivideo->sisfb_parm_rate != -1) {
  1336. /* Sic, sisfb_parm_rate - want to know originally desired rate here */
  1337. refresh_rate = ivideo->sisfb_parm_rate;
  1338. } else {
  1339. refresh_rate = 60;
  1340. }
  1341. recalc_clock = true;
  1342. } else if((pixclock) && (htotal) && (vtotal)) {
  1343. drate = 1000000000 / pixclock;
  1344. hrate = (drate * 1000) / htotal;
  1345. refresh_rate = (unsigned int) (hrate * 2 / vtotal);
  1346. } else if(ivideo->current_refresh_rate) {
  1347. refresh_rate = ivideo->current_refresh_rate;
  1348. recalc_clock = true;
  1349. } else {
  1350. refresh_rate = 60;
  1351. recalc_clock = true;
  1352. }
  1353. myrateindex = sisfb_search_refresh_rate(ivideo, refresh_rate, search_idx);
  1354. /* Eventually recalculate timing and clock */
  1355. if(recalc_clock) {
  1356. if(!myrateindex) myrateindex = sisbios_mode[search_idx].rate_idx;
  1357. var->pixclock = (u32) (1000000000 / sisfb_mode_rate_to_dclock(&ivideo->SiS_Pr,
  1358. sisbios_mode[search_idx].mode_no[ivideo->mni],
  1359. myrateindex));
  1360. sisfb_mode_rate_to_ddata(&ivideo->SiS_Pr,
  1361. sisbios_mode[search_idx].mode_no[ivideo->mni],
  1362. myrateindex, var);
  1363. if((var->vmode & FB_VMODE_MASK) == FB_VMODE_DOUBLE) {
  1364. var->pixclock <<= 1;
  1365. }
  1366. }
  1367. if(ivideo->sisfb_thismonitor.datavalid) {
  1368. if(!sisfb_verify_rate(ivideo, &ivideo->sisfb_thismonitor, search_idx,
  1369. myrateindex, refresh_rate)) {
  1370. printk(KERN_INFO
  1371. "sisfb: WARNING: Refresh rate exceeds monitor specs!\n");
  1372. }
  1373. }
  1374. /* Adapt RGB settings */
  1375. sisfb_bpp_to_var(ivideo, var);
  1376. /* Sanity check for offsets */
  1377. if(var->xoffset < 0) var->xoffset = 0;
  1378. if(var->yoffset < 0) var->yoffset = 0;
  1379. if(var->xres > var->xres_virtual)
  1380. var->xres_virtual = var->xres;
  1381. if(ivideo->sisfb_ypan) {
  1382. maxyres = sisfb_calc_maxyres(ivideo, var);
  1383. if(ivideo->sisfb_max) {
  1384. var->yres_virtual = maxyres;
  1385. } else {
  1386. if(var->yres_virtual > maxyres) {
  1387. var->yres_virtual = maxyres;
  1388. }
  1389. }
  1390. if(var->yres_virtual <= var->yres) {
  1391. var->yres_virtual = var->yres;
  1392. }
  1393. } else {
  1394. if(var->yres != var->yres_virtual) {
  1395. var->yres_virtual = var->yres;
  1396. }
  1397. var->xoffset = 0;
  1398. var->yoffset = 0;
  1399. }
  1400. /* Truncate offsets to maximum if too high */
  1401. if(var->xoffset > var->xres_virtual - var->xres) {
  1402. var->xoffset = var->xres_virtual - var->xres - 1;
  1403. }
  1404. if(var->yoffset > var->yres_virtual - var->yres) {
  1405. var->yoffset = var->yres_virtual - var->yres - 1;
  1406. }
  1407. /* Set everything else to 0 */
  1408. var->red.msb_right =
  1409. var->green.msb_right =
  1410. var->blue.msb_right =
  1411. var->transp.offset =
  1412. var->transp.length =
  1413. var->transp.msb_right = 0;
  1414. return 0;
  1415. }
  1416. static int
  1417. sisfb_pan_display(struct fb_var_screeninfo *var, struct fb_info* info)
  1418. {
  1419. struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
  1420. int err;
  1421. if(var->xoffset > (var->xres_virtual - var->xres))
  1422. return -EINVAL;
  1423. if(var->yoffset > (var->yres_virtual - var->yres))
  1424. return -EINVAL;
  1425. if(var->vmode & FB_VMODE_YWRAP)
  1426. return -EINVAL;
  1427. if(var->xoffset + info->var.xres > info->var.xres_virtual ||
  1428. var->yoffset + info->var.yres > info->var.yres_virtual)
  1429. return -EINVAL;
  1430. if((err = sisfb_pan_var(ivideo, var)) < 0)
  1431. return err;
  1432. info->var.xoffset = var->xoffset;
  1433. info->var.yoffset = var->yoffset;
  1434. return 0;
  1435. }
  1436. static int
  1437. sisfb_blank(int blank, struct fb_info *info)
  1438. {
  1439. struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
  1440. return sisfb_myblank(ivideo, blank);
  1441. }
  1442. /* ----------- FBDev related routines for all series ---------- */
  1443. static int sisfb_ioctl(struct fb_info *info, unsigned int cmd,
  1444. unsigned long arg)
  1445. {
  1446. struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
  1447. struct sis_memreq sismemreq;
  1448. struct fb_vblank sisvbblank;
  1449. u32 gpu32 = 0;
  1450. #ifndef __user
  1451. #define __user
  1452. #endif
  1453. u32 __user *argp = (u32 __user *)arg;
  1454. switch(cmd) {
  1455. case FBIO_ALLOC:
  1456. if(!capable(CAP_SYS_RAWIO))
  1457. return -EPERM;
  1458. if(copy_from_user(&sismemreq, (void __user *)arg, sizeof(sismemreq)))
  1459. return -EFAULT;
  1460. sis_malloc(&sismemreq);
  1461. if(copy_to_user((void __user *)arg, &sismemreq, sizeof(sismemreq))) {
  1462. sis_free((u32)sismemreq.offset);
  1463. return -EFAULT;
  1464. }
  1465. break;
  1466. case FBIO_FREE:
  1467. if(!capable(CAP_SYS_RAWIO))
  1468. return -EPERM;
  1469. if(get_user(gpu32, argp))
  1470. return -EFAULT;
  1471. sis_free(gpu32);
  1472. break;
  1473. case FBIOGET_VBLANK:
  1474. memset(&sisvbblank, 0, sizeof(struct fb_vblank));
  1475. sisvbblank.count = 0;
  1476. sisvbblank.flags = sisfb_setupvbblankflags(ivideo, &sisvbblank.vcount, &sisvbblank.hcount);
  1477. if(copy_to_user((void __user *)arg, &sisvbblank, sizeof(sisvbblank)))
  1478. return -EFAULT;
  1479. break;
  1480. case SISFB_GET_INFO_SIZE:
  1481. return put_user(sizeof(struct sisfb_info), argp);
  1482. case SISFB_GET_INFO_OLD:
  1483. if(ivideo->warncount++ < 10)
  1484. printk(KERN_INFO
  1485. "sisfb: Deprecated ioctl call received - update your application!\n");
  1486. case SISFB_GET_INFO: /* For communication with X driver */
  1487. ivideo->sisfb_infoblock.sisfb_id = SISFB_ID;
  1488. ivideo->sisfb_infoblock.sisfb_version = VER_MAJOR;
  1489. ivideo->sisfb_infoblock.sisfb_revision = VER_MINOR;
  1490. ivideo->sisfb_infoblock.sisfb_patchlevel = VER_LEVEL;
  1491. ivideo->sisfb_infoblock.chip_id = ivideo->chip_id;
  1492. ivideo->sisfb_infoblock.sisfb_pci_vendor = ivideo->chip_vendor;
  1493. ivideo->sisfb_infoblock.memory = ivideo->video_size / 1024;
  1494. ivideo->sisfb_infoblock.heapstart = ivideo->heapstart / 1024;
  1495. if(ivideo->modechanged) {
  1496. ivideo->sisfb_infoblock.fbvidmode = ivideo->mode_no;
  1497. } else {
  1498. ivideo->sisfb_infoblock.fbvidmode = ivideo->modeprechange;
  1499. }
  1500. ivideo->sisfb_infoblock.sisfb_caps = ivideo->caps;
  1501. ivideo->sisfb_infoblock.sisfb_tqlen = ivideo->cmdQueueSize / 1024;
  1502. ivideo->sisfb_infoblock.sisfb_pcibus = ivideo->pcibus;
  1503. ivideo->sisfb_infoblock.sisfb_pcislot = ivideo->pcislot;
  1504. ivideo->sisfb_infoblock.sisfb_pcifunc = ivideo->pcifunc;
  1505. ivideo->sisfb_infoblock.sisfb_lcdpdc = ivideo->detectedpdc;
  1506. ivideo->sisfb_infoblock.sisfb_lcdpdca = ivideo->detectedpdca;
  1507. ivideo->sisfb_infoblock.sisfb_lcda = ivideo->detectedlcda;
  1508. ivideo->sisfb_infoblock.sisfb_vbflags = ivideo->vbflags;
  1509. ivideo->sisfb_infoblock.sisfb_currentvbflags = ivideo->currentvbflags;
  1510. ivideo->sisfb_infoblock.sisfb_scalelcd = ivideo->SiS_Pr.UsePanelScaler;
  1511. ivideo->sisfb_infoblock.sisfb_specialtiming = ivideo->SiS_Pr.SiS_CustomT;
  1512. ivideo->sisfb_infoblock.sisfb_haveemi = ivideo->SiS_Pr.HaveEMI ? 1 : 0;
  1513. ivideo->sisfb_infoblock.sisfb_haveemilcd = ivideo->SiS_Pr.HaveEMILCD ? 1 : 0;
  1514. ivideo->sisfb_infoblock.sisfb_emi30 = ivideo->SiS_Pr.EMI_30;
  1515. ivideo->sisfb_infoblock.sisfb_emi31 = ivideo->SiS_Pr.EMI_31;
  1516. ivideo->sisfb_infoblock.sisfb_emi32 = ivideo->SiS_Pr.EMI_32;
  1517. ivideo->sisfb_infoblock.sisfb_emi33 = ivideo->SiS_Pr.EMI_33;
  1518. ivideo->sisfb_infoblock.sisfb_tvxpos = (u16)(ivideo->tvxpos + 32);
  1519. ivideo->sisfb_infoblock.sisfb_tvypos = (u16)(ivideo->tvypos + 32);
  1520. ivideo->sisfb_infoblock.sisfb_heapsize = ivideo->sisfb_heap_size / 1024;
  1521. ivideo->sisfb_infoblock.sisfb_videooffset = ivideo->video_offset;
  1522. ivideo->sisfb_infoblock.sisfb_curfstn = ivideo->curFSTN;
  1523. ivideo->sisfb_infoblock.sisfb_curdstn = ivideo->curDSTN;
  1524. ivideo->sisfb_infoblock.sisfb_vbflags2 = ivideo->vbflags2;
  1525. ivideo->sisfb_infoblock.sisfb_can_post = ivideo->sisfb_can_post ? 1 : 0;
  1526. ivideo->sisfb_infoblock.sisfb_card_posted = ivideo->sisfb_card_posted ? 1 : 0;
  1527. ivideo->sisfb_infoblock.sisfb_was_boot_device = ivideo->sisfb_was_boot_device ? 1 : 0;
  1528. if(copy_to_user((void __user *)arg, &ivideo->sisfb_infoblock,
  1529. sizeof(ivideo->sisfb_infoblock)))
  1530. return -EFAULT;
  1531. break;
  1532. case SISFB_GET_VBRSTATUS_OLD:
  1533. if(ivideo->warncount++ < 10)
  1534. printk(KERN_INFO
  1535. "sisfb: Deprecated ioctl call received - update your application!\n");
  1536. case SISFB_GET_VBRSTATUS:
  1537. if(sisfb_CheckVBRetrace(ivideo))
  1538. return put_user((u32)1, argp);
  1539. else
  1540. return put_user((u32)0, argp);
  1541. case SISFB_GET_AUTOMAXIMIZE_OLD:
  1542. if(ivideo->warncount++ < 10)
  1543. printk(KERN_INFO
  1544. "sisfb: Deprecated ioctl call received - update your application!\n");
  1545. case SISFB_GET_AUTOMAXIMIZE:
  1546. if(ivideo->sisfb_max)
  1547. return put_user((u32)1, argp);
  1548. else
  1549. return put_user((u32)0, argp);
  1550. case SISFB_SET_AUTOMAXIMIZE_OLD:
  1551. if(ivideo->warncount++ < 10)
  1552. printk(KERN_INFO
  1553. "sisfb: Deprecated ioctl call received - update your application!\n");
  1554. case SISFB_SET_AUTOMAXIMIZE:
  1555. if(get_user(gpu32, argp))
  1556. return -EFAULT;
  1557. ivideo->sisfb_max = (gpu32) ? 1 : 0;
  1558. break;
  1559. case SISFB_SET_TVPOSOFFSET:
  1560. if(get_user(gpu32, argp))
  1561. return -EFAULT;
  1562. sisfb_set_TVxposoffset(ivideo, ((int)(gpu32 >> 16)) - 32);
  1563. sisfb_set_TVyposoffset(ivideo, ((int)(gpu32 & 0xffff)) - 32);
  1564. break;
  1565. case SISFB_GET_TVPOSOFFSET:
  1566. return put_user((u32)(((ivideo->tvxpos+32)<<16)|((ivideo->tvypos+32)&0xffff)),
  1567. argp);
  1568. case SISFB_COMMAND:
  1569. if(copy_from_user(&ivideo->sisfb_command, (void __user *)arg,
  1570. sizeof(struct sisfb_cmd)))
  1571. return -EFAULT;
  1572. sisfb_handle_command(ivideo, &ivideo->sisfb_command);
  1573. if(copy_to_user((void __user *)arg, &ivideo->sisfb_command,
  1574. sizeof(struct sisfb_cmd)))
  1575. return -EFAULT;
  1576. break;
  1577. case SISFB_SET_LOCK:
  1578. if(get_user(gpu32, argp))
  1579. return -EFAULT;
  1580. ivideo->sisfblocked = (gpu32) ? 1 : 0;
  1581. break;
  1582. default:
  1583. #ifdef SIS_NEW_CONFIG_COMPAT
  1584. return -ENOIOCTLCMD;
  1585. #else
  1586. return -EINVAL;
  1587. #endif
  1588. }
  1589. return 0;
  1590. }
  1591. static int
  1592. sisfb_get_fix(struct fb_fix_screeninfo *fix, int con, struct fb_info *info)
  1593. {
  1594. struct sis_video_info *ivideo = (struct sis_video_info *)info->par;
  1595. memset(fix, 0, sizeof(struct fb_fix_screeninfo));
  1596. strlcpy(fix->id, ivideo->myid, sizeof(fix->id));
  1597. mutex_lock(&info->mm_lock);
  1598. fix->smem_start = ivideo->video_base + ivideo->video_offset;
  1599. fix->smem_len = ivideo->sisfb_mem;
  1600. mutex_unlock(&info->mm_lock);
  1601. fix->type = FB_TYPE_PACKED_PIXELS;
  1602. fix->type_aux = 0;
  1603. fix->visual = (ivideo->video_bpp == 8) ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
  1604. fix->xpanstep = 1;
  1605. fix->ypanstep = (ivideo->sisfb_ypan) ? 1 : 0;
  1606. fix->ywrapstep = 0;
  1607. fix->line_length = ivideo->video_linelength;
  1608. fix->mmio_start = ivideo->mmio_base;
  1609. fix->mmio_len = ivideo->mmio_size;
  1610. if(ivideo->sisvga_engine == SIS_300_VGA) {
  1611. fix->accel = FB_ACCEL_SIS_GLAMOUR;
  1612. } else if((ivideo->chip == SIS_330) ||
  1613. (ivideo->chip == SIS_760) ||
  1614. (ivideo->chip == SIS_761)) {
  1615. fix->accel = FB_ACCEL_SIS_XABRE;
  1616. } else if(ivideo->chip == XGI_20) {
  1617. fix->accel = FB_ACCEL_XGI_VOLARI_Z;
  1618. } else if(ivideo->chip >= XGI_40) {
  1619. fix->accel = FB_ACCEL_XGI_VOLARI_V;
  1620. } else {
  1621. fix->accel = FB_ACCEL_SIS_GLAMOUR_2;
  1622. }
  1623. return 0;
  1624. }
  1625. /* ---------------- fb_ops structures ----------------- */
  1626. static struct fb_ops sisfb_ops = {
  1627. .owner = THIS_MODULE,
  1628. .fb_open = sisfb_open,
  1629. .fb_release = sisfb_release,
  1630. .fb_check_var = sisfb_check_var,
  1631. .fb_set_par = sisfb_set_par,
  1632. .fb_setcolreg = sisfb_setcolreg,
  1633. .fb_pan_display = sisfb_pan_display,
  1634. .fb_blank = sisfb_blank,
  1635. .fb_fillrect = fbcon_sis_fillrect,
  1636. .fb_copyarea = fbcon_sis_copyarea,
  1637. .fb_imageblit = cfb_imageblit,
  1638. .fb_sync = fbcon_sis_sync,
  1639. #ifdef SIS_NEW_CONFIG_COMPAT
  1640. .fb_compat_ioctl= sisfb_ioctl,
  1641. #endif
  1642. .fb_ioctl = sisfb_ioctl
  1643. };
  1644. /* ---------------- Chip generation dependent routines ---------------- */
  1645. static struct pci_dev * __devinit
  1646. sisfb_get_northbridge(int basechipid)
  1647. {
  1648. struct pci_dev *pdev = NULL;
  1649. int nbridgenum, nbridgeidx, i;
  1650. static const unsigned short nbridgeids[] = {
  1651. PCI_DEVICE_ID_SI_540, /* for SiS 540 VGA */
  1652. PCI_DEVICE_ID_SI_630, /* for SiS 630/730 VGA */
  1653. PCI_DEVICE_ID_SI_730,
  1654. PCI_DEVICE_ID_SI_550, /* for SiS 550 VGA */
  1655. PCI_DEVICE_ID_SI_650, /* for SiS 650/651/740 VGA */
  1656. PCI_DEVICE_ID_SI_651,
  1657. PCI_DEVICE_ID_SI_740,
  1658. PCI_DEVICE_ID_SI_661, /* for SiS 661/741/660/760/761 VGA */
  1659. PCI_DEVICE_ID_SI_741,
  1660. PCI_DEVICE_ID_SI_660,
  1661. PCI_DEVICE_ID_SI_760,
  1662. PCI_DEVICE_ID_SI_761
  1663. };
  1664. switch(basechipid) {
  1665. #ifdef CONFIG_FB_SIS_300
  1666. case SIS_540: nbridgeidx = 0; nbridgenum = 1; break;
  1667. case SIS_630: nbridgeidx = 1; nbridgenum = 2; break;
  1668. #endif
  1669. #ifdef CONFIG_FB_SIS_315
  1670. case SIS_550: nbridgeidx = 3; nbridgenum = 1; break;
  1671. case SIS_650: nbridgeidx = 4; nbridgenum = 3; break;
  1672. case SIS_660: nbridgeidx = 7; nbridgenum = 5; break;
  1673. #endif
  1674. default: return NULL;
  1675. }
  1676. for(i = 0; i < nbridgenum; i++) {
  1677. if((pdev = pci_get_device(PCI_VENDOR_ID_SI,
  1678. nbridgeids[nbridgeidx+i], NULL)))
  1679. break;
  1680. }
  1681. return pdev;
  1682. }
  1683. static int __devinit
  1684. sisfb_get_dram_size(struct sis_video_info *ivideo)
  1685. {
  1686. #if defined(CONFIG_FB_SIS_300) || defined(CONFIG_FB_SIS_315)
  1687. u8 reg;
  1688. #endif
  1689. ivideo->video_size = 0;
  1690. ivideo->UMAsize = ivideo->LFBsize = 0;
  1691. switch(ivideo->chip) {
  1692. #ifdef CONFIG_FB_SIS_300
  1693. case SIS_300:
  1694. reg = SiS_GetReg(SISSR, 0x14);
  1695. ivideo->video_size = ((reg & 0x3F) + 1) << 20;
  1696. break;
  1697. case SIS_540:
  1698. case SIS_630:
  1699. case SIS_730:
  1700. if(!ivideo->nbridge)
  1701. return -1;
  1702. pci_read_config_byte(ivideo->nbridge, 0x63, &reg);
  1703. ivideo->video_size = 1 << (((reg & 0x70) >> 4) + 21);
  1704. break;
  1705. #endif
  1706. #ifdef CONFIG_FB_SIS_315
  1707. case SIS_315H:
  1708. case SIS_315PRO:
  1709. case SIS_315:
  1710. reg = SiS_GetReg(SISSR, 0x14);
  1711. ivideo->video_size = (1 << ((reg & 0xf0) >> 4)) << 20;
  1712. switch((reg >> 2) & 0x03) {
  1713. case 0x01:
  1714. case 0x03:
  1715. ivideo->video_size <<= 1;
  1716. break;
  1717. case 0x02:
  1718. ivideo->video_size += (ivideo->video_size/2);
  1719. }
  1720. break;
  1721. case SIS_330:
  1722. reg = SiS_GetReg(SISSR, 0x14);
  1723. ivideo->video_size = (1 << ((reg & 0xf0) >> 4)) << 20;
  1724. if(reg & 0x0c) ivideo->video_size <<= 1;
  1725. break;
  1726. case SIS_550:
  1727. case SIS_650:
  1728. case SIS_740:
  1729. reg = SiS_GetReg(SISSR, 0x14);
  1730. ivideo->video_size = (((reg & 0x3f) + 1) << 2) << 20;
  1731. break;
  1732. case SIS_661:
  1733. case SIS_741:
  1734. reg = SiS_GetReg(SISCR, 0x79);
  1735. ivideo->video_size = (1 << ((reg & 0xf0) >> 4)) << 20;
  1736. break;
  1737. case SIS_660:
  1738. case SIS_760:
  1739. case SIS_761:
  1740. reg = SiS_GetReg(SISCR, 0x79);
  1741. reg = (reg & 0xf0) >> 4;
  1742. if(reg) {
  1743. ivideo->video_size = (1 << reg) << 20;
  1744. ivideo->UMAsize = ivideo->video_size;
  1745. }
  1746. reg = SiS_GetReg(SISCR, 0x78);
  1747. reg &= 0x30;
  1748. if(reg) {
  1749. if(reg == 0x10) {
  1750. ivideo->LFBsize = (32 << 20);
  1751. } else {
  1752. ivideo->LFBsize = (64 << 20);
  1753. }
  1754. ivideo->video_size += ivideo->LFBsize;
  1755. }
  1756. break;
  1757. case SIS_340:
  1758. case XGI_20:
  1759. case XGI_40:
  1760. reg = SiS_GetReg(SISSR, 0x14);
  1761. ivideo->video_size = (1 << ((reg & 0xf0) >> 4)) << 20;
  1762. if(ivideo->chip != XGI_20) {
  1763. reg = (reg & 0x0c) >> 2;
  1764. if(ivideo->revision_id == 2) {
  1765. if(reg & 0x01) reg = 0x02;
  1766. else reg = 0x00;
  1767. }
  1768. if(reg == 0x02) ivideo->video_size <<= 1;
  1769. else if(reg == 0x03) ivideo->video_size <<= 2;
  1770. }
  1771. break;
  1772. #endif
  1773. default:
  1774. return -1;
  1775. }
  1776. return 0;
  1777. }
  1778. /* -------------- video bridge device detection --------------- */
  1779. static void __devinit
  1780. sisfb_detect_VB_connect(struct sis_video_info *ivideo)
  1781. {
  1782. u8 cr32, temp;
  1783. /* No CRT2 on XGI Z7 */
  1784. if(ivideo->chip == XGI_20) {
  1785. ivideo->sisfb_crt1off = 0;
  1786. return;
  1787. }
  1788. #ifdef CONFIG_FB_SIS_300
  1789. if(ivideo->sisvga_engine == SIS_300_VGA) {
  1790. temp = SiS_GetReg(SISSR, 0x17);
  1791. if((temp & 0x0F) && (ivideo->chip != SIS_300)) {
  1792. /* PAL/NTSC is stored on SR16 on such machines */
  1793. if(!(ivideo->vbflags & (TV_PAL | TV_NTSC | TV_PALM | TV_PALN))) {
  1794. temp = SiS_GetReg(SISSR, 0x16);
  1795. if(temp & 0x20)
  1796. ivideo->vbflags |= TV_PAL;
  1797. else
  1798. ivideo->vbflags |= TV_NTSC;
  1799. }
  1800. }
  1801. }
  1802. #endif
  1803. cr32 = SiS_GetReg(SISCR, 0x32);
  1804. if(cr32 & SIS_CRT1) {
  1805. ivideo->sisfb_crt1off = 0;
  1806. } else {
  1807. ivideo->sisfb_crt1off = (cr32 & 0xDF) ? 1 : 0;
  1808. }
  1809. ivideo->vbflags &= ~(CRT2_TV | CRT2_LCD | CRT2_VGA);
  1810. if(cr32 & SIS_VB_TV) ivideo->vbflags |= CRT2_TV;
  1811. if(cr32 & SIS_VB_LCD) ivideo->vbflags |= CRT2_LCD;
  1812. if(cr32 & SIS_VB_CRT2) ivideo->vbflags |= CRT2_VGA;
  1813. /* Check given parms for hardware compatibility.
  1814. * (Cannot do this in the search_xx routines since we don't
  1815. * know what hardware we are running on then)
  1816. */
  1817. if(ivideo->chip != SIS_550) {
  1818. ivideo->sisfb_dstn = ivideo->sisfb_fstn = 0;
  1819. }
  1820. if(ivideo->sisfb_tvplug != -1) {
  1821. if( (ivideo->sisvga_engine != SIS_315_VGA) ||
  1822. (!(ivideo->vbflags2 & VB2_SISYPBPRBRIDGE)) ) {
  1823. if(ivideo->sisfb_tvplug & TV_YPBPR) {
  1824. ivideo->sisfb_tvplug = -1;
  1825. printk(KERN_ERR "sisfb: YPbPr not supported\n");
  1826. }
  1827. }
  1828. }
  1829. if(ivideo->sisfb_tvplug != -1) {
  1830. if( (ivideo->sisvga_engine != SIS_315_VGA) ||
  1831. (!(ivideo->vbflags2 & VB2_SISHIVISIONBRIDGE)) ) {
  1832. if(ivideo->sisfb_tvplug & TV_HIVISION) {
  1833. ivideo->sisfb_tvplug = -1;
  1834. printk(KERN_ERR "sisfb: HiVision not supported\n");
  1835. }
  1836. }
  1837. }
  1838. if(ivideo->sisfb_tvstd != -1) {
  1839. if( (!(ivideo->vbflags2 & VB2_SISBRIDGE)) &&
  1840. (!((ivideo->sisvga_engine == SIS_315_VGA) &&
  1841. (ivideo->vbflags2 & VB2_CHRONTEL))) ) {
  1842. if(ivideo->sisfb_tvstd & (TV_PALM | TV_PALN | TV_NTSCJ)) {
  1843. ivideo->sisfb_tvstd = -1;
  1844. printk(KERN_ERR "sisfb: PALM/PALN/NTSCJ not supported\n");
  1845. }
  1846. }
  1847. }
  1848. /* Detect/set TV plug & type */
  1849. if(ivideo->sisfb_tvplug != -1) {
  1850. ivideo->vbflags |= ivideo->sisfb_tvplug;
  1851. } else {
  1852. if(cr32 & SIS_VB_YPBPR) ivideo->vbflags |= (TV_YPBPR|TV_YPBPR525I); /* default: 480i */
  1853. else if(cr32 & SIS_VB_HIVISION) ivideo->vbflags |= TV_HIVISION;
  1854. else if(cr32 & SIS_VB_SCART) ivideo->vbflags |= TV_SCART;
  1855. else {
  1856. if(cr32 & SIS_VB_SVIDEO) ivideo->vbflags |= TV_SVIDEO;
  1857. if(cr32 & SIS_VB_COMPOSITE) ivideo->vbflags |= TV_AVIDEO;
  1858. }
  1859. }
  1860. if(!(ivideo->vbflags & (TV_YPBPR | TV_HIVISION))) {
  1861. if(ivideo->sisfb_tvstd != -1) {
  1862. ivideo->vbflags &= ~(TV_NTSC | TV_PAL | TV_PALM | TV_PALN | TV_NTSCJ);
  1863. ivideo->vbflags |= ivideo->sisfb_tvstd;
  1864. }
  1865. if(ivideo->vbflags & TV_SCART) {
  1866. ivideo->vbflags &= ~(TV_NTSC | TV_PALM | TV_PALN | TV_NTSCJ);
  1867. ivideo->vbflags |= TV_PAL;
  1868. }
  1869. if(!(ivideo->vbflags & (TV_PAL | TV_NTSC | TV_PALM | TV_PALN | TV_NTSCJ))) {
  1870. if(ivideo->sisvga_engine == SIS_300_VGA) {
  1871. temp = SiS_GetReg(SISSR, 0x38);
  1872. if(temp & 0x01) ivideo->vbflags |= TV_PAL;
  1873. else ivideo->vbflags |= TV_NTSC;
  1874. } else if((ivideo->chip <= SIS_315PRO) || (ivideo->chip >= SIS_330)) {
  1875. temp = SiS_GetReg(SISSR, 0x38);
  1876. if(temp & 0x01) ivideo->vbflags |= TV_PAL;
  1877. else ivideo->vbflags |= TV_NTSC;
  1878. } else {
  1879. temp = SiS_GetReg(SISCR, 0x79);
  1880. if(temp & 0x20) ivideo->vbflags |= TV_PAL;
  1881. else ivideo->vbflags |= TV_NTSC;
  1882. }
  1883. }
  1884. }
  1885. /* Copy forceCRT1 option to CRT1off if option is given */
  1886. if(ivideo->sisfb_forcecrt1 != -1) {
  1887. ivideo->sisfb_crt1off = (ivideo->sisfb_forcecrt1) ? 0 : 1;
  1888. }
  1889. }
  1890. /* ------------------ Sensing routines ------------------ */
  1891. static bool __devinit
  1892. sisfb_test_DDC1(struct sis_video_info *ivideo)
  1893. {
  1894. unsigned short old;
  1895. int count = 48;
  1896. old = SiS_ReadDDC1Bit(&ivideo->SiS_Pr);
  1897. do {
  1898. if(old != SiS_ReadDDC1Bit(&ivideo->SiS_Pr)) break;
  1899. } while(count--);
  1900. return (count != -1);
  1901. }
  1902. static void __devinit
  1903. sisfb_sense_crt1(struct sis_video_info *ivideo)
  1904. {
  1905. bool mustwait = false;
  1906. u8 sr1F, cr17;
  1907. #ifdef CONFIG_FB_SIS_315
  1908. u8 cr63=0;
  1909. #endif
  1910. u16 temp = 0xffff;
  1911. int i;
  1912. sr1F = SiS_GetReg(SISSR, 0x1F);
  1913. SiS_SetRegOR(SISSR, 0x1F, 0x04);
  1914. SiS_SetRegAND(SISSR, 0x1F, 0x3F);
  1915. if(sr1F & 0xc0) mustwait = true;
  1916. #ifdef CONFIG_FB_SIS_315
  1917. if(ivideo->sisvga_engine == SIS_315_VGA) {
  1918. cr63 = SiS_GetReg(SISCR, ivideo->SiS_Pr.SiS_MyCR63);
  1919. cr63 &= 0x40;
  1920. SiS_SetRegAND(SISCR, ivideo->SiS_Pr.SiS_MyCR63, 0xBF);
  1921. }
  1922. #endif
  1923. cr17 = SiS_GetReg(SISCR, 0x17);
  1924. cr17 &= 0x80;
  1925. if(!cr17) {
  1926. SiS_SetRegOR(SISCR, 0x17, 0x80);
  1927. mustwait = true;
  1928. SiS_SetReg(SISSR, 0x00, 0x01);
  1929. SiS_SetReg(SISSR, 0x00, 0x03);
  1930. }
  1931. if(mustwait) {
  1932. for(i=0; i < 10; i++) sisfbwaitretracecrt1(ivideo);
  1933. }
  1934. #ifdef CONFIG_FB_SIS_315
  1935. if(ivideo->chip >= SIS_330) {
  1936. SiS_SetRegAND(SISCR, 0x32, ~0x20);
  1937. if(ivideo->chip >= SIS_340) {
  1938. SiS_SetReg(SISCR, 0x57, 0x4a);
  1939. } else {
  1940. SiS_SetReg(SISCR, 0x57, 0x5f);
  1941. }
  1942. SiS_SetRegOR(SISCR, 0x53, 0x02);
  1943. while ((SiS_GetRegByte(SISINPSTAT)) & 0x01) break;
  1944. while (!((SiS_GetRegByte(SISINPSTAT)) & 0x01)) break;
  1945. if ((SiS_GetRegByte(SISMISCW)) & 0x10) temp = 1;
  1946. SiS_SetRegAND(SISCR, 0x53, 0xfd);
  1947. SiS_SetRegAND(SISCR, 0x57, 0x00);
  1948. }
  1949. #endif
  1950. if(temp == 0xffff) {
  1951. i = 3;
  1952. do {
  1953. temp = SiS_HandleDDC(&ivideo->SiS_Pr, ivideo->vbflags,
  1954. ivideo->sisvga_engine, 0, 0, NULL, ivideo->vbflags2);
  1955. } while(((temp == 0) || (temp == 0xffff)) && i--);
  1956. if((temp == 0) || (temp == 0xffff)) {
  1957. if(sisfb_test_DDC1(ivideo)) temp = 1;
  1958. }
  1959. }
  1960. if((temp) && (temp != 0xffff)) {
  1961. SiS_SetRegOR(SISCR, 0x32, 0x20);
  1962. }
  1963. #ifdef CONFIG_FB_SIS_315
  1964. if(ivideo->sisvga_engine == SIS_315_VGA) {
  1965. SiS_SetRegANDOR(SISCR, ivideo->SiS_Pr.SiS_MyCR63, 0xBF, cr63);
  1966. }
  1967. #endif
  1968. SiS_SetRegANDOR(SISCR, 0x17, 0x7F, cr17);
  1969. SiS_SetReg(SISSR, 0x1F, sr1F);
  1970. }
  1971. /* Determine and detect attached devices on SiS30x */
  1972. static void __devinit
  1973. SiS_SenseLCD(struct sis_video_info *ivideo)
  1974. {
  1975. unsigned char buffer[256];
  1976. unsigned short temp, realcrtno, i;
  1977. u8 reg, cr37 = 0, paneltype = 0;
  1978. u16 xres, yres;
  1979. ivideo->SiS_Pr.PanelSelfDetected = false;
  1980. /* LCD detection only for TMDS bridges */
  1981. if(!(ivideo->vbflags2 & VB2_SISTMDSBRIDGE))
  1982. return;
  1983. if(ivideo->vbflags2 & VB2_30xBDH)
  1984. return;
  1985. /* If LCD already set up by BIOS, skip it */
  1986. reg = SiS_GetReg(SISCR, 0x32);
  1987. if(reg & 0x08)
  1988. return;
  1989. realcrtno = 1;
  1990. if(ivideo->SiS_Pr.DDCPortMixup)
  1991. realcrtno = 0;
  1992. /* Check DDC capabilities */
  1993. temp = SiS_HandleDDC(&ivideo->SiS_Pr, ivideo->vbflags, ivideo->sisvga_engine,
  1994. realcrtno, 0, &buffer[0], ivideo->vbflags2);
  1995. if((!temp) || (temp == 0xffff) || (!(temp & 0x02)))
  1996. return;
  1997. /* Read DDC data */
  1998. i = 3; /* Number of retrys */
  1999. do {
  2000. temp = SiS_HandleDDC(&ivideo->SiS_Pr, ivideo->vbflags,
  2001. ivideo->sisvga_engine, realcrtno, 1,
  2002. &buffer[0], ivideo->vbflags2);
  2003. } while((temp) && i--);
  2004. if(temp)
  2005. return;
  2006. /* No digital device */
  2007. if(!(buffer[0x14] & 0x80))
  2008. return;
  2009. /* First detailed timing preferred timing? */
  2010. if(!(buffer[0x18] & 0x02))
  2011. return;
  2012. xres = buffer[0x38] | ((buffer[0x3a] & 0xf0) << 4);
  2013. yres = buffer[0x3b] | ((buffer[0x3d] & 0xf0) << 4);
  2014. switch(xres) {
  2015. case 1024:
  2016. if(yres == 768)
  2017. paneltype = 0x02;
  2018. break;
  2019. case 1280:
  2020. if(yres == 1024)
  2021. paneltype = 0x03;
  2022. break;
  2023. case 1600:
  2024. if((yres == 1200) && (ivideo->vbflags2 & VB2_30xC))
  2025. paneltype = 0x0b;
  2026. break;
  2027. }
  2028. if(!paneltype)
  2029. return;
  2030. if(buffer[0x23])
  2031. cr37 |= 0x10;
  2032. if((buffer[0x47] & 0x18) == 0x18)
  2033. cr37 |= ((((buffer[0x47] & 0x06) ^ 0x06) << 5) | 0x20);
  2034. else
  2035. cr37 |= 0xc0;
  2036. SiS_SetReg(SISCR, 0x36, paneltype);
  2037. cr37 &= 0xf1;
  2038. SiS_SetRegANDOR(SISCR, 0x37, 0x0c, cr37);
  2039. SiS_SetRegOR(SISCR, 0x32, 0x08);
  2040. ivideo->SiS_Pr.PanelSelfDetected = true;
  2041. }
  2042. static int __devinit
  2043. SISDoSense(struct sis_video_info *ivideo, u16 type, u16 test)
  2044. {
  2045. int temp, mytest, result, i, j;
  2046. for(j = 0; j < 10; j++) {
  2047. result = 0;
  2048. for(i = 0; i < 3; i++) {
  2049. mytest = test;
  2050. SiS_SetReg(SISPART4, 0x11, (type & 0x00ff));
  2051. temp = (type >> 8) | (mytest & 0x00ff);
  2052. SiS_SetRegANDOR(SISPART4, 0x10, 0xe0, temp);
  2053. SiS_DDC2Delay(&ivideo->SiS_Pr, 0x1500);
  2054. mytest >>= 8;
  2055. mytest &= 0x7f;
  2056. temp = SiS_GetReg(SISPART4, 0x03);
  2057. temp ^= 0x0e;
  2058. temp &= mytest;
  2059. if(temp == mytest) result++;
  2060. #if 1
  2061. SiS_SetReg(SISPART4, 0x11, 0x00);
  2062. SiS_SetRegAND(SISPART4, 0x10, 0xe0);
  2063. SiS_DDC2Delay(&ivideo->SiS_Pr, 0x1000);
  2064. #endif
  2065. }
  2066. if((result == 0) || (result >= 2)) break;
  2067. }
  2068. return result;
  2069. }
  2070. static void __devinit
  2071. SiS_Sense30x(struct sis_video_info *ivideo)
  2072. {
  2073. u8 backupP4_0d,backupP2_00,backupP2_4d,backupSR_1e,biosflag=0;
  2074. u16 svhs=0, svhs_c=0;
  2075. u16 cvbs=0, cvbs_c=0;
  2076. u16 vga2=0, vga2_c=0;
  2077. int myflag, result;
  2078. char stdstr[] = "sisfb: Detected";
  2079. char tvstr[] = "TV connected to";
  2080. if(ivideo->vbflags2 & VB2_301) {
  2081. svhs = 0x00b9; cvbs = 0x00b3; vga2 = 0x00d1;
  2082. myflag = SiS_GetReg(SISPART4, 0x01);
  2083. if(myflag & 0x04) {
  2084. svhs = 0x00dd; cvbs = 0x00ee; vga2 = 0x00fd;
  2085. }
  2086. } else if(ivideo->vbflags2 & (VB2_301B | VB2_302B)) {
  2087. svhs = 0x016b; cvbs = 0x0174; vga2 = 0x0190;
  2088. } else if(ivideo->vbflags2 & (VB2_301LV | VB2_302LV)) {
  2089. svhs = 0x0200; cvbs = 0x0100;
  2090. } else if(ivideo->vbflags2 & (VB2_301C | VB2_302ELV | VB2_307T | VB2_307LV)) {
  2091. svhs = 0x016b; cvbs = 0x0110; vga2 = 0x0190;
  2092. } else
  2093. return;
  2094. vga2_c = 0x0e08; svhs_c = 0x0404; cvbs_c = 0x0804;
  2095. if(ivideo->vbflags & (VB2_301LV|VB2_302LV|VB2_302ELV|VB2_307LV)) {
  2096. svhs_c = 0x0408; cvbs_c = 0x0808;
  2097. }
  2098. biosflag = 2;
  2099. if(ivideo->haveXGIROM) {
  2100. biosflag = ivideo->bios_abase[0x58] & 0x03;
  2101. } else if(ivideo->newrom) {
  2102. if(ivideo->bios_abase[0x5d] & 0x04) biosflag |= 0x01;
  2103. } else if(ivideo->sisvga_engine == SIS_300_VGA) {
  2104. if(ivideo->bios_abase) {
  2105. biosflag = ivideo->bios_abase[0xfe] & 0x03;
  2106. }
  2107. }
  2108. if(ivideo->chip == SIS_300) {
  2109. myflag = SiS_GetReg(SISSR, 0x3b);
  2110. if(!(myflag & 0x01)) vga2 = vga2_c = 0;
  2111. }
  2112. if(!(ivideo->vbflags2 & VB2_SISVGA2BRIDGE)) {
  2113. vga2 = vga2_c = 0;
  2114. }
  2115. backupSR_1e = SiS_GetReg(SISSR, 0x1e);
  2116. SiS_SetRegOR(SISSR, 0x1e, 0x20);
  2117. backupP4_0d = SiS_GetReg(SISPART4, 0x0d);
  2118. if(ivideo->vbflags2 & VB2_30xC) {
  2119. SiS_SetRegANDOR(SISPART4, 0x0d, ~0x07, 0x01);
  2120. } else {
  2121. SiS_SetRegOR(SISPART4, 0x0d, 0x04);
  2122. }
  2123. SiS_DDC2Delay(&ivideo->SiS_Pr, 0x2000);
  2124. backupP2_00 = SiS_GetReg(SISPART2, 0x00);
  2125. SiS_SetReg(SISPART2, 0x00, ((backupP2_00 | 0x1c) & 0xfc));
  2126. backupP2_4d = SiS_GetReg(SISPART2, 0x4d);
  2127. if(ivideo->vbflags2 & VB2_SISYPBPRBRIDGE) {
  2128. SiS_SetReg(SISPART2, 0x4d, (backupP2_4d & ~0x10));
  2129. }
  2130. if(!(ivideo->vbflags2 & VB2_30xCLV)) {
  2131. SISDoSense(ivideo, 0, 0);
  2132. }
  2133. SiS_SetRegAND(SISCR, 0x32, ~0x14);
  2134. if(vga2_c || vga2) {
  2135. if(SISDoSense(ivideo, vga2, vga2_c)) {
  2136. if(biosflag & 0x01) {
  2137. printk(KERN_INFO "%s %s SCART output\n", stdstr, tvstr);
  2138. SiS_SetRegOR(SISCR, 0x32, 0x04);
  2139. } else {
  2140. printk(KERN_INFO "%s secondary VGA connection\n", stdstr);
  2141. SiS_SetRegOR(SISCR, 0x32, 0x10);
  2142. }
  2143. }
  2144. }
  2145. SiS_SetRegAND(SISCR, 0x32, 0x3f);
  2146. if(ivideo->vbflags2 & VB2_30xCLV) {
  2147. SiS_SetRegOR(SISPART4, 0x0d, 0x04);
  2148. }
  2149. if((ivideo->sisvga_engine == SIS_315_VGA) && (ivideo->vbflags2 & VB2_SISYPBPRBRIDGE)) {
  2150. SiS_SetReg(SISPART2, 0x4d, (backupP2_4d | 0x10));
  2151. SiS_DDC2Delay(&ivideo->SiS_Pr, 0x2000);
  2152. if((result = SISDoSense(ivideo, svhs, 0x0604))) {
  2153. if((result = SISDoSense(ivideo, cvbs, 0x0804))) {
  2154. printk(KERN_INFO "%s %s YPbPr component output\n", stdstr, tvstr);
  2155. SiS_SetRegOR(SISCR, 0x32, 0x80);
  2156. }
  2157. }
  2158. SiS_SetReg(SISPART2, 0x4d, backupP2_4d);
  2159. }
  2160. SiS_SetRegAND(SISCR, 0x32, ~0x03);
  2161. if(!(ivideo->vbflags & TV_YPBPR)) {
  2162. if((result = SISDoSense(ivideo, svhs, svhs_c))) {
  2163. printk(KERN_INFO "%s %s SVIDEO output\n", stdstr, tvstr);
  2164. SiS_SetRegOR(SISCR, 0x32, 0x02);
  2165. }
  2166. if((biosflag & 0x02) || (!result)) {
  2167. if(SISDoSense(ivideo, cvbs, cvbs_c)) {
  2168. printk(KERN_INFO "%s %s COMPOSITE output\n", stdstr, tvstr);
  2169. SiS_SetRegOR(SISCR, 0x32, 0x01);
  2170. }
  2171. }
  2172. }
  2173. SISDoSense(ivideo, 0, 0);
  2174. SiS_SetReg(SISPART2, 0x00, backupP2_00);
  2175. SiS_SetReg(SISPART4, 0x0d, backupP4_0d);
  2176. SiS_SetReg(SISSR, 0x1e, backupSR_1e);
  2177. if(ivideo->vbflags2 & VB2_30xCLV) {
  2178. biosflag = SiS_GetReg(SISPART2, 0x00);
  2179. if(biosflag & 0x20) {
  2180. for(myflag = 2; myflag > 0; myflag--) {
  2181. biosflag ^= 0x20;
  2182. SiS_SetReg(SISPART2, 0x00, biosflag);
  2183. }
  2184. }
  2185. }
  2186. SiS_SetReg(SISPART2, 0x00, backupP2_00);
  2187. }
  2188. /* Determine and detect attached TV's on Chrontel */
  2189. static void __devinit
  2190. SiS_SenseCh(struct sis_video_info *ivideo)
  2191. {
  2192. #if defined(CONFIG_FB_SIS_300) || defined(CONFIG_FB_SIS_315)
  2193. u8 temp1, temp2;
  2194. char stdstr[] = "sisfb: Chrontel: Detected TV connected to";
  2195. #endif
  2196. #ifdef CONFIG_FB_SIS_300
  2197. unsigned char test[3];
  2198. int i;
  2199. #endif
  2200. if(ivideo->chip < SIS_315H) {
  2201. #ifdef CONFIG_FB_SIS_300
  2202. ivideo->SiS_Pr.SiS_IF_DEF_CH70xx = 1; /* Chrontel 700x */
  2203. SiS_SetChrontelGPIO(&ivideo->SiS_Pr, 0x9c); /* Set general purpose IO for Chrontel communication */
  2204. SiS_DDC2Delay(&ivideo->SiS_Pr, 1000);
  2205. temp1 = SiS_GetCH700x(&ivideo->SiS_Pr, 0x25);
  2206. /* See Chrontel TB31 for explanation */
  2207. temp2 = SiS_GetCH700x(&ivideo->SiS_Pr, 0x0e);
  2208. if(((temp2 & 0x07) == 0x01) || (temp2 & 0x04)) {
  2209. SiS_SetCH700x(&ivideo->SiS_Pr, 0x0e, 0x0b);
  2210. SiS_DDC2Delay(&ivideo->SiS_Pr, 300);
  2211. }
  2212. temp2 = SiS_GetCH700x(&ivideo->SiS_Pr, 0x25);
  2213. if(temp2 != temp1) temp1 = temp2;
  2214. if((temp1 >= 0x22) && (temp1 <= 0x50)) {
  2215. /* Read power status */
  2216. temp1 = SiS_GetCH700x(&ivideo->SiS_Pr, 0x0e);
  2217. if((temp1 & 0x03) != 0x03) {
  2218. /* Power all outputs */
  2219. SiS_SetCH700x(&ivideo->SiS_Pr, 0x0e,0x0b);
  2220. SiS_DDC2Delay(&ivideo->SiS_Pr, 300);
  2221. }
  2222. /* Sense connected TV devices */
  2223. for(i = 0; i < 3; i++) {
  2224. SiS_SetCH700x(&ivideo->SiS_Pr, 0x10, 0x01);
  2225. SiS_DDC2Delay(&ivideo->SiS_Pr, 0x96);
  2226. SiS_SetCH700x(&ivideo->SiS_Pr, 0x10, 0x00);
  2227. SiS_DDC2Delay(&ivideo->SiS_Pr, 0x96);
  2228. temp1 = SiS_GetCH700x(&ivideo->SiS_Pr, 0x10);
  2229. if(!(temp1 & 0x08)) test[i] = 0x02;
  2230. else if(!(temp1 & 0x02)) test[i] = 0x01;
  2231. else test[i] = 0;
  2232. SiS_DDC2Delay(&ivideo->SiS_Pr, 0x96);
  2233. }
  2234. if(test[0] == test[1]) temp1 = test[0];
  2235. else if(test[0] == test[2]) temp1 = test[0];
  2236. else if(test[1] == test[2]) temp1 = test[1];
  2237. else {
  2238. printk(KERN_INFO
  2239. "sisfb: TV detection unreliable - test results varied\n");
  2240. temp1 = test[2];
  2241. }
  2242. if(temp1 == 0x02) {
  2243. printk(KERN_INFO "%s SVIDEO output\n", stdstr);
  2244. ivideo->vbflags |= TV_SVIDEO;
  2245. SiS_SetRegOR(SISCR, 0x32, 0x02);
  2246. SiS_SetRegAND(SISCR, 0x32, ~0x05);
  2247. } else if (temp1 == 0x01) {
  2248. printk(KERN_INFO "%s CVBS output\n", stdstr);
  2249. ivideo->vbflags |= TV_AVIDEO;
  2250. SiS_SetRegOR(SISCR, 0x32, 0x01);
  2251. SiS_SetRegAND(SISCR, 0x32, ~0x06);
  2252. } else {
  2253. SiS_SetCH70xxANDOR(&ivideo->SiS_Pr, 0x0e, 0x01, 0xF8);
  2254. SiS_SetRegAND(SISCR, 0x32, ~0x07);
  2255. }
  2256. } else if(temp1 == 0) {
  2257. SiS_SetCH70xxANDOR(&ivideo->SiS_Pr, 0x0e, 0x01, 0xF8);
  2258. SiS_SetRegAND(SISCR, 0x32, ~0x07);
  2259. }
  2260. /* Set general purpose IO for Chrontel communication */
  2261. SiS_SetChrontelGPIO(&ivideo->SiS_Pr, 0x00);
  2262. #endif
  2263. } else {
  2264. #ifdef CONFIG_FB_SIS_315
  2265. ivideo->SiS_Pr.SiS_IF_DEF_CH70xx = 2; /* Chrontel 7019 */
  2266. temp1 = SiS_GetCH701x(&ivideo->SiS_Pr, 0x49);
  2267. SiS_SetCH701x(&ivideo->SiS_Pr, 0x49, 0x20);
  2268. SiS_DDC2Delay(&ivideo->SiS_Pr, 0x96);
  2269. temp2 = SiS_GetCH701x(&ivideo->SiS_Pr, 0x20);
  2270. temp2 |= 0x01;
  2271. SiS_SetCH701x(&ivideo->SiS_Pr, 0x20, temp2);
  2272. SiS_DDC2Delay(&ivideo->SiS_Pr, 0x96);
  2273. temp2 ^= 0x01;
  2274. SiS_SetCH701x(&ivideo->SiS_Pr, 0x20, temp2);
  2275. SiS_DDC2Delay(&ivideo->SiS_Pr, 0x96);
  2276. temp2 = SiS_GetCH701x(&ivideo->SiS_Pr, 0x20);
  2277. SiS_SetCH701x(&ivideo->SiS_Pr, 0x49, temp1);
  2278. temp1 = 0;
  2279. if(temp2 & 0x02) temp1 |= 0x01;
  2280. if(temp2 & 0x10) temp1 |= 0x01;
  2281. if(temp2 & 0x04) temp1 |= 0x02;
  2282. if( (temp1 & 0x01) && (temp1 & 0x02) ) temp1 = 0x04;
  2283. switch(temp1) {
  2284. case 0x01:
  2285. printk(KERN_INFO "%s CVBS output\n", stdstr);
  2286. ivideo->vbflags |= TV_AVIDEO;
  2287. SiS_SetRegOR(SISCR, 0x32, 0x01);
  2288. SiS_SetRegAND(SISCR, 0x32, ~0x06);
  2289. break;
  2290. case 0x02:
  2291. printk(KERN_INFO "%s SVIDEO output\n", stdstr);
  2292. ivideo->vbflags |= TV_SVIDEO;
  2293. SiS_SetRegOR(SISCR, 0x32, 0x02);
  2294. SiS_SetRegAND(SISCR, 0x32, ~0x05);
  2295. break;
  2296. case 0x04:
  2297. printk(KERN_INFO "%s SCART output\n", stdstr);
  2298. SiS_SetRegOR(SISCR, 0x32, 0x04);
  2299. SiS_SetRegAND(SISCR, 0x32, ~0x03);
  2300. break;
  2301. default:
  2302. SiS_SetRegAND(SISCR, 0x32, ~0x07);
  2303. }
  2304. #endif
  2305. }
  2306. }
  2307. static void __devinit
  2308. sisfb_get_VB_type(struct sis_video_info *ivideo)
  2309. {
  2310. char stdstr[] = "sisfb: Detected";
  2311. char bridgestr[] = "video bridge";
  2312. u8 vb_chipid;
  2313. u8 reg;
  2314. /* No CRT2 on XGI Z7 */
  2315. if(ivideo->chip == XGI_20)
  2316. return;
  2317. vb_chipid = SiS_GetReg(SISPART4, 0x00);
  2318. switch(vb_chipid) {
  2319. case 0x01:
  2320. reg = SiS_GetReg(SISPART4, 0x01);
  2321. if(reg < 0xb0) {
  2322. ivideo->vbflags |= VB_301; /* Deprecated */
  2323. ivideo->vbflags2 |= VB2_301;
  2324. printk(KERN_INFO "%s SiS301 %s\n", stdstr, bridgestr);
  2325. } else if(reg < 0xc0) {
  2326. ivideo->vbflags |= VB_301B; /* Deprecated */
  2327. ivideo->vbflags2 |= VB2_301B;
  2328. reg = SiS_GetReg(SISPART4, 0x23);
  2329. if(!(reg & 0x02)) {
  2330. ivideo->vbflags |= VB_30xBDH; /* Deprecated */
  2331. ivideo->vbflags2 |= VB2_30xBDH;
  2332. printk(KERN_INFO "%s SiS301B-DH %s\n", stdstr, bridgestr);
  2333. } else {
  2334. printk(KERN_INFO "%s SiS301B %s\n", stdstr, bridgestr);
  2335. }
  2336. } else if(reg < 0xd0) {
  2337. ivideo->vbflags |= VB_301C; /* Deprecated */
  2338. ivideo->vbflags2 |= VB2_301C;
  2339. printk(KERN_INFO "%s SiS301C %s\n", stdstr, bridgestr);
  2340. } else if(reg < 0xe0) {
  2341. ivideo->vbflags |= VB_301LV; /* Deprecated */
  2342. ivideo->vbflags2 |= VB2_301LV;
  2343. printk(KERN_INFO "%s SiS301LV %s\n", stdstr, bridgestr);
  2344. } else if(reg <= 0xe1) {
  2345. reg = SiS_GetReg(SISPART4, 0x39);
  2346. if(reg == 0xff) {
  2347. ivideo->vbflags |= VB_302LV; /* Deprecated */
  2348. ivideo->vbflags2 |= VB2_302LV;
  2349. printk(KERN_INFO "%s SiS302LV %s\n", stdstr, bridgestr);
  2350. } else {
  2351. ivideo->vbflags |= VB_301C; /* Deprecated */
  2352. ivideo->vbflags2 |= VB2_301C;
  2353. printk(KERN_INFO "%s SiS301C(P4) %s\n", stdstr, bridgestr);
  2354. #if 0
  2355. ivideo->vbflags |= VB_302ELV; /* Deprecated */
  2356. ivideo->vbflags2 |= VB2_302ELV;
  2357. printk(KERN_INFO "%s SiS302ELV %s\n", stdstr, bridgestr);
  2358. #endif
  2359. }
  2360. }
  2361. break;
  2362. case 0x02:
  2363. ivideo->vbflags |= VB_302B; /* Deprecated */
  2364. ivideo->vbflags2 |= VB2_302B;
  2365. printk(KERN_INFO "%s SiS302B %s\n", stdstr, bridgestr);
  2366. break;
  2367. }
  2368. if((!(ivideo->vbflags2 & VB2_VIDEOBRIDGE)) && (ivideo->chip != SIS_300)) {
  2369. reg = SiS_GetReg(SISCR, 0x37);
  2370. reg &= SIS_EXTERNAL_CHIP_MASK;
  2371. reg >>= 1;
  2372. if(ivideo->sisvga_engine == SIS_300_VGA) {
  2373. #ifdef CONFIG_FB_SIS_300
  2374. switch(reg) {
  2375. case SIS_EXTERNAL_CHIP_LVDS:
  2376. ivideo->vbflags |= VB_LVDS; /* Deprecated */
  2377. ivideo->vbflags2 |= VB2_LVDS;
  2378. break;
  2379. case SIS_EXTERNAL_CHIP_TRUMPION:
  2380. ivideo->vbflags |= (VB_LVDS | VB_TRUMPION); /* Deprecated */
  2381. ivideo->vbflags2 |= (VB2_LVDS | VB2_TRUMPION);
  2382. break;
  2383. case SIS_EXTERNAL_CHIP_CHRONTEL:
  2384. ivideo->vbflags |= VB_CHRONTEL; /* Deprecated */
  2385. ivideo->vbflags2 |= VB2_CHRONTEL;
  2386. break;
  2387. case SIS_EXTERNAL_CHIP_LVDS_CHRONTEL:
  2388. ivideo->vbflags |= (VB_LVDS | VB_CHRONTEL); /* Deprecated */
  2389. ivideo->vbflags2 |= (VB2_LVDS | VB2_CHRONTEL);
  2390. break;
  2391. }
  2392. if(ivideo->vbflags2 & VB2_CHRONTEL) ivideo->chronteltype = 1;
  2393. #endif
  2394. } else if(ivideo->chip < SIS_661) {
  2395. #ifdef CONFIG_FB_SIS_315
  2396. switch (reg) {
  2397. case SIS310_EXTERNAL_CHIP_LVDS:
  2398. ivideo->vbflags |= VB_LVDS; /* Deprecated */
  2399. ivideo->vbflags2 |= VB2_LVDS;
  2400. break;
  2401. case SIS310_EXTERNAL_CHIP_LVDS_CHRONTEL:
  2402. ivideo->vbflags |= (VB_LVDS | VB_CHRONTEL); /* Deprecated */
  2403. ivideo->vbflags2 |= (VB2_LVDS | VB2_CHRONTEL);
  2404. break;
  2405. }
  2406. if(ivideo->vbflags2 & VB2_CHRONTEL) ivideo->chronteltype = 2;
  2407. #endif
  2408. } else if(ivideo->chip >= SIS_661) {
  2409. #ifdef CONFIG_FB_SIS_315
  2410. reg = SiS_GetReg(SISCR, 0x38);
  2411. reg >>= 5;
  2412. switch(reg) {
  2413. case 0x02:
  2414. ivideo->vbflags |= VB_LVDS; /* Deprecated */
  2415. ivideo->vbflags2 |= VB2_LVDS;
  2416. break;
  2417. case 0x03:
  2418. ivideo->vbflags |= (VB_LVDS | VB_CHRONTEL); /* Deprecated */
  2419. ivideo->vbflags2 |= (VB2_LVDS | VB2_CHRONTEL);
  2420. break;
  2421. case 0x04:
  2422. ivideo->vbflags |= (VB_LVDS | VB_CONEXANT); /* Deprecated */
  2423. ivideo->vbflags2 |= (VB2_LVDS | VB2_CONEXANT);
  2424. break;
  2425. }
  2426. if(ivideo->vbflags2 & VB2_CHRONTEL) ivideo->chronteltype = 2;
  2427. #endif
  2428. }
  2429. if(ivideo->vbflags2 & VB2_LVDS) {
  2430. printk(KERN_INFO "%s LVDS transmitter\n", stdstr);
  2431. }
  2432. if((ivideo->sisvga_engine == SIS_300_VGA) && (ivideo->vbflags2 & VB2_TRUMPION)) {
  2433. printk(KERN_INFO "%s Trumpion Zurac LCD scaler\n", stdstr);
  2434. }
  2435. if(ivideo->vbflags2 & VB2_CHRONTEL) {
  2436. printk(KERN_INFO "%s Chrontel TV encoder\n", stdstr);
  2437. }
  2438. if((ivideo->chip >= SIS_661) && (ivideo->vbflags2 & VB2_CONEXANT)) {
  2439. printk(KERN_INFO "%s Conexant external device\n", stdstr);
  2440. }
  2441. }
  2442. if(ivideo->vbflags2 & VB2_SISBRIDGE) {
  2443. SiS_SenseLCD(ivideo);
  2444. SiS_Sense30x(ivideo);
  2445. } else if(ivideo->vbflags2 & VB2_CHRONTEL) {
  2446. SiS_SenseCh(ivideo);
  2447. }
  2448. }
  2449. /* ---------- Engine initialization routines ------------ */
  2450. static void
  2451. sisfb_engine_init(struct sis_video_info *ivideo)
  2452. {
  2453. /* Initialize command queue (we use MMIO only) */
  2454. /* BEFORE THIS IS CALLED, THE ENGINES *MUST* BE SYNC'ED */
  2455. ivideo->caps &= ~(TURBO_QUEUE_CAP |
  2456. MMIO_CMD_QUEUE_CAP |
  2457. VM_CMD_QUEUE_CAP |
  2458. AGP_CMD_QUEUE_CAP);
  2459. #ifdef CONFIG_FB_SIS_300
  2460. if(ivideo->sisvga_engine == SIS_300_VGA) {
  2461. u32 tqueue_pos;
  2462. u8 tq_state;
  2463. tqueue_pos = (ivideo->video_size - ivideo->cmdQueueSize) / (64 * 1024);
  2464. tq_state = SiS_GetReg(SISSR, IND_SIS_TURBOQUEUE_SET);
  2465. tq_state |= 0xf0;
  2466. tq_state &= 0xfc;
  2467. tq_state |= (u8)(tqueue_pos >> 8);
  2468. SiS_SetReg(SISSR, IND_SIS_TURBOQUEUE_SET, tq_state);
  2469. SiS_SetReg(SISSR, IND_SIS_TURBOQUEUE_ADR, (u8)(tqueue_pos & 0xff));
  2470. ivideo->caps |= TURBO_QUEUE_CAP;
  2471. }
  2472. #endif
  2473. #ifdef CONFIG_FB_SIS_315
  2474. if(ivideo->sisvga_engine == SIS_315_VGA) {
  2475. u32 tempq = 0, templ;
  2476. u8 temp;
  2477. if(ivideo->chip == XGI_20) {
  2478. switch(ivideo->cmdQueueSize) {
  2479. case (64 * 1024):
  2480. temp = SIS_CMD_QUEUE_SIZE_Z7_64k;
  2481. break;
  2482. case (128 * 1024):
  2483. default:
  2484. temp = SIS_CMD_QUEUE_SIZE_Z7_128k;
  2485. }
  2486. } else {
  2487. switch(ivideo->cmdQueueSize) {
  2488. case (4 * 1024 * 1024):
  2489. temp = SIS_CMD_QUEUE_SIZE_4M;
  2490. break;
  2491. case (2 * 1024 * 1024):
  2492. temp = SIS_CMD_QUEUE_SIZE_2M;
  2493. break;
  2494. case (1 * 1024 * 1024):
  2495. temp = SIS_CMD_QUEUE_SIZE_1M;
  2496. break;
  2497. default:
  2498. case (512 * 1024):
  2499. temp = SIS_CMD_QUEUE_SIZE_512k;
  2500. }
  2501. }
  2502. SiS_SetReg(SISSR, IND_SIS_CMDQUEUE_THRESHOLD, COMMAND_QUEUE_THRESHOLD);
  2503. SiS_SetReg(SISSR, IND_SIS_CMDQUEUE_SET, SIS_CMD_QUEUE_RESET);
  2504. if((ivideo->chip >= XGI_40) && ivideo->modechanged) {
  2505. /* Must disable dual pipe on XGI_40. Can't do
  2506. * this in MMIO mode, because it requires
  2507. * setting/clearing a bit in the MMIO fire trigger
  2508. * register.
  2509. */
  2510. if(!((templ = MMIO_IN32(ivideo->mmio_vbase, 0x8240)) & (1 << 10))) {
  2511. MMIO_OUT32(ivideo->mmio_vbase, Q_WRITE_PTR, 0);
  2512. SiS_SetReg(SISSR, IND_SIS_CMDQUEUE_SET, (temp | SIS_VRAM_CMDQUEUE_ENABLE));
  2513. tempq = MMIO_IN32(ivideo->mmio_vbase, Q_READ_PTR);
  2514. MMIO_OUT32(ivideo->mmio_vbase, Q_WRITE_PTR, tempq);
  2515. tempq = (u32)(ivideo->video_size - ivideo->cmdQueueSize);
  2516. MMIO_OUT32(ivideo->mmio_vbase, Q_BASE_ADDR, tempq);
  2517. writel(0x16800000 + 0x8240, ivideo->video_vbase + tempq);
  2518. writel(templ | (1 << 10), ivideo->video_vbase + tempq + 4);
  2519. writel(0x168F0000, ivideo->video_vbase + tempq + 8);
  2520. writel(0x168F0000, ivideo->video_vbase + tempq + 12);
  2521. MMIO_OUT32(ivideo->mmio_vbase, Q_WRITE_PTR, (tempq + 16));
  2522. sisfb_syncaccel(ivideo);
  2523. SiS_SetReg(SISSR, IND_SIS_CMDQUEUE_SET, SIS_CMD_QUEUE_RESET);
  2524. }
  2525. }
  2526. tempq = MMIO_IN32(ivideo->mmio_vbase, MMIO_QUEUE_READPORT);
  2527. MMIO_OUT32(ivideo->mmio_vbase, MMIO_QUEUE_WRITEPORT, tempq);
  2528. temp |= (SIS_MMIO_CMD_ENABLE | SIS_CMD_AUTO_CORR);
  2529. SiS_SetReg(SISSR, IND_SIS_CMDQUEUE_SET, temp);
  2530. tempq = (u32)(ivideo->video_size - ivideo->cmdQueueSize);
  2531. MMIO_OUT32(ivideo->mmio_vbase, MMIO_QUEUE_PHYBASE, tempq);
  2532. ivideo->caps |= MMIO_CMD_QUEUE_CAP;
  2533. }
  2534. #endif
  2535. ivideo->engineok = 1;
  2536. }
  2537. static void __devinit
  2538. sisfb_detect_lcd_type(struct sis_video_info *ivideo)
  2539. {
  2540. u8 reg;
  2541. int i;
  2542. reg = SiS_GetReg(SISCR, 0x36);
  2543. reg &= 0x0f;
  2544. if(ivideo->sisvga_engine == SIS_300_VGA) {
  2545. ivideo->CRT2LCDType = sis300paneltype[reg];
  2546. } else if(ivideo->chip >= SIS_661) {
  2547. ivideo->CRT2LCDType = sis661paneltype[reg];
  2548. } else {
  2549. ivideo->CRT2LCDType = sis310paneltype[reg];
  2550. if((ivideo->chip == SIS_550) && (sisfb_fstn)) {
  2551. if((ivideo->CRT2LCDType != LCD_320x240_2) &&
  2552. (ivideo->CRT2LCDType != LCD_320x240_3)) {
  2553. ivideo->CRT2LCDType = LCD_320x240;
  2554. }
  2555. }
  2556. }
  2557. if(ivideo->CRT2LCDType == LCD_UNKNOWN) {
  2558. /* For broken BIOSes: Assume 1024x768, RGB18 */
  2559. ivideo->CRT2LCDType = LCD_1024x768;
  2560. SiS_SetRegANDOR(SISCR, 0x36, 0xf0, 0x02);
  2561. SiS_SetRegANDOR(SISCR, 0x37, 0xee, 0x01);
  2562. printk(KERN_DEBUG "sisfb: Invalid panel ID (%02x), assuming 1024x768, RGB18\n", reg);
  2563. }
  2564. for(i = 0; i < SIS_LCD_NUMBER; i++) {
  2565. if(ivideo->CRT2LCDType == sis_lcd_data[i].lcdtype) {
  2566. ivideo->lcdxres = sis_lcd_data[i].xres;
  2567. ivideo->lcdyres = sis_lcd_data[i].yres;
  2568. ivideo->lcddefmodeidx = sis_lcd_data[i].default_mode_idx;
  2569. break;
  2570. }
  2571. }
  2572. #ifdef CONFIG_FB_SIS_300
  2573. if(ivideo->SiS_Pr.SiS_CustomT == CUT_BARCO1366) {
  2574. ivideo->lcdxres = 1360; ivideo->lcdyres = 1024;
  2575. ivideo->lcddefmodeidx = DEFAULT_MODE_1360;
  2576. } else if(ivideo->SiS_Pr.SiS_CustomT == CUT_PANEL848) {
  2577. ivideo->lcdxres = 848; ivideo->lcdyres = 480;
  2578. ivideo->lcddefmodeidx = DEFAULT_MODE_848;
  2579. } else if(ivideo->SiS_Pr.SiS_CustomT == CUT_PANEL856) {
  2580. ivideo->lcdxres = 856; ivideo->lcdyres = 480;
  2581. ivideo->lcddefmodeidx = DEFAULT_MODE_856;
  2582. }
  2583. #endif
  2584. printk(KERN_DEBUG "sisfb: Detected %dx%d flat panel\n",
  2585. ivideo->lcdxres, ivideo->lcdyres);
  2586. }
  2587. static void __devinit
  2588. sisfb_save_pdc_emi(struct sis_video_info *ivideo)
  2589. {
  2590. #ifdef CONFIG_FB_SIS_300
  2591. /* Save the current PanelDelayCompensation if the LCD is currently used */
  2592. if(ivideo->sisvga_engine == SIS_300_VGA) {
  2593. if(ivideo->vbflags2 & (VB2_LVDS | VB2_30xBDH)) {
  2594. int tmp;
  2595. tmp = SiS_GetReg(SISCR, 0x30);
  2596. if(tmp & 0x20) {
  2597. /* Currently on LCD? If yes, read current pdc */
  2598. ivideo->detectedpdc = SiS_GetReg(SISPART1, 0x13);
  2599. ivideo->detectedpdc &= 0x3c;
  2600. if(ivideo->SiS_Pr.PDC == -1) {
  2601. /* Let option override detection */
  2602. ivideo->SiS_Pr.PDC = ivideo->detectedpdc;
  2603. }
  2604. printk(KERN_INFO "sisfb: Detected LCD PDC 0x%02x\n",
  2605. ivideo->detectedpdc);
  2606. }
  2607. if((ivideo->SiS_Pr.PDC != -1) &&
  2608. (ivideo->SiS_Pr.PDC != ivideo->detectedpdc)) {
  2609. printk(KERN_INFO "sisfb: Using LCD PDC 0x%02x\n",
  2610. ivideo->SiS_Pr.PDC);
  2611. }
  2612. }
  2613. }
  2614. #endif
  2615. #ifdef CONFIG_FB_SIS_315
  2616. if(ivideo->sisvga_engine == SIS_315_VGA) {
  2617. /* Try to find about LCDA */
  2618. if(ivideo->vbflags2 & VB2_SISLCDABRIDGE) {
  2619. int tmp;
  2620. tmp = SiS_GetReg(SISPART1, 0x13);
  2621. if(tmp & 0x04) {
  2622. ivideo->SiS_Pr.SiS_UseLCDA = true;
  2623. ivideo->detectedlcda = 0x03;
  2624. }
  2625. }
  2626. /* Save PDC */
  2627. if(ivideo->vbflags2 & VB2_SISLVDSBRIDGE) {
  2628. int tmp;
  2629. tmp = SiS_GetReg(SISCR, 0x30);
  2630. if((tmp & 0x20) || (ivideo->detectedlcda != 0xff)) {
  2631. /* Currently on LCD? If yes, read current pdc */
  2632. u8 pdc;
  2633. pdc = SiS_GetReg(SISPART1, 0x2D);
  2634. ivideo->detectedpdc = (pdc & 0x0f) << 1;
  2635. ivideo->detectedpdca = (pdc & 0xf0) >> 3;
  2636. pdc = SiS_GetReg(SISPART1, 0x35);
  2637. ivideo->detectedpdc |= ((pdc >> 7) & 0x01);
  2638. pdc = SiS_GetReg(SISPART1, 0x20);
  2639. ivideo->detectedpdca |= ((pdc >> 6) & 0x01);
  2640. if(ivideo->newrom) {
  2641. /* New ROM invalidates other PDC resp. */
  2642. if(ivideo->detectedlcda != 0xff) {
  2643. ivideo->detectedpdc = 0xff;
  2644. } else {
  2645. ivideo->detectedpdca = 0xff;
  2646. }
  2647. }
  2648. if(ivideo->SiS_Pr.PDC == -1) {
  2649. if(ivideo->detectedpdc != 0xff) {
  2650. ivideo->SiS_Pr.PDC = ivideo->detectedpdc;
  2651. }
  2652. }
  2653. if(ivideo->SiS_Pr.PDCA == -1) {
  2654. if(ivideo->detectedpdca != 0xff) {
  2655. ivideo->SiS_Pr.PDCA = ivideo->detectedpdca;
  2656. }
  2657. }
  2658. if(ivideo->detectedpdc != 0xff) {
  2659. printk(KERN_INFO
  2660. "sisfb: Detected LCD PDC 0x%02x (for LCD=CRT2)\n",
  2661. ivideo->detectedpdc);
  2662. }
  2663. if(ivideo->detectedpdca != 0xff) {
  2664. printk(KERN_INFO
  2665. "sisfb: Detected LCD PDC1 0x%02x (for LCD=CRT1)\n",
  2666. ivideo->detectedpdca);
  2667. }
  2668. }
  2669. /* Save EMI */
  2670. if(ivideo->vbflags2 & VB2_SISEMIBRIDGE) {
  2671. ivideo->SiS_Pr.EMI_30 = SiS_GetReg(SISPART4, 0x30);
  2672. ivideo->SiS_Pr.EMI_31 = SiS_GetReg(SISPART4, 0x31);
  2673. ivideo->SiS_Pr.EMI_32 = SiS_GetReg(SISPART4, 0x32);
  2674. ivideo->SiS_Pr.EMI_33 = SiS_GetReg(SISPART4, 0x33);
  2675. ivideo->SiS_Pr.HaveEMI = true;
  2676. if((tmp & 0x20) || (ivideo->detectedlcda != 0xff)) {
  2677. ivideo->SiS_Pr.HaveEMILCD = true;
  2678. }
  2679. }
  2680. }
  2681. /* Let user override detected PDCs (all bridges) */
  2682. if(ivideo->vbflags2 & VB2_30xBLV) {
  2683. if((ivideo->SiS_Pr.PDC != -1) &&
  2684. (ivideo->SiS_Pr.PDC != ivideo->detectedpdc)) {
  2685. printk(KERN_INFO "sisfb: Using LCD PDC 0x%02x (for LCD=CRT2)\n",
  2686. ivideo->SiS_Pr.PDC);
  2687. }
  2688. if((ivideo->SiS_Pr.PDCA != -1) &&
  2689. (ivideo->SiS_Pr.PDCA != ivideo->detectedpdca)) {
  2690. printk(KERN_INFO "sisfb: Using LCD PDC1 0x%02x (for LCD=CRT1)\n",
  2691. ivideo->SiS_Pr.PDCA);
  2692. }
  2693. }
  2694. }
  2695. #endif
  2696. }
  2697. /* -------------------- Memory manager routines ---------------------- */
  2698. static u32 __devinit
  2699. sisfb_getheapstart(struct sis_video_info *ivideo)
  2700. {
  2701. u32 ret = ivideo->sisfb_parm_mem * 1024;
  2702. u32 maxoffs = ivideo->video_size - ivideo->hwcursor_size - ivideo->cmdQueueSize;
  2703. u32 def;
  2704. /* Calculate heap start = end of memory for console
  2705. *
  2706. * CCCCCCCCDDDDDDDDDDDDDDDDDDDDDDDDDDDDHHHHQQQQQQQQQQ
  2707. * C = console, D = heap, H = HWCursor, Q = cmd-queue
  2708. *
  2709. * On 76x in UMA+LFB mode, the layout is as follows:
  2710. * DDDDDDDDDDDCCCCCCCCCCCCCCCCCCCCCCCCHHHHQQQQQQQQQQQ
  2711. * where the heap is the entire UMA area, eventually
  2712. * into the LFB area if the given mem parameter is
  2713. * higher than the size of the UMA memory.
  2714. *
  2715. * Basically given by "mem" parameter
  2716. *
  2717. * maximum = videosize - cmd_queue - hwcursor
  2718. * (results in a heap of size 0)
  2719. * default = SiS 300: depends on videosize
  2720. * SiS 315/330/340/XGI: 32k below max
  2721. */
  2722. if(ivideo->sisvga_engine == SIS_300_VGA) {
  2723. if(ivideo->video_size > 0x1000000) {
  2724. def = 0xc00000;
  2725. } else if(ivideo->video_size > 0x800000) {
  2726. def = 0x800000;
  2727. } else {
  2728. def = 0x400000;
  2729. }
  2730. } else if(ivideo->UMAsize && ivideo->LFBsize) {
  2731. ret = def = 0;
  2732. } else {
  2733. def = maxoffs - 0x8000;
  2734. }
  2735. /* Use default for secondary card for now (FIXME) */
  2736. if((!ret) || (ret > maxoffs) || (ivideo->cardnumber != 0))
  2737. ret = def;
  2738. return ret;
  2739. }
  2740. static u32 __devinit
  2741. sisfb_getheapsize(struct sis_video_info *ivideo)
  2742. {
  2743. u32 max = ivideo->video_size - ivideo->hwcursor_size - ivideo->cmdQueueSize;
  2744. u32 ret = 0;
  2745. if(ivideo->UMAsize && ivideo->LFBsize) {
  2746. if( (!ivideo->sisfb_parm_mem) ||
  2747. ((ivideo->sisfb_parm_mem * 1024) > max) ||
  2748. ((max - (ivideo->sisfb_parm_mem * 1024)) < ivideo->UMAsize) ) {
  2749. ret = ivideo->UMAsize;
  2750. max -= ivideo->UMAsize;
  2751. } else {
  2752. ret = max - (ivideo->sisfb_parm_mem * 1024);
  2753. max = ivideo->sisfb_parm_mem * 1024;
  2754. }
  2755. ivideo->video_offset = ret;
  2756. ivideo->sisfb_mem = max;
  2757. } else {
  2758. ret = max - ivideo->heapstart;
  2759. ivideo->sisfb_mem = ivideo->heapstart;
  2760. }
  2761. return ret;
  2762. }
  2763. static int __devinit
  2764. sisfb_heap_init(struct sis_video_info *ivideo)
  2765. {
  2766. struct SIS_OH *poh;
  2767. ivideo->video_offset = 0;
  2768. if(ivideo->sisfb_parm_mem) {
  2769. if( (ivideo->sisfb_parm_mem < (2 * 1024 * 1024)) ||
  2770. (ivideo->sisfb_parm_mem > ivideo->video_size) ) {
  2771. ivideo->sisfb_parm_mem = 0;
  2772. }
  2773. }
  2774. ivideo->heapstart = sisfb_getheapstart(ivideo);
  2775. ivideo->sisfb_heap_size = sisfb_getheapsize(ivideo);
  2776. ivideo->sisfb_heap_start = ivideo->video_vbase + ivideo->heapstart;
  2777. ivideo->sisfb_heap_end = ivideo->sisfb_heap_start + ivideo->sisfb_heap_size;
  2778. printk(KERN_INFO "sisfb: Memory heap starting at %dK, size %dK\n",
  2779. (int)(ivideo->heapstart / 1024), (int)(ivideo->sisfb_heap_size / 1024));
  2780. ivideo->sisfb_heap.vinfo = ivideo;
  2781. ivideo->sisfb_heap.poha_chain = NULL;
  2782. ivideo->sisfb_heap.poh_freelist = NULL;
  2783. poh = sisfb_poh_new_node(&ivideo->sisfb_heap);
  2784. if(poh == NULL)
  2785. return 1;
  2786. poh->poh_next = &ivideo->sisfb_heap.oh_free;
  2787. poh->poh_prev = &ivideo->sisfb_heap.oh_free;
  2788. poh->size = ivideo->sisfb_heap_size;
  2789. poh->offset = ivideo->heapstart;
  2790. ivideo->sisfb_heap.oh_free.poh_next = poh;
  2791. ivideo->sisfb_heap.oh_free.poh_prev = poh;
  2792. ivideo->sisfb_heap.oh_free.size = 0;
  2793. ivideo->sisfb_heap.max_freesize = poh->size;
  2794. ivideo->sisfb_heap.oh_used.poh_next = &ivideo->sisfb_heap.oh_used;
  2795. ivideo->sisfb_heap.oh_used.poh_prev = &ivideo->sisfb_heap.oh_used;
  2796. ivideo->sisfb_heap.oh_used.size = SENTINEL;
  2797. if(ivideo->cardnumber == 0) {
  2798. /* For the first card, make this heap the "global" one
  2799. * for old DRM (which could handle only one card)
  2800. */
  2801. sisfb_heap = &ivideo->sisfb_heap;
  2802. }
  2803. return 0;
  2804. }
  2805. static struct SIS_OH *
  2806. sisfb_poh_new_node(struct SIS_HEAP *memheap)
  2807. {
  2808. struct SIS_OHALLOC *poha;
  2809. struct SIS_OH *poh;
  2810. unsigned long cOhs;
  2811. int i;
  2812. if(memheap->poh_freelist == NULL) {
  2813. poha = kmalloc(SIS_OH_ALLOC_SIZE, GFP_KERNEL);
  2814. if(!poha)
  2815. return NULL;
  2816. poha->poha_next = memheap->poha_chain;
  2817. memheap->poha_chain = poha;
  2818. cOhs = (SIS_OH_ALLOC_SIZE - sizeof(struct SIS_OHALLOC)) / sizeof(struct SIS_OH) + 1;
  2819. poh = &poha->aoh[0];
  2820. for(i = cOhs - 1; i != 0; i--) {
  2821. poh->poh_next = poh + 1;
  2822. poh = poh + 1;
  2823. }
  2824. poh->poh_next = NULL;
  2825. memheap->poh_freelist = &poha->aoh[0];
  2826. }
  2827. poh = memheap->poh_freelist;
  2828. memheap->poh_freelist = poh->poh_next;
  2829. return poh;
  2830. }
  2831. static struct SIS_OH *
  2832. sisfb_poh_allocate(struct SIS_HEAP *memheap, u32 size)
  2833. {
  2834. struct SIS_OH *pohThis;
  2835. struct SIS_OH *pohRoot;
  2836. int bAllocated = 0;
  2837. if(size > memheap->max_freesize) {
  2838. DPRINTK("sisfb: Can't allocate %dk video memory\n",
  2839. (unsigned int) size / 1024);
  2840. return NULL;
  2841. }
  2842. pohThis = memheap->oh_free.poh_next;
  2843. while(pohThis != &memheap->oh_free) {
  2844. if(size <= pohThis->size) {
  2845. bAllocated = 1;
  2846. break;
  2847. }
  2848. pohThis = pohThis->poh_next;
  2849. }
  2850. if(!bAllocated) {
  2851. DPRINTK("sisfb: Can't allocate %dk video memory\n",
  2852. (unsigned int) size / 1024);
  2853. return NULL;
  2854. }
  2855. if(size == pohThis->size) {
  2856. pohRoot = pohThis;
  2857. sisfb_delete_node(pohThis);
  2858. } else {
  2859. pohRoot = sisfb_poh_new_node(memheap);
  2860. if(pohRoot == NULL)
  2861. return NULL;
  2862. pohRoot->offset = pohThis->offset;
  2863. pohRoot->size = size;
  2864. pohThis->offset += size;
  2865. pohThis->size -= size;
  2866. }
  2867. memheap->max_freesize -= size;
  2868. pohThis = &memheap->oh_used;
  2869. sisfb_insert_node(pohThis, pohRoot);
  2870. return pohRoot;
  2871. }
  2872. static void
  2873. sisfb_delete_node(struct SIS_OH *poh)
  2874. {
  2875. poh->poh_prev->poh_next = poh->poh_next;
  2876. poh->poh_next->poh_prev = poh->poh_prev;
  2877. }
  2878. static void
  2879. sisfb_insert_node(struct SIS_OH *pohList, struct SIS_OH *poh)
  2880. {
  2881. struct SIS_OH *pohTemp = pohList->poh_next;
  2882. pohList->poh_next = poh;
  2883. pohTemp->poh_prev = poh;
  2884. poh->poh_prev = pohList;
  2885. poh->poh_next = pohTemp;
  2886. }
  2887. static struct SIS_OH *
  2888. sisfb_poh_free(struct SIS_HEAP *memheap, u32 base)
  2889. {
  2890. struct SIS_OH *pohThis;
  2891. struct SIS_OH *poh_freed;
  2892. struct SIS_OH *poh_prev;
  2893. struct SIS_OH *poh_next;
  2894. u32 ulUpper;
  2895. u32 ulLower;
  2896. int foundNode = 0;
  2897. poh_freed = memheap->oh_used.poh_next;
  2898. while(poh_freed != &memheap->oh_used) {
  2899. if(poh_freed->offset == base) {
  2900. foundNode = 1;
  2901. break;
  2902. }
  2903. poh_freed = poh_freed->poh_next;
  2904. }
  2905. if(!foundNode)
  2906. return NULL;
  2907. memheap->max_freesize += poh_freed->size;
  2908. poh_prev = poh_next = NULL;
  2909. ulUpper = poh_freed->offset + poh_freed->size;
  2910. ulLower = poh_freed->offset;
  2911. pohThis = memheap->oh_free.poh_next;
  2912. while(pohThis != &memheap->oh_free) {
  2913. if(pohThis->offset == ulUpper) {
  2914. poh_next = pohThis;
  2915. } else if((pohThis->offset + pohThis->size) == ulLower) {
  2916. poh_prev = pohThis;
  2917. }
  2918. pohThis = pohThis->poh_next;
  2919. }
  2920. sisfb_delete_node(poh_freed);
  2921. if(poh_prev && poh_next) {
  2922. poh_prev->size += (poh_freed->size + poh_next->size);
  2923. sisfb_delete_node(poh_next);
  2924. sisfb_free_node(memheap, poh_freed);
  2925. sisfb_free_node(memheap, poh_next);
  2926. return poh_prev;
  2927. }
  2928. if(poh_prev) {
  2929. poh_prev->size += poh_freed->size;
  2930. sisfb_free_node(memheap, poh_freed);
  2931. return poh_prev;
  2932. }
  2933. if(poh_next) {
  2934. poh_next->size += poh_freed->size;
  2935. poh_next->offset = poh_freed->offset;
  2936. sisfb_free_node(memheap, poh_freed);
  2937. return poh_next;
  2938. }
  2939. sisfb_insert_node(&memheap->oh_free, poh_freed);
  2940. return poh_freed;
  2941. }
  2942. static void
  2943. sisfb_free_node(struct SIS_HEAP *memheap, struct SIS_OH *poh)
  2944. {
  2945. if(poh == NULL)
  2946. return;
  2947. poh->poh_next = memheap->poh_freelist;
  2948. memheap->poh_freelist = poh;
  2949. }
  2950. static void
  2951. sis_int_malloc(struct sis_video_info *ivideo, struct sis_memreq *req)
  2952. {
  2953. struct SIS_OH *poh = NULL;
  2954. if((ivideo) && (ivideo->sisfb_id == SISFB_ID) && (!ivideo->havenoheap))
  2955. poh = sisfb_poh_allocate(&ivideo->sisfb_heap, (u32)req->size);
  2956. if(poh == NULL) {
  2957. req->offset = req->size = 0;
  2958. DPRINTK("sisfb: Video RAM allocation failed\n");
  2959. } else {
  2960. req->offset = poh->offset;
  2961. req->size = poh->size;
  2962. DPRINTK("sisfb: Video RAM allocation succeeded: 0x%lx\n",
  2963. (poh->offset + ivideo->video_vbase));
  2964. }
  2965. }
  2966. void
  2967. sis_malloc(struct sis_memreq *req)
  2968. {
  2969. struct sis_video_info *ivideo = sisfb_heap->vinfo;
  2970. if(&ivideo->sisfb_heap == sisfb_heap)
  2971. sis_int_malloc(ivideo, req);
  2972. else
  2973. req->offset = req->size = 0;
  2974. }
  2975. void
  2976. sis_malloc_new(struct pci_dev *pdev, struct sis_memreq *req)
  2977. {
  2978. struct sis_video_info *ivideo = pci_get_drvdata(pdev);
  2979. sis_int_malloc(ivideo, req);
  2980. }
  2981. /* sis_free: u32 because "base" is offset inside video ram, can never be >4GB */
  2982. static void
  2983. sis_int_free(struct sis_video_info *ivideo, u32 base)
  2984. {
  2985. struct SIS_OH *poh;
  2986. if((!ivideo) || (ivideo->sisfb_id != SISFB_ID) || (ivideo->havenoheap))
  2987. return;
  2988. poh = sisfb_poh_free(&ivideo->sisfb_heap, base);
  2989. if(poh == NULL) {
  2990. DPRINTK("sisfb: sisfb_poh_free() failed at base 0x%x\n",
  2991. (unsigned int) base);
  2992. }
  2993. }
  2994. void
  2995. sis_free(u32 base)
  2996. {
  2997. struct sis_video_info *ivideo = sisfb_heap->vinfo;
  2998. sis_int_free(ivideo, base);
  2999. }
  3000. void
  3001. sis_free_new(struct pci_dev *pdev, u32 base)
  3002. {
  3003. struct sis_video_info *ivideo = pci_get_drvdata(pdev);
  3004. sis_int_free(ivideo, base);
  3005. }
  3006. /* --------------------- SetMode routines ------------------------- */
  3007. static void
  3008. sisfb_check_engine_and_sync(struct sis_video_info *ivideo)
  3009. {
  3010. u8 cr30, cr31;
  3011. /* Check if MMIO and engines are enabled,
  3012. * and sync in case they are. Can't use
  3013. * ivideo->accel here, as this might have
  3014. * been changed before this is called.
  3015. */
  3016. cr30 = SiS_GetReg(SISSR, IND_SIS_PCI_ADDRESS_SET);
  3017. cr31 = SiS_GetReg(SISSR, IND_SIS_MODULE_ENABLE);
  3018. /* MMIO and 2D/3D engine enabled? */
  3019. if((cr30 & SIS_MEM_MAP_IO_ENABLE) && (cr31 & 0x42)) {
  3020. #ifdef CONFIG_FB_SIS_300
  3021. if(ivideo->sisvga_engine == SIS_300_VGA) {
  3022. /* Don't care about TurboQueue. It's
  3023. * enough to know that the engines
  3024. * are enabled
  3025. */
  3026. sisfb_syncaccel(ivideo);
  3027. }
  3028. #endif
  3029. #ifdef CONFIG_FB_SIS_315
  3030. if(ivideo->sisvga_engine == SIS_315_VGA) {
  3031. /* Check that any queue mode is
  3032. * enabled, and that the queue
  3033. * is not in the state of "reset"
  3034. */
  3035. cr30 = SiS_GetReg(SISSR, 0x26);
  3036. if((cr30 & 0xe0) && (!(cr30 & 0x01))) {
  3037. sisfb_syncaccel(ivideo);
  3038. }
  3039. }
  3040. #endif
  3041. }
  3042. }
  3043. static void
  3044. sisfb_pre_setmode(struct sis_video_info *ivideo)
  3045. {
  3046. u8 cr30 = 0, cr31 = 0, cr33 = 0, cr35 = 0, cr38 = 0;
  3047. int tvregnum = 0;
  3048. ivideo->currentvbflags &= (VB_VIDEOBRIDGE | VB_DISPTYPE_DISP2);
  3049. SiS_SetReg(SISSR, 0x05, 0x86);
  3050. cr31 = SiS_GetReg(SISCR, 0x31);
  3051. cr31 &= ~0x60;
  3052. cr31 |= 0x04;
  3053. cr33 = ivideo->rate_idx & 0x0F;
  3054. #ifdef CONFIG_FB_SIS_315
  3055. if(ivideo->sisvga_engine == SIS_315_VGA) {
  3056. if(ivideo->chip >= SIS_661) {
  3057. cr38 = SiS_GetReg(SISCR, 0x38);
  3058. cr38 &= ~0x07; /* Clear LCDA/DualEdge and YPbPr bits */
  3059. } else {
  3060. tvregnum = 0x38;
  3061. cr38 = SiS_GetReg(SISCR, tvregnum);
  3062. cr38 &= ~0x3b; /* Clear LCDA/DualEdge and YPbPr bits */
  3063. }
  3064. }
  3065. #endif
  3066. #ifdef CONFIG_FB_SIS_300
  3067. if(ivideo->sisvga_engine == SIS_300_VGA) {
  3068. tvregnum = 0x35;
  3069. cr38 = SiS_GetReg(SISCR, tvregnum);
  3070. }
  3071. #endif
  3072. SiS_SetEnableDstn(&ivideo->SiS_Pr, false);
  3073. SiS_SetEnableFstn(&ivideo->SiS_Pr, false);
  3074. ivideo->curFSTN = ivideo->curDSTN = 0;
  3075. switch(ivideo->currentvbflags & VB_DISPTYPE_DISP2) {
  3076. case CRT2_TV:
  3077. cr38 &= ~0xc0; /* Clear PAL-M / PAL-N bits */
  3078. if((ivideo->vbflags & TV_YPBPR) && (ivideo->vbflags2 & VB2_SISYPBPRBRIDGE)) {
  3079. #ifdef CONFIG_FB_SIS_315
  3080. if(ivideo->chip >= SIS_661) {
  3081. cr38 |= 0x04;
  3082. if(ivideo->vbflags & TV_YPBPR525P) cr35 |= 0x20;
  3083. else if(ivideo->vbflags & TV_YPBPR750P) cr35 |= 0x40;
  3084. else if(ivideo->vbflags & TV_YPBPR1080I) cr35 |= 0x60;
  3085. cr30 |= SIS_SIMULTANEOUS_VIEW_ENABLE;
  3086. cr35 &= ~0x01;
  3087. ivideo->currentvbflags |= (TV_YPBPR | (ivideo->vbflags & TV_YPBPRALL));
  3088. } else if(ivideo->sisvga_engine == SIS_315_VGA) {
  3089. cr30 |= (0x80 | SIS_SIMULTANEOUS_VIEW_ENABLE);
  3090. cr38 |= 0x08;
  3091. if(ivideo->vbflags & TV_YPBPR525P) cr38 |= 0x10;
  3092. else if(ivideo->vbflags & TV_YPBPR750P) cr38 |= 0x20;
  3093. else if(ivideo->vbflags & TV_YPBPR1080I) cr38 |= 0x30;
  3094. cr31 &= ~0x01;
  3095. ivideo->currentvbflags |= (TV_YPBPR | (ivideo->vbflags & TV_YPBPRALL));
  3096. }
  3097. #endif
  3098. } else if((ivideo->vbflags & TV_HIVISION) &&
  3099. (ivideo->vbflags2 & VB2_SISHIVISIONBRIDGE)) {
  3100. if(ivideo->chip >= SIS_661) {
  3101. cr38 |= 0x04;
  3102. cr35 |= 0x60;
  3103. } else {
  3104. cr30 |= 0x80;
  3105. }
  3106. cr30 |= SIS_SIMULTANEOUS_VIEW_ENABLE;
  3107. cr31 |= 0x01;
  3108. cr35 |= 0x01;
  3109. ivideo->currentvbflags |= TV_HIVISION;
  3110. } else if(ivideo->vbflags & TV_SCART) {
  3111. cr30 = (SIS_VB_OUTPUT_SCART | SIS_SIMULTANEOUS_VIEW_ENABLE);
  3112. cr31 |= 0x01;
  3113. cr35 |= 0x01;
  3114. ivideo->currentvbflags |= TV_SCART;
  3115. } else {
  3116. if(ivideo->vbflags & TV_SVIDEO) {
  3117. cr30 = (SIS_VB_OUTPUT_SVIDEO | SIS_SIMULTANEOUS_VIEW_ENABLE);
  3118. ivideo->currentvbflags |= TV_SVIDEO;
  3119. }
  3120. if(ivideo->vbflags & TV_AVIDEO) {
  3121. cr30 = (SIS_VB_OUTPUT_COMPOSITE | SIS_SIMULTANEOUS_VIEW_ENABLE);
  3122. ivideo->currentvbflags |= TV_AVIDEO;
  3123. }
  3124. }
  3125. cr31 |= SIS_DRIVER_MODE;
  3126. if(ivideo->vbflags & (TV_AVIDEO | TV_SVIDEO)) {
  3127. if(ivideo->vbflags & TV_PAL) {
  3128. cr31 |= 0x01; cr35 |= 0x01;
  3129. ivideo->currentvbflags |= TV_PAL;
  3130. if(ivideo->vbflags & TV_PALM) {
  3131. cr38 |= 0x40; cr35 |= 0x04;
  3132. ivideo->currentvbflags |= TV_PALM;
  3133. } else if(ivideo->vbflags & TV_PALN) {
  3134. cr38 |= 0x80; cr35 |= 0x08;
  3135. ivideo->currentvbflags |= TV_PALN;
  3136. }
  3137. } else {
  3138. cr31 &= ~0x01; cr35 &= ~0x01;
  3139. ivideo->currentvbflags |= TV_NTSC;
  3140. if(ivideo->vbflags & TV_NTSCJ) {
  3141. cr38 |= 0x40; cr35 |= 0x02;
  3142. ivideo->currentvbflags |= TV_NTSCJ;
  3143. }
  3144. }
  3145. }
  3146. break;
  3147. case CRT2_LCD:
  3148. cr30 = (SIS_VB_OUTPUT_LCD | SIS_SIMULTANEOUS_VIEW_ENABLE);
  3149. cr31 |= SIS_DRIVER_MODE;
  3150. SiS_SetEnableDstn(&ivideo->SiS_Pr, ivideo->sisfb_dstn);
  3151. SiS_SetEnableFstn(&ivideo->SiS_Pr, ivideo->sisfb_fstn);
  3152. ivideo->curFSTN = ivideo->sisfb_fstn;
  3153. ivideo->curDSTN = ivideo->sisfb_dstn;
  3154. break;
  3155. case CRT2_VGA:
  3156. cr30 = (SIS_VB_OUTPUT_CRT2 | SIS_SIMULTANEOUS_VIEW_ENABLE);
  3157. cr31 |= SIS_DRIVER_MODE;
  3158. if(ivideo->sisfb_nocrt2rate) {
  3159. cr33 |= (sisbios_mode[ivideo->sisfb_mode_idx].rate_idx << 4);
  3160. } else {
  3161. cr33 |= ((ivideo->rate_idx & 0x0F) << 4);
  3162. }
  3163. break;
  3164. default: /* disable CRT2 */
  3165. cr30 = 0x00;
  3166. cr31 |= (SIS_DRIVER_MODE | SIS_VB_OUTPUT_DISABLE);
  3167. }
  3168. SiS_SetReg(SISCR, 0x30, cr30);
  3169. SiS_SetReg(SISCR, 0x33, cr33);
  3170. if(ivideo->chip >= SIS_661) {
  3171. #ifdef CONFIG_FB_SIS_315
  3172. cr31 &= ~0x01; /* Clear PAL flag (now in CR35) */
  3173. SiS_SetRegANDOR(SISCR, 0x35, ~0x10, cr35); /* Leave overscan bit alone */
  3174. cr38 &= 0x07; /* Use only LCDA and HiVision/YPbPr bits */
  3175. SiS_SetRegANDOR(SISCR, 0x38, 0xf8, cr38);
  3176. #endif
  3177. } else if(ivideo->chip != SIS_300) {
  3178. SiS_SetReg(SISCR, tvregnum, cr38);
  3179. }
  3180. SiS_SetReg(SISCR, 0x31, cr31);
  3181. ivideo->SiS_Pr.SiS_UseOEM = ivideo->sisfb_useoem;
  3182. sisfb_check_engine_and_sync(ivideo);
  3183. }
  3184. /* Fix SR11 for 661 and later */
  3185. #ifdef CONFIG_FB_SIS_315
  3186. static void
  3187. sisfb_fixup_SR11(struct sis_video_info *ivideo)
  3188. {
  3189. u8 tmpreg;
  3190. if(ivideo->chip >= SIS_661) {
  3191. tmpreg = SiS_GetReg(SISSR, 0x11);
  3192. if(tmpreg & 0x20) {
  3193. tmpreg = SiS_GetReg(SISSR, 0x3e);
  3194. tmpreg = (tmpreg + 1) & 0xff;
  3195. SiS_SetReg(SISSR, 0x3e, tmpreg);
  3196. tmpreg = SiS_GetReg(SISSR, 0x11);
  3197. }
  3198. if(tmpreg & 0xf0) {
  3199. SiS_SetRegAND(SISSR, 0x11, 0x0f);
  3200. }
  3201. }
  3202. }
  3203. #endif
  3204. static void
  3205. sisfb_set_TVxposoffset(struct sis_video_info *ivideo, int val)
  3206. {
  3207. if(val > 32) val = 32;
  3208. if(val < -32) val = -32;
  3209. ivideo->tvxpos = val;
  3210. if(ivideo->sisfblocked) return;
  3211. if(!ivideo->modechanged) return;
  3212. if(ivideo->currentvbflags & CRT2_TV) {
  3213. if(ivideo->vbflags2 & VB2_CHRONTEL) {
  3214. int x = ivideo->tvx;
  3215. switch(ivideo->chronteltype) {
  3216. case 1:
  3217. x += val;
  3218. if(x < 0) x = 0;
  3219. SiS_SetReg(SISSR, 0x05, 0x86);
  3220. SiS_SetCH700x(&ivideo->SiS_Pr, 0x0a, (x & 0xff));
  3221. SiS_SetCH70xxANDOR(&ivideo->SiS_Pr, 0x08, ((x & 0x0100) >> 7), 0xFD);
  3222. break;
  3223. case 2:
  3224. /* Not supported by hardware */
  3225. break;
  3226. }
  3227. } else if(ivideo->vbflags2 & VB2_SISBRIDGE) {
  3228. u8 p2_1f,p2_20,p2_2b,p2_42,p2_43;
  3229. unsigned short temp;
  3230. p2_1f = ivideo->p2_1f;
  3231. p2_20 = ivideo->p2_20;
  3232. p2_2b = ivideo->p2_2b;
  3233. p2_42 = ivideo->p2_42;
  3234. p2_43 = ivideo->p2_43;
  3235. temp = p2_1f | ((p2_20 & 0xf0) << 4);
  3236. temp += (val * 2);
  3237. p2_1f = temp & 0xff;
  3238. p2_20 = (temp & 0xf00) >> 4;
  3239. p2_2b = ((p2_2b & 0x0f) + (val * 2)) & 0x0f;
  3240. temp = p2_43 | ((p2_42 & 0xf0) << 4);
  3241. temp += (val * 2);
  3242. p2_43 = temp & 0xff;
  3243. p2_42 = (temp & 0xf00) >> 4;
  3244. SiS_SetReg(SISPART2, 0x1f, p2_1f);
  3245. SiS_SetRegANDOR(SISPART2, 0x20, 0x0F, p2_20);
  3246. SiS_SetRegANDOR(SISPART2, 0x2b, 0xF0, p2_2b);
  3247. SiS_SetRegANDOR(SISPART2, 0x42, 0x0F, p2_42);
  3248. SiS_SetReg(SISPART2, 0x43, p2_43);
  3249. }
  3250. }
  3251. }
  3252. static void
  3253. sisfb_set_TVyposoffset(struct sis_video_info *ivideo, int val)
  3254. {
  3255. if(val > 32) val = 32;
  3256. if(val < -32) val = -32;
  3257. ivideo->tvypos = val;
  3258. if(ivideo->sisfblocked) return;
  3259. if(!ivideo->modechanged) return;
  3260. if(ivideo->currentvbflags & CRT2_TV) {
  3261. if(ivideo->vbflags2 & VB2_CHRONTEL) {
  3262. int y = ivideo->tvy;
  3263. switch(ivideo->chronteltype) {
  3264. case 1:
  3265. y -= val;
  3266. if(y < 0) y = 0;
  3267. SiS_SetReg(SISSR, 0x05, 0x86);
  3268. SiS_SetCH700x(&ivideo->SiS_Pr, 0x0b, (y & 0xff));
  3269. SiS_SetCH70xxANDOR(&ivideo->SiS_Pr, 0x08, ((y & 0x0100) >> 8), 0xFE);
  3270. break;
  3271. case 2:
  3272. /* Not supported by hardware */
  3273. break;
  3274. }
  3275. } else if(ivideo->vbflags2 & VB2_SISBRIDGE) {
  3276. char p2_01, p2_02;
  3277. val /= 2;
  3278. p2_01 = ivideo->p2_01;
  3279. p2_02 = ivideo->p2_02;
  3280. p2_01 += val;
  3281. p2_02 += val;
  3282. if(!(ivideo->currentvbflags & (TV_HIVISION | TV_YPBPR))) {
  3283. while((p2_01 <= 0) || (p2_02 <= 0)) {
  3284. p2_01 += 2;
  3285. p2_02 += 2;
  3286. }
  3287. }
  3288. SiS_SetReg(SISPART2, 0x01, p2_01);
  3289. SiS_SetReg(SISPART2, 0x02, p2_02);
  3290. }
  3291. }
  3292. }
  3293. static void
  3294. sisfb_post_setmode(struct sis_video_info *ivideo)
  3295. {
  3296. bool crt1isoff = false;
  3297. bool doit = true;
  3298. #if defined(CONFIG_FB_SIS_300) || defined(CONFIG_FB_SIS_315)
  3299. u8 reg;
  3300. #endif
  3301. #ifdef CONFIG_FB_SIS_315
  3302. u8 reg1;
  3303. #endif
  3304. SiS_SetReg(SISSR, 0x05, 0x86);
  3305. #ifdef CONFIG_FB_SIS_315
  3306. sisfb_fixup_SR11(ivideo);
  3307. #endif
  3308. /* Now we actually HAVE changed the display mode */
  3309. ivideo->modechanged = 1;
  3310. /* We can't switch off CRT1 if bridge is in slave mode */
  3311. if(ivideo->vbflags2 & VB2_VIDEOBRIDGE) {
  3312. if(sisfb_bridgeisslave(ivideo)) doit = false;
  3313. } else
  3314. ivideo->sisfb_crt1off = 0;
  3315. #ifdef CONFIG_FB_SIS_300
  3316. if(ivideo->sisvga_engine == SIS_300_VGA) {
  3317. if((ivideo->sisfb_crt1off) && (doit)) {
  3318. crt1isoff = true;
  3319. reg = 0x00;
  3320. } else {
  3321. crt1isoff = false;
  3322. reg = 0x80;
  3323. }
  3324. SiS_SetRegANDOR(SISCR, 0x17, 0x7f, reg);
  3325. }
  3326. #endif
  3327. #ifdef CONFIG_FB_SIS_315
  3328. if(ivideo->sisvga_engine == SIS_315_VGA) {
  3329. if((ivideo->sisfb_crt1off) && (doit)) {
  3330. crt1isoff = true;
  3331. reg = 0x40;
  3332. reg1 = 0xc0;
  3333. } else {
  3334. crt1isoff = false;
  3335. reg = 0x00;
  3336. reg1 = 0x00;
  3337. }
  3338. SiS_SetRegANDOR(SISCR, ivideo->SiS_Pr.SiS_MyCR63, ~0x40, reg);
  3339. SiS_SetRegANDOR(SISSR, 0x1f, 0x3f, reg1);
  3340. }
  3341. #endif
  3342. if(crt1isoff) {
  3343. ivideo->currentvbflags &= ~VB_DISPTYPE_CRT1;
  3344. ivideo->currentvbflags |= VB_SINGLE_MODE;
  3345. } else {
  3346. ivideo->currentvbflags |= VB_DISPTYPE_CRT1;
  3347. if(ivideo->currentvbflags & VB_DISPTYPE_CRT2) {
  3348. ivideo->currentvbflags |= VB_MIRROR_MODE;
  3349. } else {
  3350. ivideo->currentvbflags |= VB_SINGLE_MODE;
  3351. }
  3352. }
  3353. SiS_SetRegAND(SISSR, IND_SIS_RAMDAC_CONTROL, ~0x04);
  3354. if(ivideo->currentvbflags & CRT2_TV) {
  3355. if(ivideo->vbflags2 & VB2_SISBRIDGE) {
  3356. ivideo->p2_1f = SiS_GetReg(SISPART2, 0x1f);
  3357. ivideo->p2_20 = SiS_GetReg(SISPART2, 0x20);
  3358. ivideo->p2_2b = SiS_GetReg(SISPART2, 0x2b);
  3359. ivideo->p2_42 = SiS_GetReg(SISPART2, 0x42);
  3360. ivideo->p2_43 = SiS_GetReg(SISPART2, 0x43);
  3361. ivideo->p2_01 = SiS_GetReg(SISPART2, 0x01);
  3362. ivideo->p2_02 = SiS_GetReg(SISPART2, 0x02);
  3363. } else if(ivideo->vbflags2 & VB2_CHRONTEL) {
  3364. if(ivideo->chronteltype == 1) {
  3365. ivideo->tvx = SiS_GetCH700x(&ivideo->SiS_Pr, 0x0a);
  3366. ivideo->tvx |= (((SiS_GetCH700x(&ivideo->SiS_Pr, 0x08) & 0x02) >> 1) << 8);
  3367. ivideo->tvy = SiS_GetCH700x(&ivideo->SiS_Pr, 0x0b);
  3368. ivideo->tvy |= ((SiS_GetCH700x(&ivideo->SiS_Pr, 0x08) & 0x01) << 8);
  3369. }
  3370. }
  3371. }
  3372. if(ivideo->tvxpos) {
  3373. sisfb_set_TVxposoffset(ivideo, ivideo->tvxpos);
  3374. }
  3375. if(ivideo->tvypos) {
  3376. sisfb_set_TVyposoffset(ivideo, ivideo->tvypos);
  3377. }
  3378. /* Eventually sync engines */
  3379. sisfb_check_engine_and_sync(ivideo);
  3380. /* (Re-)Initialize chip engines */
  3381. if(ivideo->accel) {
  3382. sisfb_engine_init(ivideo);
  3383. } else {
  3384. ivideo->engineok = 0;
  3385. }
  3386. }
  3387. static int
  3388. sisfb_reset_mode(struct sis_video_info *ivideo)
  3389. {
  3390. if(sisfb_set_mode(ivideo, 0))
  3391. return 1;
  3392. sisfb_set_pitch(ivideo);
  3393. sisfb_set_base_CRT1(ivideo, ivideo->current_base);
  3394. sisfb_set_base_CRT2(ivideo, ivideo->current_base);
  3395. return 0;
  3396. }
  3397. static void
  3398. sisfb_handle_command(struct sis_video_info *ivideo, struct sisfb_cmd *sisfb_command)
  3399. {
  3400. int mycrt1off;
  3401. switch(sisfb_command->sisfb_cmd) {
  3402. case SISFB_CMD_GETVBFLAGS:
  3403. if(!ivideo->modechanged) {
  3404. sisfb_command->sisfb_result[0] = SISFB_CMD_ERR_EARLY;
  3405. } else {
  3406. sisfb_command->sisfb_result[0] = SISFB_CMD_ERR_OK;
  3407. sisfb_command->sisfb_result[1] = ivideo->currentvbflags;
  3408. sisfb_command->sisfb_result[2] = ivideo->vbflags2;
  3409. }
  3410. break;
  3411. case SISFB_CMD_SWITCHCRT1:
  3412. /* arg[0]: 0 = off, 1 = on, 99 = query */
  3413. if(!ivideo->modechanged) {
  3414. sisfb_command->sisfb_result[0] = SISFB_CMD_ERR_EARLY;
  3415. } else if(sisfb_command->sisfb_arg[0] == 99) {
  3416. /* Query */
  3417. sisfb_command->sisfb_result[1] = ivideo->sisfb_crt1off ? 0 : 1;
  3418. sisfb_command->sisfb_result[0] = SISFB_CMD_ERR_OK;
  3419. } else if(ivideo->sisfblocked) {
  3420. sisfb_command->sisfb_result[0] = SISFB_CMD_ERR_LOCKED;
  3421. } else if((!(ivideo->currentvbflags & CRT2_ENABLE)) &&
  3422. (sisfb_command->sisfb_arg[0] == 0)) {
  3423. sisfb_command->sisfb_result[0] = SISFB_CMD_ERR_NOCRT2;
  3424. } else {
  3425. sisfb_command->sisfb_result[0] = SISFB_CMD_ERR_OK;
  3426. mycrt1off = sisfb_command->sisfb_arg[0] ? 0 : 1;
  3427. if( ((ivideo->currentvbflags & VB_DISPTYPE_CRT1) && mycrt1off) ||
  3428. ((!(ivideo->currentvbflags & VB_DISPTYPE_CRT1)) && !mycrt1off) ) {
  3429. ivideo->sisfb_crt1off = mycrt1off;
  3430. if(sisfb_reset_mode(ivideo)) {
  3431. sisfb_command->sisfb_result[0] = SISFB_CMD_ERR_OTHER;
  3432. }
  3433. }
  3434. sisfb_command->sisfb_result[1] = ivideo->sisfb_crt1off ? 0 : 1;
  3435. }
  3436. break;
  3437. /* more to come */
  3438. default:
  3439. sisfb_command->sisfb_result[0] = SISFB_CMD_ERR_UNKNOWN;
  3440. printk(KERN_ERR "sisfb: Unknown command 0x%x\n",
  3441. sisfb_command->sisfb_cmd);
  3442. }
  3443. }
  3444. #ifndef MODULE
  3445. static int __init sisfb_setup(char *options)
  3446. {
  3447. char *this_opt;
  3448. sisfb_setdefaultparms();
  3449. if(!options || !(*options))
  3450. return 0;
  3451. while((this_opt = strsep(&options, ",")) != NULL) {
  3452. if(!(*this_opt)) continue;
  3453. if(!strnicmp(this_opt, "off", 3)) {
  3454. sisfb_off = 1;
  3455. } else if(!strnicmp(this_opt, "forcecrt2type:", 14)) {
  3456. /* Need to check crt2 type first for fstn/dstn */
  3457. sisfb_search_crt2type(this_opt + 14);
  3458. } else if(!strnicmp(this_opt, "tvmode:",7)) {
  3459. sisfb_search_tvstd(this_opt + 7);
  3460. } else if(!strnicmp(this_opt, "tvstandard:",11)) {
  3461. sisfb_search_tvstd(this_opt + 11);
  3462. } else if(!strnicmp(this_opt, "mode:", 5)) {
  3463. sisfb_search_mode(this_opt + 5, false);
  3464. } else if(!strnicmp(this_opt, "vesa:", 5)) {
  3465. sisfb_search_vesamode(simple_strtoul(this_opt + 5, NULL, 0), false);
  3466. } else if(!strnicmp(this_opt, "rate:", 5)) {
  3467. sisfb_parm_rate = simple_strtoul(this_opt + 5, NULL, 0);
  3468. } else if(!strnicmp(this_opt, "forcecrt1:", 10)) {
  3469. sisfb_forcecrt1 = (int)simple_strtoul(this_opt + 10, NULL, 0);
  3470. } else if(!strnicmp(this_opt, "mem:",4)) {
  3471. sisfb_parm_mem = simple_strtoul(this_opt + 4, NULL, 0);
  3472. } else if(!strnicmp(this_opt, "pdc:", 4)) {
  3473. sisfb_pdc = simple_strtoul(this_opt + 4, NULL, 0);
  3474. } else if(!strnicmp(this_opt, "pdc1:", 5)) {
  3475. sisfb_pdca = simple_strtoul(this_opt + 5, NULL, 0);
  3476. } else if(!strnicmp(this_opt, "noaccel", 7)) {
  3477. sisfb_accel = 0;
  3478. } else if(!strnicmp(this_opt, "accel", 5)) {
  3479. sisfb_accel = -1;
  3480. } else if(!strnicmp(this_opt, "noypan", 6)) {
  3481. sisfb_ypan = 0;
  3482. } else if(!strnicmp(this_opt, "ypan", 4)) {
  3483. sisfb_ypan = -1;
  3484. } else if(!strnicmp(this_opt, "nomax", 5)) {
  3485. sisfb_max = 0;
  3486. } else if(!strnicmp(this_opt, "max", 3)) {
  3487. sisfb_max = -1;
  3488. } else if(!strnicmp(this_opt, "userom:", 7)) {
  3489. sisfb_userom = (int)simple_strtoul(this_opt + 7, NULL, 0);
  3490. } else if(!strnicmp(this_opt, "useoem:", 7)) {
  3491. sisfb_useoem = (int)simple_strtoul(this_opt + 7, NULL, 0);
  3492. } else if(!strnicmp(this_opt, "nocrt2rate", 10)) {
  3493. sisfb_nocrt2rate = 1;
  3494. } else if(!strnicmp(this_opt, "scalelcd:", 9)) {
  3495. unsigned long temp = 2;
  3496. temp = simple_strtoul(this_opt + 9, NULL, 0);
  3497. if((temp == 0) || (temp == 1)) {
  3498. sisfb_scalelcd = temp ^ 1;
  3499. }
  3500. } else if(!strnicmp(this_opt, "tvxposoffset:", 13)) {
  3501. int temp = 0;
  3502. temp = (int)simple_strtol(this_opt + 13, NULL, 0);
  3503. if((temp >= -32) && (temp <= 32)) {
  3504. sisfb_tvxposoffset = temp;
  3505. }
  3506. } else if(!strnicmp(this_opt, "tvyposoffset:", 13)) {
  3507. int temp = 0;
  3508. temp = (int)simple_strtol(this_opt + 13, NULL, 0);
  3509. if((temp >= -32) && (temp <= 32)) {
  3510. sisfb_tvyposoffset = temp;
  3511. }
  3512. } else if(!strnicmp(this_opt, "specialtiming:", 14)) {
  3513. sisfb_search_specialtiming(this_opt + 14);
  3514. } else if(!strnicmp(this_opt, "lvdshl:", 7)) {
  3515. int temp = 4;
  3516. temp = simple_strtoul(this_opt + 7, NULL, 0);
  3517. if((temp >= 0) && (temp <= 3)) {
  3518. sisfb_lvdshl = temp;
  3519. }
  3520. } else if(this_opt[0] >= '0' && this_opt[0] <= '9') {
  3521. sisfb_search_mode(this_opt, true);
  3522. #if !defined(__i386__) && !defined(__x86_64__)
  3523. } else if(!strnicmp(this_opt, "resetcard", 9)) {
  3524. sisfb_resetcard = 1;
  3525. } else if(!strnicmp(this_opt, "videoram:", 9)) {
  3526. sisfb_videoram = simple_strtoul(this_opt + 9, NULL, 0);
  3527. #endif
  3528. } else {
  3529. printk(KERN_INFO "sisfb: Invalid option %s\n", this_opt);
  3530. }
  3531. }
  3532. return 0;
  3533. }
  3534. #endif
  3535. static int __devinit
  3536. sisfb_check_rom(void __iomem *rom_base, struct sis_video_info *ivideo)
  3537. {
  3538. void __iomem *rom;
  3539. int romptr;
  3540. if((readb(rom_base) != 0x55) || (readb(rom_base + 1) != 0xaa))
  3541. return 0;
  3542. romptr = (readb(rom_base + 0x18) | (readb(rom_base + 0x19) << 8));
  3543. if(romptr > (0x10000 - 8))
  3544. return 0;
  3545. rom = rom_base + romptr;
  3546. if((readb(rom) != 'P') || (readb(rom + 1) != 'C') ||
  3547. (readb(rom + 2) != 'I') || (readb(rom + 3) != 'R'))
  3548. return 0;
  3549. if((readb(rom + 4) | (readb(rom + 5) << 8)) != ivideo->chip_vendor)
  3550. return 0;
  3551. if((readb(rom + 6) | (readb(rom + 7) << 8)) != ivideo->chip_id)
  3552. return 0;
  3553. return 1;
  3554. }
  3555. static unsigned char * __devinit
  3556. sisfb_find_rom(struct pci_dev *pdev)
  3557. {
  3558. struct sis_video_info *ivideo = pci_get_drvdata(pdev);
  3559. void __iomem *rom_base;
  3560. unsigned char *myrombase = NULL;
  3561. size_t romsize;
  3562. /* First, try the official pci ROM functions (except
  3563. * on integrated chipsets which have no ROM).
  3564. */
  3565. if(!ivideo->nbridge) {
  3566. if((rom_base = pci_map_rom(pdev, &romsize))) {
  3567. if(sisfb_check_rom(rom_base, ivideo)) {
  3568. if((myrombase = vmalloc(65536))) {
  3569. memcpy_fromio(myrombase, rom_base,
  3570. (romsize > 65536) ? 65536 : romsize);
  3571. }
  3572. }
  3573. pci_unmap_rom(pdev, rom_base);
  3574. }
  3575. }
  3576. if(myrombase) return myrombase;
  3577. /* Otherwise do it the conventional way. */
  3578. #if defined(__i386__) || defined(__x86_64__)
  3579. {
  3580. u32 temp;
  3581. for (temp = 0x000c0000; temp < 0x000f0000; temp += 0x00001000) {
  3582. rom_base = ioremap(temp, 65536);
  3583. if (!rom_base)
  3584. continue;
  3585. if (!sisfb_check_rom(rom_base, ivideo)) {
  3586. iounmap(rom_base);
  3587. continue;
  3588. }
  3589. if ((myrombase = vmalloc(65536)))
  3590. memcpy_fromio(myrombase, rom_base, 65536);
  3591. iounmap(rom_base);
  3592. break;
  3593. }
  3594. }
  3595. #endif
  3596. return myrombase;
  3597. }
  3598. static void __devinit
  3599. sisfb_post_map_vram(struct sis_video_info *ivideo, unsigned int *mapsize,
  3600. unsigned int min)
  3601. {
  3602. if (*mapsize < (min << 20))
  3603. return;
  3604. ivideo->video_vbase = ioremap(ivideo->video_base, (*mapsize));
  3605. if(!ivideo->video_vbase) {
  3606. printk(KERN_ERR
  3607. "sisfb: Unable to map maximum video RAM for size detection\n");
  3608. (*mapsize) >>= 1;
  3609. while((!(ivideo->video_vbase = ioremap(ivideo->video_base, (*mapsize))))) {
  3610. (*mapsize) >>= 1;
  3611. if((*mapsize) < (min << 20))
  3612. break;
  3613. }
  3614. if(ivideo->video_vbase) {
  3615. printk(KERN_ERR
  3616. "sisfb: Video RAM size detection limited to %dMB\n",
  3617. (int)((*mapsize) >> 20));
  3618. }
  3619. }
  3620. }
  3621. #ifdef CONFIG_FB_SIS_300
  3622. static int __devinit
  3623. sisfb_post_300_buswidth(struct sis_video_info *ivideo)
  3624. {
  3625. void __iomem *FBAddress = ivideo->video_vbase;
  3626. unsigned short temp;
  3627. unsigned char reg;
  3628. int i, j;
  3629. SiS_SetRegAND(SISSR, 0x15, 0xFB);
  3630. SiS_SetRegOR(SISSR, 0x15, 0x04);
  3631. SiS_SetReg(SISSR, 0x13, 0x00);
  3632. SiS_SetReg(SISSR, 0x14, 0xBF);
  3633. for(i = 0; i < 2; i++) {
  3634. temp = 0x1234;
  3635. for(j = 0; j < 4; j++) {
  3636. writew(temp, FBAddress);
  3637. if(readw(FBAddress) == temp)
  3638. break;
  3639. SiS_SetRegOR(SISSR, 0x3c, 0x01);
  3640. reg = SiS_GetReg(SISSR, 0x05);
  3641. reg = SiS_GetReg(SISSR, 0x05);
  3642. SiS_SetRegAND(SISSR, 0x3c, 0xfe);
  3643. reg = SiS_GetReg(SISSR, 0x05);
  3644. reg = SiS_GetReg(SISSR, 0x05);
  3645. temp++;
  3646. }
  3647. }
  3648. writel(0x01234567L, FBAddress);
  3649. writel(0x456789ABL, (FBAddress + 4));
  3650. writel(0x89ABCDEFL, (FBAddress + 8));
  3651. writel(0xCDEF0123L, (FBAddress + 12));
  3652. reg = SiS_GetReg(SISSR, 0x3b);
  3653. if(reg & 0x01) {
  3654. if(readl((FBAddress + 12)) == 0xCDEF0123L)
  3655. return 4; /* Channel A 128bit */
  3656. }
  3657. if(readl((FBAddress + 4)) == 0x456789ABL)
  3658. return 2; /* Channel B 64bit */
  3659. return 1; /* 32bit */
  3660. }
  3661. static int __devinit
  3662. sisfb_post_300_rwtest(struct sis_video_info *ivideo, int iteration, int buswidth,
  3663. int PseudoRankCapacity, int PseudoAdrPinCount,
  3664. unsigned int mapsize)
  3665. {
  3666. void __iomem *FBAddr = ivideo->video_vbase;
  3667. unsigned short sr14;
  3668. unsigned int k, RankCapacity, PageCapacity, BankNumHigh, BankNumMid;
  3669. unsigned int PhysicalAdrOtherPage, PhysicalAdrHigh, PhysicalAdrHalfPage;
  3670. static const unsigned short SiS_DRAMType[17][5] = {
  3671. {0x0C,0x0A,0x02,0x40,0x39},
  3672. {0x0D,0x0A,0x01,0x40,0x48},
  3673. {0x0C,0x09,0x02,0x20,0x35},
  3674. {0x0D,0x09,0x01,0x20,0x44},
  3675. {0x0C,0x08,0x02,0x10,0x31},
  3676. {0x0D,0x08,0x01,0x10,0x40},
  3677. {0x0C,0x0A,0x01,0x20,0x34},
  3678. {0x0C,0x09,0x01,0x08,0x32},
  3679. {0x0B,0x08,0x02,0x08,0x21},
  3680. {0x0C,0x08,0x01,0x08,0x30},
  3681. {0x0A,0x08,0x02,0x04,0x11},
  3682. {0x0B,0x0A,0x01,0x10,0x28},
  3683. {0x09,0x08,0x02,0x02,0x01},
  3684. {0x0B,0x09,0x01,0x08,0x24},
  3685. {0x0B,0x08,0x01,0x04,0x20},
  3686. {0x0A,0x08,0x01,0x02,0x10},
  3687. {0x09,0x08,0x01,0x01,0x00}
  3688. };
  3689. for(k = 0; k <= 16; k++) {
  3690. RankCapacity = buswidth * SiS_DRAMType[k][3];
  3691. if(RankCapacity != PseudoRankCapacity)
  3692. continue;
  3693. if((SiS_DRAMType[k][2] + SiS_DRAMType[k][0]) > PseudoAdrPinCount)
  3694. continue;
  3695. BankNumHigh = RankCapacity * 16 * iteration - 1;
  3696. if(iteration == 3) { /* Rank No */
  3697. BankNumMid = RankCapacity * 16 - 1;
  3698. } else {
  3699. BankNumMid = RankCapacity * 16 * iteration / 2 - 1;
  3700. }
  3701. PageCapacity = (1 << SiS_DRAMType[k][1]) * buswidth * 4;
  3702. PhysicalAdrHigh = BankNumHigh;
  3703. PhysicalAdrHalfPage = (PageCapacity / 2 + PhysicalAdrHigh) % PageCapacity;
  3704. PhysicalAdrOtherPage = PageCapacity * SiS_DRAMType[k][2] + PhysicalAdrHigh;
  3705. SiS_SetRegAND(SISSR, 0x15, 0xFB); /* Test */
  3706. SiS_SetRegOR(SISSR, 0x15, 0x04); /* Test */
  3707. sr14 = (SiS_DRAMType[k][3] * buswidth) - 1;
  3708. if(buswidth == 4) sr14 |= 0x80;
  3709. else if(buswidth == 2) sr14 |= 0x40;
  3710. SiS_SetReg(SISSR, 0x13, SiS_DRAMType[k][4]);
  3711. SiS_SetReg(SISSR, 0x14, sr14);
  3712. BankNumHigh <<= 16;
  3713. BankNumMid <<= 16;
  3714. if((BankNumHigh + PhysicalAdrHigh >= mapsize) ||
  3715. (BankNumMid + PhysicalAdrHigh >= mapsize) ||
  3716. (BankNumHigh + PhysicalAdrHalfPage >= mapsize) ||
  3717. (BankNumHigh + PhysicalAdrOtherPage >= mapsize))
  3718. continue;
  3719. /* Write data */
  3720. writew(((unsigned short)PhysicalAdrHigh),
  3721. (FBAddr + BankNumHigh + PhysicalAdrHigh));
  3722. writew(((unsigned short)BankNumMid),
  3723. (FBAddr + BankNumMid + PhysicalAdrHigh));
  3724. writew(((unsigned short)PhysicalAdrHalfPage),
  3725. (FBAddr + BankNumHigh + PhysicalAdrHalfPage));
  3726. writew(((unsigned short)PhysicalAdrOtherPage),
  3727. (FBAddr + BankNumHigh + PhysicalAdrOtherPage));
  3728. /* Read data */
  3729. if(readw(FBAddr + BankNumHigh + PhysicalAdrHigh) == PhysicalAdrHigh)
  3730. return 1;
  3731. }
  3732. return 0;
  3733. }
  3734. static void __devinit
  3735. sisfb_post_300_ramsize(struct pci_dev *pdev, unsigned int mapsize)
  3736. {
  3737. struct sis_video_info *ivideo = pci_get_drvdata(pdev);
  3738. int i, j, buswidth;
  3739. int PseudoRankCapacity, PseudoAdrPinCount;
  3740. buswidth = sisfb_post_300_buswidth(ivideo);
  3741. for(i = 6; i >= 0; i--) {
  3742. PseudoRankCapacity = 1 << i;
  3743. for(j = 4; j >= 1; j--) {
  3744. PseudoAdrPinCount = 15 - j;
  3745. if((PseudoRankCapacity * j) <= 64) {
  3746. if(sisfb_post_300_rwtest(ivideo,
  3747. j,
  3748. buswidth,
  3749. PseudoRankCapacity,
  3750. PseudoAdrPinCount,
  3751. mapsize))
  3752. return;
  3753. }
  3754. }
  3755. }
  3756. }
  3757. static void __devinit
  3758. sisfb_post_sis300(struct pci_dev *pdev)
  3759. {
  3760. struct sis_video_info *ivideo = pci_get_drvdata(pdev);
  3761. unsigned char *bios = ivideo->SiS_Pr.VirtualRomBase;
  3762. u8 reg, v1, v2, v3, v4, v5, v6, v7, v8;
  3763. u16 index, rindex, memtype = 0;
  3764. unsigned int mapsize;
  3765. if(!ivideo->SiS_Pr.UseROM)
  3766. bios = NULL;
  3767. SiS_SetReg(SISSR, 0x05, 0x86);
  3768. if(bios) {
  3769. if(bios[0x52] & 0x80) {
  3770. memtype = bios[0x52];
  3771. } else {
  3772. memtype = SiS_GetReg(SISSR, 0x3a);
  3773. }
  3774. memtype &= 0x07;
  3775. }
  3776. v3 = 0x80; v6 = 0x80;
  3777. if(ivideo->revision_id <= 0x13) {
  3778. v1 = 0x44; v2 = 0x42;
  3779. v4 = 0x44; v5 = 0x42;
  3780. } else {
  3781. v1 = 0x68; v2 = 0x43; /* Assume 125Mhz MCLK */
  3782. v4 = 0x68; v5 = 0x43; /* Assume 125Mhz ECLK */
  3783. if(bios) {
  3784. index = memtype * 5;
  3785. rindex = index + 0x54;
  3786. v1 = bios[rindex++];
  3787. v2 = bios[rindex++];
  3788. v3 = bios[rindex++];
  3789. rindex = index + 0x7c;
  3790. v4 = bios[rindex++];
  3791. v5 = bios[rindex++];
  3792. v6 = bios[rindex++];
  3793. }
  3794. }
  3795. SiS_SetReg(SISSR, 0x28, v1);
  3796. SiS_SetReg(SISSR, 0x29, v2);
  3797. SiS_SetReg(SISSR, 0x2a, v3);
  3798. SiS_SetReg(SISSR, 0x2e, v4);
  3799. SiS_SetReg(SISSR, 0x2f, v5);
  3800. SiS_SetReg(SISSR, 0x30, v6);
  3801. v1 = 0x10;
  3802. if(bios)
  3803. v1 = bios[0xa4];
  3804. SiS_SetReg(SISSR, 0x07, v1); /* DAC speed */
  3805. SiS_SetReg(SISSR, 0x11, 0x0f); /* DDC, power save */
  3806. v1 = 0x01; v2 = 0x43; v3 = 0x1e; v4 = 0x2a;
  3807. v5 = 0x06; v6 = 0x00; v7 = 0x00; v8 = 0x00;
  3808. if(bios) {
  3809. memtype += 0xa5;
  3810. v1 = bios[memtype];
  3811. v2 = bios[memtype + 8];
  3812. v3 = bios[memtype + 16];
  3813. v4 = bios[memtype + 24];
  3814. v5 = bios[memtype + 32];
  3815. v6 = bios[memtype + 40];
  3816. v7 = bios[memtype + 48];
  3817. v8 = bios[memtype + 56];
  3818. }
  3819. if(ivideo->revision_id >= 0x80)
  3820. v3 &= 0xfd;
  3821. SiS_SetReg(SISSR, 0x15, v1); /* Ram type (assuming 0, BIOS 0xa5 step 8) */
  3822. SiS_SetReg(SISSR, 0x16, v2);
  3823. SiS_SetReg(SISSR, 0x17, v3);
  3824. SiS_SetReg(SISSR, 0x18, v4);
  3825. SiS_SetReg(SISSR, 0x19, v5);
  3826. SiS_SetReg(SISSR, 0x1a, v6);
  3827. SiS_SetReg(SISSR, 0x1b, v7);
  3828. SiS_SetReg(SISSR, 0x1c, v8); /* ---- */
  3829. SiS_SetRegAND(SISSR, 0x15, 0xfb);
  3830. SiS_SetRegOR(SISSR, 0x15, 0x04);
  3831. if(bios) {
  3832. if(bios[0x53] & 0x02) {
  3833. SiS_SetRegOR(SISSR, 0x19, 0x20);
  3834. }
  3835. }
  3836. v1 = 0x04; /* DAC pedestal (BIOS 0xe5) */
  3837. if(ivideo->revision_id >= 0x80)
  3838. v1 |= 0x01;
  3839. SiS_SetReg(SISSR, 0x1f, v1);
  3840. SiS_SetReg(SISSR, 0x20, 0xa4); /* linear & relocated io & disable a0000 */
  3841. v1 = 0xf6; v2 = 0x0d; v3 = 0x00;
  3842. if(bios) {
  3843. v1 = bios[0xe8];
  3844. v2 = bios[0xe9];
  3845. v3 = bios[0xea];
  3846. }
  3847. SiS_SetReg(SISSR, 0x23, v1);
  3848. SiS_SetReg(SISSR, 0x24, v2);
  3849. SiS_SetReg(SISSR, 0x25, v3);
  3850. SiS_SetReg(SISSR, 0x21, 0x84);
  3851. SiS_SetReg(SISSR, 0x22, 0x00);
  3852. SiS_SetReg(SISCR, 0x37, 0x00);
  3853. SiS_SetRegOR(SISPART1, 0x24, 0x01); /* unlock crt2 */
  3854. SiS_SetReg(SISPART1, 0x00, 0x00);
  3855. v1 = 0x40; v2 = 0x11;
  3856. if(bios) {
  3857. v1 = bios[0xec];
  3858. v2 = bios[0xeb];
  3859. }
  3860. SiS_SetReg(SISPART1, 0x02, v1);
  3861. if(ivideo->revision_id >= 0x80)
  3862. v2 &= ~0x01;
  3863. reg = SiS_GetReg(SISPART4, 0x00);
  3864. if((reg == 1) || (reg == 2)) {
  3865. SiS_SetReg(SISCR, 0x37, 0x02);
  3866. SiS_SetReg(SISPART2, 0x00, 0x1c);
  3867. v4 = 0x00; v5 = 0x00; v6 = 0x10;
  3868. if(ivideo->SiS_Pr.UseROM) {
  3869. v4 = bios[0xf5];
  3870. v5 = bios[0xf6];
  3871. v6 = bios[0xf7];
  3872. }
  3873. SiS_SetReg(SISPART4, 0x0d, v4);
  3874. SiS_SetReg(SISPART4, 0x0e, v5);
  3875. SiS_SetReg(SISPART4, 0x10, v6);
  3876. SiS_SetReg(SISPART4, 0x0f, 0x3f);
  3877. reg = SiS_GetReg(SISPART4, 0x01);
  3878. if(reg >= 0xb0) {
  3879. reg = SiS_GetReg(SISPART4, 0x23);
  3880. reg &= 0x20;
  3881. reg <<= 1;
  3882. SiS_SetReg(SISPART4, 0x23, reg);
  3883. }
  3884. } else {
  3885. v2 &= ~0x10;
  3886. }
  3887. SiS_SetReg(SISSR, 0x32, v2);
  3888. SiS_SetRegAND(SISPART1, 0x24, 0xfe); /* Lock CRT2 */
  3889. reg = SiS_GetReg(SISSR, 0x16);
  3890. reg &= 0xc3;
  3891. SiS_SetReg(SISCR, 0x35, reg);
  3892. SiS_SetReg(SISCR, 0x83, 0x00);
  3893. #if !defined(__i386__) && !defined(__x86_64__)
  3894. if(sisfb_videoram) {
  3895. SiS_SetReg(SISSR, 0x13, 0x28); /* ? */
  3896. reg = ((sisfb_videoram >> 10) - 1) | 0x40;
  3897. SiS_SetReg(SISSR, 0x14, reg);
  3898. } else {
  3899. #endif
  3900. /* Need to map max FB size for finding out about RAM size */
  3901. mapsize = ivideo->video_size;
  3902. sisfb_post_map_vram(ivideo, &mapsize, 4);
  3903. if(ivideo->video_vbase) {
  3904. sisfb_post_300_ramsize(pdev, mapsize);
  3905. iounmap(ivideo->video_vbase);
  3906. } else {
  3907. printk(KERN_DEBUG
  3908. "sisfb: Failed to map memory for size detection, assuming 8MB\n");
  3909. SiS_SetReg(SISSR, 0x13, 0x28); /* ? */
  3910. SiS_SetReg(SISSR, 0x14, 0x47); /* 8MB, 64bit default */
  3911. }
  3912. #if !defined(__i386__) && !defined(__x86_64__)
  3913. }
  3914. #endif
  3915. if(bios) {
  3916. v1 = bios[0xe6];
  3917. v2 = bios[0xe7];
  3918. } else {
  3919. reg = SiS_GetReg(SISSR, 0x3a);
  3920. if((reg & 0x30) == 0x30) {
  3921. v1 = 0x04; /* PCI */
  3922. v2 = 0x92;
  3923. } else {
  3924. v1 = 0x14; /* AGP */
  3925. v2 = 0xb2;
  3926. }
  3927. }
  3928. SiS_SetReg(SISSR, 0x21, v1);
  3929. SiS_SetReg(SISSR, 0x22, v2);
  3930. /* Sense CRT1 */
  3931. sisfb_sense_crt1(ivideo);
  3932. /* Set default mode, don't clear screen */
  3933. ivideo->SiS_Pr.SiS_UseOEM = false;
  3934. SiS_SetEnableDstn(&ivideo->SiS_Pr, false);
  3935. SiS_SetEnableFstn(&ivideo->SiS_Pr, false);
  3936. ivideo->curFSTN = ivideo->curDSTN = 0;
  3937. ivideo->SiS_Pr.VideoMemorySize = 8 << 20;
  3938. SiSSetMode(&ivideo->SiS_Pr, 0x2e | 0x80);
  3939. SiS_SetReg(SISSR, 0x05, 0x86);
  3940. /* Display off */
  3941. SiS_SetRegOR(SISSR, 0x01, 0x20);
  3942. /* Save mode number in CR34 */
  3943. SiS_SetReg(SISCR, 0x34, 0x2e);
  3944. /* Let everyone know what the current mode is */
  3945. ivideo->modeprechange = 0x2e;
  3946. }
  3947. #endif
  3948. #ifdef CONFIG_FB_SIS_315
  3949. #if 0
  3950. static void __devinit
  3951. sisfb_post_sis315330(struct pci_dev *pdev)
  3952. {
  3953. /* TODO */
  3954. }
  3955. #endif
  3956. static inline int sisfb_xgi_is21(struct sis_video_info *ivideo)
  3957. {
  3958. return ivideo->chip_real_id == XGI_21;
  3959. }
  3960. static void __devinit
  3961. sisfb_post_xgi_delay(struct sis_video_info *ivideo, int delay)
  3962. {
  3963. unsigned int i;
  3964. u8 reg;
  3965. for(i = 0; i <= (delay * 10 * 36); i++) {
  3966. reg = SiS_GetReg(SISSR, 0x05);
  3967. reg++;
  3968. }
  3969. }
  3970. static int __devinit
  3971. sisfb_find_host_bridge(struct sis_video_info *ivideo, struct pci_dev *mypdev,
  3972. unsigned short pcivendor)
  3973. {
  3974. struct pci_dev *pdev = NULL;
  3975. unsigned short temp;
  3976. int ret = 0;
  3977. while((pdev = pci_get_class(PCI_CLASS_BRIDGE_HOST, pdev))) {
  3978. temp = pdev->vendor;
  3979. if(temp == pcivendor) {
  3980. ret = 1;
  3981. pci_dev_put(pdev);
  3982. break;
  3983. }
  3984. }
  3985. return ret;
  3986. }
  3987. static int __devinit
  3988. sisfb_post_xgi_rwtest(struct sis_video_info *ivideo, int starta,
  3989. unsigned int enda, unsigned int mapsize)
  3990. {
  3991. unsigned int pos;
  3992. int i;
  3993. writel(0, ivideo->video_vbase);
  3994. for(i = starta; i <= enda; i++) {
  3995. pos = 1 << i;
  3996. if(pos < mapsize)
  3997. writel(pos, ivideo->video_vbase + pos);
  3998. }
  3999. sisfb_post_xgi_delay(ivideo, 150);
  4000. if(readl(ivideo->video_vbase) != 0)
  4001. return 0;
  4002. for(i = starta; i <= enda; i++) {
  4003. pos = 1 << i;
  4004. if(pos < mapsize) {
  4005. if(readl(ivideo->video_vbase + pos) != pos)
  4006. return 0;
  4007. } else
  4008. return 0;
  4009. }
  4010. return 1;
  4011. }
  4012. static int __devinit
  4013. sisfb_post_xgi_ramsize(struct sis_video_info *ivideo)
  4014. {
  4015. unsigned int buswidth, ranksize, channelab, mapsize;
  4016. int i, j, k, l, status;
  4017. u8 reg, sr14;
  4018. static const u8 dramsr13[12 * 5] = {
  4019. 0x02, 0x0e, 0x0b, 0x80, 0x5d,
  4020. 0x02, 0x0e, 0x0a, 0x40, 0x59,
  4021. 0x02, 0x0d, 0x0b, 0x40, 0x4d,
  4022. 0x02, 0x0e, 0x09, 0x20, 0x55,
  4023. 0x02, 0x0d, 0x0a, 0x20, 0x49,
  4024. 0x02, 0x0c, 0x0b, 0x20, 0x3d,
  4025. 0x02, 0x0e, 0x08, 0x10, 0x51,
  4026. 0x02, 0x0d, 0x09, 0x10, 0x45,
  4027. 0x02, 0x0c, 0x0a, 0x10, 0x39,
  4028. 0x02, 0x0d, 0x08, 0x08, 0x41,
  4029. 0x02, 0x0c, 0x09, 0x08, 0x35,
  4030. 0x02, 0x0c, 0x08, 0x04, 0x31
  4031. };
  4032. static const u8 dramsr13_4[4 * 5] = {
  4033. 0x02, 0x0d, 0x09, 0x40, 0x45,
  4034. 0x02, 0x0c, 0x09, 0x20, 0x35,
  4035. 0x02, 0x0c, 0x08, 0x10, 0x31,
  4036. 0x02, 0x0b, 0x08, 0x08, 0x21
  4037. };
  4038. /* Enable linear mode, disable 0xa0000 address decoding */
  4039. /* We disable a0000 address decoding, because
  4040. * - if running on x86, if the card is disabled, it means
  4041. * that another card is in the system. We don't want
  4042. * to interphere with that primary card's textmode.
  4043. * - if running on non-x86, there usually is no VGA window
  4044. * at a0000.
  4045. */
  4046. SiS_SetRegOR(SISSR, 0x20, (0x80 | 0x04));
  4047. /* Need to map max FB size for finding out about RAM size */
  4048. mapsize = ivideo->video_size;
  4049. sisfb_post_map_vram(ivideo, &mapsize, 32);
  4050. if(!ivideo->video_vbase) {
  4051. printk(KERN_ERR "sisfb: Unable to detect RAM size. Setting default.\n");
  4052. SiS_SetReg(SISSR, 0x13, 0x35);
  4053. SiS_SetReg(SISSR, 0x14, 0x41);
  4054. /* TODO */
  4055. return -ENOMEM;
  4056. }
  4057. /* Non-interleaving */
  4058. SiS_SetReg(SISSR, 0x15, 0x00);
  4059. /* No tiling */
  4060. SiS_SetReg(SISSR, 0x1c, 0x00);
  4061. if(ivideo->chip == XGI_20) {
  4062. channelab = 1;
  4063. reg = SiS_GetReg(SISCR, 0x97);
  4064. if(!(reg & 0x01)) { /* Single 32/16 */
  4065. buswidth = 32;
  4066. SiS_SetReg(SISSR, 0x13, 0xb1);
  4067. SiS_SetReg(SISSR, 0x14, 0x52);
  4068. sisfb_post_xgi_delay(ivideo, 1);
  4069. sr14 = 0x02;
  4070. if(sisfb_post_xgi_rwtest(ivideo, 23, 24, mapsize))
  4071. goto bail_out;
  4072. SiS_SetReg(SISSR, 0x13, 0x31);
  4073. SiS_SetReg(SISSR, 0x14, 0x42);
  4074. sisfb_post_xgi_delay(ivideo, 1);
  4075. if(sisfb_post_xgi_rwtest(ivideo, 23, 23, mapsize))
  4076. goto bail_out;
  4077. buswidth = 16;
  4078. SiS_SetReg(SISSR, 0x13, 0xb1);
  4079. SiS_SetReg(SISSR, 0x14, 0x41);
  4080. sisfb_post_xgi_delay(ivideo, 1);
  4081. sr14 = 0x01;
  4082. if(sisfb_post_xgi_rwtest(ivideo, 22, 23, mapsize))
  4083. goto bail_out;
  4084. else
  4085. SiS_SetReg(SISSR, 0x13, 0x31);
  4086. } else { /* Dual 16/8 */
  4087. buswidth = 16;
  4088. SiS_SetReg(SISSR, 0x13, 0xb1);
  4089. SiS_SetReg(SISSR, 0x14, 0x41);
  4090. sisfb_post_xgi_delay(ivideo, 1);
  4091. sr14 = 0x01;
  4092. if(sisfb_post_xgi_rwtest(ivideo, 22, 23, mapsize))
  4093. goto bail_out;
  4094. SiS_SetReg(SISSR, 0x13, 0x31);
  4095. SiS_SetReg(SISSR, 0x14, 0x31);
  4096. sisfb_post_xgi_delay(ivideo, 1);
  4097. if(sisfb_post_xgi_rwtest(ivideo, 22, 22, mapsize))
  4098. goto bail_out;
  4099. buswidth = 8;
  4100. SiS_SetReg(SISSR, 0x13, 0xb1);
  4101. SiS_SetReg(SISSR, 0x14, 0x30);
  4102. sisfb_post_xgi_delay(ivideo, 1);
  4103. sr14 = 0x00;
  4104. if(sisfb_post_xgi_rwtest(ivideo, 21, 22, mapsize))
  4105. goto bail_out;
  4106. else
  4107. SiS_SetReg(SISSR, 0x13, 0x31);
  4108. }
  4109. } else { /* XGI_40 */
  4110. reg = SiS_GetReg(SISCR, 0x97);
  4111. if(!(reg & 0x10)) {
  4112. reg = SiS_GetReg(SISSR, 0x39);
  4113. reg >>= 1;
  4114. }
  4115. if(reg & 0x01) { /* DDRII */
  4116. buswidth = 32;
  4117. if(ivideo->revision_id == 2) {
  4118. channelab = 2;
  4119. SiS_SetReg(SISSR, 0x13, 0xa1);
  4120. SiS_SetReg(SISSR, 0x14, 0x44);
  4121. sr14 = 0x04;
  4122. sisfb_post_xgi_delay(ivideo, 1);
  4123. if(sisfb_post_xgi_rwtest(ivideo, 23, 24, mapsize))
  4124. goto bail_out;
  4125. SiS_SetReg(SISSR, 0x13, 0x21);
  4126. SiS_SetReg(SISSR, 0x14, 0x34);
  4127. if(sisfb_post_xgi_rwtest(ivideo, 22, 23, mapsize))
  4128. goto bail_out;
  4129. channelab = 1;
  4130. SiS_SetReg(SISSR, 0x13, 0xa1);
  4131. SiS_SetReg(SISSR, 0x14, 0x40);
  4132. sr14 = 0x00;
  4133. if(sisfb_post_xgi_rwtest(ivideo, 22, 23, mapsize))
  4134. goto bail_out;
  4135. SiS_SetReg(SISSR, 0x13, 0x21);
  4136. SiS_SetReg(SISSR, 0x14, 0x30);
  4137. } else {
  4138. channelab = 3;
  4139. SiS_SetReg(SISSR, 0x13, 0xa1);
  4140. SiS_SetReg(SISSR, 0x14, 0x4c);
  4141. sr14 = 0x0c;
  4142. sisfb_post_xgi_delay(ivideo, 1);
  4143. if(sisfb_post_xgi_rwtest(ivideo, 23, 25, mapsize))
  4144. goto bail_out;
  4145. channelab = 2;
  4146. SiS_SetReg(SISSR, 0x14, 0x48);
  4147. sisfb_post_xgi_delay(ivideo, 1);
  4148. sr14 = 0x08;
  4149. if(sisfb_post_xgi_rwtest(ivideo, 23, 24, mapsize))
  4150. goto bail_out;
  4151. SiS_SetReg(SISSR, 0x13, 0x21);
  4152. SiS_SetReg(SISSR, 0x14, 0x3c);
  4153. sr14 = 0x0c;
  4154. if(sisfb_post_xgi_rwtest(ivideo, 23, 24, mapsize)) {
  4155. channelab = 3;
  4156. } else {
  4157. channelab = 2;
  4158. SiS_SetReg(SISSR, 0x14, 0x38);
  4159. sr14 = 0x08;
  4160. }
  4161. }
  4162. sisfb_post_xgi_delay(ivideo, 1);
  4163. } else { /* DDR */
  4164. buswidth = 64;
  4165. if(ivideo->revision_id == 2) {
  4166. channelab = 1;
  4167. SiS_SetReg(SISSR, 0x13, 0xa1);
  4168. SiS_SetReg(SISSR, 0x14, 0x52);
  4169. sisfb_post_xgi_delay(ivideo, 1);
  4170. sr14 = 0x02;
  4171. if(sisfb_post_xgi_rwtest(ivideo, 23, 24, mapsize))
  4172. goto bail_out;
  4173. SiS_SetReg(SISSR, 0x13, 0x21);
  4174. SiS_SetReg(SISSR, 0x14, 0x42);
  4175. } else {
  4176. channelab = 2;
  4177. SiS_SetReg(SISSR, 0x13, 0xa1);
  4178. SiS_SetReg(SISSR, 0x14, 0x5a);
  4179. sisfb_post_xgi_delay(ivideo, 1);
  4180. sr14 = 0x0a;
  4181. if(sisfb_post_xgi_rwtest(ivideo, 24, 25, mapsize))
  4182. goto bail_out;
  4183. SiS_SetReg(SISSR, 0x13, 0x21);
  4184. SiS_SetReg(SISSR, 0x14, 0x4a);
  4185. }
  4186. sisfb_post_xgi_delay(ivideo, 1);
  4187. }
  4188. }
  4189. bail_out:
  4190. SiS_SetRegANDOR(SISSR, 0x14, 0xf0, sr14);
  4191. sisfb_post_xgi_delay(ivideo, 1);
  4192. j = (ivideo->chip == XGI_20) ? 5 : 9;
  4193. k = (ivideo->chip == XGI_20) ? 12 : 4;
  4194. status = -EIO;
  4195. for(i = 0; i < k; i++) {
  4196. reg = (ivideo->chip == XGI_20) ?
  4197. dramsr13[(i * 5) + 4] : dramsr13_4[(i * 5) + 4];
  4198. SiS_SetRegANDOR(SISSR, 0x13, 0x80, reg);
  4199. sisfb_post_xgi_delay(ivideo, 50);
  4200. ranksize = (ivideo->chip == XGI_20) ?
  4201. dramsr13[(i * 5) + 3] : dramsr13_4[(i * 5) + 3];
  4202. reg = SiS_GetReg(SISSR, 0x13);
  4203. if(reg & 0x80) ranksize <<= 1;
  4204. if(ivideo->chip == XGI_20) {
  4205. if(buswidth == 16) ranksize <<= 1;
  4206. else if(buswidth == 32) ranksize <<= 2;
  4207. } else {
  4208. if(buswidth == 64) ranksize <<= 1;
  4209. }
  4210. reg = 0;
  4211. l = channelab;
  4212. if(l == 3) l = 4;
  4213. if((ranksize * l) <= 256) {
  4214. while((ranksize >>= 1)) reg += 0x10;
  4215. }
  4216. if(!reg) continue;
  4217. SiS_SetRegANDOR(SISSR, 0x14, 0x0f, (reg & 0xf0));
  4218. sisfb_post_xgi_delay(ivideo, 1);
  4219. if (sisfb_post_xgi_rwtest(ivideo, j, ((reg >> 4) + channelab - 2 + 20), mapsize)) {
  4220. status = 0;
  4221. break;
  4222. }
  4223. }
  4224. iounmap(ivideo->video_vbase);
  4225. return status;
  4226. }
  4227. static void __devinit
  4228. sisfb_post_xgi_setclocks(struct sis_video_info *ivideo, u8 regb)
  4229. {
  4230. u8 v1, v2, v3;
  4231. int index;
  4232. static const u8 cs90[8 * 3] = {
  4233. 0x16, 0x01, 0x01,
  4234. 0x3e, 0x03, 0x01,
  4235. 0x7c, 0x08, 0x01,
  4236. 0x79, 0x06, 0x01,
  4237. 0x29, 0x01, 0x81,
  4238. 0x5c, 0x23, 0x01,
  4239. 0x5c, 0x23, 0x01,
  4240. 0x5c, 0x23, 0x01
  4241. };
  4242. static const u8 csb8[8 * 3] = {
  4243. 0x5c, 0x23, 0x01,
  4244. 0x29, 0x01, 0x01,
  4245. 0x7c, 0x08, 0x01,
  4246. 0x79, 0x06, 0x01,
  4247. 0x29, 0x01, 0x81,
  4248. 0x5c, 0x23, 0x01,
  4249. 0x5c, 0x23, 0x01,
  4250. 0x5c, 0x23, 0x01
  4251. };
  4252. regb = 0; /* ! */
  4253. index = regb * 3;
  4254. v1 = cs90[index]; v2 = cs90[index + 1]; v3 = cs90[index + 2];
  4255. if(ivideo->haveXGIROM) {
  4256. v1 = ivideo->bios_abase[0x90 + index];
  4257. v2 = ivideo->bios_abase[0x90 + index + 1];
  4258. v3 = ivideo->bios_abase[0x90 + index + 2];
  4259. }
  4260. SiS_SetReg(SISSR, 0x28, v1);
  4261. SiS_SetReg(SISSR, 0x29, v2);
  4262. SiS_SetReg(SISSR, 0x2a, v3);
  4263. sisfb_post_xgi_delay(ivideo, 0x43);
  4264. sisfb_post_xgi_delay(ivideo, 0x43);
  4265. sisfb_post_xgi_delay(ivideo, 0x43);
  4266. index = regb * 3;
  4267. v1 = csb8[index]; v2 = csb8[index + 1]; v3 = csb8[index + 2];
  4268. if(ivideo->haveXGIROM) {
  4269. v1 = ivideo->bios_abase[0xb8 + index];
  4270. v2 = ivideo->bios_abase[0xb8 + index + 1];
  4271. v3 = ivideo->bios_abase[0xb8 + index + 2];
  4272. }
  4273. SiS_SetReg(SISSR, 0x2e, v1);
  4274. SiS_SetReg(SISSR, 0x2f, v2);
  4275. SiS_SetReg(SISSR, 0x30, v3);
  4276. sisfb_post_xgi_delay(ivideo, 0x43);
  4277. sisfb_post_xgi_delay(ivideo, 0x43);
  4278. sisfb_post_xgi_delay(ivideo, 0x43);
  4279. }
  4280. static void __devinit
  4281. sisfb_post_xgi_ddr2_mrs_default(struct sis_video_info *ivideo, u8 regb)
  4282. {
  4283. unsigned char *bios = ivideo->bios_abase;
  4284. u8 v1;
  4285. SiS_SetReg(SISSR, 0x28, 0x64);
  4286. SiS_SetReg(SISSR, 0x29, 0x63);
  4287. sisfb_post_xgi_delay(ivideo, 15);
  4288. SiS_SetReg(SISSR, 0x18, 0x00);
  4289. SiS_SetReg(SISSR, 0x19, 0x20);
  4290. SiS_SetReg(SISSR, 0x16, 0x00);
  4291. SiS_SetReg(SISSR, 0x16, 0x80);
  4292. SiS_SetReg(SISSR, 0x18, 0xc5);
  4293. SiS_SetReg(SISSR, 0x19, 0x23);
  4294. SiS_SetReg(SISSR, 0x16, 0x00);
  4295. SiS_SetReg(SISSR, 0x16, 0x80);
  4296. sisfb_post_xgi_delay(ivideo, 1);
  4297. SiS_SetReg(SISCR, 0x97, 0x11);
  4298. sisfb_post_xgi_setclocks(ivideo, regb);
  4299. sisfb_post_xgi_delay(ivideo, 0x46);
  4300. SiS_SetReg(SISSR, 0x18, 0xc5);
  4301. SiS_SetReg(SISSR, 0x19, 0x23);
  4302. SiS_SetReg(SISSR, 0x16, 0x00);
  4303. SiS_SetReg(SISSR, 0x16, 0x80);
  4304. sisfb_post_xgi_delay(ivideo, 1);
  4305. SiS_SetReg(SISSR, 0x1b, 0x04);
  4306. sisfb_post_xgi_delay(ivideo, 1);
  4307. SiS_SetReg(SISSR, 0x1b, 0x00);
  4308. sisfb_post_xgi_delay(ivideo, 1);
  4309. v1 = 0x31;
  4310. if (ivideo->haveXGIROM) {
  4311. v1 = bios[0xf0];
  4312. }
  4313. SiS_SetReg(SISSR, 0x18, v1);
  4314. SiS_SetReg(SISSR, 0x19, 0x06);
  4315. SiS_SetReg(SISSR, 0x16, 0x04);
  4316. SiS_SetReg(SISSR, 0x16, 0x84);
  4317. sisfb_post_xgi_delay(ivideo, 1);
  4318. }
  4319. static void __devinit
  4320. sisfb_post_xgi_ddr2_mrs_xg21(struct sis_video_info *ivideo)
  4321. {
  4322. sisfb_post_xgi_setclocks(ivideo, 1);
  4323. SiS_SetReg(SISCR, 0x97, 0x11);
  4324. sisfb_post_xgi_delay(ivideo, 0x46);
  4325. SiS_SetReg(SISSR, 0x18, 0x00); /* EMRS2 */
  4326. SiS_SetReg(SISSR, 0x19, 0x80);
  4327. SiS_SetReg(SISSR, 0x16, 0x05);
  4328. SiS_SetReg(SISSR, 0x16, 0x85);
  4329. SiS_SetReg(SISSR, 0x18, 0x00); /* EMRS3 */
  4330. SiS_SetReg(SISSR, 0x19, 0xc0);
  4331. SiS_SetReg(SISSR, 0x16, 0x05);
  4332. SiS_SetReg(SISSR, 0x16, 0x85);
  4333. SiS_SetReg(SISSR, 0x18, 0x00); /* EMRS1 */
  4334. SiS_SetReg(SISSR, 0x19, 0x40);
  4335. SiS_SetReg(SISSR, 0x16, 0x05);
  4336. SiS_SetReg(SISSR, 0x16, 0x85);
  4337. SiS_SetReg(SISSR, 0x18, 0x42); /* MRS1 */
  4338. SiS_SetReg(SISSR, 0x19, 0x02);
  4339. SiS_SetReg(SISSR, 0x16, 0x05);
  4340. SiS_SetReg(SISSR, 0x16, 0x85);
  4341. sisfb_post_xgi_delay(ivideo, 1);
  4342. SiS_SetReg(SISSR, 0x1b, 0x04);
  4343. sisfb_post_xgi_delay(ivideo, 1);
  4344. SiS_SetReg(SISSR, 0x1b, 0x00);
  4345. sisfb_post_xgi_delay(ivideo, 1);
  4346. SiS_SetReg(SISSR, 0x18, 0x42); /* MRS1 */
  4347. SiS_SetReg(SISSR, 0x19, 0x00);
  4348. SiS_SetReg(SISSR, 0x16, 0x05);
  4349. SiS_SetReg(SISSR, 0x16, 0x85);
  4350. sisfb_post_xgi_delay(ivideo, 1);
  4351. }
  4352. static void __devinit
  4353. sisfb_post_xgi_ddr2(struct sis_video_info *ivideo, u8 regb)
  4354. {
  4355. unsigned char *bios = ivideo->bios_abase;
  4356. static const u8 cs158[8] = {
  4357. 0x88, 0xaa, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00
  4358. };
  4359. static const u8 cs160[8] = {
  4360. 0x44, 0x77, 0x77, 0x00, 0x00, 0x00, 0x00, 0x00
  4361. };
  4362. static const u8 cs168[8] = {
  4363. 0x48, 0x78, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00
  4364. };
  4365. u8 reg;
  4366. u8 v1;
  4367. u8 v2;
  4368. u8 v3;
  4369. SiS_SetReg(SISCR, 0xb0, 0x80); /* DDR2 dual frequency mode */
  4370. SiS_SetReg(SISCR, 0x82, 0x77);
  4371. SiS_SetReg(SISCR, 0x86, 0x00);
  4372. reg = SiS_GetReg(SISCR, 0x86);
  4373. SiS_SetReg(SISCR, 0x86, 0x88);
  4374. reg = SiS_GetReg(SISCR, 0x86);
  4375. v1 = cs168[regb]; v2 = cs160[regb]; v3 = cs158[regb];
  4376. if (ivideo->haveXGIROM) {
  4377. v1 = bios[regb + 0x168];
  4378. v2 = bios[regb + 0x160];
  4379. v3 = bios[regb + 0x158];
  4380. }
  4381. SiS_SetReg(SISCR, 0x86, v1);
  4382. SiS_SetReg(SISCR, 0x82, 0x77);
  4383. SiS_SetReg(SISCR, 0x85, 0x00);
  4384. reg = SiS_GetReg(SISCR, 0x85);
  4385. SiS_SetReg(SISCR, 0x85, 0x88);
  4386. reg = SiS_GetReg(SISCR, 0x85);
  4387. SiS_SetReg(SISCR, 0x85, v2);
  4388. SiS_SetReg(SISCR, 0x82, v3);
  4389. SiS_SetReg(SISCR, 0x98, 0x01);
  4390. SiS_SetReg(SISCR, 0x9a, 0x02);
  4391. if (sisfb_xgi_is21(ivideo))
  4392. sisfb_post_xgi_ddr2_mrs_xg21(ivideo);
  4393. else
  4394. sisfb_post_xgi_ddr2_mrs_default(ivideo, regb);
  4395. }
  4396. static u8 __devinit
  4397. sisfb_post_xgi_ramtype(struct sis_video_info *ivideo)
  4398. {
  4399. unsigned char *bios = ivideo->bios_abase;
  4400. u8 ramtype;
  4401. u8 reg;
  4402. u8 v1;
  4403. ramtype = 0x00; v1 = 0x10;
  4404. if (ivideo->haveXGIROM) {
  4405. ramtype = bios[0x62];
  4406. v1 = bios[0x1d2];
  4407. }
  4408. if (!(ramtype & 0x80)) {
  4409. if (sisfb_xgi_is21(ivideo)) {
  4410. SiS_SetRegAND(SISCR, 0xb4, 0xfd); /* GPIO control */
  4411. SiS_SetRegOR(SISCR, 0x4a, 0x80); /* GPIOH EN */
  4412. reg = SiS_GetReg(SISCR, 0x48);
  4413. SiS_SetRegOR(SISCR, 0xb4, 0x02);
  4414. ramtype = reg & 0x01; /* GPIOH */
  4415. } else if (ivideo->chip == XGI_20) {
  4416. SiS_SetReg(SISCR, 0x97, v1);
  4417. reg = SiS_GetReg(SISCR, 0x97);
  4418. if (reg & 0x10) {
  4419. ramtype = (reg & 0x01) << 1;
  4420. }
  4421. } else {
  4422. reg = SiS_GetReg(SISSR, 0x39);
  4423. ramtype = reg & 0x02;
  4424. if (!(ramtype)) {
  4425. reg = SiS_GetReg(SISSR, 0x3a);
  4426. ramtype = (reg >> 1) & 0x01;
  4427. }
  4428. }
  4429. }
  4430. ramtype &= 0x07;
  4431. return ramtype;
  4432. }
  4433. static int __devinit
  4434. sisfb_post_xgi(struct pci_dev *pdev)
  4435. {
  4436. struct sis_video_info *ivideo = pci_get_drvdata(pdev);
  4437. unsigned char *bios = ivideo->bios_abase;
  4438. struct pci_dev *mypdev = NULL;
  4439. const u8 *ptr, *ptr2;
  4440. u8 v1, v2, v3, v4, v5, reg, ramtype;
  4441. u32 rega, regb, regd;
  4442. int i, j, k, index;
  4443. static const u8 cs78[3] = { 0xf6, 0x0d, 0x00 };
  4444. static const u8 cs76[2] = { 0xa3, 0xfb };
  4445. static const u8 cs7b[3] = { 0xc0, 0x11, 0x00 };
  4446. static const u8 cs158[8] = {
  4447. 0x88, 0xaa, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00
  4448. };
  4449. static const u8 cs160[8] = {
  4450. 0x44, 0x77, 0x77, 0x00, 0x00, 0x00, 0x00, 0x00
  4451. };
  4452. static const u8 cs168[8] = {
  4453. 0x48, 0x78, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00
  4454. };
  4455. static const u8 cs128[3 * 8] = {
  4456. 0x90, 0x28, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00,
  4457. 0x77, 0x44, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00,
  4458. 0x77, 0x44, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00
  4459. };
  4460. static const u8 cs148[2 * 8] = {
  4461. 0x55, 0x55, 0x55, 0x00, 0x00, 0x00, 0x00, 0x00,
  4462. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  4463. };
  4464. static const u8 cs31a[8 * 4] = {
  4465. 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
  4466. 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00,
  4467. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  4468. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  4469. };
  4470. static const u8 cs33a[8 * 4] = {
  4471. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  4472. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  4473. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  4474. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  4475. };
  4476. static const u8 cs45a[8 * 2] = {
  4477. 0x00, 0x00, 0xa0, 0x00, 0xa0, 0x00, 0x00, 0x00,
  4478. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  4479. };
  4480. static const u8 cs170[7 * 8] = {
  4481. 0x54, 0x32, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00,
  4482. 0x54, 0x43, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00,
  4483. 0x0a, 0x05, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
  4484. 0x44, 0x34, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00,
  4485. 0x10, 0x0a, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00,
  4486. 0x11, 0x0c, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00,
  4487. 0x05, 0x05, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00
  4488. };
  4489. static const u8 cs1a8[3 * 8] = {
  4490. 0xf0, 0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00,
  4491. 0x05, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
  4492. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  4493. };
  4494. static const u8 cs100[2 * 8] = {
  4495. 0xc4, 0x04, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00,
  4496. 0xc4, 0x04, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00
  4497. };
  4498. /* VGA enable */
  4499. reg = SiS_GetRegByte(SISVGAENABLE) | 0x01;
  4500. SiS_SetRegByte(SISVGAENABLE, reg);
  4501. /* Misc */
  4502. reg = SiS_GetRegByte(SISMISCR) | 0x01;
  4503. SiS_SetRegByte(SISMISCW, reg);
  4504. /* Unlock SR */
  4505. SiS_SetReg(SISSR, 0x05, 0x86);
  4506. reg = SiS_GetReg(SISSR, 0x05);
  4507. if(reg != 0xa1)
  4508. return 0;
  4509. /* Clear some regs */
  4510. for(i = 0; i < 0x22; i++) {
  4511. if(0x06 + i == 0x20) continue;
  4512. SiS_SetReg(SISSR, 0x06 + i, 0x00);
  4513. }
  4514. for(i = 0; i < 0x0b; i++) {
  4515. SiS_SetReg(SISSR, 0x31 + i, 0x00);
  4516. }
  4517. for(i = 0; i < 0x10; i++) {
  4518. SiS_SetReg(SISCR, 0x30 + i, 0x00);
  4519. }
  4520. ptr = cs78;
  4521. if(ivideo->haveXGIROM) {
  4522. ptr = (const u8 *)&bios[0x78];
  4523. }
  4524. for(i = 0; i < 3; i++) {
  4525. SiS_SetReg(SISSR, 0x23 + i, ptr[i]);
  4526. }
  4527. ptr = cs76;
  4528. if(ivideo->haveXGIROM) {
  4529. ptr = (const u8 *)&bios[0x76];
  4530. }
  4531. for(i = 0; i < 2; i++) {
  4532. SiS_SetReg(SISSR, 0x21 + i, ptr[i]);
  4533. }
  4534. v1 = 0x18; v2 = 0x00;
  4535. if(ivideo->haveXGIROM) {
  4536. v1 = bios[0x74];
  4537. v2 = bios[0x75];
  4538. }
  4539. SiS_SetReg(SISSR, 0x07, v1);
  4540. SiS_SetReg(SISSR, 0x11, 0x0f);
  4541. SiS_SetReg(SISSR, 0x1f, v2);
  4542. /* PCI linear mode, RelIO enabled, A0000 decoding disabled */
  4543. SiS_SetReg(SISSR, 0x20, 0x80 | 0x20 | 0x04);
  4544. SiS_SetReg(SISSR, 0x27, 0x74);
  4545. ptr = cs7b;
  4546. if(ivideo->haveXGIROM) {
  4547. ptr = (const u8 *)&bios[0x7b];
  4548. }
  4549. for(i = 0; i < 3; i++) {
  4550. SiS_SetReg(SISSR, 0x31 + i, ptr[i]);
  4551. }
  4552. if(ivideo->chip == XGI_40) {
  4553. if(ivideo->revision_id == 2) {
  4554. SiS_SetRegANDOR(SISSR, 0x3b, 0x3f, 0xc0);
  4555. }
  4556. SiS_SetReg(SISCR, 0x7d, 0xfe);
  4557. SiS_SetReg(SISCR, 0x7e, 0x0f);
  4558. }
  4559. if(ivideo->revision_id == 0) { /* 40 *and* 20? */
  4560. SiS_SetRegAND(SISCR, 0x58, 0xd7);
  4561. reg = SiS_GetReg(SISCR, 0xcb);
  4562. if(reg & 0x20) {
  4563. SiS_SetRegANDOR(SISCR, 0x58, 0xd7, (reg & 0x10) ? 0x08 : 0x20); /* =0x28 Z7 ? */
  4564. }
  4565. }
  4566. reg = (ivideo->chip == XGI_40) ? 0x20 : 0x00;
  4567. SiS_SetRegANDOR(SISCR, 0x38, 0x1f, reg);
  4568. if(ivideo->chip == XGI_20) {
  4569. SiS_SetReg(SISSR, 0x36, 0x70);
  4570. } else {
  4571. SiS_SetReg(SISVID, 0x00, 0x86);
  4572. SiS_SetReg(SISVID, 0x32, 0x00);
  4573. SiS_SetReg(SISVID, 0x30, 0x00);
  4574. SiS_SetReg(SISVID, 0x32, 0x01);
  4575. SiS_SetReg(SISVID, 0x30, 0x00);
  4576. SiS_SetRegAND(SISVID, 0x2f, 0xdf);
  4577. SiS_SetRegAND(SISCAP, 0x00, 0x3f);
  4578. SiS_SetReg(SISPART1, 0x2f, 0x01);
  4579. SiS_SetReg(SISPART1, 0x00, 0x00);
  4580. SiS_SetReg(SISPART1, 0x02, bios[0x7e]);
  4581. SiS_SetReg(SISPART1, 0x2e, 0x08);
  4582. SiS_SetRegAND(SISPART1, 0x35, 0x7f);
  4583. SiS_SetRegAND(SISPART1, 0x50, 0xfe);
  4584. reg = SiS_GetReg(SISPART4, 0x00);
  4585. if(reg == 1 || reg == 2) {
  4586. SiS_SetReg(SISPART2, 0x00, 0x1c);
  4587. SiS_SetReg(SISPART4, 0x0d, bios[0x7f]);
  4588. SiS_SetReg(SISPART4, 0x0e, bios[0x80]);
  4589. SiS_SetReg(SISPART4, 0x10, bios[0x81]);
  4590. SiS_SetRegAND(SISPART4, 0x0f, 0x3f);
  4591. reg = SiS_GetReg(SISPART4, 0x01);
  4592. if((reg & 0xf0) >= 0xb0) {
  4593. reg = SiS_GetReg(SISPART4, 0x23);
  4594. if(reg & 0x20) reg |= 0x40;
  4595. SiS_SetReg(SISPART4, 0x23, reg);
  4596. reg = (reg & 0x20) ? 0x02 : 0x00;
  4597. SiS_SetRegANDOR(SISPART1, 0x1e, 0xfd, reg);
  4598. }
  4599. }
  4600. v1 = bios[0x77];
  4601. reg = SiS_GetReg(SISSR, 0x3b);
  4602. if(reg & 0x02) {
  4603. reg = SiS_GetReg(SISSR, 0x3a);
  4604. v2 = (reg & 0x30) >> 3;
  4605. if(!(v2 & 0x04)) v2 ^= 0x02;
  4606. reg = SiS_GetReg(SISSR, 0x39);
  4607. if(reg & 0x80) v2 |= 0x80;
  4608. v2 |= 0x01;
  4609. if((mypdev = pci_get_device(PCI_VENDOR_ID_SI, 0x0730, NULL))) {
  4610. pci_dev_put(mypdev);
  4611. if(((v2 & 0x06) == 2) || ((v2 & 0x06) == 4))
  4612. v2 &= 0xf9;
  4613. v2 |= 0x08;
  4614. v1 &= 0xfe;
  4615. } else {
  4616. mypdev = pci_get_device(PCI_VENDOR_ID_SI, 0x0735, NULL);
  4617. if(!mypdev)
  4618. mypdev = pci_get_device(PCI_VENDOR_ID_SI, 0x0645, NULL);
  4619. if(!mypdev)
  4620. mypdev = pci_get_device(PCI_VENDOR_ID_SI, 0x0650, NULL);
  4621. if(mypdev) {
  4622. pci_read_config_dword(mypdev, 0x94, &regd);
  4623. regd &= 0xfffffeff;
  4624. pci_write_config_dword(mypdev, 0x94, regd);
  4625. v1 &= 0xfe;
  4626. pci_dev_put(mypdev);
  4627. } else if(sisfb_find_host_bridge(ivideo, pdev, PCI_VENDOR_ID_SI)) {
  4628. v1 &= 0xfe;
  4629. } else if(sisfb_find_host_bridge(ivideo, pdev, 0x1106) ||
  4630. sisfb_find_host_bridge(ivideo, pdev, 0x1022) ||
  4631. sisfb_find_host_bridge(ivideo, pdev, 0x700e) ||
  4632. sisfb_find_host_bridge(ivideo, pdev, 0x10de)) {
  4633. if((v2 & 0x06) == 4)
  4634. v2 ^= 0x06;
  4635. v2 |= 0x08;
  4636. }
  4637. }
  4638. SiS_SetRegANDOR(SISCR, 0x5f, 0xf0, v2);
  4639. }
  4640. SiS_SetReg(SISSR, 0x22, v1);
  4641. if(ivideo->revision_id == 2) {
  4642. v1 = SiS_GetReg(SISSR, 0x3b);
  4643. v2 = SiS_GetReg(SISSR, 0x3a);
  4644. regd = bios[0x90 + 3] | (bios[0x90 + 4] << 8);
  4645. if( (!(v1 & 0x02)) && (v2 & 0x30) && (regd < 0xcf) )
  4646. SiS_SetRegANDOR(SISCR, 0x5f, 0xf1, 0x01);
  4647. if((mypdev = pci_get_device(0x10de, 0x01e0, NULL))) {
  4648. /* TODO: set CR5f &0xf1 | 0x01 for version 6570
  4649. * of nforce 2 ROM
  4650. */
  4651. if(0)
  4652. SiS_SetRegANDOR(SISCR, 0x5f, 0xf1, 0x01);
  4653. pci_dev_put(mypdev);
  4654. }
  4655. }
  4656. v1 = 0x30;
  4657. reg = SiS_GetReg(SISSR, 0x3b);
  4658. v2 = SiS_GetReg(SISCR, 0x5f);
  4659. if((!(reg & 0x02)) && (v2 & 0x0e))
  4660. v1 |= 0x08;
  4661. SiS_SetReg(SISSR, 0x27, v1);
  4662. if(bios[0x64] & 0x01) {
  4663. SiS_SetRegANDOR(SISCR, 0x5f, 0xf0, bios[0x64]);
  4664. }
  4665. v1 = bios[0x4f7];
  4666. pci_read_config_dword(pdev, 0x50, &regd);
  4667. regd = (regd >> 20) & 0x0f;
  4668. if(regd == 1) {
  4669. v1 &= 0xfc;
  4670. SiS_SetRegOR(SISCR, 0x5f, 0x08);
  4671. }
  4672. SiS_SetReg(SISCR, 0x48, v1);
  4673. SiS_SetRegANDOR(SISCR, 0x47, 0x04, bios[0x4f6] & 0xfb);
  4674. SiS_SetRegANDOR(SISCR, 0x49, 0xf0, bios[0x4f8] & 0x0f);
  4675. SiS_SetRegANDOR(SISCR, 0x4a, 0x60, bios[0x4f9] & 0x9f);
  4676. SiS_SetRegANDOR(SISCR, 0x4b, 0x08, bios[0x4fa] & 0xf7);
  4677. SiS_SetRegANDOR(SISCR, 0x4c, 0x80, bios[0x4fb] & 0x7f);
  4678. SiS_SetReg(SISCR, 0x70, bios[0x4fc]);
  4679. SiS_SetRegANDOR(SISCR, 0x71, 0xf0, bios[0x4fd] & 0x0f);
  4680. SiS_SetReg(SISCR, 0x74, 0xd0);
  4681. SiS_SetRegANDOR(SISCR, 0x74, 0xcf, bios[0x4fe] & 0x30);
  4682. SiS_SetRegANDOR(SISCR, 0x75, 0xe0, bios[0x4ff] & 0x1f);
  4683. SiS_SetRegANDOR(SISCR, 0x76, 0xe0, bios[0x500] & 0x1f);
  4684. v1 = bios[0x501];
  4685. if((mypdev = pci_get_device(0x8086, 0x2530, NULL))) {
  4686. v1 = 0xf0;
  4687. pci_dev_put(mypdev);
  4688. }
  4689. SiS_SetReg(SISCR, 0x77, v1);
  4690. }
  4691. /* RAM type:
  4692. *
  4693. * 0 == DDR1, 1 == DDR2, 2..7 == reserved?
  4694. *
  4695. * The code seems to written so that regb should equal ramtype,
  4696. * however, so far it has been hardcoded to 0. Enable other values only
  4697. * on XGI Z9, as it passes the POST, and add a warning for others.
  4698. */
  4699. ramtype = sisfb_post_xgi_ramtype(ivideo);
  4700. if (!sisfb_xgi_is21(ivideo) && ramtype) {
  4701. dev_warn(&pdev->dev,
  4702. "RAM type something else than expected: %d\n",
  4703. ramtype);
  4704. regb = 0;
  4705. } else {
  4706. regb = ramtype;
  4707. }
  4708. v1 = 0xff;
  4709. if(ivideo->haveXGIROM) {
  4710. v1 = bios[0x140 + regb];
  4711. }
  4712. SiS_SetReg(SISCR, 0x6d, v1);
  4713. ptr = cs128;
  4714. if(ivideo->haveXGIROM) {
  4715. ptr = (const u8 *)&bios[0x128];
  4716. }
  4717. for(i = 0, j = 0; i < 3; i++, j += 8) {
  4718. SiS_SetReg(SISCR, 0x68 + i, ptr[j + regb]);
  4719. }
  4720. ptr = cs31a;
  4721. ptr2 = cs33a;
  4722. if(ivideo->haveXGIROM) {
  4723. index = (ivideo->chip == XGI_20) ? 0x31a : 0x3a6;
  4724. ptr = (const u8 *)&bios[index];
  4725. ptr2 = (const u8 *)&bios[index + 0x20];
  4726. }
  4727. for(i = 0; i < 2; i++) {
  4728. if(i == 0) {
  4729. regd = le32_to_cpu(((u32 *)ptr)[regb]);
  4730. rega = 0x6b;
  4731. } else {
  4732. regd = le32_to_cpu(((u32 *)ptr2)[regb]);
  4733. rega = 0x6e;
  4734. }
  4735. reg = 0x00;
  4736. for(j = 0; j < 16; j++) {
  4737. reg &= 0xf3;
  4738. if(regd & 0x01) reg |= 0x04;
  4739. if(regd & 0x02) reg |= 0x08;
  4740. regd >>= 2;
  4741. SiS_SetReg(SISCR, rega, reg);
  4742. reg = SiS_GetReg(SISCR, rega);
  4743. reg = SiS_GetReg(SISCR, rega);
  4744. reg += 0x10;
  4745. }
  4746. }
  4747. SiS_SetRegAND(SISCR, 0x6e, 0xfc);
  4748. ptr = NULL;
  4749. if(ivideo->haveXGIROM) {
  4750. index = (ivideo->chip == XGI_20) ? 0x35a : 0x3e6;
  4751. ptr = (const u8 *)&bios[index];
  4752. }
  4753. for(i = 0; i < 4; i++) {
  4754. SiS_SetRegANDOR(SISCR, 0x6e, 0xfc, i);
  4755. reg = 0x00;
  4756. for(j = 0; j < 2; j++) {
  4757. regd = 0;
  4758. if(ptr) {
  4759. regd = le32_to_cpu(((u32 *)ptr)[regb * 8]);
  4760. ptr += 4;
  4761. }
  4762. /* reg = 0x00; */
  4763. for(k = 0; k < 16; k++) {
  4764. reg &= 0xfc;
  4765. if(regd & 0x01) reg |= 0x01;
  4766. if(regd & 0x02) reg |= 0x02;
  4767. regd >>= 2;
  4768. SiS_SetReg(SISCR, 0x6f, reg);
  4769. reg = SiS_GetReg(SISCR, 0x6f);
  4770. reg = SiS_GetReg(SISCR, 0x6f);
  4771. reg += 0x08;
  4772. }
  4773. }
  4774. }
  4775. ptr = cs148;
  4776. if(ivideo->haveXGIROM) {
  4777. ptr = (const u8 *)&bios[0x148];
  4778. }
  4779. for(i = 0, j = 0; i < 2; i++, j += 8) {
  4780. SiS_SetReg(SISCR, 0x80 + i, ptr[j + regb]);
  4781. }
  4782. SiS_SetRegAND(SISCR, 0x89, 0x8f);
  4783. ptr = cs45a;
  4784. if(ivideo->haveXGIROM) {
  4785. index = (ivideo->chip == XGI_20) ? 0x45a : 0x4e6;
  4786. ptr = (const u8 *)&bios[index];
  4787. }
  4788. regd = le16_to_cpu(((const u16 *)ptr)[regb]);
  4789. reg = 0x80;
  4790. for(i = 0; i < 5; i++) {
  4791. reg &= 0xfc;
  4792. if(regd & 0x01) reg |= 0x01;
  4793. if(regd & 0x02) reg |= 0x02;
  4794. regd >>= 2;
  4795. SiS_SetReg(SISCR, 0x89, reg);
  4796. reg = SiS_GetReg(SISCR, 0x89);
  4797. reg = SiS_GetReg(SISCR, 0x89);
  4798. reg += 0x10;
  4799. }
  4800. v1 = 0xb5; v2 = 0x20; v3 = 0xf0; v4 = 0x13;
  4801. if(ivideo->haveXGIROM) {
  4802. v1 = bios[0x118 + regb];
  4803. v2 = bios[0xf8 + regb];
  4804. v3 = bios[0x120 + regb];
  4805. v4 = bios[0x1ca];
  4806. }
  4807. SiS_SetReg(SISCR, 0x45, v1 & 0x0f);
  4808. SiS_SetReg(SISCR, 0x99, (v1 >> 4) & 0x07);
  4809. SiS_SetRegOR(SISCR, 0x40, v1 & 0x80);
  4810. SiS_SetReg(SISCR, 0x41, v2);
  4811. ptr = cs170;
  4812. if(ivideo->haveXGIROM) {
  4813. ptr = (const u8 *)&bios[0x170];
  4814. }
  4815. for(i = 0, j = 0; i < 7; i++, j += 8) {
  4816. SiS_SetReg(SISCR, 0x90 + i, ptr[j + regb]);
  4817. }
  4818. SiS_SetReg(SISCR, 0x59, v3);
  4819. ptr = cs1a8;
  4820. if(ivideo->haveXGIROM) {
  4821. ptr = (const u8 *)&bios[0x1a8];
  4822. }
  4823. for(i = 0, j = 0; i < 3; i++, j += 8) {
  4824. SiS_SetReg(SISCR, 0xc3 + i, ptr[j + regb]);
  4825. }
  4826. ptr = cs100;
  4827. if(ivideo->haveXGIROM) {
  4828. ptr = (const u8 *)&bios[0x100];
  4829. }
  4830. for(i = 0, j = 0; i < 2; i++, j += 8) {
  4831. SiS_SetReg(SISCR, 0x8a + i, ptr[j + regb]);
  4832. }
  4833. SiS_SetReg(SISCR, 0xcf, v4);
  4834. SiS_SetReg(SISCR, 0x83, 0x09);
  4835. SiS_SetReg(SISCR, 0x87, 0x00);
  4836. if(ivideo->chip == XGI_40) {
  4837. if( (ivideo->revision_id == 1) ||
  4838. (ivideo->revision_id == 2) ) {
  4839. SiS_SetReg(SISCR, 0x8c, 0x87);
  4840. }
  4841. }
  4842. if (regb == 1)
  4843. SiS_SetReg(SISSR, 0x17, 0x80); /* DDR2 */
  4844. else
  4845. SiS_SetReg(SISSR, 0x17, 0x00); /* DDR1 */
  4846. SiS_SetReg(SISSR, 0x1a, 0x87);
  4847. if(ivideo->chip == XGI_20) {
  4848. SiS_SetReg(SISSR, 0x15, 0x00);
  4849. SiS_SetReg(SISSR, 0x1c, 0x00);
  4850. }
  4851. switch(ramtype) {
  4852. case 0:
  4853. sisfb_post_xgi_setclocks(ivideo, regb);
  4854. if((ivideo->chip == XGI_20) ||
  4855. (ivideo->revision_id == 1) ||
  4856. (ivideo->revision_id == 2)) {
  4857. v1 = cs158[regb]; v2 = cs160[regb]; v3 = cs168[regb];
  4858. if(ivideo->haveXGIROM) {
  4859. v1 = bios[regb + 0x158];
  4860. v2 = bios[regb + 0x160];
  4861. v3 = bios[regb + 0x168];
  4862. }
  4863. SiS_SetReg(SISCR, 0x82, v1);
  4864. SiS_SetReg(SISCR, 0x85, v2);
  4865. SiS_SetReg(SISCR, 0x86, v3);
  4866. } else {
  4867. SiS_SetReg(SISCR, 0x82, 0x88);
  4868. SiS_SetReg(SISCR, 0x86, 0x00);
  4869. reg = SiS_GetReg(SISCR, 0x86);
  4870. SiS_SetReg(SISCR, 0x86, 0x88);
  4871. reg = SiS_GetReg(SISCR, 0x86);
  4872. SiS_SetReg(SISCR, 0x86, bios[regb + 0x168]);
  4873. SiS_SetReg(SISCR, 0x82, 0x77);
  4874. SiS_SetReg(SISCR, 0x85, 0x00);
  4875. reg = SiS_GetReg(SISCR, 0x85);
  4876. SiS_SetReg(SISCR, 0x85, 0x88);
  4877. reg = SiS_GetReg(SISCR, 0x85);
  4878. SiS_SetReg(SISCR, 0x85, bios[regb + 0x160]);
  4879. SiS_SetReg(SISCR, 0x82, bios[regb + 0x158]);
  4880. }
  4881. if(ivideo->chip == XGI_40) {
  4882. SiS_SetReg(SISCR, 0x97, 0x00);
  4883. }
  4884. SiS_SetReg(SISCR, 0x98, 0x01);
  4885. SiS_SetReg(SISCR, 0x9a, 0x02);
  4886. SiS_SetReg(SISSR, 0x18, 0x01);
  4887. if((ivideo->chip == XGI_20) ||
  4888. (ivideo->revision_id == 2)) {
  4889. SiS_SetReg(SISSR, 0x19, 0x40);
  4890. } else {
  4891. SiS_SetReg(SISSR, 0x19, 0x20);
  4892. }
  4893. SiS_SetReg(SISSR, 0x16, 0x00);
  4894. SiS_SetReg(SISSR, 0x16, 0x80);
  4895. if((ivideo->chip == XGI_20) || (bios[0x1cb] != 0x0c)) {
  4896. sisfb_post_xgi_delay(ivideo, 0x43);
  4897. sisfb_post_xgi_delay(ivideo, 0x43);
  4898. sisfb_post_xgi_delay(ivideo, 0x43);
  4899. SiS_SetReg(SISSR, 0x18, 0x00);
  4900. if((ivideo->chip == XGI_20) ||
  4901. (ivideo->revision_id == 2)) {
  4902. SiS_SetReg(SISSR, 0x19, 0x40);
  4903. } else {
  4904. SiS_SetReg(SISSR, 0x19, 0x20);
  4905. }
  4906. } else if((ivideo->chip == XGI_40) && (bios[0x1cb] == 0x0c)) {
  4907. /* SiS_SetReg(SISSR, 0x16, 0x0c); */ /* ? */
  4908. }
  4909. SiS_SetReg(SISSR, 0x16, 0x00);
  4910. SiS_SetReg(SISSR, 0x16, 0x80);
  4911. sisfb_post_xgi_delay(ivideo, 4);
  4912. v1 = 0x31; v2 = 0x03; v3 = 0x83; v4 = 0x03; v5 = 0x83;
  4913. if(ivideo->haveXGIROM) {
  4914. v1 = bios[0xf0];
  4915. index = (ivideo->chip == XGI_20) ? 0x4b2 : 0x53e;
  4916. v2 = bios[index];
  4917. v3 = bios[index + 1];
  4918. v4 = bios[index + 2];
  4919. v5 = bios[index + 3];
  4920. }
  4921. SiS_SetReg(SISSR, 0x18, v1);
  4922. SiS_SetReg(SISSR, 0x19, ((ivideo->chip == XGI_20) ? 0x02 : 0x01));
  4923. SiS_SetReg(SISSR, 0x16, v2);
  4924. SiS_SetReg(SISSR, 0x16, v3);
  4925. sisfb_post_xgi_delay(ivideo, 0x43);
  4926. SiS_SetReg(SISSR, 0x1b, 0x03);
  4927. sisfb_post_xgi_delay(ivideo, 0x22);
  4928. SiS_SetReg(SISSR, 0x18, v1);
  4929. SiS_SetReg(SISSR, 0x19, 0x00);
  4930. SiS_SetReg(SISSR, 0x16, v4);
  4931. SiS_SetReg(SISSR, 0x16, v5);
  4932. SiS_SetReg(SISSR, 0x1b, 0x00);
  4933. break;
  4934. case 1:
  4935. sisfb_post_xgi_ddr2(ivideo, regb);
  4936. break;
  4937. default:
  4938. sisfb_post_xgi_setclocks(ivideo, regb);
  4939. if((ivideo->chip == XGI_40) &&
  4940. ((ivideo->revision_id == 1) ||
  4941. (ivideo->revision_id == 2))) {
  4942. SiS_SetReg(SISCR, 0x82, bios[regb + 0x158]);
  4943. SiS_SetReg(SISCR, 0x85, bios[regb + 0x160]);
  4944. SiS_SetReg(SISCR, 0x86, bios[regb + 0x168]);
  4945. } else {
  4946. SiS_SetReg(SISCR, 0x82, 0x88);
  4947. SiS_SetReg(SISCR, 0x86, 0x00);
  4948. reg = SiS_GetReg(SISCR, 0x86);
  4949. SiS_SetReg(SISCR, 0x86, 0x88);
  4950. SiS_SetReg(SISCR, 0x82, 0x77);
  4951. SiS_SetReg(SISCR, 0x85, 0x00);
  4952. reg = SiS_GetReg(SISCR, 0x85);
  4953. SiS_SetReg(SISCR, 0x85, 0x88);
  4954. reg = SiS_GetReg(SISCR, 0x85);
  4955. v1 = cs160[regb]; v2 = cs158[regb];
  4956. if(ivideo->haveXGIROM) {
  4957. v1 = bios[regb + 0x160];
  4958. v2 = bios[regb + 0x158];
  4959. }
  4960. SiS_SetReg(SISCR, 0x85, v1);
  4961. SiS_SetReg(SISCR, 0x82, v2);
  4962. }
  4963. if(ivideo->chip == XGI_40) {
  4964. SiS_SetReg(SISCR, 0x97, 0x11);
  4965. }
  4966. if((ivideo->chip == XGI_40) && (ivideo->revision_id == 2)) {
  4967. SiS_SetReg(SISCR, 0x98, 0x01);
  4968. } else {
  4969. SiS_SetReg(SISCR, 0x98, 0x03);
  4970. }
  4971. SiS_SetReg(SISCR, 0x9a, 0x02);
  4972. if(ivideo->chip == XGI_40) {
  4973. SiS_SetReg(SISSR, 0x18, 0x01);
  4974. } else {
  4975. SiS_SetReg(SISSR, 0x18, 0x00);
  4976. }
  4977. SiS_SetReg(SISSR, 0x19, 0x40);
  4978. SiS_SetReg(SISSR, 0x16, 0x00);
  4979. SiS_SetReg(SISSR, 0x16, 0x80);
  4980. if((ivideo->chip == XGI_40) && (bios[0x1cb] != 0x0c)) {
  4981. sisfb_post_xgi_delay(ivideo, 0x43);
  4982. sisfb_post_xgi_delay(ivideo, 0x43);
  4983. sisfb_post_xgi_delay(ivideo, 0x43);
  4984. SiS_SetReg(SISSR, 0x18, 0x00);
  4985. SiS_SetReg(SISSR, 0x19, 0x40);
  4986. SiS_SetReg(SISSR, 0x16, 0x00);
  4987. SiS_SetReg(SISSR, 0x16, 0x80);
  4988. }
  4989. sisfb_post_xgi_delay(ivideo, 4);
  4990. v1 = 0x31;
  4991. if(ivideo->haveXGIROM) {
  4992. v1 = bios[0xf0];
  4993. }
  4994. SiS_SetReg(SISSR, 0x18, v1);
  4995. SiS_SetReg(SISSR, 0x19, 0x01);
  4996. if(ivideo->chip == XGI_40) {
  4997. SiS_SetReg(SISSR, 0x16, bios[0x53e]);
  4998. SiS_SetReg(SISSR, 0x16, bios[0x53f]);
  4999. } else {
  5000. SiS_SetReg(SISSR, 0x16, 0x05);
  5001. SiS_SetReg(SISSR, 0x16, 0x85);
  5002. }
  5003. sisfb_post_xgi_delay(ivideo, 0x43);
  5004. if(ivideo->chip == XGI_40) {
  5005. SiS_SetReg(SISSR, 0x1b, 0x01);
  5006. } else {
  5007. SiS_SetReg(SISSR, 0x1b, 0x03);
  5008. }
  5009. sisfb_post_xgi_delay(ivideo, 0x22);
  5010. SiS_SetReg(SISSR, 0x18, v1);
  5011. SiS_SetReg(SISSR, 0x19, 0x00);
  5012. if(ivideo->chip == XGI_40) {
  5013. SiS_SetReg(SISSR, 0x16, bios[0x540]);
  5014. SiS_SetReg(SISSR, 0x16, bios[0x541]);
  5015. } else {
  5016. SiS_SetReg(SISSR, 0x16, 0x05);
  5017. SiS_SetReg(SISSR, 0x16, 0x85);
  5018. }
  5019. SiS_SetReg(SISSR, 0x1b, 0x00);
  5020. }
  5021. regb = 0; /* ! */
  5022. v1 = 0x03;
  5023. if(ivideo->haveXGIROM) {
  5024. v1 = bios[0x110 + regb];
  5025. }
  5026. SiS_SetReg(SISSR, 0x1b, v1);
  5027. /* RAM size */
  5028. v1 = 0x00; v2 = 0x00;
  5029. if(ivideo->haveXGIROM) {
  5030. v1 = bios[0x62];
  5031. v2 = bios[0x63];
  5032. }
  5033. regb = 0; /* ! */
  5034. regd = 1 << regb;
  5035. if((v1 & 0x40) && (v2 & regd) && ivideo->haveXGIROM) {
  5036. SiS_SetReg(SISSR, 0x13, bios[regb + 0xe0]);
  5037. SiS_SetReg(SISSR, 0x14, bios[regb + 0xe0 + 8]);
  5038. } else {
  5039. int err;
  5040. /* Set default mode, don't clear screen */
  5041. ivideo->SiS_Pr.SiS_UseOEM = false;
  5042. SiS_SetEnableDstn(&ivideo->SiS_Pr, false);
  5043. SiS_SetEnableFstn(&ivideo->SiS_Pr, false);
  5044. ivideo->curFSTN = ivideo->curDSTN = 0;
  5045. ivideo->SiS_Pr.VideoMemorySize = 8 << 20;
  5046. SiSSetMode(&ivideo->SiS_Pr, 0x2e | 0x80);
  5047. SiS_SetReg(SISSR, 0x05, 0x86);
  5048. /* Disable read-cache */
  5049. SiS_SetRegAND(SISSR, 0x21, 0xdf);
  5050. err = sisfb_post_xgi_ramsize(ivideo);
  5051. /* Enable read-cache */
  5052. SiS_SetRegOR(SISSR, 0x21, 0x20);
  5053. if (err) {
  5054. dev_err(&pdev->dev,
  5055. "%s: RAM size detection failed: %d\n",
  5056. __func__, err);
  5057. return 0;
  5058. }
  5059. }
  5060. #if 0
  5061. printk(KERN_DEBUG "-----------------\n");
  5062. for(i = 0; i < 0xff; i++) {
  5063. reg = SiS_GetReg(SISCR, i);
  5064. printk(KERN_DEBUG "CR%02x(%x) = 0x%02x\n", i, SISCR, reg);
  5065. }
  5066. for(i = 0; i < 0x40; i++) {
  5067. reg = SiS_GetReg(SISSR, i);
  5068. printk(KERN_DEBUG "SR%02x(%x) = 0x%02x\n", i, SISSR, reg);
  5069. }
  5070. printk(KERN_DEBUG "-----------------\n");
  5071. #endif
  5072. /* Sense CRT1 */
  5073. if(ivideo->chip == XGI_20) {
  5074. SiS_SetRegOR(SISCR, 0x32, 0x20);
  5075. } else {
  5076. reg = SiS_GetReg(SISPART4, 0x00);
  5077. if((reg == 1) || (reg == 2)) {
  5078. sisfb_sense_crt1(ivideo);
  5079. } else {
  5080. SiS_SetRegOR(SISCR, 0x32, 0x20);
  5081. }
  5082. }
  5083. /* Set default mode, don't clear screen */
  5084. ivideo->SiS_Pr.SiS_UseOEM = false;
  5085. SiS_SetEnableDstn(&ivideo->SiS_Pr, false);
  5086. SiS_SetEnableFstn(&ivideo->SiS_Pr, false);
  5087. ivideo->curFSTN = ivideo->curDSTN = 0;
  5088. SiSSetMode(&ivideo->SiS_Pr, 0x2e | 0x80);
  5089. SiS_SetReg(SISSR, 0x05, 0x86);
  5090. /* Display off */
  5091. SiS_SetRegOR(SISSR, 0x01, 0x20);
  5092. /* Save mode number in CR34 */
  5093. SiS_SetReg(SISCR, 0x34, 0x2e);
  5094. /* Let everyone know what the current mode is */
  5095. ivideo->modeprechange = 0x2e;
  5096. if(ivideo->chip == XGI_40) {
  5097. reg = SiS_GetReg(SISCR, 0xca);
  5098. v1 = SiS_GetReg(SISCR, 0xcc);
  5099. if((reg & 0x10) && (!(v1 & 0x04))) {
  5100. printk(KERN_ERR
  5101. "sisfb: Please connect power to the card.\n");
  5102. return 0;
  5103. }
  5104. }
  5105. return 1;
  5106. }
  5107. #endif
  5108. static int __devinit
  5109. sisfb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  5110. {
  5111. struct sisfb_chip_info *chipinfo = &sisfb_chip_info[ent->driver_data];
  5112. struct sis_video_info *ivideo = NULL;
  5113. struct fb_info *sis_fb_info = NULL;
  5114. u16 reg16;
  5115. u8 reg;
  5116. int i, ret;
  5117. if(sisfb_off)
  5118. return -ENXIO;
  5119. sis_fb_info = framebuffer_alloc(sizeof(*ivideo), &pdev->dev);
  5120. if(!sis_fb_info)
  5121. return -ENOMEM;
  5122. ivideo = (struct sis_video_info *)sis_fb_info->par;
  5123. ivideo->memyselfandi = sis_fb_info;
  5124. ivideo->sisfb_id = SISFB_ID;
  5125. if(card_list == NULL) {
  5126. ivideo->cardnumber = 0;
  5127. } else {
  5128. struct sis_video_info *countvideo = card_list;
  5129. ivideo->cardnumber = 1;
  5130. while((countvideo = countvideo->next) != NULL)
  5131. ivideo->cardnumber++;
  5132. }
  5133. strncpy(ivideo->myid, chipinfo->chip_name, 30);
  5134. ivideo->warncount = 0;
  5135. ivideo->chip_id = pdev->device;
  5136. ivideo->chip_vendor = pdev->vendor;
  5137. ivideo->revision_id = pdev->revision;
  5138. ivideo->SiS_Pr.ChipRevision = ivideo->revision_id;
  5139. pci_read_config_word(pdev, PCI_COMMAND, &reg16);
  5140. ivideo->sisvga_enabled = reg16 & 0x01;
  5141. ivideo->pcibus = pdev->bus->number;
  5142. ivideo->pcislot = PCI_SLOT(pdev->devfn);
  5143. ivideo->pcifunc = PCI_FUNC(pdev->devfn);
  5144. ivideo->subsysvendor = pdev->subsystem_vendor;
  5145. ivideo->subsysdevice = pdev->subsystem_device;
  5146. #ifndef MODULE
  5147. if(sisfb_mode_idx == -1) {
  5148. sisfb_get_vga_mode_from_kernel();
  5149. }
  5150. #endif
  5151. ivideo->chip = chipinfo->chip;
  5152. ivideo->chip_real_id = chipinfo->chip;
  5153. ivideo->sisvga_engine = chipinfo->vgaengine;
  5154. ivideo->hwcursor_size = chipinfo->hwcursor_size;
  5155. ivideo->CRT2_write_enable = chipinfo->CRT2_write_enable;
  5156. ivideo->mni = chipinfo->mni;
  5157. ivideo->detectedpdc = 0xff;
  5158. ivideo->detectedpdca = 0xff;
  5159. ivideo->detectedlcda = 0xff;
  5160. ivideo->sisfb_thismonitor.datavalid = false;
  5161. ivideo->current_base = 0;
  5162. ivideo->engineok = 0;
  5163. ivideo->sisfb_was_boot_device = 0;
  5164. if(pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW) {
  5165. if(ivideo->sisvga_enabled)
  5166. ivideo->sisfb_was_boot_device = 1;
  5167. else {
  5168. printk(KERN_DEBUG "sisfb: PCI device is disabled, "
  5169. "but marked as boot video device ???\n");
  5170. printk(KERN_DEBUG "sisfb: I will not accept this "
  5171. "as the primary VGA device\n");
  5172. }
  5173. }
  5174. ivideo->sisfb_parm_mem = sisfb_parm_mem;
  5175. ivideo->sisfb_accel = sisfb_accel;
  5176. ivideo->sisfb_ypan = sisfb_ypan;
  5177. ivideo->sisfb_max = sisfb_max;
  5178. ivideo->sisfb_userom = sisfb_userom;
  5179. ivideo->sisfb_useoem = sisfb_useoem;
  5180. ivideo->sisfb_mode_idx = sisfb_mode_idx;
  5181. ivideo->sisfb_parm_rate = sisfb_parm_rate;
  5182. ivideo->sisfb_crt1off = sisfb_crt1off;
  5183. ivideo->sisfb_forcecrt1 = sisfb_forcecrt1;
  5184. ivideo->sisfb_crt2type = sisfb_crt2type;
  5185. ivideo->sisfb_crt2flags = sisfb_crt2flags;
  5186. /* pdc(a), scalelcd, special timing, lvdshl handled below */
  5187. ivideo->sisfb_dstn = sisfb_dstn;
  5188. ivideo->sisfb_fstn = sisfb_fstn;
  5189. ivideo->sisfb_tvplug = sisfb_tvplug;
  5190. ivideo->sisfb_tvstd = sisfb_tvstd;
  5191. ivideo->tvxpos = sisfb_tvxposoffset;
  5192. ivideo->tvypos = sisfb_tvyposoffset;
  5193. ivideo->sisfb_nocrt2rate = sisfb_nocrt2rate;
  5194. ivideo->refresh_rate = 0;
  5195. if(ivideo->sisfb_parm_rate != -1) {
  5196. ivideo->refresh_rate = ivideo->sisfb_parm_rate;
  5197. }
  5198. ivideo->SiS_Pr.UsePanelScaler = sisfb_scalelcd;
  5199. ivideo->SiS_Pr.CenterScreen = -1;
  5200. ivideo->SiS_Pr.SiS_CustomT = sisfb_specialtiming;
  5201. ivideo->SiS_Pr.LVDSHL = sisfb_lvdshl;
  5202. ivideo->SiS_Pr.SiS_Backup70xx = 0xff;
  5203. ivideo->SiS_Pr.SiS_CHOverScan = -1;
  5204. ivideo->SiS_Pr.SiS_ChSW = false;
  5205. ivideo->SiS_Pr.SiS_UseLCDA = false;
  5206. ivideo->SiS_Pr.HaveEMI = false;
  5207. ivideo->SiS_Pr.HaveEMILCD = false;
  5208. ivideo->SiS_Pr.OverruleEMI = false;
  5209. ivideo->SiS_Pr.SiS_SensibleSR11 = false;
  5210. ivideo->SiS_Pr.SiS_MyCR63 = 0x63;
  5211. ivideo->SiS_Pr.PDC = -1;
  5212. ivideo->SiS_Pr.PDCA = -1;
  5213. ivideo->SiS_Pr.DDCPortMixup = false;
  5214. #ifdef CONFIG_FB_SIS_315
  5215. if(ivideo->chip >= SIS_330) {
  5216. ivideo->SiS_Pr.SiS_MyCR63 = 0x53;
  5217. if(ivideo->chip >= SIS_661) {
  5218. ivideo->SiS_Pr.SiS_SensibleSR11 = true;
  5219. }
  5220. }
  5221. #endif
  5222. memcpy(&ivideo->default_var, &my_default_var, sizeof(my_default_var));
  5223. pci_set_drvdata(pdev, ivideo);
  5224. /* Patch special cases */
  5225. if((ivideo->nbridge = sisfb_get_northbridge(ivideo->chip))) {
  5226. switch(ivideo->nbridge->device) {
  5227. #ifdef CONFIG_FB_SIS_300
  5228. case PCI_DEVICE_ID_SI_730:
  5229. ivideo->chip = SIS_730;
  5230. strcpy(ivideo->myid, "SiS 730");
  5231. break;
  5232. #endif
  5233. #ifdef CONFIG_FB_SIS_315
  5234. case PCI_DEVICE_ID_SI_651:
  5235. /* ivideo->chip is ok */
  5236. strcpy(ivideo->myid, "SiS 651");
  5237. break;
  5238. case PCI_DEVICE_ID_SI_740:
  5239. ivideo->chip = SIS_740;
  5240. strcpy(ivideo->myid, "SiS 740");
  5241. break;
  5242. case PCI_DEVICE_ID_SI_661:
  5243. ivideo->chip = SIS_661;
  5244. strcpy(ivideo->myid, "SiS 661");
  5245. break;
  5246. case PCI_DEVICE_ID_SI_741:
  5247. ivideo->chip = SIS_741;
  5248. strcpy(ivideo->myid, "SiS 741");
  5249. break;
  5250. case PCI_DEVICE_ID_SI_760:
  5251. ivideo->chip = SIS_760;
  5252. strcpy(ivideo->myid, "SiS 760");
  5253. break;
  5254. case PCI_DEVICE_ID_SI_761:
  5255. ivideo->chip = SIS_761;
  5256. strcpy(ivideo->myid, "SiS 761");
  5257. break;
  5258. #endif
  5259. default:
  5260. break;
  5261. }
  5262. }
  5263. ivideo->SiS_Pr.ChipType = ivideo->chip;
  5264. ivideo->SiS_Pr.ivideo = (void *)ivideo;
  5265. #ifdef CONFIG_FB_SIS_315
  5266. if((ivideo->SiS_Pr.ChipType == SIS_315PRO) ||
  5267. (ivideo->SiS_Pr.ChipType == SIS_315)) {
  5268. ivideo->SiS_Pr.ChipType = SIS_315H;
  5269. }
  5270. #endif
  5271. if(!ivideo->sisvga_enabled) {
  5272. if(pci_enable_device(pdev)) {
  5273. if(ivideo->nbridge) pci_dev_put(ivideo->nbridge);
  5274. pci_set_drvdata(pdev, NULL);
  5275. framebuffer_release(sis_fb_info);
  5276. return -EIO;
  5277. }
  5278. }
  5279. ivideo->video_base = pci_resource_start(pdev, 0);
  5280. ivideo->video_size = pci_resource_len(pdev, 0);
  5281. ivideo->mmio_base = pci_resource_start(pdev, 1);
  5282. ivideo->mmio_size = pci_resource_len(pdev, 1);
  5283. ivideo->SiS_Pr.RelIO = pci_resource_start(pdev, 2) + 0x30;
  5284. ivideo->SiS_Pr.IOAddress = ivideo->vga_base = ivideo->SiS_Pr.RelIO;
  5285. SiSRegInit(&ivideo->SiS_Pr, ivideo->SiS_Pr.IOAddress);
  5286. #ifdef CONFIG_FB_SIS_300
  5287. /* Find PCI systems for Chrontel/GPIO communication setup */
  5288. if(ivideo->chip == SIS_630) {
  5289. i = 0;
  5290. do {
  5291. if(mychswtable[i].subsysVendor == ivideo->subsysvendor &&
  5292. mychswtable[i].subsysCard == ivideo->subsysdevice) {
  5293. ivideo->SiS_Pr.SiS_ChSW = true;
  5294. printk(KERN_DEBUG "sisfb: Identified [%s %s] "
  5295. "requiring Chrontel/GPIO setup\n",
  5296. mychswtable[i].vendorName,
  5297. mychswtable[i].cardName);
  5298. ivideo->lpcdev = pci_get_device(PCI_VENDOR_ID_SI, 0x0008, NULL);
  5299. break;
  5300. }
  5301. i++;
  5302. } while(mychswtable[i].subsysVendor != 0);
  5303. }
  5304. #endif
  5305. #ifdef CONFIG_FB_SIS_315
  5306. if((ivideo->chip == SIS_760) && (ivideo->nbridge)) {
  5307. ivideo->lpcdev = pci_get_slot(ivideo->nbridge->bus, (2 << 3));
  5308. }
  5309. #endif
  5310. SiS_SetReg(SISSR, 0x05, 0x86);
  5311. if( (!ivideo->sisvga_enabled)
  5312. #if !defined(__i386__) && !defined(__x86_64__)
  5313. || (sisfb_resetcard)
  5314. #endif
  5315. ) {
  5316. for(i = 0x30; i <= 0x3f; i++) {
  5317. SiS_SetReg(SISCR, i, 0x00);
  5318. }
  5319. }
  5320. /* Find out about current video mode */
  5321. ivideo->modeprechange = 0x03;
  5322. reg = SiS_GetReg(SISCR, 0x34);
  5323. if(reg & 0x7f) {
  5324. ivideo->modeprechange = reg & 0x7f;
  5325. } else if(ivideo->sisvga_enabled) {
  5326. #if defined(__i386__) || defined(__x86_64__)
  5327. unsigned char __iomem *tt = ioremap(0x400, 0x100);
  5328. if(tt) {
  5329. ivideo->modeprechange = readb(tt + 0x49);
  5330. iounmap(tt);
  5331. }
  5332. #endif
  5333. }
  5334. /* Search and copy ROM image */
  5335. ivideo->bios_abase = NULL;
  5336. ivideo->SiS_Pr.VirtualRomBase = NULL;
  5337. ivideo->SiS_Pr.UseROM = false;
  5338. ivideo->haveXGIROM = ivideo->SiS_Pr.SiS_XGIROM = false;
  5339. if(ivideo->sisfb_userom) {
  5340. ivideo->SiS_Pr.VirtualRomBase = sisfb_find_rom(pdev);
  5341. ivideo->bios_abase = ivideo->SiS_Pr.VirtualRomBase;
  5342. ivideo->SiS_Pr.UseROM = (bool)(ivideo->SiS_Pr.VirtualRomBase);
  5343. printk(KERN_INFO "sisfb: Video ROM %sfound\n",
  5344. ivideo->SiS_Pr.UseROM ? "" : "not ");
  5345. if((ivideo->SiS_Pr.UseROM) && (ivideo->chip >= XGI_20)) {
  5346. ivideo->SiS_Pr.UseROM = false;
  5347. ivideo->haveXGIROM = ivideo->SiS_Pr.SiS_XGIROM = true;
  5348. if( (ivideo->revision_id == 2) &&
  5349. (!(ivideo->bios_abase[0x1d1] & 0x01)) ) {
  5350. ivideo->SiS_Pr.DDCPortMixup = true;
  5351. }
  5352. }
  5353. } else {
  5354. printk(KERN_INFO "sisfb: Video ROM usage disabled\n");
  5355. }
  5356. /* Find systems for special custom timing */
  5357. if(ivideo->SiS_Pr.SiS_CustomT == CUT_NONE) {
  5358. sisfb_detect_custom_timing(ivideo);
  5359. }
  5360. #ifdef CONFIG_FB_SIS_315
  5361. if (ivideo->chip == XGI_20) {
  5362. /* Check if our Z7 chip is actually Z9 */
  5363. SiS_SetRegOR(SISCR, 0x4a, 0x40); /* GPIOG EN */
  5364. reg = SiS_GetReg(SISCR, 0x48);
  5365. if (reg & 0x02) { /* GPIOG */
  5366. ivideo->chip_real_id = XGI_21;
  5367. dev_info(&pdev->dev, "Z9 detected\n");
  5368. }
  5369. }
  5370. #endif
  5371. /* POST card in case this has not been done by the BIOS */
  5372. if( (!ivideo->sisvga_enabled)
  5373. #if !defined(__i386__) && !defined(__x86_64__)
  5374. || (sisfb_resetcard)
  5375. #endif
  5376. ) {
  5377. #ifdef CONFIG_FB_SIS_300
  5378. if(ivideo->sisvga_engine == SIS_300_VGA) {
  5379. if(ivideo->chip == SIS_300) {
  5380. sisfb_post_sis300(pdev);
  5381. ivideo->sisfb_can_post = 1;
  5382. }
  5383. }
  5384. #endif
  5385. #ifdef CONFIG_FB_SIS_315
  5386. if(ivideo->sisvga_engine == SIS_315_VGA) {
  5387. int result = 1;
  5388. /* if((ivideo->chip == SIS_315H) ||
  5389. (ivideo->chip == SIS_315) ||
  5390. (ivideo->chip == SIS_315PRO) ||
  5391. (ivideo->chip == SIS_330)) {
  5392. sisfb_post_sis315330(pdev);
  5393. } else */ if(ivideo->chip == XGI_20) {
  5394. result = sisfb_post_xgi(pdev);
  5395. ivideo->sisfb_can_post = 1;
  5396. } else if((ivideo->chip == XGI_40) && ivideo->haveXGIROM) {
  5397. result = sisfb_post_xgi(pdev);
  5398. ivideo->sisfb_can_post = 1;
  5399. } else {
  5400. printk(KERN_INFO "sisfb: Card is not "
  5401. "POSTed and sisfb can't do this either.\n");
  5402. }
  5403. if(!result) {
  5404. printk(KERN_ERR "sisfb: Failed to POST card\n");
  5405. ret = -ENODEV;
  5406. goto error_3;
  5407. }
  5408. }
  5409. #endif
  5410. }
  5411. ivideo->sisfb_card_posted = 1;
  5412. /* Find out about RAM size */
  5413. if(sisfb_get_dram_size(ivideo)) {
  5414. printk(KERN_INFO "sisfb: Fatal error: Unable to determine VRAM size.\n");
  5415. ret = -ENODEV;
  5416. goto error_3;
  5417. }
  5418. /* Enable PCI addressing and MMIO */
  5419. if((ivideo->sisfb_mode_idx < 0) ||
  5420. ((sisbios_mode[ivideo->sisfb_mode_idx].mode_no[ivideo->mni]) != 0xFF)) {
  5421. /* Enable PCI_LINEAR_ADDRESSING and MMIO_ENABLE */
  5422. SiS_SetRegOR(SISSR, IND_SIS_PCI_ADDRESS_SET, (SIS_PCI_ADDR_ENABLE | SIS_MEM_MAP_IO_ENABLE));
  5423. /* Enable 2D accelerator engine */
  5424. SiS_SetRegOR(SISSR, IND_SIS_MODULE_ENABLE, SIS_ENABLE_2D);
  5425. }
  5426. if(sisfb_pdc != 0xff) {
  5427. if(ivideo->sisvga_engine == SIS_300_VGA)
  5428. sisfb_pdc &= 0x3c;
  5429. else
  5430. sisfb_pdc &= 0x1f;
  5431. ivideo->SiS_Pr.PDC = sisfb_pdc;
  5432. }
  5433. #ifdef CONFIG_FB_SIS_315
  5434. if(ivideo->sisvga_engine == SIS_315_VGA) {
  5435. if(sisfb_pdca != 0xff)
  5436. ivideo->SiS_Pr.PDCA = sisfb_pdca & 0x1f;
  5437. }
  5438. #endif
  5439. if(!request_mem_region(ivideo->video_base, ivideo->video_size, "sisfb FB")) {
  5440. printk(KERN_ERR "sisfb: Fatal error: Unable to reserve %dMB framebuffer memory\n",
  5441. (int)(ivideo->video_size >> 20));
  5442. printk(KERN_ERR "sisfb: Is there another framebuffer driver active?\n");
  5443. ret = -ENODEV;
  5444. goto error_3;
  5445. }
  5446. if(!request_mem_region(ivideo->mmio_base, ivideo->mmio_size, "sisfb MMIO")) {
  5447. printk(KERN_ERR "sisfb: Fatal error: Unable to reserve MMIO region\n");
  5448. ret = -ENODEV;
  5449. goto error_2;
  5450. }
  5451. ivideo->video_vbase = ioremap(ivideo->video_base, ivideo->video_size);
  5452. ivideo->SiS_Pr.VideoMemoryAddress = ivideo->video_vbase;
  5453. if(!ivideo->video_vbase) {
  5454. printk(KERN_ERR "sisfb: Fatal error: Unable to map framebuffer memory\n");
  5455. ret = -ENODEV;
  5456. goto error_1;
  5457. }
  5458. ivideo->mmio_vbase = ioremap(ivideo->mmio_base, ivideo->mmio_size);
  5459. if(!ivideo->mmio_vbase) {
  5460. printk(KERN_ERR "sisfb: Fatal error: Unable to map MMIO region\n");
  5461. ret = -ENODEV;
  5462. error_0: iounmap(ivideo->video_vbase);
  5463. error_1: release_mem_region(ivideo->video_base, ivideo->video_size);
  5464. error_2: release_mem_region(ivideo->mmio_base, ivideo->mmio_size);
  5465. error_3: vfree(ivideo->bios_abase);
  5466. if(ivideo->lpcdev)
  5467. pci_dev_put(ivideo->lpcdev);
  5468. if(ivideo->nbridge)
  5469. pci_dev_put(ivideo->nbridge);
  5470. pci_set_drvdata(pdev, NULL);
  5471. if(!ivideo->sisvga_enabled)
  5472. pci_disable_device(pdev);
  5473. framebuffer_release(sis_fb_info);
  5474. return ret;
  5475. }
  5476. printk(KERN_INFO "sisfb: Video RAM at 0x%lx, mapped to 0x%lx, size %ldk\n",
  5477. ivideo->video_base, (unsigned long)ivideo->video_vbase, ivideo->video_size / 1024);
  5478. if(ivideo->video_offset) {
  5479. printk(KERN_INFO "sisfb: Viewport offset %ldk\n",
  5480. ivideo->video_offset / 1024);
  5481. }
  5482. printk(KERN_INFO "sisfb: MMIO at 0x%lx, mapped to 0x%lx, size %ldk\n",
  5483. ivideo->mmio_base, (unsigned long)ivideo->mmio_vbase, ivideo->mmio_size / 1024);
  5484. /* Determine the size of the command queue */
  5485. if(ivideo->sisvga_engine == SIS_300_VGA) {
  5486. ivideo->cmdQueueSize = TURBO_QUEUE_AREA_SIZE;
  5487. } else {
  5488. if(ivideo->chip == XGI_20) {
  5489. ivideo->cmdQueueSize = COMMAND_QUEUE_AREA_SIZE_Z7;
  5490. } else {
  5491. ivideo->cmdQueueSize = COMMAND_QUEUE_AREA_SIZE;
  5492. }
  5493. }
  5494. /* Engines are no longer initialized here; this is
  5495. * now done after the first mode-switch (if the
  5496. * submitted var has its acceleration flags set).
  5497. */
  5498. /* Calculate the base of the (unused) hw cursor */
  5499. ivideo->hwcursor_vbase = ivideo->video_vbase
  5500. + ivideo->video_size
  5501. - ivideo->cmdQueueSize
  5502. - ivideo->hwcursor_size;
  5503. ivideo->caps |= HW_CURSOR_CAP;
  5504. /* Initialize offscreen memory manager */
  5505. if((ivideo->havenoheap = sisfb_heap_init(ivideo))) {
  5506. printk(KERN_WARNING "sisfb: Failed to initialize offscreen memory heap\n");
  5507. }
  5508. /* Used for clearing the screen only, therefore respect our mem limit */
  5509. ivideo->SiS_Pr.VideoMemoryAddress += ivideo->video_offset;
  5510. ivideo->SiS_Pr.VideoMemorySize = ivideo->sisfb_mem;
  5511. ivideo->mtrr = -1;
  5512. ivideo->vbflags = 0;
  5513. ivideo->lcddefmodeidx = DEFAULT_LCDMODE;
  5514. ivideo->tvdefmodeidx = DEFAULT_TVMODE;
  5515. ivideo->defmodeidx = DEFAULT_MODE;
  5516. ivideo->newrom = 0;
  5517. if(ivideo->chip < XGI_20) {
  5518. if(ivideo->bios_abase) {
  5519. ivideo->newrom = SiSDetermineROMLayout661(&ivideo->SiS_Pr);
  5520. }
  5521. }
  5522. if((ivideo->sisfb_mode_idx < 0) ||
  5523. ((sisbios_mode[ivideo->sisfb_mode_idx].mode_no[ivideo->mni]) != 0xFF)) {
  5524. sisfb_sense_crt1(ivideo);
  5525. sisfb_get_VB_type(ivideo);
  5526. if(ivideo->vbflags2 & VB2_VIDEOBRIDGE) {
  5527. sisfb_detect_VB_connect(ivideo);
  5528. }
  5529. ivideo->currentvbflags = ivideo->vbflags & (VB_VIDEOBRIDGE | TV_STANDARD);
  5530. /* Decide on which CRT2 device to use */
  5531. if(ivideo->vbflags2 & VB2_VIDEOBRIDGE) {
  5532. if(ivideo->sisfb_crt2type != -1) {
  5533. if((ivideo->sisfb_crt2type == CRT2_LCD) &&
  5534. (ivideo->vbflags & CRT2_LCD)) {
  5535. ivideo->currentvbflags |= CRT2_LCD;
  5536. } else if(ivideo->sisfb_crt2type != CRT2_LCD) {
  5537. ivideo->currentvbflags |= ivideo->sisfb_crt2type;
  5538. }
  5539. } else {
  5540. /* Chrontel 700x TV detection often unreliable, therefore
  5541. * use a different default order on such machines
  5542. */
  5543. if((ivideo->sisvga_engine == SIS_300_VGA) &&
  5544. (ivideo->vbflags2 & VB2_CHRONTEL)) {
  5545. if(ivideo->vbflags & CRT2_LCD)
  5546. ivideo->currentvbflags |= CRT2_LCD;
  5547. else if(ivideo->vbflags & CRT2_TV)
  5548. ivideo->currentvbflags |= CRT2_TV;
  5549. else if(ivideo->vbflags & CRT2_VGA)
  5550. ivideo->currentvbflags |= CRT2_VGA;
  5551. } else {
  5552. if(ivideo->vbflags & CRT2_TV)
  5553. ivideo->currentvbflags |= CRT2_TV;
  5554. else if(ivideo->vbflags & CRT2_LCD)
  5555. ivideo->currentvbflags |= CRT2_LCD;
  5556. else if(ivideo->vbflags & CRT2_VGA)
  5557. ivideo->currentvbflags |= CRT2_VGA;
  5558. }
  5559. }
  5560. }
  5561. if(ivideo->vbflags & CRT2_LCD) {
  5562. sisfb_detect_lcd_type(ivideo);
  5563. }
  5564. sisfb_save_pdc_emi(ivideo);
  5565. if(!ivideo->sisfb_crt1off) {
  5566. sisfb_handle_ddc(ivideo, &ivideo->sisfb_thismonitor, 0);
  5567. } else {
  5568. if((ivideo->vbflags2 & VB2_SISTMDSBRIDGE) &&
  5569. (ivideo->vbflags & (CRT2_VGA | CRT2_LCD))) {
  5570. sisfb_handle_ddc(ivideo, &ivideo->sisfb_thismonitor, 1);
  5571. }
  5572. }
  5573. if(ivideo->sisfb_mode_idx >= 0) {
  5574. int bu = ivideo->sisfb_mode_idx;
  5575. ivideo->sisfb_mode_idx = sisfb_validate_mode(ivideo,
  5576. ivideo->sisfb_mode_idx, ivideo->currentvbflags);
  5577. if(bu != ivideo->sisfb_mode_idx) {
  5578. printk(KERN_ERR "Mode %dx%dx%d failed validation\n",
  5579. sisbios_mode[bu].xres,
  5580. sisbios_mode[bu].yres,
  5581. sisbios_mode[bu].bpp);
  5582. }
  5583. }
  5584. if(ivideo->sisfb_mode_idx < 0) {
  5585. switch(ivideo->currentvbflags & VB_DISPTYPE_DISP2) {
  5586. case CRT2_LCD:
  5587. ivideo->sisfb_mode_idx = ivideo->lcddefmodeidx;
  5588. break;
  5589. case CRT2_TV:
  5590. ivideo->sisfb_mode_idx = ivideo->tvdefmodeidx;
  5591. break;
  5592. default:
  5593. ivideo->sisfb_mode_idx = ivideo->defmodeidx;
  5594. break;
  5595. }
  5596. }
  5597. ivideo->mode_no = sisbios_mode[ivideo->sisfb_mode_idx].mode_no[ivideo->mni];
  5598. if(ivideo->refresh_rate != 0) {
  5599. sisfb_search_refresh_rate(ivideo, ivideo->refresh_rate,
  5600. ivideo->sisfb_mode_idx);
  5601. }
  5602. if(ivideo->rate_idx == 0) {
  5603. ivideo->rate_idx = sisbios_mode[ivideo->sisfb_mode_idx].rate_idx;
  5604. ivideo->refresh_rate = 60;
  5605. }
  5606. if(ivideo->sisfb_thismonitor.datavalid) {
  5607. if(!sisfb_verify_rate(ivideo, &ivideo->sisfb_thismonitor,
  5608. ivideo->sisfb_mode_idx,
  5609. ivideo->rate_idx,
  5610. ivideo->refresh_rate)) {
  5611. printk(KERN_INFO "sisfb: WARNING: Refresh rate "
  5612. "exceeds monitor specs!\n");
  5613. }
  5614. }
  5615. ivideo->video_bpp = sisbios_mode[ivideo->sisfb_mode_idx].bpp;
  5616. ivideo->video_width = sisbios_mode[ivideo->sisfb_mode_idx].xres;
  5617. ivideo->video_height = sisbios_mode[ivideo->sisfb_mode_idx].yres;
  5618. sisfb_set_vparms(ivideo);
  5619. printk(KERN_INFO "sisfb: Default mode is %dx%dx%d (%dHz)\n",
  5620. ivideo->video_width, ivideo->video_height, ivideo->video_bpp,
  5621. ivideo->refresh_rate);
  5622. /* Set up the default var according to chosen default display mode */
  5623. ivideo->default_var.xres = ivideo->default_var.xres_virtual = ivideo->video_width;
  5624. ivideo->default_var.yres = ivideo->default_var.yres_virtual = ivideo->video_height;
  5625. ivideo->default_var.bits_per_pixel = ivideo->video_bpp;
  5626. sisfb_bpp_to_var(ivideo, &ivideo->default_var);
  5627. ivideo->default_var.pixclock = (u32) (1000000000 /
  5628. sisfb_mode_rate_to_dclock(&ivideo->SiS_Pr, ivideo->mode_no, ivideo->rate_idx));
  5629. if(sisfb_mode_rate_to_ddata(&ivideo->SiS_Pr, ivideo->mode_no,
  5630. ivideo->rate_idx, &ivideo->default_var)) {
  5631. if((ivideo->default_var.vmode & FB_VMODE_MASK) == FB_VMODE_DOUBLE) {
  5632. ivideo->default_var.pixclock <<= 1;
  5633. }
  5634. }
  5635. if(ivideo->sisfb_ypan) {
  5636. /* Maximize regardless of sisfb_max at startup */
  5637. ivideo->default_var.yres_virtual =
  5638. sisfb_calc_maxyres(ivideo, &ivideo->default_var);
  5639. if(ivideo->default_var.yres_virtual < ivideo->default_var.yres) {
  5640. ivideo->default_var.yres_virtual = ivideo->default_var.yres;
  5641. }
  5642. }
  5643. sisfb_calc_pitch(ivideo, &ivideo->default_var);
  5644. ivideo->accel = 0;
  5645. if(ivideo->sisfb_accel) {
  5646. ivideo->accel = -1;
  5647. #ifdef STUPID_ACCELF_TEXT_SHIT
  5648. ivideo->default_var.accel_flags |= FB_ACCELF_TEXT;
  5649. #endif
  5650. }
  5651. sisfb_initaccel(ivideo);
  5652. #if defined(FBINFO_HWACCEL_DISABLED) && defined(FBINFO_HWACCEL_XPAN)
  5653. sis_fb_info->flags = FBINFO_DEFAULT |
  5654. FBINFO_HWACCEL_YPAN |
  5655. FBINFO_HWACCEL_XPAN |
  5656. FBINFO_HWACCEL_COPYAREA |
  5657. FBINFO_HWACCEL_FILLRECT |
  5658. ((ivideo->accel) ? 0 : FBINFO_HWACCEL_DISABLED);
  5659. #else
  5660. sis_fb_info->flags = FBINFO_FLAG_DEFAULT;
  5661. #endif
  5662. sis_fb_info->var = ivideo->default_var;
  5663. sis_fb_info->fix = ivideo->sisfb_fix;
  5664. sis_fb_info->screen_base = ivideo->video_vbase + ivideo->video_offset;
  5665. sis_fb_info->fbops = &sisfb_ops;
  5666. sis_fb_info->pseudo_palette = ivideo->pseudo_palette;
  5667. fb_alloc_cmap(&sis_fb_info->cmap, 256 , 0);
  5668. printk(KERN_DEBUG "sisfb: Initial vbflags 0x%x\n", (int)ivideo->vbflags);
  5669. #ifdef CONFIG_MTRR
  5670. ivideo->mtrr = mtrr_add(ivideo->video_base, ivideo->video_size,
  5671. MTRR_TYPE_WRCOMB, 1);
  5672. if(ivideo->mtrr < 0) {
  5673. printk(KERN_DEBUG "sisfb: Failed to add MTRRs\n");
  5674. }
  5675. #endif
  5676. if(register_framebuffer(sis_fb_info) < 0) {
  5677. printk(KERN_ERR "sisfb: Fatal error: Failed to register framebuffer\n");
  5678. ret = -EINVAL;
  5679. iounmap(ivideo->mmio_vbase);
  5680. goto error_0;
  5681. }
  5682. ivideo->registered = 1;
  5683. /* Enlist us */
  5684. ivideo->next = card_list;
  5685. card_list = ivideo;
  5686. printk(KERN_INFO "sisfb: 2D acceleration is %s, y-panning %s\n",
  5687. ivideo->sisfb_accel ? "enabled" : "disabled",
  5688. ivideo->sisfb_ypan ?
  5689. (ivideo->sisfb_max ? "enabled (auto-max)" :
  5690. "enabled (no auto-max)") :
  5691. "disabled");
  5692. printk(KERN_INFO "fb%d: %s frame buffer device version %d.%d.%d\n",
  5693. sis_fb_info->node, ivideo->myid, VER_MAJOR, VER_MINOR, VER_LEVEL);
  5694. printk(KERN_INFO "sisfb: Copyright (C) 2001-2005 Thomas Winischhofer\n");
  5695. } /* if mode = "none" */
  5696. return 0;
  5697. }
  5698. /*****************************************************/
  5699. /* PCI DEVICE HANDLING */
  5700. /*****************************************************/
  5701. static void __devexit sisfb_remove(struct pci_dev *pdev)
  5702. {
  5703. struct sis_video_info *ivideo = pci_get_drvdata(pdev);
  5704. struct fb_info *sis_fb_info = ivideo->memyselfandi;
  5705. int registered = ivideo->registered;
  5706. int modechanged = ivideo->modechanged;
  5707. /* Unmap */
  5708. iounmap(ivideo->mmio_vbase);
  5709. iounmap(ivideo->video_vbase);
  5710. /* Release mem regions */
  5711. release_mem_region(ivideo->video_base, ivideo->video_size);
  5712. release_mem_region(ivideo->mmio_base, ivideo->mmio_size);
  5713. vfree(ivideo->bios_abase);
  5714. if(ivideo->lpcdev)
  5715. pci_dev_put(ivideo->lpcdev);
  5716. if(ivideo->nbridge)
  5717. pci_dev_put(ivideo->nbridge);
  5718. #ifdef CONFIG_MTRR
  5719. /* Release MTRR region */
  5720. if(ivideo->mtrr >= 0)
  5721. mtrr_del(ivideo->mtrr, ivideo->video_base, ivideo->video_size);
  5722. #endif
  5723. pci_set_drvdata(pdev, NULL);
  5724. /* If device was disabled when starting, disable
  5725. * it when quitting.
  5726. */
  5727. if(!ivideo->sisvga_enabled)
  5728. pci_disable_device(pdev);
  5729. /* Unregister the framebuffer */
  5730. if(ivideo->registered) {
  5731. unregister_framebuffer(sis_fb_info);
  5732. framebuffer_release(sis_fb_info);
  5733. }
  5734. /* OK, our ivideo is gone for good from here. */
  5735. /* TODO: Restore the initial mode
  5736. * This sounds easy but is as good as impossible
  5737. * on many machines with SiS chip and video bridge
  5738. * since text modes are always set up differently
  5739. * from machine to machine. Depends on the type
  5740. * of integration between chipset and bridge.
  5741. */
  5742. if(registered && modechanged)
  5743. printk(KERN_INFO
  5744. "sisfb: Restoring of text mode not supported yet\n");
  5745. };
  5746. static struct pci_driver sisfb_driver = {
  5747. .name = "sisfb",
  5748. .id_table = sisfb_pci_table,
  5749. .probe = sisfb_probe,
  5750. .remove = __devexit_p(sisfb_remove)
  5751. };
  5752. static int __init sisfb_init(void)
  5753. {
  5754. #ifndef MODULE
  5755. char *options = NULL;
  5756. if(fb_get_options("sisfb", &options))
  5757. return -ENODEV;
  5758. sisfb_setup(options);
  5759. #endif
  5760. return pci_register_driver(&sisfb_driver);
  5761. }
  5762. #ifndef MODULE
  5763. module_init(sisfb_init);
  5764. #endif
  5765. /*****************************************************/
  5766. /* MODULE */
  5767. /*****************************************************/
  5768. #ifdef MODULE
  5769. static char *mode = NULL;
  5770. static int vesa = -1;
  5771. static unsigned int rate = 0;
  5772. static unsigned int crt1off = 1;
  5773. static unsigned int mem = 0;
  5774. static char *forcecrt2type = NULL;
  5775. static int forcecrt1 = -1;
  5776. static int pdc = -1;
  5777. static int pdc1 = -1;
  5778. static int noaccel = -1;
  5779. static int noypan = -1;
  5780. static int nomax = -1;
  5781. static int userom = -1;
  5782. static int useoem = -1;
  5783. static char *tvstandard = NULL;
  5784. static int nocrt2rate = 0;
  5785. static int scalelcd = -1;
  5786. static char *specialtiming = NULL;
  5787. static int lvdshl = -1;
  5788. static int tvxposoffset = 0, tvyposoffset = 0;
  5789. #if !defined(__i386__) && !defined(__x86_64__)
  5790. static int resetcard = 0;
  5791. static int videoram = 0;
  5792. #endif
  5793. static int __init sisfb_init_module(void)
  5794. {
  5795. sisfb_setdefaultparms();
  5796. if(rate)
  5797. sisfb_parm_rate = rate;
  5798. if((scalelcd == 0) || (scalelcd == 1))
  5799. sisfb_scalelcd = scalelcd ^ 1;
  5800. /* Need to check crt2 type first for fstn/dstn */
  5801. if(forcecrt2type)
  5802. sisfb_search_crt2type(forcecrt2type);
  5803. if(tvstandard)
  5804. sisfb_search_tvstd(tvstandard);
  5805. if(mode)
  5806. sisfb_search_mode(mode, false);
  5807. else if(vesa != -1)
  5808. sisfb_search_vesamode(vesa, false);
  5809. sisfb_crt1off = (crt1off == 0) ? 1 : 0;
  5810. sisfb_forcecrt1 = forcecrt1;
  5811. if(forcecrt1 == 1)
  5812. sisfb_crt1off = 0;
  5813. else if(forcecrt1 == 0)
  5814. sisfb_crt1off = 1;
  5815. if(noaccel == 1)
  5816. sisfb_accel = 0;
  5817. else if(noaccel == 0)
  5818. sisfb_accel = 1;
  5819. if(noypan == 1)
  5820. sisfb_ypan = 0;
  5821. else if(noypan == 0)
  5822. sisfb_ypan = 1;
  5823. if(nomax == 1)
  5824. sisfb_max = 0;
  5825. else if(nomax == 0)
  5826. sisfb_max = 1;
  5827. if(mem)
  5828. sisfb_parm_mem = mem;
  5829. if(userom != -1)
  5830. sisfb_userom = userom;
  5831. if(useoem != -1)
  5832. sisfb_useoem = useoem;
  5833. if(pdc != -1)
  5834. sisfb_pdc = (pdc & 0x7f);
  5835. if(pdc1 != -1)
  5836. sisfb_pdca = (pdc1 & 0x1f);
  5837. sisfb_nocrt2rate = nocrt2rate;
  5838. if(specialtiming)
  5839. sisfb_search_specialtiming(specialtiming);
  5840. if((lvdshl >= 0) && (lvdshl <= 3))
  5841. sisfb_lvdshl = lvdshl;
  5842. sisfb_tvxposoffset = tvxposoffset;
  5843. sisfb_tvyposoffset = tvyposoffset;
  5844. #if !defined(__i386__) && !defined(__x86_64__)
  5845. sisfb_resetcard = (resetcard) ? 1 : 0;
  5846. if(videoram)
  5847. sisfb_videoram = videoram;
  5848. #endif
  5849. return sisfb_init();
  5850. }
  5851. static void __exit sisfb_remove_module(void)
  5852. {
  5853. pci_unregister_driver(&sisfb_driver);
  5854. printk(KERN_DEBUG "sisfb: Module unloaded\n");
  5855. }
  5856. module_init(sisfb_init_module);
  5857. module_exit(sisfb_remove_module);
  5858. MODULE_DESCRIPTION("SiS 300/540/630/730/315/55x/65x/661/74x/330/76x/34x, XGI V3XT/V5/V8/Z7 framebuffer device driver");
  5859. MODULE_LICENSE("GPL");
  5860. MODULE_AUTHOR("Thomas Winischhofer <thomas@winischhofer.net>, Others");
  5861. module_param(mem, int, 0);
  5862. module_param(noaccel, int, 0);
  5863. module_param(noypan, int, 0);
  5864. module_param(nomax, int, 0);
  5865. module_param(userom, int, 0);
  5866. module_param(useoem, int, 0);
  5867. module_param(mode, charp, 0);
  5868. module_param(vesa, int, 0);
  5869. module_param(rate, int, 0);
  5870. module_param(forcecrt1, int, 0);
  5871. module_param(forcecrt2type, charp, 0);
  5872. module_param(scalelcd, int, 0);
  5873. module_param(pdc, int, 0);
  5874. module_param(pdc1, int, 0);
  5875. module_param(specialtiming, charp, 0);
  5876. module_param(lvdshl, int, 0);
  5877. module_param(tvstandard, charp, 0);
  5878. module_param(tvxposoffset, int, 0);
  5879. module_param(tvyposoffset, int, 0);
  5880. module_param(nocrt2rate, int, 0);
  5881. #if !defined(__i386__) && !defined(__x86_64__)
  5882. module_param(resetcard, int, 0);
  5883. module_param(videoram, int, 0);
  5884. #endif
  5885. MODULE_PARM_DESC(mem,
  5886. "\nDetermines the beginning of the video memory heap in KB. This heap is used\n"
  5887. "for video RAM management for eg. DRM/DRI. On 300 series, the default depends\n"
  5888. "on the amount of video RAM available. If 8MB of video RAM or less is available,\n"
  5889. "the heap starts at 4096KB, if between 8 and 16MB are available at 8192KB,\n"
  5890. "otherwise at 12288KB. On 315/330/340 series, the heap size is 32KB by default.\n"
  5891. "The value is to be specified without 'KB'.\n");
  5892. MODULE_PARM_DESC(noaccel,
  5893. "\nIf set to anything other than 0, 2D acceleration will be disabled.\n"
  5894. "(default: 0)\n");
  5895. MODULE_PARM_DESC(noypan,
  5896. "\nIf set to anything other than 0, y-panning will be disabled and scrolling\n"
  5897. "will be performed by redrawing the screen. (default: 0)\n");
  5898. MODULE_PARM_DESC(nomax,
  5899. "\nIf y-panning is enabled, sisfb will by default use the entire available video\n"
  5900. "memory for the virtual screen in order to optimize scrolling performance. If\n"
  5901. "this is set to anything other than 0, sisfb will not do this and thereby \n"
  5902. "enable the user to positively specify a virtual Y size of the screen using\n"
  5903. "fbset. (default: 0)\n");
  5904. MODULE_PARM_DESC(mode,
  5905. "\nSelects the desired default display mode in the format XxYxDepth,\n"
  5906. "eg. 1024x768x16. Other formats supported include XxY-Depth and\n"
  5907. "XxY-Depth@Rate. If the parameter is only one (decimal or hexadecimal)\n"
  5908. "number, it will be interpreted as a VESA mode number. (default: 800x600x8)\n");
  5909. MODULE_PARM_DESC(vesa,
  5910. "\nSelects the desired default display mode by VESA defined mode number, eg.\n"
  5911. "0x117 (default: 0x0103)\n");
  5912. MODULE_PARM_DESC(rate,
  5913. "\nSelects the desired vertical refresh rate for CRT1 (external VGA) in Hz.\n"
  5914. "If the mode is specified in the format XxY-Depth@Rate, this parameter\n"
  5915. "will be ignored (default: 60)\n");
  5916. MODULE_PARM_DESC(forcecrt1,
  5917. "\nNormally, the driver autodetects whether or not CRT1 (external VGA) is \n"
  5918. "connected. With this option, the detection can be overridden (1=CRT1 ON,\n"
  5919. "0=CRT1 OFF) (default: [autodetected])\n");
  5920. MODULE_PARM_DESC(forcecrt2type,
  5921. "\nIf this option is omitted, the driver autodetects CRT2 output devices, such as\n"
  5922. "LCD, TV or secondary VGA. With this option, this autodetection can be\n"
  5923. "overridden. Possible parameters are LCD, TV, VGA or NONE. NONE disables CRT2.\n"
  5924. "On systems with a SiS video bridge, parameters SVIDEO, COMPOSITE or SCART can\n"
  5925. "be used instead of TV to override the TV detection. Furthermore, on systems\n"
  5926. "with a SiS video bridge, SVIDEO+COMPOSITE, HIVISION, YPBPR480I, YPBPR480P,\n"
  5927. "YPBPR720P and YPBPR1080I are understood. However, whether or not these work\n"
  5928. "depends on the very hardware in use. (default: [autodetected])\n");
  5929. MODULE_PARM_DESC(scalelcd,
  5930. "\nSetting this to 1 will force the driver to scale the LCD image to the panel's\n"
  5931. "native resolution. Setting it to 0 will disable scaling; LVDS panels will\n"
  5932. "show black bars around the image, TMDS panels will probably do the scaling\n"
  5933. "themselves. Default: 1 on LVDS panels, 0 on TMDS panels\n");
  5934. MODULE_PARM_DESC(pdc,
  5935. "\nThis is for manually selecting the LCD panel delay compensation. The driver\n"
  5936. "should detect this correctly in most cases; however, sometimes this is not\n"
  5937. "possible. If you see 'small waves' on the LCD, try setting this to 4, 32 or 24\n"
  5938. "on a 300 series chipset; 6 on other chipsets. If the problem persists, try\n"
  5939. "other values (on 300 series: between 4 and 60 in steps of 4; otherwise: any\n"
  5940. "value from 0 to 31). (default: autodetected, if LCD is active during start)\n");
  5941. #ifdef CONFIG_FB_SIS_315
  5942. MODULE_PARM_DESC(pdc1,
  5943. "\nThis is same as pdc, but for LCD-via CRT1. Hence, this is for the 315/330/340\n"
  5944. "series only. (default: autodetected if LCD is in LCD-via-CRT1 mode during\n"
  5945. "startup) - Note: currently, this has no effect because LCD-via-CRT1 is not\n"
  5946. "implemented yet.\n");
  5947. #endif
  5948. MODULE_PARM_DESC(specialtiming,
  5949. "\nPlease refer to documentation for more information on this option.\n");
  5950. MODULE_PARM_DESC(lvdshl,
  5951. "\nPlease refer to documentation for more information on this option.\n");
  5952. MODULE_PARM_DESC(tvstandard,
  5953. "\nThis allows overriding the BIOS default for the TV standard. Valid choices are\n"
  5954. "pal, ntsc, palm and paln. (default: [auto; pal or ntsc only])\n");
  5955. MODULE_PARM_DESC(tvxposoffset,
  5956. "\nRelocate TV output horizontally. Possible parameters: -32 through 32.\n"
  5957. "Default: 0\n");
  5958. MODULE_PARM_DESC(tvyposoffset,
  5959. "\nRelocate TV output vertically. Possible parameters: -32 through 32.\n"
  5960. "Default: 0\n");
  5961. MODULE_PARM_DESC(nocrt2rate,
  5962. "\nSetting this to 1 will force the driver to use the default refresh rate for\n"
  5963. "CRT2 if CRT2 type is VGA. (default: 0, use same rate as CRT1)\n");
  5964. #if !defined(__i386__) && !defined(__x86_64__)
  5965. #ifdef CONFIG_FB_SIS_300
  5966. MODULE_PARM_DESC(resetcard,
  5967. "\nSet this to 1 in order to reset (POST) the card on non-x86 machines where\n"
  5968. "the BIOS did not POST the card (only supported for SiS 300/305 and XGI cards\n"
  5969. "currently). Default: 0\n");
  5970. MODULE_PARM_DESC(videoram,
  5971. "\nSet this to the amount of video RAM (in kilobyte) the card has. Required on\n"
  5972. "some non-x86 architectures where the memory auto detection fails. Only\n"
  5973. "relevant if resetcard is set, too. SiS300/305 only. Default: [auto-detect]\n");
  5974. #endif
  5975. #endif
  5976. #endif /* /MODULE */
  5977. /* _GPL only for new symbols. */
  5978. EXPORT_SYMBOL(sis_malloc);
  5979. EXPORT_SYMBOL(sis_free);
  5980. EXPORT_SYMBOL_GPL(sis_malloc_new);
  5981. EXPORT_SYMBOL_GPL(sis_free_new);