init301.c 333 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075
  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. #ifdef HAVE_CONFIG_H
  60. #include "config.h"
  61. #endif
  62. #if 1
  63. #define SET_EMI /* 302LV/ELV: Set EMI values */
  64. #endif
  65. #if 1
  66. #define SET_PWD /* 301/302LV: Set PWD */
  67. #endif
  68. #define COMPAL_HACK /* Needed for Compal 1400x1050 (EMI) */
  69. #define COMPAQ_HACK /* Needed for Inventec/Compaq 1280x1024 (EMI) */
  70. #define ASUS_HACK /* Needed for Asus A2H 1024x768 (EMI) */
  71. #include "init301.h"
  72. #ifdef SIS300
  73. #include "oem300.h"
  74. #endif
  75. #ifdef SIS315H
  76. #include "oem310.h"
  77. #endif
  78. #define SiS_I2CDELAY 1000
  79. #define SiS_I2CDELAYSHORT 150
  80. static unsigned short SiS_GetBIOSLCDResInfo(struct SiS_Private *SiS_Pr);
  81. static void SiS_SetCH70xx(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val);
  82. /*********************************************/
  83. /* HELPER: Lock/Unlock CRT2 */
  84. /*********************************************/
  85. void
  86. SiS_UnLockCRT2(struct SiS_Private *SiS_Pr)
  87. {
  88. if(SiS_Pr->ChipType == XGI_20)
  89. return;
  90. else if(SiS_Pr->ChipType >= SIS_315H)
  91. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2f,0x01);
  92. else
  93. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x24,0x01);
  94. }
  95. static
  96. void
  97. SiS_LockCRT2(struct SiS_Private *SiS_Pr)
  98. {
  99. if(SiS_Pr->ChipType == XGI_20)
  100. return;
  101. else if(SiS_Pr->ChipType >= SIS_315H)
  102. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2F,0xFE);
  103. else
  104. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x24,0xFE);
  105. }
  106. /*********************************************/
  107. /* HELPER: Write SR11 */
  108. /*********************************************/
  109. static void
  110. SiS_SetRegSR11ANDOR(struct SiS_Private *SiS_Pr, unsigned short DataAND, unsigned short DataOR)
  111. {
  112. if(SiS_Pr->ChipType >= SIS_661) {
  113. DataAND &= 0x0f;
  114. DataOR &= 0x0f;
  115. }
  116. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x11,DataAND,DataOR);
  117. }
  118. /*********************************************/
  119. /* HELPER: Get Pointer to LCD structure */
  120. /*********************************************/
  121. #ifdef SIS315H
  122. static unsigned char *
  123. GetLCDStructPtr661(struct SiS_Private *SiS_Pr)
  124. {
  125. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  126. unsigned char *myptr = NULL;
  127. unsigned short romindex = 0, reg = 0, idx = 0;
  128. /* Use the BIOS tables only for LVDS panels; TMDS is unreliable
  129. * due to the variaty of panels the BIOS doesn't know about.
  130. * Exception: If the BIOS has better knowledge (such as in case
  131. * of machines with a 301C and a panel that does not support DDC)
  132. * use the BIOS data as well.
  133. */
  134. if((SiS_Pr->SiS_ROMNew) &&
  135. ((SiS_Pr->SiS_VBType & VB_SISLVDS) || (!SiS_Pr->PanelSelfDetected))) {
  136. if(SiS_Pr->ChipType < SIS_661) reg = 0x3c;
  137. else reg = 0x7d;
  138. idx = (SiS_GetReg(SiS_Pr->SiS_P3d4,reg) & 0x1f) * 26;
  139. if(idx < (8*26)) {
  140. myptr = (unsigned char *)&SiS_LCDStruct661[idx];
  141. }
  142. romindex = SISGETROMW(0x100);
  143. if(romindex) {
  144. romindex += idx;
  145. myptr = &ROMAddr[romindex];
  146. }
  147. }
  148. return myptr;
  149. }
  150. static unsigned short
  151. GetLCDStructPtr661_2(struct SiS_Private *SiS_Pr)
  152. {
  153. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  154. unsigned short romptr = 0;
  155. /* Use the BIOS tables only for LVDS panels; TMDS is unreliable
  156. * due to the variaty of panels the BIOS doesn't know about.
  157. * Exception: If the BIOS has better knowledge (such as in case
  158. * of machines with a 301C and a panel that does not support DDC)
  159. * use the BIOS data as well.
  160. */
  161. if((SiS_Pr->SiS_ROMNew) &&
  162. ((SiS_Pr->SiS_VBType & VB_SISLVDS) || (!SiS_Pr->PanelSelfDetected))) {
  163. romptr = SISGETROMW(0x102);
  164. romptr += ((SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4) * SiS_Pr->SiS661LCD2TableSize);
  165. }
  166. return romptr;
  167. }
  168. #endif
  169. /*********************************************/
  170. /* Adjust Rate for CRT2 */
  171. /*********************************************/
  172. static bool
  173. SiS_AdjustCRT2Rate(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  174. unsigned short RRTI, unsigned short *i)
  175. {
  176. unsigned short checkmask=0, modeid, infoflag;
  177. modeid = SiS_Pr->SiS_RefIndex[RRTI + (*i)].ModeID;
  178. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  179. if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) {
  180. checkmask |= SupportRAMDAC2;
  181. if(SiS_Pr->ChipType >= SIS_315H) {
  182. checkmask |= SupportRAMDAC2_135;
  183. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  184. checkmask |= SupportRAMDAC2_162;
  185. if(SiS_Pr->SiS_VBType & VB_SISRAMDAC202) {
  186. checkmask |= SupportRAMDAC2_202;
  187. }
  188. }
  189. }
  190. } else if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  191. checkmask |= SupportLCD;
  192. if(SiS_Pr->ChipType >= SIS_315H) {
  193. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  194. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  195. if(modeid == 0x2e) checkmask |= Support64048060Hz;
  196. }
  197. }
  198. }
  199. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  200. checkmask |= SupportHiVision;
  201. } else if(SiS_Pr->SiS_VBInfo & (SetCRT2ToYPbPr525750|SetCRT2ToAVIDEO|SetCRT2ToSVIDEO|SetCRT2ToSCART)) {
  202. checkmask |= SupportTV;
  203. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  204. checkmask |= SupportTV1024;
  205. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  206. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) {
  207. checkmask |= SupportYPbPr750p;
  208. }
  209. }
  210. }
  211. }
  212. } else { /* LVDS */
  213. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  214. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  215. checkmask |= SupportCHTV;
  216. }
  217. }
  218. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  219. checkmask |= SupportLCD;
  220. }
  221. }
  222. /* Look backwards in table for matching CRT2 mode */
  223. for(; SiS_Pr->SiS_RefIndex[RRTI + (*i)].ModeID == modeid; (*i)--) {
  224. infoflag = SiS_Pr->SiS_RefIndex[RRTI + (*i)].Ext_InfoFlag;
  225. if(infoflag & checkmask) return true;
  226. if((*i) == 0) break;
  227. }
  228. /* Look through the whole mode-section of the table from the beginning
  229. * for a matching CRT2 mode if no mode was found yet.
  230. */
  231. for((*i) = 0; ; (*i)++) {
  232. if(SiS_Pr->SiS_RefIndex[RRTI + (*i)].ModeID != modeid) break;
  233. infoflag = SiS_Pr->SiS_RefIndex[RRTI + (*i)].Ext_InfoFlag;
  234. if(infoflag & checkmask) return true;
  235. }
  236. return false;
  237. }
  238. /*********************************************/
  239. /* Get rate index */
  240. /*********************************************/
  241. unsigned short
  242. SiS_GetRatePtr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  243. {
  244. unsigned short RRTI,i,backup_i;
  245. unsigned short modeflag,index,temp,backupindex;
  246. static const unsigned short LCDRefreshIndex[] = {
  247. 0x00, 0x00, 0x01, 0x01,
  248. 0x01, 0x01, 0x01, 0x01,
  249. 0x01, 0x01, 0x01, 0x01,
  250. 0x01, 0x01, 0x01, 0x01,
  251. 0x00, 0x00, 0x00, 0x00
  252. };
  253. /* Do NOT check for UseCustomMode here, will skrew up FIFO */
  254. if(ModeNo == 0xfe) return 0;
  255. if(ModeNo <= 0x13) {
  256. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  257. } else {
  258. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  259. }
  260. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  261. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  262. if(modeflag & HalfDCLK) return 0;
  263. }
  264. }
  265. if(ModeNo < 0x14) return 0xFFFF;
  266. index = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x33) >> SiS_Pr->SiS_SelectCRT2Rate) & 0x0F;
  267. backupindex = index;
  268. if(index > 0) index--;
  269. if(SiS_Pr->SiS_SetFlag & ProgrammingCRT2) {
  270. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  271. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  272. if(SiS_Pr->SiS_VBType & VB_NoLCD) index = 0;
  273. else if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) index = backupindex = 0;
  274. }
  275. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  276. if(!(SiS_Pr->SiS_VBType & VB_NoLCD)) {
  277. temp = LCDRefreshIndex[SiS_GetBIOSLCDResInfo(SiS_Pr)];
  278. if(index > temp) index = temp;
  279. }
  280. }
  281. } else {
  282. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) index = 0;
  283. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  284. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) index = 0;
  285. }
  286. }
  287. }
  288. RRTI = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].REFindex;
  289. ModeNo = SiS_Pr->SiS_RefIndex[RRTI].ModeID;
  290. if(SiS_Pr->ChipType >= SIS_315H) {
  291. if(!(SiS_Pr->SiS_VBInfo & DriverMode)) {
  292. if( (SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_VESAID == 0x105) ||
  293. (SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_VESAID == 0x107) ) {
  294. if(backupindex <= 1) RRTI++;
  295. }
  296. }
  297. }
  298. i = 0;
  299. do {
  300. if(SiS_Pr->SiS_RefIndex[RRTI + i].ModeID != ModeNo) break;
  301. temp = SiS_Pr->SiS_RefIndex[RRTI + i].Ext_InfoFlag;
  302. temp &= ModeTypeMask;
  303. if(temp < SiS_Pr->SiS_ModeType) break;
  304. i++;
  305. index--;
  306. } while(index != 0xFFFF);
  307. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) {
  308. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  309. temp = SiS_Pr->SiS_RefIndex[RRTI + i - 1].Ext_InfoFlag;
  310. if(temp & InterlaceMode) i++;
  311. }
  312. }
  313. i--;
  314. if((SiS_Pr->SiS_SetFlag & ProgrammingCRT2) && (!(SiS_Pr->SiS_VBInfo & DisableCRT2Display))) {
  315. backup_i = i;
  316. if(!(SiS_AdjustCRT2Rate(SiS_Pr, ModeNo, ModeIdIndex, RRTI, &i))) {
  317. i = backup_i;
  318. }
  319. }
  320. return (RRTI + i);
  321. }
  322. /*********************************************/
  323. /* STORE CRT2 INFO in CR34 */
  324. /*********************************************/
  325. static void
  326. SiS_SaveCRT2Info(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
  327. {
  328. unsigned short temp1, temp2;
  329. /* Store CRT1 ModeNo in CR34 */
  330. SiS_SetReg(SiS_Pr->SiS_P3d4,0x34,ModeNo);
  331. temp1 = (SiS_Pr->SiS_VBInfo & SetInSlaveMode) >> 8;
  332. temp2 = ~(SetInSlaveMode >> 8);
  333. SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x31,temp2,temp1);
  334. }
  335. /*********************************************/
  336. /* HELPER: GET SOME DATA FROM BIOS ROM */
  337. /*********************************************/
  338. #ifdef SIS300
  339. static bool
  340. SiS_CR36BIOSWord23b(struct SiS_Private *SiS_Pr)
  341. {
  342. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  343. unsigned short temp,temp1;
  344. if(SiS_Pr->SiS_UseROM) {
  345. if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) {
  346. temp = 1 << ((SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4) & 0x0f);
  347. temp1 = SISGETROMW(0x23b);
  348. if(temp1 & temp) return true;
  349. }
  350. }
  351. return false;
  352. }
  353. static bool
  354. SiS_CR36BIOSWord23d(struct SiS_Private *SiS_Pr)
  355. {
  356. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  357. unsigned short temp,temp1;
  358. if(SiS_Pr->SiS_UseROM) {
  359. if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) {
  360. temp = 1 << ((SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4) & 0x0f);
  361. temp1 = SISGETROMW(0x23d);
  362. if(temp1 & temp) return true;
  363. }
  364. }
  365. return false;
  366. }
  367. #endif
  368. /*********************************************/
  369. /* HELPER: DELAY FUNCTIONS */
  370. /*********************************************/
  371. void
  372. SiS_DDC2Delay(struct SiS_Private *SiS_Pr, unsigned int delaytime)
  373. {
  374. while (delaytime-- > 0)
  375. SiS_GetReg(SiS_Pr->SiS_P3c4, 0x05);
  376. }
  377. #if defined(SIS300) || defined(SIS315H)
  378. static void
  379. SiS_GenericDelay(struct SiS_Private *SiS_Pr, unsigned short delay)
  380. {
  381. SiS_DDC2Delay(SiS_Pr, delay * 36);
  382. }
  383. #endif
  384. #ifdef SIS315H
  385. static void
  386. SiS_LongDelay(struct SiS_Private *SiS_Pr, unsigned short delay)
  387. {
  388. while(delay--) {
  389. SiS_GenericDelay(SiS_Pr, 6623);
  390. }
  391. }
  392. #endif
  393. #if defined(SIS300) || defined(SIS315H)
  394. static void
  395. SiS_ShortDelay(struct SiS_Private *SiS_Pr, unsigned short delay)
  396. {
  397. while(delay--) {
  398. SiS_GenericDelay(SiS_Pr, 66);
  399. }
  400. }
  401. #endif
  402. static void
  403. SiS_PanelDelay(struct SiS_Private *SiS_Pr, unsigned short DelayTime)
  404. {
  405. #if defined(SIS300) || defined(SIS315H)
  406. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  407. unsigned short PanelID, DelayIndex, Delay=0;
  408. #endif
  409. if(SiS_Pr->ChipType < SIS_315H) {
  410. #ifdef SIS300
  411. PanelID = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36);
  412. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  413. if(SiS_Pr->SiS_VBType & VB_SIS301) PanelID &= 0xf7;
  414. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x18) & 0x10)) PanelID = 0x12;
  415. }
  416. DelayIndex = PanelID >> 4;
  417. if((DelayTime >= 2) && ((PanelID & 0x0f) == 1)) {
  418. Delay = 3;
  419. } else {
  420. if(DelayTime >= 2) DelayTime -= 2;
  421. if(!(DelayTime & 0x01)) {
  422. Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[0];
  423. } else {
  424. Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[1];
  425. }
  426. if(SiS_Pr->SiS_UseROM) {
  427. if(ROMAddr[0x220] & 0x40) {
  428. if(!(DelayTime & 0x01)) Delay = (unsigned short)ROMAddr[0x225];
  429. else Delay = (unsigned short)ROMAddr[0x226];
  430. }
  431. }
  432. }
  433. SiS_ShortDelay(SiS_Pr, Delay);
  434. #endif /* SIS300 */
  435. } else {
  436. #ifdef SIS315H
  437. if((SiS_Pr->ChipType >= SIS_661) ||
  438. (SiS_Pr->ChipType <= SIS_315PRO) ||
  439. (SiS_Pr->ChipType == SIS_330) ||
  440. (SiS_Pr->SiS_ROMNew)) {
  441. if(!(DelayTime & 0x01)) {
  442. SiS_DDC2Delay(SiS_Pr, 0x1000);
  443. } else {
  444. SiS_DDC2Delay(SiS_Pr, 0x4000);
  445. }
  446. } else if((SiS_Pr->SiS_IF_DEF_LVDS == 1) /* ||
  447. (SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) ||
  448. (SiS_Pr->SiS_CustomT == CUT_CLEVO1400) */ ) { /* 315 series, LVDS; Special */
  449. if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
  450. PanelID = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36);
  451. if(SiS_Pr->SiS_CustomT == CUT_CLEVO1400) {
  452. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x1b) & 0x10)) PanelID = 0x12;
  453. }
  454. if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) {
  455. DelayIndex = PanelID & 0x0f;
  456. } else {
  457. DelayIndex = PanelID >> 4;
  458. }
  459. if((DelayTime >= 2) && ((PanelID & 0x0f) == 1)) {
  460. Delay = 3;
  461. } else {
  462. if(DelayTime >= 2) DelayTime -= 2;
  463. if(!(DelayTime & 0x01)) {
  464. Delay = SiS_Pr->SiS_PanelDelayTblLVDS[DelayIndex].timer[0];
  465. } else {
  466. Delay = SiS_Pr->SiS_PanelDelayTblLVDS[DelayIndex].timer[1];
  467. }
  468. if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
  469. if(ROMAddr[0x13c] & 0x40) {
  470. if(!(DelayTime & 0x01)) {
  471. Delay = (unsigned short)ROMAddr[0x17e];
  472. } else {
  473. Delay = (unsigned short)ROMAddr[0x17f];
  474. }
  475. }
  476. }
  477. }
  478. SiS_ShortDelay(SiS_Pr, Delay);
  479. }
  480. } else if(SiS_Pr->SiS_VBType & VB_SISVB) { /* 315 series, all bridges */
  481. DelayIndex = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4;
  482. if(!(DelayTime & 0x01)) {
  483. Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[0];
  484. } else {
  485. Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[1];
  486. }
  487. Delay <<= 8;
  488. SiS_DDC2Delay(SiS_Pr, Delay);
  489. }
  490. #endif /* SIS315H */
  491. }
  492. }
  493. #ifdef SIS315H
  494. static void
  495. SiS_PanelDelayLoop(struct SiS_Private *SiS_Pr, unsigned short DelayTime, unsigned short DelayLoop)
  496. {
  497. int i;
  498. for(i = 0; i < DelayLoop; i++) {
  499. SiS_PanelDelay(SiS_Pr, DelayTime);
  500. }
  501. }
  502. #endif
  503. /*********************************************/
  504. /* HELPER: WAIT-FOR-RETRACE FUNCTIONS */
  505. /*********************************************/
  506. void
  507. SiS_WaitRetrace1(struct SiS_Private *SiS_Pr)
  508. {
  509. unsigned short watchdog;
  510. if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x1f) & 0xc0) return;
  511. if(!(SiS_GetReg(SiS_Pr->SiS_P3d4,0x17) & 0x80)) return;
  512. watchdog = 65535;
  513. while((SiS_GetRegByte(SiS_Pr->SiS_P3da) & 0x08) && --watchdog);
  514. watchdog = 65535;
  515. while((!(SiS_GetRegByte(SiS_Pr->SiS_P3da) & 0x08)) && --watchdog);
  516. }
  517. #if defined(SIS300) || defined(SIS315H)
  518. static void
  519. SiS_WaitRetrace2(struct SiS_Private *SiS_Pr, unsigned short reg)
  520. {
  521. unsigned short watchdog;
  522. watchdog = 65535;
  523. while((SiS_GetReg(SiS_Pr->SiS_Part1Port,reg) & 0x02) && --watchdog);
  524. watchdog = 65535;
  525. while((!(SiS_GetReg(SiS_Pr->SiS_Part1Port,reg) & 0x02)) && --watchdog);
  526. }
  527. #endif
  528. static void
  529. SiS_WaitVBRetrace(struct SiS_Private *SiS_Pr)
  530. {
  531. if(SiS_Pr->ChipType < SIS_315H) {
  532. #ifdef SIS300
  533. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  534. if(!(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x20)) return;
  535. }
  536. if(!(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x80)) {
  537. SiS_WaitRetrace1(SiS_Pr);
  538. } else {
  539. SiS_WaitRetrace2(SiS_Pr, 0x25);
  540. }
  541. #endif
  542. } else {
  543. #ifdef SIS315H
  544. if(!(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x40)) {
  545. SiS_WaitRetrace1(SiS_Pr);
  546. } else {
  547. SiS_WaitRetrace2(SiS_Pr, 0x30);
  548. }
  549. #endif
  550. }
  551. }
  552. static void
  553. SiS_VBWait(struct SiS_Private *SiS_Pr)
  554. {
  555. unsigned short tempal,temp,i,j;
  556. temp = 0;
  557. for(i = 0; i < 3; i++) {
  558. for(j = 0; j < 100; j++) {
  559. tempal = SiS_GetRegByte(SiS_Pr->SiS_P3da);
  560. if(temp & 0x01) {
  561. if((tempal & 0x08)) continue;
  562. else break;
  563. } else {
  564. if(!(tempal & 0x08)) continue;
  565. else break;
  566. }
  567. }
  568. temp ^= 0x01;
  569. }
  570. }
  571. static void
  572. SiS_VBLongWait(struct SiS_Private *SiS_Pr)
  573. {
  574. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  575. SiS_VBWait(SiS_Pr);
  576. } else {
  577. SiS_WaitRetrace1(SiS_Pr);
  578. }
  579. }
  580. /*********************************************/
  581. /* HELPER: MISC */
  582. /*********************************************/
  583. #ifdef SIS300
  584. static bool
  585. SiS_Is301B(struct SiS_Private *SiS_Pr)
  586. {
  587. if(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x01) >= 0xb0) return true;
  588. return false;
  589. }
  590. #endif
  591. static bool
  592. SiS_CRT2IsLCD(struct SiS_Private *SiS_Pr)
  593. {
  594. if(SiS_Pr->ChipType == SIS_730) {
  595. if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x20) return true;
  596. }
  597. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x30) & 0x20) return true;
  598. return false;
  599. }
  600. bool
  601. SiS_IsDualEdge(struct SiS_Private *SiS_Pr)
  602. {
  603. #ifdef SIS315H
  604. if(SiS_Pr->ChipType >= SIS_315H) {
  605. if((SiS_Pr->ChipType != SIS_650) || (SiS_GetReg(SiS_Pr->SiS_P3d4,0x5f) & 0xf0)) {
  606. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x38) & EnableDualEdge) return true;
  607. }
  608. }
  609. #endif
  610. return false;
  611. }
  612. bool
  613. SiS_IsVAMode(struct SiS_Private *SiS_Pr)
  614. {
  615. #ifdef SIS315H
  616. unsigned short flag;
  617. if(SiS_Pr->ChipType >= SIS_315H) {
  618. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  619. if((flag & EnableDualEdge) && (flag & SetToLCDA)) return true;
  620. }
  621. #endif
  622. return false;
  623. }
  624. #ifdef SIS315H
  625. static bool
  626. SiS_IsVAorLCD(struct SiS_Private *SiS_Pr)
  627. {
  628. if(SiS_IsVAMode(SiS_Pr)) return true;
  629. if(SiS_CRT2IsLCD(SiS_Pr)) return true;
  630. return false;
  631. }
  632. #endif
  633. static bool
  634. SiS_IsDualLink(struct SiS_Private *SiS_Pr)
  635. {
  636. #ifdef SIS315H
  637. if(SiS_Pr->ChipType >= SIS_315H) {
  638. if((SiS_CRT2IsLCD(SiS_Pr)) ||
  639. (SiS_IsVAMode(SiS_Pr))) {
  640. if(SiS_Pr->SiS_LCDInfo & LCDDualLink) return true;
  641. }
  642. }
  643. #endif
  644. return false;
  645. }
  646. #ifdef SIS315H
  647. static bool
  648. SiS_TVEnabled(struct SiS_Private *SiS_Pr)
  649. {
  650. if((SiS_GetReg(SiS_Pr->SiS_Part2Port,0x00) & 0x0f) != 0x0c) return true;
  651. if(SiS_Pr->SiS_VBType & VB_SISYPBPR) {
  652. if(SiS_GetReg(SiS_Pr->SiS_Part2Port,0x4d) & 0x10) return true;
  653. }
  654. return false;
  655. }
  656. #endif
  657. #ifdef SIS315H
  658. static bool
  659. SiS_LCDAEnabled(struct SiS_Private *SiS_Pr)
  660. {
  661. if(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x13) & 0x04) return true;
  662. return false;
  663. }
  664. #endif
  665. #ifdef SIS315H
  666. static bool
  667. SiS_WeHaveBacklightCtrl(struct SiS_Private *SiS_Pr)
  668. {
  669. if((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->ChipType < SIS_661)) {
  670. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x79) & 0x10) return true;
  671. }
  672. return false;
  673. }
  674. #endif
  675. #ifdef SIS315H
  676. static bool
  677. SiS_IsNotM650orLater(struct SiS_Private *SiS_Pr)
  678. {
  679. unsigned short flag;
  680. if(SiS_Pr->ChipType == SIS_650) {
  681. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x5f) & 0xf0;
  682. /* Check for revision != A0 only */
  683. if((flag == 0xe0) || (flag == 0xc0) ||
  684. (flag == 0xb0) || (flag == 0x90)) return false;
  685. } else if(SiS_Pr->ChipType >= SIS_661) return false;
  686. return true;
  687. }
  688. #endif
  689. #ifdef SIS315H
  690. static bool
  691. SiS_IsYPbPr(struct SiS_Private *SiS_Pr)
  692. {
  693. if(SiS_Pr->ChipType >= SIS_315H) {
  694. /* YPrPb = 0x08 */
  695. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x38) & EnableCHYPbPr) return true;
  696. }
  697. return false;
  698. }
  699. #endif
  700. #ifdef SIS315H
  701. static bool
  702. SiS_IsChScart(struct SiS_Private *SiS_Pr)
  703. {
  704. if(SiS_Pr->ChipType >= SIS_315H) {
  705. /* Scart = 0x04 */
  706. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x38) & EnableCHScart) return true;
  707. }
  708. return false;
  709. }
  710. #endif
  711. #ifdef SIS315H
  712. static bool
  713. SiS_IsTVOrYPbPrOrScart(struct SiS_Private *SiS_Pr)
  714. {
  715. unsigned short flag;
  716. if(SiS_Pr->ChipType >= SIS_315H) {
  717. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  718. if(flag & SetCRT2ToTV) return true;
  719. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  720. if(flag & EnableCHYPbPr) return true; /* = YPrPb = 0x08 */
  721. if(flag & EnableCHScart) return true; /* = Scart = 0x04 - TW */
  722. } else {
  723. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  724. if(flag & SetCRT2ToTV) return true;
  725. }
  726. return false;
  727. }
  728. #endif
  729. #ifdef SIS315H
  730. static bool
  731. SiS_IsLCDOrLCDA(struct SiS_Private *SiS_Pr)
  732. {
  733. unsigned short flag;
  734. if(SiS_Pr->ChipType >= SIS_315H) {
  735. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  736. if(flag & SetCRT2ToLCD) return true;
  737. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  738. if(flag & SetToLCDA) return true;
  739. } else {
  740. flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  741. if(flag & SetCRT2ToLCD) return true;
  742. }
  743. return false;
  744. }
  745. #endif
  746. static bool
  747. SiS_HaveBridge(struct SiS_Private *SiS_Pr)
  748. {
  749. unsigned short flag;
  750. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  751. return true;
  752. } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
  753. flag = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x00);
  754. if((flag == 1) || (flag == 2)) return true;
  755. }
  756. return false;
  757. }
  758. static bool
  759. SiS_BridgeIsEnabled(struct SiS_Private *SiS_Pr)
  760. {
  761. unsigned short flag;
  762. if(SiS_HaveBridge(SiS_Pr)) {
  763. flag = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00);
  764. if(SiS_Pr->ChipType < SIS_315H) {
  765. flag &= 0xa0;
  766. if((flag == 0x80) || (flag == 0x20)) return true;
  767. } else {
  768. flag &= 0x50;
  769. if((flag == 0x40) || (flag == 0x10)) return true;
  770. }
  771. }
  772. return false;
  773. }
  774. static bool
  775. SiS_BridgeInSlavemode(struct SiS_Private *SiS_Pr)
  776. {
  777. unsigned short flag1;
  778. flag1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x31);
  779. if(flag1 & (SetInSlaveMode >> 8)) return true;
  780. return false;
  781. }
  782. /*********************************************/
  783. /* GET VIDEO BRIDGE CONFIG INFO */
  784. /*********************************************/
  785. /* Setup general purpose IO for Chrontel communication */
  786. #ifdef SIS300
  787. void
  788. SiS_SetChrontelGPIO(struct SiS_Private *SiS_Pr, unsigned short myvbinfo)
  789. {
  790. unsigned int acpibase;
  791. unsigned short temp;
  792. if(!(SiS_Pr->SiS_ChSW)) return;
  793. acpibase = sisfb_read_lpc_pci_dword(SiS_Pr, 0x74);
  794. acpibase &= 0xFFFF;
  795. if(!acpibase) return;
  796. temp = SiS_GetRegShort((acpibase + 0x3c)); /* ACPI register 0x3c: GP Event 1 I/O mode select */
  797. temp &= 0xFEFF;
  798. SiS_SetRegShort((acpibase + 0x3c), temp);
  799. temp = SiS_GetRegShort((acpibase + 0x3c));
  800. temp = SiS_GetRegShort((acpibase + 0x3a)); /* ACPI register 0x3a: GP Pin Level (low/high) */
  801. temp &= 0xFEFF;
  802. if(!(myvbinfo & SetCRT2ToTV)) temp |= 0x0100;
  803. SiS_SetRegShort((acpibase + 0x3a), temp);
  804. temp = SiS_GetRegShort((acpibase + 0x3a));
  805. }
  806. #endif
  807. void
  808. SiS_GetVBInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
  809. unsigned short ModeIdIndex, int checkcrt2mode)
  810. {
  811. unsigned short tempax, tempbx, temp;
  812. unsigned short modeflag, resinfo = 0;
  813. SiS_Pr->SiS_SetFlag = 0;
  814. modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
  815. SiS_Pr->SiS_ModeType = modeflag & ModeTypeMask;
  816. if((ModeNo > 0x13) && (!SiS_Pr->UseCustomMode)) {
  817. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  818. }
  819. tempbx = 0;
  820. if(SiS_HaveBridge(SiS_Pr)) {
  821. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  822. tempbx |= temp;
  823. tempax = SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) << 8;
  824. tempax &= (DriverMode | LoadDACFlag | SetNotSimuMode | SetPALTV);
  825. tempbx |= tempax;
  826. #ifdef SIS315H
  827. if(SiS_Pr->ChipType >= SIS_315H) {
  828. if(SiS_Pr->SiS_VBType & VB_SISLCDA) {
  829. if(ModeNo == 0x03) {
  830. /* Mode 0x03 is never in driver mode */
  831. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x31,0xbf);
  832. }
  833. if(!(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & (DriverMode >> 8))) {
  834. /* Reset LCDA setting if not driver mode */
  835. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x38,0xfc);
  836. }
  837. if(IS_SIS650) {
  838. if(SiS_Pr->SiS_UseLCDA) {
  839. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x5f) & 0xF0) {
  840. if((ModeNo <= 0x13) || (!(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & (DriverMode >> 8)))) {
  841. SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x38,(EnableDualEdge | SetToLCDA));
  842. }
  843. }
  844. }
  845. }
  846. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  847. if((temp & (EnableDualEdge | SetToLCDA)) == (EnableDualEdge | SetToLCDA)) {
  848. tempbx |= SetCRT2ToLCDA;
  849. }
  850. }
  851. if(SiS_Pr->ChipType >= SIS_661) { /* New CR layout */
  852. tempbx &= ~(SetCRT2ToYPbPr525750 | SetCRT2ToHiVision);
  853. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x38) & 0x04) {
  854. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35) & 0xe0;
  855. if(temp == 0x60) tempbx |= SetCRT2ToHiVision;
  856. else if(SiS_Pr->SiS_VBType & VB_SISYPBPR) {
  857. tempbx |= SetCRT2ToYPbPr525750;
  858. }
  859. }
  860. }
  861. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  862. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  863. if(temp & SetToLCDA) {
  864. tempbx |= SetCRT2ToLCDA;
  865. }
  866. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  867. if(temp & EnableCHYPbPr) {
  868. tempbx |= SetCRT2ToCHYPbPr;
  869. }
  870. }
  871. }
  872. }
  873. #endif /* SIS315H */
  874. if(!(SiS_Pr->SiS_VBType & VB_SISVGA2)) {
  875. tempbx &= ~(SetCRT2ToRAMDAC);
  876. }
  877. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  878. temp = SetCRT2ToSVIDEO |
  879. SetCRT2ToAVIDEO |
  880. SetCRT2ToSCART |
  881. SetCRT2ToLCDA |
  882. SetCRT2ToLCD |
  883. SetCRT2ToRAMDAC |
  884. SetCRT2ToHiVision |
  885. SetCRT2ToYPbPr525750;
  886. } else {
  887. if(SiS_Pr->ChipType >= SIS_315H) {
  888. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  889. temp = SetCRT2ToAVIDEO |
  890. SetCRT2ToSVIDEO |
  891. SetCRT2ToSCART |
  892. SetCRT2ToLCDA |
  893. SetCRT2ToLCD |
  894. SetCRT2ToCHYPbPr;
  895. } else {
  896. temp = SetCRT2ToLCDA |
  897. SetCRT2ToLCD;
  898. }
  899. } else {
  900. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  901. temp = SetCRT2ToTV | SetCRT2ToLCD;
  902. } else {
  903. temp = SetCRT2ToLCD;
  904. }
  905. }
  906. }
  907. if(!(tempbx & temp)) {
  908. tempax = DisableCRT2Display;
  909. tempbx = 0;
  910. }
  911. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  912. unsigned short clearmask = ( DriverMode |
  913. DisableCRT2Display |
  914. LoadDACFlag |
  915. SetNotSimuMode |
  916. SetInSlaveMode |
  917. SetPALTV |
  918. SwitchCRT2 |
  919. SetSimuScanMode );
  920. if(tempbx & SetCRT2ToLCDA) tempbx &= (clearmask | SetCRT2ToLCDA);
  921. if(tempbx & SetCRT2ToRAMDAC) tempbx &= (clearmask | SetCRT2ToRAMDAC);
  922. if(tempbx & SetCRT2ToLCD) tempbx &= (clearmask | SetCRT2ToLCD);
  923. if(tempbx & SetCRT2ToSCART) tempbx &= (clearmask | SetCRT2ToSCART);
  924. if(tempbx & SetCRT2ToHiVision) tempbx &= (clearmask | SetCRT2ToHiVision);
  925. if(tempbx & SetCRT2ToYPbPr525750) tempbx &= (clearmask | SetCRT2ToYPbPr525750);
  926. } else {
  927. if(SiS_Pr->ChipType >= SIS_315H) {
  928. if(tempbx & SetCRT2ToLCDA) {
  929. tempbx &= (0xFF00|SwitchCRT2|SetSimuScanMode);
  930. }
  931. }
  932. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  933. if(tempbx & SetCRT2ToTV) {
  934. tempbx &= (0xFF00|SetCRT2ToTV|SwitchCRT2|SetSimuScanMode);
  935. }
  936. }
  937. if(tempbx & SetCRT2ToLCD) {
  938. tempbx &= (0xFF00|SetCRT2ToLCD|SwitchCRT2|SetSimuScanMode);
  939. }
  940. if(SiS_Pr->ChipType >= SIS_315H) {
  941. if(tempbx & SetCRT2ToLCDA) {
  942. tempbx |= SetCRT2ToLCD;
  943. }
  944. }
  945. }
  946. if(tempax & DisableCRT2Display) {
  947. if(!(tempbx & (SwitchCRT2 | SetSimuScanMode))) {
  948. tempbx = SetSimuScanMode | DisableCRT2Display;
  949. }
  950. }
  951. if(!(tempbx & DriverMode)) tempbx |= SetSimuScanMode;
  952. /* LVDS/CHRONTEL (LCD/TV) and 301BDH (LCD) can only be slave in 8bpp modes */
  953. if(SiS_Pr->SiS_ModeType <= ModeVGA) {
  954. if( (SiS_Pr->SiS_IF_DEF_LVDS == 1) ||
  955. ((SiS_Pr->SiS_VBType & VB_NoLCD) && (tempbx & SetCRT2ToLCD)) ) {
  956. modeflag &= (~CRT2Mode);
  957. }
  958. }
  959. if(!(tempbx & SetSimuScanMode)) {
  960. if(tempbx & SwitchCRT2) {
  961. if((!(modeflag & CRT2Mode)) && (checkcrt2mode)) {
  962. if(resinfo != SIS_RI_1600x1200) {
  963. tempbx |= SetSimuScanMode;
  964. }
  965. }
  966. } else {
  967. if(SiS_BridgeIsEnabled(SiS_Pr)) {
  968. if(!(tempbx & DriverMode)) {
  969. if(SiS_BridgeInSlavemode(SiS_Pr)) {
  970. tempbx |= SetSimuScanMode;
  971. }
  972. }
  973. }
  974. }
  975. }
  976. if(!(tempbx & DisableCRT2Display)) {
  977. if(tempbx & DriverMode) {
  978. if(tempbx & SetSimuScanMode) {
  979. if((!(modeflag & CRT2Mode)) && (checkcrt2mode)) {
  980. if(resinfo != SIS_RI_1600x1200) {
  981. tempbx |= SetInSlaveMode;
  982. }
  983. }
  984. }
  985. } else {
  986. tempbx |= SetInSlaveMode;
  987. }
  988. }
  989. }
  990. SiS_Pr->SiS_VBInfo = tempbx;
  991. #ifdef SIS300
  992. if(SiS_Pr->ChipType == SIS_630) {
  993. SiS_SetChrontelGPIO(SiS_Pr, SiS_Pr->SiS_VBInfo);
  994. }
  995. #endif
  996. #if 0
  997. printk(KERN_DEBUG "sisfb: (init301: VBInfo= 0x%04x, SetFlag=0x%04x)\n",
  998. SiS_Pr->SiS_VBInfo, SiS_Pr->SiS_SetFlag);
  999. #endif
  1000. }
  1001. /*********************************************/
  1002. /* DETERMINE YPbPr MODE */
  1003. /*********************************************/
  1004. void
  1005. SiS_SetYPbPr(struct SiS_Private *SiS_Pr)
  1006. {
  1007. unsigned char temp;
  1008. /* Note: This variable is only used on 30xLV systems.
  1009. * CR38 has a different meaning on LVDS/CH7019 systems.
  1010. * On 661 and later, these bits moved to CR35.
  1011. *
  1012. * On 301, 301B, only HiVision 1080i is supported.
  1013. * On 30xLV, 301C, only YPbPr 1080i is supported.
  1014. */
  1015. SiS_Pr->SiS_YPbPr = 0;
  1016. if(SiS_Pr->ChipType >= SIS_661) return;
  1017. if(SiS_Pr->SiS_VBType) {
  1018. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  1019. SiS_Pr->SiS_YPbPr = YPbPrHiVision;
  1020. }
  1021. }
  1022. if(SiS_Pr->ChipType >= SIS_315H) {
  1023. if(SiS_Pr->SiS_VBType & VB_SISYPBPR) {
  1024. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  1025. if(temp & 0x08) {
  1026. switch((temp >> 4)) {
  1027. case 0x00: SiS_Pr->SiS_YPbPr = YPbPr525i; break;
  1028. case 0x01: SiS_Pr->SiS_YPbPr = YPbPr525p; break;
  1029. case 0x02: SiS_Pr->SiS_YPbPr = YPbPr750p; break;
  1030. case 0x03: SiS_Pr->SiS_YPbPr = YPbPrHiVision; break;
  1031. }
  1032. }
  1033. }
  1034. }
  1035. }
  1036. /*********************************************/
  1037. /* DETERMINE TVMode flag */
  1038. /*********************************************/
  1039. void
  1040. SiS_SetTVMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  1041. {
  1042. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  1043. unsigned short temp, temp1, resinfo = 0, romindex = 0;
  1044. unsigned char OutputSelect = *SiS_Pr->pSiS_OutputSelect;
  1045. SiS_Pr->SiS_TVMode = 0;
  1046. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) return;
  1047. if(SiS_Pr->UseCustomMode) return;
  1048. if(ModeNo > 0x13) {
  1049. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  1050. }
  1051. if(SiS_Pr->ChipType < SIS_661) {
  1052. if(SiS_Pr->SiS_VBInfo & SetPALTV) SiS_Pr->SiS_TVMode |= TVSetPAL;
  1053. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  1054. temp = 0;
  1055. if((SiS_Pr->ChipType == SIS_630) ||
  1056. (SiS_Pr->ChipType == SIS_730)) {
  1057. temp = 0x35;
  1058. romindex = 0xfe;
  1059. } else if(SiS_Pr->ChipType >= SIS_315H) {
  1060. temp = 0x38;
  1061. if(SiS_Pr->ChipType < XGI_20) {
  1062. romindex = 0xf3;
  1063. if(SiS_Pr->ChipType >= SIS_330) romindex = 0x11b;
  1064. }
  1065. }
  1066. if(temp) {
  1067. if(romindex && SiS_Pr->SiS_UseROM && (!(SiS_Pr->SiS_ROMNew))) {
  1068. OutputSelect = ROMAddr[romindex];
  1069. if(!(OutputSelect & EnablePALMN)) {
  1070. SiS_SetRegAND(SiS_Pr->SiS_P3d4,temp,0x3F);
  1071. }
  1072. }
  1073. temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,temp);
  1074. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  1075. if(temp1 & EnablePALM) { /* 0x40 */
  1076. SiS_Pr->SiS_TVMode |= TVSetPALM;
  1077. SiS_Pr->SiS_TVMode &= ~TVSetPAL;
  1078. } else if(temp1 & EnablePALN) { /* 0x80 */
  1079. SiS_Pr->SiS_TVMode |= TVSetPALN;
  1080. }
  1081. } else {
  1082. if(temp1 & EnableNTSCJ) { /* 0x40 */
  1083. SiS_Pr->SiS_TVMode |= TVSetNTSCJ;
  1084. }
  1085. }
  1086. }
  1087. /* Translate HiVision/YPbPr to our new flags */
  1088. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  1089. if(SiS_Pr->SiS_YPbPr == YPbPr750p) SiS_Pr->SiS_TVMode |= TVSetYPbPr750p;
  1090. else if(SiS_Pr->SiS_YPbPr == YPbPr525p) SiS_Pr->SiS_TVMode |= TVSetYPbPr525p;
  1091. else if(SiS_Pr->SiS_YPbPr == YPbPrHiVision) SiS_Pr->SiS_TVMode |= TVSetHiVision;
  1092. else SiS_Pr->SiS_TVMode |= TVSetYPbPr525i;
  1093. if(SiS_Pr->SiS_TVMode & (TVSetYPbPr750p | TVSetYPbPr525p | TVSetYPbPr525i)) {
  1094. SiS_Pr->SiS_VBInfo &= ~SetCRT2ToHiVision;
  1095. SiS_Pr->SiS_VBInfo |= SetCRT2ToYPbPr525750;
  1096. } else if(SiS_Pr->SiS_TVMode & TVSetHiVision) {
  1097. SiS_Pr->SiS_TVMode |= TVSetPAL;
  1098. }
  1099. }
  1100. } else if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  1101. if(SiS_Pr->SiS_CHOverScan) {
  1102. if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) {
  1103. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35);
  1104. if((temp & TVOverScan) || (SiS_Pr->SiS_CHOverScan == 1)) {
  1105. SiS_Pr->SiS_TVMode |= TVSetCHOverScan;
  1106. }
  1107. } else if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  1108. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x79);
  1109. if((temp & 0x80) || (SiS_Pr->SiS_CHOverScan == 1)) {
  1110. SiS_Pr->SiS_TVMode |= TVSetCHOverScan;
  1111. }
  1112. }
  1113. if(SiS_Pr->SiS_CHSOverScan) {
  1114. SiS_Pr->SiS_TVMode |= TVSetCHOverScan;
  1115. }
  1116. }
  1117. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  1118. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
  1119. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  1120. if(temp & EnablePALM) SiS_Pr->SiS_TVMode |= TVSetPALM;
  1121. else if(temp & EnablePALN) SiS_Pr->SiS_TVMode |= TVSetPALN;
  1122. } else {
  1123. if(temp & EnableNTSCJ) {
  1124. SiS_Pr->SiS_TVMode |= TVSetNTSCJ;
  1125. }
  1126. }
  1127. }
  1128. }
  1129. } else { /* 661 and later */
  1130. temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35);
  1131. if(temp1 & 0x01) {
  1132. SiS_Pr->SiS_TVMode |= TVSetPAL;
  1133. if(temp1 & 0x08) {
  1134. SiS_Pr->SiS_TVMode |= TVSetPALN;
  1135. } else if(temp1 & 0x04) {
  1136. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  1137. SiS_Pr->SiS_TVMode &= ~TVSetPAL;
  1138. }
  1139. SiS_Pr->SiS_TVMode |= TVSetPALM;
  1140. }
  1141. } else {
  1142. if(temp1 & 0x02) {
  1143. SiS_Pr->SiS_TVMode |= TVSetNTSCJ;
  1144. }
  1145. }
  1146. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  1147. if(SiS_Pr->SiS_CHOverScan) {
  1148. if((temp1 & 0x10) || (SiS_Pr->SiS_CHOverScan == 1)) {
  1149. SiS_Pr->SiS_TVMode |= TVSetCHOverScan;
  1150. }
  1151. }
  1152. }
  1153. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  1154. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  1155. temp1 &= 0xe0;
  1156. if(temp1 == 0x00) SiS_Pr->SiS_TVMode |= TVSetYPbPr525i;
  1157. else if(temp1 == 0x20) SiS_Pr->SiS_TVMode |= TVSetYPbPr525p;
  1158. else if(temp1 == 0x40) SiS_Pr->SiS_TVMode |= TVSetYPbPr750p;
  1159. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  1160. SiS_Pr->SiS_TVMode |= (TVSetHiVision | TVSetPAL);
  1161. }
  1162. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToYPbPr525750 | SetCRT2ToHiVision)) {
  1163. if(resinfo == SIS_RI_800x480 || resinfo == SIS_RI_1024x576 || resinfo == SIS_RI_1280x720) {
  1164. SiS_Pr->SiS_TVMode |= TVAspect169;
  1165. } else {
  1166. temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x39);
  1167. if(temp1 & 0x02) {
  1168. if(SiS_Pr->SiS_TVMode & (TVSetYPbPr750p | TVSetHiVision)) {
  1169. SiS_Pr->SiS_TVMode |= TVAspect169;
  1170. } else {
  1171. SiS_Pr->SiS_TVMode |= TVAspect43LB;
  1172. }
  1173. } else {
  1174. SiS_Pr->SiS_TVMode |= TVAspect43;
  1175. }
  1176. }
  1177. }
  1178. }
  1179. }
  1180. if(SiS_Pr->SiS_VBInfo & SetCRT2ToSCART) SiS_Pr->SiS_TVMode |= TVSetPAL;
  1181. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  1182. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  1183. SiS_Pr->SiS_TVMode |= TVSetPAL;
  1184. SiS_Pr->SiS_TVMode &= ~(TVSetPALM | TVSetPALN | TVSetNTSCJ);
  1185. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  1186. if(SiS_Pr->SiS_TVMode & (TVSetYPbPr525i | TVSetYPbPr525p | TVSetYPbPr750p)) {
  1187. SiS_Pr->SiS_TVMode &= ~(TVSetPAL | TVSetNTSCJ | TVSetPALM | TVSetPALN);
  1188. }
  1189. }
  1190. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  1191. if(!(SiS_Pr->SiS_VBInfo & SetNotSimuMode)) {
  1192. SiS_Pr->SiS_TVMode |= TVSetTVSimuMode;
  1193. }
  1194. }
  1195. if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) {
  1196. if(resinfo == SIS_RI_1024x768) {
  1197. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) {
  1198. SiS_Pr->SiS_TVMode |= TVSet525p1024;
  1199. } else if(!(SiS_Pr->SiS_TVMode & (TVSetHiVision | TVSetYPbPr750p))) {
  1200. SiS_Pr->SiS_TVMode |= TVSetNTSC1024;
  1201. }
  1202. }
  1203. }
  1204. SiS_Pr->SiS_TVMode |= TVRPLLDIV2XO;
  1205. if((SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) &&
  1206. (SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  1207. SiS_Pr->SiS_TVMode &= ~TVRPLLDIV2XO;
  1208. } else if(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p)) {
  1209. SiS_Pr->SiS_TVMode &= ~TVRPLLDIV2XO;
  1210. } else if(!(SiS_Pr->SiS_VBType & VB_SIS30xBLV)) {
  1211. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) {
  1212. SiS_Pr->SiS_TVMode &= ~TVRPLLDIV2XO;
  1213. }
  1214. }
  1215. }
  1216. SiS_Pr->SiS_VBInfo &= ~SetPALTV;
  1217. }
  1218. /*********************************************/
  1219. /* GET LCD INFO */
  1220. /*********************************************/
  1221. static unsigned short
  1222. SiS_GetBIOSLCDResInfo(struct SiS_Private *SiS_Pr)
  1223. {
  1224. unsigned short temp = SiS_Pr->SiS_LCDResInfo;
  1225. /* Translate my LCDResInfo to BIOS value */
  1226. switch(temp) {
  1227. case Panel_1280x768_2: temp = Panel_1280x768; break;
  1228. case Panel_1280x800_2: temp = Panel_1280x800; break;
  1229. case Panel_1280x854: temp = Panel661_1280x854; break;
  1230. }
  1231. return temp;
  1232. }
  1233. static void
  1234. SiS_GetLCDInfoBIOS(struct SiS_Private *SiS_Pr)
  1235. {
  1236. #ifdef SIS315H
  1237. unsigned char *ROMAddr;
  1238. unsigned short temp;
  1239. if((ROMAddr = GetLCDStructPtr661(SiS_Pr))) {
  1240. if((temp = SISGETROMW(6)) != SiS_Pr->PanelHT) {
  1241. SiS_Pr->SiS_NeedRomModeData = true;
  1242. SiS_Pr->PanelHT = temp;
  1243. }
  1244. if((temp = SISGETROMW(8)) != SiS_Pr->PanelVT) {
  1245. SiS_Pr->SiS_NeedRomModeData = true;
  1246. SiS_Pr->PanelVT = temp;
  1247. }
  1248. SiS_Pr->PanelHRS = SISGETROMW(10);
  1249. SiS_Pr->PanelHRE = SISGETROMW(12);
  1250. SiS_Pr->PanelVRS = SISGETROMW(14);
  1251. SiS_Pr->PanelVRE = SISGETROMW(16);
  1252. SiS_Pr->PanelVCLKIdx315 = VCLK_CUSTOM_315;
  1253. SiS_Pr->SiS_VCLKData[VCLK_CUSTOM_315].CLOCK =
  1254. SiS_Pr->SiS_VBVCLKData[VCLK_CUSTOM_315].CLOCK = (unsigned short)((unsigned char)ROMAddr[18]);
  1255. SiS_Pr->SiS_VCLKData[VCLK_CUSTOM_315].SR2B =
  1256. SiS_Pr->SiS_VBVCLKData[VCLK_CUSTOM_315].Part4_A = ROMAddr[19];
  1257. SiS_Pr->SiS_VCLKData[VCLK_CUSTOM_315].SR2C =
  1258. SiS_Pr->SiS_VBVCLKData[VCLK_CUSTOM_315].Part4_B = ROMAddr[20];
  1259. }
  1260. #endif
  1261. }
  1262. static void
  1263. SiS_CheckScaling(struct SiS_Private *SiS_Pr, unsigned short resinfo,
  1264. const unsigned char *nonscalingmodes)
  1265. {
  1266. int i = 0;
  1267. while(nonscalingmodes[i] != 0xff) {
  1268. if(nonscalingmodes[i++] == resinfo) {
  1269. if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) ||
  1270. (SiS_Pr->UsePanelScaler == -1)) {
  1271. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1272. }
  1273. break;
  1274. }
  1275. }
  1276. }
  1277. void
  1278. SiS_GetLCDResInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  1279. {
  1280. unsigned short temp,modeflag,resinfo=0,modexres=0,modeyres=0;
  1281. bool panelcanscale = false;
  1282. #ifdef SIS300
  1283. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  1284. static const unsigned char SiS300SeriesLCDRes[] =
  1285. { 0, 1, 2, 3, 7, 4, 5, 8,
  1286. 0, 0, 10, 0, 0, 0, 0, 15 };
  1287. #endif
  1288. #ifdef SIS315H
  1289. unsigned char *myptr = NULL;
  1290. #endif
  1291. SiS_Pr->SiS_LCDResInfo = 0;
  1292. SiS_Pr->SiS_LCDTypeInfo = 0;
  1293. SiS_Pr->SiS_LCDInfo = 0;
  1294. SiS_Pr->PanelHRS = 999; /* HSync start */
  1295. SiS_Pr->PanelHRE = 999; /* HSync end */
  1296. SiS_Pr->PanelVRS = 999; /* VSync start */
  1297. SiS_Pr->PanelVRE = 999; /* VSync end */
  1298. SiS_Pr->SiS_NeedRomModeData = false;
  1299. /* Alternative 1600x1200@60 timing for 1600x1200 LCDA */
  1300. SiS_Pr->Alternate1600x1200 = false;
  1301. if(!(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA))) return;
  1302. modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
  1303. if((ModeNo > 0x13) && (!SiS_Pr->UseCustomMode)) {
  1304. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  1305. modexres = SiS_Pr->SiS_ModeResInfo[resinfo].HTotal;
  1306. modeyres = SiS_Pr->SiS_ModeResInfo[resinfo].VTotal;
  1307. }
  1308. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36);
  1309. /* For broken BIOSes: Assume 1024x768 */
  1310. if(temp == 0) temp = 0x02;
  1311. if((SiS_Pr->ChipType >= SIS_661) || (SiS_Pr->SiS_ROMNew)) {
  1312. SiS_Pr->SiS_LCDTypeInfo = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x39) & 0x7c) >> 2;
  1313. } else if((SiS_Pr->ChipType < SIS_315H) || (SiS_Pr->ChipType >= SIS_661)) {
  1314. SiS_Pr->SiS_LCDTypeInfo = temp >> 4;
  1315. } else {
  1316. SiS_Pr->SiS_LCDTypeInfo = (temp & 0x0F) - 1;
  1317. }
  1318. temp &= 0x0f;
  1319. #ifdef SIS300
  1320. if(SiS_Pr->ChipType < SIS_315H) {
  1321. /* Very old BIOSes only know 7 sizes (NetVista 2179, 1.01g) */
  1322. if(SiS_Pr->SiS_VBType & VB_SIS301) {
  1323. if(temp < 0x0f) temp &= 0x07;
  1324. }
  1325. /* Translate 300 series LCDRes to 315 series for unified usage */
  1326. temp = SiS300SeriesLCDRes[temp];
  1327. }
  1328. #endif
  1329. /* Translate to our internal types */
  1330. #ifdef SIS315H
  1331. if(SiS_Pr->ChipType == SIS_550) {
  1332. if (temp == Panel310_1152x768) temp = Panel_320x240_2; /* Verified working */
  1333. else if(temp == Panel310_320x240_2) temp = Panel_320x240_2;
  1334. else if(temp == Panel310_320x240_3) temp = Panel_320x240_3;
  1335. } else if(SiS_Pr->ChipType >= SIS_661) {
  1336. if(temp == Panel661_1280x854) temp = Panel_1280x854;
  1337. }
  1338. #endif
  1339. if(SiS_Pr->SiS_VBType & VB_SISLVDS) { /* SiS LVDS */
  1340. if(temp == Panel310_1280x768) {
  1341. temp = Panel_1280x768_2;
  1342. }
  1343. if(SiS_Pr->SiS_ROMNew) {
  1344. if(temp == Panel661_1280x800) {
  1345. temp = Panel_1280x800_2;
  1346. }
  1347. }
  1348. }
  1349. SiS_Pr->SiS_LCDResInfo = temp;
  1350. #ifdef SIS300
  1351. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  1352. if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) {
  1353. SiS_Pr->SiS_LCDResInfo = Panel_Barco1366;
  1354. } else if(SiS_Pr->SiS_CustomT == CUT_PANEL848) {
  1355. SiS_Pr->SiS_LCDResInfo = Panel_848x480;
  1356. } else if(SiS_Pr->SiS_CustomT == CUT_PANEL856) {
  1357. SiS_Pr->SiS_LCDResInfo = Panel_856x480;
  1358. }
  1359. }
  1360. #endif
  1361. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  1362. if(SiS_Pr->SiS_LCDResInfo < SiS_Pr->SiS_PanelMin301)
  1363. SiS_Pr->SiS_LCDResInfo = SiS_Pr->SiS_PanelMin301;
  1364. } else {
  1365. if(SiS_Pr->SiS_LCDResInfo < SiS_Pr->SiS_PanelMinLVDS)
  1366. SiS_Pr->SiS_LCDResInfo = SiS_Pr->SiS_PanelMinLVDS;
  1367. }
  1368. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x37);
  1369. SiS_Pr->SiS_LCDInfo = temp & ~0x000e;
  1370. /* Need temp below! */
  1371. /* These must/can't scale no matter what */
  1372. switch(SiS_Pr->SiS_LCDResInfo) {
  1373. case Panel_320x240_1:
  1374. case Panel_320x240_2:
  1375. case Panel_320x240_3:
  1376. case Panel_1280x960:
  1377. SiS_Pr->SiS_LCDInfo &= ~DontExpandLCD;
  1378. break;
  1379. case Panel_640x480:
  1380. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1381. }
  1382. panelcanscale = (bool)(SiS_Pr->SiS_LCDInfo & DontExpandLCD);
  1383. if(!SiS_Pr->UsePanelScaler) SiS_Pr->SiS_LCDInfo &= ~DontExpandLCD;
  1384. else if(SiS_Pr->UsePanelScaler == 1) SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1385. /* Dual link, Pass 1:1 BIOS default, etc. */
  1386. #ifdef SIS315H
  1387. if(SiS_Pr->ChipType >= SIS_661) {
  1388. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  1389. if(temp & 0x08) SiS_Pr->SiS_LCDInfo |= LCDPass11;
  1390. }
  1391. if(SiS_Pr->SiS_VBType & VB_SISDUALLINK) {
  1392. if(SiS_Pr->SiS_ROMNew) {
  1393. if(temp & 0x02) SiS_Pr->SiS_LCDInfo |= LCDDualLink;
  1394. } else if((myptr = GetLCDStructPtr661(SiS_Pr))) {
  1395. if(myptr[2] & 0x01) SiS_Pr->SiS_LCDInfo |= LCDDualLink;
  1396. }
  1397. }
  1398. } else if(SiS_Pr->ChipType >= SIS_315H) {
  1399. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  1400. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x39) & 0x01) SiS_Pr->SiS_LCDInfo |= LCDPass11;
  1401. }
  1402. if((SiS_Pr->SiS_ROMNew) && (!(SiS_Pr->PanelSelfDetected))) {
  1403. SiS_Pr->SiS_LCDInfo &= ~(LCDRGB18Bit);
  1404. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x35);
  1405. if(temp & 0x01) SiS_Pr->SiS_LCDInfo |= LCDRGB18Bit;
  1406. if(SiS_Pr->SiS_VBType & VB_SISDUALLINK) {
  1407. if(temp & 0x02) SiS_Pr->SiS_LCDInfo |= LCDDualLink;
  1408. }
  1409. } else if(!(SiS_Pr->SiS_ROMNew)) {
  1410. if(SiS_Pr->SiS_VBType & VB_SISDUALLINK) {
  1411. if((SiS_Pr->SiS_CustomT == CUT_CLEVO1024) &&
  1412. (SiS_Pr->SiS_LCDResInfo == Panel_1024x768)) {
  1413. SiS_Pr->SiS_LCDInfo |= LCDDualLink;
  1414. }
  1415. if((SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) ||
  1416. (SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) ||
  1417. (SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) ||
  1418. (SiS_Pr->SiS_LCDResInfo == Panel_1680x1050)) {
  1419. SiS_Pr->SiS_LCDInfo |= LCDDualLink;
  1420. }
  1421. }
  1422. }
  1423. }
  1424. #endif
  1425. /* Pass 1:1 */
  1426. if((SiS_Pr->SiS_IF_DEF_LVDS == 1) || (SiS_Pr->SiS_VBType & VB_NoLCD)) {
  1427. /* Always center screen on LVDS (if scaling is disabled) */
  1428. SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  1429. } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
  1430. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  1431. /* Always center screen on SiS LVDS (if scaling is disabled) */
  1432. SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  1433. } else {
  1434. /* By default, pass 1:1 on SiS TMDS (if scaling is supported) */
  1435. if(panelcanscale) SiS_Pr->SiS_LCDInfo |= LCDPass11;
  1436. if(SiS_Pr->CenterScreen == 1) SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  1437. }
  1438. }
  1439. SiS_Pr->PanelVCLKIdx300 = VCLK65_300;
  1440. SiS_Pr->PanelVCLKIdx315 = VCLK108_2_315;
  1441. switch(SiS_Pr->SiS_LCDResInfo) {
  1442. case Panel_320x240_1:
  1443. case Panel_320x240_2:
  1444. case Panel_320x240_3: SiS_Pr->PanelXRes = 640; SiS_Pr->PanelYRes = 480;
  1445. SiS_Pr->PanelVRS = 24; SiS_Pr->PanelVRE = 3;
  1446. SiS_Pr->PanelVCLKIdx300 = VCLK28;
  1447. SiS_Pr->PanelVCLKIdx315 = VCLK28;
  1448. break;
  1449. case Panel_640x480: SiS_Pr->PanelXRes = 640; SiS_Pr->PanelYRes = 480;
  1450. SiS_Pr->PanelVRE = 3;
  1451. SiS_Pr->PanelVCLKIdx300 = VCLK28;
  1452. SiS_Pr->PanelVCLKIdx315 = VCLK28;
  1453. break;
  1454. case Panel_800x600: SiS_Pr->PanelXRes = 800; SiS_Pr->PanelYRes = 600;
  1455. SiS_Pr->PanelHT = 1056; SiS_Pr->PanelVT = 628;
  1456. SiS_Pr->PanelHRS = 40; SiS_Pr->PanelHRE = 128;
  1457. SiS_Pr->PanelVRS = 1; SiS_Pr->PanelVRE = 4;
  1458. SiS_Pr->PanelVCLKIdx300 = VCLK40;
  1459. SiS_Pr->PanelVCLKIdx315 = VCLK40;
  1460. break;
  1461. case Panel_1024x600: SiS_Pr->PanelXRes = 1024; SiS_Pr->PanelYRes = 600;
  1462. SiS_Pr->PanelHT = 1344; SiS_Pr->PanelVT = 800;
  1463. SiS_Pr->PanelHRS = 24; SiS_Pr->PanelHRE = 136;
  1464. SiS_Pr->PanelVRS = 2 /* 88 */ ; SiS_Pr->PanelVRE = 6;
  1465. SiS_Pr->PanelVCLKIdx300 = VCLK65_300;
  1466. SiS_Pr->PanelVCLKIdx315 = VCLK65_315;
  1467. break;
  1468. case Panel_1024x768: SiS_Pr->PanelXRes = 1024; SiS_Pr->PanelYRes = 768;
  1469. SiS_Pr->PanelHT = 1344; SiS_Pr->PanelVT = 806;
  1470. SiS_Pr->PanelHRS = 24; SiS_Pr->PanelHRE = 136;
  1471. SiS_Pr->PanelVRS = 3; SiS_Pr->PanelVRE = 6;
  1472. if(SiS_Pr->ChipType < SIS_315H) {
  1473. SiS_Pr->PanelHRS = 23;
  1474. SiS_Pr->PanelVRE = 5;
  1475. }
  1476. SiS_Pr->PanelVCLKIdx300 = VCLK65_300;
  1477. SiS_Pr->PanelVCLKIdx315 = VCLK65_315;
  1478. SiS_GetLCDInfoBIOS(SiS_Pr);
  1479. break;
  1480. case Panel_1152x768: SiS_Pr->PanelXRes = 1152; SiS_Pr->PanelYRes = 768;
  1481. SiS_Pr->PanelHT = 1344; SiS_Pr->PanelVT = 806;
  1482. SiS_Pr->PanelHRS = 24; SiS_Pr->PanelHRE = 136;
  1483. SiS_Pr->PanelVRS = 3; SiS_Pr->PanelVRE = 6;
  1484. if(SiS_Pr->ChipType < SIS_315H) {
  1485. SiS_Pr->PanelHRS = 23;
  1486. SiS_Pr->PanelVRE = 5;
  1487. }
  1488. SiS_Pr->PanelVCLKIdx300 = VCLK65_300;
  1489. SiS_Pr->PanelVCLKIdx315 = VCLK65_315;
  1490. break;
  1491. case Panel_1152x864: SiS_Pr->PanelXRes = 1152; SiS_Pr->PanelYRes = 864;
  1492. break;
  1493. case Panel_1280x720: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 720;
  1494. SiS_Pr->PanelHT = 1650; SiS_Pr->PanelVT = 750;
  1495. SiS_Pr->PanelHRS = 110; SiS_Pr->PanelHRE = 40;
  1496. SiS_Pr->PanelVRS = 5; SiS_Pr->PanelVRE = 5;
  1497. SiS_Pr->PanelVCLKIdx315 = VCLK_1280x720;
  1498. /* Data above for TMDS (projector); get from BIOS for LVDS */
  1499. SiS_GetLCDInfoBIOS(SiS_Pr);
  1500. break;
  1501. case Panel_1280x768: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 768;
  1502. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  1503. SiS_Pr->PanelHT = 1408; SiS_Pr->PanelVT = 806;
  1504. SiS_Pr->PanelVCLKIdx300 = VCLK81_300; /* ? */
  1505. SiS_Pr->PanelVCLKIdx315 = VCLK81_315; /* ? */
  1506. } else {
  1507. SiS_Pr->PanelHT = 1688; SiS_Pr->PanelVT = 802;
  1508. SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRS = 112;
  1509. SiS_Pr->PanelVRS = 3; SiS_Pr->PanelVRE = 6;
  1510. SiS_Pr->PanelVCLKIdx300 = VCLK81_300;
  1511. SiS_Pr->PanelVCLKIdx315 = VCLK81_315;
  1512. }
  1513. break;
  1514. case Panel_1280x768_2: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 768;
  1515. SiS_Pr->PanelHT = 1660; SiS_Pr->PanelVT = 806;
  1516. SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 112;
  1517. SiS_Pr->PanelVRS = 3; SiS_Pr->PanelVRE = 6;
  1518. SiS_Pr->PanelVCLKIdx315 = VCLK_1280x768_2;
  1519. SiS_GetLCDInfoBIOS(SiS_Pr);
  1520. break;
  1521. case Panel_1280x800: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 800;
  1522. SiS_Pr->PanelHT = 1408; SiS_Pr->PanelVT = 816;
  1523. SiS_Pr->PanelHRS = 21; SiS_Pr->PanelHRE = 24;
  1524. SiS_Pr->PanelVRS = 4; SiS_Pr->PanelVRE = 3;
  1525. SiS_Pr->PanelVCLKIdx315 = VCLK_1280x800_315;
  1526. SiS_GetLCDInfoBIOS(SiS_Pr);
  1527. break;
  1528. case Panel_1280x800_2: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 800;
  1529. SiS_Pr->PanelHT = 1552; SiS_Pr->PanelVT = 812;
  1530. SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 112;
  1531. SiS_Pr->PanelVRS = 4; SiS_Pr->PanelVRE = 3;
  1532. SiS_Pr->PanelVCLKIdx315 = VCLK_1280x800_315_2;
  1533. SiS_GetLCDInfoBIOS(SiS_Pr);
  1534. break;
  1535. case Panel_1280x854: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 854;
  1536. SiS_Pr->PanelHT = 1664; SiS_Pr->PanelVT = 861;
  1537. SiS_Pr->PanelHRS = 16; SiS_Pr->PanelHRE = 112;
  1538. SiS_Pr->PanelVRS = 1; SiS_Pr->PanelVRE = 3;
  1539. SiS_Pr->PanelVCLKIdx315 = VCLK_1280x854;
  1540. SiS_GetLCDInfoBIOS(SiS_Pr);
  1541. break;
  1542. case Panel_1280x960: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 960;
  1543. SiS_Pr->PanelHT = 1800; SiS_Pr->PanelVT = 1000;
  1544. SiS_Pr->PanelVCLKIdx300 = VCLK108_3_300;
  1545. SiS_Pr->PanelVCLKIdx315 = VCLK108_3_315;
  1546. if(resinfo == SIS_RI_1280x1024) {
  1547. SiS_Pr->PanelVCLKIdx300 = VCLK100_300;
  1548. SiS_Pr->PanelVCLKIdx315 = VCLK100_315;
  1549. }
  1550. break;
  1551. case Panel_1280x1024: SiS_Pr->PanelXRes = 1280; SiS_Pr->PanelYRes = 1024;
  1552. SiS_Pr->PanelHT = 1688; SiS_Pr->PanelVT = 1066;
  1553. SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 112;
  1554. SiS_Pr->PanelVRS = 1; SiS_Pr->PanelVRE = 3;
  1555. SiS_Pr->PanelVCLKIdx300 = VCLK108_3_300;
  1556. SiS_Pr->PanelVCLKIdx315 = VCLK108_2_315;
  1557. SiS_GetLCDInfoBIOS(SiS_Pr);
  1558. break;
  1559. case Panel_1400x1050: SiS_Pr->PanelXRes = 1400; SiS_Pr->PanelYRes = 1050;
  1560. SiS_Pr->PanelHT = 1688; SiS_Pr->PanelVT = 1066;
  1561. SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 112;
  1562. SiS_Pr->PanelVRS = 1; SiS_Pr->PanelVRE = 3;
  1563. SiS_Pr->PanelVCLKIdx315 = VCLK108_2_315;
  1564. SiS_GetLCDInfoBIOS(SiS_Pr);
  1565. break;
  1566. case Panel_1600x1200: SiS_Pr->PanelXRes = 1600; SiS_Pr->PanelYRes = 1200;
  1567. SiS_Pr->PanelHT = 2160; SiS_Pr->PanelVT = 1250;
  1568. SiS_Pr->PanelHRS = 64; SiS_Pr->PanelHRE = 192;
  1569. SiS_Pr->PanelVRS = 1; SiS_Pr->PanelVRE = 3;
  1570. SiS_Pr->PanelVCLKIdx315 = VCLK162_315;
  1571. if(SiS_Pr->SiS_VBType & VB_SISTMDSLCDA) {
  1572. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  1573. SiS_Pr->PanelHT = 1760; SiS_Pr->PanelVT = 1235;
  1574. SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 32;
  1575. SiS_Pr->PanelVRS = 2; SiS_Pr->PanelVRE = 4;
  1576. SiS_Pr->PanelVCLKIdx315 = VCLK130_315;
  1577. SiS_Pr->Alternate1600x1200 = true;
  1578. }
  1579. } else if(SiS_Pr->SiS_IF_DEF_LVDS) {
  1580. SiS_Pr->PanelHT = 2048; SiS_Pr->PanelVT = 1320;
  1581. SiS_Pr->PanelHRS = SiS_Pr->PanelHRE = 999;
  1582. SiS_Pr->PanelVRS = SiS_Pr->PanelVRE = 999;
  1583. }
  1584. SiS_GetLCDInfoBIOS(SiS_Pr);
  1585. break;
  1586. case Panel_1680x1050: SiS_Pr->PanelXRes = 1680; SiS_Pr->PanelYRes = 1050;
  1587. SiS_Pr->PanelHT = 1900; SiS_Pr->PanelVT = 1066;
  1588. SiS_Pr->PanelHRS = 26; SiS_Pr->PanelHRE = 76;
  1589. SiS_Pr->PanelVRS = 3; SiS_Pr->PanelVRE = 6;
  1590. SiS_Pr->PanelVCLKIdx315 = VCLK121_315;
  1591. SiS_GetLCDInfoBIOS(SiS_Pr);
  1592. break;
  1593. case Panel_Barco1366: SiS_Pr->PanelXRes = 1360; SiS_Pr->PanelYRes = 1024;
  1594. SiS_Pr->PanelHT = 1688; SiS_Pr->PanelVT = 1066;
  1595. break;
  1596. case Panel_848x480: SiS_Pr->PanelXRes = 848; SiS_Pr->PanelYRes = 480;
  1597. SiS_Pr->PanelHT = 1088; SiS_Pr->PanelVT = 525;
  1598. break;
  1599. case Panel_856x480: SiS_Pr->PanelXRes = 856; SiS_Pr->PanelYRes = 480;
  1600. SiS_Pr->PanelHT = 1088; SiS_Pr->PanelVT = 525;
  1601. break;
  1602. case Panel_Custom: SiS_Pr->PanelXRes = SiS_Pr->CP_MaxX;
  1603. SiS_Pr->PanelYRes = SiS_Pr->CP_MaxY;
  1604. SiS_Pr->PanelHT = SiS_Pr->CHTotal;
  1605. SiS_Pr->PanelVT = SiS_Pr->CVTotal;
  1606. if(SiS_Pr->CP_PreferredIndex != -1) {
  1607. SiS_Pr->PanelXRes = SiS_Pr->CP_HDisplay[SiS_Pr->CP_PreferredIndex];
  1608. SiS_Pr->PanelYRes = SiS_Pr->CP_VDisplay[SiS_Pr->CP_PreferredIndex];
  1609. SiS_Pr->PanelHT = SiS_Pr->CP_HTotal[SiS_Pr->CP_PreferredIndex];
  1610. SiS_Pr->PanelVT = SiS_Pr->CP_VTotal[SiS_Pr->CP_PreferredIndex];
  1611. SiS_Pr->PanelHRS = SiS_Pr->CP_HSyncStart[SiS_Pr->CP_PreferredIndex];
  1612. SiS_Pr->PanelHRE = SiS_Pr->CP_HSyncEnd[SiS_Pr->CP_PreferredIndex];
  1613. SiS_Pr->PanelVRS = SiS_Pr->CP_VSyncStart[SiS_Pr->CP_PreferredIndex];
  1614. SiS_Pr->PanelVRE = SiS_Pr->CP_VSyncEnd[SiS_Pr->CP_PreferredIndex];
  1615. SiS_Pr->PanelHRS -= SiS_Pr->PanelXRes;
  1616. SiS_Pr->PanelHRE -= SiS_Pr->PanelHRS;
  1617. SiS_Pr->PanelVRS -= SiS_Pr->PanelYRes;
  1618. SiS_Pr->PanelVRE -= SiS_Pr->PanelVRS;
  1619. if(SiS_Pr->CP_PrefClock) {
  1620. int idx;
  1621. SiS_Pr->PanelVCLKIdx315 = VCLK_CUSTOM_315;
  1622. SiS_Pr->PanelVCLKIdx300 = VCLK_CUSTOM_300;
  1623. if(SiS_Pr->ChipType < SIS_315H) idx = VCLK_CUSTOM_300;
  1624. else idx = VCLK_CUSTOM_315;
  1625. SiS_Pr->SiS_VCLKData[idx].CLOCK =
  1626. SiS_Pr->SiS_VBVCLKData[idx].CLOCK = SiS_Pr->CP_PrefClock;
  1627. SiS_Pr->SiS_VCLKData[idx].SR2B =
  1628. SiS_Pr->SiS_VBVCLKData[idx].Part4_A = SiS_Pr->CP_PrefSR2B;
  1629. SiS_Pr->SiS_VCLKData[idx].SR2C =
  1630. SiS_Pr->SiS_VBVCLKData[idx].Part4_B = SiS_Pr->CP_PrefSR2C;
  1631. }
  1632. }
  1633. break;
  1634. default: SiS_Pr->PanelXRes = 1024; SiS_Pr->PanelYRes = 768;
  1635. SiS_Pr->PanelHT = 1344; SiS_Pr->PanelVT = 806;
  1636. break;
  1637. }
  1638. /* Special cases */
  1639. if( (SiS_Pr->SiS_IF_DEF_FSTN) ||
  1640. (SiS_Pr->SiS_IF_DEF_DSTN) ||
  1641. (SiS_Pr->SiS_CustomT == CUT_BARCO1366) ||
  1642. (SiS_Pr->SiS_CustomT == CUT_BARCO1024) ||
  1643. (SiS_Pr->SiS_CustomT == CUT_PANEL848) ||
  1644. (SiS_Pr->SiS_CustomT == CUT_PANEL856) ) {
  1645. SiS_Pr->PanelHRS = 999;
  1646. SiS_Pr->PanelHRE = 999;
  1647. }
  1648. if( (SiS_Pr->SiS_CustomT == CUT_BARCO1366) ||
  1649. (SiS_Pr->SiS_CustomT == CUT_BARCO1024) ||
  1650. (SiS_Pr->SiS_CustomT == CUT_PANEL848) ||
  1651. (SiS_Pr->SiS_CustomT == CUT_PANEL856) ) {
  1652. SiS_Pr->PanelVRS = 999;
  1653. SiS_Pr->PanelVRE = 999;
  1654. }
  1655. /* DontExpand overrule */
  1656. if((SiS_Pr->SiS_VBType & VB_SISVB) && (!(SiS_Pr->SiS_VBType & VB_NoLCD))) {
  1657. if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && (modeflag & NoSupportLCDScale)) {
  1658. /* No scaling for this mode on any panel (LCD=CRT2)*/
  1659. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1660. }
  1661. switch(SiS_Pr->SiS_LCDResInfo) {
  1662. case Panel_Custom:
  1663. case Panel_1152x864:
  1664. case Panel_1280x768: /* TMDS only */
  1665. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1666. break;
  1667. case Panel_800x600: {
  1668. static const unsigned char nonscalingmodes[] = {
  1669. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, 0xff
  1670. };
  1671. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1672. break;
  1673. }
  1674. case Panel_1024x768: {
  1675. static const unsigned char nonscalingmodes[] = {
  1676. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1677. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1678. 0xff
  1679. };
  1680. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1681. break;
  1682. }
  1683. case Panel_1280x720: {
  1684. static const unsigned char nonscalingmodes[] = {
  1685. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1686. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1687. 0xff
  1688. };
  1689. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1690. if(SiS_Pr->PanelHT == 1650) {
  1691. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1692. }
  1693. break;
  1694. }
  1695. case Panel_1280x768_2: { /* LVDS only */
  1696. static const unsigned char nonscalingmodes[] = {
  1697. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1698. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1699. SIS_RI_1152x768,0xff
  1700. };
  1701. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1702. switch(resinfo) {
  1703. case SIS_RI_1280x720: if(SiS_Pr->UsePanelScaler == -1) {
  1704. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1705. }
  1706. break;
  1707. }
  1708. break;
  1709. }
  1710. case Panel_1280x800: { /* SiS TMDS special (Averatec 6200 series) */
  1711. static const unsigned char nonscalingmodes[] = {
  1712. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1713. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1714. SIS_RI_1152x768,SIS_RI_1280x720,SIS_RI_1280x768,0xff
  1715. };
  1716. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1717. break;
  1718. }
  1719. case Panel_1280x800_2: { /* SiS LVDS */
  1720. static const unsigned char nonscalingmodes[] = {
  1721. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1722. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1723. SIS_RI_1152x768,0xff
  1724. };
  1725. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1726. switch(resinfo) {
  1727. case SIS_RI_1280x720:
  1728. case SIS_RI_1280x768: if(SiS_Pr->UsePanelScaler == -1) {
  1729. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1730. }
  1731. break;
  1732. }
  1733. break;
  1734. }
  1735. case Panel_1280x854: { /* SiS LVDS */
  1736. static const unsigned char nonscalingmodes[] = {
  1737. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1738. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1739. SIS_RI_1152x768,0xff
  1740. };
  1741. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1742. switch(resinfo) {
  1743. case SIS_RI_1280x720:
  1744. case SIS_RI_1280x768:
  1745. case SIS_RI_1280x800: if(SiS_Pr->UsePanelScaler == -1) {
  1746. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1747. }
  1748. break;
  1749. }
  1750. break;
  1751. }
  1752. case Panel_1280x960: {
  1753. static const unsigned char nonscalingmodes[] = {
  1754. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1755. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1756. SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x720,SIS_RI_1280x768,SIS_RI_1280x800,
  1757. SIS_RI_1280x854,0xff
  1758. };
  1759. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1760. break;
  1761. }
  1762. case Panel_1280x1024: {
  1763. static const unsigned char nonscalingmodes[] = {
  1764. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1765. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1766. SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x720,SIS_RI_1280x768,SIS_RI_1280x800,
  1767. SIS_RI_1280x854,SIS_RI_1280x960,0xff
  1768. };
  1769. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1770. break;
  1771. }
  1772. case Panel_1400x1050: {
  1773. static const unsigned char nonscalingmodes[] = {
  1774. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1775. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1776. SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x768,SIS_RI_1280x800,SIS_RI_1280x854,
  1777. SIS_RI_1280x960,0xff
  1778. };
  1779. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1780. switch(resinfo) {
  1781. case SIS_RI_1280x720: if(SiS_Pr->UsePanelScaler == -1) {
  1782. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1783. }
  1784. break;
  1785. case SIS_RI_1280x1024: SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  1786. break;
  1787. }
  1788. break;
  1789. }
  1790. case Panel_1600x1200: {
  1791. static const unsigned char nonscalingmodes[] = {
  1792. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1793. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1794. SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x720,SIS_RI_1280x768,SIS_RI_1280x800,
  1795. SIS_RI_1280x854,SIS_RI_1280x960,SIS_RI_1360x768,SIS_RI_1360x1024,0xff
  1796. };
  1797. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1798. break;
  1799. }
  1800. case Panel_1680x1050: {
  1801. static const unsigned char nonscalingmodes[] = {
  1802. SIS_RI_720x480, SIS_RI_720x576, SIS_RI_768x576, SIS_RI_800x480, SIS_RI_848x480,
  1803. SIS_RI_856x480, SIS_RI_960x540, SIS_RI_960x600, SIS_RI_1024x576,SIS_RI_1024x600,
  1804. SIS_RI_1152x768,SIS_RI_1152x864,SIS_RI_1280x854,SIS_RI_1280x960,SIS_RI_1360x768,
  1805. SIS_RI_1360x1024,0xff
  1806. };
  1807. SiS_CheckScaling(SiS_Pr, resinfo, nonscalingmodes);
  1808. break;
  1809. }
  1810. }
  1811. }
  1812. #ifdef SIS300
  1813. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  1814. if(SiS_Pr->SiS_CustomT == CUT_PANEL848 || SiS_Pr->SiS_CustomT == CUT_PANEL856) {
  1815. SiS_Pr->SiS_LCDInfo = 0x80 | 0x40 | 0x20; /* neg h/v sync, RGB24(D0 = 0) */
  1816. }
  1817. }
  1818. if(SiS_Pr->ChipType < SIS_315H) {
  1819. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  1820. if(SiS_Pr->SiS_UseROM) {
  1821. if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) {
  1822. if(!(ROMAddr[0x235] & 0x02)) {
  1823. SiS_Pr->SiS_LCDInfo &= (~DontExpandLCD);
  1824. }
  1825. }
  1826. }
  1827. } else if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  1828. if((SiS_Pr->SiS_SetFlag & SetDOSMode) && ((ModeNo == 0x03) || (ModeNo == 0x10))) {
  1829. SiS_Pr->SiS_LCDInfo &= (~DontExpandLCD);
  1830. }
  1831. }
  1832. }
  1833. #endif
  1834. /* Special cases */
  1835. if(modexres == SiS_Pr->PanelXRes && modeyres == SiS_Pr->PanelYRes) {
  1836. SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  1837. }
  1838. if(SiS_Pr->SiS_IF_DEF_TRUMPION) {
  1839. SiS_Pr->SiS_LCDInfo |= (DontExpandLCD | LCDPass11);
  1840. }
  1841. switch(SiS_Pr->SiS_LCDResInfo) {
  1842. case Panel_640x480:
  1843. SiS_Pr->SiS_LCDInfo |= (DontExpandLCD | LCDPass11);
  1844. break;
  1845. case Panel_1280x800:
  1846. /* Don't pass 1:1 by default (TMDS special) */
  1847. if(SiS_Pr->CenterScreen == -1) SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  1848. break;
  1849. case Panel_1280x960:
  1850. SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  1851. break;
  1852. case Panel_Custom:
  1853. if((!SiS_Pr->CP_PrefClock) ||
  1854. (modexres > SiS_Pr->PanelXRes) || (modeyres > SiS_Pr->PanelYRes)) {
  1855. SiS_Pr->SiS_LCDInfo |= LCDPass11;
  1856. }
  1857. break;
  1858. }
  1859. if((SiS_Pr->UseCustomMode) || (SiS_Pr->SiS_CustomT == CUT_UNKNOWNLCD)) {
  1860. SiS_Pr->SiS_LCDInfo |= (DontExpandLCD | LCDPass11);
  1861. }
  1862. /* (In)validate LCDPass11 flag */
  1863. if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
  1864. SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  1865. }
  1866. /* LVDS DDA */
  1867. if(!((SiS_Pr->ChipType < SIS_315H) && (SiS_Pr->SiS_SetFlag & SetDOSMode))) {
  1868. if((SiS_Pr->SiS_IF_DEF_LVDS == 1) || (SiS_Pr->SiS_VBType & VB_NoLCD)) {
  1869. if(SiS_Pr->SiS_IF_DEF_TRUMPION == 0) {
  1870. if(ModeNo == 0x12) {
  1871. if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
  1872. SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
  1873. }
  1874. } else if(ModeNo > 0x13) {
  1875. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x600) {
  1876. if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
  1877. if((resinfo == SIS_RI_800x600) || (resinfo == SIS_RI_400x300)) {
  1878. SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
  1879. }
  1880. }
  1881. }
  1882. }
  1883. }
  1884. }
  1885. if(modeflag & HalfDCLK) {
  1886. if(SiS_Pr->SiS_IF_DEF_TRUMPION == 1) {
  1887. SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
  1888. } else if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  1889. SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
  1890. } else if(SiS_Pr->SiS_LCDResInfo == Panel_640x480) {
  1891. SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
  1892. } else if(ModeNo > 0x13) {
  1893. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  1894. if(resinfo == SIS_RI_512x384) SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
  1895. } else if(SiS_Pr->SiS_LCDResInfo == Panel_800x600) {
  1896. if(resinfo == SIS_RI_400x300) SiS_Pr->SiS_SetFlag |= EnableLVDSDDA;
  1897. }
  1898. }
  1899. }
  1900. }
  1901. /* VESA timing */
  1902. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  1903. if(SiS_Pr->SiS_VBInfo & SetNotSimuMode) {
  1904. SiS_Pr->SiS_SetFlag |= LCDVESATiming;
  1905. }
  1906. } else {
  1907. SiS_Pr->SiS_SetFlag |= LCDVESATiming;
  1908. }
  1909. #if 0
  1910. printk(KERN_DEBUG "sisfb: (LCDInfo=0x%04x LCDResInfo=0x%02x LCDTypeInfo=0x%02x)\n",
  1911. SiS_Pr->SiS_LCDInfo, SiS_Pr->SiS_LCDResInfo, SiS_Pr->SiS_LCDTypeInfo);
  1912. #endif
  1913. }
  1914. /*********************************************/
  1915. /* GET VCLK */
  1916. /*********************************************/
  1917. unsigned short
  1918. SiS_GetVCLK2Ptr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  1919. unsigned short RefreshRateTableIndex)
  1920. {
  1921. unsigned short CRT2Index, VCLKIndex = 0, VCLKIndexGEN = 0, VCLKIndexGENCRT = 0;
  1922. unsigned short modeflag, resinfo, tempbx;
  1923. const unsigned char *CHTVVCLKPtr = NULL;
  1924. if(ModeNo <= 0x13) {
  1925. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  1926. resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
  1927. CRT2Index = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  1928. VCLKIndexGEN = (SiS_GetRegByte((SiS_Pr->SiS_P3ca+0x02)) >> 2) & 0x03;
  1929. VCLKIndexGENCRT = VCLKIndexGEN;
  1930. } else {
  1931. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  1932. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  1933. CRT2Index = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  1934. VCLKIndexGEN = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
  1935. VCLKIndexGENCRT = SiS_GetRefCRTVCLK(SiS_Pr, RefreshRateTableIndex,
  1936. (SiS_Pr->SiS_SetFlag & ProgrammingCRT2) ? SiS_Pr->SiS_UseWideCRT2 : SiS_Pr->SiS_UseWide);
  1937. }
  1938. if(SiS_Pr->SiS_VBType & VB_SISVB) { /* 30x/B/LV */
  1939. if(SiS_Pr->SiS_SetFlag & ProgrammingCRT2) {
  1940. CRT2Index >>= 6;
  1941. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { /* LCD */
  1942. if(SiS_Pr->ChipType < SIS_315H) {
  1943. VCLKIndex = SiS_Pr->PanelVCLKIdx300;
  1944. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  1945. VCLKIndex = VCLKIndexGEN;
  1946. }
  1947. } else {
  1948. VCLKIndex = SiS_Pr->PanelVCLKIdx315;
  1949. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  1950. switch(resinfo) {
  1951. /* Correct those whose IndexGEN doesn't match VBVCLK array */
  1952. case SIS_RI_720x480: VCLKIndex = VCLK_720x480; break;
  1953. case SIS_RI_720x576: VCLKIndex = VCLK_720x576; break;
  1954. case SIS_RI_768x576: VCLKIndex = VCLK_768x576; break;
  1955. case SIS_RI_848x480: VCLKIndex = VCLK_848x480; break;
  1956. case SIS_RI_856x480: VCLKIndex = VCLK_856x480; break;
  1957. case SIS_RI_800x480: VCLKIndex = VCLK_800x480; break;
  1958. case SIS_RI_1024x576: VCLKIndex = VCLK_1024x576; break;
  1959. case SIS_RI_1152x864: VCLKIndex = VCLK_1152x864; break;
  1960. case SIS_RI_1280x720: VCLKIndex = VCLK_1280x720; break;
  1961. case SIS_RI_1360x768: VCLKIndex = VCLK_1360x768; break;
  1962. default: VCLKIndex = VCLKIndexGEN;
  1963. }
  1964. if(ModeNo <= 0x13) {
  1965. if(SiS_Pr->ChipType <= SIS_315PRO) {
  1966. if(SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC == 1) VCLKIndex = 0x42;
  1967. } else {
  1968. if(SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC == 1) VCLKIndex = 0x00;
  1969. }
  1970. }
  1971. if(SiS_Pr->ChipType <= SIS_315PRO) {
  1972. if(VCLKIndex == 0) VCLKIndex = 0x41;
  1973. if(VCLKIndex == 1) VCLKIndex = 0x43;
  1974. if(VCLKIndex == 4) VCLKIndex = 0x44;
  1975. }
  1976. }
  1977. }
  1978. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { /* TV */
  1979. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  1980. if(SiS_Pr->SiS_TVMode & TVRPLLDIV2XO) VCLKIndex = HiTVVCLKDIV2;
  1981. else VCLKIndex = HiTVVCLK;
  1982. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) VCLKIndex = HiTVSimuVCLK;
  1983. } else if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) VCLKIndex = YPbPr750pVCLK;
  1984. else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) VCLKIndex = TVVCLKDIV2;
  1985. else if(SiS_Pr->SiS_TVMode & TVRPLLDIV2XO) VCLKIndex = TVVCLKDIV2;
  1986. else VCLKIndex = TVVCLK;
  1987. if(SiS_Pr->ChipType < SIS_315H) VCLKIndex += TVCLKBASE_300;
  1988. else VCLKIndex += TVCLKBASE_315;
  1989. } else { /* VGA2 */
  1990. VCLKIndex = VCLKIndexGENCRT;
  1991. if(SiS_Pr->ChipType < SIS_315H) {
  1992. if(ModeNo > 0x13) {
  1993. if( (SiS_Pr->ChipType == SIS_630) &&
  1994. (SiS_Pr->ChipRevision >= 0x30)) {
  1995. if(VCLKIndex == 0x14) VCLKIndex = 0x34;
  1996. }
  1997. /* Better VGA2 clock for 1280x1024@75 */
  1998. if(VCLKIndex == 0x17) VCLKIndex = 0x45;
  1999. }
  2000. }
  2001. }
  2002. } else { /* If not programming CRT2 */
  2003. VCLKIndex = VCLKIndexGENCRT;
  2004. if(SiS_Pr->ChipType < SIS_315H) {
  2005. if(ModeNo > 0x13) {
  2006. if( (SiS_Pr->ChipType != SIS_630) &&
  2007. (SiS_Pr->ChipType != SIS_300) ) {
  2008. if(VCLKIndex == 0x1b) VCLKIndex = 0x48;
  2009. }
  2010. }
  2011. }
  2012. }
  2013. } else { /* LVDS */
  2014. VCLKIndex = CRT2Index;
  2015. if(SiS_Pr->SiS_SetFlag & ProgrammingCRT2) {
  2016. if( (SiS_Pr->SiS_IF_DEF_CH70xx != 0) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV) ) {
  2017. VCLKIndex &= 0x1f;
  2018. tempbx = 0;
  2019. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx += 1;
  2020. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  2021. tempbx += 2;
  2022. if(SiS_Pr->SiS_ModeType > ModeVGA) {
  2023. if(SiS_Pr->SiS_CHSOverScan) tempbx = 8;
  2024. }
  2025. if(SiS_Pr->SiS_TVMode & TVSetPALM) {
  2026. tempbx = 4;
  2027. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx += 1;
  2028. } else if(SiS_Pr->SiS_TVMode & TVSetPALN) {
  2029. tempbx = 6;
  2030. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx += 1;
  2031. }
  2032. }
  2033. switch(tempbx) {
  2034. case 0: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKUNTSC; break;
  2035. case 1: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKONTSC; break;
  2036. case 2: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKUPAL; break;
  2037. case 3: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKOPAL; break;
  2038. case 4: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKUPALM; break;
  2039. case 5: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKOPALM; break;
  2040. case 6: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKUPALN; break;
  2041. case 7: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKOPALN; break;
  2042. case 8: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKSOPAL; break;
  2043. default: CHTVVCLKPtr = SiS_Pr->SiS_CHTVVCLKOPAL; break;
  2044. }
  2045. VCLKIndex = CHTVVCLKPtr[VCLKIndex];
  2046. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  2047. if(SiS_Pr->ChipType < SIS_315H) {
  2048. VCLKIndex = SiS_Pr->PanelVCLKIdx300;
  2049. } else {
  2050. VCLKIndex = SiS_Pr->PanelVCLKIdx315;
  2051. }
  2052. #ifdef SIS300
  2053. /* Special Timing: Barco iQ Pro R series */
  2054. if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) VCLKIndex = 0x44;
  2055. /* Special Timing: 848x480 and 856x480 parallel lvds panels */
  2056. if(SiS_Pr->SiS_CustomT == CUT_PANEL848 || SiS_Pr->SiS_CustomT == CUT_PANEL856) {
  2057. if(SiS_Pr->ChipType < SIS_315H) {
  2058. VCLKIndex = VCLK34_300;
  2059. /* if(resinfo == SIS_RI_1360x768) VCLKIndex = ?; */
  2060. } else {
  2061. VCLKIndex = VCLK34_315;
  2062. /* if(resinfo == SIS_RI_1360x768) VCLKIndex = ?; */
  2063. }
  2064. }
  2065. #endif
  2066. } else {
  2067. VCLKIndex = VCLKIndexGENCRT;
  2068. if(SiS_Pr->ChipType < SIS_315H) {
  2069. if(ModeNo > 0x13) {
  2070. if( (SiS_Pr->ChipType == SIS_630) &&
  2071. (SiS_Pr->ChipRevision >= 0x30) ) {
  2072. if(VCLKIndex == 0x14) VCLKIndex = 0x2e;
  2073. }
  2074. }
  2075. }
  2076. }
  2077. } else { /* if not programming CRT2 */
  2078. VCLKIndex = VCLKIndexGENCRT;
  2079. if(SiS_Pr->ChipType < SIS_315H) {
  2080. if(ModeNo > 0x13) {
  2081. if( (SiS_Pr->ChipType != SIS_630) &&
  2082. (SiS_Pr->ChipType != SIS_300) ) {
  2083. if(VCLKIndex == 0x1b) VCLKIndex = 0x48;
  2084. }
  2085. #if 0
  2086. if(SiS_Pr->ChipType == SIS_730) {
  2087. if(VCLKIndex == 0x0b) VCLKIndex = 0x40; /* 1024x768-70 */
  2088. if(VCLKIndex == 0x0d) VCLKIndex = 0x41; /* 1024x768-75 */
  2089. }
  2090. #endif
  2091. }
  2092. }
  2093. }
  2094. }
  2095. return VCLKIndex;
  2096. }
  2097. /*********************************************/
  2098. /* SET CRT2 MODE TYPE REGISTERS */
  2099. /*********************************************/
  2100. static void
  2101. SiS_SetCRT2ModeRegs(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  2102. {
  2103. unsigned short i, j, modeflag, tempah=0;
  2104. short tempcl;
  2105. #if defined(SIS300) || defined(SIS315H)
  2106. unsigned short tempbl;
  2107. #endif
  2108. #ifdef SIS315H
  2109. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  2110. unsigned short tempah2, tempbl2;
  2111. #endif
  2112. modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
  2113. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  2114. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x00,0xAF,0x40);
  2115. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2E,0xF7);
  2116. } else {
  2117. for(i=0,j=4; i<3; i++,j++) SiS_SetReg(SiS_Pr->SiS_Part1Port,j,0);
  2118. if(SiS_Pr->ChipType >= SIS_315H) {
  2119. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x02,0x7F);
  2120. }
  2121. tempcl = SiS_Pr->SiS_ModeType;
  2122. if(SiS_Pr->ChipType < SIS_315H) {
  2123. #ifdef SIS300 /* ---- 300 series ---- */
  2124. /* For 301BDH: (with LCD via LVDS) */
  2125. if(SiS_Pr->SiS_VBType & VB_NoLCD) {
  2126. tempbl = SiS_GetReg(SiS_Pr->SiS_P3c4,0x32);
  2127. tempbl &= 0xef;
  2128. tempbl |= 0x02;
  2129. if((SiS_Pr->SiS_VBInfo & SetCRT2ToTV) || (SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) {
  2130. tempbl |= 0x10;
  2131. tempbl &= 0xfd;
  2132. }
  2133. SiS_SetReg(SiS_Pr->SiS_P3c4,0x32,tempbl);
  2134. }
  2135. if(ModeNo > 0x13) {
  2136. tempcl -= ModeVGA;
  2137. if(tempcl >= 0) {
  2138. tempah = ((0x10 >> tempcl) | 0x80);
  2139. }
  2140. } else tempah = 0x80;
  2141. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) tempah ^= 0xA0;
  2142. #endif /* SIS300 */
  2143. } else {
  2144. #ifdef SIS315H /* ------- 315/330 series ------ */
  2145. if(ModeNo > 0x13) {
  2146. tempcl -= ModeVGA;
  2147. if(tempcl >= 0) {
  2148. tempah = (0x08 >> tempcl);
  2149. if (tempah == 0) tempah = 1;
  2150. tempah |= 0x40;
  2151. }
  2152. } else tempah = 0x40;
  2153. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) tempah ^= 0x50;
  2154. #endif /* SIS315H */
  2155. }
  2156. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 0;
  2157. if(SiS_Pr->ChipType < SIS_315H) {
  2158. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,tempah);
  2159. } else {
  2160. #ifdef SIS315H
  2161. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  2162. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x00,0xa0,tempah);
  2163. } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
  2164. if(IS_SIS740) {
  2165. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,tempah);
  2166. } else {
  2167. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x00,0xa0,tempah);
  2168. }
  2169. }
  2170. #endif
  2171. }
  2172. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  2173. tempah = 0x01;
  2174. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  2175. tempah |= 0x02;
  2176. }
  2177. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) {
  2178. tempah ^= 0x05;
  2179. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) {
  2180. tempah ^= 0x01;
  2181. }
  2182. }
  2183. if(SiS_Pr->ChipType < SIS_315H) {
  2184. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 0;
  2185. tempah = (tempah << 5) & 0xFF;
  2186. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x01,tempah);
  2187. tempah = (tempah >> 5) & 0xFF;
  2188. } else {
  2189. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 0x08;
  2190. else if(!(SiS_IsDualEdge(SiS_Pr))) tempah |= 0x08;
  2191. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2E,0xF0,tempah);
  2192. tempah &= ~0x08;
  2193. }
  2194. if((SiS_Pr->SiS_ModeType == ModeVGA) && (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode))) {
  2195. tempah |= 0x10;
  2196. }
  2197. tempah |= 0x80;
  2198. if(SiS_Pr->SiS_VBType & VB_SIS301) {
  2199. if(SiS_Pr->PanelXRes < 1280 && SiS_Pr->PanelYRes < 960) tempah &= ~0x80;
  2200. }
  2201. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  2202. if(!(SiS_Pr->SiS_TVMode & (TVSetYPbPr750p | TVSetYPbPr525p))) {
  2203. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  2204. tempah |= 0x20;
  2205. }
  2206. }
  2207. }
  2208. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x0D,0x40,tempah);
  2209. tempah = 0x80;
  2210. if(SiS_Pr->SiS_VBType & VB_SIS301) {
  2211. if(SiS_Pr->PanelXRes < 1280 && SiS_Pr->PanelYRes < 960) tempah = 0;
  2212. }
  2213. if(SiS_IsDualLink(SiS_Pr)) tempah |= 0x40;
  2214. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  2215. if(SiS_Pr->SiS_TVMode & TVRPLLDIV2XO) {
  2216. tempah |= 0x40;
  2217. }
  2218. }
  2219. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0C,tempah);
  2220. } else { /* LVDS */
  2221. if(SiS_Pr->ChipType >= SIS_315H) {
  2222. #ifdef SIS315H
  2223. /* LVDS can only be slave in 8bpp modes */
  2224. tempah = 0x80;
  2225. if((modeflag & CRT2Mode) && (SiS_Pr->SiS_ModeType > ModeVGA)) {
  2226. if(SiS_Pr->SiS_VBInfo & DriverMode) {
  2227. tempah |= 0x02;
  2228. }
  2229. }
  2230. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) tempah |= 0x02;
  2231. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) tempah ^= 0x01;
  2232. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 1;
  2233. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2e,0xF0,tempah);
  2234. #endif
  2235. } else {
  2236. #ifdef SIS300
  2237. tempah = 0;
  2238. if( (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) && (SiS_Pr->SiS_ModeType > ModeVGA) ) {
  2239. tempah |= 0x02;
  2240. }
  2241. tempah <<= 5;
  2242. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 0;
  2243. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x01,tempah);
  2244. #endif
  2245. }
  2246. }
  2247. } /* LCDA */
  2248. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  2249. if(SiS_Pr->ChipType >= SIS_315H) {
  2250. #ifdef SIS315H
  2251. /* unsigned char bridgerev = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x01); */
  2252. /* The following is nearly unpreditable and varies from machine
  2253. * to machine. Especially the 301DH seems to be a real trouble
  2254. * maker. Some BIOSes simply set the registers (like in the
  2255. * NoLCD-if-statements here), some set them according to the
  2256. * LCDA stuff. It is very likely that some machines are not
  2257. * treated correctly in the following, very case-orientated
  2258. * code. What do I do then...?
  2259. */
  2260. /* 740 variants match for 30xB, 301B-DH, 30xLV */
  2261. if(!(IS_SIS740)) {
  2262. tempah = 0x04; /* For all bridges */
  2263. tempbl = 0xfb;
  2264. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  2265. tempah = 0x00;
  2266. if(SiS_IsDualEdge(SiS_Pr)) {
  2267. tempbl = 0xff;
  2268. }
  2269. }
  2270. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,tempbl,tempah);
  2271. }
  2272. /* The following two are responsible for eventually wrong colors
  2273. * in TV output. The DH (VB_NoLCD) conditions are unknown; the
  2274. * b0 was found in some 651 machine (Pim; P4_23=0xe5); the b1 version
  2275. * in a 650 box (Jake). What is the criteria?
  2276. * Addendum: Another combination 651+301B-DH(b1) (Rapo) needs same
  2277. * treatment like the 651+301B-DH(b0) case. Seems more to be the
  2278. * chipset than the bridge revision.
  2279. */
  2280. if((IS_SIS740) || (SiS_Pr->ChipType >= SIS_661) || (SiS_Pr->SiS_ROMNew)) {
  2281. tempah = 0x30;
  2282. tempbl = 0xc0;
  2283. if((SiS_Pr->SiS_VBInfo & DisableCRT2Display) ||
  2284. ((SiS_Pr->SiS_ROMNew) && (!(ROMAddr[0x5b] & 0x04)))) {
  2285. tempah = 0x00;
  2286. tempbl = 0x00;
  2287. }
  2288. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2c,0xcf,tempah);
  2289. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x21,0x3f,tempbl);
  2290. } else if(SiS_Pr->SiS_VBType & VB_SIS301) {
  2291. /* Fixes "TV-blue-bug" on 315+301 */
  2292. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2c,0xcf); /* For 301 */
  2293. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x21,0x3f);
  2294. } else if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  2295. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2c,0x30); /* For 30xLV */
  2296. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x21,0xc0);
  2297. } else if(SiS_Pr->SiS_VBType & VB_NoLCD) { /* For 301B-DH */
  2298. tempah = 0x30; tempah2 = 0xc0;
  2299. tempbl = 0xcf; tempbl2 = 0x3f;
  2300. if(SiS_Pr->SiS_TVBlue == 0) {
  2301. tempah = tempah2 = 0x00;
  2302. } else if(SiS_Pr->SiS_TVBlue == -1) {
  2303. /* Set on 651/M650, clear on 315/650 */
  2304. if(!(IS_SIS65x)) /* (bridgerev != 0xb0) */ {
  2305. tempah = tempah2 = 0x00;
  2306. }
  2307. }
  2308. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2c,tempbl,tempah);
  2309. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x21,tempbl2,tempah2);
  2310. } else {
  2311. tempah = 0x30; tempah2 = 0xc0; /* For 30xB, 301C */
  2312. tempbl = 0xcf; tempbl2 = 0x3f;
  2313. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  2314. tempah = tempah2 = 0x00;
  2315. if(SiS_IsDualEdge(SiS_Pr)) {
  2316. tempbl = tempbl2 = 0xff;
  2317. }
  2318. }
  2319. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2c,tempbl,tempah);
  2320. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x21,tempbl2,tempah2);
  2321. }
  2322. if(IS_SIS740) {
  2323. tempah = 0x80;
  2324. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) tempah = 0x00;
  2325. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x23,0x7f,tempah);
  2326. } else {
  2327. tempah = 0x00;
  2328. tempbl = 0x7f;
  2329. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  2330. tempbl = 0xff;
  2331. if(!(SiS_IsDualEdge(SiS_Pr))) tempah = 0x80;
  2332. }
  2333. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x23,tempbl,tempah);
  2334. }
  2335. #endif /* SIS315H */
  2336. } else if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  2337. #ifdef SIS300
  2338. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x21,0x3f);
  2339. if((SiS_Pr->SiS_VBInfo & DisableCRT2Display) ||
  2340. ((SiS_Pr->SiS_VBType & VB_NoLCD) &&
  2341. (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD))) {
  2342. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x23,0x7F);
  2343. } else {
  2344. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x23,0x80);
  2345. }
  2346. #endif
  2347. }
  2348. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  2349. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x0D,0x80);
  2350. if(SiS_Pr->SiS_VBType & VB_SIS30xCLV) {
  2351. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x3A,0xC0);
  2352. }
  2353. }
  2354. } else { /* LVDS */
  2355. #ifdef SIS315H
  2356. if(SiS_Pr->ChipType >= SIS_315H) {
  2357. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  2358. tempah = 0x04;
  2359. tempbl = 0xfb;
  2360. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  2361. tempah = 0x00;
  2362. if(SiS_IsDualEdge(SiS_Pr)) tempbl = 0xff;
  2363. }
  2364. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,tempbl,tempah);
  2365. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) {
  2366. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xfb);
  2367. }
  2368. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2c,0x30);
  2369. } else if(SiS_Pr->ChipType == SIS_550) {
  2370. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xfb);
  2371. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2c,0x30);
  2372. }
  2373. }
  2374. #endif
  2375. }
  2376. }
  2377. /*********************************************/
  2378. /* GET RESOLUTION DATA */
  2379. /*********************************************/
  2380. unsigned short
  2381. SiS_GetResInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  2382. {
  2383. if(ModeNo <= 0x13)
  2384. return ((unsigned short)SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo);
  2385. else
  2386. return ((unsigned short)SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO);
  2387. }
  2388. static void
  2389. SiS_GetCRT2ResInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  2390. {
  2391. unsigned short xres, yres, modeflag=0, resindex;
  2392. if(SiS_Pr->UseCustomMode) {
  2393. xres = SiS_Pr->CHDisplay;
  2394. if(SiS_Pr->CModeFlag & HalfDCLK) xres <<= 1;
  2395. SiS_Pr->SiS_VGAHDE = SiS_Pr->SiS_HDE = xres;
  2396. /* DoubleScanMode-check done in CheckCalcCustomMode()! */
  2397. SiS_Pr->SiS_VGAVDE = SiS_Pr->SiS_VDE = SiS_Pr->CVDisplay;
  2398. return;
  2399. }
  2400. resindex = SiS_GetResInfo(SiS_Pr,ModeNo,ModeIdIndex);
  2401. if(ModeNo <= 0x13) {
  2402. xres = SiS_Pr->SiS_StResInfo[resindex].HTotal;
  2403. yres = SiS_Pr->SiS_StResInfo[resindex].VTotal;
  2404. } else {
  2405. xres = SiS_Pr->SiS_ModeResInfo[resindex].HTotal;
  2406. yres = SiS_Pr->SiS_ModeResInfo[resindex].VTotal;
  2407. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  2408. }
  2409. if(!SiS_Pr->SiS_IF_DEF_DSTN && !SiS_Pr->SiS_IF_DEF_FSTN) {
  2410. if((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->SiS_IF_DEF_LVDS == 1)) {
  2411. if((ModeNo != 0x03) && (SiS_Pr->SiS_SetFlag & SetDOSMode)) {
  2412. if(yres == 350) yres = 400;
  2413. }
  2414. if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x3a) & 0x01) {
  2415. if(ModeNo == 0x12) yres = 400;
  2416. }
  2417. }
  2418. if(modeflag & HalfDCLK) xres <<= 1;
  2419. if(modeflag & DoubleScanMode) yres <<= 1;
  2420. }
  2421. if((SiS_Pr->SiS_VBType & VB_SISVB) && (!(SiS_Pr->SiS_VBType & VB_NoLCD))) {
  2422. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  2423. switch(SiS_Pr->SiS_LCDResInfo) {
  2424. case Panel_1024x768:
  2425. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
  2426. if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
  2427. if(yres == 350) yres = 357;
  2428. if(yres == 400) yres = 420;
  2429. if(yres == 480) yres = 525;
  2430. }
  2431. }
  2432. break;
  2433. case Panel_1280x1024:
  2434. if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
  2435. /* BIOS bug - does this regardless of scaling */
  2436. if(yres == 400) yres = 405;
  2437. }
  2438. if(yres == 350) yres = 360;
  2439. if(SiS_Pr->SiS_SetFlag & LCDVESATiming) {
  2440. if(yres == 360) yres = 375;
  2441. }
  2442. break;
  2443. case Panel_1600x1200:
  2444. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
  2445. if(yres == 1024) yres = 1056;
  2446. }
  2447. break;
  2448. }
  2449. }
  2450. } else {
  2451. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  2452. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToHiVision)) {
  2453. if(xres == 720) xres = 640;
  2454. }
  2455. } else if(xres == 720) xres = 640;
  2456. if(SiS_Pr->SiS_SetFlag & SetDOSMode) {
  2457. yres = 400;
  2458. if(SiS_Pr->ChipType >= SIS_315H) {
  2459. if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x17) & 0x80) yres = 480;
  2460. } else {
  2461. if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x80) yres = 480;
  2462. }
  2463. if(SiS_Pr->SiS_IF_DEF_DSTN || SiS_Pr->SiS_IF_DEF_FSTN) yres = 480;
  2464. }
  2465. }
  2466. SiS_Pr->SiS_VGAHDE = SiS_Pr->SiS_HDE = xres;
  2467. SiS_Pr->SiS_VGAVDE = SiS_Pr->SiS_VDE = yres;
  2468. }
  2469. /*********************************************/
  2470. /* GET CRT2 TIMING DATA */
  2471. /*********************************************/
  2472. static void
  2473. SiS_GetCRT2Ptr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  2474. unsigned short RefreshRateTableIndex, unsigned short *CRT2Index,
  2475. unsigned short *ResIndex)
  2476. {
  2477. unsigned short tempbx=0, tempal=0, resinfo=0;
  2478. if(ModeNo <= 0x13) {
  2479. tempal = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  2480. } else {
  2481. tempal = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  2482. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  2483. }
  2484. if((SiS_Pr->SiS_VBType & VB_SISVB) && (SiS_Pr->SiS_IF_DEF_LVDS == 0)) {
  2485. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) { /* LCD */
  2486. tempbx = SiS_Pr->SiS_LCDResInfo;
  2487. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) tempbx += 32;
  2488. /* patch index */
  2489. if(SiS_Pr->SiS_LCDResInfo == Panel_1680x1050) {
  2490. if (resinfo == SIS_RI_1280x800) tempal = 9;
  2491. else if(resinfo == SIS_RI_1400x1050) tempal = 11;
  2492. } else if((SiS_Pr->SiS_LCDResInfo == Panel_1280x800) ||
  2493. (SiS_Pr->SiS_LCDResInfo == Panel_1280x800_2) ||
  2494. (SiS_Pr->SiS_LCDResInfo == Panel_1280x854)) {
  2495. if (resinfo == SIS_RI_1280x768) tempal = 9;
  2496. }
  2497. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  2498. /* Pass 1:1 only (center-screen handled outside) */
  2499. /* This is never called for the panel's native resolution */
  2500. /* since Pass1:1 will not be set in this case */
  2501. tempbx = 100;
  2502. if(ModeNo >= 0x13) {
  2503. tempal = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC_NS;
  2504. }
  2505. }
  2506. #ifdef SIS315H
  2507. if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) {
  2508. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) {
  2509. if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
  2510. tempbx = 200;
  2511. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) tempbx++;
  2512. }
  2513. }
  2514. }
  2515. #endif
  2516. } else { /* TV */
  2517. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  2518. /* if(SiS_Pr->SiS_VGAVDE > 480) SiS_Pr->SiS_TVMode &= (~TVSetTVSimuMode); */
  2519. tempbx = 2;
  2520. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  2521. tempbx = 13;
  2522. if(!(SiS_Pr->SiS_TVMode & TVSetTVSimuMode)) tempbx = 14;
  2523. }
  2524. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  2525. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) tempbx = 7;
  2526. else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) tempbx = 6;
  2527. else tempbx = 5;
  2528. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) tempbx += 5;
  2529. } else {
  2530. if(SiS_Pr->SiS_TVMode & TVSetPAL) tempbx = 3;
  2531. else tempbx = 4;
  2532. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) tempbx += 5;
  2533. }
  2534. }
  2535. tempal &= 0x3F;
  2536. if(ModeNo > 0x13) {
  2537. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoHiVision) {
  2538. switch(resinfo) {
  2539. case SIS_RI_720x480:
  2540. tempal = 6;
  2541. if(SiS_Pr->SiS_TVMode & (TVSetPAL | TVSetPALN)) tempal = 9;
  2542. break;
  2543. case SIS_RI_720x576:
  2544. case SIS_RI_768x576:
  2545. case SIS_RI_1024x576: /* Not in NTSC or YPBPR mode (except 1080i)! */
  2546. tempal = 6;
  2547. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  2548. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) tempal = 8;
  2549. }
  2550. break;
  2551. case SIS_RI_800x480:
  2552. tempal = 4;
  2553. break;
  2554. case SIS_RI_512x384:
  2555. case SIS_RI_1024x768:
  2556. tempal = 7;
  2557. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  2558. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) tempal = 8;
  2559. }
  2560. break;
  2561. case SIS_RI_1280x720:
  2562. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  2563. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) tempal = 9;
  2564. }
  2565. break;
  2566. }
  2567. }
  2568. }
  2569. *CRT2Index = tempbx;
  2570. *ResIndex = tempal;
  2571. } else { /* LVDS, 301B-DH (if running on LCD) */
  2572. tempbx = 0;
  2573. if((SiS_Pr->SiS_IF_DEF_CH70xx) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
  2574. tempbx = 90;
  2575. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  2576. tempbx = 92;
  2577. if(SiS_Pr->SiS_ModeType > ModeVGA) {
  2578. if(SiS_Pr->SiS_CHSOverScan) tempbx = 99;
  2579. }
  2580. if(SiS_Pr->SiS_TVMode & TVSetPALM) tempbx = 94;
  2581. else if(SiS_Pr->SiS_TVMode & TVSetPALN) tempbx = 96;
  2582. }
  2583. if(tempbx != 99) {
  2584. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) tempbx++;
  2585. }
  2586. } else {
  2587. switch(SiS_Pr->SiS_LCDResInfo) {
  2588. case Panel_640x480: tempbx = 12; break;
  2589. case Panel_320x240_1: tempbx = 10; break;
  2590. case Panel_320x240_2:
  2591. case Panel_320x240_3: tempbx = 14; break;
  2592. case Panel_800x600: tempbx = 16; break;
  2593. case Panel_1024x600: tempbx = 18; break;
  2594. case Panel_1152x768:
  2595. case Panel_1024x768: tempbx = 20; break;
  2596. case Panel_1280x768: tempbx = 22; break;
  2597. case Panel_1280x1024: tempbx = 24; break;
  2598. case Panel_1400x1050: tempbx = 26; break;
  2599. case Panel_1600x1200: tempbx = 28; break;
  2600. #ifdef SIS300
  2601. case Panel_Barco1366: tempbx = 80; break;
  2602. #endif
  2603. }
  2604. switch(SiS_Pr->SiS_LCDResInfo) {
  2605. case Panel_320x240_1:
  2606. case Panel_320x240_2:
  2607. case Panel_320x240_3:
  2608. case Panel_640x480:
  2609. break;
  2610. default:
  2611. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++;
  2612. }
  2613. if(SiS_Pr->SiS_LCDInfo & LCDPass11) tempbx = 30;
  2614. #ifdef SIS300
  2615. if(SiS_Pr->SiS_CustomT == CUT_BARCO1024) {
  2616. tempbx = 82;
  2617. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++;
  2618. } else if(SiS_Pr->SiS_CustomT == CUT_PANEL848 || SiS_Pr->SiS_CustomT == CUT_PANEL856) {
  2619. tempbx = 84;
  2620. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++;
  2621. }
  2622. #endif
  2623. }
  2624. (*CRT2Index) = tempbx;
  2625. (*ResIndex) = tempal & 0x1F;
  2626. }
  2627. }
  2628. static void
  2629. SiS_GetRAMDAC2DATA(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  2630. unsigned short RefreshRateTableIndex)
  2631. {
  2632. unsigned short tempax=0, tempbx=0, index, dotclock;
  2633. unsigned short temp1=0, modeflag=0, tempcx=0;
  2634. SiS_Pr->SiS_RVBHCMAX = 1;
  2635. SiS_Pr->SiS_RVBHCFACT = 1;
  2636. if(ModeNo <= 0x13) {
  2637. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  2638. index = SiS_GetModePtr(SiS_Pr,ModeNo,ModeIdIndex);
  2639. tempax = SiS_Pr->SiS_StandTable[index].CRTC[0];
  2640. tempbx = SiS_Pr->SiS_StandTable[index].CRTC[6];
  2641. temp1 = SiS_Pr->SiS_StandTable[index].CRTC[7];
  2642. dotclock = (modeflag & Charx8Dot) ? 8 : 9;
  2643. } else {
  2644. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  2645. index = SiS_GetRefCRT1CRTC(SiS_Pr, RefreshRateTableIndex, SiS_Pr->SiS_UseWideCRT2);
  2646. tempax = SiS_Pr->SiS_CRT1Table[index].CR[0];
  2647. tempax |= (SiS_Pr->SiS_CRT1Table[index].CR[14] << 8);
  2648. tempax &= 0x03FF;
  2649. tempbx = SiS_Pr->SiS_CRT1Table[index].CR[6];
  2650. tempcx = SiS_Pr->SiS_CRT1Table[index].CR[13] << 8;
  2651. tempcx &= 0x0100;
  2652. tempcx <<= 2;
  2653. tempbx |= tempcx;
  2654. temp1 = SiS_Pr->SiS_CRT1Table[index].CR[7];
  2655. dotclock = 8;
  2656. }
  2657. if(temp1 & 0x01) tempbx |= 0x0100;
  2658. if(temp1 & 0x20) tempbx |= 0x0200;
  2659. tempax += 5;
  2660. tempax *= dotclock;
  2661. if(modeflag & HalfDCLK) tempax <<= 1;
  2662. tempbx++;
  2663. SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_HT = tempax;
  2664. SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_VT = tempbx;
  2665. }
  2666. static void
  2667. SiS_CalcPanelLinkTiming(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
  2668. unsigned short ModeIdIndex, unsigned short RefreshRateTableIndex)
  2669. {
  2670. unsigned short ResIndex;
  2671. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  2672. if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
  2673. if(SiS_Pr->UseCustomMode) {
  2674. ResIndex = SiS_Pr->CHTotal;
  2675. if(SiS_Pr->CModeFlag & HalfDCLK) ResIndex <<= 1;
  2676. SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_HT = ResIndex;
  2677. SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_VT = SiS_Pr->CVTotal;
  2678. } else {
  2679. if(ModeNo < 0x13) {
  2680. ResIndex = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  2681. } else {
  2682. ResIndex = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC_NS;
  2683. }
  2684. if(ResIndex == 0x09) {
  2685. if(SiS_Pr->Alternate1600x1200) ResIndex = 0x20; /* 1600x1200 LCDA */
  2686. else if(SiS_Pr->SiS_IF_DEF_LVDS == 1) ResIndex = 0x21; /* 1600x1200 LVDS */
  2687. }
  2688. SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_NoScaleData[ResIndex].VGAHT;
  2689. SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_NoScaleData[ResIndex].VGAVT;
  2690. SiS_Pr->SiS_HT = SiS_Pr->SiS_NoScaleData[ResIndex].LCDHT;
  2691. SiS_Pr->SiS_VT = SiS_Pr->SiS_NoScaleData[ResIndex].LCDVT;
  2692. }
  2693. } else {
  2694. SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_HT = SiS_Pr->PanelHT;
  2695. SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_VT = SiS_Pr->PanelVT;
  2696. }
  2697. } else {
  2698. /* This handles custom modes and custom panels */
  2699. SiS_Pr->SiS_HDE = SiS_Pr->PanelXRes;
  2700. SiS_Pr->SiS_VDE = SiS_Pr->PanelYRes;
  2701. SiS_Pr->SiS_HT = SiS_Pr->PanelHT;
  2702. SiS_Pr->SiS_VT = SiS_Pr->PanelVT;
  2703. SiS_Pr->SiS_VGAHT = SiS_Pr->PanelHT - (SiS_Pr->PanelXRes - SiS_Pr->SiS_VGAHDE);
  2704. SiS_Pr->SiS_VGAVT = SiS_Pr->PanelVT - (SiS_Pr->PanelYRes - SiS_Pr->SiS_VGAVDE);
  2705. }
  2706. }
  2707. static void
  2708. SiS_GetCRT2DataLVDS(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  2709. unsigned short RefreshRateTableIndex)
  2710. {
  2711. unsigned short CRT2Index, ResIndex, backup;
  2712. const struct SiS_LVDSData *LVDSData = NULL;
  2713. SiS_GetCRT2ResInfo(SiS_Pr, ModeNo, ModeIdIndex);
  2714. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  2715. SiS_Pr->SiS_RVBHCMAX = 1;
  2716. SiS_Pr->SiS_RVBHCFACT = 1;
  2717. SiS_Pr->SiS_NewFlickerMode = 0;
  2718. SiS_Pr->SiS_RVBHRS = 50;
  2719. SiS_Pr->SiS_RY1COE = 0;
  2720. SiS_Pr->SiS_RY2COE = 0;
  2721. SiS_Pr->SiS_RY3COE = 0;
  2722. SiS_Pr->SiS_RY4COE = 0;
  2723. SiS_Pr->SiS_RVBHRS2 = 0;
  2724. }
  2725. if((SiS_Pr->SiS_VBType & VB_SISVB) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  2726. #ifdef SIS315H
  2727. SiS_CalcPanelLinkTiming(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  2728. SiS_CalcLCDACRT1Timing(SiS_Pr, ModeNo, ModeIdIndex);
  2729. #endif
  2730. } else {
  2731. /* 301BDH needs LVDS Data */
  2732. backup = SiS_Pr->SiS_IF_DEF_LVDS;
  2733. if((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) {
  2734. SiS_Pr->SiS_IF_DEF_LVDS = 1;
  2735. }
  2736. SiS_GetCRT2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex,
  2737. &CRT2Index, &ResIndex);
  2738. SiS_Pr->SiS_IF_DEF_LVDS = backup;
  2739. switch(CRT2Index) {
  2740. case 10: LVDSData = SiS_Pr->SiS_LVDS320x240Data_1; break;
  2741. case 14: LVDSData = SiS_Pr->SiS_LVDS320x240Data_2; break;
  2742. case 12: LVDSData = SiS_Pr->SiS_LVDS640x480Data_1; break;
  2743. case 16: LVDSData = SiS_Pr->SiS_LVDS800x600Data_1; break;
  2744. case 18: LVDSData = SiS_Pr->SiS_LVDS1024x600Data_1; break;
  2745. case 20: LVDSData = SiS_Pr->SiS_LVDS1024x768Data_1; break;
  2746. #ifdef SIS300
  2747. case 80: LVDSData = SiS_Pr->SiS_LVDSBARCO1366Data_1; break;
  2748. case 81: LVDSData = SiS_Pr->SiS_LVDSBARCO1366Data_2; break;
  2749. case 82: LVDSData = SiS_Pr->SiS_LVDSBARCO1024Data_1; break;
  2750. case 84: LVDSData = SiS_Pr->SiS_LVDS848x480Data_1; break;
  2751. case 85: LVDSData = SiS_Pr->SiS_LVDS848x480Data_2; break;
  2752. #endif
  2753. case 90: LVDSData = SiS_Pr->SiS_CHTVUNTSCData; break;
  2754. case 91: LVDSData = SiS_Pr->SiS_CHTVONTSCData; break;
  2755. case 92: LVDSData = SiS_Pr->SiS_CHTVUPALData; break;
  2756. case 93: LVDSData = SiS_Pr->SiS_CHTVOPALData; break;
  2757. case 94: LVDSData = SiS_Pr->SiS_CHTVUPALMData; break;
  2758. case 95: LVDSData = SiS_Pr->SiS_CHTVOPALMData; break;
  2759. case 96: LVDSData = SiS_Pr->SiS_CHTVUPALNData; break;
  2760. case 97: LVDSData = SiS_Pr->SiS_CHTVOPALNData; break;
  2761. case 99: LVDSData = SiS_Pr->SiS_CHTVSOPALData; break;
  2762. }
  2763. if(LVDSData) {
  2764. SiS_Pr->SiS_VGAHT = (LVDSData+ResIndex)->VGAHT;
  2765. SiS_Pr->SiS_VGAVT = (LVDSData+ResIndex)->VGAVT;
  2766. SiS_Pr->SiS_HT = (LVDSData+ResIndex)->LCDHT;
  2767. SiS_Pr->SiS_VT = (LVDSData+ResIndex)->LCDVT;
  2768. } else {
  2769. SiS_CalcPanelLinkTiming(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  2770. }
  2771. if( (!(SiS_Pr->SiS_VBType & VB_SISVB)) &&
  2772. (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) &&
  2773. (!(SiS_Pr->SiS_LCDInfo & LCDPass11)) ) {
  2774. if( (!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) ||
  2775. (SiS_Pr->SiS_SetFlag & SetDOSMode) ) {
  2776. SiS_Pr->SiS_HDE = SiS_Pr->PanelXRes;
  2777. SiS_Pr->SiS_VDE = SiS_Pr->PanelYRes;
  2778. #ifdef SIS300
  2779. if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) {
  2780. if(ResIndex < 0x08) {
  2781. SiS_Pr->SiS_HDE = 1280;
  2782. SiS_Pr->SiS_VDE = 1024;
  2783. }
  2784. }
  2785. #endif
  2786. }
  2787. }
  2788. }
  2789. }
  2790. static void
  2791. SiS_GetCRT2Data301(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  2792. unsigned short RefreshRateTableIndex)
  2793. {
  2794. unsigned char *ROMAddr = NULL;
  2795. unsigned short tempax, tempbx, modeflag, romptr=0;
  2796. unsigned short resinfo, CRT2Index, ResIndex;
  2797. const struct SiS_LCDData *LCDPtr = NULL;
  2798. const struct SiS_TVData *TVPtr = NULL;
  2799. #ifdef SIS315H
  2800. short resinfo661;
  2801. #endif
  2802. if(ModeNo <= 0x13) {
  2803. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  2804. resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
  2805. } else if(SiS_Pr->UseCustomMode) {
  2806. modeflag = SiS_Pr->CModeFlag;
  2807. resinfo = 0;
  2808. } else {
  2809. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  2810. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  2811. #ifdef SIS315H
  2812. resinfo661 = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].ROMMODEIDX661;
  2813. if( (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) &&
  2814. (SiS_Pr->SiS_SetFlag & LCDVESATiming) &&
  2815. (resinfo661 >= 0) &&
  2816. (SiS_Pr->SiS_NeedRomModeData) ) {
  2817. if((ROMAddr = GetLCDStructPtr661(SiS_Pr))) {
  2818. if((romptr = (SISGETROMW(21)))) {
  2819. romptr += (resinfo661 * 10);
  2820. ROMAddr = SiS_Pr->VirtualRomBase;
  2821. }
  2822. }
  2823. }
  2824. #endif
  2825. }
  2826. SiS_Pr->SiS_NewFlickerMode = 0;
  2827. SiS_Pr->SiS_RVBHRS = 50;
  2828. SiS_Pr->SiS_RY1COE = 0;
  2829. SiS_Pr->SiS_RY2COE = 0;
  2830. SiS_Pr->SiS_RY3COE = 0;
  2831. SiS_Pr->SiS_RY4COE = 0;
  2832. SiS_Pr->SiS_RVBHRS2 = 0;
  2833. SiS_GetCRT2ResInfo(SiS_Pr,ModeNo,ModeIdIndex);
  2834. if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) {
  2835. if(SiS_Pr->UseCustomMode) {
  2836. SiS_Pr->SiS_RVBHCMAX = 1;
  2837. SiS_Pr->SiS_RVBHCFACT = 1;
  2838. SiS_Pr->SiS_HDE = SiS_Pr->SiS_VGAHDE;
  2839. SiS_Pr->SiS_VDE = SiS_Pr->SiS_VGAVDE;
  2840. tempax = SiS_Pr->CHTotal;
  2841. if(modeflag & HalfDCLK) tempax <<= 1;
  2842. SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_HT = tempax;
  2843. SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_VT = SiS_Pr->CVTotal;
  2844. } else {
  2845. SiS_GetRAMDAC2DATA(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  2846. }
  2847. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  2848. SiS_GetCRT2Ptr(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex,
  2849. &CRT2Index,&ResIndex);
  2850. switch(CRT2Index) {
  2851. case 2: TVPtr = SiS_Pr->SiS_ExtHiTVData; break;
  2852. case 3: TVPtr = SiS_Pr->SiS_ExtPALData; break;
  2853. case 4: TVPtr = SiS_Pr->SiS_ExtNTSCData; break;
  2854. case 5: TVPtr = SiS_Pr->SiS_Ext525iData; break;
  2855. case 6: TVPtr = SiS_Pr->SiS_Ext525pData; break;
  2856. case 7: TVPtr = SiS_Pr->SiS_Ext750pData; break;
  2857. case 8: TVPtr = SiS_Pr->SiS_StPALData; break;
  2858. case 9: TVPtr = SiS_Pr->SiS_StNTSCData; break;
  2859. case 10: TVPtr = SiS_Pr->SiS_St525iData; break;
  2860. case 11: TVPtr = SiS_Pr->SiS_St525pData; break;
  2861. case 12: TVPtr = SiS_Pr->SiS_St750pData; break;
  2862. case 13: TVPtr = SiS_Pr->SiS_St1HiTVData; break;
  2863. case 14: TVPtr = SiS_Pr->SiS_St2HiTVData; break;
  2864. default: TVPtr = SiS_Pr->SiS_StPALData; break;
  2865. }
  2866. SiS_Pr->SiS_RVBHCMAX = (TVPtr+ResIndex)->RVBHCMAX;
  2867. SiS_Pr->SiS_RVBHCFACT = (TVPtr+ResIndex)->RVBHCFACT;
  2868. SiS_Pr->SiS_VGAHT = (TVPtr+ResIndex)->VGAHT;
  2869. SiS_Pr->SiS_VGAVT = (TVPtr+ResIndex)->VGAVT;
  2870. SiS_Pr->SiS_HDE = (TVPtr+ResIndex)->TVHDE;
  2871. SiS_Pr->SiS_VDE = (TVPtr+ResIndex)->TVVDE;
  2872. SiS_Pr->SiS_RVBHRS2 = (TVPtr+ResIndex)->RVBHRS2 & 0x0fff;
  2873. if(modeflag & HalfDCLK) {
  2874. SiS_Pr->SiS_RVBHRS = (TVPtr+ResIndex)->HALFRVBHRS;
  2875. if(SiS_Pr->SiS_RVBHRS2) {
  2876. SiS_Pr->SiS_RVBHRS2 = ((SiS_Pr->SiS_RVBHRS2 + 3) >> 1) - 3;
  2877. tempax = ((TVPtr+ResIndex)->RVBHRS2 >> 12) & 0x07;
  2878. if((TVPtr+ResIndex)->RVBHRS2 & 0x8000) SiS_Pr->SiS_RVBHRS2 -= tempax;
  2879. else SiS_Pr->SiS_RVBHRS2 += tempax;
  2880. }
  2881. } else {
  2882. SiS_Pr->SiS_RVBHRS = (TVPtr+ResIndex)->RVBHRS;
  2883. }
  2884. SiS_Pr->SiS_NewFlickerMode = ((TVPtr+ResIndex)->FlickerMode) << 7;
  2885. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  2886. if((resinfo == SIS_RI_960x600) ||
  2887. (resinfo == SIS_RI_1024x768) ||
  2888. (resinfo == SIS_RI_1280x1024) ||
  2889. (resinfo == SIS_RI_1280x720)) {
  2890. SiS_Pr->SiS_NewFlickerMode = 0x40;
  2891. }
  2892. if(SiS_Pr->SiS_VGAVDE == 350) SiS_Pr->SiS_TVMode |= TVSetTVSimuMode;
  2893. SiS_Pr->SiS_HT = ExtHiTVHT;
  2894. SiS_Pr->SiS_VT = ExtHiTVVT;
  2895. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  2896. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) {
  2897. SiS_Pr->SiS_HT = StHiTVHT;
  2898. SiS_Pr->SiS_VT = StHiTVVT;
  2899. }
  2900. }
  2901. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  2902. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) {
  2903. SiS_Pr->SiS_HT = 1650;
  2904. SiS_Pr->SiS_VT = 750;
  2905. } else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) {
  2906. SiS_Pr->SiS_HT = NTSCHT;
  2907. if(SiS_Pr->SiS_TVMode & TVSet525p1024) SiS_Pr->SiS_HT = NTSC2HT;
  2908. SiS_Pr->SiS_VT = NTSCVT;
  2909. } else {
  2910. SiS_Pr->SiS_HT = NTSCHT;
  2911. if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) SiS_Pr->SiS_HT = NTSC2HT;
  2912. SiS_Pr->SiS_VT = NTSCVT;
  2913. }
  2914. } else {
  2915. SiS_Pr->SiS_RY1COE = (TVPtr+ResIndex)->RY1COE;
  2916. SiS_Pr->SiS_RY2COE = (TVPtr+ResIndex)->RY2COE;
  2917. SiS_Pr->SiS_RY3COE = (TVPtr+ResIndex)->RY3COE;
  2918. SiS_Pr->SiS_RY4COE = (TVPtr+ResIndex)->RY4COE;
  2919. if(modeflag & HalfDCLK) {
  2920. SiS_Pr->SiS_RY1COE = 0x00;
  2921. SiS_Pr->SiS_RY2COE = 0xf4;
  2922. SiS_Pr->SiS_RY3COE = 0x10;
  2923. SiS_Pr->SiS_RY4COE = 0x38;
  2924. }
  2925. if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) {
  2926. SiS_Pr->SiS_HT = NTSCHT;
  2927. if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) SiS_Pr->SiS_HT = NTSC2HT;
  2928. SiS_Pr->SiS_VT = NTSCVT;
  2929. } else {
  2930. SiS_Pr->SiS_HT = PALHT;
  2931. SiS_Pr->SiS_VT = PALVT;
  2932. }
  2933. }
  2934. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  2935. SiS_Pr->SiS_RVBHCMAX = 1;
  2936. SiS_Pr->SiS_RVBHCFACT = 1;
  2937. if(SiS_Pr->UseCustomMode) {
  2938. SiS_Pr->SiS_HDE = SiS_Pr->SiS_VGAHDE;
  2939. SiS_Pr->SiS_VDE = SiS_Pr->SiS_VGAVDE;
  2940. tempax = SiS_Pr->CHTotal;
  2941. if(modeflag & HalfDCLK) tempax <<= 1;
  2942. SiS_Pr->SiS_VGAHT = SiS_Pr->SiS_HT = tempax;
  2943. SiS_Pr->SiS_VGAVT = SiS_Pr->SiS_VT = SiS_Pr->CVTotal;
  2944. } else {
  2945. bool gotit = false;
  2946. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
  2947. SiS_Pr->SiS_VGAHT = SiS_Pr->PanelHT;
  2948. SiS_Pr->SiS_VGAVT = SiS_Pr->PanelVT;
  2949. SiS_Pr->SiS_HT = SiS_Pr->PanelHT;
  2950. SiS_Pr->SiS_VT = SiS_Pr->PanelVT;
  2951. gotit = true;
  2952. } else if( (!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) && (romptr) && (ROMAddr) ) {
  2953. #ifdef SIS315H
  2954. SiS_Pr->SiS_RVBHCMAX = ROMAddr[romptr];
  2955. SiS_Pr->SiS_RVBHCFACT = ROMAddr[romptr+1];
  2956. SiS_Pr->SiS_VGAHT = ROMAddr[romptr+2] | ((ROMAddr[romptr+3] & 0x0f) << 8);
  2957. SiS_Pr->SiS_VGAVT = (ROMAddr[romptr+4] << 4) | ((ROMAddr[romptr+3] & 0xf0) >> 4);
  2958. SiS_Pr->SiS_HT = ROMAddr[romptr+5] | ((ROMAddr[romptr+6] & 0x0f) << 8);
  2959. SiS_Pr->SiS_VT = (ROMAddr[romptr+7] << 4) | ((ROMAddr[romptr+6] & 0xf0) >> 4);
  2960. SiS_Pr->SiS_RVBHRS2 = ROMAddr[romptr+8] | ((ROMAddr[romptr+9] & 0x0f) << 8);
  2961. if((SiS_Pr->SiS_RVBHRS2) && (modeflag & HalfDCLK)) {
  2962. SiS_Pr->SiS_RVBHRS2 = ((SiS_Pr->SiS_RVBHRS2 + 3) >> 1) - 3;
  2963. tempax = (ROMAddr[romptr+9] >> 4) & 0x07;
  2964. if(ROMAddr[romptr+9] & 0x80) SiS_Pr->SiS_RVBHRS2 -= tempax;
  2965. else SiS_Pr->SiS_RVBHRS2 += tempax;
  2966. }
  2967. if(SiS_Pr->SiS_VGAHT) gotit = true;
  2968. else {
  2969. SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
  2970. SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
  2971. SiS_Pr->SiS_RVBHCMAX = 1;
  2972. SiS_Pr->SiS_RVBHCFACT = 1;
  2973. SiS_Pr->SiS_VGAHT = SiS_Pr->PanelHT;
  2974. SiS_Pr->SiS_VGAVT = SiS_Pr->PanelVT;
  2975. SiS_Pr->SiS_HT = SiS_Pr->PanelHT;
  2976. SiS_Pr->SiS_VT = SiS_Pr->PanelVT;
  2977. SiS_Pr->SiS_RVBHRS2 = 0;
  2978. gotit = true;
  2979. }
  2980. #endif
  2981. }
  2982. if(!gotit) {
  2983. SiS_GetCRT2Ptr(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex,
  2984. &CRT2Index,&ResIndex);
  2985. switch(CRT2Index) {
  2986. case Panel_1024x768 : LCDPtr = SiS_Pr->SiS_ExtLCD1024x768Data; break;
  2987. case Panel_1024x768 + 32: LCDPtr = SiS_Pr->SiS_St2LCD1024x768Data; break;
  2988. case Panel_1280x720 :
  2989. case Panel_1280x720 + 32: LCDPtr = SiS_Pr->SiS_LCD1280x720Data; break;
  2990. case Panel_1280x768_2 : LCDPtr = SiS_Pr->SiS_ExtLCD1280x768_2Data; break;
  2991. case Panel_1280x768_2+ 32: LCDPtr = SiS_Pr->SiS_StLCD1280x768_2Data; break;
  2992. case Panel_1280x800 :
  2993. case Panel_1280x800 + 32: LCDPtr = SiS_Pr->SiS_LCD1280x800Data; break;
  2994. case Panel_1280x800_2 :
  2995. case Panel_1280x800_2+ 32: LCDPtr = SiS_Pr->SiS_LCD1280x800_2Data; break;
  2996. case Panel_1280x854 :
  2997. case Panel_1280x854 + 32: LCDPtr = SiS_Pr->SiS_LCD1280x854Data; break;
  2998. case Panel_1280x960 :
  2999. case Panel_1280x960 + 32: LCDPtr = SiS_Pr->SiS_LCD1280x960Data; break;
  3000. case Panel_1280x1024 : LCDPtr = SiS_Pr->SiS_ExtLCD1280x1024Data; break;
  3001. case Panel_1280x1024 + 32: LCDPtr = SiS_Pr->SiS_St2LCD1280x1024Data; break;
  3002. case Panel_1400x1050 : LCDPtr = SiS_Pr->SiS_ExtLCD1400x1050Data; break;
  3003. case Panel_1400x1050 + 32: LCDPtr = SiS_Pr->SiS_StLCD1400x1050Data; break;
  3004. case Panel_1600x1200 : LCDPtr = SiS_Pr->SiS_ExtLCD1600x1200Data; break;
  3005. case Panel_1600x1200 + 32: LCDPtr = SiS_Pr->SiS_StLCD1600x1200Data; break;
  3006. case Panel_1680x1050 :
  3007. case Panel_1680x1050 + 32: LCDPtr = SiS_Pr->SiS_LCD1680x1050Data; break;
  3008. case 100 : LCDPtr = SiS_Pr->SiS_NoScaleData; break;
  3009. #ifdef SIS315H
  3010. case 200 : LCDPtr = SiS310_ExtCompaq1280x1024Data; break;
  3011. case 201 : LCDPtr = SiS_Pr->SiS_St2LCD1280x1024Data; break;
  3012. #endif
  3013. default : LCDPtr = SiS_Pr->SiS_ExtLCD1024x768Data; break;
  3014. }
  3015. SiS_Pr->SiS_RVBHCMAX = (LCDPtr+ResIndex)->RVBHCMAX;
  3016. SiS_Pr->SiS_RVBHCFACT = (LCDPtr+ResIndex)->RVBHCFACT;
  3017. SiS_Pr->SiS_VGAHT = (LCDPtr+ResIndex)->VGAHT;
  3018. SiS_Pr->SiS_VGAVT = (LCDPtr+ResIndex)->VGAVT;
  3019. SiS_Pr->SiS_HT = (LCDPtr+ResIndex)->LCDHT;
  3020. SiS_Pr->SiS_VT = (LCDPtr+ResIndex)->LCDVT;
  3021. }
  3022. tempax = SiS_Pr->PanelXRes;
  3023. tempbx = SiS_Pr->PanelYRes;
  3024. switch(SiS_Pr->SiS_LCDResInfo) {
  3025. case Panel_1024x768:
  3026. if(SiS_Pr->SiS_SetFlag & LCDVESATiming) {
  3027. if(SiS_Pr->ChipType < SIS_315H) {
  3028. if (SiS_Pr->SiS_VGAVDE == 350) tempbx = 560;
  3029. else if(SiS_Pr->SiS_VGAVDE == 400) tempbx = 640;
  3030. }
  3031. } else {
  3032. if (SiS_Pr->SiS_VGAVDE == 357) tempbx = 527;
  3033. else if(SiS_Pr->SiS_VGAVDE == 420) tempbx = 620;
  3034. else if(SiS_Pr->SiS_VGAVDE == 525) tempbx = 775;
  3035. else if(SiS_Pr->SiS_VGAVDE == 600) tempbx = 775;
  3036. else if(SiS_Pr->SiS_VGAVDE == 350) tempbx = 560;
  3037. else if(SiS_Pr->SiS_VGAVDE == 400) tempbx = 640;
  3038. }
  3039. break;
  3040. case Panel_1280x960:
  3041. if (SiS_Pr->SiS_VGAVDE == 350) tempbx = 700;
  3042. else if(SiS_Pr->SiS_VGAVDE == 400) tempbx = 800;
  3043. else if(SiS_Pr->SiS_VGAVDE == 1024) tempbx = 960;
  3044. break;
  3045. case Panel_1280x1024:
  3046. if (SiS_Pr->SiS_VGAVDE == 360) tempbx = 768;
  3047. else if(SiS_Pr->SiS_VGAVDE == 375) tempbx = 800;
  3048. else if(SiS_Pr->SiS_VGAVDE == 405) tempbx = 864;
  3049. break;
  3050. case Panel_1600x1200:
  3051. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
  3052. if (SiS_Pr->SiS_VGAVDE == 350) tempbx = 875;
  3053. else if(SiS_Pr->SiS_VGAVDE == 400) tempbx = 1000;
  3054. }
  3055. break;
  3056. }
  3057. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  3058. tempax = SiS_Pr->SiS_VGAHDE;
  3059. tempbx = SiS_Pr->SiS_VGAVDE;
  3060. }
  3061. SiS_Pr->SiS_HDE = tempax;
  3062. SiS_Pr->SiS_VDE = tempbx;
  3063. }
  3064. }
  3065. }
  3066. static void
  3067. SiS_GetCRT2Data(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  3068. unsigned short RefreshRateTableIndex)
  3069. {
  3070. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  3071. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  3072. SiS_GetCRT2DataLVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  3073. } else {
  3074. if((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) {
  3075. /* Need LVDS Data for LCD on 301B-DH */
  3076. SiS_GetCRT2DataLVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  3077. } else {
  3078. SiS_GetCRT2Data301(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  3079. }
  3080. }
  3081. } else {
  3082. SiS_GetCRT2DataLVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  3083. }
  3084. }
  3085. /*********************************************/
  3086. /* GET LVDS DES (SKEW) DATA */
  3087. /*********************************************/
  3088. static const struct SiS_LVDSDes *
  3089. SiS_GetLVDSDesPtr(struct SiS_Private *SiS_Pr)
  3090. {
  3091. const struct SiS_LVDSDes *PanelDesPtr = NULL;
  3092. #ifdef SIS300
  3093. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  3094. if(SiS_Pr->ChipType < SIS_315H) {
  3095. if(SiS_Pr->SiS_LCDTypeInfo == 4) {
  3096. if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) {
  3097. PanelDesPtr = SiS_Pr->SiS_PanelType04_1a;
  3098. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  3099. PanelDesPtr = SiS_Pr->SiS_PanelType04_2a;
  3100. }
  3101. } else if(SiS_Pr->SiS_CustomT == CUT_BARCO1024) {
  3102. PanelDesPtr = SiS_Pr->SiS_PanelType04_1b;
  3103. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  3104. PanelDesPtr = SiS_Pr->SiS_PanelType04_2b;
  3105. }
  3106. }
  3107. }
  3108. }
  3109. }
  3110. #endif
  3111. return PanelDesPtr;
  3112. }
  3113. static void
  3114. SiS_GetLVDSDesData(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  3115. unsigned short RefreshRateTableIndex)
  3116. {
  3117. unsigned short modeflag, ResIndex;
  3118. const struct SiS_LVDSDes *PanelDesPtr = NULL;
  3119. SiS_Pr->SiS_LCDHDES = 0;
  3120. SiS_Pr->SiS_LCDVDES = 0;
  3121. /* Some special cases */
  3122. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  3123. /* Trumpion */
  3124. if(SiS_Pr->SiS_IF_DEF_TRUMPION) {
  3125. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  3126. if(SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) {
  3127. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3128. }
  3129. }
  3130. return;
  3131. }
  3132. /* 640x480 on LVDS */
  3133. if(SiS_Pr->ChipType < SIS_315H) {
  3134. if(SiS_Pr->SiS_LCDResInfo == Panel_640x480 && SiS_Pr->SiS_LCDTypeInfo == 3) {
  3135. SiS_Pr->SiS_LCDHDES = 8;
  3136. if (SiS_Pr->SiS_VGAVDE >= 480) SiS_Pr->SiS_LCDVDES = 512;
  3137. else if(SiS_Pr->SiS_VGAVDE >= 400) SiS_Pr->SiS_LCDVDES = 436;
  3138. else if(SiS_Pr->SiS_VGAVDE >= 350) SiS_Pr->SiS_LCDVDES = 440;
  3139. return;
  3140. }
  3141. }
  3142. } /* LCD */
  3143. if( (SiS_Pr->UseCustomMode) ||
  3144. (SiS_Pr->SiS_LCDResInfo == Panel_Custom) ||
  3145. (SiS_Pr->SiS_CustomT == CUT_PANEL848) ||
  3146. (SiS_Pr->SiS_CustomT == CUT_PANEL856) ||
  3147. (SiS_Pr->SiS_LCDInfo & LCDPass11) ) {
  3148. return;
  3149. }
  3150. if(ModeNo <= 0x13) ResIndex = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  3151. else ResIndex = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  3152. if((SiS_Pr->SiS_VBType & VB_SIS30xBLV) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  3153. #ifdef SIS315H
  3154. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  3155. /* non-pass 1:1 only, see above */
  3156. if(SiS_Pr->SiS_VGAHDE != SiS_Pr->PanelXRes) {
  3157. SiS_Pr->SiS_LCDHDES = SiS_Pr->SiS_HT - ((SiS_Pr->PanelXRes - SiS_Pr->SiS_VGAHDE) / 2);
  3158. }
  3159. if(SiS_Pr->SiS_VGAVDE != SiS_Pr->PanelYRes) {
  3160. SiS_Pr->SiS_LCDVDES = SiS_Pr->SiS_VT - ((SiS_Pr->PanelYRes - SiS_Pr->SiS_VGAVDE) / 2);
  3161. }
  3162. }
  3163. if(SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) {
  3164. switch(SiS_Pr->SiS_CustomT) {
  3165. case CUT_UNIWILL1024:
  3166. case CUT_UNIWILL10242:
  3167. case CUT_CLEVO1400:
  3168. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  3169. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3170. }
  3171. break;
  3172. }
  3173. switch(SiS_Pr->SiS_LCDResInfo) {
  3174. case Panel_1280x1024:
  3175. if(SiS_Pr->SiS_CustomT != CUT_COMPAQ1280) {
  3176. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3177. }
  3178. break;
  3179. case Panel_1280x800: /* Verified for Averatec 6240 */
  3180. case Panel_1280x800_2: /* Verified for Asus A4L */
  3181. case Panel_1280x854: /* Not verified yet FIXME */
  3182. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3183. break;
  3184. }
  3185. }
  3186. #endif
  3187. } else {
  3188. if((SiS_Pr->SiS_IF_DEF_CH70xx != 0) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
  3189. if((SiS_Pr->SiS_TVMode & TVSetPAL) && (!(SiS_Pr->SiS_TVMode & TVSetPALM))) {
  3190. if(ResIndex <= 3) SiS_Pr->SiS_LCDHDES = 256;
  3191. }
  3192. } else if((PanelDesPtr = SiS_GetLVDSDesPtr(SiS_Pr))) {
  3193. SiS_Pr->SiS_LCDHDES = (PanelDesPtr+ResIndex)->LCDHDES;
  3194. SiS_Pr->SiS_LCDVDES = (PanelDesPtr+ResIndex)->LCDVDES;
  3195. } else if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  3196. if(SiS_Pr->SiS_VGAHDE != SiS_Pr->PanelXRes) {
  3197. SiS_Pr->SiS_LCDHDES = SiS_Pr->SiS_HT - ((SiS_Pr->PanelXRes - SiS_Pr->SiS_VGAHDE) / 2);
  3198. }
  3199. if(SiS_Pr->SiS_VGAVDE != SiS_Pr->PanelYRes) {
  3200. SiS_Pr->SiS_LCDVDES = SiS_Pr->SiS_VT - ((SiS_Pr->PanelYRes - SiS_Pr->SiS_VGAVDE) / 2);
  3201. } else {
  3202. if(SiS_Pr->ChipType < SIS_315H) {
  3203. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3204. } else {
  3205. switch(SiS_Pr->SiS_LCDResInfo) {
  3206. case Panel_800x600:
  3207. case Panel_1024x768:
  3208. case Panel_1280x1024:
  3209. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT;
  3210. break;
  3211. case Panel_1400x1050:
  3212. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3213. break;
  3214. }
  3215. }
  3216. }
  3217. } else {
  3218. if(SiS_Pr->ChipType < SIS_315H) {
  3219. #ifdef SIS300
  3220. switch(SiS_Pr->SiS_LCDResInfo) {
  3221. case Panel_800x600:
  3222. if(SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) {
  3223. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3224. } else {
  3225. SiS_Pr->SiS_LCDHDES = SiS_Pr->PanelHT + 3;
  3226. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT;
  3227. if(SiS_Pr->SiS_VGAVDE == 400) SiS_Pr->SiS_LCDVDES -= 2;
  3228. else SiS_Pr->SiS_LCDVDES -= 4;
  3229. }
  3230. break;
  3231. case Panel_1024x768:
  3232. if(SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) {
  3233. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3234. } else {
  3235. SiS_Pr->SiS_LCDHDES = SiS_Pr->PanelHT - 1;
  3236. if(SiS_Pr->SiS_VGAVDE <= 400) SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 8;
  3237. if(SiS_Pr->SiS_VGAVDE <= 350) SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 12;
  3238. }
  3239. break;
  3240. case Panel_1024x600:
  3241. default:
  3242. if( (SiS_Pr->SiS_VGAHDE == SiS_Pr->PanelXRes) &&
  3243. (SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) ) {
  3244. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3245. } else {
  3246. SiS_Pr->SiS_LCDHDES = SiS_Pr->PanelHT - 1;
  3247. }
  3248. break;
  3249. }
  3250. switch(SiS_Pr->SiS_LCDTypeInfo) {
  3251. case 1:
  3252. SiS_Pr->SiS_LCDHDES = SiS_Pr->SiS_LCDVDES = 0;
  3253. break;
  3254. case 3: /* 640x480 only? */
  3255. SiS_Pr->SiS_LCDHDES = 8;
  3256. if (SiS_Pr->SiS_VGAVDE >= 480) SiS_Pr->SiS_LCDVDES = 512;
  3257. else if(SiS_Pr->SiS_VGAVDE >= 400) SiS_Pr->SiS_LCDVDES = 436;
  3258. else if(SiS_Pr->SiS_VGAVDE >= 350) SiS_Pr->SiS_LCDVDES = 440;
  3259. break;
  3260. }
  3261. #endif
  3262. } else {
  3263. #ifdef SIS315H
  3264. switch(SiS_Pr->SiS_LCDResInfo) {
  3265. case Panel_1024x768:
  3266. case Panel_1280x1024:
  3267. if(SiS_Pr->SiS_VGAVDE == SiS_Pr->PanelYRes) {
  3268. SiS_Pr->SiS_LCDVDES = SiS_Pr->PanelVT - 1;
  3269. }
  3270. break;
  3271. case Panel_320x240_1:
  3272. case Panel_320x240_2:
  3273. case Panel_320x240_3:
  3274. SiS_Pr->SiS_LCDVDES = 524;
  3275. break;
  3276. }
  3277. #endif
  3278. }
  3279. }
  3280. if((ModeNo <= 0x13) && (SiS_Pr->SiS_LCDInfo & DontExpandLCD)) {
  3281. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  3282. if((SiS_Pr->SiS_VBType & VB_SIS30xBLV) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  3283. if(!(modeflag & HalfDCLK)) SiS_Pr->SiS_LCDHDES = 632;
  3284. } else if(!(SiS_Pr->SiS_SetFlag & SetDOSMode)) {
  3285. if(SiS_Pr->SiS_LCDResInfo != Panel_1280x1024) {
  3286. if(SiS_Pr->SiS_LCDResInfo >= Panel_1024x768) {
  3287. if(SiS_Pr->ChipType < SIS_315H) {
  3288. if(!(modeflag & HalfDCLK)) SiS_Pr->SiS_LCDHDES = 320;
  3289. } else {
  3290. #ifdef SIS315H
  3291. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) SiS_Pr->SiS_LCDHDES = 480;
  3292. if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) SiS_Pr->SiS_LCDHDES = 804;
  3293. if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) SiS_Pr->SiS_LCDHDES = 704;
  3294. if(!(modeflag & HalfDCLK)) {
  3295. SiS_Pr->SiS_LCDHDES = 320;
  3296. if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) SiS_Pr->SiS_LCDHDES = 632;
  3297. if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) SiS_Pr->SiS_LCDHDES = 542;
  3298. }
  3299. #endif
  3300. }
  3301. }
  3302. }
  3303. }
  3304. }
  3305. }
  3306. }
  3307. /*********************************************/
  3308. /* DISABLE VIDEO BRIDGE */
  3309. /*********************************************/
  3310. #ifdef SIS315H
  3311. static int
  3312. SiS_HandlePWD(struct SiS_Private *SiS_Pr)
  3313. {
  3314. int ret = 0;
  3315. #ifdef SET_PWD
  3316. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  3317. unsigned short romptr = GetLCDStructPtr661_2(SiS_Pr);
  3318. unsigned char drivermode = SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & 0x40;
  3319. unsigned short temp;
  3320. if( (SiS_Pr->SiS_VBType & VB_SISPWD) &&
  3321. (romptr) &&
  3322. (SiS_Pr->SiS_PWDOffset) ) {
  3323. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2b,ROMAddr[romptr + SiS_Pr->SiS_PWDOffset + 0]);
  3324. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2c,ROMAddr[romptr + SiS_Pr->SiS_PWDOffset + 1]);
  3325. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2d,ROMAddr[romptr + SiS_Pr->SiS_PWDOffset + 2]);
  3326. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2e,ROMAddr[romptr + SiS_Pr->SiS_PWDOffset + 3]);
  3327. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2f,ROMAddr[romptr + SiS_Pr->SiS_PWDOffset + 4]);
  3328. temp = 0x00;
  3329. if((ROMAddr[romptr + 2] & (0x06 << 1)) && !drivermode) {
  3330. temp = 0x80;
  3331. ret = 1;
  3332. }
  3333. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x27,0x7f,temp);
  3334. }
  3335. #endif
  3336. return ret;
  3337. }
  3338. #endif
  3339. /* NEVER use any variables (VBInfo), this will be called
  3340. * from outside the context of modeswitch!
  3341. * MUST call getVBType before calling this
  3342. */
  3343. void
  3344. SiS_DisableBridge(struct SiS_Private *SiS_Pr)
  3345. {
  3346. #ifdef SIS315H
  3347. unsigned short tempah, pushax=0, modenum;
  3348. #endif
  3349. unsigned short temp=0;
  3350. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  3351. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) { /* ===== For 30xB/C/LV ===== */
  3352. if(SiS_Pr->ChipType < SIS_315H) {
  3353. #ifdef SIS300 /* 300 series */
  3354. if(!(SiS_CR36BIOSWord23b(SiS_Pr))) {
  3355. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3356. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFE);
  3357. } else {
  3358. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x08);
  3359. }
  3360. SiS_PanelDelay(SiS_Pr, 3);
  3361. }
  3362. if(SiS_Is301B(SiS_Pr)) {
  3363. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1f,0x3f);
  3364. SiS_ShortDelay(SiS_Pr,1);
  3365. }
  3366. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xDF);
  3367. SiS_DisplayOff(SiS_Pr);
  3368. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF);
  3369. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF);
  3370. SiS_UnLockCRT2(SiS_Pr);
  3371. if(!(SiS_Pr->SiS_VBType & VB_SISLVDS)) {
  3372. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x01,0x80);
  3373. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x02,0x40);
  3374. }
  3375. if( (!(SiS_CRT2IsLCD(SiS_Pr))) ||
  3376. (!(SiS_CR36BIOSWord23d(SiS_Pr))) ) {
  3377. SiS_PanelDelay(SiS_Pr, 2);
  3378. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3379. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFD);
  3380. } else {
  3381. SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x04);
  3382. }
  3383. }
  3384. #endif /* SIS300 */
  3385. } else {
  3386. #ifdef SIS315H /* 315 series */
  3387. int didpwd = 0;
  3388. bool custom1 = (SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) ||
  3389. (SiS_Pr->SiS_CustomT == CUT_CLEVO1400);
  3390. modenum = SiS_GetReg(SiS_Pr->SiS_P3d4,0x34) & 0x7f;
  3391. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3392. #ifdef SET_EMI
  3393. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  3394. if(SiS_Pr->SiS_CustomT != CUT_CLEVO1400) {
  3395. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
  3396. }
  3397. }
  3398. #endif
  3399. didpwd = SiS_HandlePWD(SiS_Pr);
  3400. if( (modenum <= 0x13) ||
  3401. (SiS_IsVAMode(SiS_Pr)) ||
  3402. (!(SiS_IsDualEdge(SiS_Pr))) ) {
  3403. if(!didpwd) {
  3404. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xfe);
  3405. if(custom1) SiS_PanelDelay(SiS_Pr, 3);
  3406. } else {
  3407. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xfc);
  3408. }
  3409. }
  3410. if(!custom1) {
  3411. SiS_DDC2Delay(SiS_Pr,0xff00);
  3412. SiS_DDC2Delay(SiS_Pr,0xe000);
  3413. SiS_SetRegByte(SiS_Pr->SiS_P3c6,0x00);
  3414. pushax = SiS_GetReg(SiS_Pr->SiS_P3c4,0x06);
  3415. if(IS_SIS740) {
  3416. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x06,0xE3);
  3417. }
  3418. SiS_PanelDelay(SiS_Pr, 3);
  3419. }
  3420. }
  3421. if(!(SiS_IsNotM650orLater(SiS_Pr))) {
  3422. /* if(SiS_Pr->ChipType < SIS_340) {*/
  3423. tempah = 0xef;
  3424. if(SiS_IsVAMode(SiS_Pr)) tempah = 0xf7;
  3425. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x4c,tempah);
  3426. /*}*/
  3427. }
  3428. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3429. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1F,~0x10);
  3430. }
  3431. tempah = 0x3f;
  3432. if(SiS_IsDualEdge(SiS_Pr)) {
  3433. tempah = 0x7f;
  3434. if(!(SiS_IsVAMode(SiS_Pr))) tempah = 0xbf;
  3435. }
  3436. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1F,tempah);
  3437. if((SiS_IsVAMode(SiS_Pr)) ||
  3438. ((SiS_Pr->SiS_VBType & VB_SISLVDS) && (modenum <= 0x13))) {
  3439. SiS_DisplayOff(SiS_Pr);
  3440. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3441. SiS_PanelDelay(SiS_Pr, 2);
  3442. }
  3443. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF);
  3444. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1E,0xDF);
  3445. }
  3446. if((!(SiS_IsVAMode(SiS_Pr))) ||
  3447. ((SiS_Pr->SiS_VBType & VB_SISLVDS) && (modenum <= 0x13))) {
  3448. if(!(SiS_IsDualEdge(SiS_Pr))) {
  3449. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xdf);
  3450. SiS_DisplayOff(SiS_Pr);
  3451. }
  3452. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x80);
  3453. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3454. SiS_PanelDelay(SiS_Pr, 2);
  3455. }
  3456. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF);
  3457. temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00);
  3458. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x10);
  3459. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF);
  3460. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,temp);
  3461. }
  3462. if(SiS_IsNotM650orLater(SiS_Pr)) {
  3463. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0x7f);
  3464. }
  3465. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3466. if( (!(SiS_IsVAMode(SiS_Pr))) &&
  3467. (!(SiS_CRT2IsLCD(SiS_Pr))) &&
  3468. (!(SiS_IsDualEdge(SiS_Pr))) ) {
  3469. if(custom1) SiS_PanelDelay(SiS_Pr, 2);
  3470. if(!didpwd) {
  3471. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFD);
  3472. }
  3473. if(custom1) SiS_PanelDelay(SiS_Pr, 4);
  3474. }
  3475. if(!custom1) {
  3476. SiS_SetReg(SiS_Pr->SiS_P3c4,0x06,pushax);
  3477. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  3478. if(SiS_IsVAorLCD(SiS_Pr)) {
  3479. SiS_PanelDelayLoop(SiS_Pr, 3, 20);
  3480. }
  3481. }
  3482. }
  3483. }
  3484. #endif /* SIS315H */
  3485. }
  3486. } else { /* ============ For 301 ================ */
  3487. if(SiS_Pr->ChipType < SIS_315H) {
  3488. #ifdef SIS300
  3489. if(!(SiS_CR36BIOSWord23b(SiS_Pr))) {
  3490. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x08);
  3491. SiS_PanelDelay(SiS_Pr, 3);
  3492. }
  3493. #endif
  3494. }
  3495. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xDF); /* disable VB */
  3496. SiS_DisplayOff(SiS_Pr);
  3497. if(SiS_Pr->ChipType >= SIS_315H) {
  3498. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x80);
  3499. }
  3500. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF); /* disable lock mode */
  3501. if(SiS_Pr->ChipType >= SIS_315H) {
  3502. temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00);
  3503. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x10);
  3504. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);
  3505. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,temp);
  3506. } else {
  3507. #ifdef SIS300
  3508. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF); /* disable CRT2 */
  3509. if( (!(SiS_CRT2IsLCD(SiS_Pr))) ||
  3510. (!(SiS_CR36BIOSWord23d(SiS_Pr))) ) {
  3511. SiS_PanelDelay(SiS_Pr, 2);
  3512. SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x04);
  3513. }
  3514. #endif
  3515. }
  3516. }
  3517. } else { /* ============ For LVDS =============*/
  3518. if(SiS_Pr->ChipType < SIS_315H) {
  3519. #ifdef SIS300 /* 300 series */
  3520. if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) {
  3521. SiS_SetCH700x(SiS_Pr,0x0E,0x09);
  3522. }
  3523. if(SiS_Pr->ChipType == SIS_730) {
  3524. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x11) & 0x08)) {
  3525. SiS_WaitVBRetrace(SiS_Pr);
  3526. }
  3527. if(!(SiS_CR36BIOSWord23b(SiS_Pr))) {
  3528. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x08);
  3529. SiS_PanelDelay(SiS_Pr, 3);
  3530. }
  3531. } else {
  3532. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x11) & 0x08)) {
  3533. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x40)) {
  3534. if(!(SiS_CR36BIOSWord23b(SiS_Pr))) {
  3535. SiS_WaitVBRetrace(SiS_Pr);
  3536. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x06) & 0x1c)) {
  3537. SiS_DisplayOff(SiS_Pr);
  3538. }
  3539. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x08);
  3540. SiS_PanelDelay(SiS_Pr, 3);
  3541. }
  3542. }
  3543. }
  3544. }
  3545. SiS_DisplayOff(SiS_Pr);
  3546. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF);
  3547. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF);
  3548. SiS_UnLockCRT2(SiS_Pr);
  3549. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x01,0x80);
  3550. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x02,0x40);
  3551. if( (!(SiS_CRT2IsLCD(SiS_Pr))) ||
  3552. (!(SiS_CR36BIOSWord23d(SiS_Pr))) ) {
  3553. SiS_PanelDelay(SiS_Pr, 2);
  3554. SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x04);
  3555. }
  3556. #endif /* SIS300 */
  3557. } else {
  3558. #ifdef SIS315H /* 315 series */
  3559. if(!(SiS_IsNotM650orLater(SiS_Pr))) {
  3560. /*if(SiS_Pr->ChipType < SIS_340) { */ /* XGI needs this */
  3561. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x4c,~0x18);
  3562. /* } */
  3563. }
  3564. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  3565. if(SiS_Pr->ChipType == SIS_740) {
  3566. temp = SiS_GetCH701x(SiS_Pr,0x61);
  3567. if(temp < 1) {
  3568. SiS_SetCH701x(SiS_Pr,0x76,0xac);
  3569. SiS_SetCH701x(SiS_Pr,0x66,0x00);
  3570. }
  3571. if( (!(SiS_IsDualEdge(SiS_Pr))) ||
  3572. (SiS_IsTVOrYPbPrOrScart(SiS_Pr)) ) {
  3573. SiS_SetCH701x(SiS_Pr,0x49,0x3e);
  3574. }
  3575. }
  3576. if( (!(SiS_IsDualEdge(SiS_Pr))) ||
  3577. (SiS_IsVAMode(SiS_Pr)) ) {
  3578. SiS_Chrontel701xBLOff(SiS_Pr);
  3579. SiS_Chrontel701xOff(SiS_Pr);
  3580. }
  3581. if(SiS_Pr->ChipType != SIS_740) {
  3582. if( (!(SiS_IsDualEdge(SiS_Pr))) ||
  3583. (SiS_IsTVOrYPbPrOrScart(SiS_Pr)) ) {
  3584. SiS_SetCH701x(SiS_Pr,0x49,0x01);
  3585. }
  3586. }
  3587. }
  3588. if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
  3589. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x08);
  3590. SiS_PanelDelay(SiS_Pr, 3);
  3591. }
  3592. if( (SiS_Pr->SiS_IF_DEF_CH70xx == 0) ||
  3593. (!(SiS_IsDualEdge(SiS_Pr))) ||
  3594. (!(SiS_IsTVOrYPbPrOrScart(SiS_Pr))) ) {
  3595. SiS_DisplayOff(SiS_Pr);
  3596. }
  3597. if( (SiS_Pr->SiS_IF_DEF_CH70xx == 0) ||
  3598. (!(SiS_IsDualEdge(SiS_Pr))) ||
  3599. (!(SiS_IsVAMode(SiS_Pr))) ) {
  3600. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x00,0x80);
  3601. }
  3602. if(SiS_Pr->ChipType == SIS_740) {
  3603. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0x7f);
  3604. }
  3605. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x32,0xDF);
  3606. if( (SiS_Pr->SiS_IF_DEF_CH70xx == 0) ||
  3607. (!(SiS_IsDualEdge(SiS_Pr))) ||
  3608. (!(SiS_IsVAMode(SiS_Pr))) ) {
  3609. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x1E,0xDF);
  3610. }
  3611. if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
  3612. if(SiS_CRT2IsLCD(SiS_Pr)) {
  3613. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xdf);
  3614. if(SiS_Pr->ChipType == SIS_550) {
  3615. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xbf);
  3616. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xef);
  3617. }
  3618. }
  3619. } else {
  3620. if(SiS_Pr->ChipType == SIS_740) {
  3621. if(SiS_IsLCDOrLCDA(SiS_Pr)) {
  3622. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xdf);
  3623. }
  3624. } else if(SiS_IsVAMode(SiS_Pr)) {
  3625. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x1e,0xdf);
  3626. }
  3627. }
  3628. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  3629. if(SiS_IsDualEdge(SiS_Pr)) {
  3630. /* SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xff); */
  3631. } else {
  3632. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xfb);
  3633. }
  3634. }
  3635. SiS_UnLockCRT2(SiS_Pr);
  3636. if(SiS_Pr->ChipType == SIS_550) {
  3637. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x01,0x80); /* DirectDVD PAL?*/
  3638. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x02,0x40); /* VB clock / 4 ? */
  3639. } else if( (SiS_Pr->SiS_IF_DEF_CH70xx == 0) ||
  3640. (!(SiS_IsDualEdge(SiS_Pr))) ||
  3641. (!(SiS_IsVAMode(SiS_Pr))) ) {
  3642. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0xf7);
  3643. }
  3644. if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
  3645. if(SiS_CRT2IsLCD(SiS_Pr)) {
  3646. if(!(SiS_WeHaveBacklightCtrl(SiS_Pr))) {
  3647. SiS_PanelDelay(SiS_Pr, 2);
  3648. SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x04);
  3649. }
  3650. }
  3651. }
  3652. #endif /* SIS315H */
  3653. } /* 315 series */
  3654. } /* LVDS */
  3655. }
  3656. /*********************************************/
  3657. /* ENABLE VIDEO BRIDGE */
  3658. /*********************************************/
  3659. /* NEVER use any variables (VBInfo), this will be called
  3660. * from outside the context of a mode switch!
  3661. * MUST call getVBType before calling this
  3662. */
  3663. static
  3664. void
  3665. SiS_EnableBridge(struct SiS_Private *SiS_Pr)
  3666. {
  3667. unsigned short temp=0, tempah;
  3668. #ifdef SIS315H
  3669. unsigned short temp1, pushax=0;
  3670. bool delaylong = false;
  3671. #endif
  3672. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  3673. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) { /* ====== For 301B et al ====== */
  3674. if(SiS_Pr->ChipType < SIS_315H) {
  3675. #ifdef SIS300 /* 300 series */
  3676. if(SiS_CRT2IsLCD(SiS_Pr)) {
  3677. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3678. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x02);
  3679. } else if(SiS_Pr->SiS_VBType & VB_NoLCD) {
  3680. SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x00);
  3681. }
  3682. if(SiS_Pr->SiS_VBType & (VB_SISLVDS | VB_NoLCD)) {
  3683. if(!(SiS_CR36BIOSWord23d(SiS_Pr))) {
  3684. SiS_PanelDelay(SiS_Pr, 0);
  3685. }
  3686. }
  3687. }
  3688. if((SiS_Pr->SiS_VBType & VB_NoLCD) &&
  3689. (SiS_CRT2IsLCD(SiS_Pr))) {
  3690. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20); /* Enable CRT2 */
  3691. SiS_DisplayOn(SiS_Pr);
  3692. SiS_UnLockCRT2(SiS_Pr);
  3693. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x02,0xBF);
  3694. if(SiS_BridgeInSlavemode(SiS_Pr)) {
  3695. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x01,0x1F);
  3696. } else {
  3697. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x01,0x1F,0x40);
  3698. }
  3699. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x40)) {
  3700. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x16) & 0x10)) {
  3701. if(!(SiS_CR36BIOSWord23b(SiS_Pr))) {
  3702. SiS_PanelDelay(SiS_Pr, 1);
  3703. }
  3704. SiS_WaitVBRetrace(SiS_Pr);
  3705. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x00);
  3706. }
  3707. }
  3708. } else {
  3709. temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x32) & 0xDF; /* lock mode */
  3710. if(SiS_BridgeInSlavemode(SiS_Pr)) {
  3711. tempah = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  3712. if(!(tempah & SetCRT2ToRAMDAC)) temp |= 0x20;
  3713. }
  3714. SiS_SetReg(SiS_Pr->SiS_P3c4,0x32,temp);
  3715. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);
  3716. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x00,0x1F,0x20); /* enable VB processor */
  3717. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x1F,0xC0);
  3718. SiS_DisplayOn(SiS_Pr);
  3719. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3720. if(SiS_CRT2IsLCD(SiS_Pr)) {
  3721. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x16) & 0x10)) {
  3722. if(!(SiS_CR36BIOSWord23b(SiS_Pr))) {
  3723. SiS_PanelDelay(SiS_Pr, 1);
  3724. }
  3725. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x01);
  3726. }
  3727. }
  3728. }
  3729. }
  3730. #endif /* SIS300 */
  3731. } else {
  3732. #ifdef SIS315H /* 315 series */
  3733. #ifdef SET_EMI
  3734. unsigned char r30=0, r31=0, r32=0, r33=0, cr36=0;
  3735. int didpwd = 0;
  3736. /* unsigned short emidelay=0; */
  3737. #endif
  3738. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3739. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x1f,0xef);
  3740. #ifdef SET_EMI
  3741. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  3742. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
  3743. }
  3744. #endif
  3745. }
  3746. if(!(SiS_IsNotM650orLater(SiS_Pr))) {
  3747. /*if(SiS_Pr->ChipType < SIS_340) { */
  3748. tempah = 0x10;
  3749. if(SiS_LCDAEnabled(SiS_Pr)) {
  3750. if(SiS_TVEnabled(SiS_Pr)) tempah = 0x18;
  3751. else tempah = 0x08;
  3752. }
  3753. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x4c,tempah);
  3754. /*}*/
  3755. }
  3756. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3757. SiS_SetRegByte(SiS_Pr->SiS_P3c6,0x00);
  3758. SiS_DisplayOff(SiS_Pr);
  3759. pushax = SiS_GetReg(SiS_Pr->SiS_P3c4,0x06);
  3760. if(IS_SIS740) {
  3761. SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x06,0xE3);
  3762. }
  3763. didpwd = SiS_HandlePWD(SiS_Pr);
  3764. if(SiS_IsVAorLCD(SiS_Pr)) {
  3765. if(!didpwd) {
  3766. if(!(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x26) & 0x02)) {
  3767. SiS_PanelDelayLoop(SiS_Pr, 3, 2);
  3768. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x02);
  3769. SiS_PanelDelayLoop(SiS_Pr, 3, 2);
  3770. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  3771. SiS_GenericDelay(SiS_Pr, 17664);
  3772. }
  3773. }
  3774. } else {
  3775. SiS_PanelDelayLoop(SiS_Pr, 3, 2);
  3776. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  3777. SiS_GenericDelay(SiS_Pr, 17664);
  3778. }
  3779. }
  3780. }
  3781. if(!(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & 0x40)) {
  3782. SiS_PanelDelayLoop(SiS_Pr, 3, 10);
  3783. delaylong = true;
  3784. }
  3785. }
  3786. if(!(SiS_IsVAMode(SiS_Pr))) {
  3787. temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x32) & 0xDF;
  3788. if(SiS_BridgeInSlavemode(SiS_Pr)) {
  3789. tempah = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  3790. if(!(tempah & SetCRT2ToRAMDAC)) {
  3791. if(!(SiS_LCDAEnabled(SiS_Pr))) temp |= 0x20;
  3792. }
  3793. }
  3794. SiS_SetReg(SiS_Pr->SiS_P3c4,0x32,temp);
  3795. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20); /* enable CRT2 */
  3796. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0x7f);
  3797. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2e,0x80);
  3798. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3799. SiS_PanelDelay(SiS_Pr, 2);
  3800. }
  3801. } else {
  3802. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1e,0x20);
  3803. }
  3804. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x00,0x1f,0x20);
  3805. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2e,0x80);
  3806. if(SiS_Pr->SiS_VBType & VB_SISPOWER) {
  3807. if( (SiS_LCDAEnabled(SiS_Pr)) ||
  3808. (SiS_CRT2IsLCD(SiS_Pr)) ) {
  3809. /* Enable "LVDS PLL power on" (even on 301C) */
  3810. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x2a,0x7f);
  3811. /* Enable "LVDS Driver Power on" (even on 301C) */
  3812. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x7f);
  3813. }
  3814. }
  3815. tempah = 0xc0;
  3816. if(SiS_IsDualEdge(SiS_Pr)) {
  3817. tempah = 0x80;
  3818. if(!(SiS_IsVAMode(SiS_Pr))) tempah = 0x40;
  3819. }
  3820. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x1F,tempah);
  3821. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  3822. SiS_PanelDelay(SiS_Pr, 2);
  3823. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x1f,0x10);
  3824. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2e,0x80);
  3825. if(SiS_Pr->SiS_CustomT != CUT_CLEVO1400) {
  3826. #ifdef SET_EMI
  3827. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  3828. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
  3829. SiS_GenericDelay(SiS_Pr, 2048);
  3830. }
  3831. #endif
  3832. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x27,0x0c);
  3833. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  3834. #ifdef SET_EMI
  3835. cr36 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36);
  3836. if(SiS_Pr->SiS_ROMNew) {
  3837. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  3838. unsigned short romptr = GetLCDStructPtr661_2(SiS_Pr);
  3839. if(romptr) {
  3840. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x30,0x20); /* Reset */
  3841. SiS_Pr->EMI_30 = 0;
  3842. SiS_Pr->EMI_31 = ROMAddr[romptr + SiS_Pr->SiS_EMIOffset + 0];
  3843. SiS_Pr->EMI_32 = ROMAddr[romptr + SiS_Pr->SiS_EMIOffset + 1];
  3844. SiS_Pr->EMI_33 = ROMAddr[romptr + SiS_Pr->SiS_EMIOffset + 2];
  3845. if(ROMAddr[romptr + 1] & 0x10) SiS_Pr->EMI_30 = 0x40;
  3846. /* emidelay = SISGETROMW((romptr + 0x22)); */
  3847. SiS_Pr->HaveEMI = SiS_Pr->HaveEMILCD = SiS_Pr->OverruleEMI = true;
  3848. }
  3849. }
  3850. /* (P4_30|0x40) */
  3851. /* Compal 1400x1050: 0x05, 0x60, 0x00 YES (1.10.7w; CR36=69) */
  3852. /* Compal 1400x1050: 0x0d, 0x70, 0x40 YES (1.10.7x; CR36=69) */
  3853. /* Acer 1280x1024: 0x12, 0xd0, 0x6b NO (1.10.9k; CR36=73) */
  3854. /* Compaq 1280x1024: 0x0d, 0x70, 0x6b YES (1.12.04b; CR36=03) */
  3855. /* Clevo 1024x768: 0x05, 0x60, 0x33 NO (1.10.8e; CR36=12, DL!) */
  3856. /* Clevo 1024x768: 0x0d, 0x70, 0x40 (if type == 3) YES (1.10.8y; CR36=?2) */
  3857. /* Clevo 1024x768: 0x05, 0x60, 0x33 (if type != 3) YES (1.10.8y; CR36=?2) */
  3858. /* Asus 1024x768: ? ? (1.10.8o; CR36=?2) */
  3859. /* Asus 1024x768: 0x08, 0x10, 0x3c (problematic) YES (1.10.8q; CR36=22) */
  3860. if(SiS_Pr->HaveEMI) {
  3861. r30 = SiS_Pr->EMI_30; r31 = SiS_Pr->EMI_31;
  3862. r32 = SiS_Pr->EMI_32; r33 = SiS_Pr->EMI_33;
  3863. } else {
  3864. r30 = 0;
  3865. }
  3866. /* EMI_30 is read at driver start; however, the BIOS sets this
  3867. * (if it is used) only if the LCD is in use. In case we caught
  3868. * the machine while on TV output, this bit is not set and we
  3869. * don't know if it should be set - hence our detection is wrong.
  3870. * Work-around this here:
  3871. */
  3872. if((!SiS_Pr->HaveEMI) || (!SiS_Pr->HaveEMILCD)) {
  3873. switch((cr36 & 0x0f)) {
  3874. case 2:
  3875. r30 |= 0x40;
  3876. if(SiS_Pr->SiS_CustomT == CUT_CLEVO1024) r30 &= ~0x40;
  3877. if(!SiS_Pr->HaveEMI) {
  3878. r31 = 0x05; r32 = 0x60; r33 = 0x33;
  3879. if((cr36 & 0xf0) == 0x30) {
  3880. r31 = 0x0d; r32 = 0x70; r33 = 0x40;
  3881. }
  3882. }
  3883. break;
  3884. case 3: /* 1280x1024 */
  3885. if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) r30 |= 0x40;
  3886. if(!SiS_Pr->HaveEMI) {
  3887. r31 = 0x12; r32 = 0xd0; r33 = 0x6b;
  3888. if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) {
  3889. r31 = 0x0d; r32 = 0x70; r33 = 0x6b;
  3890. }
  3891. }
  3892. break;
  3893. case 9: /* 1400x1050 */
  3894. r30 |= 0x40;
  3895. if(!SiS_Pr->HaveEMI) {
  3896. r31 = 0x05; r32 = 0x60; r33 = 0x00;
  3897. if(SiS_Pr->SiS_CustomT == CUT_COMPAL1400_2) {
  3898. r31 = 0x0d; r32 = 0x70; r33 = 0x40; /* BIOS values */
  3899. }
  3900. }
  3901. break;
  3902. case 11: /* 1600x1200 - unknown */
  3903. r30 |= 0x40;
  3904. if(!SiS_Pr->HaveEMI) {
  3905. r31 = 0x05; r32 = 0x60; r33 = 0x00;
  3906. }
  3907. }
  3908. }
  3909. /* BIOS values don't work so well sometimes */
  3910. if(!SiS_Pr->OverruleEMI) {
  3911. #ifdef COMPAL_HACK
  3912. if(SiS_Pr->SiS_CustomT == CUT_COMPAL1400_2) {
  3913. if((cr36 & 0x0f) == 0x09) {
  3914. r30 = 0x60; r31 = 0x05; r32 = 0x60; r33 = 0x00;
  3915. }
  3916. }
  3917. #endif
  3918. #ifdef COMPAQ_HACK
  3919. if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) {
  3920. if((cr36 & 0x0f) == 0x03) {
  3921. r30 = 0x20; r31 = 0x12; r32 = 0xd0; r33 = 0x6b;
  3922. }
  3923. }
  3924. #endif
  3925. #ifdef ASUS_HACK
  3926. if(SiS_Pr->SiS_CustomT == CUT_ASUSA2H_2) {
  3927. if((cr36 & 0x0f) == 0x02) {
  3928. /* r30 = 0x60; r31 = 0x05; r32 = 0x60; r33 = 0x33; */ /* rev 2 */
  3929. /* r30 = 0x20; r31 = 0x05; r32 = 0x60; r33 = 0x33; */ /* rev 3 */
  3930. /* r30 = 0x60; r31 = 0x0d; r32 = 0x70; r33 = 0x40; */ /* rev 4 */
  3931. /* r30 = 0x20; r31 = 0x0d; r32 = 0x70; r33 = 0x40; */ /* rev 5 */
  3932. }
  3933. }
  3934. #endif
  3935. }
  3936. if(!(SiS_Pr->OverruleEMI && (!r30) && (!r31) && (!r32) && (!r33))) {
  3937. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x30,0x20); /* Reset */
  3938. SiS_GenericDelay(SiS_Pr, 2048);
  3939. }
  3940. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x31,r31);
  3941. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x32,r32);
  3942. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x33,r33);
  3943. #endif /* SET_EMI */
  3944. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x34,0x10);
  3945. #ifdef SET_EMI
  3946. if( (SiS_LCDAEnabled(SiS_Pr)) ||
  3947. (SiS_CRT2IsLCD(SiS_Pr)) ) {
  3948. if(r30 & 0x40) {
  3949. /*SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x2a,0x80);*/
  3950. SiS_PanelDelayLoop(SiS_Pr, 3, 5);
  3951. if(delaylong) {
  3952. SiS_PanelDelayLoop(SiS_Pr, 3, 5);
  3953. delaylong = false;
  3954. }
  3955. SiS_WaitVBRetrace(SiS_Pr);
  3956. SiS_WaitVBRetrace(SiS_Pr);
  3957. if(SiS_Pr->SiS_CustomT == CUT_ASUSA2H_2) {
  3958. SiS_GenericDelay(SiS_Pr, 1280);
  3959. }
  3960. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x30,0x40); /* Enable */
  3961. /*SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x2a,0x7f);*/
  3962. }
  3963. }
  3964. #endif
  3965. }
  3966. }
  3967. if(!(SiS_WeHaveBacklightCtrl(SiS_Pr))) {
  3968. if(SiS_IsVAorLCD(SiS_Pr)) {
  3969. SiS_PanelDelayLoop(SiS_Pr, 3, 10);
  3970. if(delaylong) {
  3971. SiS_PanelDelayLoop(SiS_Pr, 3, 10);
  3972. }
  3973. SiS_WaitVBRetrace(SiS_Pr);
  3974. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  3975. SiS_GenericDelay(SiS_Pr, 2048);
  3976. SiS_WaitVBRetrace(SiS_Pr);
  3977. }
  3978. if(!didpwd) {
  3979. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x01);
  3980. } else {
  3981. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x03);
  3982. }
  3983. }
  3984. }
  3985. SiS_SetReg(SiS_Pr->SiS_P3c4,0x06,pushax);
  3986. SiS_DisplayOn(SiS_Pr);
  3987. SiS_SetRegByte(SiS_Pr->SiS_P3c6,0xff);
  3988. }
  3989. if(!(SiS_WeHaveBacklightCtrl(SiS_Pr))) {
  3990. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x00,0x7f);
  3991. }
  3992. #endif /* SIS315H */
  3993. }
  3994. } else { /* ============ For 301 ================ */
  3995. if(SiS_Pr->ChipType < SIS_315H) {
  3996. if(SiS_CRT2IsLCD(SiS_Pr)) {
  3997. SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x00);
  3998. SiS_PanelDelay(SiS_Pr, 0);
  3999. }
  4000. }
  4001. temp = SiS_GetReg(SiS_Pr->SiS_P3c4,0x32) & 0xDF; /* lock mode */
  4002. if(SiS_BridgeInSlavemode(SiS_Pr)) {
  4003. tempah = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  4004. if(!(tempah & SetCRT2ToRAMDAC)) temp |= 0x20;
  4005. }
  4006. SiS_SetReg(SiS_Pr->SiS_P3c4,0x32,temp);
  4007. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20); /* enable CRT2 */
  4008. if(SiS_Pr->ChipType >= SIS_315H) {
  4009. temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x2E);
  4010. if(!(temp & 0x80)) {
  4011. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2E,0x80); /* BVBDOENABLE=1 */
  4012. }
  4013. }
  4014. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x00,0x1F,0x20); /* enable VB processor */
  4015. SiS_VBLongWait(SiS_Pr);
  4016. SiS_DisplayOn(SiS_Pr);
  4017. if(SiS_Pr->ChipType >= SIS_315H) {
  4018. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x00,0x7f);
  4019. }
  4020. SiS_VBLongWait(SiS_Pr);
  4021. if(SiS_Pr->ChipType < SIS_315H) {
  4022. if(SiS_CRT2IsLCD(SiS_Pr)) {
  4023. SiS_PanelDelay(SiS_Pr, 1);
  4024. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x00);
  4025. }
  4026. }
  4027. }
  4028. } else { /* =================== For LVDS ================== */
  4029. if(SiS_Pr->ChipType < SIS_315H) {
  4030. #ifdef SIS300 /* 300 series */
  4031. if(SiS_CRT2IsLCD(SiS_Pr)) {
  4032. if(SiS_Pr->ChipType == SIS_730) {
  4033. SiS_PanelDelay(SiS_Pr, 1);
  4034. SiS_PanelDelay(SiS_Pr, 1);
  4035. SiS_PanelDelay(SiS_Pr, 1);
  4036. }
  4037. SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x00);
  4038. if(!(SiS_CR36BIOSWord23d(SiS_Pr))) {
  4039. SiS_PanelDelay(SiS_Pr, 0);
  4040. }
  4041. }
  4042. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);
  4043. SiS_DisplayOn(SiS_Pr);
  4044. SiS_UnLockCRT2(SiS_Pr);
  4045. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x02,0xBF);
  4046. if(SiS_BridgeInSlavemode(SiS_Pr)) {
  4047. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x01,0x1F);
  4048. } else {
  4049. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x01,0x1F,0x40);
  4050. }
  4051. if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) {
  4052. if(!(SiS_CRT2IsLCD(SiS_Pr))) {
  4053. SiS_WaitVBRetrace(SiS_Pr);
  4054. SiS_SetCH700x(SiS_Pr,0x0E,0x0B);
  4055. }
  4056. }
  4057. if(SiS_CRT2IsLCD(SiS_Pr)) {
  4058. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x40)) {
  4059. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x16) & 0x10)) {
  4060. if(!(SiS_CR36BIOSWord23b(SiS_Pr))) {
  4061. SiS_PanelDelay(SiS_Pr, 1);
  4062. SiS_PanelDelay(SiS_Pr, 1);
  4063. }
  4064. SiS_WaitVBRetrace(SiS_Pr);
  4065. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x00);
  4066. }
  4067. }
  4068. }
  4069. #endif /* SIS300 */
  4070. } else {
  4071. #ifdef SIS315H /* 315 series */
  4072. if(!(SiS_IsNotM650orLater(SiS_Pr))) {
  4073. /*if(SiS_Pr->ChipType < SIS_340) {*/ /* XGI needs this */
  4074. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x4c,0x18);
  4075. /*}*/
  4076. }
  4077. if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
  4078. if(SiS_CRT2IsLCD(SiS_Pr)) {
  4079. SiS_SetRegSR11ANDOR(SiS_Pr,0xFB,0x00);
  4080. SiS_PanelDelay(SiS_Pr, 0);
  4081. }
  4082. }
  4083. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);
  4084. SiS_UnLockCRT2(SiS_Pr);
  4085. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0xf7);
  4086. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  4087. temp = SiS_GetCH701x(SiS_Pr,0x66);
  4088. temp &= 0x20;
  4089. SiS_Chrontel701xBLOff(SiS_Pr);
  4090. }
  4091. if(SiS_Pr->ChipType != SIS_550) {
  4092. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2e,0x7f);
  4093. }
  4094. if(SiS_Pr->ChipType == SIS_740) {
  4095. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  4096. if(SiS_IsLCDOrLCDA(SiS_Pr)) {
  4097. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x20);
  4098. }
  4099. }
  4100. }
  4101. temp1 = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x2E);
  4102. if(!(temp1 & 0x80)) {
  4103. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2E,0x80);
  4104. }
  4105. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  4106. if(temp) {
  4107. SiS_Chrontel701xBLOn(SiS_Pr);
  4108. }
  4109. }
  4110. if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
  4111. if(SiS_CRT2IsLCD(SiS_Pr)) {
  4112. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x20);
  4113. if(SiS_Pr->ChipType == SIS_550) {
  4114. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x40);
  4115. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x10);
  4116. }
  4117. }
  4118. } else if(SiS_IsVAMode(SiS_Pr)) {
  4119. if(SiS_Pr->ChipType != SIS_740) {
  4120. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1E,0x20);
  4121. }
  4122. }
  4123. if(!(SiS_WeHaveBacklightCtrl(SiS_Pr))) {
  4124. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x00,0x7f);
  4125. }
  4126. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  4127. if(SiS_IsTVOrYPbPrOrScart(SiS_Pr)) {
  4128. SiS_Chrontel701xOn(SiS_Pr);
  4129. }
  4130. if( (SiS_IsVAMode(SiS_Pr)) ||
  4131. (SiS_IsLCDOrLCDA(SiS_Pr)) ) {
  4132. SiS_ChrontelDoSomething1(SiS_Pr);
  4133. }
  4134. }
  4135. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  4136. if(!(SiS_WeHaveBacklightCtrl(SiS_Pr))) {
  4137. if( (SiS_IsVAMode(SiS_Pr)) ||
  4138. (SiS_IsLCDOrLCDA(SiS_Pr)) ) {
  4139. SiS_Chrontel701xBLOn(SiS_Pr);
  4140. SiS_ChrontelInitTVVSync(SiS_Pr);
  4141. }
  4142. }
  4143. } else if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
  4144. if(!(SiS_WeHaveBacklightCtrl(SiS_Pr))) {
  4145. if(SiS_CRT2IsLCD(SiS_Pr)) {
  4146. SiS_PanelDelay(SiS_Pr, 1);
  4147. SiS_SetRegSR11ANDOR(SiS_Pr,0xF7,0x00);
  4148. }
  4149. }
  4150. }
  4151. #endif /* SIS315H */
  4152. } /* 310 series */
  4153. } /* LVDS */
  4154. }
  4155. /*********************************************/
  4156. /* SET PART 1 REGISTER GROUP */
  4157. /*********************************************/
  4158. /* Set CRT2 OFFSET / PITCH */
  4159. static void
  4160. SiS_SetCRT2Offset(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  4161. unsigned short RRTI)
  4162. {
  4163. unsigned short offset;
  4164. unsigned char temp;
  4165. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) return;
  4166. offset = SiS_GetOffset(SiS_Pr,ModeNo,ModeIdIndex,RRTI);
  4167. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x07,(offset & 0xFF));
  4168. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x09,(offset >> 8));
  4169. temp = (unsigned char)(((offset >> 3) & 0xFF) + 1);
  4170. if(offset & 0x07) temp++;
  4171. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x03,temp);
  4172. }
  4173. /* Set CRT2 sync and PanelLink mode */
  4174. static void
  4175. SiS_SetCRT2Sync(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short RefreshRateTableIndex)
  4176. {
  4177. unsigned short tempah=0, tempbl, infoflag;
  4178. tempbl = 0xC0;
  4179. if(SiS_Pr->UseCustomMode) {
  4180. infoflag = SiS_Pr->CInfoFlag;
  4181. } else {
  4182. infoflag = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
  4183. }
  4184. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { /* LVDS */
  4185. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  4186. tempah = 0;
  4187. } else if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && (SiS_Pr->SiS_LCDInfo & LCDSync)) {
  4188. tempah = SiS_Pr->SiS_LCDInfo;
  4189. } else tempah = infoflag >> 8;
  4190. tempah &= 0xC0;
  4191. tempah |= 0x20;
  4192. if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10;
  4193. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  4194. if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) ||
  4195. (SiS_Pr->SiS_CustomT == CUT_BARCO1024)) {
  4196. tempah |= 0xf0;
  4197. }
  4198. if( (SiS_Pr->SiS_IF_DEF_FSTN) ||
  4199. (SiS_Pr->SiS_IF_DEF_DSTN) ||
  4200. (SiS_Pr->SiS_IF_DEF_TRUMPION) ||
  4201. (SiS_Pr->SiS_CustomT == CUT_PANEL848) ||
  4202. (SiS_Pr->SiS_CustomT == CUT_PANEL856) ) {
  4203. tempah |= 0x30;
  4204. }
  4205. if( (SiS_Pr->SiS_IF_DEF_FSTN) ||
  4206. (SiS_Pr->SiS_IF_DEF_DSTN) ) {
  4207. tempah &= ~0xc0;
  4208. }
  4209. }
  4210. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  4211. if(SiS_Pr->ChipType >= SIS_315H) {
  4212. tempah >>= 3;
  4213. tempah &= 0x18;
  4214. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,0xE7,tempah);
  4215. /* Don't care about 12/18/24 bit mode - TV is via VGA, not PL */
  4216. } else {
  4217. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,0xe0);
  4218. }
  4219. } else {
  4220. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah);
  4221. }
  4222. } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
  4223. if(SiS_Pr->ChipType < SIS_315H) {
  4224. #ifdef SIS300 /* ---- 300 series --- */
  4225. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) { /* 630 - 301B(-DH) */
  4226. tempah = infoflag >> 8;
  4227. tempbl = 0;
  4228. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  4229. if(SiS_Pr->SiS_LCDInfo & LCDSync) {
  4230. tempah = SiS_Pr->SiS_LCDInfo;
  4231. tempbl = (tempah >> 6) & 0x03;
  4232. }
  4233. }
  4234. tempah &= 0xC0;
  4235. tempah |= 0x20;
  4236. if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10;
  4237. tempah |= 0xc0;
  4238. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah);
  4239. if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && (!(SiS_Pr->SiS_VBType & VB_NoLCD))) {
  4240. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1a,0xf0,tempbl);
  4241. }
  4242. } else { /* 630 - 301 */
  4243. tempah = ((infoflag >> 8) & 0xc0) | 0x20;
  4244. if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10;
  4245. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah);
  4246. }
  4247. #endif /* SIS300 */
  4248. } else {
  4249. #ifdef SIS315H /* ------- 315 series ------ */
  4250. if(SiS_Pr->SiS_VBType & VB_SISLVDS) { /* 315 - LVDS */
  4251. tempbl = 0;
  4252. if((SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) &&
  4253. (SiS_Pr->SiS_LCDResInfo == Panel_1280x1024)) {
  4254. tempah = infoflag >> 8;
  4255. if(SiS_Pr->SiS_LCDInfo & LCDSync) {
  4256. tempbl = ((SiS_Pr->SiS_LCDInfo & 0xc0) >> 6);
  4257. }
  4258. } else if((SiS_Pr->SiS_CustomT == CUT_CLEVO1400) &&
  4259. (SiS_Pr->SiS_LCDResInfo == Panel_1400x1050)) {
  4260. tempah = infoflag >> 8;
  4261. tempbl = 0x03;
  4262. } else {
  4263. tempah = SiS_GetReg(SiS_Pr->SiS_P3d4,0x37);
  4264. tempbl = (tempah >> 6) & 0x03;
  4265. tempbl |= 0x08;
  4266. if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempbl |= 0x04;
  4267. }
  4268. tempah &= 0xC0;
  4269. tempah |= 0x20;
  4270. if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10;
  4271. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) tempah |= 0xc0;
  4272. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah);
  4273. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  4274. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  4275. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1a,0xf0,tempbl);
  4276. }
  4277. }
  4278. } else { /* 315 - TMDS */
  4279. tempah = tempbl = infoflag >> 8;
  4280. if(!SiS_Pr->UseCustomMode) {
  4281. tempbl = 0;
  4282. if((SiS_Pr->SiS_VBType & VB_SIS30xC) && (SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) {
  4283. if(ModeNo <= 0x13) {
  4284. tempah = SiS_GetRegByte((SiS_Pr->SiS_P3ca+0x02));
  4285. }
  4286. }
  4287. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4288. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  4289. if(SiS_Pr->SiS_LCDInfo & LCDSync) {
  4290. tempah = SiS_Pr->SiS_LCDInfo;
  4291. tempbl = (tempah >> 6) & 0x03;
  4292. }
  4293. }
  4294. }
  4295. }
  4296. tempah &= 0xC0;
  4297. tempah |= 0x20;
  4298. if(!(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit)) tempah |= 0x10;
  4299. if(SiS_Pr->SiS_VBType & VB_NoLCD) {
  4300. /* Imitate BIOS bug */
  4301. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) tempah |= 0xc0;
  4302. }
  4303. if((SiS_Pr->SiS_VBType & VB_SIS30xC) && (SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) {
  4304. tempah >>= 3;
  4305. tempah &= 0x18;
  4306. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,0xe7,tempah);
  4307. } else {
  4308. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0F,tempah);
  4309. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  4310. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  4311. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1a,0xf0,tempbl);
  4312. }
  4313. }
  4314. }
  4315. }
  4316. #endif /* SIS315H */
  4317. }
  4318. }
  4319. }
  4320. /* Set CRT2 FIFO on 300/540/630/730 */
  4321. #ifdef SIS300
  4322. static void
  4323. SiS_SetCRT2FIFO_300(struct SiS_Private *SiS_Pr,unsigned short ModeNo)
  4324. {
  4325. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  4326. unsigned short temp, index, modeidindex, refreshratetableindex;
  4327. unsigned short VCLK = 0, MCLK, colorth = 0, data2 = 0;
  4328. unsigned short tempbx, tempcl, CRT1ModeNo, CRT2ModeNo, SelectRate_backup;
  4329. unsigned int data, pci50, pciA0;
  4330. static const unsigned char colortharray[] = {
  4331. 1, 1, 2, 2, 3, 4
  4332. };
  4333. SelectRate_backup = SiS_Pr->SiS_SelectCRT2Rate;
  4334. if(!SiS_Pr->CRT1UsesCustomMode) {
  4335. CRT1ModeNo = SiS_Pr->SiS_CRT1Mode; /* get CRT1 ModeNo */
  4336. SiS_SearchModeID(SiS_Pr, &CRT1ModeNo, &modeidindex);
  4337. SiS_Pr->SiS_SetFlag &= (~ProgrammingCRT2);
  4338. SiS_Pr->SiS_SelectCRT2Rate = 0;
  4339. refreshratetableindex = SiS_GetRatePtr(SiS_Pr, CRT1ModeNo, modeidindex);
  4340. if(CRT1ModeNo >= 0x13) {
  4341. /* Get VCLK */
  4342. index = SiS_GetRefCRTVCLK(SiS_Pr, refreshratetableindex, SiS_Pr->SiS_UseWide);
  4343. VCLK = SiS_Pr->SiS_VCLKData[index].CLOCK;
  4344. /* Get colordepth */
  4345. colorth = SiS_GetColorDepth(SiS_Pr,CRT1ModeNo,modeidindex) >> 1;
  4346. if(!colorth) colorth++;
  4347. }
  4348. } else {
  4349. CRT1ModeNo = 0xfe;
  4350. /* Get VCLK */
  4351. VCLK = SiS_Pr->CSRClock_CRT1;
  4352. /* Get color depth */
  4353. colorth = colortharray[((SiS_Pr->CModeFlag_CRT1 & ModeTypeMask) - 2)];
  4354. }
  4355. if(CRT1ModeNo >= 0x13) {
  4356. /* Get MCLK */
  4357. if(SiS_Pr->ChipType == SIS_300) {
  4358. index = SiS_GetReg(SiS_Pr->SiS_P3c4,0x3A);
  4359. } else {
  4360. index = SiS_GetReg(SiS_Pr->SiS_P3c4,0x1A);
  4361. }
  4362. index &= 0x07;
  4363. MCLK = SiS_Pr->SiS_MCLKData_0[index].CLOCK;
  4364. temp = ((SiS_GetReg(SiS_Pr->SiS_P3c4,0x14) >> 6) & 0x03) << 1;
  4365. if(!temp) temp++;
  4366. temp <<= 2;
  4367. data2 = temp - ((colorth * VCLK) / MCLK);
  4368. temp = (28 * 16) % data2;
  4369. data2 = (28 * 16) / data2;
  4370. if(temp) data2++;
  4371. if(SiS_Pr->ChipType == SIS_300) {
  4372. SiS_GetFIFOThresholdIndex300(SiS_Pr, &tempbx, &tempcl);
  4373. data = SiS_GetFIFOThresholdB300(tempbx, tempcl);
  4374. } else {
  4375. pci50 = sisfb_read_nbridge_pci_dword(SiS_Pr, 0x50);
  4376. pciA0 = sisfb_read_nbridge_pci_dword(SiS_Pr, 0xa0);
  4377. if(SiS_Pr->ChipType == SIS_730) {
  4378. index = (unsigned short)(((pciA0 >> 28) & 0x0f) * 3);
  4379. index += (unsigned short)(((pci50 >> 9)) & 0x03);
  4380. /* BIOS BUG (2.04.5d, 2.04.6a use ah here, which is unset!) */
  4381. index = 0; /* -- do it like the BIOS anyway... */
  4382. } else {
  4383. pci50 >>= 24;
  4384. pciA0 >>= 24;
  4385. index = (pci50 >> 1) & 0x07;
  4386. if(pci50 & 0x01) index += 6;
  4387. if(!(pciA0 & 0x01)) index += 24;
  4388. if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x14) & 0x80) index += 12;
  4389. }
  4390. data = SiS_GetLatencyFactor630(SiS_Pr, index) + 15;
  4391. if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x14) & 0x80)) data += 5;
  4392. }
  4393. data += data2; /* CRT1 Request Period */
  4394. SiS_Pr->SiS_SetFlag |= ProgrammingCRT2;
  4395. SiS_Pr->SiS_SelectCRT2Rate = SelectRate_backup;
  4396. if(!SiS_Pr->UseCustomMode) {
  4397. CRT2ModeNo = ModeNo;
  4398. SiS_SearchModeID(SiS_Pr, &CRT2ModeNo, &modeidindex);
  4399. refreshratetableindex = SiS_GetRatePtr(SiS_Pr, CRT2ModeNo, modeidindex);
  4400. /* Get VCLK */
  4401. index = SiS_GetVCLK2Ptr(SiS_Pr, CRT2ModeNo, modeidindex, refreshratetableindex);
  4402. VCLK = SiS_Pr->SiS_VCLKData[index].CLOCK;
  4403. if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) || (SiS_Pr->SiS_CustomT == CUT_BARCO1024)) {
  4404. if(SiS_Pr->SiS_UseROM) {
  4405. if(ROMAddr[0x220] & 0x01) {
  4406. VCLK = ROMAddr[0x229] | (ROMAddr[0x22a] << 8);
  4407. }
  4408. }
  4409. }
  4410. } else {
  4411. /* Get VCLK */
  4412. CRT2ModeNo = 0xfe;
  4413. VCLK = SiS_Pr->CSRClock;
  4414. }
  4415. /* Get colordepth */
  4416. colorth = SiS_GetColorDepth(SiS_Pr,CRT2ModeNo,modeidindex) >> 1;
  4417. if(!colorth) colorth++;
  4418. data = data * VCLK * colorth;
  4419. temp = data % (MCLK << 4);
  4420. data = data / (MCLK << 4);
  4421. if(temp) data++;
  4422. if(data < 6) data = 6;
  4423. else if(data > 0x14) data = 0x14;
  4424. if(SiS_Pr->ChipType == SIS_300) {
  4425. temp = 0x16;
  4426. if((data <= 0x0f) || (SiS_Pr->SiS_LCDResInfo == Panel_1280x1024))
  4427. temp = 0x13;
  4428. } else {
  4429. temp = 0x16;
  4430. if(( (SiS_Pr->ChipType == SIS_630) ||
  4431. (SiS_Pr->ChipType == SIS_730) ) &&
  4432. (SiS_Pr->ChipRevision >= 0x30))
  4433. temp = 0x1b;
  4434. }
  4435. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x01,0xe0,temp);
  4436. if((SiS_Pr->ChipType == SIS_630) &&
  4437. (SiS_Pr->ChipRevision >= 0x30)) {
  4438. if(data > 0x13) data = 0x13;
  4439. }
  4440. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x02,0xe0,data);
  4441. } else { /* If mode <= 0x13, we just restore everything */
  4442. SiS_Pr->SiS_SetFlag |= ProgrammingCRT2;
  4443. SiS_Pr->SiS_SelectCRT2Rate = SelectRate_backup;
  4444. }
  4445. }
  4446. #endif
  4447. /* Set CRT2 FIFO on 315/330 series */
  4448. #ifdef SIS315H
  4449. static void
  4450. SiS_SetCRT2FIFO_310(struct SiS_Private *SiS_Pr)
  4451. {
  4452. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x01,0x3B);
  4453. if( (SiS_Pr->ChipType == SIS_760) &&
  4454. (SiS_Pr->SiS_SysFlags & SF_760LFB) &&
  4455. (SiS_Pr->SiS_ModeType == Mode32Bpp) &&
  4456. (SiS_Pr->SiS_VGAHDE >= 1280) &&
  4457. (SiS_Pr->SiS_VGAVDE >= 1024) ) {
  4458. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2f,0x03);
  4459. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x01,0x3b);
  4460. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x4d,0xc0);
  4461. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2f,0x01);
  4462. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x4d,0xc0);
  4463. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x02,0x6e);
  4464. } else {
  4465. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x02,~0x3f,0x04);
  4466. }
  4467. }
  4468. #endif
  4469. static unsigned short
  4470. SiS_GetVGAHT2(struct SiS_Private *SiS_Pr)
  4471. {
  4472. unsigned int tempax,tempbx;
  4473. tempbx = (SiS_Pr->SiS_VGAVT - SiS_Pr->SiS_VGAVDE) * SiS_Pr->SiS_RVBHCMAX;
  4474. tempax = (SiS_Pr->SiS_VT - SiS_Pr->SiS_VDE) * SiS_Pr->SiS_RVBHCFACT;
  4475. tempax = (tempax * SiS_Pr->SiS_HT) / tempbx;
  4476. return (unsigned short)tempax;
  4477. }
  4478. /* Set Part 1 / SiS bridge slave mode */
  4479. static void
  4480. SiS_SetGroup1_301(struct SiS_Private *SiS_Pr, unsigned short ModeNo,unsigned short ModeIdIndex,
  4481. unsigned short RefreshRateTableIndex)
  4482. {
  4483. unsigned short temp, modeflag, i, j, xres=0, VGAVDE;
  4484. static const unsigned short CRTranslation[] = {
  4485. /* CR0 CR1 CR2 CR3 CR4 CR5 CR6 CR7 */
  4486. 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a,
  4487. /* CR8 CR9 SR0A SR0B SR0C SR0D SR0E CR0F */
  4488. 0x00, 0x0b, 0x17, 0x18, 0x19, 0x00, 0x1a, 0x00,
  4489. /* CR10 CR11 CR12 CR13 CR14 CR15 CR16 CR17 */
  4490. 0x0c, 0x0d, 0x0e, 0x00, 0x0f, 0x10, 0x11, 0x00
  4491. };
  4492. if(ModeNo <= 0x13) {
  4493. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  4494. } else if(SiS_Pr->UseCustomMode) {
  4495. modeflag = SiS_Pr->CModeFlag;
  4496. xres = SiS_Pr->CHDisplay;
  4497. } else {
  4498. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  4499. xres = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].XRes;
  4500. }
  4501. /* The following is only done if bridge is in slave mode: */
  4502. if(SiS_Pr->ChipType >= SIS_315H) {
  4503. if(xres >= 1600) { /* BIOS: == 1600 */
  4504. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x31,0x04);
  4505. }
  4506. }
  4507. SiS_Pr->CHTotal = 8224; /* Max HT, 0x2020, results in 0x3ff in registers */
  4508. SiS_Pr->CHDisplay = SiS_Pr->SiS_VGAHDE;
  4509. if(modeflag & HalfDCLK) SiS_Pr->CHDisplay >>= 1;
  4510. SiS_Pr->CHBlankStart = SiS_Pr->CHDisplay;
  4511. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  4512. SiS_Pr->CHBlankStart += 16;
  4513. }
  4514. SiS_Pr->CHBlankEnd = 32;
  4515. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  4516. if(xres == 1600) SiS_Pr->CHBlankEnd += 80;
  4517. }
  4518. temp = SiS_Pr->SiS_VGAHT - 96;
  4519. if(!(modeflag & HalfDCLK)) temp -= 32;
  4520. if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
  4521. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x04);
  4522. temp |= ((SiS_GetReg(SiS_Pr->SiS_P3c4,0x0b) & 0xc0) << 2);
  4523. temp -= 3;
  4524. temp <<= 3;
  4525. } else {
  4526. if(SiS_Pr->SiS_RVBHRS2) temp = SiS_Pr->SiS_RVBHRS2;
  4527. }
  4528. SiS_Pr->CHSyncStart = temp;
  4529. SiS_Pr->CHSyncEnd = 0xffe8; /* results in 0x2000 in registers */
  4530. SiS_Pr->CVTotal = 2049; /* Max VT, 0x0801, results in 0x7ff in registers */
  4531. VGAVDE = SiS_Pr->SiS_VGAVDE;
  4532. if (VGAVDE == 357) VGAVDE = 350;
  4533. else if(VGAVDE == 360) VGAVDE = 350;
  4534. else if(VGAVDE == 375) VGAVDE = 350;
  4535. else if(VGAVDE == 405) VGAVDE = 400;
  4536. else if(VGAVDE == 420) VGAVDE = 400;
  4537. else if(VGAVDE == 525) VGAVDE = 480;
  4538. else if(VGAVDE == 1056) VGAVDE = 1024;
  4539. SiS_Pr->CVDisplay = VGAVDE;
  4540. SiS_Pr->CVBlankStart = SiS_Pr->CVDisplay;
  4541. SiS_Pr->CVBlankEnd = 1;
  4542. if(ModeNo == 0x3c) SiS_Pr->CVBlankEnd = 226;
  4543. temp = (SiS_Pr->SiS_VGAVT - VGAVDE) >> 1;
  4544. SiS_Pr->CVSyncStart = VGAVDE + temp;
  4545. temp >>= 3;
  4546. SiS_Pr->CVSyncEnd = SiS_Pr->CVSyncStart + temp;
  4547. SiS_CalcCRRegisters(SiS_Pr, 0);
  4548. SiS_Pr->CCRT1CRTC[16] &= ~0xE0;
  4549. for(i = 0; i <= 7; i++) {
  4550. SiS_SetReg(SiS_Pr->SiS_Part1Port,CRTranslation[i],SiS_Pr->CCRT1CRTC[i]);
  4551. }
  4552. for(i = 0x10, j = 8; i <= 0x12; i++, j++) {
  4553. SiS_SetReg(SiS_Pr->SiS_Part1Port,CRTranslation[i],SiS_Pr->CCRT1CRTC[j]);
  4554. }
  4555. for(i = 0x15, j = 11; i <= 0x16; i++, j++) {
  4556. SiS_SetReg(SiS_Pr->SiS_Part1Port,CRTranslation[i],SiS_Pr->CCRT1CRTC[j]);
  4557. }
  4558. for(i = 0x0a, j = 13; i <= 0x0c; i++, j++) {
  4559. SiS_SetReg(SiS_Pr->SiS_Part1Port,CRTranslation[i],SiS_Pr->CCRT1CRTC[j]);
  4560. }
  4561. temp = SiS_Pr->CCRT1CRTC[16] & 0xE0;
  4562. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,CRTranslation[0x0E],0x1F,temp);
  4563. temp = (SiS_Pr->CCRT1CRTC[16] & 0x01) << 5;
  4564. if(modeflag & DoubleScanMode) temp |= 0x80;
  4565. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,CRTranslation[0x09],0x5F,temp);
  4566. temp = 0;
  4567. temp |= (SiS_GetReg(SiS_Pr->SiS_P3c4,0x01) & 0x01);
  4568. if(modeflag & HalfDCLK) temp |= 0x08;
  4569. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x16,temp); /* SR01: HalfDCLK[3], 8/9 div dotclock[0] */
  4570. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0F,0x00); /* CR14: (text mode: underline location) */
  4571. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x12,0x00); /* CR17: n/a */
  4572. temp = 0;
  4573. if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) {
  4574. temp = (SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x01) << 7;
  4575. }
  4576. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1A,temp); /* SR0E, dither[7] */
  4577. temp = SiS_GetRegByte((SiS_Pr->SiS_P3ca+0x02));
  4578. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,temp); /* ? */
  4579. }
  4580. /* Setup panel link
  4581. * This is used for LVDS, LCDA and Chrontel TV output
  4582. * 300/LVDS+TV, 300/301B-DH, 315/LVDS+TV, 315/LCDA
  4583. */
  4584. static void
  4585. SiS_SetGroup1_LVDS(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  4586. unsigned short RefreshRateTableIndex)
  4587. {
  4588. unsigned short modeflag, resinfo = 0;
  4589. unsigned short push2, tempax, tempbx, tempcx, temp;
  4590. unsigned int tempeax = 0, tempebx, tempecx, tempvcfact = 0;
  4591. bool islvds = false, issis = false, chkdclkfirst = false;
  4592. #ifdef SIS300
  4593. unsigned short crt2crtc = 0;
  4594. #endif
  4595. #ifdef SIS315H
  4596. unsigned short pushcx;
  4597. #endif
  4598. if(ModeNo <= 0x13) {
  4599. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  4600. resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
  4601. #ifdef SIS300
  4602. crt2crtc = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  4603. #endif
  4604. } else if(SiS_Pr->UseCustomMode) {
  4605. modeflag = SiS_Pr->CModeFlag;
  4606. } else {
  4607. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  4608. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  4609. #ifdef SIS300
  4610. crt2crtc = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  4611. #endif
  4612. }
  4613. /* is lvds if really LVDS, or 301B-DH with external LVDS transmitter */
  4614. if((SiS_Pr->SiS_IF_DEF_LVDS == 1) || (SiS_Pr->SiS_VBType & VB_NoLCD)) {
  4615. islvds = true;
  4616. }
  4617. /* is really sis if sis bridge, but not 301B-DH */
  4618. if((SiS_Pr->SiS_VBType & VB_SISVB) && (!(SiS_Pr->SiS_VBType & VB_NoLCD))) {
  4619. issis = true;
  4620. }
  4621. if((SiS_Pr->ChipType >= SIS_315H) && (islvds) && (!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA))) {
  4622. if((!SiS_Pr->SiS_IF_DEF_FSTN) && (!SiS_Pr->SiS_IF_DEF_DSTN)) {
  4623. chkdclkfirst = true;
  4624. }
  4625. }
  4626. #ifdef SIS315H
  4627. if((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  4628. if(IS_SIS330) {
  4629. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x10);
  4630. } else if(IS_SIS740) {
  4631. if(islvds) {
  4632. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,0xfb,0x04);
  4633. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x03);
  4634. } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
  4635. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x10);
  4636. }
  4637. } else {
  4638. if(islvds) {
  4639. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,0xfb,0x04);
  4640. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x00);
  4641. } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
  4642. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2D,0x0f);
  4643. if(SiS_Pr->SiS_VBType & VB_SIS30xC) {
  4644. if((SiS_Pr->SiS_LCDResInfo == Panel_1024x768) ||
  4645. (SiS_Pr->SiS_LCDResInfo == Panel_1280x1024)) {
  4646. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2D,0x20);
  4647. }
  4648. }
  4649. }
  4650. }
  4651. }
  4652. #endif
  4653. /* Horizontal */
  4654. tempax = SiS_Pr->SiS_LCDHDES;
  4655. if(islvds) {
  4656. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4657. if(!SiS_Pr->SiS_IF_DEF_FSTN && !SiS_Pr->SiS_IF_DEF_DSTN) {
  4658. if((SiS_Pr->SiS_LCDResInfo == Panel_640x480) &&
  4659. (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode))) {
  4660. tempax -= 8;
  4661. }
  4662. }
  4663. }
  4664. }
  4665. temp = (tempax & 0x0007);
  4666. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1A,temp); /* BPLHDESKEW[2:0] */
  4667. temp = (tempax >> 3) & 0x00FF;
  4668. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x16,temp); /* BPLHDESKEW[10:3] */
  4669. tempbx = SiS_Pr->SiS_HDE;
  4670. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4671. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  4672. tempbx = SiS_Pr->PanelXRes;
  4673. }
  4674. if((SiS_Pr->SiS_LCDResInfo == Panel_320x240_1) ||
  4675. (SiS_Pr->SiS_LCDResInfo == Panel_320x240_2) ||
  4676. (SiS_Pr->SiS_LCDResInfo == Panel_320x240_3)) {
  4677. tempbx >>= 1;
  4678. }
  4679. }
  4680. tempax += tempbx;
  4681. if(tempax >= SiS_Pr->SiS_HT) tempax -= SiS_Pr->SiS_HT;
  4682. temp = tempax;
  4683. if(temp & 0x07) temp += 8;
  4684. temp >>= 3;
  4685. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x17,temp); /* BPLHDEE */
  4686. tempcx = (SiS_Pr->SiS_HT - tempbx) >> 2;
  4687. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4688. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  4689. if(SiS_Pr->PanelHRS != 999) tempcx = SiS_Pr->PanelHRS;
  4690. }
  4691. }
  4692. tempcx += tempax;
  4693. if(tempcx >= SiS_Pr->SiS_HT) tempcx -= SiS_Pr->SiS_HT;
  4694. temp = (tempcx >> 3) & 0x00FF;
  4695. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4696. if(SiS_Pr->SiS_IF_DEF_TRUMPION) {
  4697. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  4698. switch(ModeNo) {
  4699. case 0x04:
  4700. case 0x05:
  4701. case 0x0d: temp = 0x56; break;
  4702. case 0x10: temp = 0x60; break;
  4703. case 0x13: temp = 0x5f; break;
  4704. case 0x40:
  4705. case 0x41:
  4706. case 0x4f:
  4707. case 0x43:
  4708. case 0x44:
  4709. case 0x62:
  4710. case 0x56:
  4711. case 0x53:
  4712. case 0x5d:
  4713. case 0x5e: temp = 0x54; break;
  4714. }
  4715. }
  4716. }
  4717. }
  4718. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x14,temp); /* BPLHRS */
  4719. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4720. temp += 2;
  4721. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  4722. temp += 8;
  4723. if(SiS_Pr->PanelHRE != 999) {
  4724. temp = tempcx + SiS_Pr->PanelHRE;
  4725. if(temp >= SiS_Pr->SiS_HT) temp -= SiS_Pr->SiS_HT;
  4726. temp >>= 3;
  4727. }
  4728. }
  4729. } else {
  4730. temp += 10;
  4731. }
  4732. temp &= 0x1F;
  4733. temp |= ((tempcx & 0x07) << 5);
  4734. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x15,temp); /* BPLHRE */
  4735. /* Vertical */
  4736. tempax = SiS_Pr->SiS_VGAVDE;
  4737. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4738. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  4739. tempax = SiS_Pr->PanelYRes;
  4740. }
  4741. }
  4742. tempbx = SiS_Pr->SiS_LCDVDES + tempax;
  4743. if(tempbx >= SiS_Pr->SiS_VT) tempbx -= SiS_Pr->SiS_VT;
  4744. push2 = tempbx;
  4745. tempcx = SiS_Pr->SiS_VGAVT - SiS_Pr->SiS_VGAVDE;
  4746. if(SiS_Pr->ChipType < SIS_315H) {
  4747. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4748. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  4749. tempcx = SiS_Pr->SiS_VGAVT - SiS_Pr->PanelYRes;
  4750. }
  4751. }
  4752. }
  4753. if(islvds) tempcx >>= 1;
  4754. else tempcx >>= 2;
  4755. if( (SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) &&
  4756. (!(SiS_Pr->SiS_LCDInfo & LCDPass11)) &&
  4757. (SiS_Pr->PanelVRS != 999) ) {
  4758. tempcx = SiS_Pr->PanelVRS;
  4759. tempbx += tempcx;
  4760. if(issis) tempbx++;
  4761. } else {
  4762. tempbx += tempcx;
  4763. if(SiS_Pr->ChipType < SIS_315H) tempbx++;
  4764. else if(issis) tempbx++;
  4765. }
  4766. if(tempbx >= SiS_Pr->SiS_VT) tempbx -= SiS_Pr->SiS_VT;
  4767. temp = tempbx & 0x00FF;
  4768. if(SiS_Pr->SiS_IF_DEF_TRUMPION) {
  4769. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  4770. if(ModeNo == 0x10) temp = 0xa9;
  4771. }
  4772. }
  4773. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,temp); /* BPLVRS */
  4774. tempcx >>= 3;
  4775. tempcx++;
  4776. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4777. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  4778. if(SiS_Pr->PanelVRE != 999) tempcx = SiS_Pr->PanelVRE;
  4779. }
  4780. }
  4781. tempcx += tempbx;
  4782. temp = tempcx & 0x000F;
  4783. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0xF0,temp); /* BPLVRE */
  4784. temp = ((tempbx >> 8) & 0x07) << 3;
  4785. if(SiS_Pr->SiS_IF_DEF_FSTN || SiS_Pr->SiS_IF_DEF_DSTN) {
  4786. if(SiS_Pr->SiS_HDE != 640) {
  4787. if(SiS_Pr->SiS_VGAVDE != SiS_Pr->SiS_VDE) temp |= 0x40;
  4788. }
  4789. } else if(SiS_Pr->SiS_VGAVDE != SiS_Pr->SiS_VDE) temp |= 0x40;
  4790. if(SiS_Pr->SiS_SetFlag & EnableLVDSDDA) temp |= 0x40;
  4791. tempbx = 0x87;
  4792. if((SiS_Pr->ChipType >= SIS_315H) ||
  4793. (SiS_Pr->ChipRevision >= 0x30)) {
  4794. tempbx = 0x07;
  4795. if((SiS_Pr->SiS_IF_DEF_CH70xx == 1) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
  4796. if(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x03) temp |= 0x80;
  4797. }
  4798. /* Chrontel 701x operates in 24bit mode (8-8-8, 2x12bit multiplexed) via VGA2 */
  4799. if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) {
  4800. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  4801. if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x06) & 0x10) temp |= 0x80;
  4802. } else {
  4803. if(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x01) temp |= 0x80;
  4804. }
  4805. }
  4806. }
  4807. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x1A,tempbx,temp);
  4808. tempbx = push2; /* BPLVDEE */
  4809. tempcx = SiS_Pr->SiS_LCDVDES; /* BPLVDES */
  4810. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  4811. switch(SiS_Pr->SiS_LCDResInfo) {
  4812. case Panel_640x480:
  4813. tempbx = SiS_Pr->SiS_VGAVDE - 1;
  4814. tempcx = SiS_Pr->SiS_VGAVDE;
  4815. break;
  4816. case Panel_800x600:
  4817. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  4818. if(resinfo == SIS_RI_800x600) tempcx++;
  4819. }
  4820. break;
  4821. case Panel_1024x600:
  4822. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  4823. if(resinfo == SIS_RI_1024x600) tempcx++;
  4824. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  4825. if(resinfo == SIS_RI_800x600) tempcx++;
  4826. }
  4827. }
  4828. break;
  4829. case Panel_1024x768:
  4830. if(SiS_Pr->ChipType < SIS_315H) {
  4831. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  4832. if(resinfo == SIS_RI_1024x768) tempcx++;
  4833. }
  4834. }
  4835. break;
  4836. }
  4837. }
  4838. temp = ((tempbx >> 8) & 0x07) << 3;
  4839. temp |= ((tempcx >> 8) & 0x07);
  4840. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1D,temp);
  4841. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1C,tempbx);
  4842. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1B,tempcx);
  4843. /* Vertical scaling */
  4844. if(SiS_Pr->ChipType < SIS_315H) {
  4845. #ifdef SIS300 /* 300 series */
  4846. tempeax = SiS_Pr->SiS_VGAVDE << 6;
  4847. temp = (tempeax % (unsigned int)SiS_Pr->SiS_VDE);
  4848. tempeax = tempeax / (unsigned int)SiS_Pr->SiS_VDE;
  4849. if(temp) tempeax++;
  4850. if(SiS_Pr->SiS_SetFlag & EnableLVDSDDA) tempeax = 0x3F;
  4851. temp = (unsigned short)(tempeax & 0x00FF);
  4852. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1E,temp); /* BPLVCFACT */
  4853. tempvcfact = temp;
  4854. #endif /* SIS300 */
  4855. } else {
  4856. #ifdef SIS315H /* 315 series */
  4857. tempeax = SiS_Pr->SiS_VGAVDE << 18;
  4858. tempebx = SiS_Pr->SiS_VDE;
  4859. temp = (tempeax % tempebx);
  4860. tempeax = tempeax / tempebx;
  4861. if(temp) tempeax++;
  4862. tempvcfact = tempeax;
  4863. temp = (unsigned short)(tempeax & 0x00FF);
  4864. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x37,temp);
  4865. temp = (unsigned short)((tempeax & 0x00FF00) >> 8);
  4866. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x36,temp);
  4867. temp = (unsigned short)((tempeax & 0x00030000) >> 16);
  4868. if(SiS_Pr->SiS_VDE == SiS_Pr->SiS_VGAVDE) temp |= 0x04;
  4869. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x35,temp);
  4870. if(SiS_Pr->SiS_VBType & VB_SISPART4SCALER) {
  4871. temp = (unsigned short)(tempeax & 0x00FF);
  4872. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x3c,temp);
  4873. temp = (unsigned short)((tempeax & 0x00FF00) >> 8);
  4874. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x3b,temp);
  4875. temp = (unsigned short)(((tempeax & 0x00030000) >> 16) << 6);
  4876. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x3a,0x3f,temp);
  4877. temp = 0;
  4878. if(SiS_Pr->SiS_VDE != SiS_Pr->SiS_VGAVDE) temp |= 0x08;
  4879. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x30,0xf3,temp);
  4880. }
  4881. #endif
  4882. }
  4883. /* Horizontal scaling */
  4884. tempeax = SiS_Pr->SiS_VGAHDE; /* 1f = ( (VGAHDE * 65536) / ( (VGAHDE * 65536) / HDE ) ) - 1*/
  4885. if(chkdclkfirst) {
  4886. if(modeflag & HalfDCLK) tempeax >>= 1;
  4887. }
  4888. tempebx = tempeax << 16;
  4889. if(SiS_Pr->SiS_HDE == tempeax) {
  4890. tempecx = 0xFFFF;
  4891. } else {
  4892. tempecx = tempebx / SiS_Pr->SiS_HDE;
  4893. if(SiS_Pr->ChipType >= SIS_315H) {
  4894. if(tempebx % SiS_Pr->SiS_HDE) tempecx++;
  4895. }
  4896. }
  4897. if(SiS_Pr->ChipType >= SIS_315H) {
  4898. tempeax = (tempebx / tempecx) - 1;
  4899. } else {
  4900. tempeax = ((SiS_Pr->SiS_VGAHT << 16) / tempecx) - 1;
  4901. }
  4902. tempecx = (tempecx << 16) | (tempeax & 0xFFFF);
  4903. temp = (unsigned short)(tempecx & 0x00FF);
  4904. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1F,temp);
  4905. if(SiS_Pr->ChipType >= SIS_315H) {
  4906. tempeax = (SiS_Pr->SiS_VGAVDE << 18) / tempvcfact;
  4907. tempbx = (unsigned short)(tempeax & 0xFFFF);
  4908. } else {
  4909. tempeax = SiS_Pr->SiS_VGAVDE << 6;
  4910. tempbx = tempvcfact & 0x3f;
  4911. if(tempbx == 0) tempbx = 64;
  4912. tempeax /= tempbx;
  4913. tempbx = (unsigned short)(tempeax & 0xFFFF);
  4914. }
  4915. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) tempbx--;
  4916. if(SiS_Pr->SiS_SetFlag & EnableLVDSDDA) {
  4917. if((!SiS_Pr->SiS_IF_DEF_FSTN) && (!SiS_Pr->SiS_IF_DEF_DSTN)) tempbx = 1;
  4918. else if(SiS_Pr->SiS_LCDResInfo != Panel_640x480) tempbx = 1;
  4919. }
  4920. temp = ((tempbx >> 8) & 0x07) << 3;
  4921. temp = temp | ((tempecx >> 8) & 0x07);
  4922. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x20,temp);
  4923. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x21,tempbx);
  4924. tempecx >>= 16; /* BPLHCFACT */
  4925. if(!chkdclkfirst) {
  4926. if(modeflag & HalfDCLK) tempecx >>= 1;
  4927. }
  4928. temp = (unsigned short)((tempecx & 0xFF00) >> 8);
  4929. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x22,temp);
  4930. temp = (unsigned short)(tempecx & 0x00FF);
  4931. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x23,temp);
  4932. #ifdef SIS315H
  4933. if(SiS_Pr->ChipType >= SIS_315H) {
  4934. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  4935. if((islvds) || (SiS_Pr->SiS_VBInfo & VB_SISLVDS)) {
  4936. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1e,0x20);
  4937. }
  4938. } else {
  4939. if(islvds) {
  4940. if(SiS_Pr->ChipType == SIS_740) {
  4941. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1e,0x03);
  4942. } else {
  4943. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1e,0x23);
  4944. }
  4945. }
  4946. }
  4947. }
  4948. #endif
  4949. #ifdef SIS300
  4950. if(SiS_Pr->SiS_IF_DEF_TRUMPION) {
  4951. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  4952. unsigned char *trumpdata;
  4953. int i, j = crt2crtc;
  4954. unsigned char TrumpMode13[4] = { 0x01, 0x10, 0x2c, 0x00 };
  4955. unsigned char TrumpMode10_1[4] = { 0x01, 0x10, 0x27, 0x00 };
  4956. unsigned char TrumpMode10_2[4] = { 0x01, 0x16, 0x10, 0x00 };
  4957. if(SiS_Pr->SiS_UseROM) {
  4958. trumpdata = &ROMAddr[0x8001 + (j * 80)];
  4959. } else {
  4960. if(SiS_Pr->SiS_LCDTypeInfo == 0x0e) j += 7;
  4961. trumpdata = &SiS300_TrumpionData[j][0];
  4962. }
  4963. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x02,0xbf);
  4964. for(i=0; i<5; i++) {
  4965. SiS_SetTrumpionBlock(SiS_Pr, trumpdata);
  4966. }
  4967. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  4968. if(ModeNo == 0x13) {
  4969. for(i=0; i<4; i++) {
  4970. SiS_SetTrumpionBlock(SiS_Pr, &TrumpMode13[0]);
  4971. }
  4972. } else if(ModeNo == 0x10) {
  4973. for(i=0; i<4; i++) {
  4974. SiS_SetTrumpionBlock(SiS_Pr, &TrumpMode10_1[0]);
  4975. SiS_SetTrumpionBlock(SiS_Pr, &TrumpMode10_2[0]);
  4976. }
  4977. }
  4978. }
  4979. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x02,0x40);
  4980. }
  4981. #endif
  4982. #ifdef SIS315H
  4983. if(SiS_Pr->SiS_IF_DEF_FSTN || SiS_Pr->SiS_IF_DEF_DSTN) {
  4984. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x25,0x00);
  4985. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x26,0x00);
  4986. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x27,0x00);
  4987. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x28,0x87);
  4988. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x29,0x5A);
  4989. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2A,0x4B);
  4990. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x44,~0x07,0x03);
  4991. tempax = SiS_Pr->SiS_HDE; /* Blps = lcdhdee(lcdhdes+HDE) + 64 */
  4992. if(SiS_Pr->SiS_LCDResInfo == Panel_320x240_1 ||
  4993. SiS_Pr->SiS_LCDResInfo == Panel_320x240_2 ||
  4994. SiS_Pr->SiS_LCDResInfo == Panel_320x240_3) tempax >>= 1;
  4995. tempax += 64;
  4996. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x38,tempax & 0xff);
  4997. temp = (tempax >> 8) << 3;
  4998. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x35,~0x078,temp);
  4999. tempax += 32; /* Blpe = lBlps+32 */
  5000. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x39,tempax & 0xff);
  5001. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3A,0x00); /* Bflml = 0 */
  5002. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x3C,~0x007);
  5003. tempax = SiS_Pr->SiS_VDE;
  5004. if(SiS_Pr->SiS_LCDResInfo == Panel_320x240_1 ||
  5005. SiS_Pr->SiS_LCDResInfo == Panel_320x240_2 ||
  5006. SiS_Pr->SiS_LCDResInfo == Panel_320x240_3) tempax >>= 1;
  5007. tempax >>= 1;
  5008. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3B,tempax & 0xff);
  5009. temp = (tempax >> 8) << 3;
  5010. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x3C,~0x038,temp);
  5011. tempeax = SiS_Pr->SiS_HDE;
  5012. if(SiS_Pr->SiS_LCDResInfo == Panel_320x240_1 ||
  5013. SiS_Pr->SiS_LCDResInfo == Panel_320x240_2 ||
  5014. SiS_Pr->SiS_LCDResInfo == Panel_320x240_3) tempeax >>= 1;
  5015. tempeax <<= 2; /* BDxFIFOSTOP = (HDE*4)/128 */
  5016. temp = tempeax & 0x7f;
  5017. tempeax >>= 7;
  5018. if(temp) tempeax++;
  5019. temp = tempeax & 0x3f;
  5020. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x45,temp);
  5021. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3F,0x00); /* BDxWadrst0 */
  5022. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3E,0x00);
  5023. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3D,0x10);
  5024. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x3C,~0x040);
  5025. tempax = SiS_Pr->SiS_HDE;
  5026. if(SiS_Pr->SiS_LCDResInfo == Panel_320x240_1 ||
  5027. SiS_Pr->SiS_LCDResInfo == Panel_320x240_2 ||
  5028. SiS_Pr->SiS_LCDResInfo == Panel_320x240_3) tempax >>= 1;
  5029. tempax >>= 4; /* BDxWadroff = HDE*4/8/8 */
  5030. pushcx = tempax;
  5031. temp = tempax & 0x00FF;
  5032. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x43,temp);
  5033. temp = ((tempax & 0xFF00) >> 8) << 3;
  5034. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x44,~0x0F8,temp);
  5035. tempax = SiS_Pr->SiS_VDE; /* BDxWadrst1 = BDxWadrst0 + BDxWadroff * VDE */
  5036. if(SiS_Pr->SiS_LCDResInfo == Panel_320x240_1 ||
  5037. SiS_Pr->SiS_LCDResInfo == Panel_320x240_2 ||
  5038. SiS_Pr->SiS_LCDResInfo == Panel_320x240_3) tempax >>= 1;
  5039. tempeax = tempax * pushcx;
  5040. temp = tempeax & 0xFF;
  5041. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x42,temp);
  5042. temp = (tempeax & 0xFF00) >> 8;
  5043. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x41,temp);
  5044. temp = ((tempeax & 0xFF0000) >> 16) | 0x10;
  5045. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x40,temp);
  5046. temp = ((tempeax & 0x01000000) >> 24) << 7;
  5047. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x3C,~0x080,temp);
  5048. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2F,0x03);
  5049. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x03,0x50);
  5050. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x04,0x00);
  5051. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2F,0x01);
  5052. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x19,0x38);
  5053. if(SiS_Pr->SiS_IF_DEF_FSTN) {
  5054. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2b,0x02);
  5055. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2c,0x00);
  5056. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2d,0x00);
  5057. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x35,0x0c);
  5058. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x36,0x00);
  5059. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x37,0x00);
  5060. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x38,0x80);
  5061. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x39,0xA0);
  5062. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3a,0x00);
  5063. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3b,0xf0);
  5064. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3c,0x00);
  5065. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3d,0x10);
  5066. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3e,0x00);
  5067. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x3f,0x00);
  5068. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x40,0x10);
  5069. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x41,0x25);
  5070. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x42,0x80);
  5071. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x43,0x14);
  5072. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x44,0x03);
  5073. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x45,0x0a);
  5074. }
  5075. }
  5076. #endif /* SIS315H */
  5077. }
  5078. /* Set Part 1 */
  5079. static void
  5080. SiS_SetGroup1(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  5081. unsigned short RefreshRateTableIndex)
  5082. {
  5083. #if defined(SIS300) || defined(SIS315H)
  5084. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  5085. #endif
  5086. unsigned short temp=0, tempax=0, tempbx=0, tempcx=0, bridgeadd=0;
  5087. unsigned short pushbx=0, CRT1Index=0, modeflag, resinfo=0;
  5088. #ifdef SIS315H
  5089. unsigned short tempbl=0;
  5090. #endif
  5091. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  5092. SiS_SetGroup1_LVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  5093. return;
  5094. }
  5095. if(ModeNo <= 0x13) {
  5096. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  5097. } else if(SiS_Pr->UseCustomMode) {
  5098. modeflag = SiS_Pr->CModeFlag;
  5099. } else {
  5100. CRT1Index = SiS_GetRefCRT1CRTC(SiS_Pr, RefreshRateTableIndex, SiS_Pr->SiS_UseWideCRT2);
  5101. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  5102. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  5103. }
  5104. SiS_SetCRT2Offset(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  5105. if( ! ((SiS_Pr->ChipType >= SIS_315H) &&
  5106. (SiS_Pr->SiS_IF_DEF_LVDS == 1) &&
  5107. (SiS_Pr->SiS_VBInfo & SetInSlaveMode)) ) {
  5108. if(SiS_Pr->ChipType < SIS_315H ) {
  5109. #ifdef SIS300
  5110. SiS_SetCRT2FIFO_300(SiS_Pr, ModeNo);
  5111. #endif
  5112. } else {
  5113. #ifdef SIS315H
  5114. SiS_SetCRT2FIFO_310(SiS_Pr);
  5115. #endif
  5116. }
  5117. /* 1. Horizontal setup */
  5118. if(SiS_Pr->ChipType < SIS_315H ) {
  5119. #ifdef SIS300 /* ------------- 300 series --------------*/
  5120. temp = (SiS_Pr->SiS_VGAHT - 1) & 0x0FF; /* BTVGA2HT 0x08,0x09 */
  5121. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x08,temp); /* CRT2 Horizontal Total */
  5122. temp = (((SiS_Pr->SiS_VGAHT - 1) & 0xFF00) >> 8) << 4;
  5123. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x09,0x0f,temp); /* CRT2 Horizontal Total Overflow [7:4] */
  5124. temp = (SiS_Pr->SiS_VGAHDE + 12) & 0x0FF; /* BTVGA2HDEE 0x0A,0x0C */
  5125. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0A,temp); /* CRT2 Horizontal Display Enable End */
  5126. pushbx = SiS_Pr->SiS_VGAHDE + 12; /* bx BTVGA2HRS 0x0B,0x0C */
  5127. tempcx = (SiS_Pr->SiS_VGAHT - SiS_Pr->SiS_VGAHDE) >> 2;
  5128. tempbx = pushbx + tempcx;
  5129. tempcx <<= 1;
  5130. tempcx += tempbx;
  5131. bridgeadd = 12;
  5132. #endif /* SIS300 */
  5133. } else {
  5134. #ifdef SIS315H /* ------------------- 315/330 series --------------- */
  5135. tempcx = SiS_Pr->SiS_VGAHT; /* BTVGA2HT 0x08,0x09 */
  5136. if(modeflag & HalfDCLK) {
  5137. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  5138. tempcx >>= 1;
  5139. } else {
  5140. tempax = SiS_Pr->SiS_VGAHDE >> 1;
  5141. tempcx = SiS_Pr->SiS_HT - SiS_Pr->SiS_HDE + tempax;
  5142. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  5143. tempcx = SiS_Pr->SiS_HT - tempax;
  5144. }
  5145. }
  5146. }
  5147. tempcx--;
  5148. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x08,tempcx); /* CRT2 Horizontal Total */
  5149. temp = (tempcx >> 4) & 0xF0;
  5150. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x09,0x0F,temp); /* CRT2 Horizontal Total Overflow [7:4] */
  5151. tempcx = SiS_Pr->SiS_VGAHT; /* BTVGA2HDEE 0x0A,0x0C */
  5152. tempbx = SiS_Pr->SiS_VGAHDE;
  5153. tempcx -= tempbx;
  5154. tempcx >>= 2;
  5155. if(modeflag & HalfDCLK) {
  5156. tempbx >>= 1;
  5157. tempcx >>= 1;
  5158. }
  5159. tempbx += 16;
  5160. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0A,tempbx); /* CRT2 Horizontal Display Enable End */
  5161. pushbx = tempbx;
  5162. tempcx >>= 1;
  5163. tempbx += tempcx;
  5164. tempcx += tempbx;
  5165. bridgeadd = 16;
  5166. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  5167. if(SiS_Pr->ChipType >= SIS_661) {
  5168. if((SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) ||
  5169. (SiS_Pr->SiS_LCDResInfo == Panel_1280x1024)) {
  5170. if(resinfo == SIS_RI_1280x1024) {
  5171. tempcx = (tempcx & 0xff00) | 0x30;
  5172. } else if(resinfo == SIS_RI_1600x1200) {
  5173. tempcx = (tempcx & 0xff00) | 0xff;
  5174. }
  5175. }
  5176. }
  5177. }
  5178. #endif /* SIS315H */
  5179. } /* 315/330 series */
  5180. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  5181. if(SiS_Pr->UseCustomMode) {
  5182. tempbx = SiS_Pr->CHSyncStart + bridgeadd;
  5183. tempcx = SiS_Pr->CHSyncEnd + bridgeadd;
  5184. tempax = SiS_Pr->SiS_VGAHT;
  5185. if(modeflag & HalfDCLK) tempax >>= 1;
  5186. tempax--;
  5187. if(tempcx > tempax) tempcx = tempax;
  5188. }
  5189. if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) {
  5190. unsigned char cr4, cr14, cr5, cr15;
  5191. if(SiS_Pr->UseCustomMode) {
  5192. cr4 = SiS_Pr->CCRT1CRTC[4];
  5193. cr14 = SiS_Pr->CCRT1CRTC[14];
  5194. cr5 = SiS_Pr->CCRT1CRTC[5];
  5195. cr15 = SiS_Pr->CCRT1CRTC[15];
  5196. } else {
  5197. cr4 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[4];
  5198. cr14 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[14];
  5199. cr5 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[5];
  5200. cr15 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[15];
  5201. }
  5202. tempbx = ((cr4 | ((cr14 & 0xC0) << 2)) - 3) << 3; /* (VGAHRS-3)*8 */
  5203. tempcx = (((cr5 & 0x1f) | ((cr15 & 0x04) << (5-2))) - 3) << 3; /* (VGAHRE-3)*8 */
  5204. tempcx &= 0x00FF;
  5205. tempcx |= (tempbx & 0xFF00);
  5206. tempbx += bridgeadd;
  5207. tempcx += bridgeadd;
  5208. tempax = SiS_Pr->SiS_VGAHT;
  5209. if(modeflag & HalfDCLK) tempax >>= 1;
  5210. tempax--;
  5211. if(tempcx > tempax) tempcx = tempax;
  5212. }
  5213. if(SiS_Pr->SiS_TVMode & (TVSetNTSC1024 | TVSet525p1024)) {
  5214. tempbx = 1040;
  5215. tempcx = 1044; /* HWCursor bug! */
  5216. }
  5217. }
  5218. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0B,tempbx); /* CRT2 Horizontal Retrace Start */
  5219. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0D,tempcx); /* CRT2 Horizontal Retrace End */
  5220. temp = ((tempbx >> 8) & 0x0F) | ((pushbx >> 4) & 0xF0);
  5221. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0C,temp); /* Overflow */
  5222. /* 2. Vertical setup */
  5223. tempcx = SiS_Pr->SiS_VGAVT - 1;
  5224. temp = tempcx & 0x00FF;
  5225. if(SiS_Pr->ChipType < SIS_661) {
  5226. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  5227. if(SiS_Pr->ChipType < SIS_315H) {
  5228. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  5229. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToSVIDEO | SetCRT2ToAVIDEO)) {
  5230. temp--;
  5231. }
  5232. }
  5233. } else {
  5234. temp--;
  5235. }
  5236. } else if(SiS_Pr->ChipType >= SIS_315H) {
  5237. temp--;
  5238. }
  5239. }
  5240. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0E,temp); /* CRT2 Vertical Total */
  5241. tempbx = SiS_Pr->SiS_VGAVDE - 1;
  5242. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x0F,tempbx); /* CRT2 Vertical Display Enable End */
  5243. temp = ((tempbx >> 5) & 0x38) | ((tempcx >> 8) & 0x07);
  5244. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x12,temp); /* Overflow */
  5245. if((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->ChipType < SIS_661)) {
  5246. tempbx++;
  5247. tempax = tempbx;
  5248. tempcx++;
  5249. tempcx -= tempax;
  5250. tempcx >>= 2;
  5251. tempbx += tempcx;
  5252. if(tempcx < 4) tempcx = 4;
  5253. tempcx >>= 2;
  5254. tempcx += tempbx;
  5255. tempcx++;
  5256. } else {
  5257. tempbx = (SiS_Pr->SiS_VGAVT + SiS_Pr->SiS_VGAVDE) >> 1; /* BTVGA2VRS 0x10,0x11 */
  5258. tempcx = ((SiS_Pr->SiS_VGAVT - SiS_Pr->SiS_VGAVDE) >> 4) + tempbx + 1; /* BTVGA2VRE 0x11 */
  5259. }
  5260. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  5261. if(SiS_Pr->UseCustomMode) {
  5262. tempbx = SiS_Pr->CVSyncStart;
  5263. tempcx = SiS_Pr->CVSyncEnd;
  5264. }
  5265. if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) {
  5266. unsigned char cr8, cr7, cr13;
  5267. if(SiS_Pr->UseCustomMode) {
  5268. cr8 = SiS_Pr->CCRT1CRTC[8];
  5269. cr7 = SiS_Pr->CCRT1CRTC[7];
  5270. cr13 = SiS_Pr->CCRT1CRTC[13];
  5271. tempcx = SiS_Pr->CCRT1CRTC[9];
  5272. } else {
  5273. cr8 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[8];
  5274. cr7 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[7];
  5275. cr13 = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[13];
  5276. tempcx = SiS_Pr->SiS_CRT1Table[CRT1Index].CR[9];
  5277. }
  5278. tempbx = cr8;
  5279. if(cr7 & 0x04) tempbx |= 0x0100;
  5280. if(cr7 & 0x80) tempbx |= 0x0200;
  5281. if(cr13 & 0x08) tempbx |= 0x0400;
  5282. }
  5283. }
  5284. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x10,tempbx); /* CRT2 Vertical Retrace Start */
  5285. temp = ((tempbx >> 4) & 0x70) | (tempcx & 0x0F);
  5286. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x11,temp); /* CRT2 Vert. Retrace End; Overflow */
  5287. /* 3. Panel delay compensation */
  5288. if(SiS_Pr->ChipType < SIS_315H) {
  5289. #ifdef SIS300 /* ---------- 300 series -------------- */
  5290. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  5291. temp = 0x20;
  5292. if(SiS_Pr->ChipType == SIS_300) {
  5293. temp = 0x10;
  5294. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) temp = 0x2c;
  5295. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) temp = 0x20;
  5296. }
  5297. if(SiS_Pr->SiS_VBType & VB_SIS301) {
  5298. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) temp = 0x20;
  5299. }
  5300. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x960) temp = 0x24;
  5301. if(SiS_Pr->SiS_LCDResInfo == Panel_Custom) temp = 0x2c;
  5302. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) temp = 0x08;
  5303. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  5304. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) temp = 0x2c;
  5305. else temp = 0x20;
  5306. }
  5307. if(SiS_Pr->SiS_UseROM) {
  5308. if(ROMAddr[0x220] & 0x80) {
  5309. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoYPbPrHiVision)
  5310. temp = ROMAddr[0x221];
  5311. else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision)
  5312. temp = ROMAddr[0x222];
  5313. else if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024)
  5314. temp = ROMAddr[0x223];
  5315. else
  5316. temp = ROMAddr[0x224];
  5317. }
  5318. }
  5319. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  5320. if(SiS_Pr->PDC != -1) temp = SiS_Pr->PDC;
  5321. }
  5322. } else {
  5323. temp = 0x20;
  5324. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
  5325. if(SiS_Pr->SiS_LCDResInfo == Panel_640x480) temp = 0x04;
  5326. }
  5327. if(SiS_Pr->SiS_UseROM) {
  5328. if(ROMAddr[0x220] & 0x80) {
  5329. temp = ROMAddr[0x220];
  5330. }
  5331. }
  5332. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  5333. if(SiS_Pr->PDC != -1) temp = SiS_Pr->PDC;
  5334. }
  5335. }
  5336. temp &= 0x3c;
  5337. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,~0x3C,temp); /* Panel Link Delay Compensation; (Software Command Reset; Power Saving) */
  5338. #endif /* SIS300 */
  5339. } else {
  5340. #ifdef SIS315H /* --------------- 315/330 series ---------------*/
  5341. if(SiS_Pr->ChipType < SIS_661) {
  5342. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  5343. if(SiS_Pr->ChipType == SIS_740) temp = 0x03;
  5344. else temp = 0x00;
  5345. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) temp = 0x0a;
  5346. tempbl = 0xF0;
  5347. if(SiS_Pr->ChipType == SIS_650) {
  5348. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  5349. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) tempbl = 0x0F;
  5350. }
  5351. }
  5352. if(SiS_Pr->SiS_IF_DEF_DSTN || SiS_Pr->SiS_IF_DEF_FSTN) {
  5353. temp = 0x08;
  5354. tempbl = 0;
  5355. if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
  5356. if(ROMAddr[0x13c] & 0x80) tempbl = 0xf0;
  5357. }
  5358. }
  5359. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,tempbl,temp); /* Panel Link Delay Compensation */
  5360. }
  5361. } /* < 661 */
  5362. tempax = 0;
  5363. if(modeflag & DoubleScanMode) tempax |= 0x80;
  5364. if(modeflag & HalfDCLK) tempax |= 0x40;
  5365. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2C,0x3f,tempax);
  5366. #endif /* SIS315H */
  5367. }
  5368. } /* Slavemode */
  5369. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  5370. if((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) {
  5371. /* For 301BDH with LCD, we set up the Panel Link */
  5372. SiS_SetGroup1_LVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  5373. } else if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  5374. SiS_SetGroup1_301(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  5375. }
  5376. } else {
  5377. if(SiS_Pr->ChipType < SIS_315H) {
  5378. SiS_SetGroup1_LVDS(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  5379. } else {
  5380. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  5381. if((!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) || (SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  5382. SiS_SetGroup1_LVDS(SiS_Pr, ModeNo,ModeIdIndex,RefreshRateTableIndex);
  5383. }
  5384. } else {
  5385. SiS_SetGroup1_LVDS(SiS_Pr, ModeNo,ModeIdIndex,RefreshRateTableIndex);
  5386. }
  5387. }
  5388. }
  5389. }
  5390. /*********************************************/
  5391. /* SET PART 2 REGISTER GROUP */
  5392. /*********************************************/
  5393. #ifdef SIS315H
  5394. static unsigned char *
  5395. SiS_GetGroup2CLVXPtr(struct SiS_Private *SiS_Pr, int tabletype)
  5396. {
  5397. const unsigned char *tableptr = NULL;
  5398. unsigned short a, b, p = 0;
  5399. a = SiS_Pr->SiS_VGAHDE;
  5400. b = SiS_Pr->SiS_HDE;
  5401. if(tabletype) {
  5402. a = SiS_Pr->SiS_VGAVDE;
  5403. b = SiS_Pr->SiS_VDE;
  5404. }
  5405. if(a < b) {
  5406. tableptr = SiS_Part2CLVX_1;
  5407. } else if(a == b) {
  5408. tableptr = SiS_Part2CLVX_2;
  5409. } else {
  5410. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  5411. tableptr = SiS_Part2CLVX_4;
  5412. } else {
  5413. tableptr = SiS_Part2CLVX_3;
  5414. }
  5415. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  5416. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525i) tableptr = SiS_Part2CLVX_3;
  5417. else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) tableptr = SiS_Part2CLVX_3;
  5418. else tableptr = SiS_Part2CLVX_5;
  5419. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  5420. tableptr = SiS_Part2CLVX_6;
  5421. }
  5422. do {
  5423. if((tableptr[p] | tableptr[p+1] << 8) == a) break;
  5424. p += 0x42;
  5425. } while((tableptr[p] | tableptr[p+1] << 8) != 0xffff);
  5426. if((tableptr[p] | tableptr[p+1] << 8) == 0xffff) p -= 0x42;
  5427. }
  5428. p += 2;
  5429. return ((unsigned char *)&tableptr[p]);
  5430. }
  5431. static void
  5432. SiS_SetGroup2_C_ELV(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  5433. unsigned short RefreshRateTableIndex)
  5434. {
  5435. unsigned char *tableptr;
  5436. unsigned char temp;
  5437. int i, j;
  5438. if(!(SiS_Pr->SiS_VBType & VB_SISTAP4SCALER)) return;
  5439. tableptr = SiS_GetGroup2CLVXPtr(SiS_Pr, 0);
  5440. for(i = 0x80, j = 0; i <= 0xbf; i++, j++) {
  5441. SiS_SetReg(SiS_Pr->SiS_Part2Port, i, tableptr[j]);
  5442. }
  5443. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  5444. tableptr = SiS_GetGroup2CLVXPtr(SiS_Pr, 1);
  5445. for(i = 0xc0, j = 0; i <= 0xff; i++, j++) {
  5446. SiS_SetReg(SiS_Pr->SiS_Part2Port, i, tableptr[j]);
  5447. }
  5448. }
  5449. temp = 0x10;
  5450. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) temp |= 0x04;
  5451. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x4e,0xeb,temp);
  5452. }
  5453. static bool
  5454. SiS_GetCRT2Part2Ptr(struct SiS_Private *SiS_Pr,unsigned short ModeNo,unsigned short ModeIdIndex,
  5455. unsigned short RefreshRateTableIndex,unsigned short *CRT2Index,
  5456. unsigned short *ResIndex)
  5457. {
  5458. if(SiS_Pr->ChipType < SIS_315H) return false;
  5459. if(ModeNo <= 0x13)
  5460. (*ResIndex) = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  5461. else
  5462. (*ResIndex) = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  5463. (*ResIndex) &= 0x3f;
  5464. (*CRT2Index) = 0;
  5465. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  5466. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
  5467. (*CRT2Index) = 200;
  5468. }
  5469. }
  5470. if(SiS_Pr->SiS_CustomT == CUT_ASUSA2H_2) {
  5471. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  5472. if(SiS_Pr->SiS_SetFlag & LCDVESATiming) (*CRT2Index) = 206;
  5473. }
  5474. }
  5475. return (((*CRT2Index) != 0));
  5476. }
  5477. #endif
  5478. #ifdef SIS300
  5479. static void
  5480. SiS_Group2LCDSpecial(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short crt2crtc)
  5481. {
  5482. unsigned short tempcx;
  5483. static const unsigned char atable[] = {
  5484. 0xc3,0x9e,0xc3,0x9e,0x02,0x02,0x02,
  5485. 0xab,0x87,0xab,0x9e,0xe7,0x02,0x02
  5486. };
  5487. if(!SiS_Pr->UseCustomMode) {
  5488. if( ( ( (SiS_Pr->ChipType == SIS_630) ||
  5489. (SiS_Pr->ChipType == SIS_730) ) &&
  5490. (SiS_Pr->ChipRevision > 2) ) &&
  5491. (SiS_Pr->SiS_LCDResInfo == Panel_1024x768) &&
  5492. (!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) &&
  5493. (!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) ) {
  5494. if(ModeNo == 0x13) {
  5495. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,0xB9);
  5496. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x05,0xCC);
  5497. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x06,0xA6);
  5498. } else if((crt2crtc & 0x3F) == 4) {
  5499. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x2B);
  5500. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x13);
  5501. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,0xE5);
  5502. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x05,0x08);
  5503. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x06,0xE2);
  5504. }
  5505. }
  5506. if(SiS_Pr->ChipType < SIS_315H) {
  5507. if(SiS_Pr->SiS_LCDTypeInfo == 0x0c) {
  5508. crt2crtc &= 0x1f;
  5509. tempcx = 0;
  5510. if(!(SiS_Pr->SiS_VBInfo & SetNotSimuMode)) {
  5511. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  5512. tempcx += 7;
  5513. }
  5514. }
  5515. tempcx += crt2crtc;
  5516. if(crt2crtc >= 4) {
  5517. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x06,0xff);
  5518. }
  5519. if(!(SiS_Pr->SiS_VBInfo & SetNotSimuMode)) {
  5520. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  5521. if(crt2crtc == 4) {
  5522. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x28);
  5523. }
  5524. }
  5525. }
  5526. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x18);
  5527. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,atable[tempcx]);
  5528. }
  5529. }
  5530. }
  5531. }
  5532. /* For ECS A907. Highly preliminary. */
  5533. static void
  5534. SiS_Set300Part2Regs(struct SiS_Private *SiS_Pr, unsigned short ModeIdIndex, unsigned short RefreshRateTableIndex,
  5535. unsigned short ModeNo)
  5536. {
  5537. const struct SiS_Part2PortTbl *CRT2Part2Ptr = NULL;
  5538. unsigned short crt2crtc, resindex;
  5539. int i, j;
  5540. if(SiS_Pr->ChipType != SIS_300) return;
  5541. if(!(SiS_Pr->SiS_VBType & VB_SIS30xBLV)) return;
  5542. if(SiS_Pr->UseCustomMode) return;
  5543. if(ModeNo <= 0x13) {
  5544. crt2crtc = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  5545. } else {
  5546. crt2crtc = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  5547. }
  5548. resindex = crt2crtc & 0x3F;
  5549. if(SiS_Pr->SiS_SetFlag & LCDVESATiming) CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1024x768_1;
  5550. else CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1024x768_2;
  5551. /* The BIOS code (1.16.51,56) is obviously a fragment! */
  5552. if(ModeNo > 0x13) {
  5553. CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1024x768_1;
  5554. resindex = 4;
  5555. }
  5556. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x01,0x80,(CRT2Part2Ptr+resindex)->CR[0]);
  5557. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x02,0x80,(CRT2Part2Ptr+resindex)->CR[1]);
  5558. for(i = 2, j = 0x04; j <= 0x06; i++, j++ ) {
  5559. SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]);
  5560. }
  5561. for(j = 0x1c; j <= 0x1d; i++, j++ ) {
  5562. SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]);
  5563. }
  5564. for(j = 0x1f; j <= 0x21; i++, j++ ) {
  5565. SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]);
  5566. }
  5567. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x23,(CRT2Part2Ptr+resindex)->CR[10]);
  5568. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x25,0x0f,(CRT2Part2Ptr+resindex)->CR[11]);
  5569. }
  5570. #endif
  5571. static void
  5572. SiS_SetTVSpecial(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
  5573. {
  5574. if(!(SiS_Pr->SiS_VBType & VB_SIS30xBLV)) return;
  5575. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoHiVision)) return;
  5576. if(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p)) return;
  5577. if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) {
  5578. if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) {
  5579. const unsigned char specialtv[] = {
  5580. 0xa7,0x07,0xf2,0x6e,0x17,0x8b,0x73,0x53,
  5581. 0x13,0x40,0x34,0xf4,0x63,0xbb,0xcc,0x7a,
  5582. 0x58,0xe4,0x73,0xda,0x13
  5583. };
  5584. int i, j;
  5585. for(i = 0x1c, j = 0; i <= 0x30; i++, j++) {
  5586. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,specialtv[j]);
  5587. }
  5588. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x43,0x72);
  5589. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750)) {
  5590. if(SiS_Pr->SiS_TVMode & TVSetPALM) {
  5591. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x14);
  5592. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x1b);
  5593. } else {
  5594. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x14); /* 15 */
  5595. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x1a); /* 1b */
  5596. }
  5597. }
  5598. }
  5599. } else {
  5600. if((ModeNo == 0x38) || (ModeNo == 0x4a) || (ModeNo == 0x64) ||
  5601. (ModeNo == 0x52) || (ModeNo == 0x58) || (ModeNo == 0x5c)) {
  5602. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x1b); /* 21 */
  5603. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x54); /* 5a */
  5604. } else {
  5605. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x1a); /* 21 */
  5606. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x53); /* 5a */
  5607. }
  5608. }
  5609. }
  5610. static void
  5611. SiS_SetGroup2_Tail(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
  5612. {
  5613. unsigned short temp;
  5614. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) {
  5615. if(SiS_Pr->SiS_VGAVDE == 525) {
  5616. temp = 0xc3;
  5617. if(SiS_Pr->SiS_ModeType <= ModeVGA) {
  5618. temp++;
  5619. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) temp += 2;
  5620. }
  5621. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2f,temp);
  5622. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x30,0xb3);
  5623. } else if(SiS_Pr->SiS_VGAVDE == 420) {
  5624. temp = 0x4d;
  5625. if(SiS_Pr->SiS_ModeType <= ModeVGA) {
  5626. temp++;
  5627. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) temp++;
  5628. }
  5629. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2f,temp);
  5630. }
  5631. }
  5632. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  5633. if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) {
  5634. if(SiS_Pr->SiS_VBType & VB_SIS30xB) {
  5635. SiS_SetRegOR(SiS_Pr->SiS_Part2Port,0x1a,0x03);
  5636. /* Not always for LV, see SetGrp2 */
  5637. }
  5638. temp = 1;
  5639. if(ModeNo <= 0x13) temp = 3;
  5640. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x0b,temp);
  5641. }
  5642. #if 0
  5643. /* 651+301C, for 1280x768 - do I really need that? */
  5644. if((SiS_Pr->SiS_PanelXRes == 1280) && (SiS_Pr->SiS_PanelYRes == 768)) {
  5645. if(SiS_Pr->SiS_VBInfo & SetSimuScanMode) {
  5646. if(((SiS_Pr->SiS_HDE == 640) && (SiS_Pr->SiS_VDE == 480)) ||
  5647. ((SiS_Pr->SiS_HDE == 320) && (SiS_Pr->SiS_VDE == 240))) {
  5648. SiS_SetReg(SiS_Part2Port,0x01,0x2b);
  5649. SiS_SetReg(SiS_Part2Port,0x02,0x13);
  5650. SiS_SetReg(SiS_Part2Port,0x04,0xe5);
  5651. SiS_SetReg(SiS_Part2Port,0x05,0x08);
  5652. SiS_SetReg(SiS_Part2Port,0x06,0xe2);
  5653. SiS_SetReg(SiS_Part2Port,0x1c,0x21);
  5654. SiS_SetReg(SiS_Part2Port,0x1d,0x45);
  5655. SiS_SetReg(SiS_Part2Port,0x1f,0x0b);
  5656. SiS_SetReg(SiS_Part2Port,0x20,0x00);
  5657. SiS_SetReg(SiS_Part2Port,0x21,0xa9);
  5658. SiS_SetReg(SiS_Part2Port,0x23,0x0b);
  5659. SiS_SetReg(SiS_Part2Port,0x25,0x04);
  5660. }
  5661. }
  5662. }
  5663. #endif
  5664. }
  5665. }
  5666. static void
  5667. SiS_SetGroup2(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  5668. unsigned short RefreshRateTableIndex)
  5669. {
  5670. unsigned short i, j, tempax, tempbx, tempcx, tempch, tempcl, temp;
  5671. unsigned short push2, modeflag, crt2crtc, bridgeoffset;
  5672. unsigned int longtemp, PhaseIndex;
  5673. bool newtvphase;
  5674. const unsigned char *TimingPoint;
  5675. #ifdef SIS315H
  5676. unsigned short resindex, CRT2Index;
  5677. const struct SiS_Part2PortTbl *CRT2Part2Ptr = NULL;
  5678. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) return;
  5679. #endif
  5680. if(ModeNo <= 0x13) {
  5681. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  5682. crt2crtc = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  5683. } else if(SiS_Pr->UseCustomMode) {
  5684. modeflag = SiS_Pr->CModeFlag;
  5685. crt2crtc = 0;
  5686. } else {
  5687. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  5688. crt2crtc = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  5689. }
  5690. temp = 0;
  5691. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToAVIDEO)) temp |= 0x08;
  5692. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToSVIDEO)) temp |= 0x04;
  5693. if(SiS_Pr->SiS_VBInfo & SetCRT2ToSCART) temp |= 0x02;
  5694. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) temp |= 0x01;
  5695. if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) temp |= 0x10;
  5696. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x00,temp);
  5697. PhaseIndex = 0x01; /* SiS_PALPhase */
  5698. TimingPoint = SiS_Pr->SiS_PALTiming;
  5699. newtvphase = false;
  5700. if( (SiS_Pr->SiS_VBType & VB_SIS30xBLV) &&
  5701. ( (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) ||
  5702. (SiS_Pr->SiS_TVMode & TVSetTVSimuMode) ) ) {
  5703. newtvphase = true;
  5704. }
  5705. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  5706. TimingPoint = SiS_Pr->SiS_HiTVExtTiming;
  5707. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  5708. TimingPoint = SiS_Pr->SiS_HiTVSt2Timing;
  5709. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) {
  5710. TimingPoint = SiS_Pr->SiS_HiTVSt1Timing;
  5711. }
  5712. }
  5713. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  5714. i = 0;
  5715. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) i = 2;
  5716. else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) i = 1;
  5717. TimingPoint = &SiS_YPbPrTable[i][0];
  5718. PhaseIndex = 0x00; /* SiS_NTSCPhase */
  5719. } else if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  5720. if(newtvphase) PhaseIndex = 0x09; /* SiS_PALPhase2 */
  5721. } else {
  5722. TimingPoint = SiS_Pr->SiS_NTSCTiming;
  5723. PhaseIndex = (SiS_Pr->SiS_TVMode & TVSetNTSCJ) ? 0x01 : 0x00; /* SiS_PALPhase : SiS_NTSCPhase */
  5724. if(newtvphase) PhaseIndex += 8; /* SiS_PALPhase2 : SiS_NTSCPhase2 */
  5725. }
  5726. if(SiS_Pr->SiS_TVMode & (TVSetPALM | TVSetPALN)) {
  5727. PhaseIndex = (SiS_Pr->SiS_TVMode & TVSetPALM) ? 0x02 : 0x03; /* SiS_PALMPhase : SiS_PALNPhase */
  5728. if(newtvphase) PhaseIndex += 8; /* SiS_PALMPhase2 : SiS_PALNPhase2 */
  5729. }
  5730. if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) {
  5731. if(SiS_Pr->SiS_TVMode & TVSetPALM) {
  5732. PhaseIndex = 0x05; /* SiS_SpecialPhaseM */
  5733. } else if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) {
  5734. PhaseIndex = 0x11; /* SiS_SpecialPhaseJ */
  5735. } else {
  5736. PhaseIndex = 0x10; /* SiS_SpecialPhase */
  5737. }
  5738. }
  5739. for(i = 0x31, j = 0; i <= 0x34; i++, j++) {
  5740. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS_TVPhase[(PhaseIndex * 4) + j]);
  5741. }
  5742. for(i = 0x01, j = 0; i <= 0x2D; i++, j++) {
  5743. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,TimingPoint[j]);
  5744. }
  5745. for(i = 0x39; i <= 0x45; i++, j++) {
  5746. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,TimingPoint[j]);
  5747. }
  5748. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  5749. if(SiS_Pr->SiS_ModeType != ModeText) {
  5750. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x3A,0x1F);
  5751. }
  5752. }
  5753. SiS_SetRegOR(SiS_Pr->SiS_Part2Port,0x0A,SiS_Pr->SiS_NewFlickerMode);
  5754. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x35,SiS_Pr->SiS_RY1COE);
  5755. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x36,SiS_Pr->SiS_RY2COE);
  5756. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x37,SiS_Pr->SiS_RY3COE);
  5757. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x38,SiS_Pr->SiS_RY4COE);
  5758. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) tempax = 950;
  5759. else if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) tempax = 680;
  5760. else if(SiS_Pr->SiS_TVMode & TVSetPAL) tempax = 520;
  5761. else tempax = 440; /* NTSC, YPbPr 525 */
  5762. if( ((SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) && (SiS_Pr->SiS_VDE <= tempax)) ||
  5763. ( (SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoHiVision) &&
  5764. ((SiS_Pr->SiS_VGAHDE == 1024) || (SiS_Pr->SiS_VDE <= tempax)) ) ) {
  5765. tempax -= SiS_Pr->SiS_VDE;
  5766. tempax >>= 1;
  5767. if(!(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p))) {
  5768. tempax >>= 1;
  5769. }
  5770. tempax &= 0x00ff;
  5771. temp = tempax + (unsigned short)TimingPoint[0];
  5772. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,temp);
  5773. temp = tempax + (unsigned short)TimingPoint[1];
  5774. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,temp);
  5775. if((SiS_Pr->SiS_VBInfo & SetCRT2ToTVNoYPbPrHiVision) && (SiS_Pr->SiS_VGAHDE >= 1024)) {
  5776. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  5777. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x1b);
  5778. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x54);
  5779. } else {
  5780. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,0x17);
  5781. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,0x1d);
  5782. }
  5783. }
  5784. }
  5785. tempcx = SiS_Pr->SiS_HT;
  5786. if(SiS_IsDualLink(SiS_Pr)) tempcx >>= 1;
  5787. tempcx--;
  5788. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) tempcx--;
  5789. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x1B,tempcx);
  5790. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1D,0xF0,((tempcx >> 8) & 0x0f));
  5791. tempcx = SiS_Pr->SiS_HT >> 1;
  5792. if(SiS_IsDualLink(SiS_Pr)) tempcx >>= 1;
  5793. tempcx += 7;
  5794. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) tempcx -= 4;
  5795. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x22,0x0F,((tempcx << 4) & 0xf0));
  5796. tempbx = TimingPoint[j] | (TimingPoint[j+1] << 8);
  5797. tempbx += tempcx;
  5798. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x24,tempbx);
  5799. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x25,0x0F,((tempbx >> 4) & 0xf0));
  5800. tempbx += 8;
  5801. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  5802. tempbx -= 4;
  5803. tempcx = tempbx;
  5804. }
  5805. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x29,0x0F,((tempbx << 4) & 0xf0));
  5806. j += 2;
  5807. tempcx += (TimingPoint[j] | (TimingPoint[j+1] << 8));
  5808. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x27,tempcx);
  5809. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x28,0x0F,((tempcx >> 4) & 0xf0));
  5810. tempcx += 8;
  5811. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) tempcx -= 4;
  5812. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2A,0x0F,((tempcx << 4) & 0xf0));
  5813. tempcx = SiS_Pr->SiS_HT >> 1;
  5814. if(SiS_IsDualLink(SiS_Pr)) tempcx >>= 1;
  5815. j += 2;
  5816. tempcx -= (TimingPoint[j] | ((TimingPoint[j+1]) << 8));
  5817. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2D,0x0F,((tempcx << 4) & 0xf0));
  5818. tempcx -= 11;
  5819. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
  5820. tempcx = SiS_GetVGAHT2(SiS_Pr) - 1;
  5821. }
  5822. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2E,tempcx);
  5823. tempbx = SiS_Pr->SiS_VDE;
  5824. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  5825. if(SiS_Pr->SiS_VGAVDE == 360) tempbx = 746;
  5826. if(SiS_Pr->SiS_VGAVDE == 375) tempbx = 746;
  5827. if(SiS_Pr->SiS_VGAVDE == 405) tempbx = 853;
  5828. } else if( (SiS_Pr->SiS_VBInfo & SetCRT2ToTV) &&
  5829. (!(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p|TVSetYPbPr750p))) ) {
  5830. tempbx >>= 1;
  5831. if(SiS_Pr->ChipType >= SIS_315H) {
  5832. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) {
  5833. if((ModeNo <= 0x13) && (crt2crtc == 1)) tempbx++;
  5834. } else if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  5835. if(SiS_Pr->SiS_ModeType <= ModeVGA) {
  5836. if(crt2crtc == 4) tempbx++;
  5837. }
  5838. }
  5839. }
  5840. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  5841. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  5842. if((ModeNo == 0x2f) || (ModeNo == 0x5d) || (ModeNo == 0x5e)) tempbx++;
  5843. }
  5844. if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) {
  5845. if(ModeNo == 0x03) tempbx++; /* From 1.10.7w - doesn't make sense */
  5846. }
  5847. }
  5848. }
  5849. tempbx -= 2;
  5850. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2F,tempbx);
  5851. temp = (tempcx >> 8) & 0x0F;
  5852. temp |= ((tempbx >> 2) & 0xC0);
  5853. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToSVIDEO | SetCRT2ToAVIDEO)) {
  5854. temp |= 0x10;
  5855. if(SiS_Pr->SiS_VBInfo & SetCRT2ToAVIDEO) temp |= 0x20;
  5856. }
  5857. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x30,temp);
  5858. if(SiS_Pr->SiS_VBType & VB_SISPART4OVERFLOW) {
  5859. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x10,0xdf,((tempbx & 0x0400) >> 5));
  5860. }
  5861. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  5862. tempbx = SiS_Pr->SiS_VDE;
  5863. if( (SiS_Pr->SiS_VBInfo & SetCRT2ToTV) &&
  5864. (!(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p))) ) {
  5865. tempbx >>= 1;
  5866. }
  5867. tempbx -= 3;
  5868. temp = ((tempbx >> 3) & 0x60) | 0x18;
  5869. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x46,temp);
  5870. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x47,tempbx);
  5871. if(SiS_Pr->SiS_VBType & VB_SISPART4OVERFLOW) {
  5872. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x10,0xbf,((tempbx & 0x0400) >> 4));
  5873. }
  5874. }
  5875. tempbx = 0;
  5876. if(!(modeflag & HalfDCLK)) {
  5877. if(SiS_Pr->SiS_VGAHDE >= SiS_Pr->SiS_HDE) {
  5878. tempax = 0;
  5879. tempbx |= 0x20;
  5880. }
  5881. }
  5882. tempch = tempcl = 0x01;
  5883. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  5884. if(SiS_Pr->SiS_VGAHDE >= 960) {
  5885. if((!(modeflag & HalfDCLK)) || (SiS_Pr->ChipType < SIS_315H)) {
  5886. tempcl = 0x20;
  5887. if(SiS_Pr->SiS_VGAHDE >= 1280) {
  5888. tempch = 20;
  5889. tempbx &= ~0x20;
  5890. } else if(SiS_Pr->SiS_VGAHDE >= 1024) {
  5891. tempch = 25;
  5892. } else {
  5893. tempch = 25; /* OK */
  5894. }
  5895. }
  5896. }
  5897. }
  5898. if(!(tempbx & 0x20)) {
  5899. if(modeflag & HalfDCLK) tempcl <<= 1;
  5900. longtemp = ((SiS_Pr->SiS_VGAHDE * tempch) / tempcl) << 13;
  5901. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) longtemp <<= 3;
  5902. tempax = longtemp / SiS_Pr->SiS_HDE;
  5903. if(longtemp % SiS_Pr->SiS_HDE) tempax++;
  5904. tempbx |= ((tempax >> 8) & 0x1F);
  5905. tempcx = tempax >> 13;
  5906. }
  5907. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x44,tempax);
  5908. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x45,0xC0,tempbx);
  5909. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  5910. tempcx &= 0x07;
  5911. if(tempbx & 0x20) tempcx = 0;
  5912. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x46,0xF8,tempcx);
  5913. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  5914. tempbx = 0x0382;
  5915. tempcx = 0x007e;
  5916. } else {
  5917. tempbx = 0x0369;
  5918. tempcx = 0x0061;
  5919. }
  5920. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x4B,tempbx);
  5921. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x4C,tempcx);
  5922. temp = (tempcx & 0x0300) >> 6;
  5923. temp |= ((tempbx >> 8) & 0x03);
  5924. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  5925. temp |= 0x10;
  5926. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) temp |= 0x20;
  5927. else if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) temp |= 0x40;
  5928. }
  5929. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x4D,temp);
  5930. temp = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x43);
  5931. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x43,(temp - 3));
  5932. SiS_SetTVSpecial(SiS_Pr, ModeNo);
  5933. if(SiS_Pr->SiS_VBType & VB_SIS30xCLV) {
  5934. temp = 0;
  5935. if(SiS_Pr->SiS_TVMode & TVSetPALM) temp = 8;
  5936. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x4e,0xf7,temp);
  5937. }
  5938. }
  5939. if(SiS_Pr->SiS_TVMode & TVSetPALM) {
  5940. if(!(SiS_Pr->SiS_TVMode & TVSetNTSC1024)) {
  5941. temp = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x01);
  5942. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,(temp - 1));
  5943. }
  5944. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x00,0xEF);
  5945. }
  5946. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  5947. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  5948. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x0B,0x00);
  5949. }
  5950. }
  5951. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) return;
  5952. /* From here: Part2 LCD setup */
  5953. tempbx = SiS_Pr->SiS_HDE;
  5954. if(SiS_IsDualLink(SiS_Pr)) tempbx >>= 1;
  5955. tempbx--; /* RHACTE = HDE - 1 */
  5956. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x2C,tempbx);
  5957. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2B,0x0F,((tempbx >> 4) & 0xf0));
  5958. temp = 0x01;
  5959. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) {
  5960. if(SiS_Pr->SiS_ModeType == ModeEGA) {
  5961. if(SiS_Pr->SiS_VGAHDE >= 1024) {
  5962. temp = 0x02;
  5963. if(SiS_Pr->SiS_SetFlag & LCDVESATiming) {
  5964. temp = 0x01;
  5965. }
  5966. }
  5967. }
  5968. }
  5969. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x0B,temp);
  5970. tempbx = SiS_Pr->SiS_VDE - 1;
  5971. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x03,tempbx);
  5972. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x0C,0xF8,((tempbx >> 8) & 0x07));
  5973. tempcx = SiS_Pr->SiS_VT - 1;
  5974. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x19,tempcx);
  5975. temp = (tempcx >> 3) & 0xE0;
  5976. if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) {
  5977. /* Enable dithering; only do this for 32bpp mode */
  5978. if(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x01) {
  5979. temp |= 0x10;
  5980. }
  5981. }
  5982. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1A,0x0f,temp);
  5983. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x09,0xF0);
  5984. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x0A,0xF0);
  5985. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x17,0xFB);
  5986. SiS_SetRegAND(SiS_Pr->SiS_Part2Port,0x18,0xDF);
  5987. #ifdef SIS315H
  5988. if(SiS_GetCRT2Part2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex,
  5989. &CRT2Index, &resindex)) {
  5990. switch(CRT2Index) {
  5991. case 206: CRT2Part2Ptr = SiS310_CRT2Part2_Asus1024x768_3; break;
  5992. default:
  5993. case 200: CRT2Part2Ptr = SiS_Pr->SiS_CRT2Part2_1024x768_1; break;
  5994. }
  5995. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x01,0x80,(CRT2Part2Ptr+resindex)->CR[0]);
  5996. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x02,0x80,(CRT2Part2Ptr+resindex)->CR[1]);
  5997. for(i = 2, j = 0x04; j <= 0x06; i++, j++ ) {
  5998. SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]);
  5999. }
  6000. for(j = 0x1c; j <= 0x1d; i++, j++ ) {
  6001. SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]);
  6002. }
  6003. for(j = 0x1f; j <= 0x21; i++, j++ ) {
  6004. SiS_SetReg(SiS_Pr->SiS_Part2Port,j,(CRT2Part2Ptr+resindex)->CR[i]);
  6005. }
  6006. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x23,(CRT2Part2Ptr+resindex)->CR[10]);
  6007. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x25,0x0f,(CRT2Part2Ptr+resindex)->CR[11]);
  6008. SiS_SetGroup2_Tail(SiS_Pr, ModeNo);
  6009. } else {
  6010. #endif
  6011. /* Checked for 1024x768, 1280x1024, 1400x1050, 1600x1200 */
  6012. /* Clevo dual-link 1024x768 */
  6013. /* Compaq 1280x1024 has HT 1696 sometimes (calculation OK, if given HT is correct) */
  6014. /* Acer: OK, but uses different setting for VESA timing at 640/800/1024 and 640x400 */
  6015. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  6016. if((SiS_Pr->SiS_LCDInfo & LCDPass11) || (SiS_Pr->PanelYRes == SiS_Pr->SiS_VDE)) {
  6017. tempbx = SiS_Pr->SiS_VDE - 1;
  6018. tempcx = SiS_Pr->SiS_VT - 1;
  6019. } else {
  6020. tempbx = SiS_Pr->SiS_VDE + ((SiS_Pr->PanelYRes - SiS_Pr->SiS_VDE) / 2);
  6021. tempcx = SiS_Pr->SiS_VT - ((SiS_Pr->PanelYRes - SiS_Pr->SiS_VDE) / 2);
  6022. }
  6023. } else {
  6024. tempbx = SiS_Pr->PanelYRes;
  6025. tempcx = SiS_Pr->SiS_VT;
  6026. tempax = 1;
  6027. if(SiS_Pr->PanelYRes != SiS_Pr->SiS_VDE) {
  6028. tempax = SiS_Pr->PanelYRes;
  6029. /* if(SiS_Pr->SiS_VGAVDE == 525) tempax += 0x3c; */ /* 651+301C */
  6030. if(SiS_Pr->PanelYRes < SiS_Pr->SiS_VDE) {
  6031. tempax = tempcx = 0;
  6032. } else {
  6033. tempax -= SiS_Pr->SiS_VDE;
  6034. }
  6035. tempax >>= 1;
  6036. }
  6037. tempcx -= tempax; /* lcdvdes */
  6038. tempbx -= tempax; /* lcdvdee */
  6039. }
  6040. /* Non-expanding: lcdvdes = tempcx = VT-1; lcdvdee = tempbx = VDE-1 */
  6041. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x05,tempcx); /* lcdvdes */
  6042. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x06,tempbx); /* lcdvdee */
  6043. temp = (tempbx >> 5) & 0x38;
  6044. temp |= ((tempcx >> 8) & 0x07);
  6045. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x02,temp);
  6046. tempax = SiS_Pr->SiS_VDE;
  6047. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
  6048. tempax = SiS_Pr->PanelYRes;
  6049. }
  6050. tempcx = (SiS_Pr->SiS_VT - tempax) >> 4;
  6051. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
  6052. if(SiS_Pr->PanelYRes != SiS_Pr->SiS_VDE) {
  6053. tempcx = (SiS_Pr->SiS_VT - tempax) / 10;
  6054. }
  6055. }
  6056. tempbx = ((SiS_Pr->SiS_VT + SiS_Pr->SiS_VDE) >> 1) - 1;
  6057. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  6058. if(SiS_Pr->PanelYRes != SiS_Pr->SiS_VDE) {
  6059. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) { /* ? */
  6060. tempax = SiS_Pr->SiS_VT - SiS_Pr->PanelYRes;
  6061. if(tempax % 4) { tempax >>= 2; tempax++; }
  6062. else { tempax >>= 2; }
  6063. tempbx -= (tempax - 1);
  6064. } else {
  6065. tempbx -= 10;
  6066. if(tempbx <= SiS_Pr->SiS_VDE) tempbx = SiS_Pr->SiS_VDE + 1;
  6067. }
  6068. }
  6069. }
  6070. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  6071. tempbx++;
  6072. if((!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) || (crt2crtc == 6)) {
  6073. if(SiS_Pr->SiS_SetFlag & LCDVESATiming) {
  6074. tempbx = 770;
  6075. tempcx = 3;
  6076. }
  6077. }
  6078. }
  6079. /* non-expanding: lcdvrs = ((VT + VDE) / 2) - 10 */
  6080. if(SiS_Pr->UseCustomMode) {
  6081. tempbx = SiS_Pr->CVSyncStart;
  6082. }
  6083. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,tempbx); /* lcdvrs */
  6084. temp = (tempbx >> 4) & 0xF0;
  6085. tempbx += (tempcx + 1);
  6086. temp |= (tempbx & 0x0F);
  6087. if(SiS_Pr->UseCustomMode) {
  6088. temp &= 0xf0;
  6089. temp |= (SiS_Pr->CVSyncEnd & 0x0f);
  6090. }
  6091. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x01,temp);
  6092. #ifdef SIS300
  6093. SiS_Group2LCDSpecial(SiS_Pr, ModeNo, crt2crtc);
  6094. #endif
  6095. bridgeoffset = 7;
  6096. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) bridgeoffset += 2;
  6097. if(SiS_Pr->SiS_VBType & VB_SIS30xCLV) bridgeoffset += 2; /* OK for Averatec 1280x800 (301C) */
  6098. if(SiS_IsDualLink(SiS_Pr)) bridgeoffset++;
  6099. else if(SiS_Pr->SiS_VBType & VB_SIS302LV) bridgeoffset++; /* OK for Asus A4L 1280x800 */
  6100. /* Higher bridgeoffset shifts to the LEFT */
  6101. temp = 0;
  6102. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
  6103. if(SiS_Pr->PanelXRes != SiS_Pr->SiS_HDE) {
  6104. temp = SiS_Pr->SiS_HT - ((SiS_Pr->PanelXRes - SiS_Pr->SiS_HDE) / 2);
  6105. if(SiS_IsDualLink(SiS_Pr)) temp >>= 1;
  6106. }
  6107. }
  6108. temp += bridgeoffset;
  6109. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x1F,temp); /* lcdhdes */
  6110. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x20,0x0F,((temp >> 4) & 0xf0));
  6111. tempcx = SiS_Pr->SiS_HT;
  6112. tempax = tempbx = SiS_Pr->SiS_HDE;
  6113. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
  6114. if(SiS_Pr->PanelXRes != SiS_Pr->SiS_HDE) {
  6115. tempax = SiS_Pr->PanelXRes;
  6116. tempbx = SiS_Pr->PanelXRes - ((SiS_Pr->PanelXRes - SiS_Pr->SiS_HDE) / 2);
  6117. }
  6118. }
  6119. if(SiS_IsDualLink(SiS_Pr)) {
  6120. tempcx >>= 1;
  6121. tempbx >>= 1;
  6122. tempax >>= 1;
  6123. }
  6124. tempbx += bridgeoffset;
  6125. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x23,tempbx); /* lcdhdee */
  6126. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x25,0xF0,((tempbx >> 8) & 0x0f));
  6127. tempcx = (tempcx - tempax) >> 2;
  6128. tempbx += tempcx;
  6129. push2 = tempbx;
  6130. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) {
  6131. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) {
  6132. if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
  6133. if(SiS_Pr->SiS_HDE == 1280) tempbx = (tempbx & 0xff00) | 0x47;
  6134. }
  6135. }
  6136. }
  6137. if(SiS_Pr->UseCustomMode) {
  6138. tempbx = SiS_Pr->CHSyncStart;
  6139. if(modeflag & HalfDCLK) tempbx <<= 1;
  6140. if(SiS_IsDualLink(SiS_Pr)) tempbx >>= 1;
  6141. tempbx += bridgeoffset;
  6142. }
  6143. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x1C,tempbx); /* lcdhrs */
  6144. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1D,0x0F,((tempbx >> 4) & 0xf0));
  6145. tempbx = push2;
  6146. tempcx <<= 1;
  6147. if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
  6148. if(SiS_Pr->PanelXRes != SiS_Pr->SiS_HDE) tempcx >>= 2;
  6149. }
  6150. tempbx += tempcx;
  6151. if(SiS_Pr->UseCustomMode) {
  6152. tempbx = SiS_Pr->CHSyncEnd;
  6153. if(modeflag & HalfDCLK) tempbx <<= 1;
  6154. if(SiS_IsDualLink(SiS_Pr)) tempbx >>= 1;
  6155. tempbx += bridgeoffset;
  6156. }
  6157. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x21,tempbx); /* lcdhre */
  6158. SiS_SetGroup2_Tail(SiS_Pr, ModeNo);
  6159. #ifdef SIS300
  6160. SiS_Set300Part2Regs(SiS_Pr, ModeIdIndex, RefreshRateTableIndex, ModeNo);
  6161. #endif
  6162. #ifdef SIS315H
  6163. } /* CRT2-LCD from table */
  6164. #endif
  6165. }
  6166. /*********************************************/
  6167. /* SET PART 3 REGISTER GROUP */
  6168. /*********************************************/
  6169. static void
  6170. SiS_SetGroup3(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  6171. {
  6172. unsigned short i;
  6173. const unsigned char *tempdi;
  6174. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) return;
  6175. #ifndef SIS_CP
  6176. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x00,0x00);
  6177. #else
  6178. SIS_CP_INIT301_CP
  6179. #endif
  6180. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  6181. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x13,0xFA);
  6182. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x14,0xC8);
  6183. } else {
  6184. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x13,0xF5);
  6185. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x14,0xB7);
  6186. }
  6187. if(SiS_Pr->SiS_TVMode & TVSetPALM) {
  6188. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x13,0xFA);
  6189. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x14,0xC8);
  6190. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x3D,0xA8);
  6191. }
  6192. tempdi = NULL;
  6193. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  6194. tempdi = SiS_Pr->SiS_HiTVGroup3Data;
  6195. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) {
  6196. tempdi = SiS_Pr->SiS_HiTVGroup3Simu;
  6197. }
  6198. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
  6199. if(!(SiS_Pr->SiS_TVMode & TVSetYPbPr525i)) {
  6200. tempdi = SiS_HiTVGroup3_1;
  6201. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) tempdi = SiS_HiTVGroup3_2;
  6202. }
  6203. }
  6204. if(tempdi) {
  6205. for(i=0; i<=0x3E; i++) {
  6206. SiS_SetReg(SiS_Pr->SiS_Part3Port,i,tempdi[i]);
  6207. }
  6208. if(SiS_Pr->SiS_VBType & VB_SIS30xCLV) {
  6209. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) {
  6210. SiS_SetReg(SiS_Pr->SiS_Part3Port,0x28,0x3f);
  6211. }
  6212. }
  6213. }
  6214. #ifdef SIS_CP
  6215. SIS_CP_INIT301_CP2
  6216. #endif
  6217. }
  6218. /*********************************************/
  6219. /* SET PART 4 REGISTER GROUP */
  6220. /*********************************************/
  6221. #ifdef SIS315H
  6222. #if 0
  6223. static void
  6224. SiS_ShiftXPos(struct SiS_Private *SiS_Pr, int shift)
  6225. {
  6226. unsigned short temp, temp1, temp2;
  6227. temp1 = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x1f);
  6228. temp2 = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x20);
  6229. temp = (unsigned short)((int)((temp1 | ((temp2 & 0xf0) << 4))) + shift);
  6230. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x1f,temp);
  6231. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x20,0x0f,((temp >> 4) & 0xf0));
  6232. temp = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x2b) & 0x0f;
  6233. temp = (unsigned short)((int)(temp) + shift);
  6234. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x2b,0xf0,(temp & 0x0f));
  6235. temp1 = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x43);
  6236. temp2 = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x42);
  6237. temp = (unsigned short)((int)((temp1 | ((temp2 & 0xf0) << 4))) + shift);
  6238. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x43,temp);
  6239. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x42,0x0f,((temp >> 4) & 0xf0));
  6240. }
  6241. #endif
  6242. static void
  6243. SiS_SetGroup4_C_ELV(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  6244. {
  6245. unsigned short temp, temp1, resinfo = 0;
  6246. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  6247. if(!(SiS_Pr->SiS_VBType & VB_SIS30xCLV)) return;
  6248. if(!(SiS_Pr->SiS_VBInfo & (SetCRT2ToHiVision | SetCRT2ToYPbPr525750))) return;
  6249. if(SiS_Pr->ChipType >= XGI_20) return;
  6250. if((SiS_Pr->ChipType >= SIS_661) && (SiS_Pr->SiS_ROMNew)) {
  6251. if(!(ROMAddr[0x61] & 0x04)) return;
  6252. }
  6253. if(ModeNo > 0x13) {
  6254. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  6255. }
  6256. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x3a,0x08);
  6257. temp = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x3a);
  6258. if(!(temp & 0x01)) {
  6259. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x3a,0xdf);
  6260. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x25,0xfc);
  6261. if((SiS_Pr->ChipType < SIS_661) && (!(SiS_Pr->SiS_ROMNew))) {
  6262. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x25,0xf8);
  6263. }
  6264. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x0f,0xfb);
  6265. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) temp = 0x0000;
  6266. else if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) temp = 0x0002;
  6267. else if(SiS_Pr->SiS_TVMode & TVSetHiVision) temp = 0x0400;
  6268. else temp = 0x0402;
  6269. if((SiS_Pr->ChipType >= SIS_661) || (SiS_Pr->SiS_ROMNew)) {
  6270. temp1 = 0;
  6271. if(SiS_Pr->SiS_TVMode & TVAspect43) temp1 = 4;
  6272. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x0f,0xfb,temp1);
  6273. if(SiS_Pr->SiS_TVMode & TVAspect43LB) temp |= 0x01;
  6274. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x26,0x7c,(temp & 0xff));
  6275. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x3a,0xfb,(temp >> 8));
  6276. if(ModeNo > 0x13) {
  6277. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x39,0xfd);
  6278. }
  6279. } else {
  6280. temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x3b) & 0x03;
  6281. if(temp1 == 0x01) temp |= 0x01;
  6282. if(temp1 == 0x03) temp |= 0x04; /* ? why not 0x10? */
  6283. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x26,0xf8,(temp & 0xff));
  6284. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x3a,0xfb,(temp >> 8));
  6285. if(ModeNo > 0x13) {
  6286. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x3b,0xfd);
  6287. }
  6288. }
  6289. #if 0
  6290. if(SiS_Pr->ChipType >= SIS_661) { /* ? */
  6291. if(SiS_Pr->SiS_TVMode & TVAspect43) {
  6292. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) {
  6293. if(resinfo == SIS_RI_1024x768) {
  6294. SiS_ShiftXPos(SiS_Pr, 97);
  6295. } else {
  6296. SiS_ShiftXPos(SiS_Pr, 111);
  6297. }
  6298. } else if(SiS_Pr->SiS_TVMode & TVSetHiVision) {
  6299. SiS_ShiftXPos(SiS_Pr, 136);
  6300. }
  6301. }
  6302. }
  6303. #endif
  6304. }
  6305. }
  6306. #endif
  6307. static void
  6308. SiS_SetCRT2VCLK(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  6309. unsigned short RefreshRateTableIndex)
  6310. {
  6311. unsigned short vclkindex, temp, reg1, reg2;
  6312. if(SiS_Pr->UseCustomMode) {
  6313. reg1 = SiS_Pr->CSR2B;
  6314. reg2 = SiS_Pr->CSR2C;
  6315. } else {
  6316. vclkindex = SiS_GetVCLK2Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  6317. reg1 = SiS_Pr->SiS_VBVCLKData[vclkindex].Part4_A;
  6318. reg2 = SiS_Pr->SiS_VBVCLKData[vclkindex].Part4_B;
  6319. }
  6320. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  6321. if(SiS_Pr->SiS_TVMode & (TVSetNTSC1024 | TVSet525p1024)) {
  6322. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0a,0x57);
  6323. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0b,0x46);
  6324. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1f,0xf6);
  6325. } else {
  6326. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0a,reg1);
  6327. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0b,reg2);
  6328. }
  6329. } else {
  6330. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0a,0x01);
  6331. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0b,reg2);
  6332. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x0a,reg1);
  6333. }
  6334. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x12,0x00);
  6335. temp = 0x08;
  6336. if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) temp |= 0x20;
  6337. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x12,temp);
  6338. }
  6339. static void
  6340. SiS_SetDualLinkEtc(struct SiS_Private *SiS_Pr)
  6341. {
  6342. if(SiS_Pr->ChipType >= SIS_315H) {
  6343. if(SiS_Pr->SiS_VBType & VB_SISDUALLINK) {
  6344. if((SiS_CRT2IsLCD(SiS_Pr)) ||
  6345. (SiS_IsVAMode(SiS_Pr))) {
  6346. if(SiS_Pr->SiS_LCDInfo & LCDDualLink) {
  6347. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x27,0x2c);
  6348. } else {
  6349. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x27,~0x20);
  6350. }
  6351. }
  6352. }
  6353. }
  6354. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  6355. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2a,0x00);
  6356. #ifdef SET_EMI
  6357. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
  6358. #endif
  6359. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x34,0x10);
  6360. }
  6361. }
  6362. static void
  6363. SiS_SetGroup4(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  6364. unsigned short RefreshRateTableIndex)
  6365. {
  6366. unsigned short tempax, tempcx, tempbx, modeflag, temp, resinfo;
  6367. unsigned int tempebx, tempeax, templong;
  6368. if(ModeNo <= 0x13) {
  6369. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  6370. resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
  6371. } else if(SiS_Pr->UseCustomMode) {
  6372. modeflag = SiS_Pr->CModeFlag;
  6373. resinfo = 0;
  6374. } else {
  6375. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  6376. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  6377. }
  6378. if(SiS_Pr->ChipType >= SIS_315H) {
  6379. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  6380. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  6381. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x24,0x0e);
  6382. }
  6383. }
  6384. }
  6385. if(SiS_Pr->SiS_VBType & (VB_SIS30xCLV | VB_SIS302LV)) {
  6386. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  6387. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x10,0x9f);
  6388. }
  6389. }
  6390. if(SiS_Pr->ChipType >= SIS_315H) {
  6391. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  6392. SiS_SetDualLinkEtc(SiS_Pr);
  6393. return;
  6394. }
  6395. }
  6396. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x13,SiS_Pr->SiS_RVBHCFACT);
  6397. tempbx = SiS_Pr->SiS_RVBHCMAX;
  6398. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x14,tempbx);
  6399. temp = (tempbx >> 1) & 0x80;
  6400. tempcx = SiS_Pr->SiS_VGAHT - 1;
  6401. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x16,tempcx);
  6402. temp |= ((tempcx >> 5) & 0x78);
  6403. tempcx = SiS_Pr->SiS_VGAVT - 1;
  6404. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) tempcx -= 5;
  6405. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x17,tempcx);
  6406. temp |= ((tempcx >> 8) & 0x07);
  6407. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x15,temp);
  6408. tempbx = SiS_Pr->SiS_VGAHDE;
  6409. if(modeflag & HalfDCLK) tempbx >>= 1;
  6410. if(SiS_IsDualLink(SiS_Pr)) tempbx >>= 1;
  6411. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  6412. temp = 0;
  6413. if(tempbx > 800) temp = 0x60;
  6414. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  6415. temp = 0;
  6416. if(tempbx > 1024) temp = 0xC0;
  6417. else if(tempbx >= 960) temp = 0xA0;
  6418. } else if(SiS_Pr->SiS_TVMode & (TVSetYPbPr525p | TVSetYPbPr750p)) {
  6419. temp = 0;
  6420. if(tempbx >= 1280) temp = 0x40;
  6421. else if(tempbx >= 1024) temp = 0x20;
  6422. } else {
  6423. temp = 0x80;
  6424. if(tempbx >= 1024) temp = 0xA0;
  6425. }
  6426. temp |= SiS_Pr->Init_P4_0E;
  6427. if(SiS_Pr->SiS_VBType & VB_SIS301) {
  6428. if(SiS_Pr->SiS_LCDResInfo != Panel_1280x1024) {
  6429. temp &= 0xf0;
  6430. temp |= 0x0A;
  6431. }
  6432. }
  6433. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x0E,0x10,temp);
  6434. tempeax = SiS_Pr->SiS_VGAVDE;
  6435. tempebx = SiS_Pr->SiS_VDE;
  6436. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  6437. if(!(temp & 0xE0)) tempebx >>=1;
  6438. }
  6439. tempcx = SiS_Pr->SiS_RVBHRS;
  6440. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x18,tempcx);
  6441. tempcx >>= 8;
  6442. tempcx |= 0x40;
  6443. if(tempeax <= tempebx) {
  6444. tempcx ^= 0x40;
  6445. } else {
  6446. tempeax -= tempebx;
  6447. }
  6448. tempeax *= (256 * 1024);
  6449. templong = tempeax % tempebx;
  6450. tempeax /= tempebx;
  6451. if(templong) tempeax++;
  6452. temp = (unsigned short)(tempeax & 0x000000FF);
  6453. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1B,temp);
  6454. temp = (unsigned short)((tempeax & 0x0000FF00) >> 8);
  6455. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1A,temp);
  6456. temp = (unsigned short)((tempeax >> 12) & 0x70); /* sic! */
  6457. temp |= (tempcx & 0x4F);
  6458. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x19,temp);
  6459. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  6460. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1C,0x28);
  6461. /* Calc Linebuffer max address and set/clear decimode */
  6462. tempbx = 0;
  6463. if(SiS_Pr->SiS_TVMode & (TVSetHiVision | TVSetYPbPr750p)) tempbx = 0x08;
  6464. tempax = SiS_Pr->SiS_VGAHDE;
  6465. if(modeflag & HalfDCLK) tempax >>= 1;
  6466. if(SiS_IsDualLink(SiS_Pr)) tempax >>= 1;
  6467. if(tempax > 800) {
  6468. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  6469. tempax -= 800;
  6470. } else {
  6471. tempbx = 0x08;
  6472. if(tempax == 960) tempax *= 25; /* Correct */
  6473. else if(tempax == 1024) tempax *= 25;
  6474. else tempax *= 20;
  6475. temp = tempax % 32;
  6476. tempax /= 32;
  6477. if(temp) tempax++;
  6478. tempax++;
  6479. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  6480. if(resinfo == SIS_RI_1024x768 ||
  6481. resinfo == SIS_RI_1024x576 ||
  6482. resinfo == SIS_RI_1280x1024 ||
  6483. resinfo == SIS_RI_1280x720) {
  6484. /* Otherwise white line or garbage at right edge */
  6485. tempax = (tempax & 0xff00) | 0x20;
  6486. }
  6487. }
  6488. }
  6489. }
  6490. tempax--;
  6491. temp = ((tempax >> 4) & 0x30) | tempbx;
  6492. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1D,tempax);
  6493. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x1E,temp);
  6494. temp = 0x0036; tempbx = 0xD0;
  6495. if((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->SiS_VBType & VB_SISLVDS)) {
  6496. temp = 0x0026; tempbx = 0xC0; /* See En/DisableBridge() */
  6497. }
  6498. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  6499. if(!(SiS_Pr->SiS_TVMode & (TVSetNTSC1024 | TVSetHiVision | TVSetYPbPr750p | TVSetYPbPr525p))) {
  6500. temp |= 0x01;
  6501. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  6502. if(!(SiS_Pr->SiS_TVMode & TVSetTVSimuMode)) {
  6503. temp &= ~0x01;
  6504. }
  6505. }
  6506. }
  6507. }
  6508. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x1F,tempbx,temp);
  6509. tempbx = SiS_Pr->SiS_HT >> 1;
  6510. if(SiS_IsDualLink(SiS_Pr)) tempbx >>= 1;
  6511. tempbx -= 2;
  6512. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x22,tempbx);
  6513. temp = (tempbx >> 5) & 0x38;
  6514. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x21,0xC0,temp);
  6515. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  6516. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  6517. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x24,0x0e);
  6518. /* LCD-too-dark-error-source, see FinalizeLCD() */
  6519. }
  6520. }
  6521. SiS_SetDualLinkEtc(SiS_Pr);
  6522. } /* 301B */
  6523. SiS_SetCRT2VCLK(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  6524. }
  6525. /*********************************************/
  6526. /* SET PART 5 REGISTER GROUP */
  6527. /*********************************************/
  6528. static void
  6529. SiS_SetGroup5(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  6530. {
  6531. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) return;
  6532. if(SiS_Pr->SiS_ModeType == ModeVGA) {
  6533. if(!(SiS_Pr->SiS_VBInfo & (SetInSlaveMode | LoadDACFlag))) {
  6534. SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x20);
  6535. SiS_LoadDAC(SiS_Pr, ModeNo, ModeIdIndex);
  6536. }
  6537. }
  6538. }
  6539. /*********************************************/
  6540. /* MODIFY CRT1 GROUP FOR SLAVE MODE */
  6541. /*********************************************/
  6542. static bool
  6543. SiS_GetLVDSCRT1Ptr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  6544. unsigned short RefreshRateTableIndex, unsigned short *ResIndex,
  6545. unsigned short *DisplayType)
  6546. {
  6547. unsigned short modeflag = 0;
  6548. bool checkhd = true;
  6549. /* Pass 1:1 not supported here */
  6550. if(ModeNo <= 0x13) {
  6551. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  6552. (*ResIndex) = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  6553. } else {
  6554. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  6555. (*ResIndex) = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  6556. }
  6557. (*ResIndex) &= 0x3F;
  6558. if((SiS_Pr->SiS_IF_DEF_CH70xx) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
  6559. (*DisplayType) = 80;
  6560. if((SiS_Pr->SiS_TVMode & TVSetPAL) && (!(SiS_Pr->SiS_TVMode & TVSetPALM))) {
  6561. (*DisplayType) = 82;
  6562. if(SiS_Pr->SiS_ModeType > ModeVGA) {
  6563. if(SiS_Pr->SiS_CHSOverScan) (*DisplayType) = 84;
  6564. }
  6565. }
  6566. if((*DisplayType) != 84) {
  6567. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) (*DisplayType)++;
  6568. }
  6569. } else {
  6570. (*DisplayType = 0);
  6571. switch(SiS_Pr->SiS_LCDResInfo) {
  6572. case Panel_320x240_1: (*DisplayType) = 50;
  6573. checkhd = false;
  6574. break;
  6575. case Panel_320x240_2: (*DisplayType) = 14;
  6576. break;
  6577. case Panel_320x240_3: (*DisplayType) = 18;
  6578. break;
  6579. case Panel_640x480: (*DisplayType) = 10;
  6580. break;
  6581. case Panel_1024x600: (*DisplayType) = 26;
  6582. break;
  6583. default: return true;
  6584. }
  6585. if(checkhd) {
  6586. if(modeflag & HalfDCLK) (*DisplayType)++;
  6587. }
  6588. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x600) {
  6589. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) (*DisplayType) += 2;
  6590. }
  6591. }
  6592. return true;
  6593. }
  6594. static void
  6595. SiS_ModCRT1CRTC(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  6596. unsigned short RefreshRateTableIndex)
  6597. {
  6598. unsigned short tempah, i, modeflag, j, ResIndex, DisplayType;
  6599. const struct SiS_LVDSCRT1Data *LVDSCRT1Ptr=NULL;
  6600. static const unsigned short CRIdx[] = {
  6601. 0x00, 0x02, 0x03, 0x04, 0x05, 0x06,
  6602. 0x07, 0x10, 0x11, 0x15, 0x16
  6603. };
  6604. if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) ||
  6605. (SiS_Pr->SiS_CustomT == CUT_BARCO1024) ||
  6606. (SiS_Pr->SiS_CustomT == CUT_PANEL848) ||
  6607. (SiS_Pr->SiS_CustomT == CUT_PANEL856) )
  6608. return;
  6609. if(SiS_Pr->SiS_IF_DEF_LVDS) {
  6610. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  6611. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) return;
  6612. }
  6613. } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
  6614. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) return;
  6615. } else return;
  6616. if(SiS_Pr->SiS_LCDInfo & LCDPass11) return;
  6617. if(SiS_Pr->ChipType < SIS_315H) {
  6618. if(SiS_Pr->SiS_SetFlag & SetDOSMode) return;
  6619. }
  6620. if(!(SiS_GetLVDSCRT1Ptr(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex,
  6621. &ResIndex, &DisplayType))) {
  6622. return;
  6623. }
  6624. switch(DisplayType) {
  6625. case 50: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1320x240_1; break; /* xSTN */
  6626. case 14: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1320x240_2; break; /* xSTN */
  6627. case 15: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1320x240_2_H; break; /* xSTN */
  6628. case 18: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1320x240_3; break; /* xSTN */
  6629. case 19: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1320x240_3_H; break; /* xSTN */
  6630. case 10: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1640x480_1; break;
  6631. case 11: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT1640x480_1_H; break;
  6632. #if 0 /* Works better with calculated numbers */
  6633. case 26: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x600_1; break;
  6634. case 27: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x600_1_H; break;
  6635. case 28: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x600_2; break;
  6636. case 29: LVDSCRT1Ptr = SiS_Pr->SiS_LVDSCRT11024x600_2_H; break;
  6637. #endif
  6638. case 80: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1UNTSC; break;
  6639. case 81: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1ONTSC; break;
  6640. case 82: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1UPAL; break;
  6641. case 83: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1OPAL; break;
  6642. case 84: LVDSCRT1Ptr = SiS_Pr->SiS_CHTVCRT1SOPAL; break;
  6643. }
  6644. if(LVDSCRT1Ptr) {
  6645. SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x11,0x7f);
  6646. for(i = 0; i <= 10; i++) {
  6647. tempah = (LVDSCRT1Ptr + ResIndex)->CR[i];
  6648. SiS_SetReg(SiS_Pr->SiS_P3d4,CRIdx[i],tempah);
  6649. }
  6650. for(i = 0x0A, j = 11; i <= 0x0C; i++, j++) {
  6651. tempah = (LVDSCRT1Ptr + ResIndex)->CR[j];
  6652. SiS_SetReg(SiS_Pr->SiS_P3c4,i,tempah);
  6653. }
  6654. tempah = (LVDSCRT1Ptr + ResIndex)->CR[14] & 0xE0;
  6655. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x0E,0x1f,tempah);
  6656. if(ModeNo <= 0x13) modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  6657. else modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  6658. tempah = ((LVDSCRT1Ptr + ResIndex)->CR[14] & 0x01) << 5;
  6659. if(modeflag & DoubleScanMode) tempah |= 0x80;
  6660. SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x09,~0x020,tempah);
  6661. } else {
  6662. SiS_CalcLCDACRT1Timing(SiS_Pr, ModeNo, ModeIdIndex);
  6663. }
  6664. }
  6665. /*********************************************/
  6666. /* SET CRT2 ECLK */
  6667. /*********************************************/
  6668. static void
  6669. SiS_SetCRT2ECLK(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  6670. unsigned short RefreshRateTableIndex)
  6671. {
  6672. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  6673. unsigned short clkbase, vclkindex = 0;
  6674. unsigned char sr2b, sr2c;
  6675. if(SiS_Pr->SiS_LCDInfo & LCDPass11) {
  6676. SiS_Pr->SiS_SetFlag &= (~ProgrammingCRT2);
  6677. if(SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK == 2) {
  6678. RefreshRateTableIndex--;
  6679. }
  6680. vclkindex = SiS_GetVCLK2Ptr(SiS_Pr, ModeNo, ModeIdIndex,
  6681. RefreshRateTableIndex);
  6682. SiS_Pr->SiS_SetFlag |= ProgrammingCRT2;
  6683. } else {
  6684. vclkindex = SiS_GetVCLK2Ptr(SiS_Pr, ModeNo, ModeIdIndex,
  6685. RefreshRateTableIndex);
  6686. }
  6687. sr2b = SiS_Pr->SiS_VCLKData[vclkindex].SR2B;
  6688. sr2c = SiS_Pr->SiS_VCLKData[vclkindex].SR2C;
  6689. if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) || (SiS_Pr->SiS_CustomT == CUT_BARCO1024)) {
  6690. if(SiS_Pr->SiS_UseROM) {
  6691. if(ROMAddr[0x220] & 0x01) {
  6692. sr2b = ROMAddr[0x227];
  6693. sr2c = ROMAddr[0x228];
  6694. }
  6695. }
  6696. }
  6697. clkbase = 0x02B;
  6698. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA)) {
  6699. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) {
  6700. clkbase += 3;
  6701. }
  6702. }
  6703. SiS_SetReg(SiS_Pr->SiS_P3c4,0x31,0x20);
  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,0x10);
  6707. SiS_SetReg(SiS_Pr->SiS_P3c4,clkbase,sr2b);
  6708. SiS_SetReg(SiS_Pr->SiS_P3c4,clkbase+1,sr2c);
  6709. SiS_SetReg(SiS_Pr->SiS_P3c4,0x31,0x00);
  6710. SiS_SetReg(SiS_Pr->SiS_P3c4,clkbase,sr2b);
  6711. SiS_SetReg(SiS_Pr->SiS_P3c4,clkbase+1,sr2c);
  6712. }
  6713. /*********************************************/
  6714. /* SET UP CHRONTEL CHIPS */
  6715. /*********************************************/
  6716. static void
  6717. SiS_SetCHTVReg(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  6718. unsigned short RefreshRateTableIndex)
  6719. {
  6720. unsigned short TVType, resindex;
  6721. const struct SiS_CHTVRegData *CHTVRegData = NULL;
  6722. if(ModeNo <= 0x13)
  6723. resindex = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  6724. else
  6725. resindex = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
  6726. resindex &= 0x3F;
  6727. TVType = 0;
  6728. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) TVType += 1;
  6729. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  6730. TVType += 2;
  6731. if(SiS_Pr->SiS_ModeType > ModeVGA) {
  6732. if(SiS_Pr->SiS_CHSOverScan) TVType = 8;
  6733. }
  6734. if(SiS_Pr->SiS_TVMode & TVSetPALM) {
  6735. TVType = 4;
  6736. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) TVType += 1;
  6737. } else if(SiS_Pr->SiS_TVMode & TVSetPALN) {
  6738. TVType = 6;
  6739. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) TVType += 1;
  6740. }
  6741. }
  6742. switch(TVType) {
  6743. case 0: CHTVRegData = SiS_Pr->SiS_CHTVReg_UNTSC; break;
  6744. case 1: CHTVRegData = SiS_Pr->SiS_CHTVReg_ONTSC; break;
  6745. case 2: CHTVRegData = SiS_Pr->SiS_CHTVReg_UPAL; break;
  6746. case 3: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPAL; break;
  6747. case 4: CHTVRegData = SiS_Pr->SiS_CHTVReg_UPALM; break;
  6748. case 5: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPALM; break;
  6749. case 6: CHTVRegData = SiS_Pr->SiS_CHTVReg_UPALN; break;
  6750. case 7: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPALN; break;
  6751. case 8: CHTVRegData = SiS_Pr->SiS_CHTVReg_SOPAL; break;
  6752. default: CHTVRegData = SiS_Pr->SiS_CHTVReg_OPAL; break;
  6753. }
  6754. if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) {
  6755. #ifdef SIS300
  6756. /* Chrontel 7005 - I assume that it does not come with a 315 series chip */
  6757. /* We don't support modes >800x600 */
  6758. if (resindex > 5) return;
  6759. if(SiS_Pr->SiS_TVMode & TVSetPAL) {
  6760. SiS_SetCH700x(SiS_Pr,0x04,0x43); /* 0x40=76uA (PAL); 0x03=15bit non-multi RGB*/
  6761. SiS_SetCH700x(SiS_Pr,0x09,0x69); /* Black level for PAL (105)*/
  6762. } else {
  6763. SiS_SetCH700x(SiS_Pr,0x04,0x03); /* upper nibble=71uA (NTSC), 0x03=15bit non-multi RGB*/
  6764. SiS_SetCH700x(SiS_Pr,0x09,0x71); /* Black level for NTSC (113)*/
  6765. }
  6766. SiS_SetCH700x(SiS_Pr,0x00,CHTVRegData[resindex].Reg[0]); /* Mode register */
  6767. SiS_SetCH700x(SiS_Pr,0x07,CHTVRegData[resindex].Reg[1]); /* Start active video register */
  6768. SiS_SetCH700x(SiS_Pr,0x08,CHTVRegData[resindex].Reg[2]); /* Position overflow register */
  6769. SiS_SetCH700x(SiS_Pr,0x0a,CHTVRegData[resindex].Reg[3]); /* Horiz Position register */
  6770. SiS_SetCH700x(SiS_Pr,0x0b,CHTVRegData[resindex].Reg[4]); /* Vertical Position register */
  6771. /* Set minimum flicker filter for Luma channel (SR1-0=00),
  6772. minimum text enhancement (S3-2=10),
  6773. maximum flicker filter for Chroma channel (S5-4=10)
  6774. =00101000=0x28 (When reading, S1-0->S3-2, and S3-2->S1-0!)
  6775. */
  6776. SiS_SetCH700x(SiS_Pr,0x01,0x28);
  6777. /* Set video bandwidth
  6778. High bandwidth Luma composite video filter(S0=1)
  6779. low bandwidth Luma S-video filter (S2-1=00)
  6780. disable peak filter in S-video channel (S3=0)
  6781. high bandwidth Chroma Filter (S5-4=11)
  6782. =00110001=0x31
  6783. */
  6784. SiS_SetCH700x(SiS_Pr,0x03,0xb1); /* old: 3103 */
  6785. /* Register 0x3D does not exist in non-macrovision register map
  6786. (Maybe this is a macrovision register?)
  6787. */
  6788. #ifndef SIS_CP
  6789. SiS_SetCH70xx(SiS_Pr,0x3d,0x00);
  6790. #endif
  6791. /* Register 0x10 only contains 1 writable bit (S0) for sensing,
  6792. all other bits a read-only. Macrovision?
  6793. */
  6794. SiS_SetCH70xxANDOR(SiS_Pr,0x10,0x00,0x1F);
  6795. /* Register 0x11 only contains 3 writable bits (S0-S2) for
  6796. contrast enhancement (set to 010 -> gain 1 Yout = 17/16*(Yin-30) )
  6797. */
  6798. SiS_SetCH70xxANDOR(SiS_Pr,0x11,0x02,0xF8);
  6799. /* Clear DSEN
  6800. */
  6801. SiS_SetCH70xxANDOR(SiS_Pr,0x1c,0x00,0xEF);
  6802. if(!(SiS_Pr->SiS_TVMode & TVSetPAL)) { /* ---- NTSC ---- */
  6803. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) {
  6804. if(resindex == 0x04) { /* 640x480 overscan: Mode 16 */
  6805. SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x00,0xEF); /* loop filter off */
  6806. SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x01,0xFE); /* ACIV on, no need to set FSCI */
  6807. } else if(resindex == 0x05) { /* 800x600 overscan: Mode 23 */
  6808. SiS_SetCH70xxANDOR(SiS_Pr,0x18,0x01,0xF0); /* 0x18-0x1f: FSCI 469,762,048 */
  6809. SiS_SetCH70xxANDOR(SiS_Pr,0x19,0x0C,0xF0);
  6810. SiS_SetCH70xxANDOR(SiS_Pr,0x1a,0x00,0xF0);
  6811. SiS_SetCH70xxANDOR(SiS_Pr,0x1b,0x00,0xF0);
  6812. SiS_SetCH70xxANDOR(SiS_Pr,0x1c,0x00,0xF0);
  6813. SiS_SetCH70xxANDOR(SiS_Pr,0x1d,0x00,0xF0);
  6814. SiS_SetCH70xxANDOR(SiS_Pr,0x1e,0x00,0xF0);
  6815. SiS_SetCH70xxANDOR(SiS_Pr,0x1f,0x00,0xF0);
  6816. SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x01,0xEF); /* Loop filter on for mode 23 */
  6817. SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x00,0xFE); /* ACIV off, need to set FSCI */
  6818. }
  6819. } else {
  6820. if(resindex == 0x04) { /* ----- 640x480 underscan; Mode 17 */
  6821. SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x00,0xEF); /* loop filter off */
  6822. SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x01,0xFE);
  6823. } else if(resindex == 0x05) { /* ----- 800x600 underscan: Mode 24 */
  6824. #if 0
  6825. SiS_SetCH70xxANDOR(SiS_Pr,0x18,0x01,0xF0); /* (FSCI was 0x1f1c71c7 - this is for mode 22) */
  6826. SiS_SetCH70xxANDOR(SiS_Pr,0x19,0x09,0xF0); /* FSCI for mode 24 is 428,554,851 */
  6827. SiS_SetCH70xxANDOR(SiS_Pr,0x1a,0x08,0xF0); /* 198b3a63 */
  6828. SiS_SetCH70xxANDOR(SiS_Pr,0x1b,0x0b,0xF0);
  6829. SiS_SetCH70xxANDOR(SiS_Pr,0x1c,0x04,0xF0);
  6830. SiS_SetCH70xxANDOR(SiS_Pr,0x1d,0x01,0xF0);
  6831. SiS_SetCH70xxANDOR(SiS_Pr,0x1e,0x06,0xF0);
  6832. SiS_SetCH70xxANDOR(SiS_Pr,0x1f,0x05,0xF0);
  6833. SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x00,0xEF); /* loop filter off for mode 24 */
  6834. SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x00,0xFE); * ACIV off, need to set FSCI */
  6835. #endif /* All alternatives wrong (datasheet wrong?), don't use FSCI */
  6836. SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x00,0xEF); /* loop filter off */
  6837. SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x01,0xFE);
  6838. }
  6839. }
  6840. } else { /* ---- PAL ---- */
  6841. /* We don't play around with FSCI in PAL mode */
  6842. if(resindex == 0x04) {
  6843. SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x00,0xEF); /* loop filter off */
  6844. SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x01,0xFE); /* ACIV on */
  6845. } else {
  6846. SiS_SetCH70xxANDOR(SiS_Pr,0x20,0x00,0xEF); /* loop filter off */
  6847. SiS_SetCH70xxANDOR(SiS_Pr,0x21,0x01,0xFE); /* ACIV on */
  6848. }
  6849. }
  6850. #endif /* 300 */
  6851. } else {
  6852. /* Chrontel 7019 - assumed that it does not come with a 300 series chip */
  6853. #ifdef SIS315H
  6854. unsigned short temp;
  6855. /* We don't support modes >1024x768 */
  6856. if (resindex > 6) return;
  6857. temp = CHTVRegData[resindex].Reg[0];
  6858. if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) temp |= 0x10;
  6859. SiS_SetCH701x(SiS_Pr,0x00,temp);
  6860. SiS_SetCH701x(SiS_Pr,0x01,CHTVRegData[resindex].Reg[1]);
  6861. SiS_SetCH701x(SiS_Pr,0x02,CHTVRegData[resindex].Reg[2]);
  6862. SiS_SetCH701x(SiS_Pr,0x04,CHTVRegData[resindex].Reg[3]);
  6863. SiS_SetCH701x(SiS_Pr,0x03,CHTVRegData[resindex].Reg[4]);
  6864. SiS_SetCH701x(SiS_Pr,0x05,CHTVRegData[resindex].Reg[5]);
  6865. SiS_SetCH701x(SiS_Pr,0x06,CHTVRegData[resindex].Reg[6]);
  6866. temp = CHTVRegData[resindex].Reg[7];
  6867. if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) temp = 0x66;
  6868. SiS_SetCH701x(SiS_Pr,0x07,temp);
  6869. SiS_SetCH701x(SiS_Pr,0x08,CHTVRegData[resindex].Reg[8]);
  6870. SiS_SetCH701x(SiS_Pr,0x15,CHTVRegData[resindex].Reg[9]);
  6871. SiS_SetCH701x(SiS_Pr,0x1f,CHTVRegData[resindex].Reg[10]);
  6872. SiS_SetCH701x(SiS_Pr,0x0c,CHTVRegData[resindex].Reg[11]);
  6873. SiS_SetCH701x(SiS_Pr,0x0d,CHTVRegData[resindex].Reg[12]);
  6874. SiS_SetCH701x(SiS_Pr,0x0e,CHTVRegData[resindex].Reg[13]);
  6875. SiS_SetCH701x(SiS_Pr,0x0f,CHTVRegData[resindex].Reg[14]);
  6876. SiS_SetCH701x(SiS_Pr,0x10,CHTVRegData[resindex].Reg[15]);
  6877. temp = SiS_GetCH701x(SiS_Pr,0x21) & ~0x02;
  6878. /* D1 should be set for PAL, PAL-N and NTSC-J,
  6879. but I won't do that for PAL unless somebody
  6880. tells me to do so. Since the BIOS uses
  6881. non-default CIV values and blacklevels,
  6882. this might be compensated anyway.
  6883. */
  6884. if(SiS_Pr->SiS_TVMode & (TVSetPALN | TVSetNTSCJ)) temp |= 0x02;
  6885. SiS_SetCH701x(SiS_Pr,0x21,temp);
  6886. #endif /* 315 */
  6887. }
  6888. #ifdef SIS_CP
  6889. SIS_CP_INIT301_CP3
  6890. #endif
  6891. }
  6892. #ifdef SIS315H /* ----------- 315 series only ---------- */
  6893. void
  6894. SiS_Chrontel701xBLOn(struct SiS_Private *SiS_Pr)
  6895. {
  6896. unsigned short temp;
  6897. /* Enable Chrontel 7019 LCD panel backlight */
  6898. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  6899. if(SiS_Pr->ChipType == SIS_740) {
  6900. SiS_SetCH701x(SiS_Pr,0x66,0x65);
  6901. } else {
  6902. temp = SiS_GetCH701x(SiS_Pr,0x66);
  6903. temp |= 0x20;
  6904. SiS_SetCH701x(SiS_Pr,0x66,temp);
  6905. }
  6906. }
  6907. }
  6908. void
  6909. SiS_Chrontel701xBLOff(struct SiS_Private *SiS_Pr)
  6910. {
  6911. unsigned short temp;
  6912. /* Disable Chrontel 7019 LCD panel backlight */
  6913. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  6914. temp = SiS_GetCH701x(SiS_Pr,0x66);
  6915. temp &= 0xDF;
  6916. SiS_SetCH701x(SiS_Pr,0x66,temp);
  6917. }
  6918. }
  6919. static void
  6920. SiS_ChrontelPowerSequencing(struct SiS_Private *SiS_Pr)
  6921. {
  6922. static const unsigned char regtable[] = { 0x67, 0x68, 0x69, 0x6a, 0x6b };
  6923. static const unsigned char table1024_740[] = { 0x01, 0x02, 0x01, 0x01, 0x01 };
  6924. static const unsigned char table1400_740[] = { 0x01, 0x6e, 0x01, 0x01, 0x01 };
  6925. static const unsigned char asus1024_740[] = { 0x19, 0x6e, 0x01, 0x19, 0x09 };
  6926. static const unsigned char asus1400_740[] = { 0x19, 0x6e, 0x01, 0x19, 0x09 };
  6927. static const unsigned char table1024_650[] = { 0x01, 0x02, 0x01, 0x01, 0x02 };
  6928. static const unsigned char table1400_650[] = { 0x01, 0x02, 0x01, 0x01, 0x02 };
  6929. const unsigned char *tableptr = NULL;
  6930. int i;
  6931. /* Set up Power up/down timing */
  6932. if(SiS_Pr->ChipType == SIS_740) {
  6933. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  6934. if(SiS_Pr->SiS_CustomT == CUT_ASUSL3000D) tableptr = asus1024_740;
  6935. else tableptr = table1024_740;
  6936. } else if((SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) ||
  6937. (SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) ||
  6938. (SiS_Pr->SiS_LCDResInfo == Panel_1600x1200)) {
  6939. if(SiS_Pr->SiS_CustomT == CUT_ASUSL3000D) tableptr = asus1400_740;
  6940. else tableptr = table1400_740;
  6941. } else return;
  6942. } else {
  6943. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  6944. tableptr = table1024_650;
  6945. } else if((SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) ||
  6946. (SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) ||
  6947. (SiS_Pr->SiS_LCDResInfo == Panel_1600x1200)) {
  6948. tableptr = table1400_650;
  6949. } else return;
  6950. }
  6951. for(i=0; i<5; i++) {
  6952. SiS_SetCH701x(SiS_Pr, regtable[i], tableptr[i]);
  6953. }
  6954. }
  6955. static void
  6956. SiS_SetCH701xForLCD(struct SiS_Private *SiS_Pr)
  6957. {
  6958. const unsigned char *tableptr = NULL;
  6959. unsigned short tempbh;
  6960. int i;
  6961. static const unsigned char regtable[] = {
  6962. 0x1c, 0x5f, 0x64, 0x6f, 0x70, 0x71,
  6963. 0x72, 0x73, 0x74, 0x76, 0x78, 0x7d, 0x66
  6964. };
  6965. static const unsigned char table1024_740[] = {
  6966. 0x60, 0x02, 0x00, 0x07, 0x40, 0xed,
  6967. 0xa3, 0xc8, 0xc7, 0xac, 0xe0, 0x02, 0x44
  6968. };
  6969. static const unsigned char table1280_740[] = {
  6970. 0x60, 0x03, 0x11, 0x00, 0x40, 0xe3,
  6971. 0xad, 0xdb, 0xf6, 0xac, 0xe0, 0x02, 0x44
  6972. };
  6973. static const unsigned char table1400_740[] = {
  6974. 0x60, 0x03, 0x11, 0x00, 0x40, 0xe3,
  6975. 0xad, 0xdb, 0xf6, 0xac, 0xe0, 0x02, 0x44
  6976. };
  6977. static const unsigned char table1600_740[] = {
  6978. 0x60, 0x04, 0x11, 0x00, 0x40, 0xe3,
  6979. 0xad, 0xde, 0xf6, 0xac, 0x60, 0x1a, 0x44
  6980. };
  6981. static const unsigned char table1024_650[] = {
  6982. 0x60, 0x02, 0x00, 0x07, 0x40, 0xed,
  6983. 0xa3, 0xc8, 0xc7, 0xac, 0x60, 0x02
  6984. };
  6985. static const unsigned char table1280_650[] = {
  6986. 0x60, 0x03, 0x11, 0x00, 0x40, 0xe3,
  6987. 0xad, 0xdb, 0xf6, 0xac, 0xe0, 0x02
  6988. };
  6989. static const unsigned char table1400_650[] = {
  6990. 0x60, 0x03, 0x11, 0x00, 0x40, 0xef,
  6991. 0xad, 0xdb, 0xf6, 0xac, 0x60, 0x02
  6992. };
  6993. static const unsigned char table1600_650[] = {
  6994. 0x60, 0x04, 0x11, 0x00, 0x40, 0xe3,
  6995. 0xad, 0xde, 0xf6, 0xac, 0x60, 0x1a
  6996. };
  6997. if(SiS_Pr->ChipType == SIS_740) {
  6998. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) tableptr = table1024_740;
  6999. else if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) tableptr = table1280_740;
  7000. else if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) tableptr = table1400_740;
  7001. else if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) tableptr = table1600_740;
  7002. else return;
  7003. } else {
  7004. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) tableptr = table1024_650;
  7005. else if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) tableptr = table1280_650;
  7006. else if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) tableptr = table1400_650;
  7007. else if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) tableptr = table1600_650;
  7008. else return;
  7009. }
  7010. tempbh = SiS_GetCH701x(SiS_Pr,0x74);
  7011. if((tempbh == 0xf6) || (tempbh == 0xc7)) {
  7012. tempbh = SiS_GetCH701x(SiS_Pr,0x73);
  7013. if(tempbh == 0xc8) {
  7014. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) return;
  7015. } else if(tempbh == 0xdb) {
  7016. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) return;
  7017. if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) return;
  7018. } else if(tempbh == 0xde) {
  7019. if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) return;
  7020. }
  7021. }
  7022. if(SiS_Pr->ChipType == SIS_740) tempbh = 0x0d;
  7023. else tempbh = 0x0c;
  7024. for(i = 0; i < tempbh; i++) {
  7025. SiS_SetCH701x(SiS_Pr, regtable[i], tableptr[i]);
  7026. }
  7027. SiS_ChrontelPowerSequencing(SiS_Pr);
  7028. tempbh = SiS_GetCH701x(SiS_Pr,0x1e);
  7029. tempbh |= 0xc0;
  7030. SiS_SetCH701x(SiS_Pr,0x1e,tempbh);
  7031. if(SiS_Pr->ChipType == SIS_740) {
  7032. tempbh = SiS_GetCH701x(SiS_Pr,0x1c);
  7033. tempbh &= 0xfb;
  7034. SiS_SetCH701x(SiS_Pr,0x1c,tempbh);
  7035. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2d,0x03);
  7036. tempbh = SiS_GetCH701x(SiS_Pr,0x64);
  7037. tempbh |= 0x40;
  7038. SiS_SetCH701x(SiS_Pr,0x64,tempbh);
  7039. tempbh = SiS_GetCH701x(SiS_Pr,0x03);
  7040. tempbh &= 0x3f;
  7041. SiS_SetCH701x(SiS_Pr,0x03,tempbh);
  7042. }
  7043. }
  7044. static void
  7045. SiS_ChrontelResetVSync(struct SiS_Private *SiS_Pr)
  7046. {
  7047. unsigned char temp, temp1;
  7048. temp1 = SiS_GetCH701x(SiS_Pr,0x49);
  7049. SiS_SetCH701x(SiS_Pr,0x49,0x3e);
  7050. temp = SiS_GetCH701x(SiS_Pr,0x47);
  7051. temp &= 0x7f; /* Use external VSYNC */
  7052. SiS_SetCH701x(SiS_Pr,0x47,temp);
  7053. SiS_LongDelay(SiS_Pr, 3);
  7054. temp = SiS_GetCH701x(SiS_Pr,0x47);
  7055. temp |= 0x80; /* Use internal VSYNC */
  7056. SiS_SetCH701x(SiS_Pr,0x47,temp);
  7057. SiS_SetCH701x(SiS_Pr,0x49,temp1);
  7058. }
  7059. static void
  7060. SiS_Chrontel701xOn(struct SiS_Private *SiS_Pr)
  7061. {
  7062. unsigned short temp;
  7063. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  7064. if(SiS_Pr->ChipType == SIS_740) {
  7065. temp = SiS_GetCH701x(SiS_Pr,0x1c);
  7066. temp |= 0x04; /* Invert XCLK phase */
  7067. SiS_SetCH701x(SiS_Pr,0x1c,temp);
  7068. }
  7069. if(SiS_IsYPbPr(SiS_Pr)) {
  7070. temp = SiS_GetCH701x(SiS_Pr,0x01);
  7071. temp &= 0x3f;
  7072. temp |= 0x80; /* Enable YPrPb (HDTV) */
  7073. SiS_SetCH701x(SiS_Pr,0x01,temp);
  7074. }
  7075. if(SiS_IsChScart(SiS_Pr)) {
  7076. temp = SiS_GetCH701x(SiS_Pr,0x01);
  7077. temp &= 0x3f;
  7078. temp |= 0xc0; /* Enable SCART + CVBS */
  7079. SiS_SetCH701x(SiS_Pr,0x01,temp);
  7080. }
  7081. if(SiS_Pr->ChipType == SIS_740) {
  7082. SiS_ChrontelResetVSync(SiS_Pr);
  7083. SiS_SetCH701x(SiS_Pr,0x49,0x20); /* Enable TV path */
  7084. } else {
  7085. SiS_SetCH701x(SiS_Pr,0x49,0x20); /* Enable TV path */
  7086. temp = SiS_GetCH701x(SiS_Pr,0x49);
  7087. if(SiS_IsYPbPr(SiS_Pr)) {
  7088. temp = SiS_GetCH701x(SiS_Pr,0x73);
  7089. temp |= 0x60;
  7090. SiS_SetCH701x(SiS_Pr,0x73,temp);
  7091. }
  7092. temp = SiS_GetCH701x(SiS_Pr,0x47);
  7093. temp &= 0x7f;
  7094. SiS_SetCH701x(SiS_Pr,0x47,temp);
  7095. SiS_LongDelay(SiS_Pr, 2);
  7096. temp = SiS_GetCH701x(SiS_Pr,0x47);
  7097. temp |= 0x80;
  7098. SiS_SetCH701x(SiS_Pr,0x47,temp);
  7099. }
  7100. }
  7101. }
  7102. static void
  7103. SiS_Chrontel701xOff(struct SiS_Private *SiS_Pr)
  7104. {
  7105. unsigned short temp;
  7106. /* Complete power down of LVDS */
  7107. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  7108. if(SiS_Pr->ChipType == SIS_740) {
  7109. SiS_LongDelay(SiS_Pr, 1);
  7110. SiS_GenericDelay(SiS_Pr, 5887);
  7111. SiS_SetCH701x(SiS_Pr,0x76,0xac);
  7112. SiS_SetCH701x(SiS_Pr,0x66,0x00);
  7113. } else {
  7114. SiS_LongDelay(SiS_Pr, 2);
  7115. temp = SiS_GetCH701x(SiS_Pr,0x76);
  7116. temp &= 0xfc;
  7117. SiS_SetCH701x(SiS_Pr,0x76,temp);
  7118. SiS_SetCH701x(SiS_Pr,0x66,0x00);
  7119. }
  7120. }
  7121. }
  7122. static void
  7123. SiS_ChrontelResetDB(struct SiS_Private *SiS_Pr)
  7124. {
  7125. unsigned short temp;
  7126. if(SiS_Pr->ChipType == SIS_740) {
  7127. temp = SiS_GetCH701x(SiS_Pr,0x4a); /* Version ID */
  7128. temp &= 0x01;
  7129. if(!temp) {
  7130. if(SiS_WeHaveBacklightCtrl(SiS_Pr)) {
  7131. temp = SiS_GetCH701x(SiS_Pr,0x49);
  7132. SiS_SetCH701x(SiS_Pr,0x49,0x3e);
  7133. }
  7134. /* Reset Chrontel 7019 datapath */
  7135. SiS_SetCH701x(SiS_Pr,0x48,0x10);
  7136. SiS_LongDelay(SiS_Pr, 1);
  7137. SiS_SetCH701x(SiS_Pr,0x48,0x18);
  7138. if(SiS_WeHaveBacklightCtrl(SiS_Pr)) {
  7139. SiS_ChrontelResetVSync(SiS_Pr);
  7140. SiS_SetCH701x(SiS_Pr,0x49,temp);
  7141. }
  7142. } else {
  7143. /* Clear/set/clear GPIO */
  7144. temp = SiS_GetCH701x(SiS_Pr,0x5c);
  7145. temp &= 0xef;
  7146. SiS_SetCH701x(SiS_Pr,0x5c,temp);
  7147. temp = SiS_GetCH701x(SiS_Pr,0x5c);
  7148. temp |= 0x10;
  7149. SiS_SetCH701x(SiS_Pr,0x5c,temp);
  7150. temp = SiS_GetCH701x(SiS_Pr,0x5c);
  7151. temp &= 0xef;
  7152. SiS_SetCH701x(SiS_Pr,0x5c,temp);
  7153. temp = SiS_GetCH701x(SiS_Pr,0x61);
  7154. if(!temp) {
  7155. SiS_SetCH701xForLCD(SiS_Pr);
  7156. }
  7157. }
  7158. } else { /* 650 */
  7159. /* Reset Chrontel 7019 datapath */
  7160. SiS_SetCH701x(SiS_Pr,0x48,0x10);
  7161. SiS_LongDelay(SiS_Pr, 1);
  7162. SiS_SetCH701x(SiS_Pr,0x48,0x18);
  7163. }
  7164. }
  7165. static void
  7166. SiS_ChrontelInitTVVSync(struct SiS_Private *SiS_Pr)
  7167. {
  7168. unsigned short temp;
  7169. if(SiS_Pr->ChipType == SIS_740) {
  7170. if(SiS_WeHaveBacklightCtrl(SiS_Pr)) {
  7171. SiS_ChrontelResetVSync(SiS_Pr);
  7172. }
  7173. } else {
  7174. SiS_SetCH701x(SiS_Pr,0x76,0xaf); /* Power up LVDS block */
  7175. temp = SiS_GetCH701x(SiS_Pr,0x49);
  7176. temp &= 1;
  7177. if(temp != 1) { /* TV block powered? (0 = yes, 1 = no) */
  7178. temp = SiS_GetCH701x(SiS_Pr,0x47);
  7179. temp &= 0x70;
  7180. SiS_SetCH701x(SiS_Pr,0x47,temp); /* enable VSYNC */
  7181. SiS_LongDelay(SiS_Pr, 3);
  7182. temp = SiS_GetCH701x(SiS_Pr,0x47);
  7183. temp |= 0x80;
  7184. SiS_SetCH701x(SiS_Pr,0x47,temp); /* disable VSYNC */
  7185. }
  7186. }
  7187. }
  7188. static void
  7189. SiS_ChrontelDoSomething3(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
  7190. {
  7191. unsigned short temp,temp1;
  7192. if(SiS_Pr->ChipType == SIS_740) {
  7193. temp = SiS_GetCH701x(SiS_Pr,0x61);
  7194. if(temp < 1) {
  7195. temp++;
  7196. SiS_SetCH701x(SiS_Pr,0x61,temp);
  7197. }
  7198. SiS_SetCH701x(SiS_Pr,0x66,0x45); /* Panel power on */
  7199. SiS_SetCH701x(SiS_Pr,0x76,0xaf); /* All power on */
  7200. SiS_LongDelay(SiS_Pr, 1);
  7201. SiS_GenericDelay(SiS_Pr, 5887);
  7202. } else { /* 650 */
  7203. temp1 = 0;
  7204. temp = SiS_GetCH701x(SiS_Pr,0x61);
  7205. if(temp < 2) {
  7206. temp++;
  7207. SiS_SetCH701x(SiS_Pr,0x61,temp);
  7208. temp1 = 1;
  7209. }
  7210. SiS_SetCH701x(SiS_Pr,0x76,0xac);
  7211. temp = SiS_GetCH701x(SiS_Pr,0x66);
  7212. temp |= 0x5f;
  7213. SiS_SetCH701x(SiS_Pr,0x66,temp);
  7214. if(ModeNo > 0x13) {
  7215. if(SiS_WeHaveBacklightCtrl(SiS_Pr)) {
  7216. SiS_GenericDelay(SiS_Pr, 1023);
  7217. } else {
  7218. SiS_GenericDelay(SiS_Pr, 767);
  7219. }
  7220. } else {
  7221. if(!temp1)
  7222. SiS_GenericDelay(SiS_Pr, 767);
  7223. }
  7224. temp = SiS_GetCH701x(SiS_Pr,0x76);
  7225. temp |= 0x03;
  7226. SiS_SetCH701x(SiS_Pr,0x76,temp);
  7227. temp = SiS_GetCH701x(SiS_Pr,0x66);
  7228. temp &= 0x7f;
  7229. SiS_SetCH701x(SiS_Pr,0x66,temp);
  7230. SiS_LongDelay(SiS_Pr, 1);
  7231. }
  7232. }
  7233. static void
  7234. SiS_ChrontelDoSomething2(struct SiS_Private *SiS_Pr)
  7235. {
  7236. unsigned short temp;
  7237. SiS_LongDelay(SiS_Pr, 1);
  7238. do {
  7239. temp = SiS_GetCH701x(SiS_Pr,0x66);
  7240. temp &= 0x04; /* PLL stable? -> bail out */
  7241. if(temp == 0x04) break;
  7242. if(SiS_Pr->ChipType == SIS_740) {
  7243. /* Power down LVDS output, PLL normal operation */
  7244. SiS_SetCH701x(SiS_Pr,0x76,0xac);
  7245. }
  7246. SiS_SetCH701xForLCD(SiS_Pr);
  7247. temp = SiS_GetCH701x(SiS_Pr,0x76);
  7248. temp &= 0xfb; /* Reset PLL */
  7249. SiS_SetCH701x(SiS_Pr,0x76,temp);
  7250. SiS_LongDelay(SiS_Pr, 2);
  7251. temp = SiS_GetCH701x(SiS_Pr,0x76);
  7252. temp |= 0x04; /* PLL normal operation */
  7253. SiS_SetCH701x(SiS_Pr,0x76,temp);
  7254. if(SiS_Pr->ChipType == SIS_740) {
  7255. SiS_SetCH701x(SiS_Pr,0x78,0xe0); /* PLL loop filter */
  7256. } else {
  7257. SiS_SetCH701x(SiS_Pr,0x78,0x60);
  7258. }
  7259. SiS_LongDelay(SiS_Pr, 2);
  7260. } while(0);
  7261. SiS_SetCH701x(SiS_Pr,0x77,0x00); /* MV? */
  7262. }
  7263. static void
  7264. SiS_ChrontelDoSomething1(struct SiS_Private *SiS_Pr)
  7265. {
  7266. unsigned short temp;
  7267. temp = SiS_GetCH701x(SiS_Pr,0x03);
  7268. temp |= 0x80; /* Set datapath 1 to TV */
  7269. temp &= 0xbf; /* Set datapath 2 to LVDS */
  7270. SiS_SetCH701x(SiS_Pr,0x03,temp);
  7271. if(SiS_Pr->ChipType == SIS_740) {
  7272. temp = SiS_GetCH701x(SiS_Pr,0x1c);
  7273. temp &= 0xfb; /* Normal XCLK phase */
  7274. SiS_SetCH701x(SiS_Pr,0x1c,temp);
  7275. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2d,0x03);
  7276. temp = SiS_GetCH701x(SiS_Pr,0x64);
  7277. temp |= 0x40; /* ? Bit not defined */
  7278. SiS_SetCH701x(SiS_Pr,0x64,temp);
  7279. temp = SiS_GetCH701x(SiS_Pr,0x03);
  7280. temp &= 0x3f; /* D1 input to both LVDS and TV */
  7281. SiS_SetCH701x(SiS_Pr,0x03,temp);
  7282. if(SiS_Pr->SiS_CustomT == CUT_ASUSL3000D) {
  7283. SiS_SetCH701x(SiS_Pr,0x63,0x40); /* LVDS off */
  7284. SiS_LongDelay(SiS_Pr, 1);
  7285. SiS_SetCH701x(SiS_Pr,0x63,0x00); /* LVDS on */
  7286. SiS_ChrontelResetDB(SiS_Pr);
  7287. SiS_ChrontelDoSomething2(SiS_Pr);
  7288. SiS_ChrontelDoSomething3(SiS_Pr, 0);
  7289. } else {
  7290. temp = SiS_GetCH701x(SiS_Pr,0x66);
  7291. if(temp != 0x45) {
  7292. SiS_ChrontelResetDB(SiS_Pr);
  7293. SiS_ChrontelDoSomething2(SiS_Pr);
  7294. SiS_ChrontelDoSomething3(SiS_Pr, 0);
  7295. }
  7296. }
  7297. } else { /* 650 */
  7298. SiS_ChrontelResetDB(SiS_Pr);
  7299. SiS_ChrontelDoSomething2(SiS_Pr);
  7300. temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x34);
  7301. SiS_ChrontelDoSomething3(SiS_Pr,temp);
  7302. SiS_SetCH701x(SiS_Pr,0x76,0xaf); /* All power on, LVDS normal operation */
  7303. }
  7304. }
  7305. #endif /* 315 series */
  7306. /*********************************************/
  7307. /* MAIN: SET CRT2 REGISTER GROUP */
  7308. /*********************************************/
  7309. bool
  7310. SiS_SetCRT2Group(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
  7311. {
  7312. #ifdef SIS300
  7313. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  7314. #endif
  7315. unsigned short ModeIdIndex, RefreshRateTableIndex;
  7316. SiS_Pr->SiS_SetFlag |= ProgrammingCRT2;
  7317. if(!SiS_Pr->UseCustomMode) {
  7318. SiS_SearchModeID(SiS_Pr, &ModeNo, &ModeIdIndex);
  7319. } else {
  7320. ModeIdIndex = 0;
  7321. }
  7322. /* Used for shifting CR33 */
  7323. SiS_Pr->SiS_SelectCRT2Rate = 4;
  7324. SiS_UnLockCRT2(SiS_Pr);
  7325. RefreshRateTableIndex = SiS_GetRatePtr(SiS_Pr, ModeNo, ModeIdIndex);
  7326. SiS_SaveCRT2Info(SiS_Pr,ModeNo);
  7327. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7328. SiS_DisableBridge(SiS_Pr);
  7329. if((SiS_Pr->SiS_IF_DEF_LVDS == 1) && (SiS_Pr->ChipType == SIS_730)) {
  7330. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x00,0x80);
  7331. }
  7332. SiS_SetCRT2ModeRegs(SiS_Pr, ModeNo, ModeIdIndex);
  7333. }
  7334. if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) {
  7335. SiS_LockCRT2(SiS_Pr);
  7336. SiS_DisplayOn(SiS_Pr);
  7337. return true;
  7338. }
  7339. SiS_GetCRT2Data(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7340. /* Set up Panel Link for LVDS and LCDA */
  7341. SiS_Pr->SiS_LCDHDES = SiS_Pr->SiS_LCDVDES = 0;
  7342. if( (SiS_Pr->SiS_IF_DEF_LVDS == 1) ||
  7343. ((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) ||
  7344. ((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->SiS_VBType & VB_SIS30xBLV)) ) {
  7345. SiS_GetLVDSDesData(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7346. }
  7347. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7348. SiS_SetGroup1(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7349. }
  7350. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  7351. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7352. SiS_SetGroup2(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7353. #ifdef SIS315H
  7354. SiS_SetGroup2_C_ELV(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7355. #endif
  7356. SiS_SetGroup3(SiS_Pr, ModeNo, ModeIdIndex);
  7357. SiS_SetGroup4(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7358. #ifdef SIS315H
  7359. SiS_SetGroup4_C_ELV(SiS_Pr, ModeNo, ModeIdIndex);
  7360. #endif
  7361. SiS_SetGroup5(SiS_Pr, ModeNo, ModeIdIndex);
  7362. SiS_SetCRT2Sync(SiS_Pr, ModeNo, RefreshRateTableIndex);
  7363. /* For 301BDH (Panel link initialization): */
  7364. if((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) {
  7365. if(!((SiS_Pr->SiS_SetFlag & SetDOSMode) && ((ModeNo == 0x03) || (ModeNo == 0x10)))) {
  7366. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
  7367. SiS_ModCRT1CRTC(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7368. }
  7369. }
  7370. SiS_SetCRT2ECLK(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7371. }
  7372. }
  7373. } else {
  7374. SiS_SetCRT2Sync(SiS_Pr, ModeNo, RefreshRateTableIndex);
  7375. SiS_ModCRT1CRTC(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex);
  7376. SiS_SetCRT2ECLK(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex);
  7377. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7378. if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
  7379. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  7380. if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {
  7381. #ifdef SIS315H
  7382. SiS_SetCH701xForLCD(SiS_Pr);
  7383. #endif
  7384. }
  7385. }
  7386. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  7387. SiS_SetCHTVReg(SiS_Pr,ModeNo,ModeIdIndex,RefreshRateTableIndex);
  7388. }
  7389. }
  7390. }
  7391. }
  7392. #ifdef SIS300
  7393. if(SiS_Pr->ChipType < SIS_315H) {
  7394. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7395. if(SiS_Pr->SiS_UseOEM) {
  7396. if((SiS_Pr->SiS_UseROM) && (SiS_Pr->SiS_UseOEM == -1)) {
  7397. if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) {
  7398. SiS_OEM300Setting(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7399. }
  7400. } else {
  7401. SiS_OEM300Setting(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7402. }
  7403. }
  7404. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  7405. if((SiS_Pr->SiS_CustomT == CUT_BARCO1366) ||
  7406. (SiS_Pr->SiS_CustomT == CUT_BARCO1024)) {
  7407. SetOEMLCDData2(SiS_Pr, ModeNo, ModeIdIndex,RefreshRateTableIndex);
  7408. }
  7409. SiS_DisplayOn(SiS_Pr);
  7410. }
  7411. }
  7412. }
  7413. #endif
  7414. #ifdef SIS315H
  7415. if(SiS_Pr->ChipType >= SIS_315H) {
  7416. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7417. if(SiS_Pr->ChipType < SIS_661) {
  7418. SiS_FinalizeLCD(SiS_Pr, ModeNo, ModeIdIndex);
  7419. SiS_OEM310Setting(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7420. } else {
  7421. SiS_OEM661Setting(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
  7422. }
  7423. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x01,0x40);
  7424. }
  7425. }
  7426. #endif
  7427. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7428. SiS_EnableBridge(SiS_Pr);
  7429. }
  7430. SiS_DisplayOn(SiS_Pr);
  7431. if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) {
  7432. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  7433. /* Disable LCD panel when using TV */
  7434. SiS_SetRegSR11ANDOR(SiS_Pr,0xFF,0x0C);
  7435. } else {
  7436. /* Disable TV when using LCD */
  7437. SiS_SetCH70xxANDOR(SiS_Pr,0x0e,0x01,0xf8);
  7438. }
  7439. }
  7440. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  7441. SiS_LockCRT2(SiS_Pr);
  7442. }
  7443. return true;
  7444. }
  7445. /*********************************************/
  7446. /* ENABLE/DISABLE LCD BACKLIGHT (SIS) */
  7447. /*********************************************/
  7448. void
  7449. SiS_SiS30xBLOn(struct SiS_Private *SiS_Pr)
  7450. {
  7451. /* Switch on LCD backlight on SiS30xLV */
  7452. SiS_DDC2Delay(SiS_Pr,0xff00);
  7453. if(!(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x26) & 0x02)) {
  7454. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x02);
  7455. SiS_WaitVBRetrace(SiS_Pr);
  7456. }
  7457. if(!(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x26) & 0x01)) {
  7458. SiS_SetRegOR(SiS_Pr->SiS_Part4Port,0x26,0x01);
  7459. }
  7460. }
  7461. void
  7462. SiS_SiS30xBLOff(struct SiS_Private *SiS_Pr)
  7463. {
  7464. /* Switch off LCD backlight on SiS30xLV */
  7465. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x26,0xFE);
  7466. SiS_DDC2Delay(SiS_Pr,0xff00);
  7467. }
  7468. /*********************************************/
  7469. /* DDC RELATED FUNCTIONS */
  7470. /*********************************************/
  7471. static void
  7472. SiS_SetupDDCN(struct SiS_Private *SiS_Pr)
  7473. {
  7474. SiS_Pr->SiS_DDC_NData = ~SiS_Pr->SiS_DDC_Data;
  7475. SiS_Pr->SiS_DDC_NClk = ~SiS_Pr->SiS_DDC_Clk;
  7476. if((SiS_Pr->SiS_DDC_Index == 0x11) && (SiS_Pr->SiS_SensibleSR11)) {
  7477. SiS_Pr->SiS_DDC_NData &= 0x0f;
  7478. SiS_Pr->SiS_DDC_NClk &= 0x0f;
  7479. }
  7480. }
  7481. #ifdef SIS300
  7482. static unsigned char *
  7483. SiS_SetTrumpBlockLoop(struct SiS_Private *SiS_Pr, unsigned char *dataptr)
  7484. {
  7485. int i, j, num;
  7486. unsigned short tempah,temp;
  7487. unsigned char *mydataptr;
  7488. for(i=0; i<20; i++) { /* Do 20 attempts to write */
  7489. mydataptr = dataptr;
  7490. num = *mydataptr++;
  7491. if(!num) return mydataptr;
  7492. if(i) {
  7493. SiS_SetStop(SiS_Pr);
  7494. SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT * 2);
  7495. }
  7496. if(SiS_SetStart(SiS_Pr)) continue; /* Set start condition */
  7497. tempah = SiS_Pr->SiS_DDC_DeviceAddr;
  7498. temp = SiS_WriteDDC2Data(SiS_Pr,tempah); /* Write DAB (S0=0=write) */
  7499. if(temp) continue; /* (ERROR: no ack) */
  7500. tempah = *mydataptr++;
  7501. temp = SiS_WriteDDC2Data(SiS_Pr,tempah); /* Write register number */
  7502. if(temp) continue; /* (ERROR: no ack) */
  7503. for(j=0; j<num; j++) {
  7504. tempah = *mydataptr++;
  7505. temp = SiS_WriteDDC2Data(SiS_Pr,tempah);/* Write DAB (S0=0=write) */
  7506. if(temp) break;
  7507. }
  7508. if(temp) continue;
  7509. if(SiS_SetStop(SiS_Pr)) continue;
  7510. return mydataptr;
  7511. }
  7512. return NULL;
  7513. }
  7514. static bool
  7515. SiS_SetTrumpionBlock(struct SiS_Private *SiS_Pr, unsigned char *dataptr)
  7516. {
  7517. SiS_Pr->SiS_DDC_DeviceAddr = 0xF0; /* DAB (Device Address Byte) */
  7518. SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */
  7519. SiS_Pr->SiS_DDC_Data = 0x02; /* Bitmask in IndexReg for Data */
  7520. SiS_Pr->SiS_DDC_Clk = 0x01; /* Bitmask in IndexReg for Clk */
  7521. SiS_SetupDDCN(SiS_Pr);
  7522. SiS_SetSwitchDDC2(SiS_Pr);
  7523. while(*dataptr) {
  7524. dataptr = SiS_SetTrumpBlockLoop(SiS_Pr, dataptr);
  7525. if(!dataptr) return false;
  7526. }
  7527. return true;
  7528. }
  7529. #endif
  7530. /* The Chrontel 700x is connected to the 630/730 via
  7531. * the 630/730's DDC/I2C port.
  7532. *
  7533. * On 630(S)T chipset, the index changed from 0x11 to
  7534. * 0x0a, possibly for working around the DDC problems
  7535. */
  7536. static bool
  7537. SiS_SetChReg(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val, unsigned short myor)
  7538. {
  7539. unsigned short temp, i;
  7540. for(i=0; i<20; i++) { /* Do 20 attempts to write */
  7541. if(i) {
  7542. SiS_SetStop(SiS_Pr);
  7543. SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT * 4);
  7544. }
  7545. if(SiS_SetStart(SiS_Pr)) continue; /* Set start condition */
  7546. temp = SiS_WriteDDC2Data(SiS_Pr, SiS_Pr->SiS_DDC_DeviceAddr); /* Write DAB (S0=0=write) */
  7547. if(temp) continue; /* (ERROR: no ack) */
  7548. temp = SiS_WriteDDC2Data(SiS_Pr, (reg | myor)); /* Write RAB (700x: set bit 7, see datasheet) */
  7549. if(temp) continue; /* (ERROR: no ack) */
  7550. temp = SiS_WriteDDC2Data(SiS_Pr, val); /* Write data */
  7551. if(temp) continue; /* (ERROR: no ack) */
  7552. if(SiS_SetStop(SiS_Pr)) continue; /* Set stop condition */
  7553. SiS_Pr->SiS_ChrontelInit = 1;
  7554. return true;
  7555. }
  7556. return false;
  7557. }
  7558. /* Write to Chrontel 700x */
  7559. void
  7560. SiS_SetCH700x(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val)
  7561. {
  7562. SiS_Pr->SiS_DDC_DeviceAddr = 0xEA; /* DAB (Device Address Byte) */
  7563. SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT);
  7564. if(!(SiS_Pr->SiS_ChrontelInit)) {
  7565. SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */
  7566. SiS_Pr->SiS_DDC_Data = 0x02; /* Bitmask in IndexReg for Data */
  7567. SiS_Pr->SiS_DDC_Clk = 0x01; /* Bitmask in IndexReg for Clk */
  7568. SiS_SetupDDCN(SiS_Pr);
  7569. }
  7570. if( (!(SiS_SetChReg(SiS_Pr, reg, val, 0x80))) &&
  7571. (!(SiS_Pr->SiS_ChrontelInit)) ) {
  7572. SiS_Pr->SiS_DDC_Index = 0x0a;
  7573. SiS_Pr->SiS_DDC_Data = 0x80;
  7574. SiS_Pr->SiS_DDC_Clk = 0x40;
  7575. SiS_SetupDDCN(SiS_Pr);
  7576. SiS_SetChReg(SiS_Pr, reg, val, 0x80);
  7577. }
  7578. }
  7579. /* Write to Chrontel 701x */
  7580. /* Parameter is [Data (S15-S8) | Register no (S7-S0)] */
  7581. void
  7582. SiS_SetCH701x(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val)
  7583. {
  7584. SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */
  7585. SiS_Pr->SiS_DDC_Data = 0x08; /* Bitmask in IndexReg for Data */
  7586. SiS_Pr->SiS_DDC_Clk = 0x04; /* Bitmask in IndexReg for Clk */
  7587. SiS_SetupDDCN(SiS_Pr);
  7588. SiS_Pr->SiS_DDC_DeviceAddr = 0xEA; /* DAB (Device Address Byte) */
  7589. SiS_SetChReg(SiS_Pr, reg, val, 0);
  7590. }
  7591. static
  7592. void
  7593. SiS_SetCH70xx(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val)
  7594. {
  7595. if(SiS_Pr->SiS_IF_DEF_CH70xx == 1)
  7596. SiS_SetCH700x(SiS_Pr, reg, val);
  7597. else
  7598. SiS_SetCH701x(SiS_Pr, reg, val);
  7599. }
  7600. static unsigned short
  7601. SiS_GetChReg(struct SiS_Private *SiS_Pr, unsigned short myor)
  7602. {
  7603. unsigned short tempah, temp, i;
  7604. for(i=0; i<20; i++) { /* Do 20 attempts to read */
  7605. if(i) {
  7606. SiS_SetStop(SiS_Pr);
  7607. SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT * 4);
  7608. }
  7609. if(SiS_SetStart(SiS_Pr)) continue; /* Set start condition */
  7610. temp = SiS_WriteDDC2Data(SiS_Pr,SiS_Pr->SiS_DDC_DeviceAddr); /* Write DAB (S0=0=write) */
  7611. if(temp) continue; /* (ERROR: no ack) */
  7612. temp = SiS_WriteDDC2Data(SiS_Pr,SiS_Pr->SiS_DDC_ReadAddr | myor); /* Write RAB (700x: | 0x80) */
  7613. if(temp) continue; /* (ERROR: no ack) */
  7614. if (SiS_SetStart(SiS_Pr)) continue; /* Re-start */
  7615. temp = SiS_WriteDDC2Data(SiS_Pr,SiS_Pr->SiS_DDC_DeviceAddr | 0x01);/* DAB (S0=1=read) */
  7616. if(temp) continue; /* (ERROR: no ack) */
  7617. tempah = SiS_ReadDDC2Data(SiS_Pr); /* Read byte */
  7618. if(SiS_SetStop(SiS_Pr)) continue; /* Stop condition */
  7619. SiS_Pr->SiS_ChrontelInit = 1;
  7620. return tempah;
  7621. }
  7622. return 0xFFFF;
  7623. }
  7624. /* Read from Chrontel 700x */
  7625. /* Parameter is [Register no (S7-S0)] */
  7626. unsigned short
  7627. SiS_GetCH700x(struct SiS_Private *SiS_Pr, unsigned short tempbx)
  7628. {
  7629. unsigned short result;
  7630. SiS_Pr->SiS_DDC_DeviceAddr = 0xEA; /* DAB */
  7631. SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT);
  7632. if(!(SiS_Pr->SiS_ChrontelInit)) {
  7633. SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */
  7634. SiS_Pr->SiS_DDC_Data = 0x02; /* Bitmask in IndexReg for Data */
  7635. SiS_Pr->SiS_DDC_Clk = 0x01; /* Bitmask in IndexReg for Clk */
  7636. SiS_SetupDDCN(SiS_Pr);
  7637. }
  7638. SiS_Pr->SiS_DDC_ReadAddr = tempbx;
  7639. if( ((result = SiS_GetChReg(SiS_Pr,0x80)) == 0xFFFF) &&
  7640. (!SiS_Pr->SiS_ChrontelInit) ) {
  7641. SiS_Pr->SiS_DDC_Index = 0x0a;
  7642. SiS_Pr->SiS_DDC_Data = 0x80;
  7643. SiS_Pr->SiS_DDC_Clk = 0x40;
  7644. SiS_SetupDDCN(SiS_Pr);
  7645. result = SiS_GetChReg(SiS_Pr,0x80);
  7646. }
  7647. return result;
  7648. }
  7649. /* Read from Chrontel 701x */
  7650. /* Parameter is [Register no (S7-S0)] */
  7651. unsigned short
  7652. SiS_GetCH701x(struct SiS_Private *SiS_Pr, unsigned short tempbx)
  7653. {
  7654. SiS_Pr->SiS_DDC_Index = 0x11; /* Bit 0 = SC; Bit 1 = SD */
  7655. SiS_Pr->SiS_DDC_Data = 0x08; /* Bitmask in IndexReg for Data */
  7656. SiS_Pr->SiS_DDC_Clk = 0x04; /* Bitmask in IndexReg for Clk */
  7657. SiS_SetupDDCN(SiS_Pr);
  7658. SiS_Pr->SiS_DDC_DeviceAddr = 0xEA; /* DAB */
  7659. SiS_Pr->SiS_DDC_ReadAddr = tempbx;
  7660. return SiS_GetChReg(SiS_Pr,0);
  7661. }
  7662. /* Read from Chrontel 70xx */
  7663. /* Parameter is [Register no (S7-S0)] */
  7664. static
  7665. unsigned short
  7666. SiS_GetCH70xx(struct SiS_Private *SiS_Pr, unsigned short tempbx)
  7667. {
  7668. if(SiS_Pr->SiS_IF_DEF_CH70xx == 1)
  7669. return SiS_GetCH700x(SiS_Pr, tempbx);
  7670. else
  7671. return SiS_GetCH701x(SiS_Pr, tempbx);
  7672. }
  7673. void
  7674. SiS_SetCH70xxANDOR(struct SiS_Private *SiS_Pr, unsigned short reg,
  7675. unsigned char myor, unsigned short myand)
  7676. {
  7677. unsigned short tempbl;
  7678. tempbl = (SiS_GetCH70xx(SiS_Pr, (reg & 0xFF)) & myand) | myor;
  7679. SiS_SetCH70xx(SiS_Pr, reg, tempbl);
  7680. }
  7681. /* Our own DDC functions */
  7682. static
  7683. unsigned short
  7684. SiS_InitDDCRegs(struct SiS_Private *SiS_Pr, unsigned int VBFlags, int VGAEngine,
  7685. unsigned short adaptnum, unsigned short DDCdatatype, bool checkcr32,
  7686. unsigned int VBFlags2)
  7687. {
  7688. unsigned char ddcdtype[] = { 0xa0, 0xa0, 0xa0, 0xa2, 0xa6 };
  7689. unsigned char flag, cr32;
  7690. unsigned short temp = 0, myadaptnum = adaptnum;
  7691. if(adaptnum != 0) {
  7692. if(!(VBFlags2 & VB2_SISTMDSBRIDGE)) return 0xFFFF;
  7693. if((VBFlags2 & VB2_30xBDH) && (adaptnum == 1)) return 0xFFFF;
  7694. }
  7695. /* adapternum for SiS bridges: 0 = CRT1, 1 = LCD, 2 = VGA2 */
  7696. SiS_Pr->SiS_ChrontelInit = 0; /* force re-detection! */
  7697. SiS_Pr->SiS_DDC_SecAddr = 0;
  7698. SiS_Pr->SiS_DDC_DeviceAddr = ddcdtype[DDCdatatype];
  7699. SiS_Pr->SiS_DDC_Port = SiS_Pr->SiS_P3c4;
  7700. SiS_Pr->SiS_DDC_Index = 0x11;
  7701. flag = 0xff;
  7702. cr32 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x32);
  7703. #if 0
  7704. if(VBFlags2 & VB2_SISBRIDGE) {
  7705. if(myadaptnum == 0) {
  7706. if(!(cr32 & 0x20)) {
  7707. myadaptnum = 2;
  7708. if(!(cr32 & 0x10)) {
  7709. myadaptnum = 1;
  7710. if(!(cr32 & 0x08)) {
  7711. myadaptnum = 0;
  7712. }
  7713. }
  7714. }
  7715. }
  7716. }
  7717. #endif
  7718. if(VGAEngine == SIS_300_VGA) { /* 300 series */
  7719. if(myadaptnum != 0) {
  7720. flag = 0;
  7721. if(VBFlags2 & VB2_SISBRIDGE) {
  7722. SiS_Pr->SiS_DDC_Port = SiS_Pr->SiS_Part4Port;
  7723. SiS_Pr->SiS_DDC_Index = 0x0f;
  7724. }
  7725. }
  7726. if(!(VBFlags2 & VB2_301)) {
  7727. if((cr32 & 0x80) && (checkcr32)) {
  7728. if(myadaptnum >= 1) {
  7729. if(!(cr32 & 0x08)) {
  7730. myadaptnum = 1;
  7731. if(!(cr32 & 0x10)) return 0xFFFF;
  7732. }
  7733. }
  7734. }
  7735. }
  7736. temp = 4 - (myadaptnum * 2);
  7737. if(flag) temp = 0;
  7738. } else { /* 315/330 series */
  7739. /* here we simplify: 0 = CRT1, 1 = CRT2 (VGA, LCD) */
  7740. if(VBFlags2 & VB2_SISBRIDGE) {
  7741. if(myadaptnum == 2) {
  7742. myadaptnum = 1;
  7743. }
  7744. }
  7745. if(myadaptnum == 1) {
  7746. flag = 0;
  7747. if(VBFlags2 & VB2_SISBRIDGE) {
  7748. SiS_Pr->SiS_DDC_Port = SiS_Pr->SiS_Part4Port;
  7749. SiS_Pr->SiS_DDC_Index = 0x0f;
  7750. }
  7751. }
  7752. if((cr32 & 0x80) && (checkcr32)) {
  7753. if(myadaptnum >= 1) {
  7754. if(!(cr32 & 0x08)) {
  7755. myadaptnum = 1;
  7756. if(!(cr32 & 0x10)) return 0xFFFF;
  7757. }
  7758. }
  7759. }
  7760. temp = myadaptnum;
  7761. if(myadaptnum == 1) {
  7762. temp = 0;
  7763. if(VBFlags2 & VB2_LVDS) flag = 0xff;
  7764. }
  7765. if(flag) temp = 0;
  7766. }
  7767. SiS_Pr->SiS_DDC_Data = 0x02 << temp;
  7768. SiS_Pr->SiS_DDC_Clk = 0x01 << temp;
  7769. SiS_SetupDDCN(SiS_Pr);
  7770. return 0;
  7771. }
  7772. static unsigned short
  7773. SiS_WriteDABDDC(struct SiS_Private *SiS_Pr)
  7774. {
  7775. if(SiS_SetStart(SiS_Pr)) return 0xFFFF;
  7776. if(SiS_WriteDDC2Data(SiS_Pr, SiS_Pr->SiS_DDC_DeviceAddr)) {
  7777. return 0xFFFF;
  7778. }
  7779. if(SiS_WriteDDC2Data(SiS_Pr, SiS_Pr->SiS_DDC_SecAddr)) {
  7780. return 0xFFFF;
  7781. }
  7782. return 0;
  7783. }
  7784. static unsigned short
  7785. SiS_PrepareReadDDC(struct SiS_Private *SiS_Pr)
  7786. {
  7787. if(SiS_SetStart(SiS_Pr)) return 0xFFFF;
  7788. if(SiS_WriteDDC2Data(SiS_Pr, (SiS_Pr->SiS_DDC_DeviceAddr | 0x01))) {
  7789. return 0xFFFF;
  7790. }
  7791. return 0;
  7792. }
  7793. static unsigned short
  7794. SiS_PrepareDDC(struct SiS_Private *SiS_Pr)
  7795. {
  7796. if(SiS_WriteDABDDC(SiS_Pr)) SiS_WriteDABDDC(SiS_Pr);
  7797. if(SiS_PrepareReadDDC(SiS_Pr)) return (SiS_PrepareReadDDC(SiS_Pr));
  7798. return 0;
  7799. }
  7800. static void
  7801. SiS_SendACK(struct SiS_Private *SiS_Pr, unsigned short yesno)
  7802. {
  7803. SiS_SetSCLKLow(SiS_Pr);
  7804. if(yesno) {
  7805. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  7806. SiS_Pr->SiS_DDC_Index,
  7807. SiS_Pr->SiS_DDC_NData,
  7808. SiS_Pr->SiS_DDC_Data);
  7809. } else {
  7810. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  7811. SiS_Pr->SiS_DDC_Index,
  7812. SiS_Pr->SiS_DDC_NData,
  7813. 0);
  7814. }
  7815. SiS_SetSCLKHigh(SiS_Pr);
  7816. }
  7817. static unsigned short
  7818. SiS_DoProbeDDC(struct SiS_Private *SiS_Pr)
  7819. {
  7820. unsigned char mask, value;
  7821. unsigned short temp, ret=0;
  7822. bool failed = false;
  7823. SiS_SetSwitchDDC2(SiS_Pr);
  7824. if(SiS_PrepareDDC(SiS_Pr)) {
  7825. SiS_SetStop(SiS_Pr);
  7826. return 0xFFFF;
  7827. }
  7828. mask = 0xf0;
  7829. value = 0x20;
  7830. if(SiS_Pr->SiS_DDC_DeviceAddr == 0xa0) {
  7831. temp = (unsigned char)SiS_ReadDDC2Data(SiS_Pr);
  7832. SiS_SendACK(SiS_Pr, 0);
  7833. if(temp == 0) {
  7834. mask = 0xff;
  7835. value = 0xff;
  7836. } else {
  7837. failed = true;
  7838. ret = 0xFFFF;
  7839. }
  7840. }
  7841. if(!failed) {
  7842. temp = (unsigned char)SiS_ReadDDC2Data(SiS_Pr);
  7843. SiS_SendACK(SiS_Pr, 1);
  7844. temp &= mask;
  7845. if(temp == value) ret = 0;
  7846. else {
  7847. ret = 0xFFFF;
  7848. if(SiS_Pr->SiS_DDC_DeviceAddr == 0xa0) {
  7849. if(temp == 0x30) ret = 0;
  7850. }
  7851. }
  7852. }
  7853. SiS_SetStop(SiS_Pr);
  7854. return ret;
  7855. }
  7856. static
  7857. unsigned short
  7858. SiS_ProbeDDC(struct SiS_Private *SiS_Pr)
  7859. {
  7860. unsigned short flag;
  7861. flag = 0x180;
  7862. SiS_Pr->SiS_DDC_DeviceAddr = 0xa0;
  7863. if(!(SiS_DoProbeDDC(SiS_Pr))) flag |= 0x02;
  7864. SiS_Pr->SiS_DDC_DeviceAddr = 0xa2;
  7865. if(!(SiS_DoProbeDDC(SiS_Pr))) flag |= 0x08;
  7866. SiS_Pr->SiS_DDC_DeviceAddr = 0xa6;
  7867. if(!(SiS_DoProbeDDC(SiS_Pr))) flag |= 0x10;
  7868. if(!(flag & 0x1a)) flag = 0;
  7869. return flag;
  7870. }
  7871. static
  7872. unsigned short
  7873. SiS_ReadDDC(struct SiS_Private *SiS_Pr, unsigned short DDCdatatype, unsigned char *buffer)
  7874. {
  7875. unsigned short flag, length, i;
  7876. unsigned char chksum,gotcha;
  7877. if(DDCdatatype > 4) return 0xFFFF;
  7878. flag = 0;
  7879. SiS_SetSwitchDDC2(SiS_Pr);
  7880. if(!(SiS_PrepareDDC(SiS_Pr))) {
  7881. length = 127;
  7882. if(DDCdatatype != 1) length = 255;
  7883. chksum = 0;
  7884. gotcha = 0;
  7885. for(i=0; i<length; i++) {
  7886. buffer[i] = (unsigned char)SiS_ReadDDC2Data(SiS_Pr);
  7887. chksum += buffer[i];
  7888. gotcha |= buffer[i];
  7889. SiS_SendACK(SiS_Pr, 0);
  7890. }
  7891. buffer[i] = (unsigned char)SiS_ReadDDC2Data(SiS_Pr);
  7892. chksum += buffer[i];
  7893. SiS_SendACK(SiS_Pr, 1);
  7894. if(gotcha) flag = (unsigned short)chksum;
  7895. else flag = 0xFFFF;
  7896. } else {
  7897. flag = 0xFFFF;
  7898. }
  7899. SiS_SetStop(SiS_Pr);
  7900. return flag;
  7901. }
  7902. /* Our private DDC functions
  7903. It complies somewhat with the corresponding VESA function
  7904. in arguments and return values.
  7905. Since this is probably called before the mode is changed,
  7906. we use our pre-detected pSiS-values instead of SiS_Pr as
  7907. regards chipset and video bridge type.
  7908. Arguments:
  7909. adaptnum: 0=CRT1(analog), 1=CRT2/LCD(digital), 2=CRT2/VGA2(analog)
  7910. CRT2 DDC is only supported on SiS301, 301B, 301C, 302B.
  7911. LCDA is CRT1, but DDC is read from CRT2 port.
  7912. DDCdatatype: 0=Probe, 1=EDID, 2=EDID+VDIF, 3=EDID V2 (P&D), 4=EDID V2 (FPDI-2)
  7913. buffer: ptr to 256 data bytes which will be filled with read data.
  7914. Returns 0xFFFF if error, otherwise
  7915. if DDCdatatype > 0: Returns 0 if reading OK (included a correct checksum)
  7916. if DDCdatatype = 0: Returns supported DDC modes
  7917. */
  7918. unsigned short
  7919. SiS_HandleDDC(struct SiS_Private *SiS_Pr, unsigned int VBFlags, int VGAEngine,
  7920. unsigned short adaptnum, unsigned short DDCdatatype, unsigned char *buffer,
  7921. unsigned int VBFlags2)
  7922. {
  7923. unsigned char sr1f, cr17=1;
  7924. unsigned short result;
  7925. if(adaptnum > 2)
  7926. return 0xFFFF;
  7927. if(DDCdatatype > 4)
  7928. return 0xFFFF;
  7929. if((!(VBFlags2 & VB2_VIDEOBRIDGE)) && (adaptnum > 0))
  7930. return 0xFFFF;
  7931. if(SiS_InitDDCRegs(SiS_Pr, VBFlags, VGAEngine, adaptnum, DDCdatatype, false, VBFlags2) == 0xFFFF)
  7932. return 0xFFFF;
  7933. sr1f = SiS_GetReg(SiS_Pr->SiS_P3c4,0x1f);
  7934. SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x1f,0x3f,0x04);
  7935. if(VGAEngine == SIS_300_VGA) {
  7936. cr17 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x17) & 0x80;
  7937. if(!cr17) {
  7938. SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x17,0x80);
  7939. SiS_SetReg(SiS_Pr->SiS_P3c4,0x00,0x01);
  7940. SiS_SetReg(SiS_Pr->SiS_P3c4,0x00,0x03);
  7941. }
  7942. }
  7943. if((sr1f) || (!cr17)) {
  7944. SiS_WaitRetrace1(SiS_Pr);
  7945. SiS_WaitRetrace1(SiS_Pr);
  7946. SiS_WaitRetrace1(SiS_Pr);
  7947. SiS_WaitRetrace1(SiS_Pr);
  7948. }
  7949. if(DDCdatatype == 0) {
  7950. result = SiS_ProbeDDC(SiS_Pr);
  7951. } else {
  7952. result = SiS_ReadDDC(SiS_Pr, DDCdatatype, buffer);
  7953. if((!result) && (DDCdatatype == 1)) {
  7954. if((buffer[0] == 0x00) && (buffer[1] == 0xff) &&
  7955. (buffer[2] == 0xff) && (buffer[3] == 0xff) &&
  7956. (buffer[4] == 0xff) && (buffer[5] == 0xff) &&
  7957. (buffer[6] == 0xff) && (buffer[7] == 0x00) &&
  7958. (buffer[0x12] == 1)) {
  7959. if(!SiS_Pr->DDCPortMixup) {
  7960. if(adaptnum == 1) {
  7961. if(!(buffer[0x14] & 0x80)) result = 0xFFFE;
  7962. } else {
  7963. if(buffer[0x14] & 0x80) result = 0xFFFE;
  7964. }
  7965. }
  7966. }
  7967. }
  7968. }
  7969. SiS_SetReg(SiS_Pr->SiS_P3c4,0x1f,sr1f);
  7970. if(VGAEngine == SIS_300_VGA) {
  7971. SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x17,0x7f,cr17);
  7972. }
  7973. return result;
  7974. }
  7975. /* Generic I2C functions for Chrontel & DDC --------- */
  7976. static void
  7977. SiS_SetSwitchDDC2(struct SiS_Private *SiS_Pr)
  7978. {
  7979. SiS_SetSCLKHigh(SiS_Pr);
  7980. SiS_WaitRetrace1(SiS_Pr);
  7981. SiS_SetSCLKLow(SiS_Pr);
  7982. SiS_WaitRetrace1(SiS_Pr);
  7983. }
  7984. unsigned short
  7985. SiS_ReadDDC1Bit(struct SiS_Private *SiS_Pr)
  7986. {
  7987. SiS_WaitRetrace1(SiS_Pr);
  7988. return ((SiS_GetReg(SiS_Pr->SiS_P3c4,0x11) & 0x02) >> 1);
  7989. }
  7990. /* Set I2C start condition */
  7991. /* This is done by a SD high-to-low transition while SC is high */
  7992. static unsigned short
  7993. SiS_SetStart(struct SiS_Private *SiS_Pr)
  7994. {
  7995. if(SiS_SetSCLKLow(SiS_Pr)) return 0xFFFF; /* (SC->low) */
  7996. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  7997. SiS_Pr->SiS_DDC_Index,
  7998. SiS_Pr->SiS_DDC_NData,
  7999. SiS_Pr->SiS_DDC_Data); /* SD->high */
  8000. if(SiS_SetSCLKHigh(SiS_Pr)) return 0xFFFF; /* SC->high */
  8001. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8002. SiS_Pr->SiS_DDC_Index,
  8003. SiS_Pr->SiS_DDC_NData,
  8004. 0x00); /* SD->low = start condition */
  8005. if(SiS_SetSCLKHigh(SiS_Pr)) return 0xFFFF; /* (SC->low) */
  8006. return 0;
  8007. }
  8008. /* Set I2C stop condition */
  8009. /* This is done by a SD low-to-high transition while SC is high */
  8010. static unsigned short
  8011. SiS_SetStop(struct SiS_Private *SiS_Pr)
  8012. {
  8013. if(SiS_SetSCLKLow(SiS_Pr)) return 0xFFFF; /* (SC->low) */
  8014. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8015. SiS_Pr->SiS_DDC_Index,
  8016. SiS_Pr->SiS_DDC_NData,
  8017. 0x00); /* SD->low */
  8018. if(SiS_SetSCLKHigh(SiS_Pr)) return 0xFFFF; /* SC->high */
  8019. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8020. SiS_Pr->SiS_DDC_Index,
  8021. SiS_Pr->SiS_DDC_NData,
  8022. SiS_Pr->SiS_DDC_Data); /* SD->high = stop condition */
  8023. if(SiS_SetSCLKHigh(SiS_Pr)) return 0xFFFF; /* (SC->high) */
  8024. return 0;
  8025. }
  8026. /* Write 8 bits of data */
  8027. static unsigned short
  8028. SiS_WriteDDC2Data(struct SiS_Private *SiS_Pr, unsigned short tempax)
  8029. {
  8030. unsigned short i,flag,temp;
  8031. flag = 0x80;
  8032. for(i = 0; i < 8; i++) {
  8033. SiS_SetSCLKLow(SiS_Pr); /* SC->low */
  8034. if(tempax & flag) {
  8035. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8036. SiS_Pr->SiS_DDC_Index,
  8037. SiS_Pr->SiS_DDC_NData,
  8038. SiS_Pr->SiS_DDC_Data); /* Write bit (1) to SD */
  8039. } else {
  8040. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8041. SiS_Pr->SiS_DDC_Index,
  8042. SiS_Pr->SiS_DDC_NData,
  8043. 0x00); /* Write bit (0) to SD */
  8044. }
  8045. SiS_SetSCLKHigh(SiS_Pr); /* SC->high */
  8046. flag >>= 1;
  8047. }
  8048. temp = SiS_CheckACK(SiS_Pr); /* Check acknowledge */
  8049. return temp;
  8050. }
  8051. static unsigned short
  8052. SiS_ReadDDC2Data(struct SiS_Private *SiS_Pr)
  8053. {
  8054. unsigned short i, temp, getdata;
  8055. getdata = 0;
  8056. for(i = 0; i < 8; i++) {
  8057. getdata <<= 1;
  8058. SiS_SetSCLKLow(SiS_Pr);
  8059. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8060. SiS_Pr->SiS_DDC_Index,
  8061. SiS_Pr->SiS_DDC_NData,
  8062. SiS_Pr->SiS_DDC_Data);
  8063. SiS_SetSCLKHigh(SiS_Pr);
  8064. temp = SiS_GetReg(SiS_Pr->SiS_DDC_Port,SiS_Pr->SiS_DDC_Index);
  8065. if(temp & SiS_Pr->SiS_DDC_Data) getdata |= 0x01;
  8066. }
  8067. return getdata;
  8068. }
  8069. static unsigned short
  8070. SiS_SetSCLKLow(struct SiS_Private *SiS_Pr)
  8071. {
  8072. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8073. SiS_Pr->SiS_DDC_Index,
  8074. SiS_Pr->SiS_DDC_NClk,
  8075. 0x00); /* SetSCLKLow() */
  8076. SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT);
  8077. return 0;
  8078. }
  8079. static unsigned short
  8080. SiS_SetSCLKHigh(struct SiS_Private *SiS_Pr)
  8081. {
  8082. unsigned short temp, watchdog=1000;
  8083. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8084. SiS_Pr->SiS_DDC_Index,
  8085. SiS_Pr->SiS_DDC_NClk,
  8086. SiS_Pr->SiS_DDC_Clk); /* SetSCLKHigh() */
  8087. do {
  8088. temp = SiS_GetReg(SiS_Pr->SiS_DDC_Port,SiS_Pr->SiS_DDC_Index);
  8089. } while((!(temp & SiS_Pr->SiS_DDC_Clk)) && --watchdog);
  8090. if (!watchdog) {
  8091. return 0xFFFF;
  8092. }
  8093. SiS_DDC2Delay(SiS_Pr,SiS_I2CDELAYSHORT);
  8094. return 0;
  8095. }
  8096. /* Check I2C acknowledge */
  8097. /* Returns 0 if ack ok, non-0 if ack not ok */
  8098. static unsigned short
  8099. SiS_CheckACK(struct SiS_Private *SiS_Pr)
  8100. {
  8101. unsigned short tempah;
  8102. SiS_SetSCLKLow(SiS_Pr); /* (SC->low) */
  8103. SiS_SetRegANDOR(SiS_Pr->SiS_DDC_Port,
  8104. SiS_Pr->SiS_DDC_Index,
  8105. SiS_Pr->SiS_DDC_NData,
  8106. SiS_Pr->SiS_DDC_Data); /* (SD->high) */
  8107. SiS_SetSCLKHigh(SiS_Pr); /* SC->high = clock impulse for ack */
  8108. tempah = SiS_GetReg(SiS_Pr->SiS_DDC_Port,SiS_Pr->SiS_DDC_Index); /* Read SD */
  8109. SiS_SetSCLKLow(SiS_Pr); /* SC->low = end of clock impulse */
  8110. if(tempah & SiS_Pr->SiS_DDC_Data) return 1; /* Ack OK if bit = 0 */
  8111. return 0;
  8112. }
  8113. /* End of I2C functions ----------------------- */
  8114. /* =============== SiS 315/330 O.E.M. ================= */
  8115. #ifdef SIS315H
  8116. static unsigned short
  8117. GetRAMDACromptr(struct SiS_Private *SiS_Pr)
  8118. {
  8119. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  8120. unsigned short romptr;
  8121. if(SiS_Pr->ChipType < SIS_330) {
  8122. romptr = SISGETROMW(0x128);
  8123. if(SiS_Pr->SiS_VBType & VB_SIS30xB)
  8124. romptr = SISGETROMW(0x12a);
  8125. } else {
  8126. romptr = SISGETROMW(0x1a8);
  8127. if(SiS_Pr->SiS_VBType & VB_SIS30xB)
  8128. romptr = SISGETROMW(0x1aa);
  8129. }
  8130. return romptr;
  8131. }
  8132. static unsigned short
  8133. GetLCDromptr(struct SiS_Private *SiS_Pr)
  8134. {
  8135. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  8136. unsigned short romptr;
  8137. if(SiS_Pr->ChipType < SIS_330) {
  8138. romptr = SISGETROMW(0x120);
  8139. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV)
  8140. romptr = SISGETROMW(0x122);
  8141. } else {
  8142. romptr = SISGETROMW(0x1a0);
  8143. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV)
  8144. romptr = SISGETROMW(0x1a2);
  8145. }
  8146. return romptr;
  8147. }
  8148. static unsigned short
  8149. GetTVromptr(struct SiS_Private *SiS_Pr)
  8150. {
  8151. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  8152. unsigned short romptr;
  8153. if(SiS_Pr->ChipType < SIS_330) {
  8154. romptr = SISGETROMW(0x114);
  8155. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV)
  8156. romptr = SISGETROMW(0x11a);
  8157. } else {
  8158. romptr = SISGETROMW(0x194);
  8159. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV)
  8160. romptr = SISGETROMW(0x19a);
  8161. }
  8162. return romptr;
  8163. }
  8164. static unsigned short
  8165. GetLCDPtrIndexBIOS(struct SiS_Private *SiS_Pr)
  8166. {
  8167. unsigned short index;
  8168. if((IS_SIS650) && (SiS_Pr->SiS_VBType & VB_SISLVDS)) {
  8169. if(!(SiS_IsNotM650orLater(SiS_Pr))) {
  8170. if((index = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) & 0xf0)) {
  8171. index >>= 4;
  8172. index *= 3;
  8173. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) index += 2;
  8174. else if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) index++;
  8175. return index;
  8176. }
  8177. }
  8178. }
  8179. index = SiS_GetBIOSLCDResInfo(SiS_Pr) & 0x0F;
  8180. if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) index -= 5;
  8181. if(SiS_Pr->SiS_VBType & VB_SIS301C) { /* 1.15.20 and later (not VB specific) */
  8182. if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) index -= 5;
  8183. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x768) index -= 5;
  8184. } else {
  8185. if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) index -= 6;
  8186. }
  8187. index--;
  8188. index *= 3;
  8189. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) index += 2;
  8190. else if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) index++;
  8191. return index;
  8192. }
  8193. static unsigned short
  8194. GetLCDPtrIndex(struct SiS_Private *SiS_Pr)
  8195. {
  8196. unsigned short index;
  8197. index = ((SiS_GetBIOSLCDResInfo(SiS_Pr) & 0x0F) - 1) * 3;
  8198. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) index += 2;
  8199. else if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) index++;
  8200. return index;
  8201. }
  8202. static unsigned short
  8203. GetTVPtrIndex(struct SiS_Private *SiS_Pr)
  8204. {
  8205. unsigned short index;
  8206. index = 0;
  8207. if(SiS_Pr->SiS_TVMode & TVSetPAL) index = 1;
  8208. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) index = 2;
  8209. if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) index = 0;
  8210. index <<= 1;
  8211. if((SiS_Pr->SiS_VBInfo & SetInSlaveMode) &&
  8212. (SiS_Pr->SiS_TVMode & TVSetTVSimuMode)) {
  8213. index++;
  8214. }
  8215. return index;
  8216. }
  8217. static unsigned int
  8218. GetOEMTVPtr661_2_GEN(struct SiS_Private *SiS_Pr, int addme)
  8219. {
  8220. unsigned short index = 0, temp = 0;
  8221. if(SiS_Pr->SiS_TVMode & TVSetPAL) index = 1;
  8222. if(SiS_Pr->SiS_TVMode & TVSetPALM) index = 2;
  8223. if(SiS_Pr->SiS_TVMode & TVSetPALN) index = 3;
  8224. if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) index = 6;
  8225. if(SiS_Pr->SiS_TVMode & TVSetNTSC1024) {
  8226. index = 4;
  8227. if(SiS_Pr->SiS_TVMode & TVSetPALM) index++;
  8228. if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) index = 7;
  8229. }
  8230. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  8231. if((!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) ||
  8232. (SiS_Pr->SiS_TVMode & TVSetTVSimuMode)) {
  8233. index += addme;
  8234. temp++;
  8235. }
  8236. temp += 0x0100;
  8237. }
  8238. return (unsigned int)(index | (temp << 16));
  8239. }
  8240. static unsigned int
  8241. GetOEMTVPtr661_2_OLD(struct SiS_Private *SiS_Pr)
  8242. {
  8243. return (GetOEMTVPtr661_2_GEN(SiS_Pr, 8));
  8244. }
  8245. #if 0
  8246. static unsigned int
  8247. GetOEMTVPtr661_2_NEW(struct SiS_Private *SiS_Pr)
  8248. {
  8249. return (GetOEMTVPtr661_2_GEN(SiS_Pr, 6));
  8250. }
  8251. #endif
  8252. static int
  8253. GetOEMTVPtr661(struct SiS_Private *SiS_Pr)
  8254. {
  8255. int index = 0;
  8256. if(SiS_Pr->SiS_TVMode & TVSetPAL) index = 2;
  8257. if(SiS_Pr->SiS_ROMNew) {
  8258. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525i) index = 4;
  8259. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) index = 6;
  8260. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) index = 8;
  8261. if(SiS_Pr->SiS_TVMode & TVSetHiVision) index = 10;
  8262. } else {
  8263. if(SiS_Pr->SiS_TVMode & TVSetHiVision) index = 4;
  8264. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525i) index = 6;
  8265. if(SiS_Pr->SiS_TVMode & TVSetYPbPr525p) index = 8;
  8266. if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) index = 10;
  8267. }
  8268. if(SiS_Pr->SiS_TVMode & TVSetTVSimuMode) index++;
  8269. return index;
  8270. }
  8271. static void
  8272. SetDelayComp(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
  8273. {
  8274. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  8275. unsigned short delay=0,index,myindex,temp,romptr=0;
  8276. bool dochiptest = true;
  8277. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  8278. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x20,0xbf);
  8279. } else {
  8280. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x35,0x7f);
  8281. }
  8282. /* Find delay (from ROM, internal tables, PCI subsystem) */
  8283. if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) { /* ------------ VGA */
  8284. if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
  8285. romptr = GetRAMDACromptr(SiS_Pr);
  8286. }
  8287. if(romptr) delay = ROMAddr[romptr];
  8288. else {
  8289. delay = 0x04;
  8290. if(SiS_Pr->SiS_VBType & VB_SIS30xB) {
  8291. if(IS_SIS650) {
  8292. delay = 0x0a;
  8293. } else if(IS_SIS740) {
  8294. delay = 0x00;
  8295. } else if(SiS_Pr->ChipType < SIS_330) {
  8296. delay = 0x0c;
  8297. } else {
  8298. delay = 0x0c;
  8299. }
  8300. } else if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  8301. delay = 0x00;
  8302. }
  8303. }
  8304. } else if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD|SetCRT2ToLCDA)) { /* ---------- LCD/LCDA */
  8305. bool gotitfrompci = false;
  8306. /* Could we detect a PDC for LCD or did we get a user-defined? If yes, use it */
  8307. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  8308. if(SiS_Pr->PDC != -1) {
  8309. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0xf0,((SiS_Pr->PDC >> 1) & 0x0f));
  8310. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x35,0x7f,((SiS_Pr->PDC & 0x01) << 7));
  8311. return;
  8312. }
  8313. } else {
  8314. if(SiS_Pr->PDCA != -1) {
  8315. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0x0f,((SiS_Pr->PDCA << 3) & 0xf0));
  8316. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x20,0xbf,((SiS_Pr->PDCA & 0x01) << 6));
  8317. return;
  8318. }
  8319. }
  8320. /* Custom Panel? */
  8321. if(SiS_Pr->SiS_LCDResInfo == Panel_Custom) {
  8322. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  8323. delay = 0x00;
  8324. if((SiS_Pr->PanelXRes <= 1280) && (SiS_Pr->PanelYRes <= 1024)) {
  8325. delay = 0x20;
  8326. }
  8327. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0x0f,delay);
  8328. } else {
  8329. delay = 0x0c;
  8330. if(SiS_Pr->SiS_VBType & VB_SIS301C) {
  8331. delay = 0x03;
  8332. if((SiS_Pr->PanelXRes > 1280) && (SiS_Pr->PanelYRes > 1024)) {
  8333. delay = 0x00;
  8334. }
  8335. } else if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  8336. if(IS_SIS740) delay = 0x01;
  8337. else delay = 0x03;
  8338. }
  8339. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0xf0,delay);
  8340. }
  8341. return;
  8342. }
  8343. /* This is a piece of typical SiS crap: They code the OEM LCD
  8344. * delay into the code, at no defined place in the BIOS.
  8345. * We now have to start doing a PCI subsystem check here.
  8346. */
  8347. switch(SiS_Pr->SiS_CustomT) {
  8348. case CUT_COMPAQ1280:
  8349. case CUT_COMPAQ12802:
  8350. if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) {
  8351. gotitfrompci = true;
  8352. dochiptest = false;
  8353. delay = 0x03;
  8354. }
  8355. break;
  8356. case CUT_CLEVO1400:
  8357. case CUT_CLEVO14002:
  8358. gotitfrompci = true;
  8359. dochiptest = false;
  8360. delay = 0x02;
  8361. break;
  8362. case CUT_CLEVO1024:
  8363. case CUT_CLEVO10242:
  8364. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  8365. gotitfrompci = true;
  8366. dochiptest = false;
  8367. delay = 0x33;
  8368. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2D,delay);
  8369. delay &= 0x0f;
  8370. }
  8371. break;
  8372. }
  8373. /* Could we find it through the PCI ID? If no, use ROM or table */
  8374. if(!gotitfrompci) {
  8375. index = GetLCDPtrIndexBIOS(SiS_Pr);
  8376. myindex = GetLCDPtrIndex(SiS_Pr);
  8377. if(IS_SIS650 && (SiS_Pr->SiS_VBType & VB_SISLVDS)) {
  8378. if(SiS_IsNotM650orLater(SiS_Pr)) {
  8379. if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
  8380. /* Always use the second pointer on 650; some BIOSes */
  8381. /* still carry old 301 data at the first location */
  8382. /* romptr = SISGETROMW(0x120); */
  8383. /* if(SiS_Pr->SiS_VBType & VB_SIS302LV) */
  8384. romptr = SISGETROMW(0x122);
  8385. if(!romptr) return;
  8386. delay = ROMAddr[(romptr + index)];
  8387. } else {
  8388. delay = SiS310_LCDDelayCompensation_650301LV[myindex];
  8389. }
  8390. } else {
  8391. delay = SiS310_LCDDelayCompensation_651301LV[myindex];
  8392. if(SiS_Pr->SiS_VBType & (VB_SIS302LV | VB_SIS302ELV))
  8393. delay = SiS310_LCDDelayCompensation_651302LV[myindex];
  8394. }
  8395. } else if(SiS_Pr->SiS_UseROM &&
  8396. (!(SiS_Pr->SiS_ROMNew)) &&
  8397. (SiS_Pr->SiS_LCDResInfo != Panel_1280x1024) &&
  8398. (SiS_Pr->SiS_LCDResInfo != Panel_1280x768) &&
  8399. (SiS_Pr->SiS_LCDResInfo != Panel_1280x960) &&
  8400. (SiS_Pr->SiS_LCDResInfo != Panel_1600x1200) &&
  8401. ((romptr = GetLCDromptr(SiS_Pr)))) {
  8402. /* Data for 1280x1024 wrong in 301B BIOS */
  8403. /* Data for 1600x1200 wrong in 301C BIOS */
  8404. delay = ROMAddr[(romptr + index)];
  8405. } else if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  8406. if(IS_SIS740) delay = 0x03;
  8407. else delay = 0x00;
  8408. } else {
  8409. delay = SiS310_LCDDelayCompensation_301[myindex];
  8410. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  8411. if(IS_SIS740) delay = 0x01;
  8412. else if(SiS_Pr->ChipType <= SIS_315PRO) delay = SiS310_LCDDelayCompensation_3xx301LV[myindex];
  8413. else delay = SiS310_LCDDelayCompensation_650301LV[myindex];
  8414. } else if(SiS_Pr->SiS_VBType & VB_SIS301C) {
  8415. if(IS_SIS740) delay = 0x01; /* ? */
  8416. else delay = 0x03;
  8417. if(SiS_Pr->SiS_LCDResInfo == Panel_1600x1200) delay = 0x00; /* experience */
  8418. } else if(SiS_Pr->SiS_VBType & VB_SIS30xB) {
  8419. if(IS_SIS740) delay = 0x01;
  8420. else delay = SiS310_LCDDelayCompensation_3xx301B[myindex];
  8421. }
  8422. }
  8423. } /* got it from PCI */
  8424. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  8425. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,0x0F,((delay << 4) & 0xf0));
  8426. dochiptest = false;
  8427. }
  8428. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { /* ------------ TV */
  8429. index = GetTVPtrIndex(SiS_Pr);
  8430. if(IS_SIS650 && (SiS_Pr->SiS_VBType & VB_SISLVDS)) {
  8431. if(SiS_IsNotM650orLater(SiS_Pr)) {
  8432. if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
  8433. /* Always use the second pointer on 650; some BIOSes */
  8434. /* still carry old 301 data at the first location */
  8435. /* romptr = SISGETROMW(0x114); */
  8436. /* if(SiS_Pr->SiS_VBType & VB_SIS302LV) */
  8437. romptr = SISGETROMW(0x11a);
  8438. if(!romptr) return;
  8439. delay = ROMAddr[romptr + index];
  8440. } else {
  8441. delay = SiS310_TVDelayCompensation_301B[index];
  8442. }
  8443. } else {
  8444. switch(SiS_Pr->SiS_CustomT) {
  8445. case CUT_COMPAQ1280:
  8446. case CUT_COMPAQ12802:
  8447. case CUT_CLEVO1400:
  8448. case CUT_CLEVO14002:
  8449. delay = 0x02;
  8450. dochiptest = false;
  8451. break;
  8452. case CUT_CLEVO1024:
  8453. case CUT_CLEVO10242:
  8454. delay = 0x03;
  8455. dochiptest = false;
  8456. break;
  8457. default:
  8458. delay = SiS310_TVDelayCompensation_651301LV[index];
  8459. if(SiS_Pr->SiS_VBType & VB_SIS302LV) {
  8460. delay = SiS310_TVDelayCompensation_651302LV[index];
  8461. }
  8462. }
  8463. }
  8464. } else if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
  8465. romptr = GetTVromptr(SiS_Pr);
  8466. if(!romptr) return;
  8467. delay = ROMAddr[romptr + index];
  8468. } else if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  8469. delay = SiS310_TVDelayCompensation_LVDS[index];
  8470. } else {
  8471. delay = SiS310_TVDelayCompensation_301[index];
  8472. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  8473. if(IS_SIS740) {
  8474. delay = SiS310_TVDelayCompensation_740301B[index];
  8475. /* LV: use 301 data? BIOS bug? */
  8476. } else {
  8477. delay = SiS310_TVDelayCompensation_301B[index];
  8478. if(SiS_Pr->SiS_VBType & VB_SIS301C) delay = 0x02;
  8479. }
  8480. }
  8481. }
  8482. if(SiS_LCDAEnabled(SiS_Pr)) {
  8483. delay &= 0x0f;
  8484. dochiptest = false;
  8485. }
  8486. } else return;
  8487. /* Write delay */
  8488. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  8489. if(IS_SIS650 && (SiS_Pr->SiS_VBType & VB_SISLVDS) && dochiptest) {
  8490. temp = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) & 0xf0) >> 4;
  8491. if(temp == 8) { /* 1400x1050 BIOS (COMPAL) */
  8492. delay &= 0x0f;
  8493. delay |= 0xb0;
  8494. } else if(temp == 6) {
  8495. delay &= 0x0f;
  8496. delay |= 0xc0;
  8497. } else if(temp > 7) { /* 1280x1024 BIOS (which one?) */
  8498. delay = 0x35;
  8499. }
  8500. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2D,delay);
  8501. } else {
  8502. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,0xF0,delay);
  8503. }
  8504. } else { /* LVDS */
  8505. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  8506. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,0xF0,delay);
  8507. } else {
  8508. if(IS_SIS650 && (SiS_Pr->SiS_IF_DEF_CH70xx != 0)) {
  8509. delay <<= 4;
  8510. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,0x0F,delay);
  8511. } else {
  8512. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,0xF0,delay);
  8513. }
  8514. }
  8515. }
  8516. }
  8517. static void
  8518. SetAntiFlicker(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  8519. {
  8520. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  8521. unsigned short index,temp,temp1,romptr=0;
  8522. if(SiS_Pr->SiS_TVMode & (TVSetYPbPr750p|TVSetYPbPr525p)) return;
  8523. if(ModeNo<=0x13)
  8524. index = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].VB_StTVFlickerIndex;
  8525. else
  8526. index = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].VB_ExtTVFlickerIndex;
  8527. temp = GetTVPtrIndex(SiS_Pr);
  8528. temp >>= 1; /* 0: NTSC/YPbPr, 1: PAL, 2: HiTV */
  8529. temp1 = temp;
  8530. if(SiS_Pr->SiS_UseROM && (!(SiS_Pr->SiS_ROMNew))) {
  8531. if(SiS_Pr->ChipType >= SIS_661) {
  8532. temp1 = GetOEMTVPtr661(SiS_Pr);
  8533. temp1 >>= 1;
  8534. romptr = SISGETROMW(0x260);
  8535. if(SiS_Pr->ChipType >= SIS_760) {
  8536. romptr = SISGETROMW(0x360);
  8537. }
  8538. } else if(SiS_Pr->ChipType >= SIS_330) {
  8539. romptr = SISGETROMW(0x192);
  8540. } else {
  8541. romptr = SISGETROMW(0x112);
  8542. }
  8543. }
  8544. if(romptr) {
  8545. temp1 <<= 1;
  8546. temp = ROMAddr[romptr + temp1 + index];
  8547. } else {
  8548. temp = SiS310_TVAntiFlick1[temp][index];
  8549. }
  8550. temp <<= 4;
  8551. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x0A,0x8f,temp); /* index 0A D[6:4] */
  8552. }
  8553. static void
  8554. SetEdgeEnhance(struct SiS_Private *SiS_Pr, unsigned short ModeNo,unsigned short ModeIdIndex)
  8555. {
  8556. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  8557. unsigned short index,temp,temp1,romptr=0;
  8558. temp = temp1 = GetTVPtrIndex(SiS_Pr) >> 1; /* 0: NTSC/YPbPr, 1: PAL, 2: HiTV */
  8559. if(ModeNo <= 0x13)
  8560. index = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].VB_StTVEdgeIndex;
  8561. else
  8562. index = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].VB_ExtTVEdgeIndex;
  8563. if(SiS_Pr->SiS_UseROM && (!(SiS_Pr->SiS_ROMNew))) {
  8564. if(SiS_Pr->ChipType >= SIS_661) {
  8565. romptr = SISGETROMW(0x26c);
  8566. if(SiS_Pr->ChipType >= SIS_760) {
  8567. romptr = SISGETROMW(0x36c);
  8568. }
  8569. temp1 = GetOEMTVPtr661(SiS_Pr);
  8570. temp1 >>= 1;
  8571. } else if(SiS_Pr->ChipType >= SIS_330) {
  8572. romptr = SISGETROMW(0x1a4);
  8573. } else {
  8574. romptr = SISGETROMW(0x124);
  8575. }
  8576. }
  8577. if(romptr) {
  8578. temp1 <<= 1;
  8579. temp = ROMAddr[romptr + temp1 + index];
  8580. } else {
  8581. temp = SiS310_TVEdge1[temp][index];
  8582. }
  8583. temp <<= 5;
  8584. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x3A,0x1F,temp); /* index 0A D[7:5] */
  8585. }
  8586. static void
  8587. SetYFilter(struct SiS_Private *SiS_Pr, unsigned short ModeNo,unsigned short ModeIdIndex)
  8588. {
  8589. unsigned short index, temp, i, j;
  8590. if(ModeNo <= 0x13) {
  8591. index = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].VB_StTVYFilterIndex;
  8592. } else {
  8593. index = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].VB_ExtTVYFilterIndex;
  8594. }
  8595. temp = GetTVPtrIndex(SiS_Pr) >> 1; /* 0: NTSC/YPbPr, 1: PAL, 2: HiTV */
  8596. if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) temp = 1; /* NTSC-J uses PAL */
  8597. else if(SiS_Pr->SiS_TVMode & TVSetPALM) temp = 3; /* PAL-M */
  8598. else if(SiS_Pr->SiS_TVMode & TVSetPALN) temp = 4; /* PAL-N */
  8599. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) temp = 1; /* HiVision uses PAL */
  8600. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  8601. for(i=0x35, j=0; i<=0x38; i++, j++) {
  8602. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVYFilter2[temp][index][j]);
  8603. }
  8604. for(i=0x48; i<=0x4A; i++, j++) {
  8605. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVYFilter2[temp][index][j]);
  8606. }
  8607. } else {
  8608. for(i=0x35, j=0; i<=0x38; i++, j++) {
  8609. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVYFilter1[temp][index][j]);
  8610. }
  8611. }
  8612. }
  8613. static void
  8614. SetPhaseIncr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  8615. {
  8616. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  8617. unsigned short index,temp,i,j,resinfo,romptr=0;
  8618. unsigned int lindex;
  8619. if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) return;
  8620. /* NTSC-J data not in BIOS, and already set in SetGroup2 */
  8621. if(SiS_Pr->SiS_TVMode & TVSetNTSCJ) return;
  8622. if((SiS_Pr->ChipType >= SIS_661) || SiS_Pr->SiS_ROMNew) {
  8623. lindex = GetOEMTVPtr661_2_OLD(SiS_Pr) & 0xffff;
  8624. lindex <<= 2;
  8625. for(j=0, i=0x31; i<=0x34; i++, j++) {
  8626. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS_TVPhase[lindex + j]);
  8627. }
  8628. return;
  8629. }
  8630. /* PAL-M, PAL-N not in BIOS, and already set in SetGroup2 */
  8631. if(SiS_Pr->SiS_TVMode & (TVSetPALM | TVSetPALN)) return;
  8632. if(ModeNo<=0x13) {
  8633. resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
  8634. } else {
  8635. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  8636. }
  8637. temp = GetTVPtrIndex(SiS_Pr);
  8638. /* 0: NTSC Graphics, 1: NTSC Text, 2: PAL Graphics,
  8639. * 3: PAL Text, 4: HiTV Graphics 5: HiTV Text
  8640. */
  8641. if(SiS_Pr->SiS_UseROM) {
  8642. romptr = SISGETROMW(0x116);
  8643. if(SiS_Pr->ChipType >= SIS_330) {
  8644. romptr = SISGETROMW(0x196);
  8645. }
  8646. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  8647. romptr = SISGETROMW(0x11c);
  8648. if(SiS_Pr->ChipType >= SIS_330) {
  8649. romptr = SISGETROMW(0x19c);
  8650. }
  8651. if((SiS_Pr->SiS_VBInfo & SetInSlaveMode) && (!(SiS_Pr->SiS_TVMode & TVSetTVSimuMode))) {
  8652. romptr = SISGETROMW(0x116);
  8653. if(SiS_Pr->ChipType >= SIS_330) {
  8654. romptr = SISGETROMW(0x196);
  8655. }
  8656. }
  8657. }
  8658. }
  8659. if(romptr) {
  8660. romptr += (temp << 2);
  8661. for(j=0, i=0x31; i<=0x34; i++, j++) {
  8662. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,ROMAddr[romptr + j]);
  8663. }
  8664. } else {
  8665. index = temp % 2;
  8666. temp >>= 1; /* 0:NTSC, 1:PAL, 2:HiTV */
  8667. for(j=0, i=0x31; i<=0x34; i++, j++) {
  8668. if(!(SiS_Pr->SiS_VBType & VB_SIS30xBLV))
  8669. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVPhaseIncr1[temp][index][j]);
  8670. else if((!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) || (SiS_Pr->SiS_TVMode & TVSetTVSimuMode))
  8671. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVPhaseIncr2[temp][index][j]);
  8672. else
  8673. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS310_TVPhaseIncr1[temp][index][j]);
  8674. }
  8675. }
  8676. if((SiS_Pr->SiS_VBType & VB_SIS30xBLV) && (!(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision))) {
  8677. if((!(SiS_Pr->SiS_TVMode & (TVSetPAL | TVSetYPbPr525p | TVSetYPbPr750p))) && (ModeNo > 0x13)) {
  8678. if((resinfo == SIS_RI_640x480) ||
  8679. (resinfo == SIS_RI_800x600)) {
  8680. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x31,0x21);
  8681. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x32,0xf0);
  8682. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x33,0xf5);
  8683. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x34,0x7f);
  8684. } else if(resinfo == SIS_RI_1024x768) {
  8685. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x31,0x1e);
  8686. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x32,0x8b);
  8687. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x33,0xfb);
  8688. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x34,0x7b);
  8689. }
  8690. }
  8691. }
  8692. }
  8693. static void
  8694. SetDelayComp661(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
  8695. unsigned short ModeIdIndex, unsigned short RTI)
  8696. {
  8697. unsigned short delay = 0, romptr = 0, index, lcdpdcindex;
  8698. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  8699. if(!(SiS_Pr->SiS_VBInfo & (SetCRT2ToTV | SetCRT2ToLCD | SetCRT2ToLCDA | SetCRT2ToRAMDAC)))
  8700. return;
  8701. /* 1. New ROM: VGA2 and LCD/LCDA-Pass1:1 */
  8702. /* (If a custom mode is used, Pass1:1 is always set; hence we do this:) */
  8703. if(SiS_Pr->SiS_ROMNew) {
  8704. if((SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) ||
  8705. ((SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) &&
  8706. (SiS_Pr->SiS_LCDInfo & LCDPass11))) {
  8707. index = 25;
  8708. if(SiS_Pr->UseCustomMode) {
  8709. index = SiS_Pr->CSRClock;
  8710. } else if(ModeNo > 0x13) {
  8711. index = SiS_GetVCLK2Ptr(SiS_Pr,ModeNo,ModeIdIndex,RTI);
  8712. index = SiS_Pr->SiS_VCLKData[index].CLOCK;
  8713. }
  8714. if(index < 25) index = 25;
  8715. index = ((index / 25) - 1) << 1;
  8716. if((ROMAddr[0x5b] & 0x80) || (SiS_Pr->SiS_VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD))) {
  8717. index++;
  8718. }
  8719. romptr = SISGETROMW(0x104);
  8720. delay = ROMAddr[romptr + index];
  8721. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD)) {
  8722. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0xf0,((delay >> 1) & 0x0f));
  8723. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x35,0x7f,((delay & 0x01) << 7));
  8724. } else {
  8725. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0x0f,((delay << 3) & 0xf0));
  8726. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x20,0xbf,((delay & 0x01) << 6));
  8727. }
  8728. return;
  8729. }
  8730. }
  8731. /* 2. Old ROM: VGA2 and LCD/LCDA-Pass 1:1 */
  8732. if(SiS_Pr->UseCustomMode) delay = 0x04;
  8733. else if(ModeNo <= 0x13) delay = 0x04;
  8734. else delay = (SiS_Pr->SiS_RefIndex[RTI].Ext_PDC >> 4);
  8735. delay |= (delay << 8);
  8736. if(SiS_Pr->ChipType >= XGI_20) {
  8737. delay = 0x0606;
  8738. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  8739. delay = 0x0404;
  8740. if(SiS_Pr->SiS_XGIROM) {
  8741. index = GetTVPtrIndex(SiS_Pr);
  8742. if((romptr = SISGETROMW(0x35e))) {
  8743. delay = (ROMAddr[romptr + index] & 0x0f) << 1;
  8744. delay |= (delay << 8);
  8745. }
  8746. }
  8747. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
  8748. if(SiS_Pr->ChipType == XGI_40 && SiS_Pr->ChipRevision == 0x02) {
  8749. delay -= 0x0404;
  8750. }
  8751. }
  8752. }
  8753. } else if(SiS_Pr->ChipType >= SIS_340) {
  8754. delay = 0x0606;
  8755. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  8756. delay = 0x0404;
  8757. }
  8758. /* TODO (eventually) */
  8759. } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  8760. /* 3. TV */
  8761. index = GetOEMTVPtr661(SiS_Pr);
  8762. if(SiS_Pr->SiS_ROMNew) {
  8763. romptr = SISGETROMW(0x106);
  8764. if(SiS_Pr->SiS_VBType & VB_UMC) romptr += 12;
  8765. delay = ROMAddr[romptr + index];
  8766. } else {
  8767. delay = 0x04;
  8768. if(index > 3) delay = 0;
  8769. }
  8770. } else if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  8771. /* 4. LCD, LCDA (for new ROM only LV and non-Pass 1:1) */
  8772. if( (SiS_Pr->SiS_LCDResInfo != Panel_Custom) &&
  8773. ((romptr = GetLCDStructPtr661_2(SiS_Pr))) ) {
  8774. lcdpdcindex = (SiS_Pr->SiS_VBType & VB_UMC) ? 14 : 12;
  8775. /* For LVDS (and sometimes TMDS), the BIOS must know about the correct value */
  8776. delay = ROMAddr[romptr + lcdpdcindex + 1]; /* LCD */
  8777. delay |= (ROMAddr[romptr + lcdpdcindex] << 8); /* LCDA */
  8778. } else {
  8779. /* TMDS: Set our own, since BIOS has no idea */
  8780. /* (This is done on >=661 only, since <661 is calling this only for LVDS) */
  8781. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  8782. switch(SiS_Pr->SiS_LCDResInfo) {
  8783. case Panel_1024x768: delay = 0x0008; break;
  8784. case Panel_1280x720: delay = 0x0004; break;
  8785. case Panel_1280x768:
  8786. case Panel_1280x768_2:delay = 0x0004; break;
  8787. case Panel_1280x800:
  8788. case Panel_1280x800_2:delay = 0x0004; break; /* Verified for 1280x800 */
  8789. case Panel_1280x854: delay = 0x0004; break; /* FIXME */
  8790. case Panel_1280x1024: delay = 0x1e04; break;
  8791. case Panel_1400x1050: delay = 0x0004; break;
  8792. case Panel_1600x1200: delay = 0x0400; break;
  8793. case Panel_1680x1050: delay = 0x0e04; break;
  8794. default:
  8795. if((SiS_Pr->PanelXRes <= 1024) && (SiS_Pr->PanelYRes <= 768)) {
  8796. delay = 0x0008;
  8797. } else if((SiS_Pr->PanelXRes == 1280) && (SiS_Pr->PanelYRes == 1024)) {
  8798. delay = 0x1e04;
  8799. } else if((SiS_Pr->PanelXRes <= 1400) && (SiS_Pr->PanelYRes <= 1050)) {
  8800. delay = 0x0004;
  8801. } else if((SiS_Pr->PanelXRes <= 1600) && (SiS_Pr->PanelYRes <= 1200)) {
  8802. delay = 0x0400;
  8803. } else
  8804. delay = 0x0e04;
  8805. break;
  8806. }
  8807. }
  8808. /* Override by detected or user-set values */
  8809. /* (but only if, for some reason, we can't read value from BIOS) */
  8810. if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) && (SiS_Pr->PDC != -1)) {
  8811. delay = SiS_Pr->PDC & 0x1f;
  8812. }
  8813. if((SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) && (SiS_Pr->PDCA != -1)) {
  8814. delay = (SiS_Pr->PDCA & 0x1f) << 8;
  8815. }
  8816. }
  8817. }
  8818. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  8819. delay >>= 8;
  8820. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0x0f,((delay << 3) & 0xf0));
  8821. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x20,0xbf,((delay & 0x01) << 6));
  8822. } else {
  8823. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2d,0xf0,((delay >> 1) & 0x0f));
  8824. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x35,0x7f,((delay & 0x01) << 7));
  8825. }
  8826. }
  8827. static void
  8828. SetCRT2SyncDither661(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short RTI)
  8829. {
  8830. unsigned short infoflag;
  8831. unsigned char temp;
  8832. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  8833. if(ModeNo <= 0x13) {
  8834. infoflag = SiS_GetRegByte(SiS_Pr->SiS_P3ca+2);
  8835. } else if(SiS_Pr->UseCustomMode) {
  8836. infoflag = SiS_Pr->CInfoFlag;
  8837. } else {
  8838. infoflag = SiS_Pr->SiS_RefIndex[RTI].Ext_InfoFlag;
  8839. }
  8840. if(!(SiS_Pr->SiS_LCDInfo & LCDPass11)) {
  8841. infoflag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x37); /* No longer check D5 */
  8842. }
  8843. infoflag &= 0xc0;
  8844. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  8845. temp = (infoflag >> 6) | 0x0c;
  8846. if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) {
  8847. temp ^= 0x04;
  8848. if(SiS_Pr->SiS_ModeType >= Mode24Bpp) temp |= 0x10;
  8849. }
  8850. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x1a,0xe0,temp);
  8851. } else {
  8852. temp = 0x30;
  8853. if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) temp = 0x20;
  8854. temp |= infoflag;
  8855. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x19,0x0f,temp);
  8856. temp = 0;
  8857. if(SiS_Pr->SiS_LCDInfo & LCDRGB18Bit) {
  8858. if(SiS_Pr->SiS_ModeType >= Mode24Bpp) temp |= 0x80;
  8859. }
  8860. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x1a,0x7f,temp);
  8861. }
  8862. }
  8863. }
  8864. static void
  8865. SetPanelParms661(struct SiS_Private *SiS_Pr)
  8866. {
  8867. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  8868. unsigned short romptr, temp1, temp2;
  8869. if(SiS_Pr->SiS_VBType & (VB_SISLVDS | VB_SIS30xC)) {
  8870. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x24,0x0f);
  8871. }
  8872. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  8873. if(SiS_Pr->LVDSHL != -1) {
  8874. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,0xfc,SiS_Pr->LVDSHL);
  8875. }
  8876. }
  8877. if(SiS_Pr->SiS_ROMNew) {
  8878. if((romptr = GetLCDStructPtr661_2(SiS_Pr))) {
  8879. if(SiS_Pr->SiS_VBType & VB_SISLVDS) {
  8880. temp1 = (ROMAddr[romptr] & 0x03) | 0x0c;
  8881. temp2 = 0xfc;
  8882. if(SiS_Pr->LVDSHL != -1) {
  8883. temp1 &= 0xfc;
  8884. temp2 = 0xf3;
  8885. }
  8886. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,temp2,temp1);
  8887. }
  8888. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  8889. temp1 = (ROMAddr[romptr + 1] & 0x80) >> 1;
  8890. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x0d,0xbf,temp1);
  8891. }
  8892. }
  8893. }
  8894. }
  8895. static void
  8896. SiS_OEM310Setting(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex, unsigned short RRTI)
  8897. {
  8898. if((SiS_Pr->SiS_ROMNew) && (SiS_Pr->SiS_VBType & VB_SISLVDS)) {
  8899. SetDelayComp661(SiS_Pr, ModeNo, ModeIdIndex, RRTI);
  8900. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  8901. SetCRT2SyncDither661(SiS_Pr, ModeNo, RRTI);
  8902. SetPanelParms661(SiS_Pr);
  8903. }
  8904. } else {
  8905. SetDelayComp(SiS_Pr,ModeNo);
  8906. }
  8907. if((SiS_Pr->SiS_VBType & VB_SISVB) && (SiS_Pr->SiS_VBInfo & SetCRT2ToTV)) {
  8908. SetAntiFlicker(SiS_Pr,ModeNo,ModeIdIndex);
  8909. SetPhaseIncr(SiS_Pr,ModeNo,ModeIdIndex);
  8910. SetYFilter(SiS_Pr,ModeNo,ModeIdIndex);
  8911. if(SiS_Pr->SiS_VBType & VB_SIS301) {
  8912. SetEdgeEnhance(SiS_Pr,ModeNo,ModeIdIndex);
  8913. }
  8914. }
  8915. }
  8916. static void
  8917. SiS_OEM661Setting(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
  8918. unsigned short ModeIdIndex, unsigned short RRTI)
  8919. {
  8920. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  8921. SetDelayComp661(SiS_Pr, ModeNo, ModeIdIndex, RRTI);
  8922. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  8923. SetCRT2SyncDither661(SiS_Pr, ModeNo, RRTI);
  8924. SetPanelParms661(SiS_Pr);
  8925. }
  8926. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  8927. SetPhaseIncr(SiS_Pr, ModeNo, ModeIdIndex);
  8928. SetYFilter(SiS_Pr, ModeNo, ModeIdIndex);
  8929. SetAntiFlicker(SiS_Pr, ModeNo, ModeIdIndex);
  8930. if(SiS_Pr->SiS_VBType & VB_SIS301) {
  8931. SetEdgeEnhance(SiS_Pr, ModeNo, ModeIdIndex);
  8932. }
  8933. }
  8934. }
  8935. }
  8936. /* FinalizeLCD
  8937. * This finalizes some CRT2 registers for the very panel used.
  8938. * If we have a backup if these registers, we use it; otherwise
  8939. * we set the register according to most BIOSes. However, this
  8940. * function looks quite different in every BIOS, so you better
  8941. * pray that we have a backup...
  8942. */
  8943. static void
  8944. SiS_FinalizeLCD(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  8945. {
  8946. unsigned short tempcl,tempch,tempbl,tempbh,tempbx,tempax,temp;
  8947. unsigned short resinfo,modeflag;
  8948. if(!(SiS_Pr->SiS_VBType & VB_SISLVDS)) return;
  8949. if(SiS_Pr->SiS_ROMNew) return;
  8950. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  8951. if(SiS_Pr->LVDSHL != -1) {
  8952. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,0xfc,SiS_Pr->LVDSHL);
  8953. }
  8954. }
  8955. if(SiS_Pr->SiS_LCDResInfo == Panel_Custom) return;
  8956. if(SiS_Pr->UseCustomMode) return;
  8957. switch(SiS_Pr->SiS_CustomT) {
  8958. case CUT_COMPAQ1280:
  8959. case CUT_COMPAQ12802:
  8960. case CUT_CLEVO1400:
  8961. case CUT_CLEVO14002:
  8962. return;
  8963. }
  8964. if(ModeNo <= 0x13) {
  8965. resinfo = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
  8966. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  8967. } else {
  8968. resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
  8969. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  8970. }
  8971. if(IS_SIS650) {
  8972. if(!(SiS_GetReg(SiS_Pr->SiS_P3d4, 0x5f) & 0xf0)) {
  8973. if(SiS_Pr->SiS_CustomT == CUT_CLEVO1024) {
  8974. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1e,0x02);
  8975. } else {
  8976. SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x1e,0x03);
  8977. }
  8978. }
  8979. }
  8980. if(SiS_Pr->SiS_CustomT == CUT_CLEVO1024) {
  8981. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  8982. /* Maybe all panels? */
  8983. if(SiS_Pr->LVDSHL == -1) {
  8984. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,0xfc,0x01);
  8985. }
  8986. return;
  8987. }
  8988. }
  8989. if(SiS_Pr->SiS_CustomT == CUT_CLEVO10242) {
  8990. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  8991. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  8992. if(SiS_Pr->LVDSHL == -1) {
  8993. /* Maybe all panels? */
  8994. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,0xfc,0x01);
  8995. }
  8996. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  8997. tempch = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4;
  8998. if(tempch == 3) {
  8999. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x02);
  9000. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,0x25);
  9001. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1c,0x00);
  9002. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1d,0x1b);
  9003. }
  9004. }
  9005. return;
  9006. }
  9007. }
  9008. }
  9009. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
  9010. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  9011. if(SiS_Pr->SiS_VBType & VB_SISEMI) {
  9012. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x2a,0x00);
  9013. #ifdef SET_EMI
  9014. SiS_SetRegAND(SiS_Pr->SiS_Part4Port,0x30,0x0c);
  9015. #endif
  9016. SiS_SetReg(SiS_Pr->SiS_Part4Port,0x34,0x10);
  9017. }
  9018. } else if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) {
  9019. if(SiS_Pr->LVDSHL == -1) {
  9020. /* Maybe ACER only? */
  9021. SiS_SetRegANDOR(SiS_Pr->SiS_Part4Port,0x24,0xfc,0x01);
  9022. }
  9023. }
  9024. tempch = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4;
  9025. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
  9026. if(SiS_Pr->SiS_LCDResInfo == Panel_1400x1050) {
  9027. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1f,0x76);
  9028. } else if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  9029. if(tempch == 0x03) {
  9030. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x02);
  9031. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,0x25);
  9032. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1c,0x00);
  9033. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1d,0x1b);
  9034. }
  9035. if(SiS_Pr->Backup && (SiS_Pr->Backup_Mode == ModeNo)) {
  9036. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x14,SiS_Pr->Backup_14);
  9037. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x15,SiS_Pr->Backup_15);
  9038. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x16,SiS_Pr->Backup_16);
  9039. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x17,SiS_Pr->Backup_17);
  9040. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,SiS_Pr->Backup_18);
  9041. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x19,SiS_Pr->Backup_19);
  9042. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1a,SiS_Pr->Backup_1a);
  9043. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,SiS_Pr->Backup_1b);
  9044. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1c,SiS_Pr->Backup_1c);
  9045. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1d,SiS_Pr->Backup_1d);
  9046. } else if(!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) { /* 1.10.8w */
  9047. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x14,0x90);
  9048. if(ModeNo <= 0x13) {
  9049. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x11);
  9050. if((resinfo == 0) || (resinfo == 2)) return;
  9051. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x18);
  9052. if((resinfo == 1) || (resinfo == 3)) return;
  9053. }
  9054. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x02);
  9055. if((ModeNo > 0x13) && (resinfo == SIS_RI_1024x768)) {
  9056. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x02); /* 1.10.7u */
  9057. #if 0
  9058. tempbx = 806; /* 0x326 */ /* other older BIOSes */
  9059. tempbx--;
  9060. temp = tempbx & 0xff;
  9061. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,temp);
  9062. temp = (tempbx >> 8) & 0x03;
  9063. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x1d,0xf8,temp);
  9064. #endif
  9065. }
  9066. } else if(ModeNo <= 0x13) {
  9067. if(ModeNo <= 1) {
  9068. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x70);
  9069. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x19,0xff);
  9070. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,0x48);
  9071. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1d,0x12);
  9072. }
  9073. if(!(modeflag & HalfDCLK)) {
  9074. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x14,0x20);
  9075. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x15,0x1a);
  9076. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x16,0x28);
  9077. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x17,0x00);
  9078. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x4c);
  9079. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x19,0xdc);
  9080. if(ModeNo == 0x12) {
  9081. switch(tempch) {
  9082. case 0:
  9083. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x95);
  9084. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x19,0xdc);
  9085. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1a,0x10);
  9086. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,0x95);
  9087. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1c,0x48);
  9088. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1d,0x12);
  9089. break;
  9090. case 2:
  9091. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,0x95);
  9092. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,0x48);
  9093. break;
  9094. case 3:
  9095. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1b,0x95);
  9096. break;
  9097. }
  9098. }
  9099. }
  9100. }
  9101. }
  9102. } else {
  9103. tempcl = tempbh = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x01);
  9104. tempcl &= 0x0f;
  9105. tempbh &= 0x70;
  9106. tempbh >>= 4;
  9107. tempbl = SiS_GetReg(SiS_Pr->SiS_Part2Port,0x04);
  9108. tempbx = (tempbh << 8) | tempbl;
  9109. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  9110. if((resinfo == SIS_RI_1024x768) || (!(SiS_Pr->SiS_LCDInfo & DontExpandLCD))) {
  9111. if(SiS_Pr->SiS_SetFlag & LCDVESATiming) {
  9112. tempbx = 770;
  9113. } else {
  9114. if(tempbx > 770) tempbx = 770;
  9115. if(SiS_Pr->SiS_VGAVDE < 600) {
  9116. tempax = 768 - SiS_Pr->SiS_VGAVDE;
  9117. tempax >>= 4; /* 1.10.7w; 1.10.6s: 3; */
  9118. if(SiS_Pr->SiS_VGAVDE <= 480) tempax >>= 4; /* 1.10.7w; 1.10.6s: < 480; >>=1; */
  9119. tempbx -= tempax;
  9120. }
  9121. }
  9122. } else return;
  9123. }
  9124. temp = tempbx & 0xff;
  9125. SiS_SetReg(SiS_Pr->SiS_Part2Port,0x04,temp);
  9126. temp = ((tempbx & 0xff00) >> 4) | tempcl;
  9127. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x01,0x80,temp);
  9128. }
  9129. }
  9130. }
  9131. #endif
  9132. /* ================= SiS 300 O.E.M. ================== */
  9133. #ifdef SIS300
  9134. static void
  9135. SetOEMLCDData2(struct SiS_Private *SiS_Pr, unsigned short ModeNo,unsigned short ModeIdIndex,
  9136. unsigned short RefTabIndex)
  9137. {
  9138. unsigned short crt2crtc=0, modeflag, myindex=0;
  9139. unsigned char temp;
  9140. int i;
  9141. if(ModeNo <= 0x13) {
  9142. modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  9143. crt2crtc = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
  9144. } else {
  9145. modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
  9146. crt2crtc = SiS_Pr->SiS_RefIndex[RefTabIndex].Ext_CRT2CRTC;
  9147. }
  9148. crt2crtc &= 0x3f;
  9149. if(SiS_Pr->SiS_CustomT == CUT_BARCO1024) {
  9150. SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x13,0xdf);
  9151. }
  9152. if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) {
  9153. if(modeflag & HalfDCLK) myindex = 1;
  9154. if(SiS_Pr->SiS_SetFlag & LowModeTests) {
  9155. for(i=0; i<7; i++) {
  9156. if(barco_p1[myindex][crt2crtc][i][0]) {
  9157. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,
  9158. barco_p1[myindex][crt2crtc][i][0],
  9159. barco_p1[myindex][crt2crtc][i][2],
  9160. barco_p1[myindex][crt2crtc][i][1]);
  9161. }
  9162. }
  9163. }
  9164. temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00);
  9165. if(temp & 0x80) {
  9166. temp = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x18);
  9167. temp++;
  9168. SiS_SetReg(SiS_Pr->SiS_Part1Port,0x18,temp);
  9169. }
  9170. }
  9171. }
  9172. static unsigned short
  9173. GetOEMLCDPtr(struct SiS_Private *SiS_Pr, int Flag)
  9174. {
  9175. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  9176. unsigned short tempbx=0,romptr=0;
  9177. static const unsigned char customtable300[] = {
  9178. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  9179. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
  9180. };
  9181. static const unsigned char customtable630[] = {
  9182. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  9183. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
  9184. };
  9185. if(SiS_Pr->ChipType == SIS_300) {
  9186. tempbx = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) & 0x0f;
  9187. if(SiS_Pr->SiS_VBType & VB_SIS301) tempbx &= 0x07;
  9188. tempbx -= 2;
  9189. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) tempbx += 4;
  9190. if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
  9191. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx += 3;
  9192. }
  9193. if(SiS_Pr->SiS_UseROM) {
  9194. if(ROMAddr[0x235] & 0x80) {
  9195. tempbx = SiS_Pr->SiS_LCDTypeInfo;
  9196. if(Flag) {
  9197. romptr = SISGETROMW(0x255);
  9198. if(romptr) tempbx = ROMAddr[romptr + SiS_Pr->SiS_LCDTypeInfo];
  9199. else tempbx = customtable300[SiS_Pr->SiS_LCDTypeInfo];
  9200. if(tempbx == 0xFF) return 0xFFFF;
  9201. }
  9202. tempbx <<= 1;
  9203. if(!(SiS_Pr->SiS_SetFlag & LCDVESATiming)) tempbx++;
  9204. }
  9205. }
  9206. } else {
  9207. if(Flag) {
  9208. if(SiS_Pr->SiS_UseROM) {
  9209. romptr = SISGETROMW(0x255);
  9210. if(romptr) tempbx = ROMAddr[romptr + SiS_Pr->SiS_LCDTypeInfo];
  9211. else tempbx = 0xff;
  9212. } else {
  9213. tempbx = customtable630[SiS_Pr->SiS_LCDTypeInfo];
  9214. }
  9215. if(tempbx == 0xFF) return 0xFFFF;
  9216. tempbx <<= 2;
  9217. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) tempbx += 2;
  9218. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++;
  9219. return tempbx;
  9220. }
  9221. tempbx = SiS_Pr->SiS_LCDTypeInfo << 2;
  9222. if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) tempbx += 2;
  9223. if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) tempbx++;
  9224. }
  9225. return tempbx;
  9226. }
  9227. static void
  9228. SetOEMLCDDelay(struct SiS_Private *SiS_Pr, unsigned short ModeNo,unsigned short ModeIdIndex)
  9229. {
  9230. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  9231. unsigned short index,temp,romptr=0;
  9232. if(SiS_Pr->SiS_LCDResInfo == Panel_Custom) return;
  9233. if(SiS_Pr->SiS_UseROM) {
  9234. if(!(ROMAddr[0x237] & 0x01)) return;
  9235. if(!(ROMAddr[0x237] & 0x02)) return;
  9236. romptr = SISGETROMW(0x24b);
  9237. }
  9238. /* The Panel Compensation Delay should be set according to tables
  9239. * here. Unfortunately, various BIOS versions don't care about
  9240. * a uniform way using eg. ROM byte 0x220, but use different
  9241. * hard coded delays (0x04, 0x20, 0x18) in SetGroup1().
  9242. * Thus we don't set this if the user selected a custom pdc or if
  9243. * we otherwise detected a valid pdc.
  9244. */
  9245. if(SiS_Pr->PDC != -1) return;
  9246. temp = GetOEMLCDPtr(SiS_Pr, 0);
  9247. if(SiS_Pr->UseCustomMode)
  9248. index = 0;
  9249. else
  9250. index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].VB_LCDDelayIndex;
  9251. if(SiS_Pr->ChipType != SIS_300) {
  9252. if(romptr) {
  9253. romptr += (temp * 2);
  9254. romptr = SISGETROMW(romptr);
  9255. romptr += index;
  9256. temp = ROMAddr[romptr];
  9257. } else {
  9258. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  9259. temp = SiS300_OEMLCDDelay2[temp][index];
  9260. } else {
  9261. temp = SiS300_OEMLCDDelay3[temp][index];
  9262. }
  9263. }
  9264. } else {
  9265. if(SiS_Pr->SiS_UseROM && (ROMAddr[0x235] & 0x80)) {
  9266. if(romptr) {
  9267. romptr += (temp * 2);
  9268. romptr = SISGETROMW(romptr);
  9269. romptr += index;
  9270. temp = ROMAddr[romptr];
  9271. } else {
  9272. temp = SiS300_OEMLCDDelay5[temp][index];
  9273. }
  9274. } else {
  9275. if(SiS_Pr->SiS_UseROM) {
  9276. romptr = ROMAddr[0x249] | (ROMAddr[0x24a] << 8);
  9277. if(romptr) {
  9278. romptr += (temp * 2);
  9279. romptr = SISGETROMW(romptr);
  9280. romptr += index;
  9281. temp = ROMAddr[romptr];
  9282. } else {
  9283. temp = SiS300_OEMLCDDelay4[temp][index];
  9284. }
  9285. } else {
  9286. temp = SiS300_OEMLCDDelay4[temp][index];
  9287. }
  9288. }
  9289. }
  9290. temp &= 0x3c;
  9291. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,~0x3C,temp); /* index 0A D[6:4] */
  9292. }
  9293. static void
  9294. SetOEMLCDData(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  9295. {
  9296. #if 0 /* Unfinished; Data table missing */
  9297. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  9298. unsigned short index,temp;
  9299. if((SiS_Pr->SiS_UseROM) {
  9300. if(!(ROMAddr[0x237] & 0x01)) return;
  9301. if(!(ROMAddr[0x237] & 0x04)) return;
  9302. /* No rom pointer in BIOS header! */
  9303. }
  9304. temp = GetOEMLCDPtr(SiS_Pr, 1);
  9305. if(temp == 0xFFFF) return;
  9306. index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex]._VB_LCDHIndex;
  9307. for(i=0x14, j=0; i<=0x17; i++, j++) {
  9308. SiS_SetReg(SiS_Pr->SiS_Part1Port,i,SiS300_LCDHData[temp][index][j]);
  9309. }
  9310. SiS_SetRegANDOR(SiS_SiS_Part1Port,0x1a, 0xf8, (SiS300_LCDHData[temp][index][j] & 0x07));
  9311. index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex]._VB_LCDVIndex;
  9312. SiS_SetReg(SiS_SiS_Part1Port,0x18, SiS300_LCDVData[temp][index][0]);
  9313. SiS_SetRegANDOR(SiS_SiS_Part1Port,0x19, 0xF0, SiS300_LCDVData[temp][index][1]);
  9314. SiS_SetRegANDOR(SiS_SiS_Part1Port,0x1A, 0xC7, (SiS300_LCDVData[temp][index][2] & 0x38));
  9315. for(i=0x1b, j=3; i<=0x1d; i++, j++) {
  9316. SiS_SetReg(SiS_Pr->SiS_Part1Port,i,SiS300_LCDVData[temp][index][j]);
  9317. }
  9318. #endif
  9319. }
  9320. static unsigned short
  9321. GetOEMTVPtr(struct SiS_Private *SiS_Pr)
  9322. {
  9323. unsigned short index;
  9324. index = 0;
  9325. if(!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) index += 4;
  9326. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  9327. if(SiS_Pr->SiS_VBInfo & SetCRT2ToSCART) index += 2;
  9328. else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) index += 3;
  9329. else if(SiS_Pr->SiS_TVMode & TVSetPAL) index += 1;
  9330. } else {
  9331. if(SiS_Pr->SiS_TVMode & TVSetCHOverScan) index += 2;
  9332. if(SiS_Pr->SiS_TVMode & TVSetPAL) index += 1;
  9333. }
  9334. return index;
  9335. }
  9336. static void
  9337. SetOEMTVDelay(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  9338. {
  9339. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  9340. unsigned short index,temp,romptr=0;
  9341. if(SiS_Pr->SiS_UseROM) {
  9342. if(!(ROMAddr[0x238] & 0x01)) return;
  9343. if(!(ROMAddr[0x238] & 0x02)) return;
  9344. romptr = SISGETROMW(0x241);
  9345. }
  9346. temp = GetOEMTVPtr(SiS_Pr);
  9347. index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].VB_TVDelayIndex;
  9348. if(romptr) {
  9349. romptr += (temp * 2);
  9350. romptr = SISGETROMW(romptr);
  9351. romptr += index;
  9352. temp = ROMAddr[romptr];
  9353. } else {
  9354. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  9355. temp = SiS300_OEMTVDelay301[temp][index];
  9356. } else {
  9357. temp = SiS300_OEMTVDelayLVDS[temp][index];
  9358. }
  9359. }
  9360. temp &= 0x3c;
  9361. SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x13,~0x3C,temp);
  9362. }
  9363. static void
  9364. SetOEMAntiFlicker(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  9365. {
  9366. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  9367. unsigned short index,temp,romptr=0;
  9368. if(SiS_Pr->SiS_UseROM) {
  9369. if(!(ROMAddr[0x238] & 0x01)) return;
  9370. if(!(ROMAddr[0x238] & 0x04)) return;
  9371. romptr = SISGETROMW(0x243);
  9372. }
  9373. temp = GetOEMTVPtr(SiS_Pr);
  9374. index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].VB_TVFlickerIndex;
  9375. if(romptr) {
  9376. romptr += (temp * 2);
  9377. romptr = SISGETROMW(romptr);
  9378. romptr += index;
  9379. temp = ROMAddr[romptr];
  9380. } else {
  9381. temp = SiS300_OEMTVFlicker[temp][index];
  9382. }
  9383. temp &= 0x70;
  9384. SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x0A,0x8F,temp);
  9385. }
  9386. static void
  9387. SetOEMPhaseIncr(struct SiS_Private *SiS_Pr, unsigned short ModeNo,unsigned short ModeIdIndex)
  9388. {
  9389. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  9390. unsigned short index,i,j,temp,romptr=0;
  9391. if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) return;
  9392. if(SiS_Pr->SiS_TVMode & (TVSetNTSC1024 | TVSetNTSCJ | TVSetPALM | TVSetPALN)) return;
  9393. if(SiS_Pr->SiS_UseROM) {
  9394. if(!(ROMAddr[0x238] & 0x01)) return;
  9395. if(!(ROMAddr[0x238] & 0x08)) return;
  9396. romptr = SISGETROMW(0x245);
  9397. }
  9398. temp = GetOEMTVPtr(SiS_Pr);
  9399. index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].VB_TVPhaseIndex;
  9400. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  9401. for(i=0x31, j=0; i<=0x34; i++, j++) {
  9402. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS300_Phase2[temp][index][j]);
  9403. }
  9404. } else {
  9405. if(romptr) {
  9406. romptr += (temp * 2);
  9407. romptr = SISGETROMW(romptr);
  9408. romptr += (index * 4);
  9409. for(i=0x31, j=0; i<=0x34; i++, j++) {
  9410. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,ROMAddr[romptr + j]);
  9411. }
  9412. } else {
  9413. for(i=0x31, j=0; i<=0x34; i++, j++) {
  9414. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS300_Phase1[temp][index][j]);
  9415. }
  9416. }
  9417. }
  9418. }
  9419. static void
  9420. SetOEMYFilter(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
  9421. {
  9422. unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
  9423. unsigned short index,temp,i,j,romptr=0;
  9424. if(SiS_Pr->SiS_VBInfo & (SetCRT2ToSCART | SetCRT2ToHiVision | SetCRT2ToYPbPr525750)) return;
  9425. if(SiS_Pr->SiS_UseROM) {
  9426. if(!(ROMAddr[0x238] & 0x01)) return;
  9427. if(!(ROMAddr[0x238] & 0x10)) return;
  9428. romptr = SISGETROMW(0x247);
  9429. }
  9430. temp = GetOEMTVPtr(SiS_Pr);
  9431. if(SiS_Pr->SiS_TVMode & TVSetPALM) temp = 8;
  9432. else if(SiS_Pr->SiS_TVMode & TVSetPALN) temp = 9;
  9433. /* NTSCJ uses NTSC filters */
  9434. index = SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].VB_TVYFilterIndex;
  9435. if(SiS_Pr->SiS_VBType & VB_SIS30xBLV) {
  9436. for(i=0x35, j=0; i<=0x38; i++, j++) {
  9437. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS300_Filter2[temp][index][j]);
  9438. }
  9439. for(i=0x48; i<=0x4A; i++, j++) {
  9440. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS300_Filter2[temp][index][j]);
  9441. }
  9442. } else {
  9443. if((romptr) && (!(SiS_Pr->SiS_TVMode & (TVSetPALM|TVSetPALN)))) {
  9444. romptr += (temp * 2);
  9445. romptr = SISGETROMW(romptr);
  9446. romptr += (index * 4);
  9447. for(i=0x35, j=0; i<=0x38; i++, j++) {
  9448. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,ROMAddr[romptr + j]);
  9449. }
  9450. } else {
  9451. for(i=0x35, j=0; i<=0x38; i++, j++) {
  9452. SiS_SetReg(SiS_Pr->SiS_Part2Port,i,SiS300_Filter1[temp][index][j]);
  9453. }
  9454. }
  9455. }
  9456. }
  9457. static unsigned short
  9458. SiS_SearchVBModeID(struct SiS_Private *SiS_Pr, unsigned short *ModeNo)
  9459. {
  9460. unsigned short ModeIdIndex;
  9461. unsigned char VGAINFO = SiS_Pr->SiS_VGAINFO;
  9462. if(*ModeNo <= 5) *ModeNo |= 1;
  9463. for(ModeIdIndex=0; ; ModeIdIndex++) {
  9464. if(SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].ModeID == *ModeNo) break;
  9465. if(SiS_Pr->SiS_VBModeIDTable[ModeIdIndex].ModeID == 0xFF) return 0;
  9466. }
  9467. if(*ModeNo != 0x07) {
  9468. if(*ModeNo > 0x03) return ModeIdIndex;
  9469. if(VGAINFO & 0x80) return ModeIdIndex;
  9470. ModeIdIndex++;
  9471. }
  9472. if(VGAINFO & 0x10) ModeIdIndex++; /* 400 lines */
  9473. /* else 350 lines */
  9474. return ModeIdIndex;
  9475. }
  9476. static void
  9477. SiS_OEM300Setting(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
  9478. unsigned short RefTableIndex)
  9479. {
  9480. unsigned short OEMModeIdIndex = 0;
  9481. if(!SiS_Pr->UseCustomMode) {
  9482. OEMModeIdIndex = SiS_SearchVBModeID(SiS_Pr,&ModeNo);
  9483. if(!(OEMModeIdIndex)) return;
  9484. }
  9485. if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
  9486. SetOEMLCDDelay(SiS_Pr, ModeNo, OEMModeIdIndex);
  9487. if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
  9488. SetOEMLCDData(SiS_Pr, ModeNo, OEMModeIdIndex);
  9489. }
  9490. }
  9491. if(SiS_Pr->UseCustomMode) return;
  9492. if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
  9493. SetOEMTVDelay(SiS_Pr, ModeNo,OEMModeIdIndex);
  9494. if(SiS_Pr->SiS_VBType & VB_SISVB) {
  9495. SetOEMAntiFlicker(SiS_Pr, ModeNo, OEMModeIdIndex);
  9496. SetOEMPhaseIncr(SiS_Pr, ModeNo, OEMModeIdIndex);
  9497. SetOEMYFilter(SiS_Pr, ModeNo, OEMModeIdIndex);
  9498. }
  9499. }
  9500. }
  9501. #endif