sis_main.c 184 KB

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