sis_main.c 183 KB

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