init301.c 334 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072
  1. /* $XFree86$ */
  2. /* $XdotOrg$ */
  3. /*
  4. * Mode initializing code (CRT2 section)
  5. * for SiS 300/305/540/630/730,
  6. * SiS 315/550/[M]650/651/[M]661[FGM]X/[M]74x[GX]/330/[M]76x[GX],
  7. * XGI V3XT/V5/V8, Z7
  8. * (Universal module for Linux kernel framebuffer and X.org/XFree86 4.x)
  9. *
  10. * Copyright (C) 2001-2005 by Thomas Winischhofer, Vienna, Austria
  11. *
  12. * If distributed as part of the Linux kernel, the following license terms
  13. * apply:
  14. *
  15. * * This program is free software; you can redistribute it and/or modify
  16. * * it under the terms of the GNU General Public License as published by
  17. * * the Free Software Foundation; either version 2 of the named License,
  18. * * or any later version.
  19. * *
  20. * * This program is distributed in the hope that it will be useful,
  21. * * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * * GNU General Public License for more details.
  24. * *
  25. * * You should have received a copy of the GNU General Public License
  26. * * along with this program; if not, write to the Free Software
  27. * * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
  28. *
  29. * Otherwise, the following license terms apply:
  30. *
  31. * * Redistribution and use in source and binary forms, with or without
  32. * * modification, are permitted provided that the following conditions
  33. * * are met:
  34. * * 1) Redistributions of source code must retain the above copyright
  35. * * notice, this list of conditions and the following disclaimer.
  36. * * 2) Redistributions in binary form must reproduce the above copyright
  37. * * notice, this list of conditions and the following disclaimer in the
  38. * * documentation and/or other materials provided with the distribution.
  39. * * 3) The name of the author may not be used to endorse or promote products
  40. * * derived from this software without specific prior written permission.
  41. * *
  42. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  43. * * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  44. * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  45. * * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  46. * * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  47. * * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  48. * * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  49. * * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  50. * * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  51. * * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  52. *
  53. * Author: Thomas Winischhofer <thomas@winischhofer.net>
  54. *
  55. * Formerly based on non-functional code-fragements for 300 series by SiS, Inc.
  56. * Used by permission.
  57. *
  58. */
  59. #if 1
  60. #define SET_EMI /* 302LV/ELV: Set EMI values */
  61. #endif
  62. #if 1
  63. #define SET_PWD /* 301/302LV: Set PWD */
  64. #endif
  65. #define COMPAL_HACK /* Needed for Compal 1400x1050 (EMI) */
  66. #define COMPAQ_HACK /* Needed for Inventec/Compaq 1280x1024 (EMI) */
  67. #define ASUS_HACK /* Needed for Asus A2H 1024x768 (EMI) */
  68. #include "init301.h"
  69. #ifdef CONFIG_FB_SIS_300
  70. #include "oem300.h"
  71. #endif
  72. #ifdef CONFIG_FB_SIS_315
  73. #include "oem310.h"
  74. #endif
  75. #define SiS_I2CDELAY 1000
  76. #define SiS_I2CDELAYSHORT 150
  77. static unsigned short SiS_GetBIOSLCDResInfo(struct SiS_Private *SiS_Pr);
  78. static void SiS_SetCH70xx(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val);
  79. /*********************************************/
  80. /* HELPER: Lock/Unlock CRT2 */
  81. /*********************************************/
  82. void
  83. SiS_UnLockCRT2(struct SiS_Private *SiS_Pr)
  84. {
  85. if(SiS_Pr->ChipType == XGI_20)
  86. return;
  87. else if(SiS_Pr->ChipType >= SIS_315H)
  88. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2f,0x01);
  89. else
  90. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x24,0x01);
  91. }
  92. static
  93. void
  94. SiS_LockCRT2(struct SiS_Private *SiS_Pr)
  95. {
  96. if(SiS_Pr->ChipType == XGI_20)
  97. return;
  98. else if(SiS_Pr->ChipType >= SIS_315H)
  99. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2F,0xFE);
  100. else
  101. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x24,0xFE);
  102. }
  103. /*********************************************/
  104. /* HELPER: Write SR11 */
  105. /*********************************************/
  106. static void
  107. SiS_SetRegSR11ANDOR(struct SiS_Private *SiS_Pr, unsigned short DataAND, unsigned short DataOR)
  108. {
  109. if(SiS_Pr->ChipType >= SIS_661) {
  110. DataAND &= 0x0f;
  111. DataOR &= 0x0f;
  112. }
  113. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x11,DataAND,DataOR);
  114. }
  115. /*********************************************/
  116. /* HELPER: Get Pointer to LCD structure */
  117. /*********************************************/
  118. #ifdef CONFIG_FB_SIS_315
  119. static unsigned char *
  120. GetLCDStructPtr661(struct SiS_Private *SiS_Pr)
  121. {
  122. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  123. unsigned char *myptr = NULL;
  124. unsigned short romindex = 0, reg = 0, idx = 0;
  125. /* Use the BIOS tables only for LVDS panels; TMDS is unreliable
  126. * due to the variaty of panels the BIOS doesn't know about.
  127. * Exception: If the BIOS has better knowledge (such as in case
  128. * of machines with a 301C and a panel that does not support DDC)
  129. * use the BIOS data as well.
  130. */
  131. if((SiS_Pr->SiS_ROMNew) &&
  132. ((SiS_Pr->SiS_VBType & VB_SISLVDS) || (!SiS_Pr->PanelSelfDetected))) {
  133. if(SiS_Pr->ChipType < SIS_661) reg = 0x3c;
  134. else reg = 0x7d;
  135. idx = (SiS_GetReg(SiS_Pr->SiS_P3d4,reg) & 0x1f) * 26;
  136. if(idx < (8*26)) {
  137. myptr = (unsigned char *)&SiS_LCDStruct661[idx];
  138. }
  139. romindex = SISGETROMW(0x100);
  140. if(romindex) {
  141. romindex += idx;
  142. myptr = &ROMAddr[romindex];
  143. }
  144. }
  145. return myptr;
  146. }
  147. static unsigned short
  148. GetLCDStructPtr661_2(struct SiS_Private *SiS_Pr)
  149. {
  150. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  151. unsigned short romptr = 0;
  152. /* Use the BIOS tables only for LVDS panels; TMDS is unreliable
  153. * due to the variaty of panels the BIOS doesn't know about.
  154. * Exception: If the BIOS has better knowledge (such as in case
  155. * of machines with a 301C and a panel that does not support DDC)
  156. * use the BIOS data as well.
  157. */
  158. if((SiS_Pr->SiS_ROMNew) &&
  159. ((SiS_Pr->SiS_VBType & VB_SISLVDS) || (!SiS_Pr->PanelSelfDetected))) {
  160. romptr = SISGETROMW(0x102);
  161. romptr += ((SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4) * SiS_Pr->SiS661LCD2TableSize);
  162. }
  163. return romptr;
  164. }
  165. #endif
  166. /*********************************************/
  167. /* Adjust Rate for CRT2 */
  168. /*********************************************/
  169. static bool
  170. SiS_AdjustCRT2Rate(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  171. unsigned short RRTI, unsigned short *i)
  172. {
  173. unsigned short checkmask=0, modeid, infoflag;
  174. modeid = SiS_Pr->SiS_RefIndex[RRTI + (*i)].ModeID;
  175. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  176. if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) {
  177. checkmask |= SupportRAMDAC2;
  178. if(SiS_Pr->ChipType >= SIS_315H) {
  179. checkmask |= SupportRAMDAC2_135;
  180. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  181. checkmask |= SupportRAMDAC2_162;
  182. if(SiS_Pr->SiS_VBType & VB_SISRAMDAC202) {
  183. checkmask |= SupportRAMDAC2_202;
  184. }
  185. }
  186. }
  187. } else if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  188. checkmask |= SupportLCD;
  189. if(SiS_Pr->ChipType >= SIS_315H) {
  190. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  191. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  192. if(modeid == 0x2e) checkmask |= Support64048060Hz;
  193. }
  194. }
  195. }
  196. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  197. checkmask |= SupportHiVision;
  198. } else if(SiS_Pr->SiS_VBInfo & (SetCRT2ToYPbPr525750|SetCRT2ToAVIDEO|SetCRT2ToSVIDEO|SetCRT2ToSCART)) {
  199. checkmask |= SupportTV;
  200. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  201. checkmask |= SupportTV1024;
  202. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  203. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) {
  204. checkmask |= SupportYPbPr750p;
  205. }
  206. }
  207. }
  208. }
  209. } else { /* LVDS */
  210. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  211. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  212. checkmask |= SupportCHTV;
  213. }
  214. }
  215. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  216. checkmask |= SupportLCD;
  217. }
  218. }
  219. /* Look backwards in table for matching CRT2 mode */
  220. for(; SiS_Pr->SiS_RefIndex[RRTI + (*i)].ModeID == modeid; (*i)--) {
  221. infoflag = SiS_Pr->SiS_RefIndex[RRTI + (*i)].Ext_InfoFlag;
  222. if(infoflag & checkmask) return true;
  223. if((*i) == 0) break;
  224. }
  225. /* Look through the whole mode-section of the table from the beginning
  226. * for a matching CRT2 mode if no mode was found yet.
  227. */
  228. for((*i) = 0; ; (*i)++) {
  229. if(SiS_Pr->SiS_RefIndex[RRTI + (*i)].ModeID != modeid) break;
  230. infoflag = SiS_Pr->SiS_RefIndex[RRTI + (*i)].Ext_InfoFlag;
  231. if(infoflag & checkmask) return true;
  232. }
  233. return false;
  234. }
  235. /*********************************************/
  236. /* Get rate index */
  237. /*********************************************/
  238. unsigned short
  239. SiS_GetRatePtr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  240. {
  241. unsigned short RRTI,i,backup_i;
  242. unsigned short modeflag,index,temp,backupindex;
  243. static const unsigned short LCDRefreshIndex[] = {
  244. 0x00, 0x00, 0x01, 0x01,
  245. 0x01, 0x01, 0x01, 0x01,
  246. 0x01, 0x01, 0x01, 0x01,
  247. 0x01, 0x01, 0x01, 0x01,
  248. 0x00, 0x00, 0x00, 0x00
  249. };
  250. /* Do NOT check for UseCustomMode here, will skrew up FIFO */
  251. if(ModeNo == 0xfe) return 0;
  252. if(ModeNo <= 0x13) {
  253. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  254. } else {
  255. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  256. }
  257. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  258. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  259. if(modeflag & HalfDCLK) return 0;
  260. }
  261. }
  262. if(ModeNo < 0x14) return 0xFFFF;
  263. index = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x33) >> SiS_Pr->SiS_SelectCRT2Rate) & 0x0F;
  264. backupindex = index;
  265. if(index > 0) index--;
  266. if(SiS_Pr->SiS_SetFlag & ProgrammingCRT2) {
  267. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  268. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  269. if(SiS_Pr->SiS_VBType & VB_NoLCD) index = 0;
  270. else if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) index = backupindex = 0;
  271. }
  272. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  273. if(!(SiS_Pr->SiS_VBType & VB_NoLCD)) {
  274. temp = LCDRefreshIndex[SiS_GetBIOSLCDResInfo(SiS_Pr)];
  275. if(index > temp) index = temp;
  276. }
  277. }
  278. } else {
  279. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) index = 0;
  280. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  281. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) index = 0;
  282. }
  283. }
  284. }
  285. RRTI = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].REFindex;
  286. ModeNo = SiS_Pr->SiS_RefIndex[RRTI].ModeID;
  287. if(SiS_Pr->ChipType >= SIS_315H) {
  288. if(!(SiS_Pr->SiS_VBInfo & DriverMode)) {
  289. if( (SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_VESAID == 0x105) ||
  290. (SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_VESAID == 0x107) ) {
  291. if(backupindex <= 1) RRTI++;
  292. }
  293. }
  294. }
  295. i = 0;
  296. do {
  297. if(SiS_Pr->SiS_RefIndex[RRTI + i].ModeID != ModeNo) break;
  298. temp = SiS_Pr->SiS_RefIndex[RRTI + i].Ext_InfoFlag;
  299. temp &= ModeTypeMask;
  300. if(temp < SiS_Pr->SiS_ModeType) break;
  301. i++;
  302. index--;
  303. } while(index != 0xFFFF);
  304. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) {
  305. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  306. temp = SiS_Pr->SiS_RefIndex[RRTI + i - 1].Ext_InfoFlag;
  307. if(temp & InterlaceMode) i++;
  308. }
  309. }
  310. i--;
  311. if((SiS_Pr->SiS_SetFlag & ProgrammingCRT2) && (!(SiS_Pr->SiS_VBInfo & DisableCRT2Display))) {
  312. backup_i = i;
  313. if(!(SiS_AdjustCRT2Rate(SiS_Pr, ModeNo, ModeIdIndex, RRTI, &i))) {
  314. i = backup_i;
  315. }
  316. }
  317. return (RRTI + i);
  318. }
  319. /*********************************************/
  320. /* STORE CRT2 INFO in CR34 */
  321. /*********************************************/
  322. static void
  323. SiS_SaveCRT2Info(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
  324. {
  325. unsigned short temp1, temp2;
  326. /* Store CRT1 ModeNo in CR34 */
  327. SiS_SetReg(SiS_Pr->SiS_P3d4,0x34,ModeNo);
  328. temp1 = (SiS_Pr->SiS_VBInfo & SetInSlaveMode) >> 8;
  329. temp2 = ~(SetInSlaveMode >> 8);
  330. SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x31,temp2,temp1);
  331. }
  332. /*********************************************/
  333. /* HELPER: GET SOME DATA FROM BIOS ROM */
  334. /*********************************************/
  335. #ifdef CONFIG_FB_SIS_300
  336. static bool
  337. SiS_CR36BIOSWord23b(struct SiS_Private *SiS_Pr)
  338. {
  339. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  340. unsigned short temp,temp1;
  341. if(SiS_Pr->SiS_UseROM) {
  342. if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) {
  343. temp = 1 << ((SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4) & 0x0f);
  344. temp1 = SISGETROMW(0x23b);
  345. if(temp1 & temp) return true;
  346. }
  347. }
  348. return false;
  349. }
  350. static bool
  351. SiS_CR36BIOSWord23d(struct SiS_Private *SiS_Pr)
  352. {
  353. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  354. unsigned short temp,temp1;
  355. if(SiS_Pr->SiS_UseROM) {
  356. if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) {
  357. temp = 1 << ((SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4) & 0x0f);
  358. temp1 = SISGETROMW(0x23d);
  359. if(temp1 & temp) return true;
  360. }
  361. }
  362. return false;
  363. }
  364. #endif
  365. /*********************************************/
  366. /* HELPER: DELAY FUNCTIONS */
  367. /*********************************************/
  368. void
  369. SiS_DDC2Delay(struct SiS_Private *SiS_Pr, unsigned int delaytime)
  370. {
  371. while (delaytime-- > 0)
  372. SiS_GetReg(SiS_Pr->SiS_P3c4, 0x05);
  373. }
  374. #if defined(CONFIG_FB_SIS_300) || defined(CONFIG_FB_SIS_315)
  375. static void
  376. SiS_GenericDelay(struct SiS_Private *SiS_Pr, unsigned short delay)
  377. {
  378. SiS_DDC2Delay(SiS_Pr, delay * 36);
  379. }
  380. #endif
  381. #ifdef CONFIG_FB_SIS_315
  382. static void
  383. SiS_LongDelay(struct SiS_Private *SiS_Pr, unsigned short delay)
  384. {
  385. while(delay--) {
  386. SiS_GenericDelay(SiS_Pr, 6623);
  387. }
  388. }
  389. #endif
  390. #if defined(CONFIG_FB_SIS_300) || defined(CONFIG_FB_SIS_315)
  391. static void
  392. SiS_ShortDelay(struct SiS_Private *SiS_Pr, unsigned short delay)
  393. {
  394. while(delay--) {
  395. SiS_GenericDelay(SiS_Pr, 66);
  396. }
  397. }
  398. #endif
  399. static void
  400. SiS_PanelDelay(struct SiS_Private *SiS_Pr, unsigned short DelayTime)
  401. {
  402. #if defined(CONFIG_FB_SIS_300) || defined(CONFIG_FB_SIS_315)
  403. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  404. unsigned short PanelID, DelayIndex, Delay=0;
  405. #endif
  406. if(SiS_Pr->ChipType < SIS_315H) {
  407. #ifdef CONFIG_FB_SIS_300
  408. PanelID = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36);
  409. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  410. if(SiS_Pr->SiS_VBType & VB_SIS301) PanelID &= 0xf7;
  411. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x18) & 0x10)) PanelID = 0x12;
  412. }
  413. DelayIndex = PanelID >> 4;
  414. if((DelayTime >= 2) && ((PanelID & 0x0f) == 1)) {
  415. Delay = 3;
  416. } else {
  417. if(DelayTime >= 2) DelayTime -= 2;
  418. if(!(DelayTime & 0x01)) {
  419. Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[0];
  420. } else {
  421. Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[1];
  422. }
  423. if(SiS_Pr->SiS_UseROM) {
  424. if(ROMAddr[0x220] & 0x40) {
  425. if(!(DelayTime & 0x01)) Delay = (unsigned short)ROMAddr[0x225];
  426. else Delay = (unsigned short)ROMAddr[0x226];
  427. }
  428. }
  429. }
  430. SiS_ShortDelay(SiS_Pr, Delay);
  431. #endif /* CONFIG_FB_SIS_300 */
  432. } else {
  433. #ifdef CONFIG_FB_SIS_315
  434. if((SiS_Pr->ChipType >= SIS_661) ||
  435. (SiS_Pr->ChipType <= SIS_315PRO) ||
  436. (SiS_Pr->ChipType == SIS_330) ||
  437. (SiS_Pr->SiS_ROMNew)) {
  438. if(!(DelayTime & 0x01)) {
  439. SiS_DDC2Delay(SiS_Pr, 0x1000);
  440. } else {
  441. SiS_DDC2Delay(SiS_Pr, 0x4000);
  442. }
  443. } else if((SiS_Pr->SiS_IF_DEF_LVDS == 1) /* ||
  444. (SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) ||
  445. (SiS_Pr->SiS_CustomT == CUT_CLEVO1400) */ ) { /* 315 series, LVDS; Special */
  446. if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
  447. PanelID = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36);
  448. if(SiS_Pr->SiS_CustomT == CUT_CLEVO1400) {
  449. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x1b) & 0x10)) PanelID = 0x12;
  450. }
  451. if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) {
  452. DelayIndex = PanelID & 0x0f;
  453. } else {
  454. DelayIndex = PanelID >> 4;
  455. }
  456. if((DelayTime >= 2) && ((PanelID & 0x0f) == 1)) {
  457. Delay = 3;
  458. } else {
  459. if(DelayTime >= 2) DelayTime -= 2;
  460. if(!(DelayTime & 0x01)) {
  461. Delay = SiS_Pr->SiS_PanelDelayTblLVDS[DelayIndex].timer[0];
  462. } else {
  463. Delay = SiS_Pr->SiS_PanelDelayTblLVDS[DelayIndex].timer[1];
  464. }
  465. if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
  466. if(ROMAddr[0x13c] & 0x40) {
  467. if(!(DelayTime & 0x01)) {
  468. Delay = (unsigned short)ROMAddr[0x17e];
  469. } else {
  470. Delay = (unsigned short)ROMAddr[0x17f];
  471. }
  472. }
  473. }
  474. }
  475. SiS_ShortDelay(SiS_Pr, Delay);
  476. }
  477. } else if(SiS_Pr->SiS_VBType & VB_SISVB) { /* 315 series, all bridges */
  478. DelayIndex = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4;
  479. if(!(DelayTime & 0x01)) {
  480. Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[0];
  481. } else {
  482. Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[1];
  483. }
  484. Delay <<= 8;
  485. SiS_DDC2Delay(SiS_Pr, Delay);
  486. }
  487. #endif /* CONFIG_FB_SIS_315 */
  488. }
  489. }
  490. #ifdef CONFIG_FB_SIS_315
  491. static void
  492. SiS_PanelDelayLoop(struct SiS_Private *SiS_Pr, unsigned short DelayTime, unsigned short DelayLoop)
  493. {
  494. int i;
  495. for(i = 0; i < DelayLoop; i++) {
  496. SiS_PanelDelay(SiS_Pr, DelayTime);
  497. }
  498. }
  499. #endif
  500. /*********************************************/
  501. /* HELPER: WAIT-FOR-RETRACE FUNCTIONS */
  502. /*********************************************/
  503. void
  504. SiS_WaitRetrace1(struct SiS_Private *SiS_Pr)
  505. {
  506. unsigned short watchdog;
  507. if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x1f) & 0xc0) return;
  508. if(!(SiS_GetReg(SiS_Pr->SiS_P3d4,0x17) & 0x80)) return;
  509. watchdog = 65535;
  510. while((SiS_GetRegByte(SiS_Pr->SiS_P3da) & 0x08) && --watchdog);
  511. watchdog = 65535;
  512. while((!(SiS_GetRegByte(SiS_Pr->SiS_P3da) & 0x08)) && --watchdog);
  513. }
  514. #if defined(CONFIG_FB_SIS_300) || defined(CONFIG_FB_SIS_315)
  515. static void
  516. SiS_WaitRetrace2(struct SiS_Private *SiS_Pr, unsigned short reg)
  517. {
  518. unsigned short watchdog;
  519. watchdog = 65535;
  520. while((SiS_GetReg(SiS_Pr->SiS_Part1Port,reg) & 0x02) && --watchdog);
  521. watchdog = 65535;
  522. while((!(SiS_GetReg(SiS_Pr->SiS_Part1Port,reg) & 0x02)) && --watchdog);
  523. }
  524. #endif
  525. static void
  526. SiS_WaitVBRetrace(struct SiS_Private *SiS_Pr)
  527. {
  528. if(SiS_Pr->ChipType < SIS_315H) {
  529. #ifdef CONFIG_FB_SIS_300
  530. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  531. if(!(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x20)) return;
  532. }
  533. if(!(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x80)) {
  534. SiS_WaitRetrace1(SiS_Pr);
  535. } else {
  536. SiS_WaitRetrace2(SiS_Pr, 0x25);
  537. }
  538. #endif
  539. } else {
  540. #ifdef CONFIG_FB_SIS_315
  541. if(!(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x40)) {
  542. SiS_WaitRetrace1(SiS_Pr);
  543. } else {
  544. SiS_WaitRetrace2(SiS_Pr, 0x30);
  545. }
  546. #endif
  547. }
  548. }
  549. static void
  550. SiS_VBWait(struct SiS_Private *SiS_Pr)
  551. {
  552. unsigned short tempal,temp,i,j;
  553. temp = 0;
  554. for(i = 0; i < 3; i++) {
  555. for(j = 0; j < 100; j++) {
  556. tempal = SiS_GetRegByte(SiS_Pr->SiS_P3da);
  557. if(temp & 0x01) {
  558. if((tempal & 0x08)) continue;
  559. else break;
  560. } else {
  561. if(!(tempal & 0x08)) continue;
  562. else break;
  563. }
  564. }
  565. temp ^= 0x01;
  566. }
  567. }
  568. static void
  569. SiS_VBLongWait(struct SiS_Private *SiS_Pr)
  570. {
  571. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  572. SiS_VBWait(SiS_Pr);
  573. } else {
  574. SiS_WaitRetrace1(SiS_Pr);
  575. }
  576. }
  577. /*********************************************/
  578. /* HELPER: MISC */
  579. /*********************************************/
  580. #ifdef CONFIG_FB_SIS_300
  581. static bool
  582. SiS_Is301B(struct SiS_Private *SiS_Pr)
  583. {
  584. if(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x01) >= 0xb0) return true;
  585. return false;
  586. }
  587. #endif
  588. static bool
  589. SiS_CRT2IsLCD(struct SiS_Private *SiS_Pr)
  590. {
  591. if(SiS_Pr->ChipType == SIS_730) {
  592. if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x20) return true;
  593. }
  594. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x30) & 0x20) return true;
  595. return false;
  596. }
  597. bool
  598. SiS_IsDualEdge(struct SiS_Private *SiS_Pr)
  599. {
  600. #ifdef CONFIG_FB_SIS_315
  601. if(SiS_Pr->ChipType >= SIS_315H) {
  602. if((SiS_Pr->ChipType != SIS_650) || (SiS_GetReg(SiS_Pr->SiS_P3d4,0x5f) & 0xf0)) {
  603. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x38) & EnableDualEdge) return true;
  604. }
  605. }
  606. #endif
  607. return false;
  608. }
  609. bool
  610. SiS_IsVAMode(struct SiS_Private *SiS_Pr)
  611. {
  612. #ifdef CONFIG_FB_SIS_315
  613. unsigned short flag;
  614. if(SiS_Pr->ChipType >= SIS_315H) {
  615. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  616. if((flag & EnableDualEdge) && (flag & SetToLCDA)) return true;
  617. }
  618. #endif
  619. return false;
  620. }
  621. #ifdef CONFIG_FB_SIS_315
  622. static bool
  623. SiS_IsVAorLCD(struct SiS_Private *SiS_Pr)
  624. {
  625. if(SiS_IsVAMode(SiS_Pr)) return true;
  626. if(SiS_CRT2IsLCD(SiS_Pr)) return true;
  627. return false;
  628. }
  629. #endif
  630. static bool
  631. SiS_IsDualLink(struct SiS_Private *SiS_Pr)
  632. {
  633. #ifdef CONFIG_FB_SIS_315
  634. if(SiS_Pr->ChipType >= SIS_315H) {
  635. if((SiS_CRT2IsLCD(SiS_Pr)) ||
  636. (SiS_IsVAMode(SiS_Pr))) {
  637. if(SiS_Pr->SiS_LCDInfo & LCDDualLink) return true;
  638. }
  639. }
  640. #endif
  641. return false;
  642. }
  643. #ifdef CONFIG_FB_SIS_315
  644. static bool
  645. SiS_TVEnabled(struct SiS_Private *SiS_Pr)
  646. {
  647. if((SiS_GetReg(SiS_Pr->SiS_Part2Port,0x00) & 0x0f) != 0x0c) return true;
  648. if(SiS_Pr->SiS_VBType & VB_SISYPBPR) {
  649. if(SiS_GetReg(SiS_Pr->SiS_Part2Port,0x4d) & 0x10) return true;
  650. }
  651. return false;
  652. }
  653. #endif
  654. #ifdef CONFIG_FB_SIS_315
  655. static bool
  656. SiS_LCDAEnabled(struct SiS_Private *SiS_Pr)
  657. {
  658. if(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x13) & 0x04) return true;
  659. return false;
  660. }
  661. #endif
  662. #ifdef CONFIG_FB_SIS_315
  663. static bool
  664. SiS_WeHaveBacklightCtrl(struct SiS_Private *SiS_Pr)
  665. {
  666. if((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->ChipType < SIS_661)) {
  667. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x79) & 0x10) return true;
  668. }
  669. return false;
  670. }
  671. #endif
  672. #ifdef CONFIG_FB_SIS_315
  673. static bool
  674. SiS_IsNotM650orLater(struct SiS_Private *SiS_Pr)
  675. {
  676. unsigned short flag;
  677. if(SiS_Pr->ChipType == SIS_650) {
  678. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x5f) & 0xf0;
  679. /* Check for revision != A0 only */
  680. if((flag == 0xe0) || (flag == 0xc0) ||
  681. (flag == 0xb0) || (flag == 0x90)) return false;
  682. } else if(SiS_Pr->ChipType >= SIS_661) return false;
  683. return true;
  684. }
  685. #endif
  686. #ifdef CONFIG_FB_SIS_315
  687. static bool
  688. SiS_IsYPbPr(struct SiS_Private *SiS_Pr)
  689. {
  690. if(SiS_Pr->ChipType >= SIS_315H) {
  691. /* YPrPb = 0x08 */
  692. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x38) & EnableCHYPbPr) return true;
  693. }
  694. return false;
  695. }
  696. #endif
  697. #ifdef CONFIG_FB_SIS_315
  698. static bool
  699. SiS_IsChScart(struct SiS_Private *SiS_Pr)
  700. {
  701. if(SiS_Pr->ChipType >= SIS_315H) {
  702. /* Scart = 0x04 */
  703. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x38) & EnableCHScart) return true;
  704. }
  705. return false;
  706. }
  707. #endif
  708. #ifdef CONFIG_FB_SIS_315
  709. static bool
  710. SiS_IsTVOrYPbPrOrScart(struct SiS_Private *SiS_Pr)
  711. {
  712. unsigned short flag;
  713. if(SiS_Pr->ChipType >= SIS_315H) {
  714. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  715. if(flag & SetCRT2ToTV) return true;
  716. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  717. if(flag & EnableCHYPbPr) return true; /* = YPrPb = 0x08 */
  718. if(flag & EnableCHScart) return true; /* = Scart = 0x04 - TW */
  719. } else {
  720. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  721. if(flag & SetCRT2ToTV) return true;
  722. }
  723. return false;
  724. }
  725. #endif
  726. #ifdef CONFIG_FB_SIS_315
  727. static bool
  728. SiS_IsLCDOrLCDA(struct SiS_Private *SiS_Pr)
  729. {
  730. unsigned short flag;
  731. if(SiS_Pr->ChipType >= SIS_315H) {
  732. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  733. if(flag & SetCRT2ToLCD) return true;
  734. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  735. if(flag & SetToLCDA) return true;
  736. } else {
  737. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  738. if(flag & SetCRT2ToLCD) return true;
  739. }
  740. return false;
  741. }
  742. #endif
  743. static bool
  744. SiS_HaveBridge(struct SiS_Private *SiS_Pr)
  745. {
  746. unsigned short flag;
  747. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  748. return true;
  749. } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
  750. flag = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x00);
  751. if((flag == 1) || (flag == 2)) return true;
  752. }
  753. return false;
  754. }
  755. static bool
  756. SiS_BridgeIsEnabled(struct SiS_Private *SiS_Pr)
  757. {
  758. unsigned short flag;
  759. if(SiS_HaveBridge(SiS_Pr)) {
  760. flag = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00);
  761. if(SiS_Pr->ChipType < SIS_315H) {
  762. flag &= 0xa0;
  763. if((flag == 0x80) || (flag == 0x20)) return true;
  764. } else {
  765. flag &= 0x50;
  766. if((flag == 0x40) || (flag == 0x10)) return true;
  767. }
  768. }
  769. return false;
  770. }
  771. static bool
  772. SiS_BridgeInSlavemode(struct SiS_Private *SiS_Pr)
  773. {
  774. unsigned short flag1;
  775. flag1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x31);
  776. if(flag1 & (SetInSlaveMode >> 8)) return true;
  777. return false;
  778. }
  779. /*********************************************/
  780. /* GET VIDEO BRIDGE CONFIG INFO */
  781. /*********************************************/
  782. /* Setup general purpose IO for Chrontel communication */
  783. #ifdef CONFIG_FB_SIS_300
  784. void
  785. SiS_SetChrontelGPIO(struct SiS_Private *SiS_Pr, unsigned short myvbinfo)
  786. {
  787. unsigned int acpibase;
  788. unsigned short temp;
  789. if(!(SiS_Pr->SiS_ChSW)) return;
  790. acpibase = sisfb_read_lpc_pci_dword(SiS_Pr, 0x74);
  791. acpibase &= 0xFFFF;
  792. if(!acpibase) return;
  793. temp = SiS_GetRegShort((acpibase + 0x3c)); /* ACPI register 0x3c: GP Event 1 I/O mode select */
  794. temp &= 0xFEFF;
  795. SiS_SetRegShort((acpibase + 0x3c), temp);
  796. temp = SiS_GetRegShort((acpibase + 0x3c));
  797. temp = SiS_GetRegShort((acpibase + 0x3a)); /* ACPI register 0x3a: GP Pin Level (low/high) */
  798. temp &= 0xFEFF;
  799. if(!(myvbinfo & SetCRT2ToTV)) temp |= 0x0100;
  800. SiS_SetRegShort((acpibase + 0x3a), temp);
  801. temp = SiS_GetRegShort((acpibase + 0x3a));
  802. }
  803. #endif
  804. void
  805. SiS_GetVBInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
  806. unsigned short ModeIdIndex, int checkcrt2mode)
  807. {
  808. unsigned short tempax, tempbx, temp;
  809. unsigned short modeflag, resinfo = 0;
  810. SiS_Pr->SiS_SetFlag = 0;
  811. modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
  812. SiS_Pr->SiS_ModeType = modeflag & ModeTypeMask;
  813. if((ModeNo > 0x13) && (!SiS_Pr->UseCustomMode)) {
  814. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  815. }
  816. tempbx = 0;
  817. if(SiS_HaveBridge(SiS_Pr)) {
  818. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  819. tempbx |= temp;
  820. tempax = SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) << 8;
  821. tempax &= (DriverMode | LoadDACFlag | SetNotSimuMode | SetPALTV);
  822. tempbx |= tempax;
  823. #ifdef CONFIG_FB_SIS_315
  824. if(SiS_Pr->ChipType >= SIS_315H) {
  825. if(SiS_Pr->SiS_VBType & VB_SISLCDA) {
  826. if(ModeNo == 0x03) {
  827. /* Mode 0x03 is never in driver mode */
  828. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x31,0xbf);
  829. }
  830. if(!(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & (DriverMode >> 8))) {
  831. /* Reset LCDA setting if not driver mode */
  832. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x38,0xfc);
  833. }
  834. if(IS_SIS650) {
  835. if(SiS_Pr->SiS_UseLCDA) {
  836. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x5f) & 0xF0) {
  837. if((ModeNo <= 0x13) || (!(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & (DriverMode >> 8)))) {
  838. SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x38,(EnableDualEdge | SetToLCDA));
  839. }
  840. }
  841. }
  842. }
  843. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  844. if((temp & (EnableDualEdge | SetToLCDA)) == (EnableDualEdge | SetToLCDA)) {
  845. tempbx |= SetCRT2ToLCDA;
  846. }
  847. }
  848. if(SiS_Pr->ChipType >= SIS_661) { /* New CR layout */
  849. tempbx &= ~(SetCRT2ToYPbPr525750 | SetCRT2ToHiVision);
  850. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x38) & 0x04) {
  851. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35) & 0xe0;
  852. if(temp == 0x60) tempbx |= SetCRT2ToHiVision;
  853. else if(SiS_Pr->SiS_VBType & VB_SISYPBPR) {
  854. tempbx |= SetCRT2ToYPbPr525750;
  855. }
  856. }
  857. }
  858. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  859. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  860. if(temp & SetToLCDA) {
  861. tempbx |= SetCRT2ToLCDA;
  862. }
  863. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  864. if(temp & EnableCHYPbPr) {
  865. tempbx |= SetCRT2ToCHYPbPr;
  866. }
  867. }
  868. }
  869. }
  870. #endif /* CONFIG_FB_SIS_315 */
  871. if(!(SiS_Pr->SiS_VBType & VB_SISVGA2)) {
  872. tempbx &= ~(SetCRT2ToRAMDAC);
  873. }
  874. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  875. temp = SetCRT2ToSVIDEO |
  876. SetCRT2ToAVIDEO |
  877. SetCRT2ToSCART |
  878. SetCRT2ToLCDA |
  879. SetCRT2ToLCD |
  880. SetCRT2ToRAMDAC |
  881. SetCRT2ToHiVision |
  882. SetCRT2ToYPbPr525750;
  883. } else {
  884. if(SiS_Pr->ChipType >= SIS_315H) {
  885. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  886. temp = SetCRT2ToAVIDEO |
  887. SetCRT2ToSVIDEO |
  888. SetCRT2ToSCART |
  889. SetCRT2ToLCDA |
  890. SetCRT2ToLCD |
  891. SetCRT2ToCHYPbPr;
  892. } else {
  893. temp = SetCRT2ToLCDA |
  894. SetCRT2ToLCD;
  895. }
  896. } else {
  897. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  898. temp = SetCRT2ToTV | SetCRT2ToLCD;
  899. } else {
  900. temp = SetCRT2ToLCD;
  901. }
  902. }
  903. }
  904. if(!(tempbx & temp)) {
  905. tempax = DisableCRT2Display;
  906. tempbx = 0;
  907. }
  908. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  909. unsigned short clearmask = ( DriverMode |
  910. DisableCRT2Display |
  911. LoadDACFlag |
  912. SetNotSimuMode |
  913. SetInSlaveMode |
  914. SetPALTV |
  915. SwitchCRT2 |
  916. SetSimuScanMode );
  917. if(tempbx & SetCRT2ToLCDA) tempbx &= (clearmask | SetCRT2ToLCDA);
  918. if(tempbx & SetCRT2ToRAMDAC) tempbx &= (clearmask | SetCRT2ToRAMDAC);
  919. if(tempbx & SetCRT2ToLCD) tempbx &= (clearmask | SetCRT2ToLCD);
  920. if(tempbx & SetCRT2ToSCART) tempbx &= (clearmask | SetCRT2ToSCART);
  921. if(tempbx & SetCRT2ToHiVision) tempbx &= (clearmask | SetCRT2ToHiVision);
  922. if(tempbx & SetCRT2ToYPbPr525750) tempbx &= (clearmask | SetCRT2ToYPbPr525750);
  923. } else {
  924. if(SiS_Pr->ChipType >= SIS_315H) {
  925. if(tempbx & SetCRT2ToLCDA) {
  926. tempbx &= (0xFF00|SwitchCRT2|SetSimuScanMode);
  927. }
  928. }
  929. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  930. if(tempbx & SetCRT2ToTV) {
  931. tempbx &= (0xFF00|SetCRT2ToTV|SwitchCRT2|SetSimuScanMode);
  932. }
  933. }
  934. if(tempbx & SetCRT2ToLCD) {
  935. tempbx &= (0xFF00|SetCRT2ToLCD|SwitchCRT2|SetSimuScanMode);
  936. }
  937. if(SiS_Pr->ChipType >= SIS_315H) {
  938. if(tempbx & SetCRT2ToLCDA) {
  939. tempbx |= SetCRT2ToLCD;
  940. }
  941. }
  942. }
  943. if(tempax & DisableCRT2Display) {
  944. if(!(tempbx & (SwitchCRT2 | SetSimuScanMode))) {
  945. tempbx = SetSimuScanMode | DisableCRT2Display;
  946. }
  947. }
  948. if(!(tempbx & DriverMode)) tempbx |= SetSimuScanMode;
  949. /* LVDS/CHRONTEL (LCD/TV) and 301BDH (LCD) can only be slave in 8bpp modes */
  950. if(SiS_Pr->SiS_ModeType <= ModeVGA) {
  951. if( (SiS_Pr->SiS_IF_DEF_LVDS == 1) ||
  952. ((SiS_Pr->SiS_VBType & VB_NoLCD) && (tempbx & SetCRT2ToLCD)) ) {
  953. modeflag &= (~CRT2Mode);
  954. }
  955. }
  956. if(!(tempbx & SetSimuScanMode)) {
  957. if(tempbx & SwitchCRT2) {
  958. if((!(modeflag & CRT2Mode)) && (checkcrt2mode)) {
  959. if(resinfo != SIS_RI_1600x1200) {
  960. tempbx |= SetSimuScanMode;
  961. }
  962. }
  963. } else {
  964. if(SiS_BridgeIsEnabled(SiS_Pr)) {
  965. if(!(tempbx & DriverMode)) {
  966. if(SiS_BridgeInSlavemode(SiS_Pr)) {
  967. tempbx |= SetSimuScanMode;
  968. }
  969. }
  970. }
  971. }
  972. }
  973. if(!(tempbx & DisableCRT2Display)) {
  974. if(tempbx & DriverMode) {
  975. if(tempbx & SetSimuScanMode) {
  976. if((!(modeflag & CRT2Mode)) && (checkcrt2mode)) {
  977. if(resinfo != SIS_RI_1600x1200) {
  978. tempbx |= SetInSlaveMode;
  979. }
  980. }
  981. }
  982. } else {
  983. tempbx |= SetInSlaveMode;
  984. }
  985. }
  986. }
  987. SiS_Pr->SiS_VBInfo = tempbx;
  988. #ifdef CONFIG_FB_SIS_300
  989. if(SiS_Pr->ChipType == SIS_630) {
  990. SiS_SetChrontelGPIO(SiS_Pr, SiS_Pr->SiS_VBInfo);
  991. }
  992. #endif
  993. #if 0
  994. printk(KERN_DEBUG "sisfb: (init301: VBInfo= 0x%04x, SetFlag=0x%04x)\n",
  995. SiS_Pr->SiS_VBInfo, SiS_Pr->SiS_SetFlag);
  996. #endif
  997. }
  998. /*********************************************/
  999. /* DETERMINE YPbPr MODE */
  1000. /*********************************************/
  1001. void
  1002. SiS_SetYPbPr(struct SiS_Private *SiS_Pr)
  1003. {
  1004. unsigned char temp;
  1005. /* Note: This variable is only used on 30xLV systems.
  1006. * CR38 has a different meaning on LVDS/CH7019 systems.
  1007. * On 661 and later, these bits moved to CR35.
  1008. *
  1009. * On 301, 301B, only HiVision 1080i is supported.
  1010. * On 30xLV, 301C, only YPbPr 1080i is supported.
  1011. */
  1012. SiS_Pr->SiS_YPbPr = 0;
  1013. if(SiS_Pr->ChipType >= SIS_661) return;
  1014. if(SiS_Pr->SiS_VBType) {
  1015. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  1016. SiS_Pr->SiS_YPbPr = YPbPrHiVision;
  1017. }
  1018. }
  1019. if(SiS_Pr->ChipType >= SIS_315H) {
  1020. if(SiS_Pr->SiS_VBType & VB_SISYPBPR) {
  1021. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  1022. if(temp & 0x08) {
  1023. switch((temp >> 4)) {
  1024. case 0x00: SiS_Pr->SiS_YPbPr = YPbPr525i; break;
  1025. case 0x01: SiS_Pr->SiS_YPbPr = YPbPr525p; break;
  1026. case 0x02: SiS_Pr->SiS_YPbPr = YPbPr750p; break;
  1027. case 0x03: SiS_Pr->SiS_YPbPr = YPbPrHiVision; break;
  1028. }
  1029. }
  1030. }
  1031. }
  1032. }
  1033. /*********************************************/
  1034. /* DETERMINE TVMode flag */
  1035. /*********************************************/
  1036. void
  1037. SiS_SetTVMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  1038. {
  1039. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  1040. unsigned short temp, temp1, resinfo = 0, romindex = 0;
  1041. unsigned char OutputSelect = *SiS_Pr->pSiS_OutputSelect;
  1042. SiS_Pr->SiS_TVMode = 0;
  1043. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) return;
  1044. if(SiS_Pr->UseCustomMode) return;
  1045. if(ModeNo > 0x13) {
  1046. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  1047. }
  1048. if(SiS_Pr->ChipType < SIS_661) {
  1049. if(SiS_Pr->SiS_VBInfo & SetPALTV) SiS_Pr->SiS_TVMode |= TVSetPAL;
  1050. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  1051. temp = 0;
  1052. if((SiS_Pr->ChipType == SIS_630) ||
  1053. (SiS_Pr->ChipType == SIS_730)) {
  1054. temp = 0x35;
  1055. romindex = 0xfe;
  1056. } else if(SiS_Pr->ChipType >= SIS_315H) {
  1057. temp = 0x38;
  1058. if(SiS_Pr->ChipType < XGI_20) {
  1059. romindex = 0xf3;
  1060. if(SiS_Pr->ChipType >= SIS_330) romindex = 0x11b;
  1061. }
  1062. }
  1063. if(temp) {
  1064. if(romindex && SiS_Pr->SiS_UseROM && (!(SiS_Pr->SiS_ROMNew))) {
  1065. OutputSelect = ROMAddr[romindex];
  1066. if(!(OutputSelect & EnablePALMN)) {
  1067. SiS_SetRegAND(SiS_Pr->SiS_P3d4,temp,0x3F);
  1068. }
  1069. }
  1070. temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,temp);
  1071. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  1072. if(temp1 & EnablePALM) { /* 0x40 */
  1073. SiS_Pr->SiS_TVMode |= TVSetPALM;
  1074. SiS_Pr->SiS_TVMode &= ~TVSetPAL;
  1075. } else if(temp1 & EnablePALN) { /* 0x80 */
  1076. SiS_Pr->SiS_TVMode |= TVSetPALN;
  1077. }
  1078. } else {
  1079. if(temp1 & EnableNTSCJ) { /* 0x40 */
  1080. SiS_Pr->SiS_TVMode |= TVSetNTSCJ;
  1081. }
  1082. }
  1083. }
  1084. /* Translate HiVision/YPbPr to our new flags */
  1085. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  1086. if(SiS_Pr->SiS_YPbPr == YPbPr750p) SiS_Pr->SiS_TVMode |= TVSetYPbPr750p;
  1087. else if(SiS_Pr->SiS_YPbPr == YPbPr525p) SiS_Pr->SiS_TVMode |= TVSetYPbPr525p;
  1088. else if(SiS_Pr->SiS_YPbPr == YPbPrHiVision) SiS_Pr->SiS_TVMode |= TVSetHiVision;
  1089. else SiS_Pr->SiS_TVMode |= TVSetYPbPr525i;
  1090. if(SiS_Pr->SiS_TVMode & (TVSetYPbPr750p | TVSetYPbPr525p | TVSetYPbPr525i)) {
  1091. SiS_Pr->SiS_VBInfo &= ~SetCRT2ToHiVision;
  1092. SiS_Pr->SiS_VBInfo |= SetCRT2ToYPbPr525750;
  1093. } else if(SiS_Pr->SiS_TVMode & TVSetHiVision) {
  1094. SiS_Pr->SiS_TVMode |= TVSetPAL;
  1095. }
  1096. }
  1097. } else if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  1098. if(SiS_Pr->SiS_CHOverScan) {
  1099. if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) {
  1100. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35);
  1101. if((temp & TVOverScan) || (SiS_Pr->SiS_CHOverScan == 1)) {
  1102. SiS_Pr->SiS_TVMode |= TVSetCHOverScan;
  1103. }
  1104. } else if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  1105. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x79);
  1106. if((temp & 0x80) || (SiS_Pr->SiS_CHOverScan == 1)) {
  1107. SiS_Pr->SiS_TVMode |= TVSetCHOverScan;
  1108. }
  1109. }
  1110. if(SiS_Pr->SiS_CHSOverScan) {
  1111. SiS_Pr->SiS_TVMode |= TVSetCHOverScan;
  1112. }
  1113. }
  1114. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  1115. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  1116. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  1117. if(temp & EnablePALM) SiS_Pr->SiS_TVMode |= TVSetPALM;
  1118. else if(temp & EnablePALN) SiS_Pr->SiS_TVMode |= TVSetPALN;
  1119. } else {
  1120. if(temp & EnableNTSCJ) {
  1121. SiS_Pr->SiS_TVMode |= TVSetNTSCJ;
  1122. }
  1123. }
  1124. }
  1125. }
  1126. } else { /* 661 and later */
  1127. temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35);
  1128. if(temp1 & 0x01) {
  1129. SiS_Pr->SiS_TVMode |= TVSetPAL;
  1130. if(temp1 & 0x08) {
  1131. SiS_Pr->SiS_TVMode |= TVSetPALN;
  1132. } else if(temp1 & 0x04) {
  1133. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  1134. SiS_Pr->SiS_TVMode &= ~TVSetPAL;
  1135. }
  1136. SiS_Pr->SiS_TVMode |= TVSetPALM;
  1137. }
  1138. } else {
  1139. if(temp1 & 0x02) {
  1140. SiS_Pr->SiS_TVMode |= TVSetNTSCJ;
  1141. }
  1142. }
  1143. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  1144. if(SiS_Pr->SiS_CHOverScan) {
  1145. if((temp1 & 0x10) || (SiS_Pr->SiS_CHOverScan == 1)) {
  1146. SiS_Pr->SiS_TVMode |= TVSetCHOverScan;
  1147. }
  1148. }
  1149. }
  1150. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  1151. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  1152. temp1 &= 0xe0;
  1153. if(temp1 == 0x00) SiS_Pr->SiS_TVMode |= TVSetYPbPr525i;
  1154. else if(temp1 == 0x20) SiS_Pr->SiS_TVMode |= TVSetYPbPr525p;
  1155. else if(temp1 == 0x40) SiS_Pr->SiS_TVMode |= TVSetYPbPr750p;
  1156. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  1157. SiS_Pr->SiS_TVMode |= (TVSetHiVision | TVSetPAL);
  1158. }
  1159. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToYPbPr525750 | SetCRT2ToHiVision)) {
  1160. if(resinfo == SIS_RI_800x480 || resinfo == SIS_RI_1024x576 || resinfo == SIS_RI_1280x720) {
  1161. SiS_Pr->SiS_TVMode |= TVAspect169;
  1162. } else {
  1163. temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x39);
  1164. if(temp1 & 0x02) {
  1165. if(SiS_Pr->SiS_TVMode & (TVSetYPbPr750p | TVSetHiVision)) {
  1166. SiS_Pr->SiS_TVMode |= TVAspect169;
  1167. } else {
  1168. SiS_Pr->SiS_TVMode |= TVAspect43LB;
  1169. }
  1170. } else {
  1171. SiS_Pr->SiS_TVMode |= TVAspect43;
  1172. }
  1173. }
  1174. }
  1175. }
  1176. }
  1177. if(SiS_Pr->SiS_VBInfo & SetCRT2ToSCART) SiS_Pr->SiS_TVMode |= TVSetPAL;
  1178. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  1179. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  1180. SiS_Pr->SiS_TVMode |= TVSetPAL;
  1181. SiS_Pr->SiS_TVMode &= ~(TVSetPALM | TVSetPALN | TVSetNTSCJ);
  1182. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  1183. if(SiS_Pr->SiS_TVMode & (TVSetYPbPr525i | TVSetYPbPr525p | TVSetYPbPr750p)) {
  1184. SiS_Pr->SiS_TVMode &= ~(TVSetPAL | TVSetNTSCJ | TVSetPALM | TVSetPALN);
  1185. }
  1186. }
  1187. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  1188. if(!(SiS_Pr->SiS_VBInfo & SetNotSimuMode)) {
  1189. SiS_Pr->SiS_TVMode |= TVSetTVSimuMode;
  1190. }
  1191. }
  1192. if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) {
  1193. if(resinfo == SIS_RI_1024x768) {
  1194. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) {
  1195. SiS_Pr->SiS_TVMode |= TVSet525p1024;
  1196. } else if(!(SiS_Pr->SiS_TVMode & (TVSetHiVision | TVSetYPbPr750p))) {
  1197. SiS_Pr->SiS_TVMode |= TVSetNTSC1024;
  1198. }
  1199. }
  1200. }
  1201. SiS_Pr->SiS_TVMode |= TVRPLLDIV2XO;
  1202. if((SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) &&
  1203. (SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  1204. SiS_Pr->SiS_TVMode &= ~TVRPLLDIV2XO;
  1205. } else if(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p)) {
  1206. SiS_Pr->SiS_TVMode &= ~TVRPLLDIV2XO;
  1207. } else if(!(SiS_Pr->SiS_VBType & VB_SIS30xBLV)) {
  1208. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) {
  1209. SiS_Pr->SiS_TVMode &= ~TVRPLLDIV2XO;
  1210. }
  1211. }
  1212. }
  1213. SiS_Pr->SiS_VBInfo &= ~SetPALTV;
  1214. }
  1215. /*********************************************/
  1216. /* GET LCD INFO */
  1217. /*********************************************/
  1218. static unsigned short
  1219. SiS_GetBIOSLCDResInfo(struct SiS_Private *SiS_Pr)
  1220. {
  1221. unsigned short temp = SiS_Pr->SiS_LCDResInfo;
  1222. /* Translate my LCDResInfo to BIOS value */
  1223. switch(temp) {
  1224. case Panel_1280x768_2: temp = Panel_1280x768; break;
  1225. case Panel_1280x800_2: temp = Panel_1280x800; break;
  1226. case Panel_1280x854: temp = Panel661_1280x854; break;
  1227. }
  1228. return temp;
  1229. }
  1230. static void
  1231. SiS_GetLCDInfoBIOS(struct SiS_Private *SiS_Pr)
  1232. {
  1233. #ifdef CONFIG_FB_SIS_315
  1234. unsigned char *ROMAddr;
  1235. unsigned short temp;
  1236. if((ROMAddr = GetLCDStructPtr661(SiS_Pr))) {
  1237. if((temp = SISGETROMW(6)) != SiS_Pr->PanelHT) {
  1238. SiS_Pr->SiS_NeedRomModeData = true;
  1239. SiS_Pr->PanelHT = temp;
  1240. }
  1241. if((temp = SISGETROMW(8)) != SiS_Pr->PanelVT) {
  1242. SiS_Pr->SiS_NeedRomModeData = true;
  1243. SiS_Pr->PanelVT = temp;
  1244. }
  1245. SiS_Pr->PanelHRS = SISGETROMW(10);
  1246. SiS_Pr->PanelHRE = SISGETROMW(12);
  1247. SiS_Pr->PanelVRS = SISGETROMW(14);
  1248. SiS_Pr->PanelVRE = SISGETROMW(16);
  1249. SiS_Pr->PanelVCLKIdx315 = VCLK_CUSTOM_315;
  1250. SiS_Pr->SiS_VCLKData[VCLK_CUSTOM_315].CLOCK =
  1251. SiS_Pr->SiS_VBVCLKData[VCLK_CUSTOM_315].CLOCK = (unsigned short)((unsigned char)ROMAddr[18]);
  1252. SiS_Pr->SiS_VCLKData[VCLK_CUSTOM_315].SR2B =
  1253. SiS_Pr->SiS_VBVCLKData[VCLK_CUSTOM_315].Part4_A = ROMAddr[19];
  1254. SiS_Pr->SiS_VCLKData[VCLK_CUSTOM_315].SR2C =
  1255. SiS_Pr->SiS_VBVCLKData[VCLK_CUSTOM_315].Part4_B = ROMAddr[20];
  1256. }
  1257. #endif
  1258. }
  1259. static void
  1260. SiS_CheckScaling(struct SiS_Private *SiS_Pr, unsigned short resinfo,
  1261. const unsigned char *nonscalingmodes)
  1262. {
  1263. int i = 0;
  1264. while(nonscalingmodes[i] != 0xff) {
  1265. if(nonscalingmodes[i++] == resinfo) {
  1266. if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) ||
  1267. (SiS_Pr->UsePanelScaler == -1)) {
  1268. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1269. }
  1270. break;
  1271. }
  1272. }
  1273. }
  1274. void
  1275. SiS_GetLCDResInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  1276. {
  1277. unsigned short temp,modeflag,resinfo=0,modexres=0,modeyres=0;
  1278. bool panelcanscale = false;
  1279. #ifdef CONFIG_FB_SIS_300
  1280. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  1281. static const unsigned char SiS300SeriesLCDRes[] =
  1282. { 0, 1, 2, 3, 7, 4, 5, 8,
  1283. 0, 0, 10, 0, 0, 0, 0, 15 };
  1284. #endif
  1285. #ifdef CONFIG_FB_SIS_315
  1286. unsigned char *myptr = NULL;
  1287. #endif
  1288. SiS_Pr->SiS_LCDResInfo = 0;
  1289. SiS_Pr->SiS_LCDTypeInfo = 0;
  1290. SiS_Pr->SiS_LCDInfo = 0;
  1291. SiS_Pr->PanelHRS = 999; /* HSync start */
  1292. SiS_Pr->PanelHRE = 999; /* HSync end */
  1293. SiS_Pr->PanelVRS = 999; /* VSync start */
  1294. SiS_Pr->PanelVRE = 999; /* VSync end */
  1295. SiS_Pr->SiS_NeedRomModeData = false;
  1296. /* Alternative 1600x1200@60 timing for 1600x1200 LCDA */
  1297. SiS_Pr->Alternate1600x1200 = false;
  1298. if(!(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA))) return;
  1299. modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
  1300. if((ModeNo > 0x13) && (!SiS_Pr->UseCustomMode)) {
  1301. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  1302. modexres = SiS_Pr->SiS_ModeResInfo[resinfo].HTotal;
  1303. modeyres = SiS_Pr->SiS_ModeResInfo[resinfo].VTotal;
  1304. }
  1305. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36);
  1306. /* For broken BIOSes: Assume 1024x768 */
  1307. if(temp == 0) temp = 0x02;
  1308. if((SiS_Pr->ChipType >= SIS_661) || (SiS_Pr->SiS_ROMNew)) {
  1309. SiS_Pr->SiS_LCDTypeInfo = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x39) & 0x7c) >> 2;
  1310. } else if((SiS_Pr->ChipType < SIS_315H) || (SiS_Pr->ChipType >= SIS_661)) {
  1311. SiS_Pr->SiS_LCDTypeInfo = temp >> 4;
  1312. } else {
  1313. SiS_Pr->SiS_LCDTypeInfo = (temp & 0x0F) - 1;
  1314. }
  1315. temp &= 0x0f;
  1316. #ifdef CONFIG_FB_SIS_300
  1317. if(SiS_Pr->ChipType < SIS_315H) {
  1318. /* Very old BIOSes only know 7 sizes (NetVista 2179, 1.01g) */
  1319. if(SiS_Pr->SiS_VBType & VB_SIS301) {
  1320. if(temp < 0x0f) temp &= 0x07;
  1321. }
  1322. /* Translate 300 series LCDRes to 315 series for unified usage */
  1323. temp = SiS300SeriesLCDRes[temp];
  1324. }
  1325. #endif
  1326. /* Translate to our internal types */
  1327. #ifdef CONFIG_FB_SIS_315
  1328. if(SiS_Pr->ChipType == SIS_550) {
  1329. if (temp == Panel310_1152x768) temp = Panel_320x240_2; /* Verified working */
  1330. else if(temp == Panel310_320x240_2) temp = Panel_320x240_2;
  1331. else if(temp == Panel310_320x240_3) temp = Panel_320x240_3;
  1332. } else if(SiS_Pr->ChipType >= SIS_661) {
  1333. if(temp == Panel661_1280x854) temp = Panel_1280x854;
  1334. }
  1335. #endif
  1336. if(SiS_Pr->SiS_VBType & VB_SISLVDS) { /* SiS LVDS */
  1337. if(temp == Panel310_1280x768) {
  1338. temp = Panel_1280x768_2;
  1339. }
  1340. if(SiS_Pr->SiS_ROMNew) {
  1341. if(temp == Panel661_1280x800) {
  1342. temp = Panel_1280x800_2;
  1343. }
  1344. }
  1345. }
  1346. SiS_Pr->SiS_LCDResInfo = temp;
  1347. #ifdef CONFIG_FB_SIS_300
  1348. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  1349. if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) {
  1350. SiS_Pr->SiS_LCDResInfo = Panel_Barco1366;
  1351. } else if(SiS_Pr->SiS_CustomT == CUT_PANEL848) {
  1352. SiS_Pr->SiS_LCDResInfo = Panel_848x480;
  1353. } else if(SiS_Pr->SiS_CustomT == CUT_PANEL856) {
  1354. SiS_Pr->SiS_LCDResInfo = Panel_856x480;
  1355. }
  1356. }
  1357. #endif
  1358. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  1359. if(SiS_Pr->SiS_LCDResInfo < SiS_Pr->SiS_PanelMin301)
  1360. SiS_Pr->SiS_LCDResInfo = SiS_Pr->SiS_PanelMin301;
  1361. } else {
  1362. if(SiS_Pr->SiS_LCDResInfo < SiS_Pr->SiS_PanelMinLVDS)
  1363. SiS_Pr->SiS_LCDResInfo = SiS_Pr->SiS_PanelMinLVDS;
  1364. }
  1365. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x37);
  1366. SiS_Pr->SiS_LCDInfo = temp & ~0x000e;
  1367. /* Need temp below! */
  1368. /* These must/can't scale no matter what */
  1369. switch(SiS_Pr->SiS_LCDResInfo) {
  1370. case Panel_320x240_1:
  1371. case Panel_320x240_2:
  1372. case Panel_320x240_3:
  1373. case Panel_1280x960:
  1374. SiS_Pr->SiS_LCDInfo &= ~DontExpandLCD;
  1375. break;
  1376. case Panel_640x480:
  1377. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1378. }
  1379. panelcanscale = (bool)(SiS_Pr->SiS_LCDInfo & DontExpandLCD);
  1380. if(!SiS_Pr->UsePanelScaler) SiS_Pr->SiS_LCDInfo &= ~DontExpandLCD;
  1381. else if(SiS_Pr->UsePanelScaler == 1) SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1382. /* Dual link, Pass 1:1 BIOS default, etc. */
  1383. #ifdef CONFIG_FB_SIS_315
  1384. if(SiS_Pr->ChipType >= SIS_661) {
  1385. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  1386. if(temp & 0x08) SiS_Pr->SiS_LCDInfo |= LCDPass11;
  1387. }
  1388. if(SiS_Pr->SiS_VBType & VB_SISDUALLINK) {
  1389. if(SiS_Pr->SiS_ROMNew) {
  1390. if(temp & 0x02) SiS_Pr->SiS_LCDInfo |= LCDDualLink;
  1391. } else if((myptr = GetLCDStructPtr661(SiS_Pr))) {
  1392. if(myptr[2] & 0x01) SiS_Pr->SiS_LCDInfo |= LCDDualLink;
  1393. }
  1394. }
  1395. } else if(SiS_Pr->ChipType >= SIS_315H) {
  1396. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  1397. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x39) & 0x01) SiS_Pr->SiS_LCDInfo |= LCDPass11;
  1398. }
  1399. if((SiS_Pr->SiS_ROMNew) && (!(SiS_Pr->PanelSelfDetected))) {
  1400. SiS_Pr->SiS_LCDInfo &= ~(LCDRGB18Bit);
  1401. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35);
  1402. if(temp & 0x01) SiS_Pr->SiS_LCDInfo |= LCDRGB18Bit;
  1403. if(SiS_Pr->SiS_VBType & VB_SISDUALLINK) {
  1404. if(temp & 0x02) SiS_Pr->SiS_LCDInfo |= LCDDualLink;
  1405. }
  1406. } else if(!(SiS_Pr->SiS_ROMNew)) {
  1407. if(SiS_Pr->SiS_VBType & VB_SISDUALLINK) {
  1408. if((SiS_Pr->SiS_CustomT == CUT_CLEVO1024) &&
  1409. (SiS_Pr->SiS_LCDResInfo == Panel_1024x768)) {
  1410. SiS_Pr->SiS_LCDInfo |= LCDDualLink;
  1411. }
  1412. if((SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) ||
  1413. (SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) ||
  1414. (SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) ||
  1415. (SiS_Pr->SiS_LCDResInfo == Panel_1680x1050)) {
  1416. SiS_Pr->SiS_LCDInfo |= LCDDualLink;
  1417. }
  1418. }
  1419. }
  1420. }
  1421. #endif
  1422. /* Pass 1:1 */
  1423. if((SiS_Pr->SiS_IF_DEF_LVDS == 1) || (SiS_Pr->SiS_VBType & VB_NoLCD)) {
  1424. /* Always center screen on LVDS (if scaling is disabled) */
  1425. SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  1426. } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
  1427. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  1428. /* Always center screen on SiS LVDS (if scaling is disabled) */
  1429. SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  1430. } else {
  1431. /* By default, pass 1:1 on SiS TMDS (if scaling is supported) */
  1432. if(panelcanscale) SiS_Pr->SiS_LCDInfo |= LCDPass11;
  1433. if(SiS_Pr->CenterScreen == 1) SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  1434. }
  1435. }
  1436. SiS_Pr->PanelVCLKIdx300 = VCLK65_300;
  1437. SiS_Pr->PanelVCLKIdx315 = VCLK108_2_315;
  1438. switch(SiS_Pr->SiS_LCDResInfo) {
  1439. case Panel_320x240_1:
  1440. case Panel_320x240_2:
  1441. case Panel_320x240_3: SiS_Pr->PanelXRes = 640; SiS_Pr->PanelYRes = 480;
  1442. SiS_Pr->PanelVRS = 24; SiS_Pr->PanelVRE = 3;
  1443. SiS_Pr->PanelVCLKIdx300 = VCLK28;
  1444. SiS_Pr->PanelVCLKIdx315 = VCLK28;
  1445. break;
  1446. case Panel_640x480: SiS_Pr->PanelXRes = 640; SiS_Pr->PanelYRes = 480;
  1447. SiS_Pr->PanelVRE = 3;
  1448. SiS_Pr->PanelVCLKIdx300 = VCLK28;
  1449. SiS_Pr->PanelVCLKIdx315 = VCLK28;
  1450. break;
  1451. case Panel_800x600: SiS_Pr->PanelXRes = 800; SiS_Pr->PanelYRes = 600;
  1452. SiS_Pr->PanelHT = 1056; SiS_Pr->PanelVT = 628;
  1453. SiS_Pr->PanelHRS = 40; SiS_Pr->PanelHRE = 128;
  1454. SiS_Pr->PanelVRS = 1; SiS_Pr->PanelVRE = 4;
  1455. SiS_Pr->PanelVCLKIdx300 = VCLK40;
  1456. SiS_Pr->PanelVCLKIdx315 = VCLK40;
  1457. break;
  1458. case Panel_1024x600: SiS_Pr->PanelXRes = 1024; SiS_Pr->PanelYRes = 600;
  1459. SiS_Pr->PanelHT = 1344; SiS_Pr->PanelVT = 800;
  1460. SiS_Pr->PanelHRS = 24; SiS_Pr->PanelHRE = 136;
  1461. SiS_Pr->PanelVRS = 2 /* 88 */ ; SiS_Pr->PanelVRE = 6;
  1462. SiS_Pr->PanelVCLKIdx300 = VCLK65_300;
  1463. SiS_Pr->PanelVCLKIdx315 = VCLK65_315;
  1464. break;
  1465. case Panel_1024x768: SiS_Pr->PanelXRes = 1024; SiS_Pr->PanelYRes = 768;
  1466. SiS_Pr->PanelHT = 1344; SiS_Pr->PanelVT = 806;
  1467. SiS_Pr->PanelHRS = 24; SiS_Pr->PanelHRE = 136;
  1468. SiS_Pr->PanelVRS = 3; SiS_Pr->PanelVRE = 6;
  1469. if(SiS_Pr->ChipType < SIS_315H) {
  1470. SiS_Pr->PanelHRS = 23;
  1471. SiS_Pr->PanelVRE = 5;
  1472. }
  1473. SiS_Pr->PanelVCLKIdx300 = VCLK65_300;
  1474. SiS_Pr->PanelVCLKIdx315 = VCLK65_315;
  1475. SiS_GetLCDInfoBIOS(SiS_Pr);
  1476. break;
  1477. case Panel_1152x768: SiS_Pr->PanelXRes = 1152; SiS_Pr->PanelYRes = 768;
  1478. SiS_Pr->PanelHT = 1344; SiS_Pr->PanelVT = 806;
  1479. SiS_Pr->PanelHRS = 24; SiS_Pr->PanelHRE = 136;
  1480. SiS_Pr->PanelVRS = 3; SiS_Pr->PanelVRE = 6;
  1481. if(SiS_Pr->ChipType < SIS_315H) {
  1482. SiS_Pr->PanelHRS = 23;
  1483. SiS_Pr->PanelVRE = 5;
  1484. }
  1485. SiS_Pr->PanelVCLKIdx300 = VCLK65_300;
  1486. SiS_Pr->PanelVCLKIdx315 = VCLK65_315;
  1487. break;
  1488. case Panel_1152x864: SiS_Pr->PanelXRes = 1152; SiS_Pr->PanelYRes = 864;
  1489. break;
  1490. case Panel_1280x720: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 720;
  1491. SiS_Pr->PanelHT = 1650; SiS_Pr->PanelVT = 750;
  1492. SiS_Pr->PanelHRS = 110; SiS_Pr->PanelHRE = 40;
  1493. SiS_Pr->PanelVRS = 5; SiS_Pr->PanelVRE = 5;
  1494. SiS_Pr->PanelVCLKIdx315 = VCLK_1280x720;
  1495. /* Data above for TMDS (projector); get from BIOS for LVDS */
  1496. SiS_GetLCDInfoBIOS(SiS_Pr);
  1497. break;
  1498. case Panel_1280x768: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 768;
  1499. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  1500. SiS_Pr->PanelHT = 1408; SiS_Pr->PanelVT = 806;
  1501. SiS_Pr->PanelVCLKIdx300 = VCLK81_300; /* ? */
  1502. SiS_Pr->PanelVCLKIdx315 = VCLK81_315; /* ? */
  1503. } else {
  1504. SiS_Pr->PanelHT = 1688; SiS_Pr->PanelVT = 802;
  1505. SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRS = 112;
  1506. SiS_Pr->PanelVRS = 3; SiS_Pr->PanelVRE = 6;
  1507. SiS_Pr->PanelVCLKIdx300 = VCLK81_300;
  1508. SiS_Pr->PanelVCLKIdx315 = VCLK81_315;
  1509. }
  1510. break;
  1511. case Panel_1280x768_2: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 768;
  1512. SiS_Pr->PanelHT = 1660; SiS_Pr->PanelVT = 806;
  1513. SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 112;
  1514. SiS_Pr->PanelVRS = 3; SiS_Pr->PanelVRE = 6;
  1515. SiS_Pr->PanelVCLKIdx315 = VCLK_1280x768_2;
  1516. SiS_GetLCDInfoBIOS(SiS_Pr);
  1517. break;
  1518. case Panel_1280x800: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 800;
  1519. SiS_Pr->PanelHT = 1408; SiS_Pr->PanelVT = 816;
  1520. SiS_Pr->PanelHRS = 21; SiS_Pr->PanelHRE = 24;
  1521. SiS_Pr->PanelVRS = 4; SiS_Pr->PanelVRE = 3;
  1522. SiS_Pr->PanelVCLKIdx315 = VCLK_1280x800_315;
  1523. SiS_GetLCDInfoBIOS(SiS_Pr);
  1524. break;
  1525. case Panel_1280x800_2: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 800;
  1526. SiS_Pr->PanelHT = 1552; SiS_Pr->PanelVT = 812;
  1527. SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 112;
  1528. SiS_Pr->PanelVRS = 4; SiS_Pr->PanelVRE = 3;
  1529. SiS_Pr->PanelVCLKIdx315 = VCLK_1280x800_315_2;
  1530. SiS_GetLCDInfoBIOS(SiS_Pr);
  1531. break;
  1532. case Panel_1280x854: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 854;
  1533. SiS_Pr->PanelHT = 1664; SiS_Pr->PanelVT = 861;
  1534. SiS_Pr->PanelHRS = 16; SiS_Pr->PanelHRE = 112;
  1535. SiS_Pr->PanelVRS = 1; SiS_Pr->PanelVRE = 3;
  1536. SiS_Pr->PanelVCLKIdx315 = VCLK_1280x854;
  1537. SiS_GetLCDInfoBIOS(SiS_Pr);
  1538. break;
  1539. case Panel_1280x960: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 960;
  1540. SiS_Pr->PanelHT = 1800; SiS_Pr->PanelVT = 1000;
  1541. SiS_Pr->PanelVCLKIdx300 = VCLK108_3_300;
  1542. SiS_Pr->PanelVCLKIdx315 = VCLK108_3_315;
  1543. if(resinfo == SIS_RI_1280x1024) {
  1544. SiS_Pr->PanelVCLKIdx300 = VCLK100_300;
  1545. SiS_Pr->PanelVCLKIdx315 = VCLK100_315;
  1546. }
  1547. break;
  1548. case Panel_1280x1024: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 1024;
  1549. SiS_Pr->PanelHT = 1688; SiS_Pr->PanelVT = 1066;
  1550. SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 112;
  1551. SiS_Pr->PanelVRS = 1; SiS_Pr->PanelVRE = 3;
  1552. SiS_Pr->PanelVCLKIdx300 = VCLK108_3_300;
  1553. SiS_Pr->PanelVCLKIdx315 = VCLK108_2_315;
  1554. SiS_GetLCDInfoBIOS(SiS_Pr);
  1555. break;
  1556. case Panel_1400x1050: SiS_Pr->PanelXRes = 1400; SiS_Pr->PanelYRes = 1050;
  1557. SiS_Pr->PanelHT = 1688; SiS_Pr->PanelVT = 1066;
  1558. SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 112;
  1559. SiS_Pr->PanelVRS = 1; SiS_Pr->PanelVRE = 3;
  1560. SiS_Pr->PanelVCLKIdx315 = VCLK108_2_315;
  1561. SiS_GetLCDInfoBIOS(SiS_Pr);
  1562. break;
  1563. case Panel_1600x1200: SiS_Pr->PanelXRes = 1600; SiS_Pr->PanelYRes = 1200;
  1564. SiS_Pr->PanelHT = 2160; SiS_Pr->PanelVT = 1250;
  1565. SiS_Pr->PanelHRS = 64; SiS_Pr->PanelHRE = 192;
  1566. SiS_Pr->PanelVRS = 1; SiS_Pr->PanelVRE = 3;
  1567. SiS_Pr->PanelVCLKIdx315 = VCLK162_315;
  1568. if(SiS_Pr->SiS_VBType & VB_SISTMDSLCDA) {
  1569. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  1570. SiS_Pr->PanelHT = 1760; SiS_Pr->PanelVT = 1235;
  1571. SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 32;
  1572. SiS_Pr->PanelVRS = 2; SiS_Pr->PanelVRE = 4;
  1573. SiS_Pr->PanelVCLKIdx315 = VCLK130_315;
  1574. SiS_Pr->Alternate1600x1200 = true;
  1575. }
  1576. } else if(SiS_Pr->SiS_IF_DEF_LVDS) {
  1577. SiS_Pr->PanelHT = 2048; SiS_Pr->PanelVT = 1320;
  1578. SiS_Pr->PanelHRS = SiS_Pr->PanelHRE = 999;
  1579. SiS_Pr->PanelVRS = SiS_Pr->PanelVRE = 999;
  1580. }
  1581. SiS_GetLCDInfoBIOS(SiS_Pr);
  1582. break;
  1583. case Panel_1680x1050: SiS_Pr->PanelXRes = 1680; SiS_Pr->PanelYRes = 1050;
  1584. SiS_Pr->PanelHT = 1900; SiS_Pr->PanelVT = 1066;
  1585. SiS_Pr->PanelHRS = 26; SiS_Pr->PanelHRE = 76;
  1586. SiS_Pr->PanelVRS = 3; SiS_Pr->PanelVRE = 6;
  1587. SiS_Pr->PanelVCLKIdx315 = VCLK121_315;
  1588. SiS_GetLCDInfoBIOS(SiS_Pr);
  1589. break;
  1590. case Panel_Barco1366: SiS_Pr->PanelXRes = 1360; SiS_Pr->PanelYRes = 1024;
  1591. SiS_Pr->PanelHT = 1688; SiS_Pr->PanelVT = 1066;
  1592. break;
  1593. case Panel_848x480: SiS_Pr->PanelXRes = 848; SiS_Pr->PanelYRes = 480;
  1594. SiS_Pr->PanelHT = 1088; SiS_Pr->PanelVT = 525;
  1595. break;
  1596. case Panel_856x480: SiS_Pr->PanelXRes = 856; SiS_Pr->PanelYRes = 480;
  1597. SiS_Pr->PanelHT = 1088; SiS_Pr->PanelVT = 525;
  1598. break;
  1599. case Panel_Custom: SiS_Pr->PanelXRes = SiS_Pr->CP_MaxX;
  1600. SiS_Pr->PanelYRes = SiS_Pr->CP_MaxY;
  1601. SiS_Pr->PanelHT = SiS_Pr->CHTotal;
  1602. SiS_Pr->PanelVT = SiS_Pr->CVTotal;
  1603. if(SiS_Pr->CP_PreferredIndex != -1) {
  1604. SiS_Pr->PanelXRes = SiS_Pr->CP_HDisplay[SiS_Pr->CP_PreferredIndex];
  1605. SiS_Pr->PanelYRes = SiS_Pr->CP_VDisplay[SiS_Pr->CP_PreferredIndex];
  1606. SiS_Pr->PanelHT = SiS_Pr->CP_HTotal[SiS_Pr->CP_PreferredIndex];
  1607. SiS_Pr->PanelVT = SiS_Pr->CP_VTotal[SiS_Pr->CP_PreferredIndex];
  1608. SiS_Pr->PanelHRS = SiS_Pr->CP_HSyncStart[SiS_Pr->CP_PreferredIndex];
  1609. SiS_Pr->PanelHRE = SiS_Pr->CP_HSyncEnd[SiS_Pr->CP_PreferredIndex];
  1610. SiS_Pr->PanelVRS = SiS_Pr->CP_VSyncStart[SiS_Pr->CP_PreferredIndex];
  1611. SiS_Pr->PanelVRE = SiS_Pr->CP_VSyncEnd[SiS_Pr->CP_PreferredIndex];
  1612. SiS_Pr->PanelHRS -= SiS_Pr->PanelXRes;
  1613. SiS_Pr->PanelHRE -= SiS_Pr->PanelHRS;
  1614. SiS_Pr->PanelVRS -= SiS_Pr->PanelYRes;
  1615. SiS_Pr->PanelVRE -= SiS_Pr->PanelVRS;
  1616. if(SiS_Pr->CP_PrefClock) {
  1617. int idx;
  1618. SiS_Pr->PanelVCLKIdx315 = VCLK_CUSTOM_315;
  1619. SiS_Pr->PanelVCLKIdx300 = VCLK_CUSTOM_300;
  1620. if(SiS_Pr->ChipType < SIS_315H) idx = VCLK_CUSTOM_300;
  1621. else idx = VCLK_CUSTOM_315;
  1622. SiS_Pr->SiS_VCLKData[idx].CLOCK =
  1623. SiS_Pr->SiS_VBVCLKData[idx].CLOCK = SiS_Pr->CP_PrefClock;
  1624. SiS_Pr->SiS_VCLKData[idx].SR2B =
  1625. SiS_Pr->SiS_VBVCLKData[idx].Part4_A = SiS_Pr->CP_PrefSR2B;
  1626. SiS_Pr->SiS_VCLKData[idx].SR2C =
  1627. SiS_Pr->SiS_VBVCLKData[idx].Part4_B = SiS_Pr->CP_PrefSR2C;
  1628. }
  1629. }
  1630. break;
  1631. default: SiS_Pr->PanelXRes = 1024; SiS_Pr->PanelYRes = 768;
  1632. SiS_Pr->PanelHT = 1344; SiS_Pr->PanelVT = 806;
  1633. break;
  1634. }
  1635. /* Special cases */
  1636. if( (SiS_Pr->SiS_IF_DEF_FSTN) ||
  1637. (SiS_Pr->SiS_IF_DEF_DSTN) ||
  1638. (SiS_Pr->SiS_CustomT == CUT_BARCO1366) ||
  1639. (SiS_Pr->SiS_CustomT == CUT_BARCO1024) ||
  1640. (SiS_Pr->SiS_CustomT == CUT_PANEL848) ||
  1641. (SiS_Pr->SiS_CustomT == CUT_PANEL856) ) {
  1642. SiS_Pr->PanelHRS = 999;
  1643. SiS_Pr->PanelHRE = 999;
  1644. }
  1645. if( (SiS_Pr->SiS_CustomT == CUT_BARCO1366) ||
  1646. (SiS_Pr->SiS_CustomT == CUT_BARCO1024) ||
  1647. (SiS_Pr->SiS_CustomT == CUT_PANEL848) ||
  1648. (SiS_Pr->SiS_CustomT == CUT_PANEL856) ) {
  1649. SiS_Pr->PanelVRS = 999;
  1650. SiS_Pr->PanelVRE = 999;
  1651. }
  1652. /* DontExpand overrule */
  1653. if((SiS_Pr->SiS_VBType & VB_SISVB) && (!(SiS_Pr->SiS_VBType & VB_NoLCD))) {
  1654. if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && (modeflag & NoSupportLCDScale)) {
  1655. /* No scaling for this mode on any panel (LCD=CRT2)*/
  1656. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1657. }
  1658. switch(SiS_Pr->SiS_LCDResInfo) {
  1659. case Panel_Custom:
  1660. case Panel_1152x864:
  1661. case Panel_1280x768: /* TMDS only */
  1662. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1663. break;
  1664. case Panel_800x600: {
  1665. static const unsigned char nonscalingmodes[] = {
  1666. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, 0xff
  1667. };
  1668. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1669. break;
  1670. }
  1671. case Panel_1024x768: {
  1672. static const unsigned char nonscalingmodes[] = {
  1673. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1674. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1675. 0xff
  1676. };
  1677. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1678. break;
  1679. }
  1680. case Panel_1280x720: {
  1681. static const unsigned char nonscalingmodes[] = {
  1682. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1683. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1684. 0xff
  1685. };
  1686. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1687. if(SiS_Pr->PanelHT == 1650) {
  1688. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1689. }
  1690. break;
  1691. }
  1692. case Panel_1280x768_2: { /* LVDS only */
  1693. static const unsigned char nonscalingmodes[] = {
  1694. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1695. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1696. SIS_RI_1152x768,0xff
  1697. };
  1698. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1699. switch(resinfo) {
  1700. case SIS_RI_1280x720: if(SiS_Pr->UsePanelScaler == -1) {
  1701. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1702. }
  1703. break;
  1704. }
  1705. break;
  1706. }
  1707. case Panel_1280x800: { /* SiS TMDS special (Averatec 6200 series) */
  1708. static const unsigned char nonscalingmodes[] = {
  1709. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1710. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1711. SIS_RI_1152x768,SIS_RI_1280x720,SIS_RI_1280x768,0xff
  1712. };
  1713. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1714. break;
  1715. }
  1716. case Panel_1280x800_2: { /* SiS LVDS */
  1717. static const unsigned char nonscalingmodes[] = {
  1718. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1719. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1720. SIS_RI_1152x768,0xff
  1721. };
  1722. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1723. switch(resinfo) {
  1724. case SIS_RI_1280x720:
  1725. case SIS_RI_1280x768: if(SiS_Pr->UsePanelScaler == -1) {
  1726. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1727. }
  1728. break;
  1729. }
  1730. break;
  1731. }
  1732. case Panel_1280x854: { /* SiS LVDS */
  1733. static const unsigned char nonscalingmodes[] = {
  1734. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1735. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1736. SIS_RI_1152x768,0xff
  1737. };
  1738. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1739. switch(resinfo) {
  1740. case SIS_RI_1280x720:
  1741. case SIS_RI_1280x768:
  1742. case SIS_RI_1280x800: if(SiS_Pr->UsePanelScaler == -1) {
  1743. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1744. }
  1745. break;
  1746. }
  1747. break;
  1748. }
  1749. case Panel_1280x960: {
  1750. static const unsigned char nonscalingmodes[] = {
  1751. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1752. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1753. SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x720,SIS_RI_1280x768,SIS_RI_1280x800,
  1754. SIS_RI_1280x854,0xff
  1755. };
  1756. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1757. break;
  1758. }
  1759. case Panel_1280x1024: {
  1760. static const unsigned char nonscalingmodes[] = {
  1761. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1762. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1763. SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x720,SIS_RI_1280x768,SIS_RI_1280x800,
  1764. SIS_RI_1280x854,SIS_RI_1280x960,0xff
  1765. };
  1766. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1767. break;
  1768. }
  1769. case Panel_1400x1050: {
  1770. static const unsigned char nonscalingmodes[] = {
  1771. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1772. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1773. SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x768,SIS_RI_1280x800,SIS_RI_1280x854,
  1774. SIS_RI_1280x960,0xff
  1775. };
  1776. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1777. switch(resinfo) {
  1778. case SIS_RI_1280x720: if(SiS_Pr->UsePanelScaler == -1) {
  1779. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1780. }
  1781. break;
  1782. case SIS_RI_1280x1024: SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1783. break;
  1784. }
  1785. break;
  1786. }
  1787. case Panel_1600x1200: {
  1788. static const unsigned char nonscalingmodes[] = {
  1789. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1790. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1791. SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x720,SIS_RI_1280x768,SIS_RI_1280x800,
  1792. SIS_RI_1280x854,SIS_RI_1280x960,SIS_RI_1360x768,SIS_RI_1360x1024,0xff
  1793. };
  1794. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1795. break;
  1796. }
  1797. case Panel_1680x1050: {
  1798. static const unsigned char nonscalingmodes[] = {
  1799. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1800. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1801. SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x854,SIS_RI_1280x960,SIS_RI_1360x768,
  1802. SIS_RI_1360x1024,0xff
  1803. };
  1804. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1805. break;
  1806. }
  1807. }
  1808. }
  1809. #ifdef CONFIG_FB_SIS_300
  1810. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  1811. if(SiS_Pr->SiS_CustomT == CUT_PANEL848 || SiS_Pr->SiS_CustomT == CUT_PANEL856) {
  1812. SiS_Pr->SiS_LCDInfo = 0x80 | 0x40 | 0x20; /* neg h/v sync, RGB24(D0 = 0) */
  1813. }
  1814. }
  1815. if(SiS_Pr->ChipType < SIS_315H) {
  1816. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  1817. if(SiS_Pr->SiS_UseROM) {
  1818. if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) {
  1819. if(!(ROMAddr[0x235] & 0x02)) {
  1820. SiS_Pr->SiS_LCDInfo &= (~DontExpandLCD);
  1821. }
  1822. }
  1823. }
  1824. } else if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  1825. if((SiS_Pr->SiS_SetFlag & SetDOSMode) && ((ModeNo == 0x03) || (ModeNo == 0x10))) {
  1826. SiS_Pr->SiS_LCDInfo &= (~DontExpandLCD);
  1827. }
  1828. }
  1829. }
  1830. #endif
  1831. /* Special cases */
  1832. if(modexres == SiS_Pr->PanelXRes && modeyres == SiS_Pr->PanelYRes) {
  1833. SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  1834. }
  1835. if(SiS_Pr->SiS_IF_DEF_TRUMPION) {
  1836. SiS_Pr->SiS_LCDInfo |= (DontExpandLCD | LCDPass11);
  1837. }
  1838. switch(SiS_Pr->SiS_LCDResInfo) {
  1839. case Panel_640x480:
  1840. SiS_Pr->SiS_LCDInfo |= (DontExpandLCD | LCDPass11);
  1841. break;
  1842. case Panel_1280x800:
  1843. /* Don't pass 1:1 by default (TMDS special) */
  1844. if(SiS_Pr->CenterScreen == -1) SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  1845. break;
  1846. case Panel_1280x960:
  1847. SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  1848. break;
  1849. case Panel_Custom:
  1850. if((!SiS_Pr->CP_PrefClock) ||
  1851. (modexres > SiS_Pr->PanelXRes) || (modeyres > SiS_Pr->PanelYRes)) {
  1852. SiS_Pr->SiS_LCDInfo |= LCDPass11;
  1853. }
  1854. break;
  1855. }
  1856. if((SiS_Pr->UseCustomMode) || (SiS_Pr->SiS_CustomT == CUT_UNKNOWNLCD)) {
  1857. SiS_Pr->SiS_LCDInfo |= (DontExpandLCD | LCDPass11);
  1858. }
  1859. /* (In)validate LCDPass11 flag */
  1860. if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
  1861. SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  1862. }
  1863. /* LVDS DDA */
  1864. if(!((SiS_Pr->ChipType < SIS_315H) && (SiS_Pr->SiS_SetFlag & SetDOSMode))) {
  1865. if((SiS_Pr->SiS_IF_DEF_LVDS == 1) || (SiS_Pr->SiS_VBType & VB_NoLCD)) {
  1866. if(SiS_Pr->SiS_IF_DEF_TRUMPION == 0) {
  1867. if(ModeNo == 0x12) {
  1868. if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
  1869. SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
  1870. }
  1871. } else if(ModeNo > 0x13) {
  1872. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x600) {
  1873. if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
  1874. if((resinfo == SIS_RI_800x600) || (resinfo == SIS_RI_400x300)) {
  1875. SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
  1876. }
  1877. }
  1878. }
  1879. }
  1880. }
  1881. }
  1882. if(modeflag & HalfDCLK) {
  1883. if(SiS_Pr->SiS_IF_DEF_TRUMPION == 1) {
  1884. SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
  1885. } else if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  1886. SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
  1887. } else if(SiS_Pr->SiS_LCDResInfo == Panel_640x480) {
  1888. SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
  1889. } else if(ModeNo > 0x13) {
  1890. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  1891. if(resinfo == SIS_RI_512x384) SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
  1892. } else if(SiS_Pr->SiS_LCDResInfo == Panel_800x600) {
  1893. if(resinfo == SIS_RI_400x300) SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
  1894. }
  1895. }
  1896. }
  1897. }
  1898. /* VESA timing */
  1899. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  1900. if(SiS_Pr->SiS_VBInfo & SetNotSimuMode) {
  1901. SiS_Pr->SiS_SetFlag |= LCDVESATiming;
  1902. }
  1903. } else {
  1904. SiS_Pr->SiS_SetFlag |= LCDVESATiming;
  1905. }
  1906. #if 0
  1907. printk(KERN_DEBUG "sisfb: (LCDInfo=0x%04x LCDResInfo=0x%02x LCDTypeInfo=0x%02x)\n",
  1908. SiS_Pr->SiS_LCDInfo, SiS_Pr->SiS_LCDResInfo, SiS_Pr->SiS_LCDTypeInfo);
  1909. #endif
  1910. }
  1911. /*********************************************/
  1912. /* GET VCLK */
  1913. /*********************************************/
  1914. unsigned short
  1915. SiS_GetVCLK2Ptr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  1916. unsigned short RefreshRateTableIndex)
  1917. {
  1918. unsigned short CRT2Index, VCLKIndex = 0, VCLKIndexGEN = 0, VCLKIndexGENCRT = 0;
  1919. unsigned short modeflag, resinfo, tempbx;
  1920. const unsigned char *CHTVVCLKPtr = NULL;
  1921. if(ModeNo <= 0x13) {
  1922. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  1923. resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
  1924. CRT2Index = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  1925. VCLKIndexGEN = (SiS_GetRegByte((SiS_Pr->SiS_P3ca+0x02)) >> 2) & 0x03;
  1926. VCLKIndexGENCRT = VCLKIndexGEN;
  1927. } else {
  1928. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  1929. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  1930. CRT2Index = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  1931. VCLKIndexGEN = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
  1932. VCLKIndexGENCRT = SiS_GetRefCRTVCLK(SiS_Pr, RefreshRateTableIndex,
  1933. (SiS_Pr->SiS_SetFlag & ProgrammingCRT2) ? SiS_Pr->SiS_UseWideCRT2 : SiS_Pr->SiS_UseWide);
  1934. }
  1935. if(SiS_Pr->SiS_VBType & VB_SISVB) { /* 30x/B/LV */
  1936. if(SiS_Pr->SiS_SetFlag & ProgrammingCRT2) {
  1937. CRT2Index >>= 6;
  1938. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { /* LCD */
  1939. if(SiS_Pr->ChipType < SIS_315H) {
  1940. VCLKIndex = SiS_Pr->PanelVCLKIdx300;
  1941. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  1942. VCLKIndex = VCLKIndexGEN;
  1943. }
  1944. } else {
  1945. VCLKIndex = SiS_Pr->PanelVCLKIdx315;
  1946. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  1947. switch(resinfo) {
  1948. /* Correct those whose IndexGEN doesn't match VBVCLK array */
  1949. case SIS_RI_720x480: VCLKIndex = VCLK_720x480; break;
  1950. case SIS_RI_720x576: VCLKIndex = VCLK_720x576; break;
  1951. case SIS_RI_768x576: VCLKIndex = VCLK_768x576; break;
  1952. case SIS_RI_848x480: VCLKIndex = VCLK_848x480; break;
  1953. case SIS_RI_856x480: VCLKIndex = VCLK_856x480; break;
  1954. case SIS_RI_800x480: VCLKIndex = VCLK_800x480; break;
  1955. case SIS_RI_1024x576: VCLKIndex = VCLK_1024x576; break;
  1956. case SIS_RI_1152x864: VCLKIndex = VCLK_1152x864; break;
  1957. case SIS_RI_1280x720: VCLKIndex = VCLK_1280x720; break;
  1958. case SIS_RI_1360x768: VCLKIndex = VCLK_1360x768; break;
  1959. default: VCLKIndex = VCLKIndexGEN;
  1960. }
  1961. if(ModeNo <= 0x13) {
  1962. if(SiS_Pr->ChipType <= SIS_315PRO) {
  1963. if(SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC == 1) VCLKIndex = 0x42;
  1964. } else {
  1965. if(SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC == 1) VCLKIndex = 0x00;
  1966. }
  1967. }
  1968. if(SiS_Pr->ChipType <= SIS_315PRO) {
  1969. if(VCLKIndex == 0) VCLKIndex = 0x41;
  1970. if(VCLKIndex == 1) VCLKIndex = 0x43;
  1971. if(VCLKIndex == 4) VCLKIndex = 0x44;
  1972. }
  1973. }
  1974. }
  1975. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { /* TV */
  1976. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  1977. if(SiS_Pr->SiS_TVMode & TVRPLLDIV2XO) VCLKIndex = HiTVVCLKDIV2;
  1978. else VCLKIndex = HiTVVCLK;
  1979. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) VCLKIndex = HiTVSimuVCLK;
  1980. } else if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) VCLKIndex = YPbPr750pVCLK;
  1981. else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) VCLKIndex = TVVCLKDIV2;
  1982. else if(SiS_Pr->SiS_TVMode & TVRPLLDIV2XO) VCLKIndex = TVVCLKDIV2;
  1983. else VCLKIndex = TVVCLK;
  1984. if(SiS_Pr->ChipType < SIS_315H) VCLKIndex += TVCLKBASE_300;
  1985. else VCLKIndex += TVCLKBASE_315;
  1986. } else { /* VGA2 */
  1987. VCLKIndex = VCLKIndexGENCRT;
  1988. if(SiS_Pr->ChipType < SIS_315H) {
  1989. if(ModeNo > 0x13) {
  1990. if( (SiS_Pr->ChipType == SIS_630) &&
  1991. (SiS_Pr->ChipRevision >= 0x30)) {
  1992. if(VCLKIndex == 0x14) VCLKIndex = 0x34;
  1993. }
  1994. /* Better VGA2 clock for 1280x1024@75 */
  1995. if(VCLKIndex == 0x17) VCLKIndex = 0x45;
  1996. }
  1997. }
  1998. }
  1999. } else { /* If not programming CRT2 */
  2000. VCLKIndex = VCLKIndexGENCRT;
  2001. if(SiS_Pr->ChipType < SIS_315H) {
  2002. if(ModeNo > 0x13) {
  2003. if( (SiS_Pr->ChipType != SIS_630) &&
  2004. (SiS_Pr->ChipType != SIS_300) ) {
  2005. if(VCLKIndex == 0x1b) VCLKIndex = 0x48;
  2006. }
  2007. }
  2008. }
  2009. }
  2010. } else { /* LVDS */
  2011. VCLKIndex = CRT2Index;
  2012. if(SiS_Pr->SiS_SetFlag & ProgrammingCRT2) {
  2013. if( (SiS_Pr->SiS_IF_DEF_CH70xx != 0) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV) ) {
  2014. VCLKIndex &= 0x1f;
  2015. tempbx = 0;
  2016. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx += 1;
  2017. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  2018. tempbx += 2;
  2019. if(SiS_Pr->SiS_ModeType > ModeVGA) {
  2020. if(SiS_Pr->SiS_CHSOverScan) tempbx = 8;
  2021. }
  2022. if(SiS_Pr->SiS_TVMode & TVSetPALM) {
  2023. tempbx = 4;
  2024. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx += 1;
  2025. } else if(SiS_Pr->SiS_TVMode & TVSetPALN) {
  2026. tempbx = 6;
  2027. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx += 1;
  2028. }
  2029. }
  2030. switch(tempbx) {
  2031. case 0: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKUNTSC; break;
  2032. case 1: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKONTSC; break;
  2033. case 2: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKUPAL; break;
  2034. case 3: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKOPAL; break;
  2035. case 4: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKUPALM; break;
  2036. case 5: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKOPALM; break;
  2037. case 6: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKUPALN; break;
  2038. case 7: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKOPALN; break;
  2039. case 8: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKSOPAL; break;
  2040. default: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKOPAL; break;
  2041. }
  2042. VCLKIndex = CHTVVCLKPtr[VCLKIndex];
  2043. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  2044. if(SiS_Pr->ChipType < SIS_315H) {
  2045. VCLKIndex = SiS_Pr->PanelVCLKIdx300;
  2046. } else {
  2047. VCLKIndex = SiS_Pr->PanelVCLKIdx315;
  2048. }
  2049. #ifdef CONFIG_FB_SIS_300
  2050. /* Special Timing: Barco iQ Pro R series */
  2051. if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) VCLKIndex = 0x44;
  2052. /* Special Timing: 848x480 and 856x480 parallel lvds panels */
  2053. if(SiS_Pr->SiS_CustomT == CUT_PANEL848 || SiS_Pr->SiS_CustomT == CUT_PANEL856) {
  2054. if(SiS_Pr->ChipType < SIS_315H) {
  2055. VCLKIndex = VCLK34_300;
  2056. /* if(resinfo == SIS_RI_1360x768) VCLKIndex = ?; */
  2057. } else {
  2058. VCLKIndex = VCLK34_315;
  2059. /* if(resinfo == SIS_RI_1360x768) VCLKIndex = ?; */
  2060. }
  2061. }
  2062. #endif
  2063. } else {
  2064. VCLKIndex = VCLKIndexGENCRT;
  2065. if(SiS_Pr->ChipType < SIS_315H) {
  2066. if(ModeNo > 0x13) {
  2067. if( (SiS_Pr->ChipType == SIS_630) &&
  2068. (SiS_Pr->ChipRevision >= 0x30) ) {
  2069. if(VCLKIndex == 0x14) VCLKIndex = 0x2e;
  2070. }
  2071. }
  2072. }
  2073. }
  2074. } else { /* if not programming CRT2 */
  2075. VCLKIndex = VCLKIndexGENCRT;
  2076. if(SiS_Pr->ChipType < SIS_315H) {
  2077. if(ModeNo > 0x13) {
  2078. if( (SiS_Pr->ChipType != SIS_630) &&
  2079. (SiS_Pr->ChipType != SIS_300) ) {
  2080. if(VCLKIndex == 0x1b) VCLKIndex = 0x48;
  2081. }
  2082. #if 0
  2083. if(SiS_Pr->ChipType == SIS_730) {
  2084. if(VCLKIndex == 0x0b) VCLKIndex = 0x40; /* 1024x768-70 */
  2085. if(VCLKIndex == 0x0d) VCLKIndex = 0x41; /* 1024x768-75 */
  2086. }
  2087. #endif
  2088. }
  2089. }
  2090. }
  2091. }
  2092. return VCLKIndex;
  2093. }
  2094. /*********************************************/
  2095. /* SET CRT2 MODE TYPE REGISTERS */
  2096. /*********************************************/
  2097. static void
  2098. SiS_SetCRT2ModeRegs(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  2099. {
  2100. unsigned short i, j, modeflag, tempah=0;
  2101. short tempcl;
  2102. #if defined(CONFIG_FB_SIS_300) || defined(CONFIG_FB_SIS_315)
  2103. unsigned short tempbl;
  2104. #endif
  2105. #ifdef CONFIG_FB_SIS_315
  2106. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  2107. unsigned short tempah2, tempbl2;
  2108. #endif
  2109. modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
  2110. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  2111. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x00,0xAF,0x40);
  2112. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2E,0xF7);
  2113. } else {
  2114. for(i=0,j=4; i<3; i++,j++) SiS_SetReg(SiS_Pr->SiS_Part1Port,j,0);
  2115. if(SiS_Pr->ChipType >= SIS_315H) {
  2116. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x02,0x7F);
  2117. }
  2118. tempcl = SiS_Pr->SiS_ModeType;
  2119. if(SiS_Pr->ChipType < SIS_315H) {
  2120. #ifdef CONFIG_FB_SIS_300 /* ---- 300 series ---- */
  2121. /* For 301BDH: (with LCD via LVDS) */
  2122. if(SiS_Pr->SiS_VBType & VB_NoLCD) {
  2123. tempbl = SiS_GetReg(SiS_Pr->SiS_P3c4,0x32);
  2124. tempbl &= 0xef;
  2125. tempbl |= 0x02;
  2126. if((SiS_Pr->SiS_VBInfo & SetCRT2ToTV) || (SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) {
  2127. tempbl |= 0x10;
  2128. tempbl &= 0xfd;
  2129. }
  2130. SiS_SetReg(SiS_Pr->SiS_P3c4,0x32,tempbl);
  2131. }
  2132. if(ModeNo > 0x13) {
  2133. tempcl -= ModeVGA;
  2134. if(tempcl >= 0) {
  2135. tempah = ((0x10 >> tempcl) | 0x80);
  2136. }
  2137. } else tempah = 0x80;
  2138. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) tempah ^= 0xA0;
  2139. #endif /* CONFIG_FB_SIS_300 */
  2140. } else {
  2141. #ifdef CONFIG_FB_SIS_315 /* ------- 315/330 series ------ */
  2142. if(ModeNo > 0x13) {
  2143. tempcl -= ModeVGA;
  2144. if(tempcl >= 0) {
  2145. tempah = (0x08 >> tempcl);
  2146. if (tempah == 0) tempah = 1;
  2147. tempah |= 0x40;
  2148. }
  2149. } else tempah = 0x40;
  2150. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) tempah ^= 0x50;
  2151. #endif /* CONFIG_FB_SIS_315 */
  2152. }
  2153. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 0;
  2154. if(SiS_Pr->ChipType < SIS_315H) {
  2155. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,tempah);
  2156. } else {
  2157. #ifdef CONFIG_FB_SIS_315
  2158. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  2159. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x00,0xa0,tempah);
  2160. } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
  2161. if(IS_SIS740) {
  2162. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,tempah);
  2163. } else {
  2164. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x00,0xa0,tempah);
  2165. }
  2166. }
  2167. #endif
  2168. }
  2169. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  2170. tempah = 0x01;
  2171. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  2172. tempah |= 0x02;
  2173. }
  2174. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) {
  2175. tempah ^= 0x05;
  2176. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) {
  2177. tempah ^= 0x01;
  2178. }
  2179. }
  2180. if(SiS_Pr->ChipType < SIS_315H) {
  2181. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 0;
  2182. tempah = (tempah << 5) & 0xFF;
  2183. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x01,tempah);
  2184. tempah = (tempah >> 5) & 0xFF;
  2185. } else {
  2186. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 0x08;
  2187. else if(!(SiS_IsDualEdge(SiS_Pr))) tempah |= 0x08;
  2188. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2E,0xF0,tempah);
  2189. tempah &= ~0x08;
  2190. }
  2191. if((SiS_Pr->SiS_ModeType == ModeVGA) && (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode))) {
  2192. tempah |= 0x10;
  2193. }
  2194. tempah |= 0x80;
  2195. if(SiS_Pr->SiS_VBType & VB_SIS301) {
  2196. if(SiS_Pr->PanelXRes < 1280 && SiS_Pr->PanelYRes < 960) tempah &= ~0x80;
  2197. }
  2198. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  2199. if(!(SiS_Pr->SiS_TVMode & (TVSetYPbPr750p | TVSetYPbPr525p))) {
  2200. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  2201. tempah |= 0x20;
  2202. }
  2203. }
  2204. }
  2205. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x0D,0x40,tempah);
  2206. tempah = 0x80;
  2207. if(SiS_Pr->SiS_VBType & VB_SIS301) {
  2208. if(SiS_Pr->PanelXRes < 1280 && SiS_Pr->PanelYRes < 960) tempah = 0;
  2209. }
  2210. if(SiS_IsDualLink(SiS_Pr)) tempah |= 0x40;
  2211. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  2212. if(SiS_Pr->SiS_TVMode & TVRPLLDIV2XO) {
  2213. tempah |= 0x40;
  2214. }
  2215. }
  2216. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0C,tempah);
  2217. } else { /* LVDS */
  2218. if(SiS_Pr->ChipType >= SIS_315H) {
  2219. #ifdef CONFIG_FB_SIS_315
  2220. /* LVDS can only be slave in 8bpp modes */
  2221. tempah = 0x80;
  2222. if((modeflag & CRT2Mode) && (SiS_Pr->SiS_ModeType > ModeVGA)) {
  2223. if(SiS_Pr->SiS_VBInfo & DriverMode) {
  2224. tempah |= 0x02;
  2225. }
  2226. }
  2227. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) tempah |= 0x02;
  2228. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) tempah ^= 0x01;
  2229. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 1;
  2230. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2e,0xF0,tempah);
  2231. #endif
  2232. } else {
  2233. #ifdef CONFIG_FB_SIS_300
  2234. tempah = 0;
  2235. if( (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) && (SiS_Pr->SiS_ModeType > ModeVGA) ) {
  2236. tempah |= 0x02;
  2237. }
  2238. tempah <<= 5;
  2239. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 0;
  2240. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x01,tempah);
  2241. #endif
  2242. }
  2243. }
  2244. } /* LCDA */
  2245. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  2246. if(SiS_Pr->ChipType >= SIS_315H) {
  2247. #ifdef CONFIG_FB_SIS_315
  2248. /* unsigned char bridgerev = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x01); */
  2249. /* The following is nearly unpreditable and varies from machine
  2250. * to machine. Especially the 301DH seems to be a real trouble
  2251. * maker. Some BIOSes simply set the registers (like in the
  2252. * NoLCD-if-statements here), some set them according to the
  2253. * LCDA stuff. It is very likely that some machines are not
  2254. * treated correctly in the following, very case-orientated
  2255. * code. What do I do then...?
  2256. */
  2257. /* 740 variants match for 30xB, 301B-DH, 30xLV */
  2258. if(!(IS_SIS740)) {
  2259. tempah = 0x04; /* For all bridges */
  2260. tempbl = 0xfb;
  2261. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  2262. tempah = 0x00;
  2263. if(SiS_IsDualEdge(SiS_Pr)) {
  2264. tempbl = 0xff;
  2265. }
  2266. }
  2267. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,tempbl,tempah);
  2268. }
  2269. /* The following two are responsible for eventually wrong colors
  2270. * in TV output. The DH (VB_NoLCD) conditions are unknown; the
  2271. * b0 was found in some 651 machine (Pim; P4_23=0xe5); the b1 version
  2272. * in a 650 box (Jake). What is the criteria?
  2273. * Addendum: Another combination 651+301B-DH(b1) (Rapo) needs same
  2274. * treatment like the 651+301B-DH(b0) case. Seems more to be the
  2275. * chipset than the bridge revision.
  2276. */
  2277. if((IS_SIS740) || (SiS_Pr->ChipType >= SIS_661) || (SiS_Pr->SiS_ROMNew)) {
  2278. tempah = 0x30;
  2279. tempbl = 0xc0;
  2280. if((SiS_Pr->SiS_VBInfo & DisableCRT2Display) ||
  2281. ((SiS_Pr->SiS_ROMNew) && (!(ROMAddr[0x5b] & 0x04)))) {
  2282. tempah = 0x00;
  2283. tempbl = 0x00;
  2284. }
  2285. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2c,0xcf,tempah);
  2286. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x21,0x3f,tempbl);
  2287. } else if(SiS_Pr->SiS_VBType & VB_SIS301) {
  2288. /* Fixes "TV-blue-bug" on 315+301 */
  2289. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2c,0xcf); /* For 301 */
  2290. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x21,0x3f);
  2291. } else if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  2292. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2c,0x30); /* For 30xLV */
  2293. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x21,0xc0);
  2294. } else if(SiS_Pr->SiS_VBType & VB_NoLCD) { /* For 301B-DH */
  2295. tempah = 0x30; tempah2 = 0xc0;
  2296. tempbl = 0xcf; tempbl2 = 0x3f;
  2297. if(SiS_Pr->SiS_TVBlue == 0) {
  2298. tempah = tempah2 = 0x00;
  2299. } else if(SiS_Pr->SiS_TVBlue == -1) {
  2300. /* Set on 651/M650, clear on 315/650 */
  2301. if(!(IS_SIS65x)) /* (bridgerev != 0xb0) */ {
  2302. tempah = tempah2 = 0x00;
  2303. }
  2304. }
  2305. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2c,tempbl,tempah);
  2306. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x21,tempbl2,tempah2);
  2307. } else {
  2308. tempah = 0x30; tempah2 = 0xc0; /* For 30xB, 301C */
  2309. tempbl = 0xcf; tempbl2 = 0x3f;
  2310. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  2311. tempah = tempah2 = 0x00;
  2312. if(SiS_IsDualEdge(SiS_Pr)) {
  2313. tempbl = tempbl2 = 0xff;
  2314. }
  2315. }
  2316. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2c,tempbl,tempah);
  2317. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x21,tempbl2,tempah2);
  2318. }
  2319. if(IS_SIS740) {
  2320. tempah = 0x80;
  2321. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 0x00;
  2322. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x23,0x7f,tempah);
  2323. } else {
  2324. tempah = 0x00;
  2325. tempbl = 0x7f;
  2326. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  2327. tempbl = 0xff;
  2328. if(!(SiS_IsDualEdge(SiS_Pr))) tempah = 0x80;
  2329. }
  2330. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x23,tempbl,tempah);
  2331. }
  2332. #endif /* CONFIG_FB_SIS_315 */
  2333. } else if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  2334. #ifdef CONFIG_FB_SIS_300
  2335. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x21,0x3f);
  2336. if((SiS_Pr->SiS_VBInfo & DisableCRT2Display) ||
  2337. ((SiS_Pr->SiS_VBType & VB_NoLCD) &&
  2338. (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD))) {
  2339. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x23,0x7F);
  2340. } else {
  2341. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x23,0x80);
  2342. }
  2343. #endif
  2344. }
  2345. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  2346. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x0D,0x80);
  2347. if(SiS_Pr->SiS_VBType & VB_SIS30xCLV) {
  2348. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x3A,0xC0);
  2349. }
  2350. }
  2351. } else { /* LVDS */
  2352. #ifdef CONFIG_FB_SIS_315
  2353. if(SiS_Pr->ChipType >= SIS_315H) {
  2354. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  2355. tempah = 0x04;
  2356. tempbl = 0xfb;
  2357. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  2358. tempah = 0x00;
  2359. if(SiS_IsDualEdge(SiS_Pr)) tempbl = 0xff;
  2360. }
  2361. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,tempbl,tempah);
  2362. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) {
  2363. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xfb);
  2364. }
  2365. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2c,0x30);
  2366. } else if(SiS_Pr->ChipType == SIS_550) {
  2367. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xfb);
  2368. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2c,0x30);
  2369. }
  2370. }
  2371. #endif
  2372. }
  2373. }
  2374. /*********************************************/
  2375. /* GET RESOLUTION DATA */
  2376. /*********************************************/
  2377. unsigned short
  2378. SiS_GetResInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  2379. {
  2380. if(ModeNo <= 0x13)
  2381. return ((unsigned short)SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo);
  2382. else
  2383. return ((unsigned short)SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO);
  2384. }
  2385. static void
  2386. SiS_GetCRT2ResInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  2387. {
  2388. unsigned short xres, yres, modeflag=0, resindex;
  2389. if(SiS_Pr->UseCustomMode) {
  2390. xres = SiS_Pr->CHDisplay;
  2391. if(SiS_Pr->CModeFlag & HalfDCLK) xres <<= 1;
  2392. SiS_Pr->SiS_VGAHDE = SiS_Pr->SiS_HDE = xres;
  2393. /* DoubleScanMode-check done in CheckCalcCustomMode()! */
  2394. SiS_Pr->SiS_VGAVDE = SiS_Pr->SiS_VDE = SiS_Pr->CVDisplay;
  2395. return;
  2396. }
  2397. resindex = SiS_GetResInfo(SiS_Pr,ModeNo,ModeIdIndex);
  2398. if(ModeNo <= 0x13) {
  2399. xres = SiS_Pr->SiS_StResInfo[resindex].HTotal;
  2400. yres = SiS_Pr->SiS_StResInfo[resindex].VTotal;
  2401. } else {
  2402. xres = SiS_Pr->SiS_ModeResInfo[resindex].HTotal;
  2403. yres = SiS_Pr->SiS_ModeResInfo[resindex].VTotal;
  2404. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  2405. }
  2406. if(!SiS_Pr->SiS_IF_DEF_DSTN && !SiS_Pr->SiS_IF_DEF_FSTN) {
  2407. if((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->SiS_IF_DEF_LVDS == 1)) {
  2408. if((ModeNo != 0x03) && (SiS_Pr->SiS_SetFlag & SetDOSMode)) {
  2409. if(yres == 350) yres = 400;
  2410. }
  2411. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x3a) & 0x01) {
  2412. if(ModeNo == 0x12) yres = 400;
  2413. }
  2414. }
  2415. if(modeflag & HalfDCLK) xres <<= 1;
  2416. if(modeflag & DoubleScanMode) yres <<= 1;
  2417. }
  2418. if((SiS_Pr->SiS_VBType & VB_SISVB) && (!(SiS_Pr->SiS_VBType & VB_NoLCD))) {
  2419. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  2420. switch(SiS_Pr->SiS_LCDResInfo) {
  2421. case Panel_1024x768:
  2422. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
  2423. if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
  2424. if(yres == 350) yres = 357;
  2425. if(yres == 400) yres = 420;
  2426. if(yres == 480) yres = 525;
  2427. }
  2428. }
  2429. break;
  2430. case Panel_1280x1024:
  2431. if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
  2432. /* BIOS bug - does this regardless of scaling */
  2433. if(yres == 400) yres = 405;
  2434. }
  2435. if(yres == 350) yres = 360;
  2436. if(SiS_Pr->SiS_SetFlag & LCDVESATiming) {
  2437. if(yres == 360) yres = 375;
  2438. }
  2439. break;
  2440. case Panel_1600x1200:
  2441. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
  2442. if(yres == 1024) yres = 1056;
  2443. }
  2444. break;
  2445. }
  2446. }
  2447. } else {
  2448. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  2449. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToHiVision)) {
  2450. if(xres == 720) xres = 640;
  2451. }
  2452. } else if(xres == 720) xres = 640;
  2453. if(SiS_Pr->SiS_SetFlag & SetDOSMode) {
  2454. yres = 400;
  2455. if(SiS_Pr->ChipType >= SIS_315H) {
  2456. if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x17) & 0x80) yres = 480;
  2457. } else {
  2458. if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x80) yres = 480;
  2459. }
  2460. if(SiS_Pr->SiS_IF_DEF_DSTN || SiS_Pr->SiS_IF_DEF_FSTN) yres = 480;
  2461. }
  2462. }
  2463. SiS_Pr->SiS_VGAHDE = SiS_Pr->SiS_HDE = xres;
  2464. SiS_Pr->SiS_VGAVDE = SiS_Pr->SiS_VDE = yres;
  2465. }
  2466. /*********************************************/
  2467. /* GET CRT2 TIMING DATA */
  2468. /*********************************************/
  2469. static void
  2470. SiS_GetCRT2Ptr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  2471. unsigned short RefreshRateTableIndex, unsigned short *CRT2Index,
  2472. unsigned short *ResIndex)
  2473. {
  2474. unsigned short tempbx=0, tempal=0, resinfo=0;
  2475. if(ModeNo <= 0x13) {
  2476. tempal = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  2477. } else {
  2478. tempal = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  2479. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  2480. }
  2481. if((SiS_Pr->SiS_VBType & VB_SISVB) && (SiS_Pr->SiS_IF_DEF_LVDS == 0)) {
  2482. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { /* LCD */
  2483. tempbx = SiS_Pr->SiS_LCDResInfo;
  2484. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) tempbx += 32;
  2485. /* patch index */
  2486. if(SiS_Pr->SiS_LCDResInfo == Panel_1680x1050) {
  2487. if (resinfo == SIS_RI_1280x800) tempal = 9;
  2488. else if(resinfo == SIS_RI_1400x1050) tempal = 11;
  2489. } else if((SiS_Pr->SiS_LCDResInfo == Panel_1280x800) ||
  2490. (SiS_Pr->SiS_LCDResInfo == Panel_1280x800_2) ||
  2491. (SiS_Pr->SiS_LCDResInfo == Panel_1280x854)) {
  2492. if (resinfo == SIS_RI_1280x768) tempal = 9;
  2493. }
  2494. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  2495. /* Pass 1:1 only (center-screen handled outside) */
  2496. /* This is never called for the panel's native resolution */
  2497. /* since Pass1:1 will not be set in this case */
  2498. tempbx = 100;
  2499. if(ModeNo >= 0x13) {
  2500. tempal = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC_NS;
  2501. }
  2502. }
  2503. #ifdef CONFIG_FB_SIS_315
  2504. if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) {
  2505. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) {
  2506. if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
  2507. tempbx = 200;
  2508. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) tempbx++;
  2509. }
  2510. }
  2511. }
  2512. #endif
  2513. } else { /* TV */
  2514. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  2515. /* if(SiS_Pr->SiS_VGAVDE > 480) SiS_Pr->SiS_TVMode &= (~TVSetTVSimuMode); */
  2516. tempbx = 2;
  2517. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  2518. tempbx = 13;
  2519. if(!(SiS_Pr->SiS_TVMode & TVSetTVSimuMode)) tempbx = 14;
  2520. }
  2521. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  2522. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) tempbx = 7;
  2523. else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) tempbx = 6;
  2524. else tempbx = 5;
  2525. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) tempbx += 5;
  2526. } else {
  2527. if(SiS_Pr->SiS_TVMode & TVSetPAL) tempbx = 3;
  2528. else tempbx = 4;
  2529. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) tempbx += 5;
  2530. }
  2531. }
  2532. tempal &= 0x3F;
  2533. if(ModeNo > 0x13) {
  2534. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoHiVision) {
  2535. switch(resinfo) {
  2536. case SIS_RI_720x480:
  2537. tempal = 6;
  2538. if(SiS_Pr->SiS_TVMode & (TVSetPAL | TVSetPALN)) tempal = 9;
  2539. break;
  2540. case SIS_RI_720x576:
  2541. case SIS_RI_768x576:
  2542. case SIS_RI_1024x576: /* Not in NTSC or YPBPR mode (except 1080i)! */
  2543. tempal = 6;
  2544. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  2545. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) tempal = 8;
  2546. }
  2547. break;
  2548. case SIS_RI_800x480:
  2549. tempal = 4;
  2550. break;
  2551. case SIS_RI_512x384:
  2552. case SIS_RI_1024x768:
  2553. tempal = 7;
  2554. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  2555. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) tempal = 8;
  2556. }
  2557. break;
  2558. case SIS_RI_1280x720:
  2559. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  2560. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) tempal = 9;
  2561. }
  2562. break;
  2563. }
  2564. }
  2565. }
  2566. *CRT2Index = tempbx;
  2567. *ResIndex = tempal;
  2568. } else { /* LVDS, 301B-DH (if running on LCD) */
  2569. tempbx = 0;
  2570. if((SiS_Pr->SiS_IF_DEF_CH70xx) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
  2571. tempbx = 90;
  2572. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  2573. tempbx = 92;
  2574. if(SiS_Pr->SiS_ModeType > ModeVGA) {
  2575. if(SiS_Pr->SiS_CHSOverScan) tempbx = 99;
  2576. }
  2577. if(SiS_Pr->SiS_TVMode & TVSetPALM) tempbx = 94;
  2578. else if(SiS_Pr->SiS_TVMode & TVSetPALN) tempbx = 96;
  2579. }
  2580. if(tempbx != 99) {
  2581. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx++;
  2582. }
  2583. } else {
  2584. switch(SiS_Pr->SiS_LCDResInfo) {
  2585. case Panel_640x480: tempbx = 12; break;
  2586. case Panel_320x240_1: tempbx = 10; break;
  2587. case Panel_320x240_2:
  2588. case Panel_320x240_3: tempbx = 14; break;
  2589. case Panel_800x600: tempbx = 16; break;
  2590. case Panel_1024x600: tempbx = 18; break;
  2591. case Panel_1152x768:
  2592. case Panel_1024x768: tempbx = 20; break;
  2593. case Panel_1280x768: tempbx = 22; break;
  2594. case Panel_1280x1024: tempbx = 24; break;
  2595. case Panel_1400x1050: tempbx = 26; break;
  2596. case Panel_1600x1200: tempbx = 28; break;
  2597. #ifdef CONFIG_FB_SIS_300
  2598. case Panel_Barco1366: tempbx = 80; break;
  2599. #endif
  2600. }
  2601. switch(SiS_Pr->SiS_LCDResInfo) {
  2602. case Panel_320x240_1:
  2603. case Panel_320x240_2:
  2604. case Panel_320x240_3:
  2605. case Panel_640x480:
  2606. break;
  2607. default:
  2608. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++;
  2609. }
  2610. if(SiS_Pr->SiS_LCDInfo & LCDPass11) tempbx = 30;
  2611. #ifdef CONFIG_FB_SIS_300
  2612. if(SiS_Pr->SiS_CustomT == CUT_BARCO1024) {
  2613. tempbx = 82;
  2614. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++;
  2615. } else if(SiS_Pr->SiS_CustomT == CUT_PANEL848 || SiS_Pr->SiS_CustomT == CUT_PANEL856) {
  2616. tempbx = 84;
  2617. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++;
  2618. }
  2619. #endif
  2620. }
  2621. (*CRT2Index) = tempbx;
  2622. (*ResIndex) = tempal & 0x1F;
  2623. }
  2624. }
  2625. static void
  2626. SiS_GetRAMDAC2DATA(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  2627. unsigned short RefreshRateTableIndex)
  2628. {
  2629. unsigned short tempax=0, tempbx=0, index, dotclock;
  2630. unsigned short temp1=0, modeflag=0, tempcx=0;
  2631. SiS_Pr->SiS_RVBHCMAX = 1;
  2632. SiS_Pr->SiS_RVBHCFACT = 1;
  2633. if(ModeNo <= 0x13) {
  2634. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  2635. index = SiS_GetModePtr(SiS_Pr,ModeNo,ModeIdIndex);
  2636. tempax = SiS_Pr->SiS_StandTable[index].CRTC[0];
  2637. tempbx = SiS_Pr->SiS_StandTable[index].CRTC[6];
  2638. temp1 = SiS_Pr->SiS_StandTable[index].CRTC[7];
  2639. dotclock = (modeflag & Charx8Dot) ? 8 : 9;
  2640. } else {
  2641. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  2642. index = SiS_GetRefCRT1CRTC(SiS_Pr, RefreshRateTableIndex, SiS_Pr->SiS_UseWideCRT2);
  2643. tempax = SiS_Pr->SiS_CRT1Table[index].CR[0];
  2644. tempax |= (SiS_Pr->SiS_CRT1Table[index].CR[14] << 8);
  2645. tempax &= 0x03FF;
  2646. tempbx = SiS_Pr->SiS_CRT1Table[index].CR[6];
  2647. tempcx = SiS_Pr->SiS_CRT1Table[index].CR[13] << 8;
  2648. tempcx &= 0x0100;
  2649. tempcx <<= 2;
  2650. tempbx |= tempcx;
  2651. temp1 = SiS_Pr->SiS_CRT1Table[index].CR[7];
  2652. dotclock = 8;
  2653. }
  2654. if(temp1 & 0x01) tempbx |= 0x0100;
  2655. if(temp1 & 0x20) tempbx |= 0x0200;
  2656. tempax += 5;
  2657. tempax *= dotclock;
  2658. if(modeflag & HalfDCLK) tempax <<= 1;
  2659. tempbx++;
  2660. SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_HT = tempax;
  2661. SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_VT = tempbx;
  2662. }
  2663. static void
  2664. SiS_CalcPanelLinkTiming(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
  2665. unsigned short ModeIdIndex, unsigned short RefreshRateTableIndex)
  2666. {
  2667. unsigned short ResIndex;
  2668. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  2669. if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
  2670. if(SiS_Pr->UseCustomMode) {
  2671. ResIndex = SiS_Pr->CHTotal;
  2672. if(SiS_Pr->CModeFlag & HalfDCLK) ResIndex <<= 1;
  2673. SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_HT = ResIndex;
  2674. SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_VT = SiS_Pr->CVTotal;
  2675. } else {
  2676. if(ModeNo < 0x13) {
  2677. ResIndex = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  2678. } else {
  2679. ResIndex = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC_NS;
  2680. }
  2681. if(ResIndex == 0x09) {
  2682. if(SiS_Pr->Alternate1600x1200) ResIndex = 0x20; /* 1600x1200 LCDA */
  2683. else if(SiS_Pr->SiS_IF_DEF_LVDS == 1) ResIndex = 0x21; /* 1600x1200 LVDS */
  2684. }
  2685. SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_NoScaleData[ResIndex].VGAHT;
  2686. SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_NoScaleData[ResIndex].VGAVT;
  2687. SiS_Pr->SiS_HT = SiS_Pr->SiS_NoScaleData[ResIndex].LCDHT;
  2688. SiS_Pr->SiS_VT = SiS_Pr->SiS_NoScaleData[ResIndex].LCDVT;
  2689. }
  2690. } else {
  2691. SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_HT = SiS_Pr->PanelHT;
  2692. SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_VT = SiS_Pr->PanelVT;
  2693. }
  2694. } else {
  2695. /* This handles custom modes and custom panels */
  2696. SiS_Pr->SiS_HDE = SiS_Pr->PanelXRes;
  2697. SiS_Pr->SiS_VDE = SiS_Pr->PanelYRes;
  2698. SiS_Pr->SiS_HT = SiS_Pr->PanelHT;
  2699. SiS_Pr->SiS_VT = SiS_Pr->PanelVT;
  2700. SiS_Pr->SiS_VGAHT = SiS_Pr->PanelHT - (SiS_Pr->PanelXRes - SiS_Pr->SiS_VGAHDE);
  2701. SiS_Pr->SiS_VGAVT = SiS_Pr->PanelVT - (SiS_Pr->PanelYRes - SiS_Pr->SiS_VGAVDE);
  2702. }
  2703. }
  2704. static void
  2705. SiS_GetCRT2DataLVDS(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  2706. unsigned short RefreshRateTableIndex)
  2707. {
  2708. unsigned short CRT2Index, ResIndex, backup;
  2709. const struct SiS_LVDSData *LVDSData = NULL;
  2710. SiS_GetCRT2ResInfo(SiS_Pr, ModeNo, ModeIdIndex);
  2711. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  2712. SiS_Pr->SiS_RVBHCMAX = 1;
  2713. SiS_Pr->SiS_RVBHCFACT = 1;
  2714. SiS_Pr->SiS_NewFlickerMode = 0;
  2715. SiS_Pr->SiS_RVBHRS = 50;
  2716. SiS_Pr->SiS_RY1COE = 0;
  2717. SiS_Pr->SiS_RY2COE = 0;
  2718. SiS_Pr->SiS_RY3COE = 0;
  2719. SiS_Pr->SiS_RY4COE = 0;
  2720. SiS_Pr->SiS_RVBHRS2 = 0;
  2721. }
  2722. if((SiS_Pr->SiS_VBType & VB_SISVB) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  2723. #ifdef CONFIG_FB_SIS_315
  2724. SiS_CalcPanelLinkTiming(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  2725. SiS_CalcLCDACRT1Timing(SiS_Pr, ModeNo, ModeIdIndex);
  2726. #endif
  2727. } else {
  2728. /* 301BDH needs LVDS Data */
  2729. backup = SiS_Pr->SiS_IF_DEF_LVDS;
  2730. if((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) {
  2731. SiS_Pr->SiS_IF_DEF_LVDS = 1;
  2732. }
  2733. SiS_GetCRT2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex,
  2734. &CRT2Index, &ResIndex);
  2735. SiS_Pr->SiS_IF_DEF_LVDS = backup;
  2736. switch(CRT2Index) {
  2737. case 10: LVDSData = SiS_Pr->SiS_LVDS320x240Data_1; break;
  2738. case 14: LVDSData = SiS_Pr->SiS_LVDS320x240Data_2; break;
  2739. case 12: LVDSData = SiS_Pr->SiS_LVDS640x480Data_1; break;
  2740. case 16: LVDSData = SiS_Pr->SiS_LVDS800x600Data_1; break;
  2741. case 18: LVDSData = SiS_Pr->SiS_LVDS1024x600Data_1; break;
  2742. case 20: LVDSData = SiS_Pr->SiS_LVDS1024x768Data_1; break;
  2743. #ifdef CONFIG_FB_SIS_300
  2744. case 80: LVDSData = SiS_Pr->SiS_LVDSBARCO1366Data_1; break;
  2745. case 81: LVDSData = SiS_Pr->SiS_LVDSBARCO1366Data_2; break;
  2746. case 82: LVDSData = SiS_Pr->SiS_LVDSBARCO1024Data_1; break;
  2747. case 84: LVDSData = SiS_Pr->SiS_LVDS848x480Data_1; break;
  2748. case 85: LVDSData = SiS_Pr->SiS_LVDS848x480Data_2; break;
  2749. #endif
  2750. case 90: LVDSData = SiS_Pr->SiS_CHTVUNTSCData; break;
  2751. case 91: LVDSData = SiS_Pr->SiS_CHTVONTSCData; break;
  2752. case 92: LVDSData = SiS_Pr->SiS_CHTVUPALData; break;
  2753. case 93: LVDSData = SiS_Pr->SiS_CHTVOPALData; break;
  2754. case 94: LVDSData = SiS_Pr->SiS_CHTVUPALMData; break;
  2755. case 95: LVDSData = SiS_Pr->SiS_CHTVOPALMData; break;
  2756. case 96: LVDSData = SiS_Pr->SiS_CHTVUPALNData; break;
  2757. case 97: LVDSData = SiS_Pr->SiS_CHTVOPALNData; break;
  2758. case 99: LVDSData = SiS_Pr->SiS_CHTVSOPALData; break;
  2759. }
  2760. if(LVDSData) {
  2761. SiS_Pr->SiS_VGAHT = (LVDSData+ResIndex)->VGAHT;
  2762. SiS_Pr->SiS_VGAVT = (LVDSData+ResIndex)->VGAVT;
  2763. SiS_Pr->SiS_HT = (LVDSData+ResIndex)->LCDHT;
  2764. SiS_Pr->SiS_VT = (LVDSData+ResIndex)->LCDVT;
  2765. } else {
  2766. SiS_CalcPanelLinkTiming(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  2767. }
  2768. if( (!(SiS_Pr->SiS_VBType & VB_SISVB)) &&
  2769. (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) &&
  2770. (!(SiS_Pr->SiS_LCDInfo & LCDPass11)) ) {
  2771. if( (!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) ||
  2772. (SiS_Pr->SiS_SetFlag & SetDOSMode) ) {
  2773. SiS_Pr->SiS_HDE = SiS_Pr->PanelXRes;
  2774. SiS_Pr->SiS_VDE = SiS_Pr->PanelYRes;
  2775. #ifdef CONFIG_FB_SIS_300
  2776. if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) {
  2777. if(ResIndex < 0x08) {
  2778. SiS_Pr->SiS_HDE = 1280;
  2779. SiS_Pr->SiS_VDE = 1024;
  2780. }
  2781. }
  2782. #endif
  2783. }
  2784. }
  2785. }
  2786. }
  2787. static void
  2788. SiS_GetCRT2Data301(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  2789. unsigned short RefreshRateTableIndex)
  2790. {
  2791. unsigned char *ROMAddr = NULL;
  2792. unsigned short tempax, tempbx, modeflag, romptr=0;
  2793. unsigned short resinfo, CRT2Index, ResIndex;
  2794. const struct SiS_LCDData *LCDPtr = NULL;
  2795. const struct SiS_TVData *TVPtr = NULL;
  2796. #ifdef CONFIG_FB_SIS_315
  2797. short resinfo661;
  2798. #endif
  2799. if(ModeNo <= 0x13) {
  2800. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  2801. resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
  2802. } else if(SiS_Pr->UseCustomMode) {
  2803. modeflag = SiS_Pr->CModeFlag;
  2804. resinfo = 0;
  2805. } else {
  2806. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  2807. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  2808. #ifdef CONFIG_FB_SIS_315
  2809. resinfo661 = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].ROMMODEIDX661;
  2810. if( (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) &&
  2811. (SiS_Pr->SiS_SetFlag & LCDVESATiming) &&
  2812. (resinfo661 >= 0) &&
  2813. (SiS_Pr->SiS_NeedRomModeData) ) {
  2814. if((ROMAddr = GetLCDStructPtr661(SiS_Pr))) {
  2815. if((romptr = (SISGETROMW(21)))) {
  2816. romptr += (resinfo661 * 10);
  2817. ROMAddr = SiS_Pr->VirtualRomBase;
  2818. }
  2819. }
  2820. }
  2821. #endif
  2822. }
  2823. SiS_Pr->SiS_NewFlickerMode = 0;
  2824. SiS_Pr->SiS_RVBHRS = 50;
  2825. SiS_Pr->SiS_RY1COE = 0;
  2826. SiS_Pr->SiS_RY2COE = 0;
  2827. SiS_Pr->SiS_RY3COE = 0;
  2828. SiS_Pr->SiS_RY4COE = 0;
  2829. SiS_Pr->SiS_RVBHRS2 = 0;
  2830. SiS_GetCRT2ResInfo(SiS_Pr,ModeNo,ModeIdIndex);
  2831. if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) {
  2832. if(SiS_Pr->UseCustomMode) {
  2833. SiS_Pr->SiS_RVBHCMAX = 1;
  2834. SiS_Pr->SiS_RVBHCFACT = 1;
  2835. SiS_Pr->SiS_HDE = SiS_Pr->SiS_VGAHDE;
  2836. SiS_Pr->SiS_VDE = SiS_Pr->SiS_VGAVDE;
  2837. tempax = SiS_Pr->CHTotal;
  2838. if(modeflag & HalfDCLK) tempax <<= 1;
  2839. SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_HT = tempax;
  2840. SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_VT = SiS_Pr->CVTotal;
  2841. } else {
  2842. SiS_GetRAMDAC2DATA(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  2843. }
  2844. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  2845. SiS_GetCRT2Ptr(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex,
  2846. &CRT2Index,&ResIndex);
  2847. switch(CRT2Index) {
  2848. case 2: TVPtr = SiS_Pr->SiS_ExtHiTVData; break;
  2849. case 3: TVPtr = SiS_Pr->SiS_ExtPALData; break;
  2850. case 4: TVPtr = SiS_Pr->SiS_ExtNTSCData; break;
  2851. case 5: TVPtr = SiS_Pr->SiS_Ext525iData; break;
  2852. case 6: TVPtr = SiS_Pr->SiS_Ext525pData; break;
  2853. case 7: TVPtr = SiS_Pr->SiS_Ext750pData; break;
  2854. case 8: TVPtr = SiS_Pr->SiS_StPALData; break;
  2855. case 9: TVPtr = SiS_Pr->SiS_StNTSCData; break;
  2856. case 10: TVPtr = SiS_Pr->SiS_St525iData; break;
  2857. case 11: TVPtr = SiS_Pr->SiS_St525pData; break;
  2858. case 12: TVPtr = SiS_Pr->SiS_St750pData; break;
  2859. case 13: TVPtr = SiS_Pr->SiS_St1HiTVData; break;
  2860. case 14: TVPtr = SiS_Pr->SiS_St2HiTVData; break;
  2861. default: TVPtr = SiS_Pr->SiS_StPALData; break;
  2862. }
  2863. SiS_Pr->SiS_RVBHCMAX = (TVPtr+ResIndex)->RVBHCMAX;
  2864. SiS_Pr->SiS_RVBHCFACT = (TVPtr+ResIndex)->RVBHCFACT;
  2865. SiS_Pr->SiS_VGAHT = (TVPtr+ResIndex)->VGAHT;
  2866. SiS_Pr->SiS_VGAVT = (TVPtr+ResIndex)->VGAVT;
  2867. SiS_Pr->SiS_HDE = (TVPtr+ResIndex)->TVHDE;
  2868. SiS_Pr->SiS_VDE = (TVPtr+ResIndex)->TVVDE;
  2869. SiS_Pr->SiS_RVBHRS2 = (TVPtr+ResIndex)->RVBHRS2 & 0x0fff;
  2870. if(modeflag & HalfDCLK) {
  2871. SiS_Pr->SiS_RVBHRS = (TVPtr+ResIndex)->HALFRVBHRS;
  2872. if(SiS_Pr->SiS_RVBHRS2) {
  2873. SiS_Pr->SiS_RVBHRS2 = ((SiS_Pr->SiS_RVBHRS2 + 3) >> 1) - 3;
  2874. tempax = ((TVPtr+ResIndex)->RVBHRS2 >> 12) & 0x07;
  2875. if((TVPtr+ResIndex)->RVBHRS2 & 0x8000) SiS_Pr->SiS_RVBHRS2 -= tempax;
  2876. else SiS_Pr->SiS_RVBHRS2 += tempax;
  2877. }
  2878. } else {
  2879. SiS_Pr->SiS_RVBHRS = (TVPtr+ResIndex)->RVBHRS;
  2880. }
  2881. SiS_Pr->SiS_NewFlickerMode = ((TVPtr+ResIndex)->FlickerMode) << 7;
  2882. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  2883. if((resinfo == SIS_RI_960x600) ||
  2884. (resinfo == SIS_RI_1024x768) ||
  2885. (resinfo == SIS_RI_1280x1024) ||
  2886. (resinfo == SIS_RI_1280x720)) {
  2887. SiS_Pr->SiS_NewFlickerMode = 0x40;
  2888. }
  2889. if(SiS_Pr->SiS_VGAVDE == 350) SiS_Pr->SiS_TVMode |= TVSetTVSimuMode;
  2890. SiS_Pr->SiS_HT = ExtHiTVHT;
  2891. SiS_Pr->SiS_VT = ExtHiTVVT;
  2892. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  2893. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) {
  2894. SiS_Pr->SiS_HT = StHiTVHT;
  2895. SiS_Pr->SiS_VT = StHiTVVT;
  2896. }
  2897. }
  2898. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  2899. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) {
  2900. SiS_Pr->SiS_HT = 1650;
  2901. SiS_Pr->SiS_VT = 750;
  2902. } else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) {
  2903. SiS_Pr->SiS_HT = NTSCHT;
  2904. if(SiS_Pr->SiS_TVMode & TVSet525p1024) SiS_Pr->SiS_HT = NTSC2HT;
  2905. SiS_Pr->SiS_VT = NTSCVT;
  2906. } else {
  2907. SiS_Pr->SiS_HT = NTSCHT;
  2908. if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) SiS_Pr->SiS_HT = NTSC2HT;
  2909. SiS_Pr->SiS_VT = NTSCVT;
  2910. }
  2911. } else {
  2912. SiS_Pr->SiS_RY1COE = (TVPtr+ResIndex)->RY1COE;
  2913. SiS_Pr->SiS_RY2COE = (TVPtr+ResIndex)->RY2COE;
  2914. SiS_Pr->SiS_RY3COE = (TVPtr+ResIndex)->RY3COE;
  2915. SiS_Pr->SiS_RY4COE = (TVPtr+ResIndex)->RY4COE;
  2916. if(modeflag & HalfDCLK) {
  2917. SiS_Pr->SiS_RY1COE = 0x00;
  2918. SiS_Pr->SiS_RY2COE = 0xf4;
  2919. SiS_Pr->SiS_RY3COE = 0x10;
  2920. SiS_Pr->SiS_RY4COE = 0x38;
  2921. }
  2922. if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) {
  2923. SiS_Pr->SiS_HT = NTSCHT;
  2924. if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) SiS_Pr->SiS_HT = NTSC2HT;
  2925. SiS_Pr->SiS_VT = NTSCVT;
  2926. } else {
  2927. SiS_Pr->SiS_HT = PALHT;
  2928. SiS_Pr->SiS_VT = PALVT;
  2929. }
  2930. }
  2931. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  2932. SiS_Pr->SiS_RVBHCMAX = 1;
  2933. SiS_Pr->SiS_RVBHCFACT = 1;
  2934. if(SiS_Pr->UseCustomMode) {
  2935. SiS_Pr->SiS_HDE = SiS_Pr->SiS_VGAHDE;
  2936. SiS_Pr->SiS_VDE = SiS_Pr->SiS_VGAVDE;
  2937. tempax = SiS_Pr->CHTotal;
  2938. if(modeflag & HalfDCLK) tempax <<= 1;
  2939. SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_HT = tempax;
  2940. SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_VT = SiS_Pr->CVTotal;
  2941. } else {
  2942. bool gotit = false;
  2943. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
  2944. SiS_Pr->SiS_VGAHT = SiS_Pr->PanelHT;
  2945. SiS_Pr->SiS_VGAVT = SiS_Pr->PanelVT;
  2946. SiS_Pr->SiS_HT = SiS_Pr->PanelHT;
  2947. SiS_Pr->SiS_VT = SiS_Pr->PanelVT;
  2948. gotit = true;
  2949. } else if( (!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) && (romptr) && (ROMAddr) ) {
  2950. #ifdef CONFIG_FB_SIS_315
  2951. SiS_Pr->SiS_RVBHCMAX = ROMAddr[romptr];
  2952. SiS_Pr->SiS_RVBHCFACT = ROMAddr[romptr+1];
  2953. SiS_Pr->SiS_VGAHT = ROMAddr[romptr+2] | ((ROMAddr[romptr+3] & 0x0f) << 8);
  2954. SiS_Pr->SiS_VGAVT = (ROMAddr[romptr+4] << 4) | ((ROMAddr[romptr+3] & 0xf0) >> 4);
  2955. SiS_Pr->SiS_HT = ROMAddr[romptr+5] | ((ROMAddr[romptr+6] & 0x0f) << 8);
  2956. SiS_Pr->SiS_VT = (ROMAddr[romptr+7] << 4) | ((ROMAddr[romptr+6] & 0xf0) >> 4);
  2957. SiS_Pr->SiS_RVBHRS2 = ROMAddr[romptr+8] | ((ROMAddr[romptr+9] & 0x0f) << 8);
  2958. if((SiS_Pr->SiS_RVBHRS2) && (modeflag & HalfDCLK)) {
  2959. SiS_Pr->SiS_RVBHRS2 = ((SiS_Pr->SiS_RVBHRS2 + 3) >> 1) - 3;
  2960. tempax = (ROMAddr[romptr+9] >> 4) & 0x07;
  2961. if(ROMAddr[romptr+9] & 0x80) SiS_Pr->SiS_RVBHRS2 -= tempax;
  2962. else SiS_Pr->SiS_RVBHRS2 += tempax;
  2963. }
  2964. if(SiS_Pr->SiS_VGAHT) gotit = true;
  2965. else {
  2966. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  2967. SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  2968. SiS_Pr->SiS_RVBHCMAX = 1;
  2969. SiS_Pr->SiS_RVBHCFACT = 1;
  2970. SiS_Pr->SiS_VGAHT = SiS_Pr->PanelHT;
  2971. SiS_Pr->SiS_VGAVT = SiS_Pr->PanelVT;
  2972. SiS_Pr->SiS_HT = SiS_Pr->PanelHT;
  2973. SiS_Pr->SiS_VT = SiS_Pr->PanelVT;
  2974. SiS_Pr->SiS_RVBHRS2 = 0;
  2975. gotit = true;
  2976. }
  2977. #endif
  2978. }
  2979. if(!gotit) {
  2980. SiS_GetCRT2Ptr(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex,
  2981. &CRT2Index,&ResIndex);
  2982. switch(CRT2Index) {
  2983. case Panel_1024x768 : LCDPtr = SiS_Pr->SiS_ExtLCD1024x768Data; break;
  2984. case Panel_1024x768 + 32: LCDPtr = SiS_Pr->SiS_St2LCD1024x768Data; break;
  2985. case Panel_1280x720 :
  2986. case Panel_1280x720 + 32: LCDPtr = SiS_Pr->SiS_LCD1280x720Data; break;
  2987. case Panel_1280x768_2 : LCDPtr = SiS_Pr->SiS_ExtLCD1280x768_2Data; break;
  2988. case Panel_1280x768_2+ 32: LCDPtr = SiS_Pr->SiS_StLCD1280x768_2Data; break;
  2989. case Panel_1280x800 :
  2990. case Panel_1280x800 + 32: LCDPtr = SiS_Pr->SiS_LCD1280x800Data; break;
  2991. case Panel_1280x800_2 :
  2992. case Panel_1280x800_2+ 32: LCDPtr = SiS_Pr->SiS_LCD1280x800_2Data; break;
  2993. case Panel_1280x854 :
  2994. case Panel_1280x854 + 32: LCDPtr = SiS_Pr->SiS_LCD1280x854Data; break;
  2995. case Panel_1280x960 :
  2996. case Panel_1280x960 + 32: LCDPtr = SiS_Pr->SiS_LCD1280x960Data; break;
  2997. case Panel_1280x1024 : LCDPtr = SiS_Pr->SiS_ExtLCD1280x1024Data; break;
  2998. case Panel_1280x1024 + 32: LCDPtr = SiS_Pr->SiS_St2LCD1280x1024Data; break;
  2999. case Panel_1400x1050 : LCDPtr = SiS_Pr->SiS_ExtLCD1400x1050Data; break;
  3000. case Panel_1400x1050 + 32: LCDPtr = SiS_Pr->SiS_StLCD1400x1050Data; break;
  3001. case Panel_1600x1200 : LCDPtr = SiS_Pr->SiS_ExtLCD1600x1200Data; break;
  3002. case Panel_1600x1200 + 32: LCDPtr = SiS_Pr->SiS_StLCD1600x1200Data; break;
  3003. case Panel_1680x1050 :
  3004. case Panel_1680x1050 + 32: LCDPtr = SiS_Pr->SiS_LCD1680x1050Data; break;
  3005. case 100 : LCDPtr = SiS_Pr->SiS_NoScaleData; break;
  3006. #ifdef CONFIG_FB_SIS_315
  3007. case 200 : LCDPtr = SiS310_ExtCompaq1280x1024Data; break;
  3008. case 201 : LCDPtr = SiS_Pr->SiS_St2LCD1280x1024Data; break;
  3009. #endif
  3010. default : LCDPtr = SiS_Pr->SiS_ExtLCD1024x768Data; break;
  3011. }
  3012. SiS_Pr->SiS_RVBHCMAX = (LCDPtr+ResIndex)->RVBHCMAX;
  3013. SiS_Pr->SiS_RVBHCFACT = (LCDPtr+ResIndex)->RVBHCFACT;
  3014. SiS_Pr->SiS_VGAHT = (LCDPtr+ResIndex)->VGAHT;
  3015. SiS_Pr->SiS_VGAVT = (LCDPtr+ResIndex)->VGAVT;
  3016. SiS_Pr->SiS_HT = (LCDPtr+ResIndex)->LCDHT;
  3017. SiS_Pr->SiS_VT = (LCDPtr+ResIndex)->LCDVT;
  3018. }
  3019. tempax = SiS_Pr->PanelXRes;
  3020. tempbx = SiS_Pr->PanelYRes;
  3021. switch(SiS_Pr->SiS_LCDResInfo) {
  3022. case Panel_1024x768:
  3023. if(SiS_Pr->SiS_SetFlag & LCDVESATiming) {
  3024. if(SiS_Pr->ChipType < SIS_315H) {
  3025. if (SiS_Pr->SiS_VGAVDE == 350) tempbx = 560;
  3026. else if(SiS_Pr->SiS_VGAVDE == 400) tempbx = 640;
  3027. }
  3028. } else {
  3029. if (SiS_Pr->SiS_VGAVDE == 357) tempbx = 527;
  3030. else if(SiS_Pr->SiS_VGAVDE == 420) tempbx = 620;
  3031. else if(SiS_Pr->SiS_VGAVDE == 525) tempbx = 775;
  3032. else if(SiS_Pr->SiS_VGAVDE == 600) tempbx = 775;
  3033. else if(SiS_Pr->SiS_VGAVDE == 350) tempbx = 560;
  3034. else if(SiS_Pr->SiS_VGAVDE == 400) tempbx = 640;
  3035. }
  3036. break;
  3037. case Panel_1280x960:
  3038. if (SiS_Pr->SiS_VGAVDE == 350) tempbx = 700;
  3039. else if(SiS_Pr->SiS_VGAVDE == 400) tempbx = 800;
  3040. else if(SiS_Pr->SiS_VGAVDE == 1024) tempbx = 960;
  3041. break;
  3042. case Panel_1280x1024:
  3043. if (SiS_Pr->SiS_VGAVDE == 360) tempbx = 768;
  3044. else if(SiS_Pr->SiS_VGAVDE == 375) tempbx = 800;
  3045. else if(SiS_Pr->SiS_VGAVDE == 405) tempbx = 864;
  3046. break;
  3047. case Panel_1600x1200:
  3048. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
  3049. if (SiS_Pr->SiS_VGAVDE == 350) tempbx = 875;
  3050. else if(SiS_Pr->SiS_VGAVDE == 400) tempbx = 1000;
  3051. }
  3052. break;
  3053. }
  3054. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  3055. tempax = SiS_Pr->SiS_VGAHDE;
  3056. tempbx = SiS_Pr->SiS_VGAVDE;
  3057. }
  3058. SiS_Pr->SiS_HDE = tempax;
  3059. SiS_Pr->SiS_VDE = tempbx;
  3060. }
  3061. }
  3062. }
  3063. static void
  3064. SiS_GetCRT2Data(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  3065. unsigned short RefreshRateTableIndex)
  3066. {
  3067. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  3068. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  3069. SiS_GetCRT2DataLVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  3070. } else {
  3071. if((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) {
  3072. /* Need LVDS Data for LCD on 301B-DH */
  3073. SiS_GetCRT2DataLVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  3074. } else {
  3075. SiS_GetCRT2Data301(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  3076. }
  3077. }
  3078. } else {
  3079. SiS_GetCRT2DataLVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  3080. }
  3081. }
  3082. /*********************************************/
  3083. /* GET LVDS DES (SKEW) DATA */
  3084. /*********************************************/
  3085. static const struct SiS_LVDSDes *
  3086. SiS_GetLVDSDesPtr(struct SiS_Private *SiS_Pr)
  3087. {
  3088. const struct SiS_LVDSDes *PanelDesPtr = NULL;
  3089. #ifdef CONFIG_FB_SIS_300
  3090. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  3091. if(SiS_Pr->ChipType < SIS_315H) {
  3092. if(SiS_Pr->SiS_LCDTypeInfo == 4) {
  3093. if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) {
  3094. PanelDesPtr = SiS_Pr->SiS_PanelType04_1a;
  3095. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  3096. PanelDesPtr = SiS_Pr->SiS_PanelType04_2a;
  3097. }
  3098. } else if(SiS_Pr->SiS_CustomT == CUT_BARCO1024) {
  3099. PanelDesPtr = SiS_Pr->SiS_PanelType04_1b;
  3100. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  3101. PanelDesPtr = SiS_Pr->SiS_PanelType04_2b;
  3102. }
  3103. }
  3104. }
  3105. }
  3106. }
  3107. #endif
  3108. return PanelDesPtr;
  3109. }
  3110. static void
  3111. SiS_GetLVDSDesData(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  3112. unsigned short RefreshRateTableIndex)
  3113. {
  3114. unsigned short modeflag, ResIndex;
  3115. const struct SiS_LVDSDes *PanelDesPtr = NULL;
  3116. SiS_Pr->SiS_LCDHDES = 0;
  3117. SiS_Pr->SiS_LCDVDES = 0;
  3118. /* Some special cases */
  3119. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  3120. /* Trumpion */
  3121. if(SiS_Pr->SiS_IF_DEF_TRUMPION) {
  3122. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  3123. if(SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) {
  3124. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3125. }
  3126. }
  3127. return;
  3128. }
  3129. /* 640x480 on LVDS */
  3130. if(SiS_Pr->ChipType < SIS_315H) {
  3131. if(SiS_Pr->SiS_LCDResInfo == Panel_640x480 && SiS_Pr->SiS_LCDTypeInfo == 3) {
  3132. SiS_Pr->SiS_LCDHDES = 8;
  3133. if (SiS_Pr->SiS_VGAVDE >= 480) SiS_Pr->SiS_LCDVDES = 512;
  3134. else if(SiS_Pr->SiS_VGAVDE >= 400) SiS_Pr->SiS_LCDVDES = 436;
  3135. else if(SiS_Pr->SiS_VGAVDE >= 350) SiS_Pr->SiS_LCDVDES = 440;
  3136. return;
  3137. }
  3138. }
  3139. } /* LCD */
  3140. if( (SiS_Pr->UseCustomMode) ||
  3141. (SiS_Pr->SiS_LCDResInfo == Panel_Custom) ||
  3142. (SiS_Pr->SiS_CustomT == CUT_PANEL848) ||
  3143. (SiS_Pr->SiS_CustomT == CUT_PANEL856) ||
  3144. (SiS_Pr->SiS_LCDInfo & LCDPass11) ) {
  3145. return;
  3146. }
  3147. if(ModeNo <= 0x13) ResIndex = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  3148. else ResIndex = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  3149. if((SiS_Pr->SiS_VBType & VB_SIS30xBLV) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  3150. #ifdef CONFIG_FB_SIS_315
  3151. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  3152. /* non-pass 1:1 only, see above */
  3153. if(SiS_Pr->SiS_VGAHDE != SiS_Pr->PanelXRes) {
  3154. SiS_Pr->SiS_LCDHDES = SiS_Pr->SiS_HT - ((SiS_Pr->PanelXRes - SiS_Pr->SiS_VGAHDE) / 2);
  3155. }
  3156. if(SiS_Pr->SiS_VGAVDE != SiS_Pr->PanelYRes) {
  3157. SiS_Pr->SiS_LCDVDES = SiS_Pr->SiS_VT - ((SiS_Pr->PanelYRes - SiS_Pr->SiS_VGAVDE) / 2);
  3158. }
  3159. }
  3160. if(SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) {
  3161. switch(SiS_Pr->SiS_CustomT) {
  3162. case CUT_UNIWILL1024:
  3163. case CUT_UNIWILL10242:
  3164. case CUT_CLEVO1400:
  3165. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  3166. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3167. }
  3168. break;
  3169. }
  3170. switch(SiS_Pr->SiS_LCDResInfo) {
  3171. case Panel_1280x1024:
  3172. if(SiS_Pr->SiS_CustomT != CUT_COMPAQ1280) {
  3173. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3174. }
  3175. break;
  3176. case Panel_1280x800: /* Verified for Averatec 6240 */
  3177. case Panel_1280x800_2: /* Verified for Asus A4L */
  3178. case Panel_1280x854: /* Not verified yet FIXME */
  3179. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3180. break;
  3181. }
  3182. }
  3183. #endif
  3184. } else {
  3185. if((SiS_Pr->SiS_IF_DEF_CH70xx != 0) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
  3186. if((SiS_Pr->SiS_TVMode & TVSetPAL) && (!(SiS_Pr->SiS_TVMode & TVSetPALM))) {
  3187. if(ResIndex <= 3) SiS_Pr->SiS_LCDHDES = 256;
  3188. }
  3189. } else if((PanelDesPtr = SiS_GetLVDSDesPtr(SiS_Pr))) {
  3190. SiS_Pr->SiS_LCDHDES = (PanelDesPtr+ResIndex)->LCDHDES;
  3191. SiS_Pr->SiS_LCDVDES = (PanelDesPtr+ResIndex)->LCDVDES;
  3192. } else if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  3193. if(SiS_Pr->SiS_VGAHDE != SiS_Pr->PanelXRes) {
  3194. SiS_Pr->SiS_LCDHDES = SiS_Pr->SiS_HT - ((SiS_Pr->PanelXRes - SiS_Pr->SiS_VGAHDE) / 2);
  3195. }
  3196. if(SiS_Pr->SiS_VGAVDE != SiS_Pr->PanelYRes) {
  3197. SiS_Pr->SiS_LCDVDES = SiS_Pr->SiS_VT - ((SiS_Pr->PanelYRes - SiS_Pr->SiS_VGAVDE) / 2);
  3198. } else {
  3199. if(SiS_Pr->ChipType < SIS_315H) {
  3200. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3201. } else {
  3202. switch(SiS_Pr->SiS_LCDResInfo) {
  3203. case Panel_800x600:
  3204. case Panel_1024x768:
  3205. case Panel_1280x1024:
  3206. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT;
  3207. break;
  3208. case Panel_1400x1050:
  3209. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3210. break;
  3211. }
  3212. }
  3213. }
  3214. } else {
  3215. if(SiS_Pr->ChipType < SIS_315H) {
  3216. #ifdef CONFIG_FB_SIS_300
  3217. switch(SiS_Pr->SiS_LCDResInfo) {
  3218. case Panel_800x600:
  3219. if(SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) {
  3220. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3221. } else {
  3222. SiS_Pr->SiS_LCDHDES = SiS_Pr->PanelHT + 3;
  3223. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT;
  3224. if(SiS_Pr->SiS_VGAVDE == 400) SiS_Pr->SiS_LCDVDES -= 2;
  3225. else SiS_Pr->SiS_LCDVDES -= 4;
  3226. }
  3227. break;
  3228. case Panel_1024x768:
  3229. if(SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) {
  3230. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3231. } else {
  3232. SiS_Pr->SiS_LCDHDES = SiS_Pr->PanelHT - 1;
  3233. if(SiS_Pr->SiS_VGAVDE <= 400) SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 8;
  3234. if(SiS_Pr->SiS_VGAVDE <= 350) SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 12;
  3235. }
  3236. break;
  3237. case Panel_1024x600:
  3238. default:
  3239. if( (SiS_Pr->SiS_VGAHDE == SiS_Pr->PanelXRes) &&
  3240. (SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) ) {
  3241. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3242. } else {
  3243. SiS_Pr->SiS_LCDHDES = SiS_Pr->PanelHT - 1;
  3244. }
  3245. break;
  3246. }
  3247. switch(SiS_Pr->SiS_LCDTypeInfo) {
  3248. case 1:
  3249. SiS_Pr->SiS_LCDHDES = SiS_Pr->SiS_LCDVDES = 0;
  3250. break;
  3251. case 3: /* 640x480 only? */
  3252. SiS_Pr->SiS_LCDHDES = 8;
  3253. if (SiS_Pr->SiS_VGAVDE >= 480) SiS_Pr->SiS_LCDVDES = 512;
  3254. else if(SiS_Pr->SiS_VGAVDE >= 400) SiS_Pr->SiS_LCDVDES = 436;
  3255. else if(SiS_Pr->SiS_VGAVDE >= 350) SiS_Pr->SiS_LCDVDES = 440;
  3256. break;
  3257. }
  3258. #endif
  3259. } else {
  3260. #ifdef CONFIG_FB_SIS_315
  3261. switch(SiS_Pr->SiS_LCDResInfo) {
  3262. case Panel_1024x768:
  3263. case Panel_1280x1024:
  3264. if(SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) {
  3265. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3266. }
  3267. break;
  3268. case Panel_320x240_1:
  3269. case Panel_320x240_2:
  3270. case Panel_320x240_3:
  3271. SiS_Pr->SiS_LCDVDES = 524;
  3272. break;
  3273. }
  3274. #endif
  3275. }
  3276. }
  3277. if((ModeNo <= 0x13) && (SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
  3278. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  3279. if((SiS_Pr->SiS_VBType & VB_SIS30xBLV) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  3280. if(!(modeflag & HalfDCLK)) SiS_Pr->SiS_LCDHDES = 632;
  3281. } else if(!(SiS_Pr->SiS_SetFlag & SetDOSMode)) {
  3282. if(SiS_Pr->SiS_LCDResInfo != Panel_1280x1024) {
  3283. if(SiS_Pr->SiS_LCDResInfo >= Panel_1024x768) {
  3284. if(SiS_Pr->ChipType < SIS_315H) {
  3285. if(!(modeflag & HalfDCLK)) SiS_Pr->SiS_LCDHDES = 320;
  3286. } else {
  3287. #ifdef CONFIG_FB_SIS_315
  3288. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) SiS_Pr->SiS_LCDHDES = 480;
  3289. if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) SiS_Pr->SiS_LCDHDES = 804;
  3290. if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) SiS_Pr->SiS_LCDHDES = 704;
  3291. if(!(modeflag & HalfDCLK)) {
  3292. SiS_Pr->SiS_LCDHDES = 320;
  3293. if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) SiS_Pr->SiS_LCDHDES = 632;
  3294. if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) SiS_Pr->SiS_LCDHDES = 542;
  3295. }
  3296. #endif
  3297. }
  3298. }
  3299. }
  3300. }
  3301. }
  3302. }
  3303. }
  3304. /*********************************************/
  3305. /* DISABLE VIDEO BRIDGE */
  3306. /*********************************************/
  3307. #ifdef CONFIG_FB_SIS_315
  3308. static int
  3309. SiS_HandlePWD(struct SiS_Private *SiS_Pr)
  3310. {
  3311. int ret = 0;
  3312. #ifdef SET_PWD
  3313. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  3314. unsigned short romptr = GetLCDStructPtr661_2(SiS_Pr);
  3315. unsigned char drivermode = SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & 0x40;
  3316. unsigned short temp;
  3317. if( (SiS_Pr->SiS_VBType & VB_SISPWD) &&
  3318. (romptr) &&
  3319. (SiS_Pr->SiS_PWDOffset) ) {
  3320. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2b,ROMAddr[romptr + SiS_Pr->SiS_PWDOffset + 0]);
  3321. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2c,ROMAddr[romptr + SiS_Pr->SiS_PWDOffset + 1]);
  3322. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2d,ROMAddr[romptr + SiS_Pr->SiS_PWDOffset + 2]);
  3323. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2e,ROMAddr[romptr + SiS_Pr->SiS_PWDOffset + 3]);
  3324. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2f,ROMAddr[romptr + SiS_Pr->SiS_PWDOffset + 4]);
  3325. temp = 0x00;
  3326. if((ROMAddr[romptr + 2] & (0x06 << 1)) && !drivermode) {
  3327. temp = 0x80;
  3328. ret = 1;
  3329. }
  3330. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x27,0x7f,temp);
  3331. }
  3332. #endif
  3333. return ret;
  3334. }
  3335. #endif
  3336. /* NEVER use any variables (VBInfo), this will be called
  3337. * from outside the context of modeswitch!
  3338. * MUST call getVBType before calling this
  3339. */
  3340. void
  3341. SiS_DisableBridge(struct SiS_Private *SiS_Pr)
  3342. {
  3343. #ifdef CONFIG_FB_SIS_315
  3344. unsigned short tempah, pushax=0, modenum;
  3345. #endif
  3346. unsigned short temp=0;
  3347. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  3348. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) { /* ===== For 30xB/C/LV ===== */
  3349. if(SiS_Pr->ChipType < SIS_315H) {
  3350. #ifdef CONFIG_FB_SIS_300 /* 300 series */
  3351. if(!(SiS_CR36BIOSWord23b(SiS_Pr))) {
  3352. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3353. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFE);
  3354. } else {
  3355. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x08);
  3356. }
  3357. SiS_PanelDelay(SiS_Pr, 3);
  3358. }
  3359. if(SiS_Is301B(SiS_Pr)) {
  3360. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1f,0x3f);
  3361. SiS_ShortDelay(SiS_Pr,1);
  3362. }
  3363. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xDF);
  3364. SiS_DisplayOff(SiS_Pr);
  3365. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF);
  3366. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF);
  3367. SiS_UnLockCRT2(SiS_Pr);
  3368. if(!(SiS_Pr->SiS_VBType & VB_SISLVDS)) {
  3369. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x01,0x80);
  3370. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x02,0x40);
  3371. }
  3372. if( (!(SiS_CRT2IsLCD(SiS_Pr))) ||
  3373. (!(SiS_CR36BIOSWord23d(SiS_Pr))) ) {
  3374. SiS_PanelDelay(SiS_Pr, 2);
  3375. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3376. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFD);
  3377. } else {
  3378. SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x04);
  3379. }
  3380. }
  3381. #endif /* CONFIG_FB_SIS_300 */
  3382. } else {
  3383. #ifdef CONFIG_FB_SIS_315 /* 315 series */
  3384. int didpwd = 0;
  3385. bool custom1 = (SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) ||
  3386. (SiS_Pr->SiS_CustomT == CUT_CLEVO1400);
  3387. modenum = SiS_GetReg(SiS_Pr->SiS_P3d4,0x34) & 0x7f;
  3388. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3389. #ifdef SET_EMI
  3390. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  3391. if(SiS_Pr->SiS_CustomT != CUT_CLEVO1400) {
  3392. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
  3393. }
  3394. }
  3395. #endif
  3396. didpwd = SiS_HandlePWD(SiS_Pr);
  3397. if( (modenum <= 0x13) ||
  3398. (SiS_IsVAMode(SiS_Pr)) ||
  3399. (!(SiS_IsDualEdge(SiS_Pr))) ) {
  3400. if(!didpwd) {
  3401. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xfe);
  3402. if(custom1) SiS_PanelDelay(SiS_Pr, 3);
  3403. } else {
  3404. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xfc);
  3405. }
  3406. }
  3407. if(!custom1) {
  3408. SiS_DDC2Delay(SiS_Pr,0xff00);
  3409. SiS_DDC2Delay(SiS_Pr,0xe000);
  3410. SiS_SetRegByte(SiS_Pr->SiS_P3c6,0x00);
  3411. pushax = SiS_GetReg(SiS_Pr->SiS_P3c4,0x06);
  3412. if(IS_SIS740) {
  3413. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x06,0xE3);
  3414. }
  3415. SiS_PanelDelay(SiS_Pr, 3);
  3416. }
  3417. }
  3418. if(!(SiS_IsNotM650orLater(SiS_Pr))) {
  3419. /* if(SiS_Pr->ChipType < SIS_340) {*/
  3420. tempah = 0xef;
  3421. if(SiS_IsVAMode(SiS_Pr)) tempah = 0xf7;
  3422. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x4c,tempah);
  3423. /*}*/
  3424. }
  3425. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3426. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1F,~0x10);
  3427. }
  3428. tempah = 0x3f;
  3429. if(SiS_IsDualEdge(SiS_Pr)) {
  3430. tempah = 0x7f;
  3431. if(!(SiS_IsVAMode(SiS_Pr))) tempah = 0xbf;
  3432. }
  3433. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1F,tempah);
  3434. if((SiS_IsVAMode(SiS_Pr)) ||
  3435. ((SiS_Pr->SiS_VBType & VB_SISLVDS) && (modenum <= 0x13))) {
  3436. SiS_DisplayOff(SiS_Pr);
  3437. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3438. SiS_PanelDelay(SiS_Pr, 2);
  3439. }
  3440. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF);
  3441. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1E,0xDF);
  3442. }
  3443. if((!(SiS_IsVAMode(SiS_Pr))) ||
  3444. ((SiS_Pr->SiS_VBType & VB_SISLVDS) && (modenum <= 0x13))) {
  3445. if(!(SiS_IsDualEdge(SiS_Pr))) {
  3446. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xdf);
  3447. SiS_DisplayOff(SiS_Pr);
  3448. }
  3449. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x80);
  3450. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3451. SiS_PanelDelay(SiS_Pr, 2);
  3452. }
  3453. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF);
  3454. temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00);
  3455. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x10);
  3456. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF);
  3457. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,temp);
  3458. }
  3459. if(SiS_IsNotM650orLater(SiS_Pr)) {
  3460. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0x7f);
  3461. }
  3462. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3463. if( (!(SiS_IsVAMode(SiS_Pr))) &&
  3464. (!(SiS_CRT2IsLCD(SiS_Pr))) &&
  3465. (!(SiS_IsDualEdge(SiS_Pr))) ) {
  3466. if(custom1) SiS_PanelDelay(SiS_Pr, 2);
  3467. if(!didpwd) {
  3468. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFD);
  3469. }
  3470. if(custom1) SiS_PanelDelay(SiS_Pr, 4);
  3471. }
  3472. if(!custom1) {
  3473. SiS_SetReg(SiS_Pr->SiS_P3c4,0x06,pushax);
  3474. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  3475. if(SiS_IsVAorLCD(SiS_Pr)) {
  3476. SiS_PanelDelayLoop(SiS_Pr, 3, 20);
  3477. }
  3478. }
  3479. }
  3480. }
  3481. #endif /* CONFIG_FB_SIS_315 */
  3482. }
  3483. } else { /* ============ For 301 ================ */
  3484. if(SiS_Pr->ChipType < SIS_315H) {
  3485. #ifdef CONFIG_FB_SIS_300
  3486. if(!(SiS_CR36BIOSWord23b(SiS_Pr))) {
  3487. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x08);
  3488. SiS_PanelDelay(SiS_Pr, 3);
  3489. }
  3490. #endif
  3491. }
  3492. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xDF); /* disable VB */
  3493. SiS_DisplayOff(SiS_Pr);
  3494. if(SiS_Pr->ChipType >= SIS_315H) {
  3495. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x80);
  3496. }
  3497. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF); /* disable lock mode */
  3498. if(SiS_Pr->ChipType >= SIS_315H) {
  3499. temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00);
  3500. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x10);
  3501. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);
  3502. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,temp);
  3503. } else {
  3504. #ifdef CONFIG_FB_SIS_300
  3505. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF); /* disable CRT2 */
  3506. if( (!(SiS_CRT2IsLCD(SiS_Pr))) ||
  3507. (!(SiS_CR36BIOSWord23d(SiS_Pr))) ) {
  3508. SiS_PanelDelay(SiS_Pr, 2);
  3509. SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x04);
  3510. }
  3511. #endif
  3512. }
  3513. }
  3514. } else { /* ============ For LVDS =============*/
  3515. if(SiS_Pr->ChipType < SIS_315H) {
  3516. #ifdef CONFIG_FB_SIS_300 /* 300 series */
  3517. if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) {
  3518. SiS_SetCH700x(SiS_Pr,0x0E,0x09);
  3519. }
  3520. if(SiS_Pr->ChipType == SIS_730) {
  3521. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x11) & 0x08)) {
  3522. SiS_WaitVBRetrace(SiS_Pr);
  3523. }
  3524. if(!(SiS_CR36BIOSWord23b(SiS_Pr))) {
  3525. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x08);
  3526. SiS_PanelDelay(SiS_Pr, 3);
  3527. }
  3528. } else {
  3529. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x11) & 0x08)) {
  3530. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x40)) {
  3531. if(!(SiS_CR36BIOSWord23b(SiS_Pr))) {
  3532. SiS_WaitVBRetrace(SiS_Pr);
  3533. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x06) & 0x1c)) {
  3534. SiS_DisplayOff(SiS_Pr);
  3535. }
  3536. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x08);
  3537. SiS_PanelDelay(SiS_Pr, 3);
  3538. }
  3539. }
  3540. }
  3541. }
  3542. SiS_DisplayOff(SiS_Pr);
  3543. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF);
  3544. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF);
  3545. SiS_UnLockCRT2(SiS_Pr);
  3546. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x01,0x80);
  3547. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x02,0x40);
  3548. if( (!(SiS_CRT2IsLCD(SiS_Pr))) ||
  3549. (!(SiS_CR36BIOSWord23d(SiS_Pr))) ) {
  3550. SiS_PanelDelay(SiS_Pr, 2);
  3551. SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x04);
  3552. }
  3553. #endif /* CONFIG_FB_SIS_300 */
  3554. } else {
  3555. #ifdef CONFIG_FB_SIS_315 /* 315 series */
  3556. if(!(SiS_IsNotM650orLater(SiS_Pr))) {
  3557. /*if(SiS_Pr->ChipType < SIS_340) { */ /* XGI needs this */
  3558. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x4c,~0x18);
  3559. /* } */
  3560. }
  3561. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  3562. if(SiS_Pr->ChipType == SIS_740) {
  3563. temp = SiS_GetCH701x(SiS_Pr,0x61);
  3564. if(temp < 1) {
  3565. SiS_SetCH701x(SiS_Pr,0x76,0xac);
  3566. SiS_SetCH701x(SiS_Pr,0x66,0x00);
  3567. }
  3568. if( (!(SiS_IsDualEdge(SiS_Pr))) ||
  3569. (SiS_IsTVOrYPbPrOrScart(SiS_Pr)) ) {
  3570. SiS_SetCH701x(SiS_Pr,0x49,0x3e);
  3571. }
  3572. }
  3573. if( (!(SiS_IsDualEdge(SiS_Pr))) ||
  3574. (SiS_IsVAMode(SiS_Pr)) ) {
  3575. SiS_Chrontel701xBLOff(SiS_Pr);
  3576. SiS_Chrontel701xOff(SiS_Pr);
  3577. }
  3578. if(SiS_Pr->ChipType != SIS_740) {
  3579. if( (!(SiS_IsDualEdge(SiS_Pr))) ||
  3580. (SiS_IsTVOrYPbPrOrScart(SiS_Pr)) ) {
  3581. SiS_SetCH701x(SiS_Pr,0x49,0x01);
  3582. }
  3583. }
  3584. }
  3585. if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
  3586. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x08);
  3587. SiS_PanelDelay(SiS_Pr, 3);
  3588. }
  3589. if( (SiS_Pr->SiS_IF_DEF_CH70xx == 0) ||
  3590. (!(SiS_IsDualEdge(SiS_Pr))) ||
  3591. (!(SiS_IsTVOrYPbPrOrScart(SiS_Pr))) ) {
  3592. SiS_DisplayOff(SiS_Pr);
  3593. }
  3594. if( (SiS_Pr->SiS_IF_DEF_CH70xx == 0) ||
  3595. (!(SiS_IsDualEdge(SiS_Pr))) ||
  3596. (!(SiS_IsVAMode(SiS_Pr))) ) {
  3597. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x80);
  3598. }
  3599. if(SiS_Pr->ChipType == SIS_740) {
  3600. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0x7f);
  3601. }
  3602. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF);
  3603. if( (SiS_Pr->SiS_IF_DEF_CH70xx == 0) ||
  3604. (!(SiS_IsDualEdge(SiS_Pr))) ||
  3605. (!(SiS_IsVAMode(SiS_Pr))) ) {
  3606. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF);
  3607. }
  3608. if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
  3609. if(SiS_CRT2IsLCD(SiS_Pr)) {
  3610. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xdf);
  3611. if(SiS_Pr->ChipType == SIS_550) {
  3612. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xbf);
  3613. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xef);
  3614. }
  3615. }
  3616. } else {
  3617. if(SiS_Pr->ChipType == SIS_740) {
  3618. if(SiS_IsLCDOrLCDA(SiS_Pr)) {
  3619. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xdf);
  3620. }
  3621. } else if(SiS_IsVAMode(SiS_Pr)) {
  3622. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xdf);
  3623. }
  3624. }
  3625. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  3626. if(SiS_IsDualEdge(SiS_Pr)) {
  3627. /* SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xff); */
  3628. } else {
  3629. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xfb);
  3630. }
  3631. }
  3632. SiS_UnLockCRT2(SiS_Pr);
  3633. if(SiS_Pr->ChipType == SIS_550) {
  3634. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x01,0x80); /* DirectDVD PAL?*/
  3635. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x02,0x40); /* VB clock / 4 ? */
  3636. } else if( (SiS_Pr->SiS_IF_DEF_CH70xx == 0) ||
  3637. (!(SiS_IsDualEdge(SiS_Pr))) ||
  3638. (!(SiS_IsVAMode(SiS_Pr))) ) {
  3639. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0xf7);
  3640. }
  3641. if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
  3642. if(SiS_CRT2IsLCD(SiS_Pr)) {
  3643. if(!(SiS_WeHaveBacklightCtrl(SiS_Pr))) {
  3644. SiS_PanelDelay(SiS_Pr, 2);
  3645. SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x04);
  3646. }
  3647. }
  3648. }
  3649. #endif /* CONFIG_FB_SIS_315 */
  3650. } /* 315 series */
  3651. } /* LVDS */
  3652. }
  3653. /*********************************************/
  3654. /* ENABLE VIDEO BRIDGE */
  3655. /*********************************************/
  3656. /* NEVER use any variables (VBInfo), this will be called
  3657. * from outside the context of a mode switch!
  3658. * MUST call getVBType before calling this
  3659. */
  3660. static
  3661. void
  3662. SiS_EnableBridge(struct SiS_Private *SiS_Pr)
  3663. {
  3664. unsigned short temp=0, tempah;
  3665. #ifdef CONFIG_FB_SIS_315
  3666. unsigned short temp1, pushax=0;
  3667. bool delaylong = false;
  3668. #endif
  3669. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  3670. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) { /* ====== For 301B et al ====== */
  3671. if(SiS_Pr->ChipType < SIS_315H) {
  3672. #ifdef CONFIG_FB_SIS_300 /* 300 series */
  3673. if(SiS_CRT2IsLCD(SiS_Pr)) {
  3674. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3675. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x02);
  3676. } else if(SiS_Pr->SiS_VBType & VB_NoLCD) {
  3677. SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x00);
  3678. }
  3679. if(SiS_Pr->SiS_VBType & (VB_SISLVDS | VB_NoLCD)) {
  3680. if(!(SiS_CR36BIOSWord23d(SiS_Pr))) {
  3681. SiS_PanelDelay(SiS_Pr, 0);
  3682. }
  3683. }
  3684. }
  3685. if((SiS_Pr->SiS_VBType & VB_NoLCD) &&
  3686. (SiS_CRT2IsLCD(SiS_Pr))) {
  3687. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20); /* Enable CRT2 */
  3688. SiS_DisplayOn(SiS_Pr);
  3689. SiS_UnLockCRT2(SiS_Pr);
  3690. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x02,0xBF);
  3691. if(SiS_BridgeInSlavemode(SiS_Pr)) {
  3692. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x01,0x1F);
  3693. } else {
  3694. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x01,0x1F,0x40);
  3695. }
  3696. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x40)) {
  3697. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x16) & 0x10)) {
  3698. if(!(SiS_CR36BIOSWord23b(SiS_Pr))) {
  3699. SiS_PanelDelay(SiS_Pr, 1);
  3700. }
  3701. SiS_WaitVBRetrace(SiS_Pr);
  3702. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x00);
  3703. }
  3704. }
  3705. } else {
  3706. temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x32) & 0xDF; /* lock mode */
  3707. if(SiS_BridgeInSlavemode(SiS_Pr)) {
  3708. tempah = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  3709. if(!(tempah & SetCRT2ToRAMDAC)) temp |= 0x20;
  3710. }
  3711. SiS_SetReg(SiS_Pr->SiS_P3c4,0x32,temp);
  3712. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);
  3713. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x00,0x1F,0x20); /* enable VB processor */
  3714. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x1F,0xC0);
  3715. SiS_DisplayOn(SiS_Pr);
  3716. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3717. if(SiS_CRT2IsLCD(SiS_Pr)) {
  3718. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x16) & 0x10)) {
  3719. if(!(SiS_CR36BIOSWord23b(SiS_Pr))) {
  3720. SiS_PanelDelay(SiS_Pr, 1);
  3721. }
  3722. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x01);
  3723. }
  3724. }
  3725. }
  3726. }
  3727. #endif /* CONFIG_FB_SIS_300 */
  3728. } else {
  3729. #ifdef CONFIG_FB_SIS_315 /* 315 series */
  3730. #ifdef SET_EMI
  3731. unsigned char r30=0, r31=0, r32=0, r33=0, cr36=0;
  3732. int didpwd = 0;
  3733. /* unsigned short emidelay=0; */
  3734. #endif
  3735. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3736. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1f,0xef);
  3737. #ifdef SET_EMI
  3738. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  3739. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
  3740. }
  3741. #endif
  3742. }
  3743. if(!(SiS_IsNotM650orLater(SiS_Pr))) {
  3744. /*if(SiS_Pr->ChipType < SIS_340) { */
  3745. tempah = 0x10;
  3746. if(SiS_LCDAEnabled(SiS_Pr)) {
  3747. if(SiS_TVEnabled(SiS_Pr)) tempah = 0x18;
  3748. else tempah = 0x08;
  3749. }
  3750. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x4c,tempah);
  3751. /*}*/
  3752. }
  3753. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3754. SiS_SetRegByte(SiS_Pr->SiS_P3c6,0x00);
  3755. SiS_DisplayOff(SiS_Pr);
  3756. pushax = SiS_GetReg(SiS_Pr->SiS_P3c4,0x06);
  3757. if(IS_SIS740) {
  3758. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x06,0xE3);
  3759. }
  3760. didpwd = SiS_HandlePWD(SiS_Pr);
  3761. if(SiS_IsVAorLCD(SiS_Pr)) {
  3762. if(!didpwd) {
  3763. if(!(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x26) & 0x02)) {
  3764. SiS_PanelDelayLoop(SiS_Pr, 3, 2);
  3765. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x02);
  3766. SiS_PanelDelayLoop(SiS_Pr, 3, 2);
  3767. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  3768. SiS_GenericDelay(SiS_Pr, 17664);
  3769. }
  3770. }
  3771. } else {
  3772. SiS_PanelDelayLoop(SiS_Pr, 3, 2);
  3773. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  3774. SiS_GenericDelay(SiS_Pr, 17664);
  3775. }
  3776. }
  3777. }
  3778. if(!(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & 0x40)) {
  3779. SiS_PanelDelayLoop(SiS_Pr, 3, 10);
  3780. delaylong = true;
  3781. }
  3782. }
  3783. if(!(SiS_IsVAMode(SiS_Pr))) {
  3784. temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x32) & 0xDF;
  3785. if(SiS_BridgeInSlavemode(SiS_Pr)) {
  3786. tempah = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  3787. if(!(tempah & SetCRT2ToRAMDAC)) {
  3788. if(!(SiS_LCDAEnabled(SiS_Pr))) temp |= 0x20;
  3789. }
  3790. }
  3791. SiS_SetReg(SiS_Pr->SiS_P3c4,0x32,temp);
  3792. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20); /* enable CRT2 */
  3793. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0x7f);
  3794. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2e,0x80);
  3795. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3796. SiS_PanelDelay(SiS_Pr, 2);
  3797. }
  3798. } else {
  3799. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1e,0x20);
  3800. }
  3801. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x00,0x1f,0x20);
  3802. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2e,0x80);
  3803. if(SiS_Pr->SiS_VBType & VB_SISPOWER) {
  3804. if( (SiS_LCDAEnabled(SiS_Pr)) ||
  3805. (SiS_CRT2IsLCD(SiS_Pr)) ) {
  3806. /* Enable "LVDS PLL power on" (even on 301C) */
  3807. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x2a,0x7f);
  3808. /* Enable "LVDS Driver Power on" (even on 301C) */
  3809. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x7f);
  3810. }
  3811. }
  3812. tempah = 0xc0;
  3813. if(SiS_IsDualEdge(SiS_Pr)) {
  3814. tempah = 0x80;
  3815. if(!(SiS_IsVAMode(SiS_Pr))) tempah = 0x40;
  3816. }
  3817. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x1F,tempah);
  3818. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3819. SiS_PanelDelay(SiS_Pr, 2);
  3820. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x1f,0x10);
  3821. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2e,0x80);
  3822. if(SiS_Pr->SiS_CustomT != CUT_CLEVO1400) {
  3823. #ifdef SET_EMI
  3824. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  3825. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
  3826. SiS_GenericDelay(SiS_Pr, 2048);
  3827. }
  3828. #endif
  3829. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x27,0x0c);
  3830. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  3831. #ifdef SET_EMI
  3832. cr36 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36);
  3833. if(SiS_Pr->SiS_ROMNew) {
  3834. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  3835. unsigned short romptr = GetLCDStructPtr661_2(SiS_Pr);
  3836. if(romptr) {
  3837. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x30,0x20); /* Reset */
  3838. SiS_Pr->EMI_30 = 0;
  3839. SiS_Pr->EMI_31 = ROMAddr[romptr + SiS_Pr->SiS_EMIOffset + 0];
  3840. SiS_Pr->EMI_32 = ROMAddr[romptr + SiS_Pr->SiS_EMIOffset + 1];
  3841. SiS_Pr->EMI_33 = ROMAddr[romptr + SiS_Pr->SiS_EMIOffset + 2];
  3842. if(ROMAddr[romptr + 1] & 0x10) SiS_Pr->EMI_30 = 0x40;
  3843. /* emidelay = SISGETROMW((romptr + 0x22)); */
  3844. SiS_Pr->HaveEMI = SiS_Pr->HaveEMILCD = SiS_Pr->OverruleEMI = true;
  3845. }
  3846. }
  3847. /* (P4_30|0x40) */
  3848. /* Compal 1400x1050: 0x05, 0x60, 0x00 YES (1.10.7w; CR36=69) */
  3849. /* Compal 1400x1050: 0x0d, 0x70, 0x40 YES (1.10.7x; CR36=69) */
  3850. /* Acer 1280x1024: 0x12, 0xd0, 0x6b NO (1.10.9k; CR36=73) */
  3851. /* Compaq 1280x1024: 0x0d, 0x70, 0x6b YES (1.12.04b; CR36=03) */
  3852. /* Clevo 1024x768: 0x05, 0x60, 0x33 NO (1.10.8e; CR36=12, DL!) */
  3853. /* Clevo 1024x768: 0x0d, 0x70, 0x40 (if type == 3) YES (1.10.8y; CR36=?2) */
  3854. /* Clevo 1024x768: 0x05, 0x60, 0x33 (if type != 3) YES (1.10.8y; CR36=?2) */
  3855. /* Asus 1024x768: ? ? (1.10.8o; CR36=?2) */
  3856. /* Asus 1024x768: 0x08, 0x10, 0x3c (problematic) YES (1.10.8q; CR36=22) */
  3857. if(SiS_Pr->HaveEMI) {
  3858. r30 = SiS_Pr->EMI_30; r31 = SiS_Pr->EMI_31;
  3859. r32 = SiS_Pr->EMI_32; r33 = SiS_Pr->EMI_33;
  3860. } else {
  3861. r30 = 0;
  3862. }
  3863. /* EMI_30 is read at driver start; however, the BIOS sets this
  3864. * (if it is used) only if the LCD is in use. In case we caught
  3865. * the machine while on TV output, this bit is not set and we
  3866. * don't know if it should be set - hence our detection is wrong.
  3867. * Work-around this here:
  3868. */
  3869. if((!SiS_Pr->HaveEMI) || (!SiS_Pr->HaveEMILCD)) {
  3870. switch((cr36 & 0x0f)) {
  3871. case 2:
  3872. r30 |= 0x40;
  3873. if(SiS_Pr->SiS_CustomT == CUT_CLEVO1024) r30 &= ~0x40;
  3874. if(!SiS_Pr->HaveEMI) {
  3875. r31 = 0x05; r32 = 0x60; r33 = 0x33;
  3876. if((cr36 & 0xf0) == 0x30) {
  3877. r31 = 0x0d; r32 = 0x70; r33 = 0x40;
  3878. }
  3879. }
  3880. break;
  3881. case 3: /* 1280x1024 */
  3882. if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) r30 |= 0x40;
  3883. if(!SiS_Pr->HaveEMI) {
  3884. r31 = 0x12; r32 = 0xd0; r33 = 0x6b;
  3885. if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) {
  3886. r31 = 0x0d; r32 = 0x70; r33 = 0x6b;
  3887. }
  3888. }
  3889. break;
  3890. case 9: /* 1400x1050 */
  3891. r30 |= 0x40;
  3892. if(!SiS_Pr->HaveEMI) {
  3893. r31 = 0x05; r32 = 0x60; r33 = 0x00;
  3894. if(SiS_Pr->SiS_CustomT == CUT_COMPAL1400_2) {
  3895. r31 = 0x0d; r32 = 0x70; r33 = 0x40; /* BIOS values */
  3896. }
  3897. }
  3898. break;
  3899. case 11: /* 1600x1200 - unknown */
  3900. r30 |= 0x40;
  3901. if(!SiS_Pr->HaveEMI) {
  3902. r31 = 0x05; r32 = 0x60; r33 = 0x00;
  3903. }
  3904. }
  3905. }
  3906. /* BIOS values don't work so well sometimes */
  3907. if(!SiS_Pr->OverruleEMI) {
  3908. #ifdef COMPAL_HACK
  3909. if(SiS_Pr->SiS_CustomT == CUT_COMPAL1400_2) {
  3910. if((cr36 & 0x0f) == 0x09) {
  3911. r30 = 0x60; r31 = 0x05; r32 = 0x60; r33 = 0x00;
  3912. }
  3913. }
  3914. #endif
  3915. #ifdef COMPAQ_HACK
  3916. if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) {
  3917. if((cr36 & 0x0f) == 0x03) {
  3918. r30 = 0x20; r31 = 0x12; r32 = 0xd0; r33 = 0x6b;
  3919. }
  3920. }
  3921. #endif
  3922. #ifdef ASUS_HACK
  3923. if(SiS_Pr->SiS_CustomT == CUT_ASUSA2H_2) {
  3924. if((cr36 & 0x0f) == 0x02) {
  3925. /* r30 = 0x60; r31 = 0x05; r32 = 0x60; r33 = 0x33; */ /* rev 2 */
  3926. /* r30 = 0x20; r31 = 0x05; r32 = 0x60; r33 = 0x33; */ /* rev 3 */
  3927. /* r30 = 0x60; r31 = 0x0d; r32 = 0x70; r33 = 0x40; */ /* rev 4 */
  3928. /* r30 = 0x20; r31 = 0x0d; r32 = 0x70; r33 = 0x40; */ /* rev 5 */
  3929. }
  3930. }
  3931. #endif
  3932. }
  3933. if(!(SiS_Pr->OverruleEMI && (!r30) && (!r31) && (!r32) && (!r33))) {
  3934. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x30,0x20); /* Reset */
  3935. SiS_GenericDelay(SiS_Pr, 2048);
  3936. }
  3937. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x31,r31);
  3938. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x32,r32);
  3939. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x33,r33);
  3940. #endif /* SET_EMI */
  3941. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x34,0x10);
  3942. #ifdef SET_EMI
  3943. if( (SiS_LCDAEnabled(SiS_Pr)) ||
  3944. (SiS_CRT2IsLCD(SiS_Pr)) ) {
  3945. if(r30 & 0x40) {
  3946. /*SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x2a,0x80);*/
  3947. SiS_PanelDelayLoop(SiS_Pr, 3, 5);
  3948. if(delaylong) {
  3949. SiS_PanelDelayLoop(SiS_Pr, 3, 5);
  3950. delaylong = false;
  3951. }
  3952. SiS_WaitVBRetrace(SiS_Pr);
  3953. SiS_WaitVBRetrace(SiS_Pr);
  3954. if(SiS_Pr->SiS_CustomT == CUT_ASUSA2H_2) {
  3955. SiS_GenericDelay(SiS_Pr, 1280);
  3956. }
  3957. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x30,0x40); /* Enable */
  3958. /*SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x2a,0x7f);*/
  3959. }
  3960. }
  3961. #endif
  3962. }
  3963. }
  3964. if(!(SiS_WeHaveBacklightCtrl(SiS_Pr))) {
  3965. if(SiS_IsVAorLCD(SiS_Pr)) {
  3966. SiS_PanelDelayLoop(SiS_Pr, 3, 10);
  3967. if(delaylong) {
  3968. SiS_PanelDelayLoop(SiS_Pr, 3, 10);
  3969. }
  3970. SiS_WaitVBRetrace(SiS_Pr);
  3971. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  3972. SiS_GenericDelay(SiS_Pr, 2048);
  3973. SiS_WaitVBRetrace(SiS_Pr);
  3974. }
  3975. if(!didpwd) {
  3976. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x01);
  3977. } else {
  3978. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x03);
  3979. }
  3980. }
  3981. }
  3982. SiS_SetReg(SiS_Pr->SiS_P3c4,0x06,pushax);
  3983. SiS_DisplayOn(SiS_Pr);
  3984. SiS_SetRegByte(SiS_Pr->SiS_P3c6,0xff);
  3985. }
  3986. if(!(SiS_WeHaveBacklightCtrl(SiS_Pr))) {
  3987. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x00,0x7f);
  3988. }
  3989. #endif /* CONFIG_FB_SIS_315 */
  3990. }
  3991. } else { /* ============ For 301 ================ */
  3992. if(SiS_Pr->ChipType < SIS_315H) {
  3993. if(SiS_CRT2IsLCD(SiS_Pr)) {
  3994. SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x00);
  3995. SiS_PanelDelay(SiS_Pr, 0);
  3996. }
  3997. }
  3998. temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x32) & 0xDF; /* lock mode */
  3999. if(SiS_BridgeInSlavemode(SiS_Pr)) {
  4000. tempah = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  4001. if(!(tempah & SetCRT2ToRAMDAC)) temp |= 0x20;
  4002. }
  4003. SiS_SetReg(SiS_Pr->SiS_P3c4,0x32,temp);
  4004. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20); /* enable CRT2 */
  4005. if(SiS_Pr->ChipType >= SIS_315H) {
  4006. temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x2E);
  4007. if(!(temp & 0x80)) {
  4008. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2E,0x80); /* BVBDOENABLE=1 */
  4009. }
  4010. }
  4011. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x00,0x1F,0x20); /* enable VB processor */
  4012. SiS_VBLongWait(SiS_Pr);
  4013. SiS_DisplayOn(SiS_Pr);
  4014. if(SiS_Pr->ChipType >= SIS_315H) {
  4015. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x00,0x7f);
  4016. }
  4017. SiS_VBLongWait(SiS_Pr);
  4018. if(SiS_Pr->ChipType < SIS_315H) {
  4019. if(SiS_CRT2IsLCD(SiS_Pr)) {
  4020. SiS_PanelDelay(SiS_Pr, 1);
  4021. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x00);
  4022. }
  4023. }
  4024. }
  4025. } else { /* =================== For LVDS ================== */
  4026. if(SiS_Pr->ChipType < SIS_315H) {
  4027. #ifdef CONFIG_FB_SIS_300 /* 300 series */
  4028. if(SiS_CRT2IsLCD(SiS_Pr)) {
  4029. if(SiS_Pr->ChipType == SIS_730) {
  4030. SiS_PanelDelay(SiS_Pr, 1);
  4031. SiS_PanelDelay(SiS_Pr, 1);
  4032. SiS_PanelDelay(SiS_Pr, 1);
  4033. }
  4034. SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x00);
  4035. if(!(SiS_CR36BIOSWord23d(SiS_Pr))) {
  4036. SiS_PanelDelay(SiS_Pr, 0);
  4037. }
  4038. }
  4039. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);
  4040. SiS_DisplayOn(SiS_Pr);
  4041. SiS_UnLockCRT2(SiS_Pr);
  4042. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x02,0xBF);
  4043. if(SiS_BridgeInSlavemode(SiS_Pr)) {
  4044. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x01,0x1F);
  4045. } else {
  4046. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x01,0x1F,0x40);
  4047. }
  4048. if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) {
  4049. if(!(SiS_CRT2IsLCD(SiS_Pr))) {
  4050. SiS_WaitVBRetrace(SiS_Pr);
  4051. SiS_SetCH700x(SiS_Pr,0x0E,0x0B);
  4052. }
  4053. }
  4054. if(SiS_CRT2IsLCD(SiS_Pr)) {
  4055. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x40)) {
  4056. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x16) & 0x10)) {
  4057. if(!(SiS_CR36BIOSWord23b(SiS_Pr))) {
  4058. SiS_PanelDelay(SiS_Pr, 1);
  4059. SiS_PanelDelay(SiS_Pr, 1);
  4060. }
  4061. SiS_WaitVBRetrace(SiS_Pr);
  4062. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x00);
  4063. }
  4064. }
  4065. }
  4066. #endif /* CONFIG_FB_SIS_300 */
  4067. } else {
  4068. #ifdef CONFIG_FB_SIS_315 /* 315 series */
  4069. if(!(SiS_IsNotM650orLater(SiS_Pr))) {
  4070. /*if(SiS_Pr->ChipType < SIS_340) {*/ /* XGI needs this */
  4071. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x4c,0x18);
  4072. /*}*/
  4073. }
  4074. if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
  4075. if(SiS_CRT2IsLCD(SiS_Pr)) {
  4076. SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x00);
  4077. SiS_PanelDelay(SiS_Pr, 0);
  4078. }
  4079. }
  4080. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);
  4081. SiS_UnLockCRT2(SiS_Pr);
  4082. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0xf7);
  4083. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  4084. temp = SiS_GetCH701x(SiS_Pr,0x66);
  4085. temp &= 0x20;
  4086. SiS_Chrontel701xBLOff(SiS_Pr);
  4087. }
  4088. if(SiS_Pr->ChipType != SIS_550) {
  4089. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0x7f);
  4090. }
  4091. if(SiS_Pr->ChipType == SIS_740) {
  4092. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  4093. if(SiS_IsLCDOrLCDA(SiS_Pr)) {
  4094. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x20);
  4095. }
  4096. }
  4097. }
  4098. temp1 = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x2E);
  4099. if(!(temp1 & 0x80)) {
  4100. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2E,0x80);
  4101. }
  4102. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  4103. if(temp) {
  4104. SiS_Chrontel701xBLOn(SiS_Pr);
  4105. }
  4106. }
  4107. if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
  4108. if(SiS_CRT2IsLCD(SiS_Pr)) {
  4109. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x20);
  4110. if(SiS_Pr->ChipType == SIS_550) {
  4111. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x40);
  4112. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x10);
  4113. }
  4114. }
  4115. } else if(SiS_IsVAMode(SiS_Pr)) {
  4116. if(SiS_Pr->ChipType != SIS_740) {
  4117. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x20);
  4118. }
  4119. }
  4120. if(!(SiS_WeHaveBacklightCtrl(SiS_Pr))) {
  4121. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x00,0x7f);
  4122. }
  4123. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  4124. if(SiS_IsTVOrYPbPrOrScart(SiS_Pr)) {
  4125. SiS_Chrontel701xOn(SiS_Pr);
  4126. }
  4127. if( (SiS_IsVAMode(SiS_Pr)) ||
  4128. (SiS_IsLCDOrLCDA(SiS_Pr)) ) {
  4129. SiS_ChrontelDoSomething1(SiS_Pr);
  4130. }
  4131. }
  4132. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  4133. if(!(SiS_WeHaveBacklightCtrl(SiS_Pr))) {
  4134. if( (SiS_IsVAMode(SiS_Pr)) ||
  4135. (SiS_IsLCDOrLCDA(SiS_Pr)) ) {
  4136. SiS_Chrontel701xBLOn(SiS_Pr);
  4137. SiS_ChrontelInitTVVSync(SiS_Pr);
  4138. }
  4139. }
  4140. } else if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
  4141. if(!(SiS_WeHaveBacklightCtrl(SiS_Pr))) {
  4142. if(SiS_CRT2IsLCD(SiS_Pr)) {
  4143. SiS_PanelDelay(SiS_Pr, 1);
  4144. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x00);
  4145. }
  4146. }
  4147. }
  4148. #endif /* CONFIG_FB_SIS_315 */
  4149. } /* 310 series */
  4150. } /* LVDS */
  4151. }
  4152. /*********************************************/
  4153. /* SET PART 1 REGISTER GROUP */
  4154. /*********************************************/
  4155. /* Set CRT2 OFFSET / PITCH */
  4156. static void
  4157. SiS_SetCRT2Offset(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  4158. unsigned short RRTI)
  4159. {
  4160. unsigned short offset;
  4161. unsigned char temp;
  4162. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) return;
  4163. offset = SiS_GetOffset(SiS_Pr,ModeNo,ModeIdIndex,RRTI);
  4164. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x07,(offset & 0xFF));
  4165. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x09,(offset >> 8));
  4166. temp = (unsigned char)(((offset >> 3) & 0xFF) + 1);
  4167. if(offset & 0x07) temp++;
  4168. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x03,temp);
  4169. }
  4170. /* Set CRT2 sync and PanelLink mode */
  4171. static void
  4172. SiS_SetCRT2Sync(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short RefreshRateTableIndex)
  4173. {
  4174. unsigned short tempah=0, tempbl, infoflag;
  4175. tempbl = 0xC0;
  4176. if(SiS_Pr->UseCustomMode) {
  4177. infoflag = SiS_Pr->CInfoFlag;
  4178. } else {
  4179. infoflag = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
  4180. }
  4181. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { /* LVDS */
  4182. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  4183. tempah = 0;
  4184. } else if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && (SiS_Pr->SiS_LCDInfo & LCDSync)) {
  4185. tempah = SiS_Pr->SiS_LCDInfo;
  4186. } else tempah = infoflag >> 8;
  4187. tempah &= 0xC0;
  4188. tempah |= 0x20;
  4189. if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10;
  4190. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  4191. if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) ||
  4192. (SiS_Pr->SiS_CustomT == CUT_BARCO1024)) {
  4193. tempah |= 0xf0;
  4194. }
  4195. if( (SiS_Pr->SiS_IF_DEF_FSTN) ||
  4196. (SiS_Pr->SiS_IF_DEF_DSTN) ||
  4197. (SiS_Pr->SiS_IF_DEF_TRUMPION) ||
  4198. (SiS_Pr->SiS_CustomT == CUT_PANEL848) ||
  4199. (SiS_Pr->SiS_CustomT == CUT_PANEL856) ) {
  4200. tempah |= 0x30;
  4201. }
  4202. if( (SiS_Pr->SiS_IF_DEF_FSTN) ||
  4203. (SiS_Pr->SiS_IF_DEF_DSTN) ) {
  4204. tempah &= ~0xc0;
  4205. }
  4206. }
  4207. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  4208. if(SiS_Pr->ChipType >= SIS_315H) {
  4209. tempah >>= 3;
  4210. tempah &= 0x18;
  4211. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,0xE7,tempah);
  4212. /* Don't care about 12/18/24 bit mode - TV is via VGA, not PL */
  4213. } else {
  4214. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,0xe0);
  4215. }
  4216. } else {
  4217. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah);
  4218. }
  4219. } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
  4220. if(SiS_Pr->ChipType < SIS_315H) {
  4221. #ifdef CONFIG_FB_SIS_300 /* ---- 300 series --- */
  4222. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) { /* 630 - 301B(-DH) */
  4223. tempah = infoflag >> 8;
  4224. tempbl = 0;
  4225. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  4226. if(SiS_Pr->SiS_LCDInfo & LCDSync) {
  4227. tempah = SiS_Pr->SiS_LCDInfo;
  4228. tempbl = (tempah >> 6) & 0x03;
  4229. }
  4230. }
  4231. tempah &= 0xC0;
  4232. tempah |= 0x20;
  4233. if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10;
  4234. tempah |= 0xc0;
  4235. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah);
  4236. if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && (!(SiS_Pr->SiS_VBType & VB_NoLCD))) {
  4237. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1a,0xf0,tempbl);
  4238. }
  4239. } else { /* 630 - 301 */
  4240. tempah = ((infoflag >> 8) & 0xc0) | 0x20;
  4241. if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10;
  4242. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah);
  4243. }
  4244. #endif /* CONFIG_FB_SIS_300 */
  4245. } else {
  4246. #ifdef CONFIG_FB_SIS_315 /* ------- 315 series ------ */
  4247. if(SiS_Pr->SiS_VBType & VB_SISLVDS) { /* 315 - LVDS */
  4248. tempbl = 0;
  4249. if((SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) &&
  4250. (SiS_Pr->SiS_LCDResInfo == Panel_1280x1024)) {
  4251. tempah = infoflag >> 8;
  4252. if(SiS_Pr->SiS_LCDInfo & LCDSync) {
  4253. tempbl = ((SiS_Pr->SiS_LCDInfo & 0xc0) >> 6);
  4254. }
  4255. } else if((SiS_Pr->SiS_CustomT == CUT_CLEVO1400) &&
  4256. (SiS_Pr->SiS_LCDResInfo == Panel_1400x1050)) {
  4257. tempah = infoflag >> 8;
  4258. tempbl = 0x03;
  4259. } else {
  4260. tempah = SiS_GetReg(SiS_Pr->SiS_P3d4,0x37);
  4261. tempbl = (tempah >> 6) & 0x03;
  4262. tempbl |= 0x08;
  4263. if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempbl |= 0x04;
  4264. }
  4265. tempah &= 0xC0;
  4266. tempah |= 0x20;
  4267. if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10;
  4268. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) tempah |= 0xc0;
  4269. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah);
  4270. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  4271. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  4272. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1a,0xf0,tempbl);
  4273. }
  4274. }
  4275. } else { /* 315 - TMDS */
  4276. tempah = tempbl = infoflag >> 8;
  4277. if(!SiS_Pr->UseCustomMode) {
  4278. tempbl = 0;
  4279. if((SiS_Pr->SiS_VBType & VB_SIS30xC) && (SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) {
  4280. if(ModeNo <= 0x13) {
  4281. tempah = SiS_GetRegByte((SiS_Pr->SiS_P3ca+0x02));
  4282. }
  4283. }
  4284. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4285. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  4286. if(SiS_Pr->SiS_LCDInfo & LCDSync) {
  4287. tempah = SiS_Pr->SiS_LCDInfo;
  4288. tempbl = (tempah >> 6) & 0x03;
  4289. }
  4290. }
  4291. }
  4292. }
  4293. tempah &= 0xC0;
  4294. tempah |= 0x20;
  4295. if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10;
  4296. if(SiS_Pr->SiS_VBType & VB_NoLCD) {
  4297. /* Imitate BIOS bug */
  4298. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) tempah |= 0xc0;
  4299. }
  4300. if((SiS_Pr->SiS_VBType & VB_SIS30xC) && (SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) {
  4301. tempah >>= 3;
  4302. tempah &= 0x18;
  4303. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,0xe7,tempah);
  4304. } else {
  4305. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah);
  4306. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  4307. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  4308. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1a,0xf0,tempbl);
  4309. }
  4310. }
  4311. }
  4312. }
  4313. #endif /* CONFIG_FB_SIS_315 */
  4314. }
  4315. }
  4316. }
  4317. /* Set CRT2 FIFO on 300/540/630/730 */
  4318. #ifdef CONFIG_FB_SIS_300
  4319. static void
  4320. SiS_SetCRT2FIFO_300(struct SiS_Private *SiS_Pr,unsigned short ModeNo)
  4321. {
  4322. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  4323. unsigned short temp, index, modeidindex, refreshratetableindex;
  4324. unsigned short VCLK = 0, MCLK, colorth = 0, data2 = 0;
  4325. unsigned short tempbx, tempcl, CRT1ModeNo, CRT2ModeNo, SelectRate_backup;
  4326. unsigned int data, pci50, pciA0;
  4327. static const unsigned char colortharray[] = {
  4328. 1, 1, 2, 2, 3, 4
  4329. };
  4330. SelectRate_backup = SiS_Pr->SiS_SelectCRT2Rate;
  4331. if(!SiS_Pr->CRT1UsesCustomMode) {
  4332. CRT1ModeNo = SiS_Pr->SiS_CRT1Mode; /* get CRT1 ModeNo */
  4333. SiS_SearchModeID(SiS_Pr, &CRT1ModeNo, &modeidindex);
  4334. SiS_Pr->SiS_SetFlag &= (~ProgrammingCRT2);
  4335. SiS_Pr->SiS_SelectCRT2Rate = 0;
  4336. refreshratetableindex = SiS_GetRatePtr(SiS_Pr, CRT1ModeNo, modeidindex);
  4337. if(CRT1ModeNo >= 0x13) {
  4338. /* Get VCLK */
  4339. index = SiS_GetRefCRTVCLK(SiS_Pr, refreshratetableindex, SiS_Pr->SiS_UseWide);
  4340. VCLK = SiS_Pr->SiS_VCLKData[index].CLOCK;
  4341. /* Get colordepth */
  4342. colorth = SiS_GetColorDepth(SiS_Pr,CRT1ModeNo,modeidindex) >> 1;
  4343. if(!colorth) colorth++;
  4344. }
  4345. } else {
  4346. CRT1ModeNo = 0xfe;
  4347. /* Get VCLK */
  4348. VCLK = SiS_Pr->CSRClock_CRT1;
  4349. /* Get color depth */
  4350. colorth = colortharray[((SiS_Pr->CModeFlag_CRT1 & ModeTypeMask) - 2)];
  4351. }
  4352. if(CRT1ModeNo >= 0x13) {
  4353. /* Get MCLK */
  4354. if(SiS_Pr->ChipType == SIS_300) {
  4355. index = SiS_GetReg(SiS_Pr->SiS_P3c4,0x3A);
  4356. } else {
  4357. index = SiS_GetReg(SiS_Pr->SiS_P3c4,0x1A);
  4358. }
  4359. index &= 0x07;
  4360. MCLK = SiS_Pr->SiS_MCLKData_0[index].CLOCK;
  4361. temp = ((SiS_GetReg(SiS_Pr->SiS_P3c4,0x14) >> 6) & 0x03) << 1;
  4362. if(!temp) temp++;
  4363. temp <<= 2;
  4364. data2 = temp - ((colorth * VCLK) / MCLK);
  4365. temp = (28 * 16) % data2;
  4366. data2 = (28 * 16) / data2;
  4367. if(temp) data2++;
  4368. if(SiS_Pr->ChipType == SIS_300) {
  4369. SiS_GetFIFOThresholdIndex300(SiS_Pr, &tempbx, &tempcl);
  4370. data = SiS_GetFIFOThresholdB300(tempbx, tempcl);
  4371. } else {
  4372. pci50 = sisfb_read_nbridge_pci_dword(SiS_Pr, 0x50);
  4373. pciA0 = sisfb_read_nbridge_pci_dword(SiS_Pr, 0xa0);
  4374. if(SiS_Pr->ChipType == SIS_730) {
  4375. index = (unsigned short)(((pciA0 >> 28) & 0x0f) * 3);
  4376. index += (unsigned short)(((pci50 >> 9)) & 0x03);
  4377. /* BIOS BUG (2.04.5d, 2.04.6a use ah here, which is unset!) */
  4378. index = 0; /* -- do it like the BIOS anyway... */
  4379. } else {
  4380. pci50 >>= 24;
  4381. pciA0 >>= 24;
  4382. index = (pci50 >> 1) & 0x07;
  4383. if(pci50 & 0x01) index += 6;
  4384. if(!(pciA0 & 0x01)) index += 24;
  4385. if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x14) & 0x80) index += 12;
  4386. }
  4387. data = SiS_GetLatencyFactor630(SiS_Pr, index) + 15;
  4388. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x14) & 0x80)) data += 5;
  4389. }
  4390. data += data2; /* CRT1 Request Period */
  4391. SiS_Pr->SiS_SetFlag |= ProgrammingCRT2;
  4392. SiS_Pr->SiS_SelectCRT2Rate = SelectRate_backup;
  4393. if(!SiS_Pr->UseCustomMode) {
  4394. CRT2ModeNo = ModeNo;
  4395. SiS_SearchModeID(SiS_Pr, &CRT2ModeNo, &modeidindex);
  4396. refreshratetableindex = SiS_GetRatePtr(SiS_Pr, CRT2ModeNo, modeidindex);
  4397. /* Get VCLK */
  4398. index = SiS_GetVCLK2Ptr(SiS_Pr, CRT2ModeNo, modeidindex, refreshratetableindex);
  4399. VCLK = SiS_Pr->SiS_VCLKData[index].CLOCK;
  4400. if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) || (SiS_Pr->SiS_CustomT == CUT_BARCO1024)) {
  4401. if(SiS_Pr->SiS_UseROM) {
  4402. if(ROMAddr[0x220] & 0x01) {
  4403. VCLK = ROMAddr[0x229] | (ROMAddr[0x22a] << 8);
  4404. }
  4405. }
  4406. }
  4407. } else {
  4408. /* Get VCLK */
  4409. CRT2ModeNo = 0xfe;
  4410. VCLK = SiS_Pr->CSRClock;
  4411. }
  4412. /* Get colordepth */
  4413. colorth = SiS_GetColorDepth(SiS_Pr,CRT2ModeNo,modeidindex) >> 1;
  4414. if(!colorth) colorth++;
  4415. data = data * VCLK * colorth;
  4416. temp = data % (MCLK << 4);
  4417. data = data / (MCLK << 4);
  4418. if(temp) data++;
  4419. if(data < 6) data = 6;
  4420. else if(data > 0x14) data = 0x14;
  4421. if(SiS_Pr->ChipType == SIS_300) {
  4422. temp = 0x16;
  4423. if((data <= 0x0f) || (SiS_Pr->SiS_LCDResInfo == Panel_1280x1024))
  4424. temp = 0x13;
  4425. } else {
  4426. temp = 0x16;
  4427. if(( (SiS_Pr->ChipType == SIS_630) ||
  4428. (SiS_Pr->ChipType == SIS_730) ) &&
  4429. (SiS_Pr->ChipRevision >= 0x30))
  4430. temp = 0x1b;
  4431. }
  4432. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x01,0xe0,temp);
  4433. if((SiS_Pr->ChipType == SIS_630) &&
  4434. (SiS_Pr->ChipRevision >= 0x30)) {
  4435. if(data > 0x13) data = 0x13;
  4436. }
  4437. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x02,0xe0,data);
  4438. } else { /* If mode <= 0x13, we just restore everything */
  4439. SiS_Pr->SiS_SetFlag |= ProgrammingCRT2;
  4440. SiS_Pr->SiS_SelectCRT2Rate = SelectRate_backup;
  4441. }
  4442. }
  4443. #endif
  4444. /* Set CRT2 FIFO on 315/330 series */
  4445. #ifdef CONFIG_FB_SIS_315
  4446. static void
  4447. SiS_SetCRT2FIFO_310(struct SiS_Private *SiS_Pr)
  4448. {
  4449. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x01,0x3B);
  4450. if( (SiS_Pr->ChipType == SIS_760) &&
  4451. (SiS_Pr->SiS_SysFlags & SF_760LFB) &&
  4452. (SiS_Pr->SiS_ModeType == Mode32Bpp) &&
  4453. (SiS_Pr->SiS_VGAHDE >= 1280) &&
  4454. (SiS_Pr->SiS_VGAVDE >= 1024) ) {
  4455. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2f,0x03);
  4456. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x01,0x3b);
  4457. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x4d,0xc0);
  4458. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2f,0x01);
  4459. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x4d,0xc0);
  4460. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x02,0x6e);
  4461. } else {
  4462. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x02,~0x3f,0x04);
  4463. }
  4464. }
  4465. #endif
  4466. static unsigned short
  4467. SiS_GetVGAHT2(struct SiS_Private *SiS_Pr)
  4468. {
  4469. unsigned int tempax,tempbx;
  4470. tempbx = (SiS_Pr->SiS_VGAVT - SiS_Pr->SiS_VGAVDE) * SiS_Pr->SiS_RVBHCMAX;
  4471. tempax = (SiS_Pr->SiS_VT - SiS_Pr->SiS_VDE) * SiS_Pr->SiS_RVBHCFACT;
  4472. tempax = (tempax * SiS_Pr->SiS_HT) / tempbx;
  4473. return (unsigned short)tempax;
  4474. }
  4475. /* Set Part 1 / SiS bridge slave mode */
  4476. static void
  4477. SiS_SetGroup1_301(struct SiS_Private *SiS_Pr, unsigned short ModeNo,unsigned short ModeIdIndex,
  4478. unsigned short RefreshRateTableIndex)
  4479. {
  4480. unsigned short temp, modeflag, i, j, xres=0, VGAVDE;
  4481. static const unsigned short CRTranslation[] = {
  4482. /* CR0 CR1 CR2 CR3 CR4 CR5 CR6 CR7 */
  4483. 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a,
  4484. /* CR8 CR9 SR0A SR0B SR0C SR0D SR0E CR0F */
  4485. 0x00, 0x0b, 0x17, 0x18, 0x19, 0x00, 0x1a, 0x00,
  4486. /* CR10 CR11 CR12 CR13 CR14 CR15 CR16 CR17 */
  4487. 0x0c, 0x0d, 0x0e, 0x00, 0x0f, 0x10, 0x11, 0x00
  4488. };
  4489. if(ModeNo <= 0x13) {
  4490. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  4491. } else if(SiS_Pr->UseCustomMode) {
  4492. modeflag = SiS_Pr->CModeFlag;
  4493. xres = SiS_Pr->CHDisplay;
  4494. } else {
  4495. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  4496. xres = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].XRes;
  4497. }
  4498. /* The following is only done if bridge is in slave mode: */
  4499. if(SiS_Pr->ChipType >= SIS_315H) {
  4500. if(xres >= 1600) { /* BIOS: == 1600 */
  4501. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x31,0x04);
  4502. }
  4503. }
  4504. SiS_Pr->CHTotal = 8224; /* Max HT, 0x2020, results in 0x3ff in registers */
  4505. SiS_Pr->CHDisplay = SiS_Pr->SiS_VGAHDE;
  4506. if(modeflag & HalfDCLK) SiS_Pr->CHDisplay >>= 1;
  4507. SiS_Pr->CHBlankStart = SiS_Pr->CHDisplay;
  4508. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  4509. SiS_Pr->CHBlankStart += 16;
  4510. }
  4511. SiS_Pr->CHBlankEnd = 32;
  4512. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  4513. if(xres == 1600) SiS_Pr->CHBlankEnd += 80;
  4514. }
  4515. temp = SiS_Pr->SiS_VGAHT - 96;
  4516. if(!(modeflag & HalfDCLK)) temp -= 32;
  4517. if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
  4518. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x04);
  4519. temp |= ((SiS_GetReg(SiS_Pr->SiS_P3c4,0x0b) & 0xc0) << 2);
  4520. temp -= 3;
  4521. temp <<= 3;
  4522. } else {
  4523. if(SiS_Pr->SiS_RVBHRS2) temp = SiS_Pr->SiS_RVBHRS2;
  4524. }
  4525. SiS_Pr->CHSyncStart = temp;
  4526. SiS_Pr->CHSyncEnd = 0xffe8; /* results in 0x2000 in registers */
  4527. SiS_Pr->CVTotal = 2049; /* Max VT, 0x0801, results in 0x7ff in registers */
  4528. VGAVDE = SiS_Pr->SiS_VGAVDE;
  4529. if (VGAVDE == 357) VGAVDE = 350;
  4530. else if(VGAVDE == 360) VGAVDE = 350;
  4531. else if(VGAVDE == 375) VGAVDE = 350;
  4532. else if(VGAVDE == 405) VGAVDE = 400;
  4533. else if(VGAVDE == 420) VGAVDE = 400;
  4534. else if(VGAVDE == 525) VGAVDE = 480;
  4535. else if(VGAVDE == 1056) VGAVDE = 1024;
  4536. SiS_Pr->CVDisplay = VGAVDE;
  4537. SiS_Pr->CVBlankStart = SiS_Pr->CVDisplay;
  4538. SiS_Pr->CVBlankEnd = 1;
  4539. if(ModeNo == 0x3c) SiS_Pr->CVBlankEnd = 226;
  4540. temp = (SiS_Pr->SiS_VGAVT - VGAVDE) >> 1;
  4541. SiS_Pr->CVSyncStart = VGAVDE + temp;
  4542. temp >>= 3;
  4543. SiS_Pr->CVSyncEnd = SiS_Pr->CVSyncStart + temp;
  4544. SiS_CalcCRRegisters(SiS_Pr, 0);
  4545. SiS_Pr->CCRT1CRTC[16] &= ~0xE0;
  4546. for(i = 0; i <= 7; i++) {
  4547. SiS_SetReg(SiS_Pr->SiS_Part1Port,CRTranslation[i],SiS_Pr->CCRT1CRTC[i]);
  4548. }
  4549. for(i = 0x10, j = 8; i <= 0x12; i++, j++) {
  4550. SiS_SetReg(SiS_Pr->SiS_Part1Port,CRTranslation[i],SiS_Pr->CCRT1CRTC[j]);
  4551. }
  4552. for(i = 0x15, j = 11; i <= 0x16; i++, j++) {
  4553. SiS_SetReg(SiS_Pr->SiS_Part1Port,CRTranslation[i],SiS_Pr->CCRT1CRTC[j]);
  4554. }
  4555. for(i = 0x0a, j = 13; i <= 0x0c; i++, j++) {
  4556. SiS_SetReg(SiS_Pr->SiS_Part1Port,CRTranslation[i],SiS_Pr->CCRT1CRTC[j]);
  4557. }
  4558. temp = SiS_Pr->CCRT1CRTC[16] & 0xE0;
  4559. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,CRTranslation[0x0E],0x1F,temp);
  4560. temp = (SiS_Pr->CCRT1CRTC[16] & 0x01) << 5;
  4561. if(modeflag & DoubleScanMode) temp |= 0x80;
  4562. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,CRTranslation[0x09],0x5F,temp);
  4563. temp = 0;
  4564. temp |= (SiS_GetReg(SiS_Pr->SiS_P3c4,0x01) & 0x01);
  4565. if(modeflag & HalfDCLK) temp |= 0x08;
  4566. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x16,temp); /* SR01: HalfDCLK[3], 8/9 div dotclock[0] */
  4567. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0F,0x00); /* CR14: (text mode: underline location) */
  4568. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x12,0x00); /* CR17: n/a */
  4569. temp = 0;
  4570. if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) {
  4571. temp = (SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x01) << 7;
  4572. }
  4573. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1A,temp); /* SR0E, dither[7] */
  4574. temp = SiS_GetRegByte((SiS_Pr->SiS_P3ca+0x02));
  4575. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,temp); /* ? */
  4576. }
  4577. /* Setup panel link
  4578. * This is used for LVDS, LCDA and Chrontel TV output
  4579. * 300/LVDS+TV, 300/301B-DH, 315/LVDS+TV, 315/LCDA
  4580. */
  4581. static void
  4582. SiS_SetGroup1_LVDS(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  4583. unsigned short RefreshRateTableIndex)
  4584. {
  4585. unsigned short modeflag, resinfo = 0;
  4586. unsigned short push2, tempax, tempbx, tempcx, temp;
  4587. unsigned int tempeax = 0, tempebx, tempecx, tempvcfact = 0;
  4588. bool islvds = false, issis = false, chkdclkfirst = false;
  4589. #ifdef CONFIG_FB_SIS_300
  4590. unsigned short crt2crtc = 0;
  4591. #endif
  4592. #ifdef CONFIG_FB_SIS_315
  4593. unsigned short pushcx;
  4594. #endif
  4595. if(ModeNo <= 0x13) {
  4596. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  4597. resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
  4598. #ifdef CONFIG_FB_SIS_300
  4599. crt2crtc = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  4600. #endif
  4601. } else if(SiS_Pr->UseCustomMode) {
  4602. modeflag = SiS_Pr->CModeFlag;
  4603. } else {
  4604. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  4605. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  4606. #ifdef CONFIG_FB_SIS_300
  4607. crt2crtc = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  4608. #endif
  4609. }
  4610. /* is lvds if really LVDS, or 301B-DH with external LVDS transmitter */
  4611. if((SiS_Pr->SiS_IF_DEF_LVDS == 1) || (SiS_Pr->SiS_VBType & VB_NoLCD)) {
  4612. islvds = true;
  4613. }
  4614. /* is really sis if sis bridge, but not 301B-DH */
  4615. if((SiS_Pr->SiS_VBType & VB_SISVB) && (!(SiS_Pr->SiS_VBType & VB_NoLCD))) {
  4616. issis = true;
  4617. }
  4618. if((SiS_Pr->ChipType >= SIS_315H) && (islvds) && (!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA))) {
  4619. if((!SiS_Pr->SiS_IF_DEF_FSTN) && (!SiS_Pr->SiS_IF_DEF_DSTN)) {
  4620. chkdclkfirst = true;
  4621. }
  4622. }
  4623. #ifdef CONFIG_FB_SIS_315
  4624. if((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  4625. if(IS_SIS330) {
  4626. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x10);
  4627. } else if(IS_SIS740) {
  4628. if(islvds) {
  4629. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,0xfb,0x04);
  4630. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x03);
  4631. } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
  4632. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x10);
  4633. }
  4634. } else {
  4635. if(islvds) {
  4636. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,0xfb,0x04);
  4637. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x00);
  4638. } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
  4639. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2D,0x0f);
  4640. if(SiS_Pr->SiS_VBType & VB_SIS30xC) {
  4641. if((SiS_Pr->SiS_LCDResInfo == Panel_1024x768) ||
  4642. (SiS_Pr->SiS_LCDResInfo == Panel_1280x1024)) {
  4643. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x20);
  4644. }
  4645. }
  4646. }
  4647. }
  4648. }
  4649. #endif
  4650. /* Horizontal */
  4651. tempax = SiS_Pr->SiS_LCDHDES;
  4652. if(islvds) {
  4653. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4654. if(!SiS_Pr->SiS_IF_DEF_FSTN && !SiS_Pr->SiS_IF_DEF_DSTN) {
  4655. if((SiS_Pr->SiS_LCDResInfo == Panel_640x480) &&
  4656. (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode))) {
  4657. tempax -= 8;
  4658. }
  4659. }
  4660. }
  4661. }
  4662. temp = (tempax & 0x0007);
  4663. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1A,temp); /* BPLHDESKEW[2:0] */
  4664. temp = (tempax >> 3) & 0x00FF;
  4665. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x16,temp); /* BPLHDESKEW[10:3] */
  4666. tempbx = SiS_Pr->SiS_HDE;
  4667. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4668. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  4669. tempbx = SiS_Pr->PanelXRes;
  4670. }
  4671. if((SiS_Pr->SiS_LCDResInfo == Panel_320x240_1) ||
  4672. (SiS_Pr->SiS_LCDResInfo == Panel_320x240_2) ||
  4673. (SiS_Pr->SiS_LCDResInfo == Panel_320x240_3)) {
  4674. tempbx >>= 1;
  4675. }
  4676. }
  4677. tempax += tempbx;
  4678. if(tempax >= SiS_Pr->SiS_HT) tempax -= SiS_Pr->SiS_HT;
  4679. temp = tempax;
  4680. if(temp & 0x07) temp += 8;
  4681. temp >>= 3;
  4682. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x17,temp); /* BPLHDEE */
  4683. tempcx = (SiS_Pr->SiS_HT - tempbx) >> 2;
  4684. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4685. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  4686. if(SiS_Pr->PanelHRS != 999) tempcx = SiS_Pr->PanelHRS;
  4687. }
  4688. }
  4689. tempcx += tempax;
  4690. if(tempcx >= SiS_Pr->SiS_HT) tempcx -= SiS_Pr->SiS_HT;
  4691. temp = (tempcx >> 3) & 0x00FF;
  4692. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4693. if(SiS_Pr->SiS_IF_DEF_TRUMPION) {
  4694. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  4695. switch(ModeNo) {
  4696. case 0x04:
  4697. case 0x05:
  4698. case 0x0d: temp = 0x56; break;
  4699. case 0x10: temp = 0x60; break;
  4700. case 0x13: temp = 0x5f; break;
  4701. case 0x40:
  4702. case 0x41:
  4703. case 0x4f:
  4704. case 0x43:
  4705. case 0x44:
  4706. case 0x62:
  4707. case 0x56:
  4708. case 0x53:
  4709. case 0x5d:
  4710. case 0x5e: temp = 0x54; break;
  4711. }
  4712. }
  4713. }
  4714. }
  4715. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x14,temp); /* BPLHRS */
  4716. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4717. temp += 2;
  4718. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  4719. temp += 8;
  4720. if(SiS_Pr->PanelHRE != 999) {
  4721. temp = tempcx + SiS_Pr->PanelHRE;
  4722. if(temp >= SiS_Pr->SiS_HT) temp -= SiS_Pr->SiS_HT;
  4723. temp >>= 3;
  4724. }
  4725. }
  4726. } else {
  4727. temp += 10;
  4728. }
  4729. temp &= 0x1F;
  4730. temp |= ((tempcx & 0x07) << 5);
  4731. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x15,temp); /* BPLHRE */
  4732. /* Vertical */
  4733. tempax = SiS_Pr->SiS_VGAVDE;
  4734. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4735. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  4736. tempax = SiS_Pr->PanelYRes;
  4737. }
  4738. }
  4739. tempbx = SiS_Pr->SiS_LCDVDES + tempax;
  4740. if(tempbx >= SiS_Pr->SiS_VT) tempbx -= SiS_Pr->SiS_VT;
  4741. push2 = tempbx;
  4742. tempcx = SiS_Pr->SiS_VGAVT - SiS_Pr->SiS_VGAVDE;
  4743. if(SiS_Pr->ChipType < SIS_315H) {
  4744. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4745. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  4746. tempcx = SiS_Pr->SiS_VGAVT - SiS_Pr->PanelYRes;
  4747. }
  4748. }
  4749. }
  4750. if(islvds) tempcx >>= 1;
  4751. else tempcx >>= 2;
  4752. if( (SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) &&
  4753. (!(SiS_Pr->SiS_LCDInfo & LCDPass11)) &&
  4754. (SiS_Pr->PanelVRS != 999) ) {
  4755. tempcx = SiS_Pr->PanelVRS;
  4756. tempbx += tempcx;
  4757. if(issis) tempbx++;
  4758. } else {
  4759. tempbx += tempcx;
  4760. if(SiS_Pr->ChipType < SIS_315H) tempbx++;
  4761. else if(issis) tempbx++;
  4762. }
  4763. if(tempbx >= SiS_Pr->SiS_VT) tempbx -= SiS_Pr->SiS_VT;
  4764. temp = tempbx & 0x00FF;
  4765. if(SiS_Pr->SiS_IF_DEF_TRUMPION) {
  4766. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  4767. if(ModeNo == 0x10) temp = 0xa9;
  4768. }
  4769. }
  4770. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,temp); /* BPLVRS */
  4771. tempcx >>= 3;
  4772. tempcx++;
  4773. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4774. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  4775. if(SiS_Pr->PanelVRE != 999) tempcx = SiS_Pr->PanelVRE;
  4776. }
  4777. }
  4778. tempcx += tempbx;
  4779. temp = tempcx & 0x000F;
  4780. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0xF0,temp); /* BPLVRE */
  4781. temp = ((tempbx >> 8) & 0x07) << 3;
  4782. if(SiS_Pr->SiS_IF_DEF_FSTN || SiS_Pr->SiS_IF_DEF_DSTN) {
  4783. if(SiS_Pr->SiS_HDE != 640) {
  4784. if(SiS_Pr->SiS_VGAVDE != SiS_Pr->SiS_VDE) temp |= 0x40;
  4785. }
  4786. } else if(SiS_Pr->SiS_VGAVDE != SiS_Pr->SiS_VDE) temp |= 0x40;
  4787. if(SiS_Pr->SiS_SetFlag & EnableLVDSDDA) temp |= 0x40;
  4788. tempbx = 0x87;
  4789. if((SiS_Pr->ChipType >= SIS_315H) ||
  4790. (SiS_Pr->ChipRevision >= 0x30)) {
  4791. tempbx = 0x07;
  4792. if((SiS_Pr->SiS_IF_DEF_CH70xx == 1) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
  4793. if(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x03) temp |= 0x80;
  4794. }
  4795. /* Chrontel 701x operates in 24bit mode (8-8-8, 2x12bit multiplexed) via VGA2 */
  4796. if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) {
  4797. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  4798. if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x06) & 0x10) temp |= 0x80;
  4799. } else {
  4800. if(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x01) temp |= 0x80;
  4801. }
  4802. }
  4803. }
  4804. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x1A,tempbx,temp);
  4805. tempbx = push2; /* BPLVDEE */
  4806. tempcx = SiS_Pr->SiS_LCDVDES; /* BPLVDES */
  4807. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4808. switch(SiS_Pr->SiS_LCDResInfo) {
  4809. case Panel_640x480:
  4810. tempbx = SiS_Pr->SiS_VGAVDE - 1;
  4811. tempcx = SiS_Pr->SiS_VGAVDE;
  4812. break;
  4813. case Panel_800x600:
  4814. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  4815. if(resinfo == SIS_RI_800x600) tempcx++;
  4816. }
  4817. break;
  4818. case Panel_1024x600:
  4819. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  4820. if(resinfo == SIS_RI_1024x600) tempcx++;
  4821. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  4822. if(resinfo == SIS_RI_800x600) tempcx++;
  4823. }
  4824. }
  4825. break;
  4826. case Panel_1024x768:
  4827. if(SiS_Pr->ChipType < SIS_315H) {
  4828. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  4829. if(resinfo == SIS_RI_1024x768) tempcx++;
  4830. }
  4831. }
  4832. break;
  4833. }
  4834. }
  4835. temp = ((tempbx >> 8) & 0x07) << 3;
  4836. temp |= ((tempcx >> 8) & 0x07);
  4837. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1D,temp);
  4838. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1C,tempbx);
  4839. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1B,tempcx);
  4840. /* Vertical scaling */
  4841. if(SiS_Pr->ChipType < SIS_315H) {
  4842. #ifdef CONFIG_FB_SIS_300 /* 300 series */
  4843. tempeax = SiS_Pr->SiS_VGAVDE << 6;
  4844. temp = (tempeax % (unsigned int)SiS_Pr->SiS_VDE);
  4845. tempeax = tempeax / (unsigned int)SiS_Pr->SiS_VDE;
  4846. if(temp) tempeax++;
  4847. if(SiS_Pr->SiS_SetFlag & EnableLVDSDDA) tempeax = 0x3F;
  4848. temp = (unsigned short)(tempeax & 0x00FF);
  4849. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1E,temp); /* BPLVCFACT */
  4850. tempvcfact = temp;
  4851. #endif /* CONFIG_FB_SIS_300 */
  4852. } else {
  4853. #ifdef CONFIG_FB_SIS_315 /* 315 series */
  4854. tempeax = SiS_Pr->SiS_VGAVDE << 18;
  4855. tempebx = SiS_Pr->SiS_VDE;
  4856. temp = (tempeax % tempebx);
  4857. tempeax = tempeax / tempebx;
  4858. if(temp) tempeax++;
  4859. tempvcfact = tempeax;
  4860. temp = (unsigned short)(tempeax & 0x00FF);
  4861. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x37,temp);
  4862. temp = (unsigned short)((tempeax & 0x00FF00) >> 8);
  4863. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x36,temp);
  4864. temp = (unsigned short)((tempeax & 0x00030000) >> 16);
  4865. if(SiS_Pr->SiS_VDE == SiS_Pr->SiS_VGAVDE) temp |= 0x04;
  4866. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x35,temp);
  4867. if(SiS_Pr->SiS_VBType & VB_SISPART4SCALER) {
  4868. temp = (unsigned short)(tempeax & 0x00FF);
  4869. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x3c,temp);
  4870. temp = (unsigned short)((tempeax & 0x00FF00) >> 8);
  4871. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x3b,temp);
  4872. temp = (unsigned short)(((tempeax & 0x00030000) >> 16) << 6);
  4873. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x3a,0x3f,temp);
  4874. temp = 0;
  4875. if(SiS_Pr->SiS_VDE != SiS_Pr->SiS_VGAVDE) temp |= 0x08;
  4876. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x30,0xf3,temp);
  4877. }
  4878. #endif
  4879. }
  4880. /* Horizontal scaling */
  4881. tempeax = SiS_Pr->SiS_VGAHDE; /* 1f = ( (VGAHDE * 65536) / ( (VGAHDE * 65536) / HDE ) ) - 1*/
  4882. if(chkdclkfirst) {
  4883. if(modeflag & HalfDCLK) tempeax >>= 1;
  4884. }
  4885. tempebx = tempeax << 16;
  4886. if(SiS_Pr->SiS_HDE == tempeax) {
  4887. tempecx = 0xFFFF;
  4888. } else {
  4889. tempecx = tempebx / SiS_Pr->SiS_HDE;
  4890. if(SiS_Pr->ChipType >= SIS_315H) {
  4891. if(tempebx % SiS_Pr->SiS_HDE) tempecx++;
  4892. }
  4893. }
  4894. if(SiS_Pr->ChipType >= SIS_315H) {
  4895. tempeax = (tempebx / tempecx) - 1;
  4896. } else {
  4897. tempeax = ((SiS_Pr->SiS_VGAHT << 16) / tempecx) - 1;
  4898. }
  4899. tempecx = (tempecx << 16) | (tempeax & 0xFFFF);
  4900. temp = (unsigned short)(tempecx & 0x00FF);
  4901. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1F,temp);
  4902. if(SiS_Pr->ChipType >= SIS_315H) {
  4903. tempeax = (SiS_Pr->SiS_VGAVDE << 18) / tempvcfact;
  4904. tempbx = (unsigned short)(tempeax & 0xFFFF);
  4905. } else {
  4906. tempeax = SiS_Pr->SiS_VGAVDE << 6;
  4907. tempbx = tempvcfact & 0x3f;
  4908. if(tempbx == 0) tempbx = 64;
  4909. tempeax /= tempbx;
  4910. tempbx = (unsigned short)(tempeax & 0xFFFF);
  4911. }
  4912. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) tempbx--;
  4913. if(SiS_Pr->SiS_SetFlag & EnableLVDSDDA) {
  4914. if((!SiS_Pr->SiS_IF_DEF_FSTN) && (!SiS_Pr->SiS_IF_DEF_DSTN)) tempbx = 1;
  4915. else if(SiS_Pr->SiS_LCDResInfo != Panel_640x480) tempbx = 1;
  4916. }
  4917. temp = ((tempbx >> 8) & 0x07) << 3;
  4918. temp = temp | ((tempecx >> 8) & 0x07);
  4919. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x20,temp);
  4920. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x21,tempbx);
  4921. tempecx >>= 16; /* BPLHCFACT */
  4922. if(!chkdclkfirst) {
  4923. if(modeflag & HalfDCLK) tempecx >>= 1;
  4924. }
  4925. temp = (unsigned short)((tempecx & 0xFF00) >> 8);
  4926. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x22,temp);
  4927. temp = (unsigned short)(tempecx & 0x00FF);
  4928. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x23,temp);
  4929. #ifdef CONFIG_FB_SIS_315
  4930. if(SiS_Pr->ChipType >= SIS_315H) {
  4931. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  4932. if((islvds) || (SiS_Pr->SiS_VBInfo & VB_SISLVDS)) {
  4933. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1e,0x20);
  4934. }
  4935. } else {
  4936. if(islvds) {
  4937. if(SiS_Pr->ChipType == SIS_740) {
  4938. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1e,0x03);
  4939. } else {
  4940. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1e,0x23);
  4941. }
  4942. }
  4943. }
  4944. }
  4945. #endif
  4946. #ifdef CONFIG_FB_SIS_300
  4947. if(SiS_Pr->SiS_IF_DEF_TRUMPION) {
  4948. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  4949. unsigned char *trumpdata;
  4950. int i, j = crt2crtc;
  4951. unsigned char TrumpMode13[4] = { 0x01, 0x10, 0x2c, 0x00 };
  4952. unsigned char TrumpMode10_1[4] = { 0x01, 0x10, 0x27, 0x00 };
  4953. unsigned char TrumpMode10_2[4] = { 0x01, 0x16, 0x10, 0x00 };
  4954. if(SiS_Pr->SiS_UseROM) {
  4955. trumpdata = &ROMAddr[0x8001 + (j * 80)];
  4956. } else {
  4957. if(SiS_Pr->SiS_LCDTypeInfo == 0x0e) j += 7;
  4958. trumpdata = &SiS300_TrumpionData[j][0];
  4959. }
  4960. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x02,0xbf);
  4961. for(i=0; i<5; i++) {
  4962. SiS_SetTrumpionBlock(SiS_Pr, trumpdata);
  4963. }
  4964. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  4965. if(ModeNo == 0x13) {
  4966. for(i=0; i<4; i++) {
  4967. SiS_SetTrumpionBlock(SiS_Pr, &TrumpMode13[0]);
  4968. }
  4969. } else if(ModeNo == 0x10) {
  4970. for(i=0; i<4; i++) {
  4971. SiS_SetTrumpionBlock(SiS_Pr, &TrumpMode10_1[0]);
  4972. SiS_SetTrumpionBlock(SiS_Pr, &TrumpMode10_2[0]);
  4973. }
  4974. }
  4975. }
  4976. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x02,0x40);
  4977. }
  4978. #endif
  4979. #ifdef CONFIG_FB_SIS_315
  4980. if(SiS_Pr->SiS_IF_DEF_FSTN || SiS_Pr->SiS_IF_DEF_DSTN) {
  4981. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x25,0x00);
  4982. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x26,0x00);
  4983. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x27,0x00);
  4984. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x28,0x87);
  4985. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x29,0x5A);
  4986. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2A,0x4B);
  4987. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x44,~0x07,0x03);
  4988. tempax = SiS_Pr->SiS_HDE; /* Blps = lcdhdee(lcdhdes+HDE) + 64 */
  4989. if(SiS_Pr->SiS_LCDResInfo == Panel_320x240_1 ||
  4990. SiS_Pr->SiS_LCDResInfo == Panel_320x240_2 ||
  4991. SiS_Pr->SiS_LCDResInfo == Panel_320x240_3) tempax >>= 1;
  4992. tempax += 64;
  4993. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x38,tempax & 0xff);
  4994. temp = (tempax >> 8) << 3;
  4995. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x35,~0x078,temp);
  4996. tempax += 32; /* Blpe = lBlps+32 */
  4997. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x39,tempax & 0xff);
  4998. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3A,0x00); /* Bflml = 0 */
  4999. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x3C,~0x007);
  5000. tempax = SiS_Pr->SiS_VDE;
  5001. if(SiS_Pr->SiS_LCDResInfo == Panel_320x240_1 ||
  5002. SiS_Pr->SiS_LCDResInfo == Panel_320x240_2 ||
  5003. SiS_Pr->SiS_LCDResInfo == Panel_320x240_3) tempax >>= 1;
  5004. tempax >>= 1;
  5005. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3B,tempax & 0xff);
  5006. temp = (tempax >> 8) << 3;
  5007. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x3C,~0x038,temp);
  5008. tempeax = SiS_Pr->SiS_HDE;
  5009. if(SiS_Pr->SiS_LCDResInfo == Panel_320x240_1 ||
  5010. SiS_Pr->SiS_LCDResInfo == Panel_320x240_2 ||
  5011. SiS_Pr->SiS_LCDResInfo == Panel_320x240_3) tempeax >>= 1;
  5012. tempeax <<= 2; /* BDxFIFOSTOP = (HDE*4)/128 */
  5013. temp = tempeax & 0x7f;
  5014. tempeax >>= 7;
  5015. if(temp) tempeax++;
  5016. temp = tempeax & 0x3f;
  5017. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x45,temp);
  5018. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3F,0x00); /* BDxWadrst0 */
  5019. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3E,0x00);
  5020. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3D,0x10);
  5021. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x3C,~0x040);
  5022. tempax = SiS_Pr->SiS_HDE;
  5023. if(SiS_Pr->SiS_LCDResInfo == Panel_320x240_1 ||
  5024. SiS_Pr->SiS_LCDResInfo == Panel_320x240_2 ||
  5025. SiS_Pr->SiS_LCDResInfo == Panel_320x240_3) tempax >>= 1;
  5026. tempax >>= 4; /* BDxWadroff = HDE*4/8/8 */
  5027. pushcx = tempax;
  5028. temp = tempax & 0x00FF;
  5029. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x43,temp);
  5030. temp = ((tempax & 0xFF00) >> 8) << 3;
  5031. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port, 0x44, 0x07, temp);
  5032. tempax = SiS_Pr->SiS_VDE; /* BDxWadrst1 = BDxWadrst0 + BDxWadroff * VDE */
  5033. if(SiS_Pr->SiS_LCDResInfo == Panel_320x240_1 ||
  5034. SiS_Pr->SiS_LCDResInfo == Panel_320x240_2 ||
  5035. SiS_Pr->SiS_LCDResInfo == Panel_320x240_3) tempax >>= 1;
  5036. tempeax = tempax * pushcx;
  5037. temp = tempeax & 0xFF;
  5038. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x42,temp);
  5039. temp = (tempeax & 0xFF00) >> 8;
  5040. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x41,temp);
  5041. temp = ((tempeax & 0xFF0000) >> 16) | 0x10;
  5042. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x40,temp);
  5043. temp = ((tempeax & 0x01000000) >> 24) << 7;
  5044. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port, 0x3C, 0x7F, temp);
  5045. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2F,0x03);
  5046. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x03,0x50);
  5047. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x04,0x00);
  5048. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2F,0x01);
  5049. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x19,0x38);
  5050. if(SiS_Pr->SiS_IF_DEF_FSTN) {
  5051. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2b,0x02);
  5052. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2c,0x00);
  5053. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2d,0x00);
  5054. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x35,0x0c);
  5055. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x36,0x00);
  5056. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x37,0x00);
  5057. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x38,0x80);
  5058. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x39,0xA0);
  5059. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3a,0x00);
  5060. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3b,0xf0);
  5061. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3c,0x00);
  5062. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3d,0x10);
  5063. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3e,0x00);
  5064. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3f,0x00);
  5065. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x40,0x10);
  5066. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x41,0x25);
  5067. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x42,0x80);
  5068. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x43,0x14);
  5069. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x44,0x03);
  5070. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x45,0x0a);
  5071. }
  5072. }
  5073. #endif /* CONFIG_FB_SIS_315 */
  5074. }
  5075. /* Set Part 1 */
  5076. static void
  5077. SiS_SetGroup1(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  5078. unsigned short RefreshRateTableIndex)
  5079. {
  5080. #if defined(CONFIG_FB_SIS_300) || defined(CONFIG_FB_SIS_315)
  5081. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  5082. #endif
  5083. unsigned short temp=0, tempax=0, tempbx=0, tempcx=0, bridgeadd=0;
  5084. unsigned short pushbx=0, CRT1Index=0, modeflag, resinfo=0;
  5085. #ifdef CONFIG_FB_SIS_315
  5086. unsigned short tempbl=0;
  5087. #endif
  5088. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  5089. SiS_SetGroup1_LVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  5090. return;
  5091. }
  5092. if(ModeNo <= 0x13) {
  5093. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  5094. } else if(SiS_Pr->UseCustomMode) {
  5095. modeflag = SiS_Pr->CModeFlag;
  5096. } else {
  5097. CRT1Index = SiS_GetRefCRT1CRTC(SiS_Pr, RefreshRateTableIndex, SiS_Pr->SiS_UseWideCRT2);
  5098. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  5099. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  5100. }
  5101. SiS_SetCRT2Offset(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  5102. if( ! ((SiS_Pr->ChipType >= SIS_315H) &&
  5103. (SiS_Pr->SiS_IF_DEF_LVDS == 1) &&
  5104. (SiS_Pr->SiS_VBInfo & SetInSlaveMode)) ) {
  5105. if(SiS_Pr->ChipType < SIS_315H ) {
  5106. #ifdef CONFIG_FB_SIS_300
  5107. SiS_SetCRT2FIFO_300(SiS_Pr, ModeNo);
  5108. #endif
  5109. } else {
  5110. #ifdef CONFIG_FB_SIS_315
  5111. SiS_SetCRT2FIFO_310(SiS_Pr);
  5112. #endif
  5113. }
  5114. /* 1. Horizontal setup */
  5115. if(SiS_Pr->ChipType < SIS_315H ) {
  5116. #ifdef CONFIG_FB_SIS_300 /* ------------- 300 series --------------*/
  5117. temp = (SiS_Pr->SiS_VGAHT - 1) & 0x0FF; /* BTVGA2HT 0x08,0x09 */
  5118. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x08,temp); /* CRT2 Horizontal Total */
  5119. temp = (((SiS_Pr->SiS_VGAHT - 1) & 0xFF00) >> 8) << 4;
  5120. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x09,0x0f,temp); /* CRT2 Horizontal Total Overflow [7:4] */
  5121. temp = (SiS_Pr->SiS_VGAHDE + 12) & 0x0FF; /* BTVGA2HDEE 0x0A,0x0C */
  5122. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0A,temp); /* CRT2 Horizontal Display Enable End */
  5123. pushbx = SiS_Pr->SiS_VGAHDE + 12; /* bx BTVGA2HRS 0x0B,0x0C */
  5124. tempcx = (SiS_Pr->SiS_VGAHT - SiS_Pr->SiS_VGAHDE) >> 2;
  5125. tempbx = pushbx + tempcx;
  5126. tempcx <<= 1;
  5127. tempcx += tempbx;
  5128. bridgeadd = 12;
  5129. #endif /* CONFIG_FB_SIS_300 */
  5130. } else {
  5131. #ifdef CONFIG_FB_SIS_315 /* ------------------- 315/330 series --------------- */
  5132. tempcx = SiS_Pr->SiS_VGAHT; /* BTVGA2HT 0x08,0x09 */
  5133. if(modeflag & HalfDCLK) {
  5134. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  5135. tempcx >>= 1;
  5136. } else {
  5137. tempax = SiS_Pr->SiS_VGAHDE >> 1;
  5138. tempcx = SiS_Pr->SiS_HT - SiS_Pr->SiS_HDE + tempax;
  5139. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  5140. tempcx = SiS_Pr->SiS_HT - tempax;
  5141. }
  5142. }
  5143. }
  5144. tempcx--;
  5145. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x08,tempcx); /* CRT2 Horizontal Total */
  5146. temp = (tempcx >> 4) & 0xF0;
  5147. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x09,0x0F,temp); /* CRT2 Horizontal Total Overflow [7:4] */
  5148. tempcx = SiS_Pr->SiS_VGAHT; /* BTVGA2HDEE 0x0A,0x0C */
  5149. tempbx = SiS_Pr->SiS_VGAHDE;
  5150. tempcx -= tempbx;
  5151. tempcx >>= 2;
  5152. if(modeflag & HalfDCLK) {
  5153. tempbx >>= 1;
  5154. tempcx >>= 1;
  5155. }
  5156. tempbx += 16;
  5157. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0A,tempbx); /* CRT2 Horizontal Display Enable End */
  5158. pushbx = tempbx;
  5159. tempcx >>= 1;
  5160. tempbx += tempcx;
  5161. tempcx += tempbx;
  5162. bridgeadd = 16;
  5163. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  5164. if(SiS_Pr->ChipType >= SIS_661) {
  5165. if((SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) ||
  5166. (SiS_Pr->SiS_LCDResInfo == Panel_1280x1024)) {
  5167. if(resinfo == SIS_RI_1280x1024) {
  5168. tempcx = (tempcx & 0xff00) | 0x30;
  5169. } else if(resinfo == SIS_RI_1600x1200) {
  5170. tempcx = (tempcx & 0xff00) | 0xff;
  5171. }
  5172. }
  5173. }
  5174. }
  5175. #endif /* CONFIG_FB_SIS_315 */
  5176. } /* 315/330 series */
  5177. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  5178. if(SiS_Pr->UseCustomMode) {
  5179. tempbx = SiS_Pr->CHSyncStart + bridgeadd;
  5180. tempcx = SiS_Pr->CHSyncEnd + bridgeadd;
  5181. tempax = SiS_Pr->SiS_VGAHT;
  5182. if(modeflag & HalfDCLK) tempax >>= 1;
  5183. tempax--;
  5184. if(tempcx > tempax) tempcx = tempax;
  5185. }
  5186. if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) {
  5187. unsigned char cr4, cr14, cr5, cr15;
  5188. if(SiS_Pr->UseCustomMode) {
  5189. cr4 = SiS_Pr->CCRT1CRTC[4];
  5190. cr14 = SiS_Pr->CCRT1CRTC[14];
  5191. cr5 = SiS_Pr->CCRT1CRTC[5];
  5192. cr15 = SiS_Pr->CCRT1CRTC[15];
  5193. } else {
  5194. cr4 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[4];
  5195. cr14 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[14];
  5196. cr5 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[5];
  5197. cr15 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[15];
  5198. }
  5199. tempbx = ((cr4 | ((cr14 & 0xC0) << 2)) - 3) << 3; /* (VGAHRS-3)*8 */
  5200. tempcx = (((cr5 & 0x1f) | ((cr15 & 0x04) << (5-2))) - 3) << 3; /* (VGAHRE-3)*8 */
  5201. tempcx &= 0x00FF;
  5202. tempcx |= (tempbx & 0xFF00);
  5203. tempbx += bridgeadd;
  5204. tempcx += bridgeadd;
  5205. tempax = SiS_Pr->SiS_VGAHT;
  5206. if(modeflag & HalfDCLK) tempax >>= 1;
  5207. tempax--;
  5208. if(tempcx > tempax) tempcx = tempax;
  5209. }
  5210. if(SiS_Pr->SiS_TVMode & (TVSetNTSC1024 | TVSet525p1024)) {
  5211. tempbx = 1040;
  5212. tempcx = 1044; /* HWCursor bug! */
  5213. }
  5214. }
  5215. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0B,tempbx); /* CRT2 Horizontal Retrace Start */
  5216. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0D,tempcx); /* CRT2 Horizontal Retrace End */
  5217. temp = ((tempbx >> 8) & 0x0F) | ((pushbx >> 4) & 0xF0);
  5218. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0C,temp); /* Overflow */
  5219. /* 2. Vertical setup */
  5220. tempcx = SiS_Pr->SiS_VGAVT - 1;
  5221. temp = tempcx & 0x00FF;
  5222. if(SiS_Pr->ChipType < SIS_661) {
  5223. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  5224. if(SiS_Pr->ChipType < SIS_315H) {
  5225. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  5226. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToSVIDEO | SetCRT2ToAVIDEO)) {
  5227. temp--;
  5228. }
  5229. }
  5230. } else {
  5231. temp--;
  5232. }
  5233. } else if(SiS_Pr->ChipType >= SIS_315H) {
  5234. temp--;
  5235. }
  5236. }
  5237. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0E,temp); /* CRT2 Vertical Total */
  5238. tempbx = SiS_Pr->SiS_VGAVDE - 1;
  5239. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0F,tempbx); /* CRT2 Vertical Display Enable End */
  5240. temp = ((tempbx >> 5) & 0x38) | ((tempcx >> 8) & 0x07);
  5241. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x12,temp); /* Overflow */
  5242. if((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->ChipType < SIS_661)) {
  5243. tempbx++;
  5244. tempax = tempbx;
  5245. tempcx++;
  5246. tempcx -= tempax;
  5247. tempcx >>= 2;
  5248. tempbx += tempcx;
  5249. if(tempcx < 4) tempcx = 4;
  5250. tempcx >>= 2;
  5251. tempcx += tempbx;
  5252. tempcx++;
  5253. } else {
  5254. tempbx = (SiS_Pr->SiS_VGAVT + SiS_Pr->SiS_VGAVDE) >> 1; /* BTVGA2VRS 0x10,0x11 */
  5255. tempcx = ((SiS_Pr->SiS_VGAVT - SiS_Pr->SiS_VGAVDE) >> 4) + tempbx + 1; /* BTVGA2VRE 0x11 */
  5256. }
  5257. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  5258. if(SiS_Pr->UseCustomMode) {
  5259. tempbx = SiS_Pr->CVSyncStart;
  5260. tempcx = SiS_Pr->CVSyncEnd;
  5261. }
  5262. if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) {
  5263. unsigned char cr8, cr7, cr13;
  5264. if(SiS_Pr->UseCustomMode) {
  5265. cr8 = SiS_Pr->CCRT1CRTC[8];
  5266. cr7 = SiS_Pr->CCRT1CRTC[7];
  5267. cr13 = SiS_Pr->CCRT1CRTC[13];
  5268. tempcx = SiS_Pr->CCRT1CRTC[9];
  5269. } else {
  5270. cr8 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[8];
  5271. cr7 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[7];
  5272. cr13 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[13];
  5273. tempcx = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[9];
  5274. }
  5275. tempbx = cr8;
  5276. if(cr7 & 0x04) tempbx |= 0x0100;
  5277. if(cr7 & 0x80) tempbx |= 0x0200;
  5278. if(cr13 & 0x08) tempbx |= 0x0400;
  5279. }
  5280. }
  5281. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x10,tempbx); /* CRT2 Vertical Retrace Start */
  5282. temp = ((tempbx >> 4) & 0x70) | (tempcx & 0x0F);
  5283. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x11,temp); /* CRT2 Vert. Retrace End; Overflow */
  5284. /* 3. Panel delay compensation */
  5285. if(SiS_Pr->ChipType < SIS_315H) {
  5286. #ifdef CONFIG_FB_SIS_300 /* ---------- 300 series -------------- */
  5287. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  5288. temp = 0x20;
  5289. if(SiS_Pr->ChipType == SIS_300) {
  5290. temp = 0x10;
  5291. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) temp = 0x2c;
  5292. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) temp = 0x20;
  5293. }
  5294. if(SiS_Pr->SiS_VBType & VB_SIS301) {
  5295. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) temp = 0x20;
  5296. }
  5297. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x960) temp = 0x24;
  5298. if(SiS_Pr->SiS_LCDResInfo == Panel_Custom) temp = 0x2c;
  5299. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) temp = 0x08;
  5300. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  5301. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) temp = 0x2c;
  5302. else temp = 0x20;
  5303. }
  5304. if(SiS_Pr->SiS_UseROM) {
  5305. if(ROMAddr[0x220] & 0x80) {
  5306. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoYPbPrHiVision)
  5307. temp = ROMAddr[0x221];
  5308. else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision)
  5309. temp = ROMAddr[0x222];
  5310. else if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024)
  5311. temp = ROMAddr[0x223];
  5312. else
  5313. temp = ROMAddr[0x224];
  5314. }
  5315. }
  5316. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  5317. if(SiS_Pr->PDC != -1) temp = SiS_Pr->PDC;
  5318. }
  5319. } else {
  5320. temp = 0x20;
  5321. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
  5322. if(SiS_Pr->SiS_LCDResInfo == Panel_640x480) temp = 0x04;
  5323. }
  5324. if(SiS_Pr->SiS_UseROM) {
  5325. if(ROMAddr[0x220] & 0x80) {
  5326. temp = ROMAddr[0x220];
  5327. }
  5328. }
  5329. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  5330. if(SiS_Pr->PDC != -1) temp = SiS_Pr->PDC;
  5331. }
  5332. }
  5333. temp &= 0x3c;
  5334. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,~0x3C,temp); /* Panel Link Delay Compensation; (Software Command Reset; Power Saving) */
  5335. #endif /* CONFIG_FB_SIS_300 */
  5336. } else {
  5337. #ifdef CONFIG_FB_SIS_315 /* --------------- 315/330 series ---------------*/
  5338. if(SiS_Pr->ChipType < SIS_661) {
  5339. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  5340. if(SiS_Pr->ChipType == SIS_740) temp = 0x03;
  5341. else temp = 0x00;
  5342. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) temp = 0x0a;
  5343. tempbl = 0xF0;
  5344. if(SiS_Pr->ChipType == SIS_650) {
  5345. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  5346. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) tempbl = 0x0F;
  5347. }
  5348. }
  5349. if(SiS_Pr->SiS_IF_DEF_DSTN || SiS_Pr->SiS_IF_DEF_FSTN) {
  5350. temp = 0x08;
  5351. tempbl = 0;
  5352. if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
  5353. if(ROMAddr[0x13c] & 0x80) tempbl = 0xf0;
  5354. }
  5355. }
  5356. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,tempbl,temp); /* Panel Link Delay Compensation */
  5357. }
  5358. } /* < 661 */
  5359. tempax = 0;
  5360. if(modeflag & DoubleScanMode) tempax |= 0x80;
  5361. if(modeflag & HalfDCLK) tempax |= 0x40;
  5362. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2C,0x3f,tempax);
  5363. #endif /* CONFIG_FB_SIS_315 */
  5364. }
  5365. } /* Slavemode */
  5366. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  5367. if((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) {
  5368. /* For 301BDH with LCD, we set up the Panel Link */
  5369. SiS_SetGroup1_LVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  5370. } else if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  5371. SiS_SetGroup1_301(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  5372. }
  5373. } else {
  5374. if(SiS_Pr->ChipType < SIS_315H) {
  5375. SiS_SetGroup1_LVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  5376. } else {
  5377. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  5378. if((!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) || (SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  5379. SiS_SetGroup1_LVDS(SiS_Pr, ModeNo,ModeIdIndex,RefreshRateTableIndex);
  5380. }
  5381. } else {
  5382. SiS_SetGroup1_LVDS(SiS_Pr, ModeNo,ModeIdIndex,RefreshRateTableIndex);
  5383. }
  5384. }
  5385. }
  5386. }
  5387. /*********************************************/
  5388. /* SET PART 2 REGISTER GROUP */
  5389. /*********************************************/
  5390. #ifdef CONFIG_FB_SIS_315
  5391. static unsigned char *
  5392. SiS_GetGroup2CLVXPtr(struct SiS_Private *SiS_Pr, int tabletype)
  5393. {
  5394. const unsigned char *tableptr = NULL;
  5395. unsigned short a, b, p = 0;
  5396. a = SiS_Pr->SiS_VGAHDE;
  5397. b = SiS_Pr->SiS_HDE;
  5398. if(tabletype) {
  5399. a = SiS_Pr->SiS_VGAVDE;
  5400. b = SiS_Pr->SiS_VDE;
  5401. }
  5402. if(a < b) {
  5403. tableptr = SiS_Part2CLVX_1;
  5404. } else if(a == b) {
  5405. tableptr = SiS_Part2CLVX_2;
  5406. } else {
  5407. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  5408. tableptr = SiS_Part2CLVX_4;
  5409. } else {
  5410. tableptr = SiS_Part2CLVX_3;
  5411. }
  5412. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  5413. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525i) tableptr = SiS_Part2CLVX_3;
  5414. else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) tableptr = SiS_Part2CLVX_3;
  5415. else tableptr = SiS_Part2CLVX_5;
  5416. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  5417. tableptr = SiS_Part2CLVX_6;
  5418. }
  5419. do {
  5420. if((tableptr[p] | tableptr[p+1] << 8) == a) break;
  5421. p += 0x42;
  5422. } while((tableptr[p] | tableptr[p+1] << 8) != 0xffff);
  5423. if((tableptr[p] | tableptr[p+1] << 8) == 0xffff) p -= 0x42;
  5424. }
  5425. p += 2;
  5426. return ((unsigned char *)&tableptr[p]);
  5427. }
  5428. static void
  5429. SiS_SetGroup2_C_ELV(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  5430. unsigned short RefreshRateTableIndex)
  5431. {
  5432. unsigned char *tableptr;
  5433. unsigned char temp;
  5434. int i, j;
  5435. if(!(SiS_Pr->SiS_VBType & VB_SISTAP4SCALER)) return;
  5436. tableptr = SiS_GetGroup2CLVXPtr(SiS_Pr, 0);
  5437. for(i = 0x80, j = 0; i <= 0xbf; i++, j++) {
  5438. SiS_SetReg(SiS_Pr->SiS_Part2Port, i, tableptr[j]);
  5439. }
  5440. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  5441. tableptr = SiS_GetGroup2CLVXPtr(SiS_Pr, 1);
  5442. for(i = 0xc0, j = 0; i <= 0xff; i++, j++) {
  5443. SiS_SetReg(SiS_Pr->SiS_Part2Port, i, tableptr[j]);
  5444. }
  5445. }
  5446. temp = 0x10;
  5447. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) temp |= 0x04;
  5448. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x4e,0xeb,temp);
  5449. }
  5450. static bool
  5451. SiS_GetCRT2Part2Ptr(struct SiS_Private *SiS_Pr,unsigned short ModeNo,unsigned short ModeIdIndex,
  5452. unsigned short RefreshRateTableIndex,unsigned short *CRT2Index,
  5453. unsigned short *ResIndex)
  5454. {
  5455. if(SiS_Pr->ChipType < SIS_315H) return false;
  5456. if(ModeNo <= 0x13)
  5457. (*ResIndex) = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  5458. else
  5459. (*ResIndex) = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  5460. (*ResIndex) &= 0x3f;
  5461. (*CRT2Index) = 0;
  5462. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  5463. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
  5464. (*CRT2Index) = 200;
  5465. }
  5466. }
  5467. if(SiS_Pr->SiS_CustomT == CUT_ASUSA2H_2) {
  5468. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  5469. if(SiS_Pr->SiS_SetFlag & LCDVESATiming) (*CRT2Index) = 206;
  5470. }
  5471. }
  5472. return (((*CRT2Index) != 0));
  5473. }
  5474. #endif
  5475. #ifdef CONFIG_FB_SIS_300
  5476. static void
  5477. SiS_Group2LCDSpecial(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short crt2crtc)
  5478. {
  5479. unsigned short tempcx;
  5480. static const unsigned char atable[] = {
  5481. 0xc3,0x9e,0xc3,0x9e,0x02,0x02,0x02,
  5482. 0xab,0x87,0xab,0x9e,0xe7,0x02,0x02
  5483. };
  5484. if(!SiS_Pr->UseCustomMode) {
  5485. if( ( ( (SiS_Pr->ChipType == SIS_630) ||
  5486. (SiS_Pr->ChipType == SIS_730) ) &&
  5487. (SiS_Pr->ChipRevision > 2) ) &&
  5488. (SiS_Pr->SiS_LCDResInfo == Panel_1024x768) &&
  5489. (!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) &&
  5490. (!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) ) {
  5491. if(ModeNo == 0x13) {
  5492. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,0xB9);
  5493. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x05,0xCC);
  5494. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x06,0xA6);
  5495. } else if((crt2crtc & 0x3F) == 4) {
  5496. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x2B);
  5497. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x13);
  5498. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,0xE5);
  5499. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x05,0x08);
  5500. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x06,0xE2);
  5501. }
  5502. }
  5503. if(SiS_Pr->ChipType < SIS_315H) {
  5504. if(SiS_Pr->SiS_LCDTypeInfo == 0x0c) {
  5505. crt2crtc &= 0x1f;
  5506. tempcx = 0;
  5507. if(!(SiS_Pr->SiS_VBInfo & SetNotSimuMode)) {
  5508. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  5509. tempcx += 7;
  5510. }
  5511. }
  5512. tempcx += crt2crtc;
  5513. if(crt2crtc >= 4) {
  5514. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x06,0xff);
  5515. }
  5516. if(!(SiS_Pr->SiS_VBInfo & SetNotSimuMode)) {
  5517. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  5518. if(crt2crtc == 4) {
  5519. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x28);
  5520. }
  5521. }
  5522. }
  5523. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x18);
  5524. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,atable[tempcx]);
  5525. }
  5526. }
  5527. }
  5528. }
  5529. /* For ECS A907. Highly preliminary. */
  5530. static void
  5531. SiS_Set300Part2Regs(struct SiS_Private *SiS_Pr, unsigned short ModeIdIndex, unsigned short RefreshRateTableIndex,
  5532. unsigned short ModeNo)
  5533. {
  5534. const struct SiS_Part2PortTbl *CRT2Part2Ptr = NULL;
  5535. unsigned short crt2crtc, resindex;
  5536. int i, j;
  5537. if(SiS_Pr->ChipType != SIS_300) return;
  5538. if(!(SiS_Pr->SiS_VBType & VB_SIS30xBLV)) return;
  5539. if(SiS_Pr->UseCustomMode) return;
  5540. if(ModeNo <= 0x13) {
  5541. crt2crtc = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  5542. } else {
  5543. crt2crtc = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  5544. }
  5545. resindex = crt2crtc & 0x3F;
  5546. if(SiS_Pr->SiS_SetFlag & LCDVESATiming) CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1024x768_1;
  5547. else CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1024x768_2;
  5548. /* The BIOS code (1.16.51,56) is obviously a fragment! */
  5549. if(ModeNo > 0x13) {
  5550. CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1024x768_1;
  5551. resindex = 4;
  5552. }
  5553. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x01,0x80,(CRT2Part2Ptr+resindex)->CR[0]);
  5554. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x02,0x80,(CRT2Part2Ptr+resindex)->CR[1]);
  5555. for(i = 2, j = 0x04; j <= 0x06; i++, j++ ) {
  5556. SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]);
  5557. }
  5558. for(j = 0x1c; j <= 0x1d; i++, j++ ) {
  5559. SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]);
  5560. }
  5561. for(j = 0x1f; j <= 0x21; i++, j++ ) {
  5562. SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]);
  5563. }
  5564. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x23,(CRT2Part2Ptr+resindex)->CR[10]);
  5565. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x25,0x0f,(CRT2Part2Ptr+resindex)->CR[11]);
  5566. }
  5567. #endif
  5568. static void
  5569. SiS_SetTVSpecial(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
  5570. {
  5571. if(!(SiS_Pr->SiS_VBType & VB_SIS30xBLV)) return;
  5572. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoHiVision)) return;
  5573. if(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p)) return;
  5574. if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) {
  5575. if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) {
  5576. const unsigned char specialtv[] = {
  5577. 0xa7,0x07,0xf2,0x6e,0x17,0x8b,0x73,0x53,
  5578. 0x13,0x40,0x34,0xf4,0x63,0xbb,0xcc,0x7a,
  5579. 0x58,0xe4,0x73,0xda,0x13
  5580. };
  5581. int i, j;
  5582. for(i = 0x1c, j = 0; i <= 0x30; i++, j++) {
  5583. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,specialtv[j]);
  5584. }
  5585. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x43,0x72);
  5586. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750)) {
  5587. if(SiS_Pr->SiS_TVMode & TVSetPALM) {
  5588. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x14);
  5589. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x1b);
  5590. } else {
  5591. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x14); /* 15 */
  5592. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x1a); /* 1b */
  5593. }
  5594. }
  5595. }
  5596. } else {
  5597. if((ModeNo == 0x38) || (ModeNo == 0x4a) || (ModeNo == 0x64) ||
  5598. (ModeNo == 0x52) || (ModeNo == 0x58) || (ModeNo == 0x5c)) {
  5599. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x1b); /* 21 */
  5600. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x54); /* 5a */
  5601. } else {
  5602. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x1a); /* 21 */
  5603. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x53); /* 5a */
  5604. }
  5605. }
  5606. }
  5607. static void
  5608. SiS_SetGroup2_Tail(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
  5609. {
  5610. unsigned short temp;
  5611. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
  5612. if(SiS_Pr->SiS_VGAVDE == 525) {
  5613. temp = 0xc3;
  5614. if(SiS_Pr->SiS_ModeType <= ModeVGA) {
  5615. temp++;
  5616. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) temp += 2;
  5617. }
  5618. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2f,temp);
  5619. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x30,0xb3);
  5620. } else if(SiS_Pr->SiS_VGAVDE == 420) {
  5621. temp = 0x4d;
  5622. if(SiS_Pr->SiS_ModeType <= ModeVGA) {
  5623. temp++;
  5624. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) temp++;
  5625. }
  5626. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2f,temp);
  5627. }
  5628. }
  5629. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  5630. if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) {
  5631. if(SiS_Pr->SiS_VBType & VB_SIS30xB) {
  5632. SiS_SetRegOR(SiS_Pr->SiS_Part2Port,0x1a,0x03);
  5633. /* Not always for LV, see SetGrp2 */
  5634. }
  5635. temp = 1;
  5636. if(ModeNo <= 0x13) temp = 3;
  5637. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x0b,temp);
  5638. }
  5639. #if 0
  5640. /* 651+301C, for 1280x768 - do I really need that? */
  5641. if((SiS_Pr->SiS_PanelXRes == 1280) && (SiS_Pr->SiS_PanelYRes == 768)) {
  5642. if(SiS_Pr->SiS_VBInfo & SetSimuScanMode) {
  5643. if(((SiS_Pr->SiS_HDE == 640) && (SiS_Pr->SiS_VDE == 480)) ||
  5644. ((SiS_Pr->SiS_HDE == 320) && (SiS_Pr->SiS_VDE == 240))) {
  5645. SiS_SetReg(SiS_Part2Port,0x01,0x2b);
  5646. SiS_SetReg(SiS_Part2Port,0x02,0x13);
  5647. SiS_SetReg(SiS_Part2Port,0x04,0xe5);
  5648. SiS_SetReg(SiS_Part2Port,0x05,0x08);
  5649. SiS_SetReg(SiS_Part2Port,0x06,0xe2);
  5650. SiS_SetReg(SiS_Part2Port,0x1c,0x21);
  5651. SiS_SetReg(SiS_Part2Port,0x1d,0x45);
  5652. SiS_SetReg(SiS_Part2Port,0x1f,0x0b);
  5653. SiS_SetReg(SiS_Part2Port,0x20,0x00);
  5654. SiS_SetReg(SiS_Part2Port,0x21,0xa9);
  5655. SiS_SetReg(SiS_Part2Port,0x23,0x0b);
  5656. SiS_SetReg(SiS_Part2Port,0x25,0x04);
  5657. }
  5658. }
  5659. }
  5660. #endif
  5661. }
  5662. }
  5663. static void
  5664. SiS_SetGroup2(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  5665. unsigned short RefreshRateTableIndex)
  5666. {
  5667. unsigned short i, j, tempax, tempbx, tempcx, tempch, tempcl, temp;
  5668. unsigned short push2, modeflag, crt2crtc, bridgeoffset;
  5669. unsigned int longtemp, PhaseIndex;
  5670. bool newtvphase;
  5671. const unsigned char *TimingPoint;
  5672. #ifdef CONFIG_FB_SIS_315
  5673. unsigned short resindex, CRT2Index;
  5674. const struct SiS_Part2PortTbl *CRT2Part2Ptr = NULL;
  5675. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) return;
  5676. #endif
  5677. if(ModeNo <= 0x13) {
  5678. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  5679. crt2crtc = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  5680. } else if(SiS_Pr->UseCustomMode) {
  5681. modeflag = SiS_Pr->CModeFlag;
  5682. crt2crtc = 0;
  5683. } else {
  5684. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  5685. crt2crtc = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  5686. }
  5687. temp = 0;
  5688. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToAVIDEO)) temp |= 0x08;
  5689. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToSVIDEO)) temp |= 0x04;
  5690. if(SiS_Pr->SiS_VBInfo & SetCRT2ToSCART) temp |= 0x02;
  5691. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) temp |= 0x01;
  5692. if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) temp |= 0x10;
  5693. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x00,temp);
  5694. PhaseIndex = 0x01; /* SiS_PALPhase */
  5695. TimingPoint = SiS_Pr->SiS_PALTiming;
  5696. newtvphase = false;
  5697. if( (SiS_Pr->SiS_VBType & VB_SIS30xBLV) &&
  5698. ( (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) ||
  5699. (SiS_Pr->SiS_TVMode & TVSetTVSimuMode) ) ) {
  5700. newtvphase = true;
  5701. }
  5702. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  5703. TimingPoint = SiS_Pr->SiS_HiTVExtTiming;
  5704. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  5705. TimingPoint = SiS_Pr->SiS_HiTVSt2Timing;
  5706. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) {
  5707. TimingPoint = SiS_Pr->SiS_HiTVSt1Timing;
  5708. }
  5709. }
  5710. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  5711. i = 0;
  5712. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) i = 2;
  5713. else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) i = 1;
  5714. TimingPoint = &SiS_YPbPrTable[i][0];
  5715. PhaseIndex = 0x00; /* SiS_NTSCPhase */
  5716. } else if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  5717. if(newtvphase) PhaseIndex = 0x09; /* SiS_PALPhase2 */
  5718. } else {
  5719. TimingPoint = SiS_Pr->SiS_NTSCTiming;
  5720. PhaseIndex = (SiS_Pr->SiS_TVMode & TVSetNTSCJ) ? 0x01 : 0x00; /* SiS_PALPhase : SiS_NTSCPhase */
  5721. if(newtvphase) PhaseIndex += 8; /* SiS_PALPhase2 : SiS_NTSCPhase2 */
  5722. }
  5723. if(SiS_Pr->SiS_TVMode & (TVSetPALM | TVSetPALN)) {
  5724. PhaseIndex = (SiS_Pr->SiS_TVMode & TVSetPALM) ? 0x02 : 0x03; /* SiS_PALMPhase : SiS_PALNPhase */
  5725. if(newtvphase) PhaseIndex += 8; /* SiS_PALMPhase2 : SiS_PALNPhase2 */
  5726. }
  5727. if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) {
  5728. if(SiS_Pr->SiS_TVMode & TVSetPALM) {
  5729. PhaseIndex = 0x05; /* SiS_SpecialPhaseM */
  5730. } else if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) {
  5731. PhaseIndex = 0x11; /* SiS_SpecialPhaseJ */
  5732. } else {
  5733. PhaseIndex = 0x10; /* SiS_SpecialPhase */
  5734. }
  5735. }
  5736. for(i = 0x31, j = 0; i <= 0x34; i++, j++) {
  5737. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS_TVPhase[(PhaseIndex * 4) + j]);
  5738. }
  5739. for(i = 0x01, j = 0; i <= 0x2D; i++, j++) {
  5740. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,TimingPoint[j]);
  5741. }
  5742. for(i = 0x39; i <= 0x45; i++, j++) {
  5743. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,TimingPoint[j]);
  5744. }
  5745. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  5746. if(SiS_Pr->SiS_ModeType != ModeText) {
  5747. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x3A,0x1F);
  5748. }
  5749. }
  5750. SiS_SetRegOR(SiS_Pr->SiS_Part2Port,0x0A,SiS_Pr->SiS_NewFlickerMode);
  5751. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x35,SiS_Pr->SiS_RY1COE);
  5752. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x36,SiS_Pr->SiS_RY2COE);
  5753. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x37,SiS_Pr->SiS_RY3COE);
  5754. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x38,SiS_Pr->SiS_RY4COE);
  5755. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) tempax = 950;
  5756. else if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) tempax = 680;
  5757. else if(SiS_Pr->SiS_TVMode & TVSetPAL) tempax = 520;
  5758. else tempax = 440; /* NTSC, YPbPr 525 */
  5759. if( ((SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) && (SiS_Pr->SiS_VDE <= tempax)) ||
  5760. ( (SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoHiVision) &&
  5761. ((SiS_Pr->SiS_VGAHDE == 1024) || (SiS_Pr->SiS_VDE <= tempax)) ) ) {
  5762. tempax -= SiS_Pr->SiS_VDE;
  5763. tempax >>= 1;
  5764. if(!(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p))) {
  5765. tempax >>= 1;
  5766. }
  5767. tempax &= 0x00ff;
  5768. temp = tempax + (unsigned short)TimingPoint[0];
  5769. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,temp);
  5770. temp = tempax + (unsigned short)TimingPoint[1];
  5771. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,temp);
  5772. if((SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoYPbPrHiVision) && (SiS_Pr->SiS_VGAHDE >= 1024)) {
  5773. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  5774. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x1b);
  5775. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x54);
  5776. } else {
  5777. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x17);
  5778. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x1d);
  5779. }
  5780. }
  5781. }
  5782. tempcx = SiS_Pr->SiS_HT;
  5783. if(SiS_IsDualLink(SiS_Pr)) tempcx >>= 1;
  5784. tempcx--;
  5785. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) tempcx--;
  5786. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x1B,tempcx);
  5787. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1D,0xF0,((tempcx >> 8) & 0x0f));
  5788. tempcx = SiS_Pr->SiS_HT >> 1;
  5789. if(SiS_IsDualLink(SiS_Pr)) tempcx >>= 1;
  5790. tempcx += 7;
  5791. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) tempcx -= 4;
  5792. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x22,0x0F,((tempcx << 4) & 0xf0));
  5793. tempbx = TimingPoint[j] | (TimingPoint[j+1] << 8);
  5794. tempbx += tempcx;
  5795. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x24,tempbx);
  5796. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x25,0x0F,((tempbx >> 4) & 0xf0));
  5797. tempbx += 8;
  5798. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  5799. tempbx -= 4;
  5800. tempcx = tempbx;
  5801. }
  5802. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x29,0x0F,((tempbx << 4) & 0xf0));
  5803. j += 2;
  5804. tempcx += (TimingPoint[j] | (TimingPoint[j+1] << 8));
  5805. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x27,tempcx);
  5806. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x28,0x0F,((tempcx >> 4) & 0xf0));
  5807. tempcx += 8;
  5808. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) tempcx -= 4;
  5809. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2A,0x0F,((tempcx << 4) & 0xf0));
  5810. tempcx = SiS_Pr->SiS_HT >> 1;
  5811. if(SiS_IsDualLink(SiS_Pr)) tempcx >>= 1;
  5812. j += 2;
  5813. tempcx -= (TimingPoint[j] | ((TimingPoint[j+1]) << 8));
  5814. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2D,0x0F,((tempcx << 4) & 0xf0));
  5815. tempcx -= 11;
  5816. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
  5817. tempcx = SiS_GetVGAHT2(SiS_Pr) - 1;
  5818. }
  5819. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2E,tempcx);
  5820. tempbx = SiS_Pr->SiS_VDE;
  5821. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  5822. if(SiS_Pr->SiS_VGAVDE == 360) tempbx = 746;
  5823. if(SiS_Pr->SiS_VGAVDE == 375) tempbx = 746;
  5824. if(SiS_Pr->SiS_VGAVDE == 405) tempbx = 853;
  5825. } else if( (SiS_Pr->SiS_VBInfo & SetCRT2ToTV) &&
  5826. (!(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p|TVSetYPbPr750p))) ) {
  5827. tempbx >>= 1;
  5828. if(SiS_Pr->ChipType >= SIS_315H) {
  5829. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) {
  5830. if((ModeNo <= 0x13) && (crt2crtc == 1)) tempbx++;
  5831. } else if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  5832. if(SiS_Pr->SiS_ModeType <= ModeVGA) {
  5833. if(crt2crtc == 4) tempbx++;
  5834. }
  5835. }
  5836. }
  5837. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  5838. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  5839. if((ModeNo == 0x2f) || (ModeNo == 0x5d) || (ModeNo == 0x5e)) tempbx++;
  5840. }
  5841. if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) {
  5842. if(ModeNo == 0x03) tempbx++; /* From 1.10.7w - doesn't make sense */
  5843. }
  5844. }
  5845. }
  5846. tempbx -= 2;
  5847. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2F,tempbx);
  5848. temp = (tempcx >> 8) & 0x0F;
  5849. temp |= ((tempbx >> 2) & 0xC0);
  5850. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToSVIDEO | SetCRT2ToAVIDEO)) {
  5851. temp |= 0x10;
  5852. if(SiS_Pr->SiS_VBInfo & SetCRT2ToAVIDEO) temp |= 0x20;
  5853. }
  5854. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x30,temp);
  5855. if(SiS_Pr->SiS_VBType & VB_SISPART4OVERFLOW) {
  5856. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x10,0xdf,((tempbx & 0x0400) >> 5));
  5857. }
  5858. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  5859. tempbx = SiS_Pr->SiS_VDE;
  5860. if( (SiS_Pr->SiS_VBInfo & SetCRT2ToTV) &&
  5861. (!(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p))) ) {
  5862. tempbx >>= 1;
  5863. }
  5864. tempbx -= 3;
  5865. temp = ((tempbx >> 3) & 0x60) | 0x18;
  5866. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x46,temp);
  5867. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x47,tempbx);
  5868. if(SiS_Pr->SiS_VBType & VB_SISPART4OVERFLOW) {
  5869. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x10,0xbf,((tempbx & 0x0400) >> 4));
  5870. }
  5871. }
  5872. tempbx = 0;
  5873. if(!(modeflag & HalfDCLK)) {
  5874. if(SiS_Pr->SiS_VGAHDE >= SiS_Pr->SiS_HDE) {
  5875. tempax = 0;
  5876. tempbx |= 0x20;
  5877. }
  5878. }
  5879. tempch = tempcl = 0x01;
  5880. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  5881. if(SiS_Pr->SiS_VGAHDE >= 960) {
  5882. if((!(modeflag & HalfDCLK)) || (SiS_Pr->ChipType < SIS_315H)) {
  5883. tempcl = 0x20;
  5884. if(SiS_Pr->SiS_VGAHDE >= 1280) {
  5885. tempch = 20;
  5886. tempbx &= ~0x20;
  5887. } else if(SiS_Pr->SiS_VGAHDE >= 1024) {
  5888. tempch = 25;
  5889. } else {
  5890. tempch = 25; /* OK */
  5891. }
  5892. }
  5893. }
  5894. }
  5895. if(!(tempbx & 0x20)) {
  5896. if(modeflag & HalfDCLK) tempcl <<= 1;
  5897. longtemp = ((SiS_Pr->SiS_VGAHDE * tempch) / tempcl) << 13;
  5898. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) longtemp <<= 3;
  5899. tempax = longtemp / SiS_Pr->SiS_HDE;
  5900. if(longtemp % SiS_Pr->SiS_HDE) tempax++;
  5901. tempbx |= ((tempax >> 8) & 0x1F);
  5902. tempcx = tempax >> 13;
  5903. }
  5904. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x44,tempax);
  5905. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x45,0xC0,tempbx);
  5906. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  5907. tempcx &= 0x07;
  5908. if(tempbx & 0x20) tempcx = 0;
  5909. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x46,0xF8,tempcx);
  5910. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  5911. tempbx = 0x0382;
  5912. tempcx = 0x007e;
  5913. } else {
  5914. tempbx = 0x0369;
  5915. tempcx = 0x0061;
  5916. }
  5917. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x4B,tempbx);
  5918. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x4C,tempcx);
  5919. temp = (tempcx & 0x0300) >> 6;
  5920. temp |= ((tempbx >> 8) & 0x03);
  5921. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  5922. temp |= 0x10;
  5923. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) temp |= 0x20;
  5924. else if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) temp |= 0x40;
  5925. }
  5926. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x4D,temp);
  5927. temp = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x43);
  5928. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x43,(temp - 3));
  5929. SiS_SetTVSpecial(SiS_Pr, ModeNo);
  5930. if(SiS_Pr->SiS_VBType & VB_SIS30xCLV) {
  5931. temp = 0;
  5932. if(SiS_Pr->SiS_TVMode & TVSetPALM) temp = 8;
  5933. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x4e,0xf7,temp);
  5934. }
  5935. }
  5936. if(SiS_Pr->SiS_TVMode & TVSetPALM) {
  5937. if(!(SiS_Pr->SiS_TVMode & TVSetNTSC1024)) {
  5938. temp = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x01);
  5939. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,(temp - 1));
  5940. }
  5941. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xEF);
  5942. }
  5943. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  5944. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  5945. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x0B,0x00);
  5946. }
  5947. }
  5948. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) return;
  5949. /* From here: Part2 LCD setup */
  5950. tempbx = SiS_Pr->SiS_HDE;
  5951. if(SiS_IsDualLink(SiS_Pr)) tempbx >>= 1;
  5952. tempbx--; /* RHACTE = HDE - 1 */
  5953. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2C,tempbx);
  5954. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2B,0x0F,((tempbx >> 4) & 0xf0));
  5955. temp = 0x01;
  5956. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) {
  5957. if(SiS_Pr->SiS_ModeType == ModeEGA) {
  5958. if(SiS_Pr->SiS_VGAHDE >= 1024) {
  5959. temp = 0x02;
  5960. if(SiS_Pr->SiS_SetFlag & LCDVESATiming) {
  5961. temp = 0x01;
  5962. }
  5963. }
  5964. }
  5965. }
  5966. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x0B,temp);
  5967. tempbx = SiS_Pr->SiS_VDE - 1;
  5968. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x03,tempbx);
  5969. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x0C,0xF8,((tempbx >> 8) & 0x07));
  5970. tempcx = SiS_Pr->SiS_VT - 1;
  5971. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x19,tempcx);
  5972. temp = (tempcx >> 3) & 0xE0;
  5973. if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) {
  5974. /* Enable dithering; only do this for 32bpp mode */
  5975. if(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x01) {
  5976. temp |= 0x10;
  5977. }
  5978. }
  5979. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1A,0x0f,temp);
  5980. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x09,0xF0);
  5981. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x0A,0xF0);
  5982. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x17,0xFB);
  5983. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x18,0xDF);
  5984. #ifdef CONFIG_FB_SIS_315
  5985. if(SiS_GetCRT2Part2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex,
  5986. &CRT2Index, &resindex)) {
  5987. switch(CRT2Index) {
  5988. case 206: CRT2Part2Ptr = SiS310_CRT2Part2_Asus1024x768_3; break;
  5989. default:
  5990. case 200: CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1024x768_1; break;
  5991. }
  5992. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x01,0x80,(CRT2Part2Ptr+resindex)->CR[0]);
  5993. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x02,0x80,(CRT2Part2Ptr+resindex)->CR[1]);
  5994. for(i = 2, j = 0x04; j <= 0x06; i++, j++ ) {
  5995. SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]);
  5996. }
  5997. for(j = 0x1c; j <= 0x1d; i++, j++ ) {
  5998. SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]);
  5999. }
  6000. for(j = 0x1f; j <= 0x21; i++, j++ ) {
  6001. SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]);
  6002. }
  6003. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x23,(CRT2Part2Ptr+resindex)->CR[10]);
  6004. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x25,0x0f,(CRT2Part2Ptr+resindex)->CR[11]);
  6005. SiS_SetGroup2_Tail(SiS_Pr, ModeNo);
  6006. } else {
  6007. #endif
  6008. /* Checked for 1024x768, 1280x1024, 1400x1050, 1600x1200 */
  6009. /* Clevo dual-link 1024x768 */
  6010. /* Compaq 1280x1024 has HT 1696 sometimes (calculation OK, if given HT is correct) */
  6011. /* Acer: OK, but uses different setting for VESA timing at 640/800/1024 and 640x400 */
  6012. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  6013. if((SiS_Pr->SiS_LCDInfo & LCDPass11) || (SiS_Pr->PanelYRes == SiS_Pr->SiS_VDE)) {
  6014. tempbx = SiS_Pr->SiS_VDE - 1;
  6015. tempcx = SiS_Pr->SiS_VT - 1;
  6016. } else {
  6017. tempbx = SiS_Pr->SiS_VDE + ((SiS_Pr->PanelYRes - SiS_Pr->SiS_VDE) / 2);
  6018. tempcx = SiS_Pr->SiS_VT - ((SiS_Pr->PanelYRes - SiS_Pr->SiS_VDE) / 2);
  6019. }
  6020. } else {
  6021. tempbx = SiS_Pr->PanelYRes;
  6022. tempcx = SiS_Pr->SiS_VT;
  6023. tempax = 1;
  6024. if(SiS_Pr->PanelYRes != SiS_Pr->SiS_VDE) {
  6025. tempax = SiS_Pr->PanelYRes;
  6026. /* if(SiS_Pr->SiS_VGAVDE == 525) tempax += 0x3c; */ /* 651+301C */
  6027. if(SiS_Pr->PanelYRes < SiS_Pr->SiS_VDE) {
  6028. tempax = tempcx = 0;
  6029. } else {
  6030. tempax -= SiS_Pr->SiS_VDE;
  6031. }
  6032. tempax >>= 1;
  6033. }
  6034. tempcx -= tempax; /* lcdvdes */
  6035. tempbx -= tempax; /* lcdvdee */
  6036. }
  6037. /* Non-expanding: lcdvdes = tempcx = VT-1; lcdvdee = tempbx = VDE-1 */
  6038. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x05,tempcx); /* lcdvdes */
  6039. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x06,tempbx); /* lcdvdee */
  6040. temp = (tempbx >> 5) & 0x38;
  6041. temp |= ((tempcx >> 8) & 0x07);
  6042. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,temp);
  6043. tempax = SiS_Pr->SiS_VDE;
  6044. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
  6045. tempax = SiS_Pr->PanelYRes;
  6046. }
  6047. tempcx = (SiS_Pr->SiS_VT - tempax) >> 4;
  6048. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
  6049. if(SiS_Pr->PanelYRes != SiS_Pr->SiS_VDE) {
  6050. tempcx = (SiS_Pr->SiS_VT - tempax) / 10;
  6051. }
  6052. }
  6053. tempbx = ((SiS_Pr->SiS_VT + SiS_Pr->SiS_VDE) >> 1) - 1;
  6054. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  6055. if(SiS_Pr->PanelYRes != SiS_Pr->SiS_VDE) {
  6056. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) { /* ? */
  6057. tempax = SiS_Pr->SiS_VT - SiS_Pr->PanelYRes;
  6058. if(tempax % 4) { tempax >>= 2; tempax++; }
  6059. else { tempax >>= 2; }
  6060. tempbx -= (tempax - 1);
  6061. } else {
  6062. tempbx -= 10;
  6063. if(tempbx <= SiS_Pr->SiS_VDE) tempbx = SiS_Pr->SiS_VDE + 1;
  6064. }
  6065. }
  6066. }
  6067. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  6068. tempbx++;
  6069. if((!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) || (crt2crtc == 6)) {
  6070. if(SiS_Pr->SiS_SetFlag & LCDVESATiming) {
  6071. tempbx = 770;
  6072. tempcx = 3;
  6073. }
  6074. }
  6075. }
  6076. /* non-expanding: lcdvrs = ((VT + VDE) / 2) - 10 */
  6077. if(SiS_Pr->UseCustomMode) {
  6078. tempbx = SiS_Pr->CVSyncStart;
  6079. }
  6080. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,tempbx); /* lcdvrs */
  6081. temp = (tempbx >> 4) & 0xF0;
  6082. tempbx += (tempcx + 1);
  6083. temp |= (tempbx & 0x0F);
  6084. if(SiS_Pr->UseCustomMode) {
  6085. temp &= 0xf0;
  6086. temp |= (SiS_Pr->CVSyncEnd & 0x0f);
  6087. }
  6088. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,temp);
  6089. #ifdef CONFIG_FB_SIS_300
  6090. SiS_Group2LCDSpecial(SiS_Pr, ModeNo, crt2crtc);
  6091. #endif
  6092. bridgeoffset = 7;
  6093. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) bridgeoffset += 2;
  6094. if(SiS_Pr->SiS_VBType & VB_SIS30xCLV) bridgeoffset += 2; /* OK for Averatec 1280x800 (301C) */
  6095. if(SiS_IsDualLink(SiS_Pr)) bridgeoffset++;
  6096. else if(SiS_Pr->SiS_VBType & VB_SIS302LV) bridgeoffset++; /* OK for Asus A4L 1280x800 */
  6097. /* Higher bridgeoffset shifts to the LEFT */
  6098. temp = 0;
  6099. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
  6100. if(SiS_Pr->PanelXRes != SiS_Pr->SiS_HDE) {
  6101. temp = SiS_Pr->SiS_HT - ((SiS_Pr->PanelXRes - SiS_Pr->SiS_HDE) / 2);
  6102. if(SiS_IsDualLink(SiS_Pr)) temp >>= 1;
  6103. }
  6104. }
  6105. temp += bridgeoffset;
  6106. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x1F,temp); /* lcdhdes */
  6107. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x20,0x0F,((temp >> 4) & 0xf0));
  6108. tempcx = SiS_Pr->SiS_HT;
  6109. tempax = tempbx = SiS_Pr->SiS_HDE;
  6110. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
  6111. if(SiS_Pr->PanelXRes != SiS_Pr->SiS_HDE) {
  6112. tempax = SiS_Pr->PanelXRes;
  6113. tempbx = SiS_Pr->PanelXRes - ((SiS_Pr->PanelXRes - SiS_Pr->SiS_HDE) / 2);
  6114. }
  6115. }
  6116. if(SiS_IsDualLink(SiS_Pr)) {
  6117. tempcx >>= 1;
  6118. tempbx >>= 1;
  6119. tempax >>= 1;
  6120. }
  6121. tempbx += bridgeoffset;
  6122. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x23,tempbx); /* lcdhdee */
  6123. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x25,0xF0,((tempbx >> 8) & 0x0f));
  6124. tempcx = (tempcx - tempax) >> 2;
  6125. tempbx += tempcx;
  6126. push2 = tempbx;
  6127. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) {
  6128. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  6129. if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
  6130. if(SiS_Pr->SiS_HDE == 1280) tempbx = (tempbx & 0xff00) | 0x47;
  6131. }
  6132. }
  6133. }
  6134. if(SiS_Pr->UseCustomMode) {
  6135. tempbx = SiS_Pr->CHSyncStart;
  6136. if(modeflag & HalfDCLK) tempbx <<= 1;
  6137. if(SiS_IsDualLink(SiS_Pr)) tempbx >>= 1;
  6138. tempbx += bridgeoffset;
  6139. }
  6140. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x1C,tempbx); /* lcdhrs */
  6141. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1D,0x0F,((tempbx >> 4) & 0xf0));
  6142. tempbx = push2;
  6143. tempcx <<= 1;
  6144. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
  6145. if(SiS_Pr->PanelXRes != SiS_Pr->SiS_HDE) tempcx >>= 2;
  6146. }
  6147. tempbx += tempcx;
  6148. if(SiS_Pr->UseCustomMode) {
  6149. tempbx = SiS_Pr->CHSyncEnd;
  6150. if(modeflag & HalfDCLK) tempbx <<= 1;
  6151. if(SiS_IsDualLink(SiS_Pr)) tempbx >>= 1;
  6152. tempbx += bridgeoffset;
  6153. }
  6154. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x21,tempbx); /* lcdhre */
  6155. SiS_SetGroup2_Tail(SiS_Pr, ModeNo);
  6156. #ifdef CONFIG_FB_SIS_300
  6157. SiS_Set300Part2Regs(SiS_Pr, ModeIdIndex, RefreshRateTableIndex, ModeNo);
  6158. #endif
  6159. #ifdef CONFIG_FB_SIS_315
  6160. } /* CRT2-LCD from table */
  6161. #endif
  6162. }
  6163. /*********************************************/
  6164. /* SET PART 3 REGISTER GROUP */
  6165. /*********************************************/
  6166. static void
  6167. SiS_SetGroup3(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  6168. {
  6169. unsigned short i;
  6170. const unsigned char *tempdi;
  6171. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) return;
  6172. #ifndef SIS_CP
  6173. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x00,0x00);
  6174. #else
  6175. SIS_CP_INIT301_CP
  6176. #endif
  6177. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  6178. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x13,0xFA);
  6179. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x14,0xC8);
  6180. } else {
  6181. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x13,0xF5);
  6182. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x14,0xB7);
  6183. }
  6184. if(SiS_Pr->SiS_TVMode & TVSetPALM) {
  6185. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x13,0xFA);
  6186. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x14,0xC8);
  6187. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x3D,0xA8);
  6188. }
  6189. tempdi = NULL;
  6190. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  6191. tempdi = SiS_Pr->SiS_HiTVGroup3Data;
  6192. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) {
  6193. tempdi = SiS_Pr->SiS_HiTVGroup3Simu;
  6194. }
  6195. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  6196. if(!(SiS_Pr->SiS_TVMode & TVSetYPbPr525i)) {
  6197. tempdi = SiS_HiTVGroup3_1;
  6198. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) tempdi = SiS_HiTVGroup3_2;
  6199. }
  6200. }
  6201. if(tempdi) {
  6202. for(i=0; i<=0x3E; i++) {
  6203. SiS_SetReg(SiS_Pr->SiS_Part3Port,i,tempdi[i]);
  6204. }
  6205. if(SiS_Pr->SiS_VBType & VB_SIS30xCLV) {
  6206. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) {
  6207. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x28,0x3f);
  6208. }
  6209. }
  6210. }
  6211. #ifdef SIS_CP
  6212. SIS_CP_INIT301_CP2
  6213. #endif
  6214. }
  6215. /*********************************************/
  6216. /* SET PART 4 REGISTER GROUP */
  6217. /*********************************************/
  6218. #ifdef CONFIG_FB_SIS_315
  6219. #if 0
  6220. static void
  6221. SiS_ShiftXPos(struct SiS_Private *SiS_Pr, int shift)
  6222. {
  6223. unsigned short temp, temp1, temp2;
  6224. temp1 = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x1f);
  6225. temp2 = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x20);
  6226. temp = (unsigned short)((int)((temp1 | ((temp2 & 0xf0) << 4))) + shift);
  6227. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x1f,temp);
  6228. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x20,0x0f,((temp >> 4) & 0xf0));
  6229. temp = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x2b) & 0x0f;
  6230. temp = (unsigned short)((int)(temp) + shift);
  6231. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2b,0xf0,(temp & 0x0f));
  6232. temp1 = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x43);
  6233. temp2 = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x42);
  6234. temp = (unsigned short)((int)((temp1 | ((temp2 & 0xf0) << 4))) + shift);
  6235. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x43,temp);
  6236. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x42,0x0f,((temp >> 4) & 0xf0));
  6237. }
  6238. #endif
  6239. static void
  6240. SiS_SetGroup4_C_ELV(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  6241. {
  6242. unsigned short temp, temp1, resinfo = 0;
  6243. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  6244. if(!(SiS_Pr->SiS_VBType & VB_SIS30xCLV)) return;
  6245. if(!(SiS_Pr->SiS_VBInfo & (SetCRT2ToHiVision | SetCRT2ToYPbPr525750))) return;
  6246. if(SiS_Pr->ChipType >= XGI_20) return;
  6247. if((SiS_Pr->ChipType >= SIS_661) && (SiS_Pr->SiS_ROMNew)) {
  6248. if(!(ROMAddr[0x61] & 0x04)) return;
  6249. }
  6250. if(ModeNo > 0x13) {
  6251. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  6252. }
  6253. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x3a,0x08);
  6254. temp = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x3a);
  6255. if(!(temp & 0x01)) {
  6256. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x3a,0xdf);
  6257. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x25,0xfc);
  6258. if((SiS_Pr->ChipType < SIS_661) && (!(SiS_Pr->SiS_ROMNew))) {
  6259. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x25,0xf8);
  6260. }
  6261. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x0f,0xfb);
  6262. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) temp = 0x0000;
  6263. else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) temp = 0x0002;
  6264. else if(SiS_Pr->SiS_TVMode & TVSetHiVision) temp = 0x0400;
  6265. else temp = 0x0402;
  6266. if((SiS_Pr->ChipType >= SIS_661) || (SiS_Pr->SiS_ROMNew)) {
  6267. temp1 = 0;
  6268. if(SiS_Pr->SiS_TVMode & TVAspect43) temp1 = 4;
  6269. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x0f,0xfb,temp1);
  6270. if(SiS_Pr->SiS_TVMode & TVAspect43LB) temp |= 0x01;
  6271. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x26,0x7c,(temp & 0xff));
  6272. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x3a,0xfb,(temp >> 8));
  6273. if(ModeNo > 0x13) {
  6274. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x39,0xfd);
  6275. }
  6276. } else {
  6277. temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x3b) & 0x03;
  6278. if(temp1 == 0x01) temp |= 0x01;
  6279. if(temp1 == 0x03) temp |= 0x04; /* ? why not 0x10? */
  6280. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x26,0xf8,(temp & 0xff));
  6281. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x3a,0xfb,(temp >> 8));
  6282. if(ModeNo > 0x13) {
  6283. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x3b,0xfd);
  6284. }
  6285. }
  6286. #if 0
  6287. if(SiS_Pr->ChipType >= SIS_661) { /* ? */
  6288. if(SiS_Pr->SiS_TVMode & TVAspect43) {
  6289. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) {
  6290. if(resinfo == SIS_RI_1024x768) {
  6291. SiS_ShiftXPos(SiS_Pr, 97);
  6292. } else {
  6293. SiS_ShiftXPos(SiS_Pr, 111);
  6294. }
  6295. } else if(SiS_Pr->SiS_TVMode & TVSetHiVision) {
  6296. SiS_ShiftXPos(SiS_Pr, 136);
  6297. }
  6298. }
  6299. }
  6300. #endif
  6301. }
  6302. }
  6303. #endif
  6304. static void
  6305. SiS_SetCRT2VCLK(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  6306. unsigned short RefreshRateTableIndex)
  6307. {
  6308. unsigned short vclkindex, temp, reg1, reg2;
  6309. if(SiS_Pr->UseCustomMode) {
  6310. reg1 = SiS_Pr->CSR2B;
  6311. reg2 = SiS_Pr->CSR2C;
  6312. } else {
  6313. vclkindex = SiS_GetVCLK2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  6314. reg1 = SiS_Pr->SiS_VBVCLKData[vclkindex].Part4_A;
  6315. reg2 = SiS_Pr->SiS_VBVCLKData[vclkindex].Part4_B;
  6316. }
  6317. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  6318. if(SiS_Pr->SiS_TVMode & (TVSetNTSC1024 | TVSet525p1024)) {
  6319. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0a,0x57);
  6320. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0b,0x46);
  6321. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1f,0xf6);
  6322. } else {
  6323. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0a,reg1);
  6324. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0b,reg2);
  6325. }
  6326. } else {
  6327. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0a,0x01);
  6328. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0b,reg2);
  6329. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0a,reg1);
  6330. }
  6331. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x12,0x00);
  6332. temp = 0x08;
  6333. if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) temp |= 0x20;
  6334. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x12,temp);
  6335. }
  6336. static void
  6337. SiS_SetDualLinkEtc(struct SiS_Private *SiS_Pr)
  6338. {
  6339. if(SiS_Pr->ChipType >= SIS_315H) {
  6340. if(SiS_Pr->SiS_VBType & VB_SISDUALLINK) {
  6341. if((SiS_CRT2IsLCD(SiS_Pr)) ||
  6342. (SiS_IsVAMode(SiS_Pr))) {
  6343. if(SiS_Pr->SiS_LCDInfo & LCDDualLink) {
  6344. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x27,0x2c);
  6345. } else {
  6346. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x27,~0x20);
  6347. }
  6348. }
  6349. }
  6350. }
  6351. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  6352. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2a,0x00);
  6353. #ifdef SET_EMI
  6354. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
  6355. #endif
  6356. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x34,0x10);
  6357. }
  6358. }
  6359. static void
  6360. SiS_SetGroup4(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  6361. unsigned short RefreshRateTableIndex)
  6362. {
  6363. unsigned short tempax, tempcx, tempbx, modeflag, temp, resinfo;
  6364. unsigned int tempebx, tempeax, templong;
  6365. if(ModeNo <= 0x13) {
  6366. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  6367. resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
  6368. } else if(SiS_Pr->UseCustomMode) {
  6369. modeflag = SiS_Pr->CModeFlag;
  6370. resinfo = 0;
  6371. } else {
  6372. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  6373. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  6374. }
  6375. if(SiS_Pr->ChipType >= SIS_315H) {
  6376. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  6377. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  6378. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x24,0x0e);
  6379. }
  6380. }
  6381. }
  6382. if(SiS_Pr->SiS_VBType & (VB_SIS30xCLV | VB_SIS302LV)) {
  6383. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  6384. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x10,0x9f);
  6385. }
  6386. }
  6387. if(SiS_Pr->ChipType >= SIS_315H) {
  6388. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  6389. SiS_SetDualLinkEtc(SiS_Pr);
  6390. return;
  6391. }
  6392. }
  6393. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x13,SiS_Pr->SiS_RVBHCFACT);
  6394. tempbx = SiS_Pr->SiS_RVBHCMAX;
  6395. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x14,tempbx);
  6396. temp = (tempbx >> 1) & 0x80;
  6397. tempcx = SiS_Pr->SiS_VGAHT - 1;
  6398. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x16,tempcx);
  6399. temp |= ((tempcx >> 5) & 0x78);
  6400. tempcx = SiS_Pr->SiS_VGAVT - 1;
  6401. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) tempcx -= 5;
  6402. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x17,tempcx);
  6403. temp |= ((tempcx >> 8) & 0x07);
  6404. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x15,temp);
  6405. tempbx = SiS_Pr->SiS_VGAHDE;
  6406. if(modeflag & HalfDCLK) tempbx >>= 1;
  6407. if(SiS_IsDualLink(SiS_Pr)) tempbx >>= 1;
  6408. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  6409. temp = 0;
  6410. if(tempbx > 800) temp = 0x60;
  6411. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  6412. temp = 0;
  6413. if(tempbx > 1024) temp = 0xC0;
  6414. else if(tempbx >= 960) temp = 0xA0;
  6415. } else if(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p)) {
  6416. temp = 0;
  6417. if(tempbx >= 1280) temp = 0x40;
  6418. else if(tempbx >= 1024) temp = 0x20;
  6419. } else {
  6420. temp = 0x80;
  6421. if(tempbx >= 1024) temp = 0xA0;
  6422. }
  6423. temp |= SiS_Pr->Init_P4_0E;
  6424. if(SiS_Pr->SiS_VBType & VB_SIS301) {
  6425. if(SiS_Pr->SiS_LCDResInfo != Panel_1280x1024) {
  6426. temp &= 0xf0;
  6427. temp |= 0x0A;
  6428. }
  6429. }
  6430. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x0E,0x10,temp);
  6431. tempeax = SiS_Pr->SiS_VGAVDE;
  6432. tempebx = SiS_Pr->SiS_VDE;
  6433. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  6434. if(!(temp & 0xE0)) tempebx >>=1;
  6435. }
  6436. tempcx = SiS_Pr->SiS_RVBHRS;
  6437. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x18,tempcx);
  6438. tempcx >>= 8;
  6439. tempcx |= 0x40;
  6440. if(tempeax <= tempebx) {
  6441. tempcx ^= 0x40;
  6442. } else {
  6443. tempeax -= tempebx;
  6444. }
  6445. tempeax *= (256 * 1024);
  6446. templong = tempeax % tempebx;
  6447. tempeax /= tempebx;
  6448. if(templong) tempeax++;
  6449. temp = (unsigned short)(tempeax & 0x000000FF);
  6450. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1B,temp);
  6451. temp = (unsigned short)((tempeax & 0x0000FF00) >> 8);
  6452. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1A,temp);
  6453. temp = (unsigned short)((tempeax >> 12) & 0x70); /* sic! */
  6454. temp |= (tempcx & 0x4F);
  6455. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x19,temp);
  6456. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  6457. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1C,0x28);
  6458. /* Calc Linebuffer max address and set/clear decimode */
  6459. tempbx = 0;
  6460. if(SiS_Pr->SiS_TVMode & (TVSetHiVision | TVSetYPbPr750p)) tempbx = 0x08;
  6461. tempax = SiS_Pr->SiS_VGAHDE;
  6462. if(modeflag & HalfDCLK) tempax >>= 1;
  6463. if(SiS_IsDualLink(SiS_Pr)) tempax >>= 1;
  6464. if(tempax > 800) {
  6465. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  6466. tempax -= 800;
  6467. } else {
  6468. tempbx = 0x08;
  6469. if(tempax == 960) tempax *= 25; /* Correct */
  6470. else if(tempax == 1024) tempax *= 25;
  6471. else tempax *= 20;
  6472. temp = tempax % 32;
  6473. tempax /= 32;
  6474. if(temp) tempax++;
  6475. tempax++;
  6476. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  6477. if(resinfo == SIS_RI_1024x768 ||
  6478. resinfo == SIS_RI_1024x576 ||
  6479. resinfo == SIS_RI_1280x1024 ||
  6480. resinfo == SIS_RI_1280x720) {
  6481. /* Otherwise white line or garbage at right edge */
  6482. tempax = (tempax & 0xff00) | 0x20;
  6483. }
  6484. }
  6485. }
  6486. }
  6487. tempax--;
  6488. temp = ((tempax >> 4) & 0x30) | tempbx;
  6489. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1D,tempax);
  6490. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1E,temp);
  6491. temp = 0x0036; tempbx = 0xD0;
  6492. if((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->SiS_VBType & VB_SISLVDS)) {
  6493. temp = 0x0026; tempbx = 0xC0; /* See En/DisableBridge() */
  6494. }
  6495. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  6496. if(!(SiS_Pr->SiS_TVMode & (TVSetNTSC1024 | TVSetHiVision | TVSetYPbPr750p | TVSetYPbPr525p))) {
  6497. temp |= 0x01;
  6498. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  6499. if(!(SiS_Pr->SiS_TVMode & TVSetTVSimuMode)) {
  6500. temp &= ~0x01;
  6501. }
  6502. }
  6503. }
  6504. }
  6505. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x1F,tempbx,temp);
  6506. tempbx = SiS_Pr->SiS_HT >> 1;
  6507. if(SiS_IsDualLink(SiS_Pr)) tempbx >>= 1;
  6508. tempbx -= 2;
  6509. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x22,tempbx);
  6510. temp = (tempbx >> 5) & 0x38;
  6511. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x21,0xC0,temp);
  6512. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  6513. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  6514. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x24,0x0e);
  6515. /* LCD-too-dark-error-source, see FinalizeLCD() */
  6516. }
  6517. }
  6518. SiS_SetDualLinkEtc(SiS_Pr);
  6519. } /* 301B */
  6520. SiS_SetCRT2VCLK(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  6521. }
  6522. /*********************************************/
  6523. /* SET PART 5 REGISTER GROUP */
  6524. /*********************************************/
  6525. static void
  6526. SiS_SetGroup5(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  6527. {
  6528. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) return;
  6529. if(SiS_Pr->SiS_ModeType == ModeVGA) {
  6530. if(!(SiS_Pr->SiS_VBInfo & (SetInSlaveMode | LoadDACFlag))) {
  6531. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);
  6532. SiS_LoadDAC(SiS_Pr, ModeNo, ModeIdIndex);
  6533. }
  6534. }
  6535. }
  6536. /*********************************************/
  6537. /* MODIFY CRT1 GROUP FOR SLAVE MODE */
  6538. /*********************************************/
  6539. static bool
  6540. SiS_GetLVDSCRT1Ptr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  6541. unsigned short RefreshRateTableIndex, unsigned short *ResIndex,
  6542. unsigned short *DisplayType)
  6543. {
  6544. unsigned short modeflag = 0;
  6545. bool checkhd = true;
  6546. /* Pass 1:1 not supported here */
  6547. if(ModeNo <= 0x13) {
  6548. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  6549. (*ResIndex) = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  6550. } else {
  6551. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  6552. (*ResIndex) = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  6553. }
  6554. (*ResIndex) &= 0x3F;
  6555. if((SiS_Pr->SiS_IF_DEF_CH70xx) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
  6556. (*DisplayType) = 80;
  6557. if((SiS_Pr->SiS_TVMode & TVSetPAL) && (!(SiS_Pr->SiS_TVMode & TVSetPALM))) {
  6558. (*DisplayType) = 82;
  6559. if(SiS_Pr->SiS_ModeType > ModeVGA) {
  6560. if(SiS_Pr->SiS_CHSOverScan) (*DisplayType) = 84;
  6561. }
  6562. }
  6563. if((*DisplayType) != 84) {
  6564. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) (*DisplayType)++;
  6565. }
  6566. } else {
  6567. (*DisplayType = 0);
  6568. switch(SiS_Pr->SiS_LCDResInfo) {
  6569. case Panel_320x240_1: (*DisplayType) = 50;
  6570. checkhd = false;
  6571. break;
  6572. case Panel_320x240_2: (*DisplayType) = 14;
  6573. break;
  6574. case Panel_320x240_3: (*DisplayType) = 18;
  6575. break;
  6576. case Panel_640x480: (*DisplayType) = 10;
  6577. break;
  6578. case Panel_1024x600: (*DisplayType) = 26;
  6579. break;
  6580. default: return true;
  6581. }
  6582. if(checkhd) {
  6583. if(modeflag & HalfDCLK) (*DisplayType)++;
  6584. }
  6585. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x600) {
  6586. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) (*DisplayType) += 2;
  6587. }
  6588. }
  6589. return true;
  6590. }
  6591. static void
  6592. SiS_ModCRT1CRTC(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  6593. unsigned short RefreshRateTableIndex)
  6594. {
  6595. unsigned short tempah, i, modeflag, j, ResIndex, DisplayType;
  6596. const struct SiS_LVDSCRT1Data *LVDSCRT1Ptr=NULL;
  6597. static const unsigned short CRIdx[] = {
  6598. 0x00, 0x02, 0x03, 0x04, 0x05, 0x06,
  6599. 0x07, 0x10, 0x11, 0x15, 0x16
  6600. };
  6601. if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) ||
  6602. (SiS_Pr->SiS_CustomT == CUT_BARCO1024) ||
  6603. (SiS_Pr->SiS_CustomT == CUT_PANEL848) ||
  6604. (SiS_Pr->SiS_CustomT == CUT_PANEL856) )
  6605. return;
  6606. if(SiS_Pr->SiS_IF_DEF_LVDS) {
  6607. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  6608. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) return;
  6609. }
  6610. } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
  6611. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) return;
  6612. } else return;
  6613. if(SiS_Pr->SiS_LCDInfo & LCDPass11) return;
  6614. if(SiS_Pr->ChipType < SIS_315H) {
  6615. if(SiS_Pr->SiS_SetFlag & SetDOSMode) return;
  6616. }
  6617. if(!(SiS_GetLVDSCRT1Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex,
  6618. &ResIndex, &DisplayType))) {
  6619. return;
  6620. }
  6621. switch(DisplayType) {
  6622. case 50: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1320x240_1; break; /* xSTN */
  6623. case 14: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1320x240_2; break; /* xSTN */
  6624. case 15: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1320x240_2_H; break; /* xSTN */
  6625. case 18: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1320x240_3; break; /* xSTN */
  6626. case 19: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1320x240_3_H; break; /* xSTN */
  6627. case 10: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1640x480_1; break;
  6628. case 11: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1640x480_1_H; break;
  6629. #if 0 /* Works better with calculated numbers */
  6630. case 26: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x600_1; break;
  6631. case 27: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x600_1_H; break;
  6632. case 28: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x600_2; break;
  6633. case 29: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x600_2_H; break;
  6634. #endif
  6635. case 80: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1UNTSC; break;
  6636. case 81: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1ONTSC; break;
  6637. case 82: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1UPAL; break;
  6638. case 83: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1OPAL; break;
  6639. case 84: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1SOPAL; break;
  6640. }
  6641. if(LVDSCRT1Ptr) {
  6642. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x11,0x7f);
  6643. for(i = 0; i <= 10; i++) {
  6644. tempah = (LVDSCRT1Ptr + ResIndex)->CR[i];
  6645. SiS_SetReg(SiS_Pr->SiS_P3d4,CRIdx[i],tempah);
  6646. }
  6647. for(i = 0x0A, j = 11; i <= 0x0C; i++, j++) {
  6648. tempah = (LVDSCRT1Ptr + ResIndex)->CR[j];
  6649. SiS_SetReg(SiS_Pr->SiS_P3c4,i,tempah);
  6650. }
  6651. tempah = (LVDSCRT1Ptr + ResIndex)->CR[14] & 0xE0;
  6652. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0E,0x1f,tempah);
  6653. if(ModeNo <= 0x13) modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  6654. else modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  6655. tempah = ((LVDSCRT1Ptr + ResIndex)->CR[14] & 0x01) << 5;
  6656. if(modeflag & DoubleScanMode) tempah |= 0x80;
  6657. SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x09,~0x020,tempah);
  6658. } else {
  6659. SiS_CalcLCDACRT1Timing(SiS_Pr, ModeNo, ModeIdIndex);
  6660. }
  6661. }
  6662. /*********************************************/
  6663. /* SET CRT2 ECLK */
  6664. /*********************************************/
  6665. static void
  6666. SiS_SetCRT2ECLK(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  6667. unsigned short RefreshRateTableIndex)
  6668. {
  6669. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  6670. unsigned short clkbase, vclkindex = 0;
  6671. unsigned char sr2b, sr2c;
  6672. if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
  6673. SiS_Pr->SiS_SetFlag &= (~ProgrammingCRT2);
  6674. if(SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK == 2) {
  6675. RefreshRateTableIndex--;
  6676. }
  6677. vclkindex = SiS_GetVCLK2Ptr(SiS_Pr, ModeNo, ModeIdIndex,
  6678. RefreshRateTableIndex);
  6679. SiS_Pr->SiS_SetFlag |= ProgrammingCRT2;
  6680. } else {
  6681. vclkindex = SiS_GetVCLK2Ptr(SiS_Pr, ModeNo, ModeIdIndex,
  6682. RefreshRateTableIndex);
  6683. }
  6684. sr2b = SiS_Pr->SiS_VCLKData[vclkindex].SR2B;
  6685. sr2c = SiS_Pr->SiS_VCLKData[vclkindex].SR2C;
  6686. if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) || (SiS_Pr->SiS_CustomT == CUT_BARCO1024)) {
  6687. if(SiS_Pr->SiS_UseROM) {
  6688. if(ROMAddr[0x220] & 0x01) {
  6689. sr2b = ROMAddr[0x227];
  6690. sr2c = ROMAddr[0x228];
  6691. }
  6692. }
  6693. }
  6694. clkbase = 0x02B;
  6695. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  6696. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  6697. clkbase += 3;
  6698. }
  6699. }
  6700. SiS_SetReg(SiS_Pr->SiS_P3c4,0x31,0x20);
  6701. SiS_SetReg(SiS_Pr->SiS_P3c4,clkbase,sr2b);
  6702. SiS_SetReg(SiS_Pr->SiS_P3c4,clkbase+1,sr2c);
  6703. SiS_SetReg(SiS_Pr->SiS_P3c4,0x31,0x10);
  6704. SiS_SetReg(SiS_Pr->SiS_P3c4,clkbase,sr2b);
  6705. SiS_SetReg(SiS_Pr->SiS_P3c4,clkbase+1,sr2c);
  6706. SiS_SetReg(SiS_Pr->SiS_P3c4,0x31,0x00);
  6707. SiS_SetReg(SiS_Pr->SiS_P3c4,clkbase,sr2b);
  6708. SiS_SetReg(SiS_Pr->SiS_P3c4,clkbase+1,sr2c);
  6709. }
  6710. /*********************************************/
  6711. /* SET UP CHRONTEL CHIPS */
  6712. /*********************************************/
  6713. static void
  6714. SiS_SetCHTVReg(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  6715. unsigned short RefreshRateTableIndex)
  6716. {
  6717. unsigned short TVType, resindex;
  6718. const struct SiS_CHTVRegData *CHTVRegData = NULL;
  6719. if(ModeNo <= 0x13)
  6720. resindex = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  6721. else
  6722. resindex = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  6723. resindex &= 0x3F;
  6724. TVType = 0;
  6725. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) TVType += 1;
  6726. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  6727. TVType += 2;
  6728. if(SiS_Pr->SiS_ModeType > ModeVGA) {
  6729. if(SiS_Pr->SiS_CHSOverScan) TVType = 8;
  6730. }
  6731. if(SiS_Pr->SiS_TVMode & TVSetPALM) {
  6732. TVType = 4;
  6733. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) TVType += 1;
  6734. } else if(SiS_Pr->SiS_TVMode & TVSetPALN) {
  6735. TVType = 6;
  6736. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) TVType += 1;
  6737. }
  6738. }
  6739. switch(TVType) {
  6740. case 0: CHTVRegData = SiS_Pr->SiS_CHTVReg_UNTSC; break;
  6741. case 1: CHTVRegData = SiS_Pr->SiS_CHTVReg_ONTSC; break;
  6742. case 2: CHTVRegData = SiS_Pr->SiS_CHTVReg_UPAL; break;
  6743. case 3: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPAL; break;
  6744. case 4: CHTVRegData = SiS_Pr->SiS_CHTVReg_UPALM; break;
  6745. case 5: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPALM; break;
  6746. case 6: CHTVRegData = SiS_Pr->SiS_CHTVReg_UPALN; break;
  6747. case 7: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPALN; break;
  6748. case 8: CHTVRegData = SiS_Pr->SiS_CHTVReg_SOPAL; break;
  6749. default: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPAL; break;
  6750. }
  6751. if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) {
  6752. #ifdef CONFIG_FB_SIS_300
  6753. /* Chrontel 7005 - I assume that it does not come with a 315 series chip */
  6754. /* We don't support modes >800x600 */
  6755. if (resindex > 5) return;
  6756. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  6757. SiS_SetCH700x(SiS_Pr,0x04,0x43); /* 0x40=76uA (PAL); 0x03=15bit non-multi RGB*/
  6758. SiS_SetCH700x(SiS_Pr,0x09,0x69); /* Black level for PAL (105)*/
  6759. } else {
  6760. SiS_SetCH700x(SiS_Pr,0x04,0x03); /* upper nibble=71uA (NTSC), 0x03=15bit non-multi RGB*/
  6761. SiS_SetCH700x(SiS_Pr,0x09,0x71); /* Black level for NTSC (113)*/
  6762. }
  6763. SiS_SetCH700x(SiS_Pr,0x00,CHTVRegData[resindex].Reg[0]); /* Mode register */
  6764. SiS_SetCH700x(SiS_Pr,0x07,CHTVRegData[resindex].Reg[1]); /* Start active video register */
  6765. SiS_SetCH700x(SiS_Pr,0x08,CHTVRegData[resindex].Reg[2]); /* Position overflow register */
  6766. SiS_SetCH700x(SiS_Pr,0x0a,CHTVRegData[resindex].Reg[3]); /* Horiz Position register */
  6767. SiS_SetCH700x(SiS_Pr,0x0b,CHTVRegData[resindex].Reg[4]); /* Vertical Position register */
  6768. /* Set minimum flicker filter for Luma channel (SR1-0=00),
  6769. minimum text enhancement (S3-2=10),
  6770. maximum flicker filter for Chroma channel (S5-4=10)
  6771. =00101000=0x28 (When reading, S1-0->S3-2, and S3-2->S1-0!)
  6772. */
  6773. SiS_SetCH700x(SiS_Pr,0x01,0x28);
  6774. /* Set video bandwidth
  6775. High bandwidth Luma composite video filter(S0=1)
  6776. low bandwidth Luma S-video filter (S2-1=00)
  6777. disable peak filter in S-video channel (S3=0)
  6778. high bandwidth Chroma Filter (S5-4=11)
  6779. =00110001=0x31
  6780. */
  6781. SiS_SetCH700x(SiS_Pr,0x03,0xb1); /* old: 3103 */
  6782. /* Register 0x3D does not exist in non-macrovision register map
  6783. (Maybe this is a macrovision register?)
  6784. */
  6785. #ifndef SIS_CP
  6786. SiS_SetCH70xx(SiS_Pr,0x3d,0x00);
  6787. #endif
  6788. /* Register 0x10 only contains 1 writable bit (S0) for sensing,
  6789. all other bits a read-only. Macrovision?
  6790. */
  6791. SiS_SetCH70xxANDOR(SiS_Pr,0x10,0x00,0x1F);
  6792. /* Register 0x11 only contains 3 writable bits (S0-S2) for
  6793. contrast enhancement (set to 010 -> gain 1 Yout = 17/16*(Yin-30) )
  6794. */
  6795. SiS_SetCH70xxANDOR(SiS_Pr,0x11,0x02,0xF8);
  6796. /* Clear DSEN
  6797. */
  6798. SiS_SetCH70xxANDOR(SiS_Pr,0x1c,0x00,0xEF);
  6799. if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) { /* ---- NTSC ---- */
  6800. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) {
  6801. if(resindex == 0x04) { /* 640x480 overscan: Mode 16 */
  6802. SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x00,0xEF); /* loop filter off */
  6803. SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x01,0xFE); /* ACIV on, no need to set FSCI */
  6804. } else if(resindex == 0x05) { /* 800x600 overscan: Mode 23 */
  6805. SiS_SetCH70xxANDOR(SiS_Pr,0x18,0x01,0xF0); /* 0x18-0x1f: FSCI 469,762,048 */
  6806. SiS_SetCH70xxANDOR(SiS_Pr,0x19,0x0C,0xF0);
  6807. SiS_SetCH70xxANDOR(SiS_Pr,0x1a,0x00,0xF0);
  6808. SiS_SetCH70xxANDOR(SiS_Pr,0x1b,0x00,0xF0);
  6809. SiS_SetCH70xxANDOR(SiS_Pr,0x1c,0x00,0xF0);
  6810. SiS_SetCH70xxANDOR(SiS_Pr,0x1d,0x00,0xF0);
  6811. SiS_SetCH70xxANDOR(SiS_Pr,0x1e,0x00,0xF0);
  6812. SiS_SetCH70xxANDOR(SiS_Pr,0x1f,0x00,0xF0);
  6813. SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x01,0xEF); /* Loop filter on for mode 23 */
  6814. SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x00,0xFE); /* ACIV off, need to set FSCI */
  6815. }
  6816. } else {
  6817. if(resindex == 0x04) { /* ----- 640x480 underscan; Mode 17 */
  6818. SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x00,0xEF); /* loop filter off */
  6819. SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x01,0xFE);
  6820. } else if(resindex == 0x05) { /* ----- 800x600 underscan: Mode 24 */
  6821. #if 0
  6822. SiS_SetCH70xxANDOR(SiS_Pr,0x18,0x01,0xF0); /* (FSCI was 0x1f1c71c7 - this is for mode 22) */
  6823. SiS_SetCH70xxANDOR(SiS_Pr,0x19,0x09,0xF0); /* FSCI for mode 24 is 428,554,851 */
  6824. SiS_SetCH70xxANDOR(SiS_Pr,0x1a,0x08,0xF0); /* 198b3a63 */
  6825. SiS_SetCH70xxANDOR(SiS_Pr,0x1b,0x0b,0xF0);
  6826. SiS_SetCH70xxANDOR(SiS_Pr,0x1c,0x04,0xF0);
  6827. SiS_SetCH70xxANDOR(SiS_Pr,0x1d,0x01,0xF0);
  6828. SiS_SetCH70xxANDOR(SiS_Pr,0x1e,0x06,0xF0);
  6829. SiS_SetCH70xxANDOR(SiS_Pr,0x1f,0x05,0xF0);
  6830. SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x00,0xEF); /* loop filter off for mode 24 */
  6831. SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x00,0xFE); * ACIV off, need to set FSCI */
  6832. #endif /* All alternatives wrong (datasheet wrong?), don't use FSCI */
  6833. SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x00,0xEF); /* loop filter off */
  6834. SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x01,0xFE);
  6835. }
  6836. }
  6837. } else { /* ---- PAL ---- */
  6838. /* We don't play around with FSCI in PAL mode */
  6839. if(resindex == 0x04) {
  6840. SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x00,0xEF); /* loop filter off */
  6841. SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x01,0xFE); /* ACIV on */
  6842. } else {
  6843. SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x00,0xEF); /* loop filter off */
  6844. SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x01,0xFE); /* ACIV on */
  6845. }
  6846. }
  6847. #endif /* 300 */
  6848. } else {
  6849. /* Chrontel 7019 - assumed that it does not come with a 300 series chip */
  6850. #ifdef CONFIG_FB_SIS_315
  6851. unsigned short temp;
  6852. /* We don't support modes >1024x768 */
  6853. if (resindex > 6) return;
  6854. temp = CHTVRegData[resindex].Reg[0];
  6855. if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) temp |= 0x10;
  6856. SiS_SetCH701x(SiS_Pr,0x00,temp);
  6857. SiS_SetCH701x(SiS_Pr,0x01,CHTVRegData[resindex].Reg[1]);
  6858. SiS_SetCH701x(SiS_Pr,0x02,CHTVRegData[resindex].Reg[2]);
  6859. SiS_SetCH701x(SiS_Pr,0x04,CHTVRegData[resindex].Reg[3]);
  6860. SiS_SetCH701x(SiS_Pr,0x03,CHTVRegData[resindex].Reg[4]);
  6861. SiS_SetCH701x(SiS_Pr,0x05,CHTVRegData[resindex].Reg[5]);
  6862. SiS_SetCH701x(SiS_Pr,0x06,CHTVRegData[resindex].Reg[6]);
  6863. temp = CHTVRegData[resindex].Reg[7];
  6864. if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) temp = 0x66;
  6865. SiS_SetCH701x(SiS_Pr,0x07,temp);
  6866. SiS_SetCH701x(SiS_Pr,0x08,CHTVRegData[resindex].Reg[8]);
  6867. SiS_SetCH701x(SiS_Pr,0x15,CHTVRegData[resindex].Reg[9]);
  6868. SiS_SetCH701x(SiS_Pr,0x1f,CHTVRegData[resindex].Reg[10]);
  6869. SiS_SetCH701x(SiS_Pr,0x0c,CHTVRegData[resindex].Reg[11]);
  6870. SiS_SetCH701x(SiS_Pr,0x0d,CHTVRegData[resindex].Reg[12]);
  6871. SiS_SetCH701x(SiS_Pr,0x0e,CHTVRegData[resindex].Reg[13]);
  6872. SiS_SetCH701x(SiS_Pr,0x0f,CHTVRegData[resindex].Reg[14]);
  6873. SiS_SetCH701x(SiS_Pr,0x10,CHTVRegData[resindex].Reg[15]);
  6874. temp = SiS_GetCH701x(SiS_Pr,0x21) & ~0x02;
  6875. /* D1 should be set for PAL, PAL-N and NTSC-J,
  6876. but I won't do that for PAL unless somebody
  6877. tells me to do so. Since the BIOS uses
  6878. non-default CIV values and blacklevels,
  6879. this might be compensated anyway.
  6880. */
  6881. if(SiS_Pr->SiS_TVMode & (TVSetPALN | TVSetNTSCJ)) temp |= 0x02;
  6882. SiS_SetCH701x(SiS_Pr,0x21,temp);
  6883. #endif /* 315 */
  6884. }
  6885. #ifdef SIS_CP
  6886. SIS_CP_INIT301_CP3
  6887. #endif
  6888. }
  6889. #ifdef CONFIG_FB_SIS_315 /* ----------- 315 series only ---------- */
  6890. void
  6891. SiS_Chrontel701xBLOn(struct SiS_Private *SiS_Pr)
  6892. {
  6893. unsigned short temp;
  6894. /* Enable Chrontel 7019 LCD panel backlight */
  6895. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  6896. if(SiS_Pr->ChipType == SIS_740) {
  6897. SiS_SetCH701x(SiS_Pr,0x66,0x65);
  6898. } else {
  6899. temp = SiS_GetCH701x(SiS_Pr,0x66);
  6900. temp |= 0x20;
  6901. SiS_SetCH701x(SiS_Pr,0x66,temp);
  6902. }
  6903. }
  6904. }
  6905. void
  6906. SiS_Chrontel701xBLOff(struct SiS_Private *SiS_Pr)
  6907. {
  6908. unsigned short temp;
  6909. /* Disable Chrontel 7019 LCD panel backlight */
  6910. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  6911. temp = SiS_GetCH701x(SiS_Pr,0x66);
  6912. temp &= 0xDF;
  6913. SiS_SetCH701x(SiS_Pr,0x66,temp);
  6914. }
  6915. }
  6916. static void
  6917. SiS_ChrontelPowerSequencing(struct SiS_Private *SiS_Pr)
  6918. {
  6919. static const unsigned char regtable[] = { 0x67, 0x68, 0x69, 0x6a, 0x6b };
  6920. static const unsigned char table1024_740[] = { 0x01, 0x02, 0x01, 0x01, 0x01 };
  6921. static const unsigned char table1400_740[] = { 0x01, 0x6e, 0x01, 0x01, 0x01 };
  6922. static const unsigned char asus1024_740[] = { 0x19, 0x6e, 0x01, 0x19, 0x09 };
  6923. static const unsigned char asus1400_740[] = { 0x19, 0x6e, 0x01, 0x19, 0x09 };
  6924. static const unsigned char table1024_650[] = { 0x01, 0x02, 0x01, 0x01, 0x02 };
  6925. static const unsigned char table1400_650[] = { 0x01, 0x02, 0x01, 0x01, 0x02 };
  6926. const unsigned char *tableptr = NULL;
  6927. int i;
  6928. /* Set up Power up/down timing */
  6929. if(SiS_Pr->ChipType == SIS_740) {
  6930. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  6931. if(SiS_Pr->SiS_CustomT == CUT_ASUSL3000D) tableptr = asus1024_740;
  6932. else tableptr = table1024_740;
  6933. } else if((SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) ||
  6934. (SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) ||
  6935. (SiS_Pr->SiS_LCDResInfo == Panel_1600x1200)) {
  6936. if(SiS_Pr->SiS_CustomT == CUT_ASUSL3000D) tableptr = asus1400_740;
  6937. else tableptr = table1400_740;
  6938. } else return;
  6939. } else {
  6940. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  6941. tableptr = table1024_650;
  6942. } else if((SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) ||
  6943. (SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) ||
  6944. (SiS_Pr->SiS_LCDResInfo == Panel_1600x1200)) {
  6945. tableptr = table1400_650;
  6946. } else return;
  6947. }
  6948. for(i=0; i<5; i++) {
  6949. SiS_SetCH701x(SiS_Pr, regtable[i], tableptr[i]);
  6950. }
  6951. }
  6952. static void
  6953. SiS_SetCH701xForLCD(struct SiS_Private *SiS_Pr)
  6954. {
  6955. const unsigned char *tableptr = NULL;
  6956. unsigned short tempbh;
  6957. int i;
  6958. static const unsigned char regtable[] = {
  6959. 0x1c, 0x5f, 0x64, 0x6f, 0x70, 0x71,
  6960. 0x72, 0x73, 0x74, 0x76, 0x78, 0x7d, 0x66
  6961. };
  6962. static const unsigned char table1024_740[] = {
  6963. 0x60, 0x02, 0x00, 0x07, 0x40, 0xed,
  6964. 0xa3, 0xc8, 0xc7, 0xac, 0xe0, 0x02, 0x44
  6965. };
  6966. static const unsigned char table1280_740[] = {
  6967. 0x60, 0x03, 0x11, 0x00, 0x40, 0xe3,
  6968. 0xad, 0xdb, 0xf6, 0xac, 0xe0, 0x02, 0x44
  6969. };
  6970. static const unsigned char table1400_740[] = {
  6971. 0x60, 0x03, 0x11, 0x00, 0x40, 0xe3,
  6972. 0xad, 0xdb, 0xf6, 0xac, 0xe0, 0x02, 0x44
  6973. };
  6974. static const unsigned char table1600_740[] = {
  6975. 0x60, 0x04, 0x11, 0x00, 0x40, 0xe3,
  6976. 0xad, 0xde, 0xf6, 0xac, 0x60, 0x1a, 0x44
  6977. };
  6978. static const unsigned char table1024_650[] = {
  6979. 0x60, 0x02, 0x00, 0x07, 0x40, 0xed,
  6980. 0xa3, 0xc8, 0xc7, 0xac, 0x60, 0x02
  6981. };
  6982. static const unsigned char table1280_650[] = {
  6983. 0x60, 0x03, 0x11, 0x00, 0x40, 0xe3,
  6984. 0xad, 0xdb, 0xf6, 0xac, 0xe0, 0x02
  6985. };
  6986. static const unsigned char table1400_650[] = {
  6987. 0x60, 0x03, 0x11, 0x00, 0x40, 0xef,
  6988. 0xad, 0xdb, 0xf6, 0xac, 0x60, 0x02
  6989. };
  6990. static const unsigned char table1600_650[] = {
  6991. 0x60, 0x04, 0x11, 0x00, 0x40, 0xe3,
  6992. 0xad, 0xde, 0xf6, 0xac, 0x60, 0x1a
  6993. };
  6994. if(SiS_Pr->ChipType == SIS_740) {
  6995. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) tableptr = table1024_740;
  6996. else if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) tableptr = table1280_740;
  6997. else if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) tableptr = table1400_740;
  6998. else if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) tableptr = table1600_740;
  6999. else return;
  7000. } else {
  7001. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) tableptr = table1024_650;
  7002. else if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) tableptr = table1280_650;
  7003. else if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) tableptr = table1400_650;
  7004. else if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) tableptr = table1600_650;
  7005. else return;
  7006. }
  7007. tempbh = SiS_GetCH701x(SiS_Pr,0x74);
  7008. if((tempbh == 0xf6) || (tempbh == 0xc7)) {
  7009. tempbh = SiS_GetCH701x(SiS_Pr,0x73);
  7010. if(tempbh == 0xc8) {
  7011. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) return;
  7012. } else if(tempbh == 0xdb) {
  7013. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) return;
  7014. if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) return;
  7015. } else if(tempbh == 0xde) {
  7016. if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) return;
  7017. }
  7018. }
  7019. if(SiS_Pr->ChipType == SIS_740) tempbh = 0x0d;
  7020. else tempbh = 0x0c;
  7021. for(i = 0; i < tempbh; i++) {
  7022. SiS_SetCH701x(SiS_Pr, regtable[i], tableptr[i]);
  7023. }
  7024. SiS_ChrontelPowerSequencing(SiS_Pr);
  7025. tempbh = SiS_GetCH701x(SiS_Pr,0x1e);
  7026. tempbh |= 0xc0;
  7027. SiS_SetCH701x(SiS_Pr,0x1e,tempbh);
  7028. if(SiS_Pr->ChipType == SIS_740) {
  7029. tempbh = SiS_GetCH701x(SiS_Pr,0x1c);
  7030. tempbh &= 0xfb;
  7031. SiS_SetCH701x(SiS_Pr,0x1c,tempbh);
  7032. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2d,0x03);
  7033. tempbh = SiS_GetCH701x(SiS_Pr,0x64);
  7034. tempbh |= 0x40;
  7035. SiS_SetCH701x(SiS_Pr,0x64,tempbh);
  7036. tempbh = SiS_GetCH701x(SiS_Pr,0x03);
  7037. tempbh &= 0x3f;
  7038. SiS_SetCH701x(SiS_Pr,0x03,tempbh);
  7039. }
  7040. }
  7041. static void
  7042. SiS_ChrontelResetVSync(struct SiS_Private *SiS_Pr)
  7043. {
  7044. unsigned char temp, temp1;
  7045. temp1 = SiS_GetCH701x(SiS_Pr,0x49);
  7046. SiS_SetCH701x(SiS_Pr,0x49,0x3e);
  7047. temp = SiS_GetCH701x(SiS_Pr,0x47);
  7048. temp &= 0x7f; /* Use external VSYNC */
  7049. SiS_SetCH701x(SiS_Pr,0x47,temp);
  7050. SiS_LongDelay(SiS_Pr, 3);
  7051. temp = SiS_GetCH701x(SiS_Pr,0x47);
  7052. temp |= 0x80; /* Use internal VSYNC */
  7053. SiS_SetCH701x(SiS_Pr,0x47,temp);
  7054. SiS_SetCH701x(SiS_Pr,0x49,temp1);
  7055. }
  7056. static void
  7057. SiS_Chrontel701xOn(struct SiS_Private *SiS_Pr)
  7058. {
  7059. unsigned short temp;
  7060. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  7061. if(SiS_Pr->ChipType == SIS_740) {
  7062. temp = SiS_GetCH701x(SiS_Pr,0x1c);
  7063. temp |= 0x04; /* Invert XCLK phase */
  7064. SiS_SetCH701x(SiS_Pr,0x1c,temp);
  7065. }
  7066. if(SiS_IsYPbPr(SiS_Pr)) {
  7067. temp = SiS_GetCH701x(SiS_Pr,0x01);
  7068. temp &= 0x3f;
  7069. temp |= 0x80; /* Enable YPrPb (HDTV) */
  7070. SiS_SetCH701x(SiS_Pr,0x01,temp);
  7071. }
  7072. if(SiS_IsChScart(SiS_Pr)) {
  7073. temp = SiS_GetCH701x(SiS_Pr,0x01);
  7074. temp &= 0x3f;
  7075. temp |= 0xc0; /* Enable SCART + CVBS */
  7076. SiS_SetCH701x(SiS_Pr,0x01,temp);
  7077. }
  7078. if(SiS_Pr->ChipType == SIS_740) {
  7079. SiS_ChrontelResetVSync(SiS_Pr);
  7080. SiS_SetCH701x(SiS_Pr,0x49,0x20); /* Enable TV path */
  7081. } else {
  7082. SiS_SetCH701x(SiS_Pr,0x49,0x20); /* Enable TV path */
  7083. temp = SiS_GetCH701x(SiS_Pr,0x49);
  7084. if(SiS_IsYPbPr(SiS_Pr)) {
  7085. temp = SiS_GetCH701x(SiS_Pr,0x73);
  7086. temp |= 0x60;
  7087. SiS_SetCH701x(SiS_Pr,0x73,temp);
  7088. }
  7089. temp = SiS_GetCH701x(SiS_Pr,0x47);
  7090. temp &= 0x7f;
  7091. SiS_SetCH701x(SiS_Pr,0x47,temp);
  7092. SiS_LongDelay(SiS_Pr, 2);
  7093. temp = SiS_GetCH701x(SiS_Pr,0x47);
  7094. temp |= 0x80;
  7095. SiS_SetCH701x(SiS_Pr,0x47,temp);
  7096. }
  7097. }
  7098. }
  7099. static void
  7100. SiS_Chrontel701xOff(struct SiS_Private *SiS_Pr)
  7101. {
  7102. unsigned short temp;
  7103. /* Complete power down of LVDS */
  7104. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  7105. if(SiS_Pr->ChipType == SIS_740) {
  7106. SiS_LongDelay(SiS_Pr, 1);
  7107. SiS_GenericDelay(SiS_Pr, 5887);
  7108. SiS_SetCH701x(SiS_Pr,0x76,0xac);
  7109. SiS_SetCH701x(SiS_Pr,0x66,0x00);
  7110. } else {
  7111. SiS_LongDelay(SiS_Pr, 2);
  7112. temp = SiS_GetCH701x(SiS_Pr,0x76);
  7113. temp &= 0xfc;
  7114. SiS_SetCH701x(SiS_Pr,0x76,temp);
  7115. SiS_SetCH701x(SiS_Pr,0x66,0x00);
  7116. }
  7117. }
  7118. }
  7119. static void
  7120. SiS_ChrontelResetDB(struct SiS_Private *SiS_Pr)
  7121. {
  7122. unsigned short temp;
  7123. if(SiS_Pr->ChipType == SIS_740) {
  7124. temp = SiS_GetCH701x(SiS_Pr,0x4a); /* Version ID */
  7125. temp &= 0x01;
  7126. if(!temp) {
  7127. if(SiS_WeHaveBacklightCtrl(SiS_Pr)) {
  7128. temp = SiS_GetCH701x(SiS_Pr,0x49);
  7129. SiS_SetCH701x(SiS_Pr,0x49,0x3e);
  7130. }
  7131. /* Reset Chrontel 7019 datapath */
  7132. SiS_SetCH701x(SiS_Pr,0x48,0x10);
  7133. SiS_LongDelay(SiS_Pr, 1);
  7134. SiS_SetCH701x(SiS_Pr,0x48,0x18);
  7135. if(SiS_WeHaveBacklightCtrl(SiS_Pr)) {
  7136. SiS_ChrontelResetVSync(SiS_Pr);
  7137. SiS_SetCH701x(SiS_Pr,0x49,temp);
  7138. }
  7139. } else {
  7140. /* Clear/set/clear GPIO */
  7141. temp = SiS_GetCH701x(SiS_Pr,0x5c);
  7142. temp &= 0xef;
  7143. SiS_SetCH701x(SiS_Pr,0x5c,temp);
  7144. temp = SiS_GetCH701x(SiS_Pr,0x5c);
  7145. temp |= 0x10;
  7146. SiS_SetCH701x(SiS_Pr,0x5c,temp);
  7147. temp = SiS_GetCH701x(SiS_Pr,0x5c);
  7148. temp &= 0xef;
  7149. SiS_SetCH701x(SiS_Pr,0x5c,temp);
  7150. temp = SiS_GetCH701x(SiS_Pr,0x61);
  7151. if(!temp) {
  7152. SiS_SetCH701xForLCD(SiS_Pr);
  7153. }
  7154. }
  7155. } else { /* 650 */
  7156. /* Reset Chrontel 7019 datapath */
  7157. SiS_SetCH701x(SiS_Pr,0x48,0x10);
  7158. SiS_LongDelay(SiS_Pr, 1);
  7159. SiS_SetCH701x(SiS_Pr,0x48,0x18);
  7160. }
  7161. }
  7162. static void
  7163. SiS_ChrontelInitTVVSync(struct SiS_Private *SiS_Pr)
  7164. {
  7165. unsigned short temp;
  7166. if(SiS_Pr->ChipType == SIS_740) {
  7167. if(SiS_WeHaveBacklightCtrl(SiS_Pr)) {
  7168. SiS_ChrontelResetVSync(SiS_Pr);
  7169. }
  7170. } else {
  7171. SiS_SetCH701x(SiS_Pr,0x76,0xaf); /* Power up LVDS block */
  7172. temp = SiS_GetCH701x(SiS_Pr,0x49);
  7173. temp &= 1;
  7174. if(temp != 1) { /* TV block powered? (0 = yes, 1 = no) */
  7175. temp = SiS_GetCH701x(SiS_Pr,0x47);
  7176. temp &= 0x70;
  7177. SiS_SetCH701x(SiS_Pr,0x47,temp); /* enable VSYNC */
  7178. SiS_LongDelay(SiS_Pr, 3);
  7179. temp = SiS_GetCH701x(SiS_Pr,0x47);
  7180. temp |= 0x80;
  7181. SiS_SetCH701x(SiS_Pr,0x47,temp); /* disable VSYNC */
  7182. }
  7183. }
  7184. }
  7185. static void
  7186. SiS_ChrontelDoSomething3(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
  7187. {
  7188. unsigned short temp,temp1;
  7189. if(SiS_Pr->ChipType == SIS_740) {
  7190. temp = SiS_GetCH701x(SiS_Pr,0x61);
  7191. if(temp < 1) {
  7192. temp++;
  7193. SiS_SetCH701x(SiS_Pr,0x61,temp);
  7194. }
  7195. SiS_SetCH701x(SiS_Pr,0x66,0x45); /* Panel power on */
  7196. SiS_SetCH701x(SiS_Pr,0x76,0xaf); /* All power on */
  7197. SiS_LongDelay(SiS_Pr, 1);
  7198. SiS_GenericDelay(SiS_Pr, 5887);
  7199. } else { /* 650 */
  7200. temp1 = 0;
  7201. temp = SiS_GetCH701x(SiS_Pr,0x61);
  7202. if(temp < 2) {
  7203. temp++;
  7204. SiS_SetCH701x(SiS_Pr,0x61,temp);
  7205. temp1 = 1;
  7206. }
  7207. SiS_SetCH701x(SiS_Pr,0x76,0xac);
  7208. temp = SiS_GetCH701x(SiS_Pr,0x66);
  7209. temp |= 0x5f;
  7210. SiS_SetCH701x(SiS_Pr,0x66,temp);
  7211. if(ModeNo > 0x13) {
  7212. if(SiS_WeHaveBacklightCtrl(SiS_Pr)) {
  7213. SiS_GenericDelay(SiS_Pr, 1023);
  7214. } else {
  7215. SiS_GenericDelay(SiS_Pr, 767);
  7216. }
  7217. } else {
  7218. if(!temp1)
  7219. SiS_GenericDelay(SiS_Pr, 767);
  7220. }
  7221. temp = SiS_GetCH701x(SiS_Pr,0x76);
  7222. temp |= 0x03;
  7223. SiS_SetCH701x(SiS_Pr,0x76,temp);
  7224. temp = SiS_GetCH701x(SiS_Pr,0x66);
  7225. temp &= 0x7f;
  7226. SiS_SetCH701x(SiS_Pr,0x66,temp);
  7227. SiS_LongDelay(SiS_Pr, 1);
  7228. }
  7229. }
  7230. static void
  7231. SiS_ChrontelDoSomething2(struct SiS_Private *SiS_Pr)
  7232. {
  7233. unsigned short temp;
  7234. SiS_LongDelay(SiS_Pr, 1);
  7235. do {
  7236. temp = SiS_GetCH701x(SiS_Pr,0x66);
  7237. temp &= 0x04; /* PLL stable? -> bail out */
  7238. if(temp == 0x04) break;
  7239. if(SiS_Pr->ChipType == SIS_740) {
  7240. /* Power down LVDS output, PLL normal operation */
  7241. SiS_SetCH701x(SiS_Pr,0x76,0xac);
  7242. }
  7243. SiS_SetCH701xForLCD(SiS_Pr);
  7244. temp = SiS_GetCH701x(SiS_Pr,0x76);
  7245. temp &= 0xfb; /* Reset PLL */
  7246. SiS_SetCH701x(SiS_Pr,0x76,temp);
  7247. SiS_LongDelay(SiS_Pr, 2);
  7248. temp = SiS_GetCH701x(SiS_Pr,0x76);
  7249. temp |= 0x04; /* PLL normal operation */
  7250. SiS_SetCH701x(SiS_Pr,0x76,temp);
  7251. if(SiS_Pr->ChipType == SIS_740) {
  7252. SiS_SetCH701x(SiS_Pr,0x78,0xe0); /* PLL loop filter */
  7253. } else {
  7254. SiS_SetCH701x(SiS_Pr,0x78,0x60);
  7255. }
  7256. SiS_LongDelay(SiS_Pr, 2);
  7257. } while(0);
  7258. SiS_SetCH701x(SiS_Pr,0x77,0x00); /* MV? */
  7259. }
  7260. static void
  7261. SiS_ChrontelDoSomething1(struct SiS_Private *SiS_Pr)
  7262. {
  7263. unsigned short temp;
  7264. temp = SiS_GetCH701x(SiS_Pr,0x03);
  7265. temp |= 0x80; /* Set datapath 1 to TV */
  7266. temp &= 0xbf; /* Set datapath 2 to LVDS */
  7267. SiS_SetCH701x(SiS_Pr,0x03,temp);
  7268. if(SiS_Pr->ChipType == SIS_740) {
  7269. temp = SiS_GetCH701x(SiS_Pr,0x1c);
  7270. temp &= 0xfb; /* Normal XCLK phase */
  7271. SiS_SetCH701x(SiS_Pr,0x1c,temp);
  7272. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2d,0x03);
  7273. temp = SiS_GetCH701x(SiS_Pr,0x64);
  7274. temp |= 0x40; /* ? Bit not defined */
  7275. SiS_SetCH701x(SiS_Pr,0x64,temp);
  7276. temp = SiS_GetCH701x(SiS_Pr,0x03);
  7277. temp &= 0x3f; /* D1 input to both LVDS and TV */
  7278. SiS_SetCH701x(SiS_Pr,0x03,temp);
  7279. if(SiS_Pr->SiS_CustomT == CUT_ASUSL3000D) {
  7280. SiS_SetCH701x(SiS_Pr,0x63,0x40); /* LVDS off */
  7281. SiS_LongDelay(SiS_Pr, 1);
  7282. SiS_SetCH701x(SiS_Pr,0x63,0x00); /* LVDS on */
  7283. SiS_ChrontelResetDB(SiS_Pr);
  7284. SiS_ChrontelDoSomething2(SiS_Pr);
  7285. SiS_ChrontelDoSomething3(SiS_Pr, 0);
  7286. } else {
  7287. temp = SiS_GetCH701x(SiS_Pr,0x66);
  7288. if(temp != 0x45) {
  7289. SiS_ChrontelResetDB(SiS_Pr);
  7290. SiS_ChrontelDoSomething2(SiS_Pr);
  7291. SiS_ChrontelDoSomething3(SiS_Pr, 0);
  7292. }
  7293. }
  7294. } else { /* 650 */
  7295. SiS_ChrontelResetDB(SiS_Pr);
  7296. SiS_ChrontelDoSomething2(SiS_Pr);
  7297. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x34);
  7298. SiS_ChrontelDoSomething3(SiS_Pr,temp);
  7299. SiS_SetCH701x(SiS_Pr,0x76,0xaf); /* All power on, LVDS normal operation */
  7300. }
  7301. }
  7302. #endif /* 315 series */
  7303. /*********************************************/
  7304. /* MAIN: SET CRT2 REGISTER GROUP */
  7305. /*********************************************/
  7306. bool
  7307. SiS_SetCRT2Group(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
  7308. {
  7309. #ifdef CONFIG_FB_SIS_300
  7310. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  7311. #endif
  7312. unsigned short ModeIdIndex, RefreshRateTableIndex;
  7313. SiS_Pr->SiS_SetFlag |= ProgrammingCRT2;
  7314. if(!SiS_Pr->UseCustomMode) {
  7315. SiS_SearchModeID(SiS_Pr, &ModeNo, &ModeIdIndex);
  7316. } else {
  7317. ModeIdIndex = 0;
  7318. }
  7319. /* Used for shifting CR33 */
  7320. SiS_Pr->SiS_SelectCRT2Rate = 4;
  7321. SiS_UnLockCRT2(SiS_Pr);
  7322. RefreshRateTableIndex = SiS_GetRatePtr(SiS_Pr, ModeNo, ModeIdIndex);
  7323. SiS_SaveCRT2Info(SiS_Pr,ModeNo);
  7324. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7325. SiS_DisableBridge(SiS_Pr);
  7326. if((SiS_Pr->SiS_IF_DEF_LVDS == 1) && (SiS_Pr->ChipType == SIS_730)) {
  7327. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,0x80);
  7328. }
  7329. SiS_SetCRT2ModeRegs(SiS_Pr, ModeNo, ModeIdIndex);
  7330. }
  7331. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) {
  7332. SiS_LockCRT2(SiS_Pr);
  7333. SiS_DisplayOn(SiS_Pr);
  7334. return true;
  7335. }
  7336. SiS_GetCRT2Data(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7337. /* Set up Panel Link for LVDS and LCDA */
  7338. SiS_Pr->SiS_LCDHDES = SiS_Pr->SiS_LCDVDES = 0;
  7339. if( (SiS_Pr->SiS_IF_DEF_LVDS == 1) ||
  7340. ((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) ||
  7341. ((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->SiS_VBType & VB_SIS30xBLV)) ) {
  7342. SiS_GetLVDSDesData(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7343. }
  7344. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7345. SiS_SetGroup1(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7346. }
  7347. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  7348. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7349. SiS_SetGroup2(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7350. #ifdef CONFIG_FB_SIS_315
  7351. SiS_SetGroup2_C_ELV(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7352. #endif
  7353. SiS_SetGroup3(SiS_Pr, ModeNo, ModeIdIndex);
  7354. SiS_SetGroup4(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7355. #ifdef CONFIG_FB_SIS_315
  7356. SiS_SetGroup4_C_ELV(SiS_Pr, ModeNo, ModeIdIndex);
  7357. #endif
  7358. SiS_SetGroup5(SiS_Pr, ModeNo, ModeIdIndex);
  7359. SiS_SetCRT2Sync(SiS_Pr, ModeNo, RefreshRateTableIndex);
  7360. /* For 301BDH (Panel link initialization): */
  7361. if((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) {
  7362. if(!((SiS_Pr->SiS_SetFlag & SetDOSMode) && ((ModeNo == 0x03) || (ModeNo == 0x10)))) {
  7363. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  7364. SiS_ModCRT1CRTC(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7365. }
  7366. }
  7367. SiS_SetCRT2ECLK(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7368. }
  7369. }
  7370. } else {
  7371. SiS_SetCRT2Sync(SiS_Pr, ModeNo, RefreshRateTableIndex);
  7372. SiS_ModCRT1CRTC(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex);
  7373. SiS_SetCRT2ECLK(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex);
  7374. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7375. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  7376. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  7377. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  7378. #ifdef CONFIG_FB_SIS_315
  7379. SiS_SetCH701xForLCD(SiS_Pr);
  7380. #endif
  7381. }
  7382. }
  7383. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  7384. SiS_SetCHTVReg(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex);
  7385. }
  7386. }
  7387. }
  7388. }
  7389. #ifdef CONFIG_FB_SIS_300
  7390. if(SiS_Pr->ChipType < SIS_315H) {
  7391. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7392. if(SiS_Pr->SiS_UseOEM) {
  7393. if((SiS_Pr->SiS_UseROM) && (SiS_Pr->SiS_UseOEM == -1)) {
  7394. if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) {
  7395. SiS_OEM300Setting(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7396. }
  7397. } else {
  7398. SiS_OEM300Setting(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7399. }
  7400. }
  7401. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  7402. if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) ||
  7403. (SiS_Pr->SiS_CustomT == CUT_BARCO1024)) {
  7404. SetOEMLCDData2(SiS_Pr, ModeNo, ModeIdIndex,RefreshRateTableIndex);
  7405. }
  7406. SiS_DisplayOn(SiS_Pr);
  7407. }
  7408. }
  7409. }
  7410. #endif
  7411. #ifdef CONFIG_FB_SIS_315
  7412. if(SiS_Pr->ChipType >= SIS_315H) {
  7413. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7414. if(SiS_Pr->ChipType < SIS_661) {
  7415. SiS_FinalizeLCD(SiS_Pr, ModeNo, ModeIdIndex);
  7416. SiS_OEM310Setting(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7417. } else {
  7418. SiS_OEM661Setting(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7419. }
  7420. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x01,0x40);
  7421. }
  7422. }
  7423. #endif
  7424. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7425. SiS_EnableBridge(SiS_Pr);
  7426. }
  7427. SiS_DisplayOn(SiS_Pr);
  7428. if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) {
  7429. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  7430. /* Disable LCD panel when using TV */
  7431. SiS_SetRegSR11ANDOR(SiS_Pr,0xFF,0x0C);
  7432. } else {
  7433. /* Disable TV when using LCD */
  7434. SiS_SetCH70xxANDOR(SiS_Pr,0x0e,0x01,0xf8);
  7435. }
  7436. }
  7437. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7438. SiS_LockCRT2(SiS_Pr);
  7439. }
  7440. return true;
  7441. }
  7442. /*********************************************/
  7443. /* ENABLE/DISABLE LCD BACKLIGHT (SIS) */
  7444. /*********************************************/
  7445. void
  7446. SiS_SiS30xBLOn(struct SiS_Private *SiS_Pr)
  7447. {
  7448. /* Switch on LCD backlight on SiS30xLV */
  7449. SiS_DDC2Delay(SiS_Pr,0xff00);
  7450. if(!(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x26) & 0x02)) {
  7451. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x02);
  7452. SiS_WaitVBRetrace(SiS_Pr);
  7453. }
  7454. if(!(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x26) & 0x01)) {
  7455. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x01);
  7456. }
  7457. }
  7458. void
  7459. SiS_SiS30xBLOff(struct SiS_Private *SiS_Pr)
  7460. {
  7461. /* Switch off LCD backlight on SiS30xLV */
  7462. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFE);
  7463. SiS_DDC2Delay(SiS_Pr,0xff00);
  7464. }
  7465. /*********************************************/
  7466. /* DDC RELATED FUNCTIONS */
  7467. /*********************************************/
  7468. static void
  7469. SiS_SetupDDCN(struct SiS_Private *SiS_Pr)
  7470. {
  7471. SiS_Pr->SiS_DDC_NData = ~SiS_Pr->SiS_DDC_Data;
  7472. SiS_Pr->SiS_DDC_NClk = ~SiS_Pr->SiS_DDC_Clk;
  7473. if((SiS_Pr->SiS_DDC_Index == 0x11) && (SiS_Pr->SiS_SensibleSR11)) {
  7474. SiS_Pr->SiS_DDC_NData &= 0x0f;
  7475. SiS_Pr->SiS_DDC_NClk &= 0x0f;
  7476. }
  7477. }
  7478. #ifdef CONFIG_FB_SIS_300
  7479. static unsigned char *
  7480. SiS_SetTrumpBlockLoop(struct SiS_Private *SiS_Pr, unsigned char *dataptr)
  7481. {
  7482. int i, j, num;
  7483. unsigned short tempah,temp;
  7484. unsigned char *mydataptr;
  7485. for(i=0; i<20; i++) { /* Do 20 attempts to write */
  7486. mydataptr = dataptr;
  7487. num = *mydataptr++;
  7488. if(!num) return mydataptr;
  7489. if(i) {
  7490. SiS_SetStop(SiS_Pr);
  7491. SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT * 2);
  7492. }
  7493. if(SiS_SetStart(SiS_Pr)) continue; /* Set start condition */
  7494. tempah = SiS_Pr->SiS_DDC_DeviceAddr;
  7495. temp = SiS_WriteDDC2Data(SiS_Pr,tempah); /* Write DAB (S0=0=write) */
  7496. if(temp) continue; /* (ERROR: no ack) */
  7497. tempah = *mydataptr++;
  7498. temp = SiS_WriteDDC2Data(SiS_Pr,tempah); /* Write register number */
  7499. if(temp) continue; /* (ERROR: no ack) */
  7500. for(j=0; j<num; j++) {
  7501. tempah = *mydataptr++;
  7502. temp = SiS_WriteDDC2Data(SiS_Pr,tempah);/* Write DAB (S0=0=write) */
  7503. if(temp) break;
  7504. }
  7505. if(temp) continue;
  7506. if(SiS_SetStop(SiS_Pr)) continue;
  7507. return mydataptr;
  7508. }
  7509. return NULL;
  7510. }
  7511. static bool
  7512. SiS_SetTrumpionBlock(struct SiS_Private *SiS_Pr, unsigned char *dataptr)
  7513. {
  7514. SiS_Pr->SiS_DDC_DeviceAddr = 0xF0; /* DAB (Device Address Byte) */
  7515. SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */
  7516. SiS_Pr->SiS_DDC_Data = 0x02; /* Bitmask in IndexReg for Data */
  7517. SiS_Pr->SiS_DDC_Clk = 0x01; /* Bitmask in IndexReg for Clk */
  7518. SiS_SetupDDCN(SiS_Pr);
  7519. SiS_SetSwitchDDC2(SiS_Pr);
  7520. while(*dataptr) {
  7521. dataptr = SiS_SetTrumpBlockLoop(SiS_Pr, dataptr);
  7522. if(!dataptr) return false;
  7523. }
  7524. return true;
  7525. }
  7526. #endif
  7527. /* The Chrontel 700x is connected to the 630/730 via
  7528. * the 630/730's DDC/I2C port.
  7529. *
  7530. * On 630(S)T chipset, the index changed from 0x11 to
  7531. * 0x0a, possibly for working around the DDC problems
  7532. */
  7533. static bool
  7534. SiS_SetChReg(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val, unsigned short myor)
  7535. {
  7536. unsigned short temp, i;
  7537. for(i=0; i<20; i++) { /* Do 20 attempts to write */
  7538. if(i) {
  7539. SiS_SetStop(SiS_Pr);
  7540. SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT * 4);
  7541. }
  7542. if(SiS_SetStart(SiS_Pr)) continue; /* Set start condition */
  7543. temp = SiS_WriteDDC2Data(SiS_Pr, SiS_Pr->SiS_DDC_DeviceAddr); /* Write DAB (S0=0=write) */
  7544. if(temp) continue; /* (ERROR: no ack) */
  7545. temp = SiS_WriteDDC2Data(SiS_Pr, (reg | myor)); /* Write RAB (700x: set bit 7, see datasheet) */
  7546. if(temp) continue; /* (ERROR: no ack) */
  7547. temp = SiS_WriteDDC2Data(SiS_Pr, val); /* Write data */
  7548. if(temp) continue; /* (ERROR: no ack) */
  7549. if(SiS_SetStop(SiS_Pr)) continue; /* Set stop condition */
  7550. SiS_Pr->SiS_ChrontelInit = 1;
  7551. return true;
  7552. }
  7553. return false;
  7554. }
  7555. /* Write to Chrontel 700x */
  7556. void
  7557. SiS_SetCH700x(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val)
  7558. {
  7559. SiS_Pr->SiS_DDC_DeviceAddr = 0xEA; /* DAB (Device Address Byte) */
  7560. SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT);
  7561. if(!(SiS_Pr->SiS_ChrontelInit)) {
  7562. SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */
  7563. SiS_Pr->SiS_DDC_Data = 0x02; /* Bitmask in IndexReg for Data */
  7564. SiS_Pr->SiS_DDC_Clk = 0x01; /* Bitmask in IndexReg for Clk */
  7565. SiS_SetupDDCN(SiS_Pr);
  7566. }
  7567. if( (!(SiS_SetChReg(SiS_Pr, reg, val, 0x80))) &&
  7568. (!(SiS_Pr->SiS_ChrontelInit)) ) {
  7569. SiS_Pr->SiS_DDC_Index = 0x0a;
  7570. SiS_Pr->SiS_DDC_Data = 0x80;
  7571. SiS_Pr->SiS_DDC_Clk = 0x40;
  7572. SiS_SetupDDCN(SiS_Pr);
  7573. SiS_SetChReg(SiS_Pr, reg, val, 0x80);
  7574. }
  7575. }
  7576. /* Write to Chrontel 701x */
  7577. /* Parameter is [Data (S15-S8) | Register no (S7-S0)] */
  7578. void
  7579. SiS_SetCH701x(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val)
  7580. {
  7581. SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */
  7582. SiS_Pr->SiS_DDC_Data = 0x08; /* Bitmask in IndexReg for Data */
  7583. SiS_Pr->SiS_DDC_Clk = 0x04; /* Bitmask in IndexReg for Clk */
  7584. SiS_SetupDDCN(SiS_Pr);
  7585. SiS_Pr->SiS_DDC_DeviceAddr = 0xEA; /* DAB (Device Address Byte) */
  7586. SiS_SetChReg(SiS_Pr, reg, val, 0);
  7587. }
  7588. static
  7589. void
  7590. SiS_SetCH70xx(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val)
  7591. {
  7592. if(SiS_Pr->SiS_IF_DEF_CH70xx == 1)
  7593. SiS_SetCH700x(SiS_Pr, reg, val);
  7594. else
  7595. SiS_SetCH701x(SiS_Pr, reg, val);
  7596. }
  7597. static unsigned short
  7598. SiS_GetChReg(struct SiS_Private *SiS_Pr, unsigned short myor)
  7599. {
  7600. unsigned short tempah, temp, i;
  7601. for(i=0; i<20; i++) { /* Do 20 attempts to read */
  7602. if(i) {
  7603. SiS_SetStop(SiS_Pr);
  7604. SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT * 4);
  7605. }
  7606. if(SiS_SetStart(SiS_Pr)) continue; /* Set start condition */
  7607. temp = SiS_WriteDDC2Data(SiS_Pr,SiS_Pr->SiS_DDC_DeviceAddr); /* Write DAB (S0=0=write) */
  7608. if(temp) continue; /* (ERROR: no ack) */
  7609. temp = SiS_WriteDDC2Data(SiS_Pr,SiS_Pr->SiS_DDC_ReadAddr | myor); /* Write RAB (700x: | 0x80) */
  7610. if(temp) continue; /* (ERROR: no ack) */
  7611. if (SiS_SetStart(SiS_Pr)) continue; /* Re-start */
  7612. temp = SiS_WriteDDC2Data(SiS_Pr,SiS_Pr->SiS_DDC_DeviceAddr | 0x01);/* DAB (S0=1=read) */
  7613. if(temp) continue; /* (ERROR: no ack) */
  7614. tempah = SiS_ReadDDC2Data(SiS_Pr); /* Read byte */
  7615. if(SiS_SetStop(SiS_Pr)) continue; /* Stop condition */
  7616. SiS_Pr->SiS_ChrontelInit = 1;
  7617. return tempah;
  7618. }
  7619. return 0xFFFF;
  7620. }
  7621. /* Read from Chrontel 700x */
  7622. /* Parameter is [Register no (S7-S0)] */
  7623. unsigned short
  7624. SiS_GetCH700x(struct SiS_Private *SiS_Pr, unsigned short tempbx)
  7625. {
  7626. unsigned short result;
  7627. SiS_Pr->SiS_DDC_DeviceAddr = 0xEA; /* DAB */
  7628. SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT);
  7629. if(!(SiS_Pr->SiS_ChrontelInit)) {
  7630. SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */
  7631. SiS_Pr->SiS_DDC_Data = 0x02; /* Bitmask in IndexReg for Data */
  7632. SiS_Pr->SiS_DDC_Clk = 0x01; /* Bitmask in IndexReg for Clk */
  7633. SiS_SetupDDCN(SiS_Pr);
  7634. }
  7635. SiS_Pr->SiS_DDC_ReadAddr = tempbx;
  7636. if( ((result = SiS_GetChReg(SiS_Pr,0x80)) == 0xFFFF) &&
  7637. (!SiS_Pr->SiS_ChrontelInit) ) {
  7638. SiS_Pr->SiS_DDC_Index = 0x0a;
  7639. SiS_Pr->SiS_DDC_Data = 0x80;
  7640. SiS_Pr->SiS_DDC_Clk = 0x40;
  7641. SiS_SetupDDCN(SiS_Pr);
  7642. result = SiS_GetChReg(SiS_Pr,0x80);
  7643. }
  7644. return result;
  7645. }
  7646. /* Read from Chrontel 701x */
  7647. /* Parameter is [Register no (S7-S0)] */
  7648. unsigned short
  7649. SiS_GetCH701x(struct SiS_Private *SiS_Pr, unsigned short tempbx)
  7650. {
  7651. SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */
  7652. SiS_Pr->SiS_DDC_Data = 0x08; /* Bitmask in IndexReg for Data */
  7653. SiS_Pr->SiS_DDC_Clk = 0x04; /* Bitmask in IndexReg for Clk */
  7654. SiS_SetupDDCN(SiS_Pr);
  7655. SiS_Pr->SiS_DDC_DeviceAddr = 0xEA; /* DAB */
  7656. SiS_Pr->SiS_DDC_ReadAddr = tempbx;
  7657. return SiS_GetChReg(SiS_Pr,0);
  7658. }
  7659. /* Read from Chrontel 70xx */
  7660. /* Parameter is [Register no (S7-S0)] */
  7661. static
  7662. unsigned short
  7663. SiS_GetCH70xx(struct SiS_Private *SiS_Pr, unsigned short tempbx)
  7664. {
  7665. if(SiS_Pr->SiS_IF_DEF_CH70xx == 1)
  7666. return SiS_GetCH700x(SiS_Pr, tempbx);
  7667. else
  7668. return SiS_GetCH701x(SiS_Pr, tempbx);
  7669. }
  7670. void
  7671. SiS_SetCH70xxANDOR(struct SiS_Private *SiS_Pr, unsigned short reg,
  7672. unsigned char myor, unsigned short myand)
  7673. {
  7674. unsigned short tempbl;
  7675. tempbl = (SiS_GetCH70xx(SiS_Pr, (reg & 0xFF)) & myand) | myor;
  7676. SiS_SetCH70xx(SiS_Pr, reg, tempbl);
  7677. }
  7678. /* Our own DDC functions */
  7679. static
  7680. unsigned short
  7681. SiS_InitDDCRegs(struct SiS_Private *SiS_Pr, unsigned int VBFlags, int VGAEngine,
  7682. unsigned short adaptnum, unsigned short DDCdatatype, bool checkcr32,
  7683. unsigned int VBFlags2)
  7684. {
  7685. unsigned char ddcdtype[] = { 0xa0, 0xa0, 0xa0, 0xa2, 0xa6 };
  7686. unsigned char flag, cr32;
  7687. unsigned short temp = 0, myadaptnum = adaptnum;
  7688. if(adaptnum != 0) {
  7689. if(!(VBFlags2 & VB2_SISTMDSBRIDGE)) return 0xFFFF;
  7690. if((VBFlags2 & VB2_30xBDH) && (adaptnum == 1)) return 0xFFFF;
  7691. }
  7692. /* adapternum for SiS bridges: 0 = CRT1, 1 = LCD, 2 = VGA2 */
  7693. SiS_Pr->SiS_ChrontelInit = 0; /* force re-detection! */
  7694. SiS_Pr->SiS_DDC_SecAddr = 0;
  7695. SiS_Pr->SiS_DDC_DeviceAddr = ddcdtype[DDCdatatype];
  7696. SiS_Pr->SiS_DDC_Port = SiS_Pr->SiS_P3c4;
  7697. SiS_Pr->SiS_DDC_Index = 0x11;
  7698. flag = 0xff;
  7699. cr32 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x32);
  7700. #if 0
  7701. if(VBFlags2 & VB2_SISBRIDGE) {
  7702. if(myadaptnum == 0) {
  7703. if(!(cr32 & 0x20)) {
  7704. myadaptnum = 2;
  7705. if(!(cr32 & 0x10)) {
  7706. myadaptnum = 1;
  7707. if(!(cr32 & 0x08)) {
  7708. myadaptnum = 0;
  7709. }
  7710. }
  7711. }
  7712. }
  7713. }
  7714. #endif
  7715. if(VGAEngine == SIS_300_VGA) { /* 300 series */
  7716. if(myadaptnum != 0) {
  7717. flag = 0;
  7718. if(VBFlags2 & VB2_SISBRIDGE) {
  7719. SiS_Pr->SiS_DDC_Port = SiS_Pr->SiS_Part4Port;
  7720. SiS_Pr->SiS_DDC_Index = 0x0f;
  7721. }
  7722. }
  7723. if(!(VBFlags2 & VB2_301)) {
  7724. if((cr32 & 0x80) && (checkcr32)) {
  7725. if(myadaptnum >= 1) {
  7726. if(!(cr32 & 0x08)) {
  7727. myadaptnum = 1;
  7728. if(!(cr32 & 0x10)) return 0xFFFF;
  7729. }
  7730. }
  7731. }
  7732. }
  7733. temp = 4 - (myadaptnum * 2);
  7734. if(flag) temp = 0;
  7735. } else { /* 315/330 series */
  7736. /* here we simplify: 0 = CRT1, 1 = CRT2 (VGA, LCD) */
  7737. if(VBFlags2 & VB2_SISBRIDGE) {
  7738. if(myadaptnum == 2) {
  7739. myadaptnum = 1;
  7740. }
  7741. }
  7742. if(myadaptnum == 1) {
  7743. flag = 0;
  7744. if(VBFlags2 & VB2_SISBRIDGE) {
  7745. SiS_Pr->SiS_DDC_Port = SiS_Pr->SiS_Part4Port;
  7746. SiS_Pr->SiS_DDC_Index = 0x0f;
  7747. }
  7748. }
  7749. if((cr32 & 0x80) && (checkcr32)) {
  7750. if(myadaptnum >= 1) {
  7751. if(!(cr32 & 0x08)) {
  7752. myadaptnum = 1;
  7753. if(!(cr32 & 0x10)) return 0xFFFF;
  7754. }
  7755. }
  7756. }
  7757. temp = myadaptnum;
  7758. if(myadaptnum == 1) {
  7759. temp = 0;
  7760. if(VBFlags2 & VB2_LVDS) flag = 0xff;
  7761. }
  7762. if(flag) temp = 0;
  7763. }
  7764. SiS_Pr->SiS_DDC_Data = 0x02 << temp;
  7765. SiS_Pr->SiS_DDC_Clk = 0x01 << temp;
  7766. SiS_SetupDDCN(SiS_Pr);
  7767. return 0;
  7768. }
  7769. static unsigned short
  7770. SiS_WriteDABDDC(struct SiS_Private *SiS_Pr)
  7771. {
  7772. if(SiS_SetStart(SiS_Pr)) return 0xFFFF;
  7773. if(SiS_WriteDDC2Data(SiS_Pr, SiS_Pr->SiS_DDC_DeviceAddr)) {
  7774. return 0xFFFF;
  7775. }
  7776. if(SiS_WriteDDC2Data(SiS_Pr, SiS_Pr->SiS_DDC_SecAddr)) {
  7777. return 0xFFFF;
  7778. }
  7779. return 0;
  7780. }
  7781. static unsigned short
  7782. SiS_PrepareReadDDC(struct SiS_Private *SiS_Pr)
  7783. {
  7784. if(SiS_SetStart(SiS_Pr)) return 0xFFFF;
  7785. if(SiS_WriteDDC2Data(SiS_Pr, (SiS_Pr->SiS_DDC_DeviceAddr | 0x01))) {
  7786. return 0xFFFF;
  7787. }
  7788. return 0;
  7789. }
  7790. static unsigned short
  7791. SiS_PrepareDDC(struct SiS_Private *SiS_Pr)
  7792. {
  7793. if(SiS_WriteDABDDC(SiS_Pr)) SiS_WriteDABDDC(SiS_Pr);
  7794. if(SiS_PrepareReadDDC(SiS_Pr)) return (SiS_PrepareReadDDC(SiS_Pr));
  7795. return 0;
  7796. }
  7797. static void
  7798. SiS_SendACK(struct SiS_Private *SiS_Pr, unsigned short yesno)
  7799. {
  7800. SiS_SetSCLKLow(SiS_Pr);
  7801. if(yesno) {
  7802. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  7803. SiS_Pr->SiS_DDC_Index,
  7804. SiS_Pr->SiS_DDC_NData,
  7805. SiS_Pr->SiS_DDC_Data);
  7806. } else {
  7807. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  7808. SiS_Pr->SiS_DDC_Index,
  7809. SiS_Pr->SiS_DDC_NData,
  7810. 0);
  7811. }
  7812. SiS_SetSCLKHigh(SiS_Pr);
  7813. }
  7814. static unsigned short
  7815. SiS_DoProbeDDC(struct SiS_Private *SiS_Pr)
  7816. {
  7817. unsigned char mask, value;
  7818. unsigned short temp, ret=0;
  7819. bool failed = false;
  7820. SiS_SetSwitchDDC2(SiS_Pr);
  7821. if(SiS_PrepareDDC(SiS_Pr)) {
  7822. SiS_SetStop(SiS_Pr);
  7823. return 0xFFFF;
  7824. }
  7825. mask = 0xf0;
  7826. value = 0x20;
  7827. if(SiS_Pr->SiS_DDC_DeviceAddr == 0xa0) {
  7828. temp = (unsigned char)SiS_ReadDDC2Data(SiS_Pr);
  7829. SiS_SendACK(SiS_Pr, 0);
  7830. if(temp == 0) {
  7831. mask = 0xff;
  7832. value = 0xff;
  7833. } else {
  7834. failed = true;
  7835. ret = 0xFFFF;
  7836. }
  7837. }
  7838. if(!failed) {
  7839. temp = (unsigned char)SiS_ReadDDC2Data(SiS_Pr);
  7840. SiS_SendACK(SiS_Pr, 1);
  7841. temp &= mask;
  7842. if(temp == value) ret = 0;
  7843. else {
  7844. ret = 0xFFFF;
  7845. if(SiS_Pr->SiS_DDC_DeviceAddr == 0xa0) {
  7846. if(temp == 0x30) ret = 0;
  7847. }
  7848. }
  7849. }
  7850. SiS_SetStop(SiS_Pr);
  7851. return ret;
  7852. }
  7853. static
  7854. unsigned short
  7855. SiS_ProbeDDC(struct SiS_Private *SiS_Pr)
  7856. {
  7857. unsigned short flag;
  7858. flag = 0x180;
  7859. SiS_Pr->SiS_DDC_DeviceAddr = 0xa0;
  7860. if(!(SiS_DoProbeDDC(SiS_Pr))) flag |= 0x02;
  7861. SiS_Pr->SiS_DDC_DeviceAddr = 0xa2;
  7862. if(!(SiS_DoProbeDDC(SiS_Pr))) flag |= 0x08;
  7863. SiS_Pr->SiS_DDC_DeviceAddr = 0xa6;
  7864. if(!(SiS_DoProbeDDC(SiS_Pr))) flag |= 0x10;
  7865. if(!(flag & 0x1a)) flag = 0;
  7866. return flag;
  7867. }
  7868. static
  7869. unsigned short
  7870. SiS_ReadDDC(struct SiS_Private *SiS_Pr, unsigned short DDCdatatype, unsigned char *buffer)
  7871. {
  7872. unsigned short flag, length, i;
  7873. unsigned char chksum,gotcha;
  7874. if(DDCdatatype > 4) return 0xFFFF;
  7875. flag = 0;
  7876. SiS_SetSwitchDDC2(SiS_Pr);
  7877. if(!(SiS_PrepareDDC(SiS_Pr))) {
  7878. length = 127;
  7879. if(DDCdatatype != 1) length = 255;
  7880. chksum = 0;
  7881. gotcha = 0;
  7882. for(i=0; i<length; i++) {
  7883. buffer[i] = (unsigned char)SiS_ReadDDC2Data(SiS_Pr);
  7884. chksum += buffer[i];
  7885. gotcha |= buffer[i];
  7886. SiS_SendACK(SiS_Pr, 0);
  7887. }
  7888. buffer[i] = (unsigned char)SiS_ReadDDC2Data(SiS_Pr);
  7889. chksum += buffer[i];
  7890. SiS_SendACK(SiS_Pr, 1);
  7891. if(gotcha) flag = (unsigned short)chksum;
  7892. else flag = 0xFFFF;
  7893. } else {
  7894. flag = 0xFFFF;
  7895. }
  7896. SiS_SetStop(SiS_Pr);
  7897. return flag;
  7898. }
  7899. /* Our private DDC functions
  7900. It complies somewhat with the corresponding VESA function
  7901. in arguments and return values.
  7902. Since this is probably called before the mode is changed,
  7903. we use our pre-detected pSiS-values instead of SiS_Pr as
  7904. regards chipset and video bridge type.
  7905. Arguments:
  7906. adaptnum: 0=CRT1(analog), 1=CRT2/LCD(digital), 2=CRT2/VGA2(analog)
  7907. CRT2 DDC is only supported on SiS301, 301B, 301C, 302B.
  7908. LCDA is CRT1, but DDC is read from CRT2 port.
  7909. DDCdatatype: 0=Probe, 1=EDID, 2=EDID+VDIF, 3=EDID V2 (P&D), 4=EDID V2 (FPDI-2)
  7910. buffer: ptr to 256 data bytes which will be filled with read data.
  7911. Returns 0xFFFF if error, otherwise
  7912. if DDCdatatype > 0: Returns 0 if reading OK (included a correct checksum)
  7913. if DDCdatatype = 0: Returns supported DDC modes
  7914. */
  7915. unsigned short
  7916. SiS_HandleDDC(struct SiS_Private *SiS_Pr, unsigned int VBFlags, int VGAEngine,
  7917. unsigned short adaptnum, unsigned short DDCdatatype, unsigned char *buffer,
  7918. unsigned int VBFlags2)
  7919. {
  7920. unsigned char sr1f, cr17=1;
  7921. unsigned short result;
  7922. if(adaptnum > 2)
  7923. return 0xFFFF;
  7924. if(DDCdatatype > 4)
  7925. return 0xFFFF;
  7926. if((!(VBFlags2 & VB2_VIDEOBRIDGE)) && (adaptnum > 0))
  7927. return 0xFFFF;
  7928. if(SiS_InitDDCRegs(SiS_Pr, VBFlags, VGAEngine, adaptnum, DDCdatatype, false, VBFlags2) == 0xFFFF)
  7929. return 0xFFFF;
  7930. sr1f = SiS_GetReg(SiS_Pr->SiS_P3c4,0x1f);
  7931. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x1f,0x3f,0x04);
  7932. if(VGAEngine == SIS_300_VGA) {
  7933. cr17 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x17) & 0x80;
  7934. if(!cr17) {
  7935. SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x17,0x80);
  7936. SiS_SetReg(SiS_Pr->SiS_P3c4,0x00,0x01);
  7937. SiS_SetReg(SiS_Pr->SiS_P3c4,0x00,0x03);
  7938. }
  7939. }
  7940. if((sr1f) || (!cr17)) {
  7941. SiS_WaitRetrace1(SiS_Pr);
  7942. SiS_WaitRetrace1(SiS_Pr);
  7943. SiS_WaitRetrace1(SiS_Pr);
  7944. SiS_WaitRetrace1(SiS_Pr);
  7945. }
  7946. if(DDCdatatype == 0) {
  7947. result = SiS_ProbeDDC(SiS_Pr);
  7948. } else {
  7949. result = SiS_ReadDDC(SiS_Pr, DDCdatatype, buffer);
  7950. if((!result) && (DDCdatatype == 1)) {
  7951. if((buffer[0] == 0x00) && (buffer[1] == 0xff) &&
  7952. (buffer[2] == 0xff) && (buffer[3] == 0xff) &&
  7953. (buffer[4] == 0xff) && (buffer[5] == 0xff) &&
  7954. (buffer[6] == 0xff) && (buffer[7] == 0x00) &&
  7955. (buffer[0x12] == 1)) {
  7956. if(!SiS_Pr->DDCPortMixup) {
  7957. if(adaptnum == 1) {
  7958. if(!(buffer[0x14] & 0x80)) result = 0xFFFE;
  7959. } else {
  7960. if(buffer[0x14] & 0x80) result = 0xFFFE;
  7961. }
  7962. }
  7963. }
  7964. }
  7965. }
  7966. SiS_SetReg(SiS_Pr->SiS_P3c4,0x1f,sr1f);
  7967. if(VGAEngine == SIS_300_VGA) {
  7968. SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x17,0x7f,cr17);
  7969. }
  7970. return result;
  7971. }
  7972. /* Generic I2C functions for Chrontel & DDC --------- */
  7973. static void
  7974. SiS_SetSwitchDDC2(struct SiS_Private *SiS_Pr)
  7975. {
  7976. SiS_SetSCLKHigh(SiS_Pr);
  7977. SiS_WaitRetrace1(SiS_Pr);
  7978. SiS_SetSCLKLow(SiS_Pr);
  7979. SiS_WaitRetrace1(SiS_Pr);
  7980. }
  7981. unsigned short
  7982. SiS_ReadDDC1Bit(struct SiS_Private *SiS_Pr)
  7983. {
  7984. SiS_WaitRetrace1(SiS_Pr);
  7985. return ((SiS_GetReg(SiS_Pr->SiS_P3c4,0x11) & 0x02) >> 1);
  7986. }
  7987. /* Set I2C start condition */
  7988. /* This is done by a SD high-to-low transition while SC is high */
  7989. static unsigned short
  7990. SiS_SetStart(struct SiS_Private *SiS_Pr)
  7991. {
  7992. if(SiS_SetSCLKLow(SiS_Pr)) return 0xFFFF; /* (SC->low) */
  7993. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  7994. SiS_Pr->SiS_DDC_Index,
  7995. SiS_Pr->SiS_DDC_NData,
  7996. SiS_Pr->SiS_DDC_Data); /* SD->high */
  7997. if(SiS_SetSCLKHigh(SiS_Pr)) return 0xFFFF; /* SC->high */
  7998. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  7999. SiS_Pr->SiS_DDC_Index,
  8000. SiS_Pr->SiS_DDC_NData,
  8001. 0x00); /* SD->low = start condition */
  8002. if(SiS_SetSCLKHigh(SiS_Pr)) return 0xFFFF; /* (SC->low) */
  8003. return 0;
  8004. }
  8005. /* Set I2C stop condition */
  8006. /* This is done by a SD low-to-high transition while SC is high */
  8007. static unsigned short
  8008. SiS_SetStop(struct SiS_Private *SiS_Pr)
  8009. {
  8010. if(SiS_SetSCLKLow(SiS_Pr)) return 0xFFFF; /* (SC->low) */
  8011. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8012. SiS_Pr->SiS_DDC_Index,
  8013. SiS_Pr->SiS_DDC_NData,
  8014. 0x00); /* SD->low */
  8015. if(SiS_SetSCLKHigh(SiS_Pr)) return 0xFFFF; /* SC->high */
  8016. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8017. SiS_Pr->SiS_DDC_Index,
  8018. SiS_Pr->SiS_DDC_NData,
  8019. SiS_Pr->SiS_DDC_Data); /* SD->high = stop condition */
  8020. if(SiS_SetSCLKHigh(SiS_Pr)) return 0xFFFF; /* (SC->high) */
  8021. return 0;
  8022. }
  8023. /* Write 8 bits of data */
  8024. static unsigned short
  8025. SiS_WriteDDC2Data(struct SiS_Private *SiS_Pr, unsigned short tempax)
  8026. {
  8027. unsigned short i,flag,temp;
  8028. flag = 0x80;
  8029. for(i = 0; i < 8; i++) {
  8030. SiS_SetSCLKLow(SiS_Pr); /* SC->low */
  8031. if(tempax & flag) {
  8032. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8033. SiS_Pr->SiS_DDC_Index,
  8034. SiS_Pr->SiS_DDC_NData,
  8035. SiS_Pr->SiS_DDC_Data); /* Write bit (1) to SD */
  8036. } else {
  8037. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8038. SiS_Pr->SiS_DDC_Index,
  8039. SiS_Pr->SiS_DDC_NData,
  8040. 0x00); /* Write bit (0) to SD */
  8041. }
  8042. SiS_SetSCLKHigh(SiS_Pr); /* SC->high */
  8043. flag >>= 1;
  8044. }
  8045. temp = SiS_CheckACK(SiS_Pr); /* Check acknowledge */
  8046. return temp;
  8047. }
  8048. static unsigned short
  8049. SiS_ReadDDC2Data(struct SiS_Private *SiS_Pr)
  8050. {
  8051. unsigned short i, temp, getdata;
  8052. getdata = 0;
  8053. for(i = 0; i < 8; i++) {
  8054. getdata <<= 1;
  8055. SiS_SetSCLKLow(SiS_Pr);
  8056. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8057. SiS_Pr->SiS_DDC_Index,
  8058. SiS_Pr->SiS_DDC_NData,
  8059. SiS_Pr->SiS_DDC_Data);
  8060. SiS_SetSCLKHigh(SiS_Pr);
  8061. temp = SiS_GetReg(SiS_Pr->SiS_DDC_Port,SiS_Pr->SiS_DDC_Index);
  8062. if(temp & SiS_Pr->SiS_DDC_Data) getdata |= 0x01;
  8063. }
  8064. return getdata;
  8065. }
  8066. static unsigned short
  8067. SiS_SetSCLKLow(struct SiS_Private *SiS_Pr)
  8068. {
  8069. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8070. SiS_Pr->SiS_DDC_Index,
  8071. SiS_Pr->SiS_DDC_NClk,
  8072. 0x00); /* SetSCLKLow() */
  8073. SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT);
  8074. return 0;
  8075. }
  8076. static unsigned short
  8077. SiS_SetSCLKHigh(struct SiS_Private *SiS_Pr)
  8078. {
  8079. unsigned short temp, watchdog=1000;
  8080. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8081. SiS_Pr->SiS_DDC_Index,
  8082. SiS_Pr->SiS_DDC_NClk,
  8083. SiS_Pr->SiS_DDC_Clk); /* SetSCLKHigh() */
  8084. do {
  8085. temp = SiS_GetReg(SiS_Pr->SiS_DDC_Port,SiS_Pr->SiS_DDC_Index);
  8086. } while((!(temp & SiS_Pr->SiS_DDC_Clk)) && --watchdog);
  8087. if (!watchdog) {
  8088. return 0xFFFF;
  8089. }
  8090. SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT);
  8091. return 0;
  8092. }
  8093. /* Check I2C acknowledge */
  8094. /* Returns 0 if ack ok, non-0 if ack not ok */
  8095. static unsigned short
  8096. SiS_CheckACK(struct SiS_Private *SiS_Pr)
  8097. {
  8098. unsigned short tempah;
  8099. SiS_SetSCLKLow(SiS_Pr); /* (SC->low) */
  8100. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8101. SiS_Pr->SiS_DDC_Index,
  8102. SiS_Pr->SiS_DDC_NData,
  8103. SiS_Pr->SiS_DDC_Data); /* (SD->high) */
  8104. SiS_SetSCLKHigh(SiS_Pr); /* SC->high = clock impulse for ack */
  8105. tempah = SiS_GetReg(SiS_Pr->SiS_DDC_Port,SiS_Pr->SiS_DDC_Index); /* Read SD */
  8106. SiS_SetSCLKLow(SiS_Pr); /* SC->low = end of clock impulse */
  8107. if(tempah & SiS_Pr->SiS_DDC_Data) return 1; /* Ack OK if bit = 0 */
  8108. return 0;
  8109. }
  8110. /* End of I2C functions ----------------------- */
  8111. /* =============== SiS 315/330 O.E.M. ================= */
  8112. #ifdef CONFIG_FB_SIS_315
  8113. static unsigned short
  8114. GetRAMDACromptr(struct SiS_Private *SiS_Pr)
  8115. {
  8116. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  8117. unsigned short romptr;
  8118. if(SiS_Pr->ChipType < SIS_330) {
  8119. romptr = SISGETROMW(0x128);
  8120. if(SiS_Pr->SiS_VBType & VB_SIS30xB)
  8121. romptr = SISGETROMW(0x12a);
  8122. } else {
  8123. romptr = SISGETROMW(0x1a8);
  8124. if(SiS_Pr->SiS_VBType & VB_SIS30xB)
  8125. romptr = SISGETROMW(0x1aa);
  8126. }
  8127. return romptr;
  8128. }
  8129. static unsigned short
  8130. GetLCDromptr(struct SiS_Private *SiS_Pr)
  8131. {
  8132. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  8133. unsigned short romptr;
  8134. if(SiS_Pr->ChipType < SIS_330) {
  8135. romptr = SISGETROMW(0x120);
  8136. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV)
  8137. romptr = SISGETROMW(0x122);
  8138. } else {
  8139. romptr = SISGETROMW(0x1a0);
  8140. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV)
  8141. romptr = SISGETROMW(0x1a2);
  8142. }
  8143. return romptr;
  8144. }
  8145. static unsigned short
  8146. GetTVromptr(struct SiS_Private *SiS_Pr)
  8147. {
  8148. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  8149. unsigned short romptr;
  8150. if(SiS_Pr->ChipType < SIS_330) {
  8151. romptr = SISGETROMW(0x114);
  8152. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV)
  8153. romptr = SISGETROMW(0x11a);
  8154. } else {
  8155. romptr = SISGETROMW(0x194);
  8156. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV)
  8157. romptr = SISGETROMW(0x19a);
  8158. }
  8159. return romptr;
  8160. }
  8161. static unsigned short
  8162. GetLCDPtrIndexBIOS(struct SiS_Private *SiS_Pr)
  8163. {
  8164. unsigned short index;
  8165. if((IS_SIS650) && (SiS_Pr->SiS_VBType & VB_SISLVDS)) {
  8166. if(!(SiS_IsNotM650orLater(SiS_Pr))) {
  8167. if((index = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) & 0xf0)) {
  8168. index >>= 4;
  8169. index *= 3;
  8170. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) index += 2;
  8171. else if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) index++;
  8172. return index;
  8173. }
  8174. }
  8175. }
  8176. index = SiS_GetBIOSLCDResInfo(SiS_Pr) & 0x0F;
  8177. if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) index -= 5;
  8178. if(SiS_Pr->SiS_VBType & VB_SIS301C) { /* 1.15.20 and later (not VB specific) */
  8179. if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) index -= 5;
  8180. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x768) index -= 5;
  8181. } else {
  8182. if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) index -= 6;
  8183. }
  8184. index--;
  8185. index *= 3;
  8186. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) index += 2;
  8187. else if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) index++;
  8188. return index;
  8189. }
  8190. static unsigned short
  8191. GetLCDPtrIndex(struct SiS_Private *SiS_Pr)
  8192. {
  8193. unsigned short index;
  8194. index = ((SiS_GetBIOSLCDResInfo(SiS_Pr) & 0x0F) - 1) * 3;
  8195. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) index += 2;
  8196. else if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) index++;
  8197. return index;
  8198. }
  8199. static unsigned short
  8200. GetTVPtrIndex(struct SiS_Private *SiS_Pr)
  8201. {
  8202. unsigned short index;
  8203. index = 0;
  8204. if(SiS_Pr->SiS_TVMode & TVSetPAL) index = 1;
  8205. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) index = 2;
  8206. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) index = 0;
  8207. index <<= 1;
  8208. if((SiS_Pr->SiS_VBInfo & SetInSlaveMode) &&
  8209. (SiS_Pr->SiS_TVMode & TVSetTVSimuMode)) {
  8210. index++;
  8211. }
  8212. return index;
  8213. }
  8214. static unsigned int
  8215. GetOEMTVPtr661_2_GEN(struct SiS_Private *SiS_Pr, int addme)
  8216. {
  8217. unsigned short index = 0, temp = 0;
  8218. if(SiS_Pr->SiS_TVMode & TVSetPAL) index = 1;
  8219. if(SiS_Pr->SiS_TVMode & TVSetPALM) index = 2;
  8220. if(SiS_Pr->SiS_TVMode & TVSetPALN) index = 3;
  8221. if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) index = 6;
  8222. if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) {
  8223. index = 4;
  8224. if(SiS_Pr->SiS_TVMode & TVSetPALM) index++;
  8225. if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) index = 7;
  8226. }
  8227. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  8228. if((!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) ||
  8229. (SiS_Pr->SiS_TVMode & TVSetTVSimuMode)) {
  8230. index += addme;
  8231. temp++;
  8232. }
  8233. temp += 0x0100;
  8234. }
  8235. return (unsigned int)(index | (temp << 16));
  8236. }
  8237. static unsigned int
  8238. GetOEMTVPtr661_2_OLD(struct SiS_Private *SiS_Pr)
  8239. {
  8240. return (GetOEMTVPtr661_2_GEN(SiS_Pr, 8));
  8241. }
  8242. #if 0
  8243. static unsigned int
  8244. GetOEMTVPtr661_2_NEW(struct SiS_Private *SiS_Pr)
  8245. {
  8246. return (GetOEMTVPtr661_2_GEN(SiS_Pr, 6));
  8247. }
  8248. #endif
  8249. static int
  8250. GetOEMTVPtr661(struct SiS_Private *SiS_Pr)
  8251. {
  8252. int index = 0;
  8253. if(SiS_Pr->SiS_TVMode & TVSetPAL) index = 2;
  8254. if(SiS_Pr->SiS_ROMNew) {
  8255. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525i) index = 4;
  8256. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) index = 6;
  8257. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) index = 8;
  8258. if(SiS_Pr->SiS_TVMode & TVSetHiVision) index = 10;
  8259. } else {
  8260. if(SiS_Pr->SiS_TVMode & TVSetHiVision) index = 4;
  8261. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525i) index = 6;
  8262. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) index = 8;
  8263. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) index = 10;
  8264. }
  8265. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) index++;
  8266. return index;
  8267. }
  8268. static void
  8269. SetDelayComp(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
  8270. {
  8271. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  8272. unsigned short delay=0,index,myindex,temp,romptr=0;
  8273. bool dochiptest = true;
  8274. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  8275. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x20,0xbf);
  8276. } else {
  8277. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x35,0x7f);
  8278. }
  8279. /* Find delay (from ROM, internal tables, PCI subsystem) */
  8280. if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) { /* ------------ VGA */
  8281. if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
  8282. romptr = GetRAMDACromptr(SiS_Pr);
  8283. }
  8284. if(romptr) delay = ROMAddr[romptr];
  8285. else {
  8286. delay = 0x04;
  8287. if(SiS_Pr->SiS_VBType & VB_SIS30xB) {
  8288. if(IS_SIS650) {
  8289. delay = 0x0a;
  8290. } else if(IS_SIS740) {
  8291. delay = 0x00;
  8292. } else if(SiS_Pr->ChipType < SIS_330) {
  8293. delay = 0x0c;
  8294. } else {
  8295. delay = 0x0c;
  8296. }
  8297. } else if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  8298. delay = 0x00;
  8299. }
  8300. }
  8301. } else if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD|SetCRT2ToLCDA)) { /* ---------- LCD/LCDA */
  8302. bool gotitfrompci = false;
  8303. /* Could we detect a PDC for LCD or did we get a user-defined? If yes, use it */
  8304. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  8305. if(SiS_Pr->PDC != -1) {
  8306. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0xf0,((SiS_Pr->PDC >> 1) & 0x0f));
  8307. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x35,0x7f,((SiS_Pr->PDC & 0x01) << 7));
  8308. return;
  8309. }
  8310. } else {
  8311. if(SiS_Pr->PDCA != -1) {
  8312. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0x0f,((SiS_Pr->PDCA << 3) & 0xf0));
  8313. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x20,0xbf,((SiS_Pr->PDCA & 0x01) << 6));
  8314. return;
  8315. }
  8316. }
  8317. /* Custom Panel? */
  8318. if(SiS_Pr->SiS_LCDResInfo == Panel_Custom) {
  8319. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  8320. delay = 0x00;
  8321. if((SiS_Pr->PanelXRes <= 1280) && (SiS_Pr->PanelYRes <= 1024)) {
  8322. delay = 0x20;
  8323. }
  8324. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0x0f,delay);
  8325. } else {
  8326. delay = 0x0c;
  8327. if(SiS_Pr->SiS_VBType & VB_SIS301C) {
  8328. delay = 0x03;
  8329. if((SiS_Pr->PanelXRes > 1280) && (SiS_Pr->PanelYRes > 1024)) {
  8330. delay = 0x00;
  8331. }
  8332. } else if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  8333. if(IS_SIS740) delay = 0x01;
  8334. else delay = 0x03;
  8335. }
  8336. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0xf0,delay);
  8337. }
  8338. return;
  8339. }
  8340. /* This is a piece of typical SiS crap: They code the OEM LCD
  8341. * delay into the code, at no defined place in the BIOS.
  8342. * We now have to start doing a PCI subsystem check here.
  8343. */
  8344. switch(SiS_Pr->SiS_CustomT) {
  8345. case CUT_COMPAQ1280:
  8346. case CUT_COMPAQ12802:
  8347. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) {
  8348. gotitfrompci = true;
  8349. dochiptest = false;
  8350. delay = 0x03;
  8351. }
  8352. break;
  8353. case CUT_CLEVO1400:
  8354. case CUT_CLEVO14002:
  8355. gotitfrompci = true;
  8356. dochiptest = false;
  8357. delay = 0x02;
  8358. break;
  8359. case CUT_CLEVO1024:
  8360. case CUT_CLEVO10242:
  8361. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  8362. gotitfrompci = true;
  8363. dochiptest = false;
  8364. delay = 0x33;
  8365. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2D,delay);
  8366. delay &= 0x0f;
  8367. }
  8368. break;
  8369. }
  8370. /* Could we find it through the PCI ID? If no, use ROM or table */
  8371. if(!gotitfrompci) {
  8372. index = GetLCDPtrIndexBIOS(SiS_Pr);
  8373. myindex = GetLCDPtrIndex(SiS_Pr);
  8374. if(IS_SIS650 && (SiS_Pr->SiS_VBType & VB_SISLVDS)) {
  8375. if(SiS_IsNotM650orLater(SiS_Pr)) {
  8376. if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
  8377. /* Always use the second pointer on 650; some BIOSes */
  8378. /* still carry old 301 data at the first location */
  8379. /* romptr = SISGETROMW(0x120); */
  8380. /* if(SiS_Pr->SiS_VBType & VB_SIS302LV) */
  8381. romptr = SISGETROMW(0x122);
  8382. if(!romptr) return;
  8383. delay = ROMAddr[(romptr + index)];
  8384. } else {
  8385. delay = SiS310_LCDDelayCompensation_650301LV[myindex];
  8386. }
  8387. } else {
  8388. delay = SiS310_LCDDelayCompensation_651301LV[myindex];
  8389. if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV))
  8390. delay = SiS310_LCDDelayCompensation_651302LV[myindex];
  8391. }
  8392. } else if(SiS_Pr->SiS_UseROM &&
  8393. (!(SiS_Pr->SiS_ROMNew)) &&
  8394. (SiS_Pr->SiS_LCDResInfo != Panel_1280x1024) &&
  8395. (SiS_Pr->SiS_LCDResInfo != Panel_1280x768) &&
  8396. (SiS_Pr->SiS_LCDResInfo != Panel_1280x960) &&
  8397. (SiS_Pr->SiS_LCDResInfo != Panel_1600x1200) &&
  8398. ((romptr = GetLCDromptr(SiS_Pr)))) {
  8399. /* Data for 1280x1024 wrong in 301B BIOS */
  8400. /* Data for 1600x1200 wrong in 301C BIOS */
  8401. delay = ROMAddr[(romptr + index)];
  8402. } else if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  8403. if(IS_SIS740) delay = 0x03;
  8404. else delay = 0x00;
  8405. } else {
  8406. delay = SiS310_LCDDelayCompensation_301[myindex];
  8407. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  8408. if(IS_SIS740) delay = 0x01;
  8409. else if(SiS_Pr->ChipType <= SIS_315PRO) delay = SiS310_LCDDelayCompensation_3xx301LV[myindex];
  8410. else delay = SiS310_LCDDelayCompensation_650301LV[myindex];
  8411. } else if(SiS_Pr->SiS_VBType & VB_SIS301C) {
  8412. if(IS_SIS740) delay = 0x01; /* ? */
  8413. else delay = 0x03;
  8414. if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) delay = 0x00; /* experience */
  8415. } else if(SiS_Pr->SiS_VBType & VB_SIS30xB) {
  8416. if(IS_SIS740) delay = 0x01;
  8417. else delay = SiS310_LCDDelayCompensation_3xx301B[myindex];
  8418. }
  8419. }
  8420. } /* got it from PCI */
  8421. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  8422. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,0x0F,((delay << 4) & 0xf0));
  8423. dochiptest = false;
  8424. }
  8425. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { /* ------------ TV */
  8426. index = GetTVPtrIndex(SiS_Pr);
  8427. if(IS_SIS650 && (SiS_Pr->SiS_VBType & VB_SISLVDS)) {
  8428. if(SiS_IsNotM650orLater(SiS_Pr)) {
  8429. if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
  8430. /* Always use the second pointer on 650; some BIOSes */
  8431. /* still carry old 301 data at the first location */
  8432. /* romptr = SISGETROMW(0x114); */
  8433. /* if(SiS_Pr->SiS_VBType & VB_SIS302LV) */
  8434. romptr = SISGETROMW(0x11a);
  8435. if(!romptr) return;
  8436. delay = ROMAddr[romptr + index];
  8437. } else {
  8438. delay = SiS310_TVDelayCompensation_301B[index];
  8439. }
  8440. } else {
  8441. switch(SiS_Pr->SiS_CustomT) {
  8442. case CUT_COMPAQ1280:
  8443. case CUT_COMPAQ12802:
  8444. case CUT_CLEVO1400:
  8445. case CUT_CLEVO14002:
  8446. delay = 0x02;
  8447. dochiptest = false;
  8448. break;
  8449. case CUT_CLEVO1024:
  8450. case CUT_CLEVO10242:
  8451. delay = 0x03;
  8452. dochiptest = false;
  8453. break;
  8454. default:
  8455. delay = SiS310_TVDelayCompensation_651301LV[index];
  8456. if(SiS_Pr->SiS_VBType & VB_SIS302LV) {
  8457. delay = SiS310_TVDelayCompensation_651302LV[index];
  8458. }
  8459. }
  8460. }
  8461. } else if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
  8462. romptr = GetTVromptr(SiS_Pr);
  8463. if(!romptr) return;
  8464. delay = ROMAddr[romptr + index];
  8465. } else if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  8466. delay = SiS310_TVDelayCompensation_LVDS[index];
  8467. } else {
  8468. delay = SiS310_TVDelayCompensation_301[index];
  8469. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  8470. if(IS_SIS740) {
  8471. delay = SiS310_TVDelayCompensation_740301B[index];
  8472. /* LV: use 301 data? BIOS bug? */
  8473. } else {
  8474. delay = SiS310_TVDelayCompensation_301B[index];
  8475. if(SiS_Pr->SiS_VBType & VB_SIS301C) delay = 0x02;
  8476. }
  8477. }
  8478. }
  8479. if(SiS_LCDAEnabled(SiS_Pr)) {
  8480. delay &= 0x0f;
  8481. dochiptest = false;
  8482. }
  8483. } else return;
  8484. /* Write delay */
  8485. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  8486. if(IS_SIS650 && (SiS_Pr->SiS_VBType & VB_SISLVDS) && dochiptest) {
  8487. temp = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) & 0xf0) >> 4;
  8488. if(temp == 8) { /* 1400x1050 BIOS (COMPAL) */
  8489. delay &= 0x0f;
  8490. delay |= 0xb0;
  8491. } else if(temp == 6) {
  8492. delay &= 0x0f;
  8493. delay |= 0xc0;
  8494. } else if(temp > 7) { /* 1280x1024 BIOS (which one?) */
  8495. delay = 0x35;
  8496. }
  8497. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2D,delay);
  8498. } else {
  8499. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,0xF0,delay);
  8500. }
  8501. } else { /* LVDS */
  8502. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  8503. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,0xF0,delay);
  8504. } else {
  8505. if(IS_SIS650 && (SiS_Pr->SiS_IF_DEF_CH70xx != 0)) {
  8506. delay <<= 4;
  8507. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,0x0F,delay);
  8508. } else {
  8509. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,0xF0,delay);
  8510. }
  8511. }
  8512. }
  8513. }
  8514. static void
  8515. SetAntiFlicker(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  8516. {
  8517. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  8518. unsigned short index,temp,temp1,romptr=0;
  8519. if(SiS_Pr->SiS_TVMode & (TVSetYPbPr750p|TVSetYPbPr525p)) return;
  8520. if(ModeNo<=0x13)
  8521. index = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].VB_StTVFlickerIndex;
  8522. else
  8523. index = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].VB_ExtTVFlickerIndex;
  8524. temp = GetTVPtrIndex(SiS_Pr);
  8525. temp >>= 1; /* 0: NTSC/YPbPr, 1: PAL, 2: HiTV */
  8526. temp1 = temp;
  8527. if(SiS_Pr->SiS_UseROM && (!(SiS_Pr->SiS_ROMNew))) {
  8528. if(SiS_Pr->ChipType >= SIS_661) {
  8529. temp1 = GetOEMTVPtr661(SiS_Pr);
  8530. temp1 >>= 1;
  8531. romptr = SISGETROMW(0x260);
  8532. if(SiS_Pr->ChipType >= SIS_760) {
  8533. romptr = SISGETROMW(0x360);
  8534. }
  8535. } else if(SiS_Pr->ChipType >= SIS_330) {
  8536. romptr = SISGETROMW(0x192);
  8537. } else {
  8538. romptr = SISGETROMW(0x112);
  8539. }
  8540. }
  8541. if(romptr) {
  8542. temp1 <<= 1;
  8543. temp = ROMAddr[romptr + temp1 + index];
  8544. } else {
  8545. temp = SiS310_TVAntiFlick1[temp][index];
  8546. }
  8547. temp <<= 4;
  8548. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x0A,0x8f,temp); /* index 0A D[6:4] */
  8549. }
  8550. static void
  8551. SetEdgeEnhance(struct SiS_Private *SiS_Pr, unsigned short ModeNo,unsigned short ModeIdIndex)
  8552. {
  8553. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  8554. unsigned short index,temp,temp1,romptr=0;
  8555. temp = temp1 = GetTVPtrIndex(SiS_Pr) >> 1; /* 0: NTSC/YPbPr, 1: PAL, 2: HiTV */
  8556. if(ModeNo <= 0x13)
  8557. index = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].VB_StTVEdgeIndex;
  8558. else
  8559. index = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].VB_ExtTVEdgeIndex;
  8560. if(SiS_Pr->SiS_UseROM && (!(SiS_Pr->SiS_ROMNew))) {
  8561. if(SiS_Pr->ChipType >= SIS_661) {
  8562. romptr = SISGETROMW(0x26c);
  8563. if(SiS_Pr->ChipType >= SIS_760) {
  8564. romptr = SISGETROMW(0x36c);
  8565. }
  8566. temp1 = GetOEMTVPtr661(SiS_Pr);
  8567. temp1 >>= 1;
  8568. } else if(SiS_Pr->ChipType >= SIS_330) {
  8569. romptr = SISGETROMW(0x1a4);
  8570. } else {
  8571. romptr = SISGETROMW(0x124);
  8572. }
  8573. }
  8574. if(romptr) {
  8575. temp1 <<= 1;
  8576. temp = ROMAddr[romptr + temp1 + index];
  8577. } else {
  8578. temp = SiS310_TVEdge1[temp][index];
  8579. }
  8580. temp <<= 5;
  8581. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x3A,0x1F,temp); /* index 0A D[7:5] */
  8582. }
  8583. static void
  8584. SetYFilter(struct SiS_Private *SiS_Pr, unsigned short ModeNo,unsigned short ModeIdIndex)
  8585. {
  8586. unsigned short index, temp, i, j;
  8587. if(ModeNo <= 0x13) {
  8588. index = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].VB_StTVYFilterIndex;
  8589. } else {
  8590. index = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].VB_ExtTVYFilterIndex;
  8591. }
  8592. temp = GetTVPtrIndex(SiS_Pr) >> 1; /* 0: NTSC/YPbPr, 1: PAL, 2: HiTV */
  8593. if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) temp = 1; /* NTSC-J uses PAL */
  8594. else if(SiS_Pr->SiS_TVMode & TVSetPALM) temp = 3; /* PAL-M */
  8595. else if(SiS_Pr->SiS_TVMode & TVSetPALN) temp = 4; /* PAL-N */
  8596. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) temp = 1; /* HiVision uses PAL */
  8597. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  8598. for(i=0x35, j=0; i<=0x38; i++, j++) {
  8599. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVYFilter2[temp][index][j]);
  8600. }
  8601. for(i=0x48; i<=0x4A; i++, j++) {
  8602. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVYFilter2[temp][index][j]);
  8603. }
  8604. } else {
  8605. for(i=0x35, j=0; i<=0x38; i++, j++) {
  8606. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVYFilter1[temp][index][j]);
  8607. }
  8608. }
  8609. }
  8610. static void
  8611. SetPhaseIncr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  8612. {
  8613. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  8614. unsigned short index,temp,i,j,resinfo,romptr=0;
  8615. unsigned int lindex;
  8616. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) return;
  8617. /* NTSC-J data not in BIOS, and already set in SetGroup2 */
  8618. if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) return;
  8619. if((SiS_Pr->ChipType >= SIS_661) || SiS_Pr->SiS_ROMNew) {
  8620. lindex = GetOEMTVPtr661_2_OLD(SiS_Pr) & 0xffff;
  8621. lindex <<= 2;
  8622. for(j=0, i=0x31; i<=0x34; i++, j++) {
  8623. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS_TVPhase[lindex + j]);
  8624. }
  8625. return;
  8626. }
  8627. /* PAL-M, PAL-N not in BIOS, and already set in SetGroup2 */
  8628. if(SiS_Pr->SiS_TVMode & (TVSetPALM | TVSetPALN)) return;
  8629. if(ModeNo<=0x13) {
  8630. resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
  8631. } else {
  8632. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  8633. }
  8634. temp = GetTVPtrIndex(SiS_Pr);
  8635. /* 0: NTSC Graphics, 1: NTSC Text, 2: PAL Graphics,
  8636. * 3: PAL Text, 4: HiTV Graphics 5: HiTV Text
  8637. */
  8638. if(SiS_Pr->SiS_UseROM) {
  8639. romptr = SISGETROMW(0x116);
  8640. if(SiS_Pr->ChipType >= SIS_330) {
  8641. romptr = SISGETROMW(0x196);
  8642. }
  8643. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  8644. romptr = SISGETROMW(0x11c);
  8645. if(SiS_Pr->ChipType >= SIS_330) {
  8646. romptr = SISGETROMW(0x19c);
  8647. }
  8648. if((SiS_Pr->SiS_VBInfo & SetInSlaveMode) && (!(SiS_Pr->SiS_TVMode & TVSetTVSimuMode))) {
  8649. romptr = SISGETROMW(0x116);
  8650. if(SiS_Pr->ChipType >= SIS_330) {
  8651. romptr = SISGETROMW(0x196);
  8652. }
  8653. }
  8654. }
  8655. }
  8656. if(romptr) {
  8657. romptr += (temp << 2);
  8658. for(j=0, i=0x31; i<=0x34; i++, j++) {
  8659. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,ROMAddr[romptr + j]);
  8660. }
  8661. } else {
  8662. index = temp % 2;
  8663. temp >>= 1; /* 0:NTSC, 1:PAL, 2:HiTV */
  8664. for(j=0, i=0x31; i<=0x34; i++, j++) {
  8665. if(!(SiS_Pr->SiS_VBType & VB_SIS30xBLV))
  8666. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVPhaseIncr1[temp][index][j]);
  8667. else if((!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) || (SiS_Pr->SiS_TVMode & TVSetTVSimuMode))
  8668. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVPhaseIncr2[temp][index][j]);
  8669. else
  8670. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVPhaseIncr1[temp][index][j]);
  8671. }
  8672. }
  8673. if((SiS_Pr->SiS_VBType & VB_SIS30xBLV) && (!(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision))) {
  8674. if((!(SiS_Pr->SiS_TVMode & (TVSetPAL | TVSetYPbPr525p | TVSetYPbPr750p))) && (ModeNo > 0x13)) {
  8675. if((resinfo == SIS_RI_640x480) ||
  8676. (resinfo == SIS_RI_800x600)) {
  8677. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x31,0x21);
  8678. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x32,0xf0);
  8679. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x33,0xf5);
  8680. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x34,0x7f);
  8681. } else if(resinfo == SIS_RI_1024x768) {
  8682. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x31,0x1e);
  8683. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x32,0x8b);
  8684. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x33,0xfb);
  8685. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x34,0x7b);
  8686. }
  8687. }
  8688. }
  8689. }
  8690. static void
  8691. SetDelayComp661(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
  8692. unsigned short ModeIdIndex, unsigned short RTI)
  8693. {
  8694. unsigned short delay = 0, romptr = 0, index, lcdpdcindex;
  8695. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  8696. if(!(SiS_Pr->SiS_VBInfo & (SetCRT2ToTV | SetCRT2ToLCD | SetCRT2ToLCDA | SetCRT2ToRAMDAC)))
  8697. return;
  8698. /* 1. New ROM: VGA2 and LCD/LCDA-Pass1:1 */
  8699. /* (If a custom mode is used, Pass1:1 is always set; hence we do this:) */
  8700. if(SiS_Pr->SiS_ROMNew) {
  8701. if((SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) ||
  8702. ((SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) &&
  8703. (SiS_Pr->SiS_LCDInfo & LCDPass11))) {
  8704. index = 25;
  8705. if(SiS_Pr->UseCustomMode) {
  8706. index = SiS_Pr->CSRClock;
  8707. } else if(ModeNo > 0x13) {
  8708. index = SiS_GetVCLK2Ptr(SiS_Pr,ModeNo,ModeIdIndex,RTI);
  8709. index = SiS_Pr->SiS_VCLKData[index].CLOCK;
  8710. }
  8711. if(index < 25) index = 25;
  8712. index = ((index / 25) - 1) << 1;
  8713. if((ROMAddr[0x5b] & 0x80) || (SiS_Pr->SiS_VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD))) {
  8714. index++;
  8715. }
  8716. romptr = SISGETROMW(0x104);
  8717. delay = ROMAddr[romptr + index];
  8718. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD)) {
  8719. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0xf0,((delay >> 1) & 0x0f));
  8720. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x35,0x7f,((delay & 0x01) << 7));
  8721. } else {
  8722. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0x0f,((delay << 3) & 0xf0));
  8723. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x20,0xbf,((delay & 0x01) << 6));
  8724. }
  8725. return;
  8726. }
  8727. }
  8728. /* 2. Old ROM: VGA2 and LCD/LCDA-Pass 1:1 */
  8729. if(SiS_Pr->UseCustomMode) delay = 0x04;
  8730. else if(ModeNo <= 0x13) delay = 0x04;
  8731. else delay = (SiS_Pr->SiS_RefIndex[RTI].Ext_PDC >> 4);
  8732. delay |= (delay << 8);
  8733. if(SiS_Pr->ChipType >= XGI_20) {
  8734. delay = 0x0606;
  8735. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  8736. delay = 0x0404;
  8737. if(SiS_Pr->SiS_XGIROM) {
  8738. index = GetTVPtrIndex(SiS_Pr);
  8739. if((romptr = SISGETROMW(0x35e))) {
  8740. delay = (ROMAddr[romptr + index] & 0x0f) << 1;
  8741. delay |= (delay << 8);
  8742. }
  8743. }
  8744. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  8745. if(SiS_Pr->ChipType == XGI_40 && SiS_Pr->ChipRevision == 0x02) {
  8746. delay -= 0x0404;
  8747. }
  8748. }
  8749. }
  8750. } else if(SiS_Pr->ChipType >= SIS_340) {
  8751. delay = 0x0606;
  8752. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  8753. delay = 0x0404;
  8754. }
  8755. /* TODO (eventually) */
  8756. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  8757. /* 3. TV */
  8758. index = GetOEMTVPtr661(SiS_Pr);
  8759. if(SiS_Pr->SiS_ROMNew) {
  8760. romptr = SISGETROMW(0x106);
  8761. if(SiS_Pr->SiS_VBType & VB_UMC) romptr += 12;
  8762. delay = ROMAddr[romptr + index];
  8763. } else {
  8764. delay = 0x04;
  8765. if(index > 3) delay = 0;
  8766. }
  8767. } else if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  8768. /* 4. LCD, LCDA (for new ROM only LV and non-Pass 1:1) */
  8769. if( (SiS_Pr->SiS_LCDResInfo != Panel_Custom) &&
  8770. ((romptr = GetLCDStructPtr661_2(SiS_Pr))) ) {
  8771. lcdpdcindex = (SiS_Pr->SiS_VBType & VB_UMC) ? 14 : 12;
  8772. /* For LVDS (and sometimes TMDS), the BIOS must know about the correct value */
  8773. delay = ROMAddr[romptr + lcdpdcindex + 1]; /* LCD */
  8774. delay |= (ROMAddr[romptr + lcdpdcindex] << 8); /* LCDA */
  8775. } else {
  8776. /* TMDS: Set our own, since BIOS has no idea */
  8777. /* (This is done on >=661 only, since <661 is calling this only for LVDS) */
  8778. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  8779. switch(SiS_Pr->SiS_LCDResInfo) {
  8780. case Panel_1024x768: delay = 0x0008; break;
  8781. case Panel_1280x720: delay = 0x0004; break;
  8782. case Panel_1280x768:
  8783. case Panel_1280x768_2:delay = 0x0004; break;
  8784. case Panel_1280x800:
  8785. case Panel_1280x800_2:delay = 0x0004; break; /* Verified for 1280x800 */
  8786. case Panel_1280x854: delay = 0x0004; break; /* FIXME */
  8787. case Panel_1280x1024: delay = 0x1e04; break;
  8788. case Panel_1400x1050: delay = 0x0004; break;
  8789. case Panel_1600x1200: delay = 0x0400; break;
  8790. case Panel_1680x1050: delay = 0x0e04; break;
  8791. default:
  8792. if((SiS_Pr->PanelXRes <= 1024) && (SiS_Pr->PanelYRes <= 768)) {
  8793. delay = 0x0008;
  8794. } else if((SiS_Pr->PanelXRes == 1280) && (SiS_Pr->PanelYRes == 1024)) {
  8795. delay = 0x1e04;
  8796. } else if((SiS_Pr->PanelXRes <= 1400) && (SiS_Pr->PanelYRes <= 1050)) {
  8797. delay = 0x0004;
  8798. } else if((SiS_Pr->PanelXRes <= 1600) && (SiS_Pr->PanelYRes <= 1200)) {
  8799. delay = 0x0400;
  8800. } else
  8801. delay = 0x0e04;
  8802. break;
  8803. }
  8804. }
  8805. /* Override by detected or user-set values */
  8806. /* (but only if, for some reason, we can't read value from BIOS) */
  8807. if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && (SiS_Pr->PDC != -1)) {
  8808. delay = SiS_Pr->PDC & 0x1f;
  8809. }
  8810. if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) && (SiS_Pr->PDCA != -1)) {
  8811. delay = (SiS_Pr->PDCA & 0x1f) << 8;
  8812. }
  8813. }
  8814. }
  8815. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  8816. delay >>= 8;
  8817. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0x0f,((delay << 3) & 0xf0));
  8818. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x20,0xbf,((delay & 0x01) << 6));
  8819. } else {
  8820. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0xf0,((delay >> 1) & 0x0f));
  8821. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x35,0x7f,((delay & 0x01) << 7));
  8822. }
  8823. }
  8824. static void
  8825. SetCRT2SyncDither661(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short RTI)
  8826. {
  8827. unsigned short infoflag;
  8828. unsigned char temp;
  8829. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  8830. if(ModeNo <= 0x13) {
  8831. infoflag = SiS_GetRegByte(SiS_Pr->SiS_P3ca+2);
  8832. } else if(SiS_Pr->UseCustomMode) {
  8833. infoflag = SiS_Pr->CInfoFlag;
  8834. } else {
  8835. infoflag = SiS_Pr->SiS_RefIndex[RTI].Ext_InfoFlag;
  8836. }
  8837. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  8838. infoflag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x37); /* No longer check D5 */
  8839. }
  8840. infoflag &= 0xc0;
  8841. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  8842. temp = (infoflag >> 6) | 0x0c;
  8843. if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) {
  8844. temp ^= 0x04;
  8845. if(SiS_Pr->SiS_ModeType >= Mode24Bpp) temp |= 0x10;
  8846. }
  8847. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1a,0xe0,temp);
  8848. } else {
  8849. temp = 0x30;
  8850. if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) temp = 0x20;
  8851. temp |= infoflag;
  8852. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0f,temp);
  8853. temp = 0;
  8854. if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) {
  8855. if(SiS_Pr->SiS_ModeType >= Mode24Bpp) temp |= 0x80;
  8856. }
  8857. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x1a,0x7f,temp);
  8858. }
  8859. }
  8860. }
  8861. static void
  8862. SetPanelParms661(struct SiS_Private *SiS_Pr)
  8863. {
  8864. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  8865. unsigned short romptr, temp1, temp2;
  8866. if(SiS_Pr->SiS_VBType & (VB_SISLVDS | VB_SIS30xC)) {
  8867. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x24,0x0f);
  8868. }
  8869. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  8870. if(SiS_Pr->LVDSHL != -1) {
  8871. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,0xfc,SiS_Pr->LVDSHL);
  8872. }
  8873. }
  8874. if(SiS_Pr->SiS_ROMNew) {
  8875. if((romptr = GetLCDStructPtr661_2(SiS_Pr))) {
  8876. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  8877. temp1 = (ROMAddr[romptr] & 0x03) | 0x0c;
  8878. temp2 = 0xfc;
  8879. if(SiS_Pr->LVDSHL != -1) {
  8880. temp1 &= 0xfc;
  8881. temp2 = 0xf3;
  8882. }
  8883. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,temp2,temp1);
  8884. }
  8885. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  8886. temp1 = (ROMAddr[romptr + 1] & 0x80) >> 1;
  8887. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x0d,0xbf,temp1);
  8888. }
  8889. }
  8890. }
  8891. }
  8892. static void
  8893. SiS_OEM310Setting(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex, unsigned short RRTI)
  8894. {
  8895. if((SiS_Pr->SiS_ROMNew) && (SiS_Pr->SiS_VBType & VB_SISLVDS)) {
  8896. SetDelayComp661(SiS_Pr, ModeNo, ModeIdIndex, RRTI);
  8897. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  8898. SetCRT2SyncDither661(SiS_Pr, ModeNo, RRTI);
  8899. SetPanelParms661(SiS_Pr);
  8900. }
  8901. } else {
  8902. SetDelayComp(SiS_Pr,ModeNo);
  8903. }
  8904. if((SiS_Pr->SiS_VBType & VB_SISVB) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
  8905. SetAntiFlicker(SiS_Pr,ModeNo,ModeIdIndex);
  8906. SetPhaseIncr(SiS_Pr,ModeNo,ModeIdIndex);
  8907. SetYFilter(SiS_Pr,ModeNo,ModeIdIndex);
  8908. if(SiS_Pr->SiS_VBType & VB_SIS301) {
  8909. SetEdgeEnhance(SiS_Pr,ModeNo,ModeIdIndex);
  8910. }
  8911. }
  8912. }
  8913. static void
  8914. SiS_OEM661Setting(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
  8915. unsigned short ModeIdIndex, unsigned short RRTI)
  8916. {
  8917. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  8918. SetDelayComp661(SiS_Pr, ModeNo, ModeIdIndex, RRTI);
  8919. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  8920. SetCRT2SyncDither661(SiS_Pr, ModeNo, RRTI);
  8921. SetPanelParms661(SiS_Pr);
  8922. }
  8923. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  8924. SetPhaseIncr(SiS_Pr, ModeNo, ModeIdIndex);
  8925. SetYFilter(SiS_Pr, ModeNo, ModeIdIndex);
  8926. SetAntiFlicker(SiS_Pr, ModeNo, ModeIdIndex);
  8927. if(SiS_Pr->SiS_VBType & VB_SIS301) {
  8928. SetEdgeEnhance(SiS_Pr, ModeNo, ModeIdIndex);
  8929. }
  8930. }
  8931. }
  8932. }
  8933. /* FinalizeLCD
  8934. * This finalizes some CRT2 registers for the very panel used.
  8935. * If we have a backup if these registers, we use it; otherwise
  8936. * we set the register according to most BIOSes. However, this
  8937. * function looks quite different in every BIOS, so you better
  8938. * pray that we have a backup...
  8939. */
  8940. static void
  8941. SiS_FinalizeLCD(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  8942. {
  8943. unsigned short tempcl,tempch,tempbl,tempbh,tempbx,tempax,temp;
  8944. unsigned short resinfo,modeflag;
  8945. if(!(SiS_Pr->SiS_VBType & VB_SISLVDS)) return;
  8946. if(SiS_Pr->SiS_ROMNew) return;
  8947. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  8948. if(SiS_Pr->LVDSHL != -1) {
  8949. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,0xfc,SiS_Pr->LVDSHL);
  8950. }
  8951. }
  8952. if(SiS_Pr->SiS_LCDResInfo == Panel_Custom) return;
  8953. if(SiS_Pr->UseCustomMode) return;
  8954. switch(SiS_Pr->SiS_CustomT) {
  8955. case CUT_COMPAQ1280:
  8956. case CUT_COMPAQ12802:
  8957. case CUT_CLEVO1400:
  8958. case CUT_CLEVO14002:
  8959. return;
  8960. }
  8961. if(ModeNo <= 0x13) {
  8962. resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
  8963. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  8964. } else {
  8965. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  8966. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  8967. }
  8968. if(IS_SIS650) {
  8969. if(!(SiS_GetReg(SiS_Pr->SiS_P3d4, 0x5f) & 0xf0)) {
  8970. if(SiS_Pr->SiS_CustomT == CUT_CLEVO1024) {
  8971. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1e,0x02);
  8972. } else {
  8973. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1e,0x03);
  8974. }
  8975. }
  8976. }
  8977. if(SiS_Pr->SiS_CustomT == CUT_CLEVO1024) {
  8978. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  8979. /* Maybe all panels? */
  8980. if(SiS_Pr->LVDSHL == -1) {
  8981. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,0xfc,0x01);
  8982. }
  8983. return;
  8984. }
  8985. }
  8986. if(SiS_Pr->SiS_CustomT == CUT_CLEVO10242) {
  8987. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  8988. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  8989. if(SiS_Pr->LVDSHL == -1) {
  8990. /* Maybe all panels? */
  8991. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,0xfc,0x01);
  8992. }
  8993. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  8994. tempch = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4;
  8995. if(tempch == 3) {
  8996. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x02);
  8997. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,0x25);
  8998. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1c,0x00);
  8999. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1d,0x1b);
  9000. }
  9001. }
  9002. return;
  9003. }
  9004. }
  9005. }
  9006. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  9007. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  9008. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  9009. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2a,0x00);
  9010. #ifdef SET_EMI
  9011. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
  9012. #endif
  9013. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x34,0x10);
  9014. }
  9015. } else if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) {
  9016. if(SiS_Pr->LVDSHL == -1) {
  9017. /* Maybe ACER only? */
  9018. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,0xfc,0x01);
  9019. }
  9020. }
  9021. tempch = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4;
  9022. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  9023. if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) {
  9024. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1f,0x76);
  9025. } else if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  9026. if(tempch == 0x03) {
  9027. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x02);
  9028. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,0x25);
  9029. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1c,0x00);
  9030. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1d,0x1b);
  9031. }
  9032. if(SiS_Pr->Backup && (SiS_Pr->Backup_Mode == ModeNo)) {
  9033. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x14,SiS_Pr->Backup_14);
  9034. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x15,SiS_Pr->Backup_15);
  9035. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x16,SiS_Pr->Backup_16);
  9036. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x17,SiS_Pr->Backup_17);
  9037. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,SiS_Pr->Backup_18);
  9038. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x19,SiS_Pr->Backup_19);
  9039. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1a,SiS_Pr->Backup_1a);
  9040. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,SiS_Pr->Backup_1b);
  9041. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1c,SiS_Pr->Backup_1c);
  9042. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1d,SiS_Pr->Backup_1d);
  9043. } else if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) { /* 1.10.8w */
  9044. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x14,0x90);
  9045. if(ModeNo <= 0x13) {
  9046. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x11);
  9047. if((resinfo == 0) || (resinfo == 2)) return;
  9048. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x18);
  9049. if((resinfo == 1) || (resinfo == 3)) return;
  9050. }
  9051. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x02);
  9052. if((ModeNo > 0x13) && (resinfo == SIS_RI_1024x768)) {
  9053. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x02); /* 1.10.7u */
  9054. #if 0
  9055. tempbx = 806; /* 0x326 */ /* other older BIOSes */
  9056. tempbx--;
  9057. temp = tempbx & 0xff;
  9058. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,temp);
  9059. temp = (tempbx >> 8) & 0x03;
  9060. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x1d,0xf8,temp);
  9061. #endif
  9062. }
  9063. } else if(ModeNo <= 0x13) {
  9064. if(ModeNo <= 1) {
  9065. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x70);
  9066. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x19,0xff);
  9067. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,0x48);
  9068. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1d,0x12);
  9069. }
  9070. if(!(modeflag & HalfDCLK)) {
  9071. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x14,0x20);
  9072. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x15,0x1a);
  9073. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x16,0x28);
  9074. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x17,0x00);
  9075. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x4c);
  9076. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x19,0xdc);
  9077. if(ModeNo == 0x12) {
  9078. switch(tempch) {
  9079. case 0:
  9080. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x95);
  9081. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x19,0xdc);
  9082. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1a,0x10);
  9083. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,0x95);
  9084. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1c,0x48);
  9085. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1d,0x12);
  9086. break;
  9087. case 2:
  9088. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x95);
  9089. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,0x48);
  9090. break;
  9091. case 3:
  9092. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,0x95);
  9093. break;
  9094. }
  9095. }
  9096. }
  9097. }
  9098. }
  9099. } else {
  9100. tempcl = tempbh = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x01);
  9101. tempcl &= 0x0f;
  9102. tempbh &= 0x70;
  9103. tempbh >>= 4;
  9104. tempbl = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x04);
  9105. tempbx = (tempbh << 8) | tempbl;
  9106. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  9107. if((resinfo == SIS_RI_1024x768) || (!(SiS_Pr->SiS_LCDInfo & DontExpandLCD))) {
  9108. if(SiS_Pr->SiS_SetFlag & LCDVESATiming) {
  9109. tempbx = 770;
  9110. } else {
  9111. if(tempbx > 770) tempbx = 770;
  9112. if(SiS_Pr->SiS_VGAVDE < 600) {
  9113. tempax = 768 - SiS_Pr->SiS_VGAVDE;
  9114. tempax >>= 4; /* 1.10.7w; 1.10.6s: 3; */
  9115. if(SiS_Pr->SiS_VGAVDE <= 480) tempax >>= 4; /* 1.10.7w; 1.10.6s: < 480; >>=1; */
  9116. tempbx -= tempax;
  9117. }
  9118. }
  9119. } else return;
  9120. }
  9121. temp = tempbx & 0xff;
  9122. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,temp);
  9123. temp = ((tempbx & 0xff00) >> 4) | tempcl;
  9124. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x01,0x80,temp);
  9125. }
  9126. }
  9127. }
  9128. #endif
  9129. /* ================= SiS 300 O.E.M. ================== */
  9130. #ifdef CONFIG_FB_SIS_300
  9131. static void
  9132. SetOEMLCDData2(struct SiS_Private *SiS_Pr, unsigned short ModeNo,unsigned short ModeIdIndex,
  9133. unsigned short RefTabIndex)
  9134. {
  9135. unsigned short crt2crtc=0, modeflag, myindex=0;
  9136. unsigned char temp;
  9137. int i;
  9138. if(ModeNo <= 0x13) {
  9139. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  9140. crt2crtc = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  9141. } else {
  9142. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  9143. crt2crtc = SiS_Pr->SiS_RefIndex[RefTabIndex].Ext_CRT2CRTC;
  9144. }
  9145. crt2crtc &= 0x3f;
  9146. if(SiS_Pr->SiS_CustomT == CUT_BARCO1024) {
  9147. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xdf);
  9148. }
  9149. if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) {
  9150. if(modeflag & HalfDCLK) myindex = 1;
  9151. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  9152. for(i=0; i<7; i++) {
  9153. if(barco_p1[myindex][crt2crtc][i][0]) {
  9154. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,
  9155. barco_p1[myindex][crt2crtc][i][0],
  9156. barco_p1[myindex][crt2crtc][i][2],
  9157. barco_p1[myindex][crt2crtc][i][1]);
  9158. }
  9159. }
  9160. }
  9161. temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00);
  9162. if(temp & 0x80) {
  9163. temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x18);
  9164. temp++;
  9165. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,temp);
  9166. }
  9167. }
  9168. }
  9169. static unsigned short
  9170. GetOEMLCDPtr(struct SiS_Private *SiS_Pr, int Flag)
  9171. {
  9172. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  9173. unsigned short tempbx=0,romptr=0;
  9174. static const unsigned char customtable300[] = {
  9175. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  9176. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
  9177. };
  9178. static const unsigned char customtable630[] = {
  9179. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  9180. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
  9181. };
  9182. if(SiS_Pr->ChipType == SIS_300) {
  9183. tempbx = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) & 0x0f;
  9184. if(SiS_Pr->SiS_VBType & VB_SIS301) tempbx &= 0x07;
  9185. tempbx -= 2;
  9186. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) tempbx += 4;
  9187. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  9188. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx += 3;
  9189. }
  9190. if(SiS_Pr->SiS_UseROM) {
  9191. if(ROMAddr[0x235] & 0x80) {
  9192. tempbx = SiS_Pr->SiS_LCDTypeInfo;
  9193. if(Flag) {
  9194. romptr = SISGETROMW(0x255);
  9195. if(romptr) tempbx = ROMAddr[romptr + SiS_Pr->SiS_LCDTypeInfo];
  9196. else tempbx = customtable300[SiS_Pr->SiS_LCDTypeInfo];
  9197. if(tempbx == 0xFF) return 0xFFFF;
  9198. }
  9199. tempbx <<= 1;
  9200. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) tempbx++;
  9201. }
  9202. }
  9203. } else {
  9204. if(Flag) {
  9205. if(SiS_Pr->SiS_UseROM) {
  9206. romptr = SISGETROMW(0x255);
  9207. if(romptr) tempbx = ROMAddr[romptr + SiS_Pr->SiS_LCDTypeInfo];
  9208. else tempbx = 0xff;
  9209. } else {
  9210. tempbx = customtable630[SiS_Pr->SiS_LCDTypeInfo];
  9211. }
  9212. if(tempbx == 0xFF) return 0xFFFF;
  9213. tempbx <<= 2;
  9214. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) tempbx += 2;
  9215. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++;
  9216. return tempbx;
  9217. }
  9218. tempbx = SiS_Pr->SiS_LCDTypeInfo << 2;
  9219. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) tempbx += 2;
  9220. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++;
  9221. }
  9222. return tempbx;
  9223. }
  9224. static void
  9225. SetOEMLCDDelay(struct SiS_Private *SiS_Pr, unsigned short ModeNo,unsigned short ModeIdIndex)
  9226. {
  9227. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  9228. unsigned short index,temp,romptr=0;
  9229. if(SiS_Pr->SiS_LCDResInfo == Panel_Custom) return;
  9230. if(SiS_Pr->SiS_UseROM) {
  9231. if(!(ROMAddr[0x237] & 0x01)) return;
  9232. if(!(ROMAddr[0x237] & 0x02)) return;
  9233. romptr = SISGETROMW(0x24b);
  9234. }
  9235. /* The Panel Compensation Delay should be set according to tables
  9236. * here. Unfortunately, various BIOS versions don't care about
  9237. * a uniform way using eg. ROM byte 0x220, but use different
  9238. * hard coded delays (0x04, 0x20, 0x18) in SetGroup1().
  9239. * Thus we don't set this if the user selected a custom pdc or if
  9240. * we otherwise detected a valid pdc.
  9241. */
  9242. if(SiS_Pr->PDC != -1) return;
  9243. temp = GetOEMLCDPtr(SiS_Pr, 0);
  9244. if(SiS_Pr->UseCustomMode)
  9245. index = 0;
  9246. else
  9247. index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].VB_LCDDelayIndex;
  9248. if(SiS_Pr->ChipType != SIS_300) {
  9249. if(romptr) {
  9250. romptr += (temp * 2);
  9251. romptr = SISGETROMW(romptr);
  9252. romptr += index;
  9253. temp = ROMAddr[romptr];
  9254. } else {
  9255. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  9256. temp = SiS300_OEMLCDDelay2[temp][index];
  9257. } else {
  9258. temp = SiS300_OEMLCDDelay3[temp][index];
  9259. }
  9260. }
  9261. } else {
  9262. if(SiS_Pr->SiS_UseROM && (ROMAddr[0x235] & 0x80)) {
  9263. if(romptr) {
  9264. romptr += (temp * 2);
  9265. romptr = SISGETROMW(romptr);
  9266. romptr += index;
  9267. temp = ROMAddr[romptr];
  9268. } else {
  9269. temp = SiS300_OEMLCDDelay5[temp][index];
  9270. }
  9271. } else {
  9272. if(SiS_Pr->SiS_UseROM) {
  9273. romptr = ROMAddr[0x249] | (ROMAddr[0x24a] << 8);
  9274. if(romptr) {
  9275. romptr += (temp * 2);
  9276. romptr = SISGETROMW(romptr);
  9277. romptr += index;
  9278. temp = ROMAddr[romptr];
  9279. } else {
  9280. temp = SiS300_OEMLCDDelay4[temp][index];
  9281. }
  9282. } else {
  9283. temp = SiS300_OEMLCDDelay4[temp][index];
  9284. }
  9285. }
  9286. }
  9287. temp &= 0x3c;
  9288. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,~0x3C,temp); /* index 0A D[6:4] */
  9289. }
  9290. static void
  9291. SetOEMLCDData(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  9292. {
  9293. #if 0 /* Unfinished; Data table missing */
  9294. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  9295. unsigned short index,temp;
  9296. if((SiS_Pr->SiS_UseROM) {
  9297. if(!(ROMAddr[0x237] & 0x01)) return;
  9298. if(!(ROMAddr[0x237] & 0x04)) return;
  9299. /* No rom pointer in BIOS header! */
  9300. }
  9301. temp = GetOEMLCDPtr(SiS_Pr, 1);
  9302. if(temp == 0xFFFF) return;
  9303. index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex]._VB_LCDHIndex;
  9304. for(i=0x14, j=0; i<=0x17; i++, j++) {
  9305. SiS_SetReg(SiS_Pr->SiS_Part1Port,i,SiS300_LCDHData[temp][index][j]);
  9306. }
  9307. SiS_SetRegANDOR(SiS_SiS_Part1Port,0x1a, 0xf8, (SiS300_LCDHData[temp][index][j] & 0x07));
  9308. index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex]._VB_LCDVIndex;
  9309. SiS_SetReg(SiS_SiS_Part1Port,0x18, SiS300_LCDVData[temp][index][0]);
  9310. SiS_SetRegANDOR(SiS_SiS_Part1Port,0x19, 0xF0, SiS300_LCDVData[temp][index][1]);
  9311. SiS_SetRegANDOR(SiS_SiS_Part1Port,0x1A, 0xC7, (SiS300_LCDVData[temp][index][2] & 0x38));
  9312. for(i=0x1b, j=3; i<=0x1d; i++, j++) {
  9313. SiS_SetReg(SiS_Pr->SiS_Part1Port,i,SiS300_LCDVData[temp][index][j]);
  9314. }
  9315. #endif
  9316. }
  9317. static unsigned short
  9318. GetOEMTVPtr(struct SiS_Private *SiS_Pr)
  9319. {
  9320. unsigned short index;
  9321. index = 0;
  9322. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) index += 4;
  9323. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  9324. if(SiS_Pr->SiS_VBInfo & SetCRT2ToSCART) index += 2;
  9325. else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) index += 3;
  9326. else if(SiS_Pr->SiS_TVMode & TVSetPAL) index += 1;
  9327. } else {
  9328. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) index += 2;
  9329. if(SiS_Pr->SiS_TVMode & TVSetPAL) index += 1;
  9330. }
  9331. return index;
  9332. }
  9333. static void
  9334. SetOEMTVDelay(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  9335. {
  9336. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  9337. unsigned short index,temp,romptr=0;
  9338. if(SiS_Pr->SiS_UseROM) {
  9339. if(!(ROMAddr[0x238] & 0x01)) return;
  9340. if(!(ROMAddr[0x238] & 0x02)) return;
  9341. romptr = SISGETROMW(0x241);
  9342. }
  9343. temp = GetOEMTVPtr(SiS_Pr);
  9344. index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].VB_TVDelayIndex;
  9345. if(romptr) {
  9346. romptr += (temp * 2);
  9347. romptr = SISGETROMW(romptr);
  9348. romptr += index;
  9349. temp = ROMAddr[romptr];
  9350. } else {
  9351. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  9352. temp = SiS300_OEMTVDelay301[temp][index];
  9353. } else {
  9354. temp = SiS300_OEMTVDelayLVDS[temp][index];
  9355. }
  9356. }
  9357. temp &= 0x3c;
  9358. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,~0x3C,temp);
  9359. }
  9360. static void
  9361. SetOEMAntiFlicker(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  9362. {
  9363. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  9364. unsigned short index,temp,romptr=0;
  9365. if(SiS_Pr->SiS_UseROM) {
  9366. if(!(ROMAddr[0x238] & 0x01)) return;
  9367. if(!(ROMAddr[0x238] & 0x04)) return;
  9368. romptr = SISGETROMW(0x243);
  9369. }
  9370. temp = GetOEMTVPtr(SiS_Pr);
  9371. index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].VB_TVFlickerIndex;
  9372. if(romptr) {
  9373. romptr += (temp * 2);
  9374. romptr = SISGETROMW(romptr);
  9375. romptr += index;
  9376. temp = ROMAddr[romptr];
  9377. } else {
  9378. temp = SiS300_OEMTVFlicker[temp][index];
  9379. }
  9380. temp &= 0x70;
  9381. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x0A,0x8F,temp);
  9382. }
  9383. static void
  9384. SetOEMPhaseIncr(struct SiS_Private *SiS_Pr, unsigned short ModeNo,unsigned short ModeIdIndex)
  9385. {
  9386. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  9387. unsigned short index,i,j,temp,romptr=0;
  9388. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) return;
  9389. if(SiS_Pr->SiS_TVMode & (TVSetNTSC1024 | TVSetNTSCJ | TVSetPALM | TVSetPALN)) return;
  9390. if(SiS_Pr->SiS_UseROM) {
  9391. if(!(ROMAddr[0x238] & 0x01)) return;
  9392. if(!(ROMAddr[0x238] & 0x08)) return;
  9393. romptr = SISGETROMW(0x245);
  9394. }
  9395. temp = GetOEMTVPtr(SiS_Pr);
  9396. index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].VB_TVPhaseIndex;
  9397. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  9398. for(i=0x31, j=0; i<=0x34; i++, j++) {
  9399. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS300_Phase2[temp][index][j]);
  9400. }
  9401. } else {
  9402. if(romptr) {
  9403. romptr += (temp * 2);
  9404. romptr = SISGETROMW(romptr);
  9405. romptr += (index * 4);
  9406. for(i=0x31, j=0; i<=0x34; i++, j++) {
  9407. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,ROMAddr[romptr + j]);
  9408. }
  9409. } else {
  9410. for(i=0x31, j=0; i<=0x34; i++, j++) {
  9411. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS300_Phase1[temp][index][j]);
  9412. }
  9413. }
  9414. }
  9415. }
  9416. static void
  9417. SetOEMYFilter(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  9418. {
  9419. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  9420. unsigned short index,temp,i,j,romptr=0;
  9421. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToSCART | SetCRT2ToHiVision | SetCRT2ToYPbPr525750)) return;
  9422. if(SiS_Pr->SiS_UseROM) {
  9423. if(!(ROMAddr[0x238] & 0x01)) return;
  9424. if(!(ROMAddr[0x238] & 0x10)) return;
  9425. romptr = SISGETROMW(0x247);
  9426. }
  9427. temp = GetOEMTVPtr(SiS_Pr);
  9428. if(SiS_Pr->SiS_TVMode & TVSetPALM) temp = 8;
  9429. else if(SiS_Pr->SiS_TVMode & TVSetPALN) temp = 9;
  9430. /* NTSCJ uses NTSC filters */
  9431. index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].VB_TVYFilterIndex;
  9432. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  9433. for(i=0x35, j=0; i<=0x38; i++, j++) {
  9434. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS300_Filter2[temp][index][j]);
  9435. }
  9436. for(i=0x48; i<=0x4A; i++, j++) {
  9437. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS300_Filter2[temp][index][j]);
  9438. }
  9439. } else {
  9440. if((romptr) && (!(SiS_Pr->SiS_TVMode & (TVSetPALM|TVSetPALN)))) {
  9441. romptr += (temp * 2);
  9442. romptr = SISGETROMW(romptr);
  9443. romptr += (index * 4);
  9444. for(i=0x35, j=0; i<=0x38; i++, j++) {
  9445. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,ROMAddr[romptr + j]);
  9446. }
  9447. } else {
  9448. for(i=0x35, j=0; i<=0x38; i++, j++) {
  9449. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS300_Filter1[temp][index][j]);
  9450. }
  9451. }
  9452. }
  9453. }
  9454. static unsigned short
  9455. SiS_SearchVBModeID(struct SiS_Private *SiS_Pr, unsigned short *ModeNo)
  9456. {
  9457. unsigned short ModeIdIndex;
  9458. unsigned char VGAINFO = SiS_Pr->SiS_VGAINFO;
  9459. if(*ModeNo <= 5) *ModeNo |= 1;
  9460. for(ModeIdIndex=0; ; ModeIdIndex++) {
  9461. if(SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].ModeID == *ModeNo) break;
  9462. if(SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].ModeID == 0xFF) return 0;
  9463. }
  9464. if(*ModeNo != 0x07) {
  9465. if(*ModeNo > 0x03) return ModeIdIndex;
  9466. if(VGAINFO & 0x80) return ModeIdIndex;
  9467. ModeIdIndex++;
  9468. }
  9469. if(VGAINFO & 0x10) ModeIdIndex++; /* 400 lines */
  9470. /* else 350 lines */
  9471. return ModeIdIndex;
  9472. }
  9473. static void
  9474. SiS_OEM300Setting(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  9475. unsigned short RefTableIndex)
  9476. {
  9477. unsigned short OEMModeIdIndex = 0;
  9478. if(!SiS_Pr->UseCustomMode) {
  9479. OEMModeIdIndex = SiS_SearchVBModeID(SiS_Pr,&ModeNo);
  9480. if(!(OEMModeIdIndex)) return;
  9481. }
  9482. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  9483. SetOEMLCDDelay(SiS_Pr, ModeNo, OEMModeIdIndex);
  9484. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  9485. SetOEMLCDData(SiS_Pr, ModeNo, OEMModeIdIndex);
  9486. }
  9487. }
  9488. if(SiS_Pr->UseCustomMode) return;
  9489. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  9490. SetOEMTVDelay(SiS_Pr, ModeNo,OEMModeIdIndex);
  9491. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  9492. SetOEMAntiFlicker(SiS_Pr, ModeNo, OEMModeIdIndex);
  9493. SetOEMPhaseIncr(SiS_Pr, ModeNo, OEMModeIdIndex);
  9494. SetOEMYFilter(SiS_Pr, ModeNo, OEMModeIdIndex);
  9495. }
  9496. }
  9497. }
  9498. #endif